@@ -26,7 +26,7 @@ use Data::Dumper;
2626
2727use C4::Context;
2828use C4::Koha qw( GetAuthorisedValues ) ;
29- use C4::Auth qw( get_template_and_user ) ;
29+ use C4::Auth qw( get_template_and_user haspermission ) ;
3030
3131use Koha::Acquisition::Currencies qw( get_active ) ;
3232use Koha::DateUtils qw( dt_from_string output_pref ) ;
@@ -40,7 +40,7 @@ use Koha::Plugin::Com::LMSCloud::LatePaymentClaiming::LatePaymentClaimingConfigu
4040use Koha::Plugin::Com::LMSCloud::LatePaymentClaiming::LatePaymentClaiming;
4141use Koha::Plugin::Com::LMSCloud::LatePaymentClaiming::CheckExecution;
4242
43- our $VERSION = " 0.8 .0" ;
43+ our $VERSION = " 0.9 .0" ;
4444our $MINIMUM_VERSION = " 22.11" ;
4545
4646our $metadata = {
@@ -75,6 +75,7 @@ sub configure {
7575 $self -> store_data(
7676 {
7777 batch_active => scalar $cgi -> param(' batch_active' ),
78+ last_run => scalar $cgi -> param(' last_run' ),
7879 execution_month_days => scalar $cgi -> param(' execution_month_days' ) || ' *' ,
7980 execution_monthes => scalar $cgi -> param(' execution_monthes' ) || ' *' ,
8081 execution_weekdays => scalar $cgi -> param(' execution_weekdays' ) || ' *' ,
@@ -171,6 +172,7 @@ sub configure {
171172
172173 $template -> param(
173174 batch_active => $self -> retrieve_data(' batch_active' ) || 0,
175+ last_run => $self -> retrieve_data(' last_run' ),
174176 execution_month_days => $self -> retrieve_data(' execution_month_days' ) || ' *' ,
175177 execution_monthes => $self -> retrieve_data(' execution_monthes' ) || ' *' ,
176178 execution_weekdays => $self -> retrieve_data(' execution_weekdays' ) || ' *' ,
@@ -202,21 +204,86 @@ sub cronjob_nightly {
202204
203205 my $cron = Koha::Plugin::Com::LMSCloud::LatePaymentClaiming::CheckExecution-> new();
204206
207+ my $startdate = DateTime-> now()-> subtract(days => 1);
208+ my $lastrun = $self -> retrieve_data(' last_run' );
209+ if ( $lastrun ) {
210+ $startdate = dt_from_string($lastrun );
211+ }
212+
205213 my $result = $cron -> getNextDay(
206214 $execution_month_days ,
207215 $execution_monthes ,
208216 $execution_weekdays ,
209- DateTime -> now() -> subtract( days => 1) ,
217+ $startdate ,
210218 $execution_on_closing_days ,
211219 $execution_on_closing_days_library );
212220 if ( $result -> {ok } ) {
213221 if ( $result -> {next }-> ymd(' -' ) eq DateTime-> now()-> ymd(' -' ) ) {
214222 my $doClaim = Koha::Plugin::Com::LMSCloud::LatePaymentClaiming::LatePaymentClaiming-> new();
215223 $doClaim -> claimPatronsOfAllConfigurations();
224+ $self -> store_data({ last_run => dt_from_string()-> ymd(' -' ) });
216225 }
217226 }
218227}
219228
229+ sub intranet_js {
230+ my ( $self ) = @_ ;
231+
232+ my $user_id = C4::Context-> userenv ? C4::Context-> userenv-> {' id' } : undef ;
233+ my $canViewClaims = 0;
234+ if ( $user_id && haspermission($user_id , { plugins => ' plugins_tool' }) ) {
235+ $canViewClaims = 1;
236+ }
237+
238+ my $intranetJSadd = q^
239+ <script>
240+ $(document).ready( function() {
241+ if ( $('#patron_messages.circmessage,#circmessages.circmessage').length > 0 ) {
242+ var msgPanel = $('#patron_messages.circmessage,#circmessages.circmessage').first();
243+ if ( $('input[name="borrowernumber"]').length > 0 ) {
244+ var patron = $('input[name="borrowernumber"]').first().val();
245+ if ( patron && patron.length > 0 ) {
246+ $.ajax({
247+ 'dataType': 'json',
248+ 'type': 'GET',
249+ 'url': '/api/v1/contrib/latepaymentclaiming/late_payment_claims',
250+ 'data': { patron_id: patron, status: 'current', draw: 1 },
251+ 'success': function(result) {
252+ // console.log(result);
253+ if ( result && result.data && result.recordsTotal == 1 ) {
254+ var claimDate = result.data[0].creationdate;
255+ var level = result.data[0].level;
256+
257+ if ( ! msgPanel.hasClass("attention") ) {
258+ msgPanel.addClass("attention");
259+ }
260+
261+ var listElem;
262+ var msgPanelHead = msgPanel.find("h3:contains('Attention'),h3:contains('Achtung')");
263+ if ( msgPanelHead.length > 0 ) {
264+ listElem = msgPanelHead.next('ul');
265+ }
266+ else {
267+ msgPanel.prepend('<h3>Achtung</h3><ul></ul>');
268+ msgPanelHead = msgPanel.find("h3:contains('Attention'),h3:contains('Achtung')");
269+ listElem = msgPanelHead.next('ul');
270+ }
271+ if ( listElem && listElem.length > 0 ) {
272+ listElem.prepend('<li class="charges blocker"><span class="circ-hlt">Gebührenmahnung:</span> ' + level + '. Gebührenmahnung (angemahnt seit ' + $date(claimDate) + ').^ .
273+ ($canViewClaims ? q^ <a href="/cgi-bin/koha/plugins/run.pl?class=Koha%3A%3APlugin%3A%3ACom%3A%3ALMSCloud%3A%3ALatePaymentClaiming&method=tool&toolaction=currentClaims&status_filter=all&patron_id=' + patron + '">Zeige Mahnfall</a>^ : ' ' ) . q^ </li>');
274+ }
275+ }
276+ }
277+ });
278+ }
279+ }
280+ }
281+ });
282+ </script>
283+ ^ ;
284+ return $intranetJSadd ;
285+ }
286+
220287sub tool {
221288 my ( $self , $args ) = @_ ;
222289
@@ -346,6 +413,7 @@ sub claimInteractive {
346413 );
347414 }
348415 elsif ( exists ($result -> {actionIdList }) ) {
416+ $self -> store_data({ last_run => dt_from_string()-> ymd(' -' ) });
349417 $self -> claimHistory({ actionIdList => $result -> {actionIdList }, actionIdCount => $result -> {actionIdCount } });
350418 exit ;
351419 }
@@ -368,6 +436,7 @@ sub currentClaims {
368436 my $cgi = $self -> {cgi };
369437
370438 my $status_filter = $cgi -> param(' status_filter' ) || ' ' ;
439+ my $patron_id = $cgi -> param(' patron_id' ) || ' ' ;
371440
372441 $status_filter = ' open' if (! $status_filter );
373442 $status_filter = ' ' if ( $status_filter eq ' all' );
@@ -381,6 +450,7 @@ sub currentClaims {
381450
382451 $template -> param(
383452 status_filter => $status_filter ,
453+ patron_id => $patron_id ,
384454 action => ' list' ,
385455 branches => \@branches ,
386456 categorylist => \@categorylist
@@ -429,7 +499,6 @@ sub install {
429499 `amountoutstanding` DECIMAL(28,6) default NULL COMMENT 'Outstanding fee at the time of the history entry',
430500 `patron_selections` mediumtext DEFAULT NULL COMMENT 'Selection parameters applied to reach that level JSON format',
431501 `ban_actions` mediumtext NOT NULL COMMENT 'Ban actions performed at the level in JSON format',
432- `unban_actions` mediumtext NOT NULL COMMENT 'Unban actions performed in JSON format',
433502 `timestamp` timestamp NOT NULL
434503 DEFAULT current_timestamp() COMMENT 'The timestamp the action was performed',
435504 `manager_id` int(11) DEFAULT NULL COMMENT 'Staff member who performed the action (NULL if it was an automated action)',
@@ -451,7 +520,6 @@ sub install {
451520 `outstanding_fee_limit` DECIMAL(28,6) default NULL COMMENT 'Fee limit that needs to be reached for this level',
452521 `patron_selections` mediumtext NOT NULL COMMENT 'Selection parameters defined in JSON format',
453522 `ban_actions` mediumtext NOT NULL COMMENT 'Ban actions to perform in JSON format',
454- `unban_actions` mediumtext NOT NULL COMMENT 'Unban actions to perform in JSON format',
455523 PRIMARY KEY (`id`),
456524 UNIQUE KEY `lmsc_lpcr_uniq` (`branchcode`,`categorycode`,`level`),
457525 KEY `lmsc_lpcr_ibfk_1` (`branchcode`),
0 commit comments