View | Details | Raw Unified | Return to bug 31487
Collapse All | Expand All

(-)a/misc/cronjobs/longoverdue.pl (-3 / +84 lines)
Lines 34-39 use Pod::Usage qw( pod2usage ); Link Here
34
use C4::Circulation qw( LostItem MarkIssueReturned );
34
use C4::Circulation qw( LostItem MarkIssueReturned );
35
use C4::Context;
35
use C4::Context;
36
use C4::Log qw( cronlogaction );
36
use C4::Log qw( cronlogaction );
37
use C4::Letters;
37
use Koha::ItemTypes;
38
use Koha::ItemTypes;
38
use Koha::Patron::Categories;
39
use Koha::Patron::Categories;
39
use Koha::Patrons;
40
use Koha::Patrons;
Lines 52-57 my $man=0; Link Here
52
my $list_categories = 0;
53
my $list_categories = 0;
53
my $list_itemtypes = 0;
54
my $list_itemtypes = 0;
54
my @skip_lost_values;
55
my @skip_lost_values;
56
my ($mail, $code, $branchcode, $letter_template);
55
57
56
GetOptions(
58
GetOptions(
57
    'l|lost=s%'         => \$lost,
59
    'l|lost=s%'         => \$lost,
Lines 70-75 GetOptions( Link Here
70
    'skip-itemtype=s'   => $skip_itemtype,
72
    'skip-itemtype=s'   => $skip_itemtype,
71
    'list-itemtypes'    => \$list_itemtypes,
73
    'list-itemtypes'    => \$list_itemtypes,
72
    'skip-lost-value=s' => \@skip_lost_values,
74
    'skip-lost-value=s' => \@skip_lost_values,
75
    'mail'              => \$mail,
76
    'code=s'            => \$code,
77
    'branchcode=s'      => \$branchcode,
73
);
78
);
74
79
75
if ( $man ) {
80
if ( $man ) {
Lines 213-218 Display short help message an exit. Link Here
213
218
214
Display entire manual and exit.
219
Display entire manual and exit.
215
220
221
=item B<--mail >
222
223
Send a mail based on configured letter template.
224
225
=item B<--code >
226
227
Get notice template code for longoverdue mail.
228
229
=item B<--branchcode >
230
231
Specify particular branchcode for longoverdue mail.
232
216
=back
233
=back
217
234
218
=cut
235
=cut
Lines 275-282 if ( ! defined($charge) ) { Link Here
275
}
292
}
276
unless ($confirm) {
293
unless ($confirm) {
277
    $verbose = 1;     # If you're not running it for real, then the whole point is the print output.
294
    $verbose = 1;     # If you're not running it for real, then the whole point is the print output.
278
    print "### TEST MODE -- NO ACTIONS TAKEN ###\n";
295
 }
279
}
280
296
281
cronlogaction();
297
cronlogaction();
282
298
Lines 368-373 if ( @$skip_itemtype ) { Link Here
368
    %itemtype_to_process = ( %itemtype_to_process, map { $_ => 0 } @$skip_itemtype );
384
    %itemtype_to_process = ( %itemtype_to_process, map { $_ => 0 } @$skip_itemtype );
369
}
385
}
370
386
387
if ( $mail && !$code || $mail && !$branchcode) {
388
    print "Argument -code or -branchcode missing for mail option\n";
389
} else {
390
    $letter_template = Koha::Notice::Templates->find_effective_template(
391
            {
392
                module     => 'circulation',
393
                code       => $code,
394
                branchcode => $branchcode,
395
            }
396
        );        
397
}
398
371
my $filter_itemtypes = ( scalar @$itemtype || scalar @$skip_itemtype );
399
my $filter_itemtypes = ( scalar @$itemtype || scalar @$skip_itemtype );
372
400
373
my $count;
401
my $count;
Lines 379-384 my $i = 0; Link Here
379
#         We need a better way to handle this.
407
#         We need a better way to handle this.
380
#
408
#
381
my $sth_items = longoverdue_sth({ skip_lost_values => \@skip_lost_values });
409
my $sth_items = longoverdue_sth({ skip_lost_values => \@skip_lost_values });
410
my $reminders_email;
411
my $letter;
412
my $admin_email_address;
382
413
383
foreach my $startrange (sort keys %$lost) {
414
foreach my $startrange (sort keys %$lost) {
384
    if( my $lostvalue = $lost->{$startrange} ) {
415
    if( my $lostvalue = $lost->{$startrange} ) {
Lines 410-415 foreach my $startrange (sort keys %$lost) { Link Here
410
                    MarkIssueReturned($row->{borrowernumber},$row->{itemnumber},undef,$patron->privacy)
441
                    MarkIssueReturned($row->{borrowernumber},$row->{itemnumber},undef,$patron->privacy)
411
                }
442
                }
412
            }
443
            }
444
            if ($letter_template) {
445
446
                $letter = $letter_template->unblessed;
447
                my $library = Koha::Libraries->find($branchcode);
448
                $admin_email_address = $library->from_email_address;
449
450
                my $borrowernumber = $row->{borrowernumber};
451
                my $itemnumber     = $row->{itemnumber};
452
                my $patron         = Koha::Patrons->find($borrowernumber);
453
                my $notice_email   = $patron->email;
454
455
                if ($notice_email) {
456
                    $reminders_email->{$borrowernumber}->{'email'} =
457
                      $notice_email;
458
                    push
459
                      @{ $reminders_email->{$borrowernumber}->{'itemnumbers'} },
460
                      $itemnumber;
461
                }
462
            } elsif ($mail) {
463
                print "\nLetter template not found\n";
464
            }
465
413
            $count++;
466
            $count++;
414
        }
467
        }
415
        push @report, {
468
        push @report, {
Lines 443-445 if (!$quiet){ Link Here
443
    summarize (\@report, 1);
496
    summarize (\@report, 1);
444
    print "\nTOTAL: $total items\n";
497
    print "\nTOTAL: $total items\n";
445
}
498
}
446
- 
499
500
if ($reminders_email) {
501
    foreach ( keys %$reminders_email ) {
502
        my $items_due =
503
          join( ";", @{ %$reminders_email{$_}->{'itemnumbers'} } );
504
505
        C4::Letters::EnqueueLetter(
506
            {
507
                letter                 => $letter,
508
                borrowernumber         => $_,
509
                message_transport_type => 'email',
510
                from_address           => $admin_email_address,
511
                to_address             => %$reminders_email{$_}->{'email'},
512
                items                  => $items_due,
513
            }
514
        );
515
516
        printf(
517
"\nEnqueue mail to %s - borrowernumber %s for longoverdue on item(s): %s\n",
518
            %$reminders_email{$_}->{'email'},
519
            $_, $items_due
520
        );
521
    }
522
}
523
else {
524
    if ($mail) {
525
        print "\nNo mail add to enqueue list\n";
526
    }
527
}

Return to bug 31487