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

(-)a/misc/cronjobs/longoverdue.pl (-4 / +86 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 54-59 my $man=0; Link Here
54
my $list_categories = 0;
55
my $list_categories = 0;
55
my $list_itemtypes = 0;
56
my $list_itemtypes = 0;
56
my @skip_lost_values;
57
my @skip_lost_values;
58
my ($mail, $code, $branchcode, $letter_template);
57
59
58
my $command_line_options = join(" ",@ARGV);
60
my $command_line_options = join(" ",@ARGV);
59
61
Lines 76-81 GetOptions( Link Here
76
    'skip-itemtype=s'   => $skip_itemtype,
78
    'skip-itemtype=s'   => $skip_itemtype,
77
    'list-itemtypes'    => \$list_itemtypes,
79
    'list-itemtypes'    => \$list_itemtypes,
78
    'skip-lost-value=s' => \@skip_lost_values,
80
    'skip-lost-value=s' => \@skip_lost_values,
81
    'mail'              => \$mail,
82
    'code=s'            => \$code,
83
    'branchcode=s'      => \$branchcode,
79
);
84
);
80
85
81
if ( $man ) {
86
if ( $man ) {
Lines 240-245 Display short help message an exit. Link Here
240
245
241
Display entire manual and exit.
246
Display entire manual and exit.
242
247
248
=item B<--mail >
249
250
Send a mail based on configured letter template.
251
252
=item B<--code >
253
254
Get notice template code for longoverdue mail.
255
256
=item B<--branchcode >
257
258
Specify particular branchcode for longoverdue mail.
259
243
=back
260
=back
244
261
245
=cut
262
=cut
Lines 317-324 if ( scalar @$skip_borrower_category == 0 ) { Link Here
317
334
318
unless ($confirm) {
335
unless ($confirm) {
319
    $verbose = 1;     # If you're not running it for real, then the whole point is the print output.
336
    $verbose = 1;     # If you're not running it for real, then the whole point is the print output.
320
    print "### TEST MODE -- NO ACTIONS TAKEN ###\n";
337
        print "### TEST MODE -- NO ACTIONS TAKEN ###\n";
321
}
338
 }
322
339
323
cronlogaction({ info => $command_line_options });
340
cronlogaction({ info => $command_line_options });
324
341
Lines 441-446 if ( @$skip_itemtype ) { Link Here
441
    %itemtype_to_process = ( %itemtype_to_process, map { $_ => 0 } @$skip_itemtype );
458
    %itemtype_to_process = ( %itemtype_to_process, map { $_ => 0 } @$skip_itemtype );
442
}
459
}
443
460
461
if ( $mail && !$code || $mail && !$branchcode) {
462
    print "Argument -code or -branchcode missing for mail option\n";
463
} else {
464
    $letter_template = Koha::Notice::Templates->find_effective_template(
465
            {
466
                module     => 'circulation',
467
                code       => $code,
468
                branchcode => $branchcode,
469
            }
470
        );
471
}
472
444
my $filter_itemtypes = ( scalar @$itemtype || scalar @$skip_itemtype );
473
my $filter_itemtypes = ( scalar @$itemtype || scalar @$skip_itemtype );
445
474
446
my $count;
475
my $count;
Lines 452-457 my $i = 0; Link Here
452
#         We need a better way to handle this.
481
#         We need a better way to handle this.
453
#
482
#
454
my $sth_items = longoverdue_sth({ skip_lost_values => \@skip_lost_values });
483
my $sth_items = longoverdue_sth({ skip_lost_values => \@skip_lost_values });
484
my $reminders_email;
485
my $letter;
486
my $admin_email_address;
455
487
456
foreach my $startrange (sort keys %$lost) {
488
foreach my $startrange (sort keys %$lost) {
457
    if( my $lostvalue = $lost->{$startrange} ) {
489
    if( my $lostvalue = $lost->{$startrange} ) {
Lines 499-504 foreach my $startrange (sort keys %$lost) { Link Here
499
                    MarkIssueReturned($row->{borrowernumber},$row->{itemnumber},undef,$patron->privacy)
531
                    MarkIssueReturned($row->{borrowernumber},$row->{itemnumber},undef,$patron->privacy)
500
                }
532
                }
501
            }
533
            }
534
            if ($letter_template) {
535
536
                $letter = $letter_template->unblessed;
537
                my $library = Koha::Libraries->find($branchcode);
538
                $admin_email_address = $library->from_email_address;
539
540
                my $borrowernumber = $row->{borrowernumber};
541
                my $itemnumber     = $row->{itemnumber};
542
                my $patron         = Koha::Patrons->find($borrowernumber);
543
                my $notice_email   = $patron->email;
544
545
                if ($notice_email) {
546
                    $reminders_email->{$borrowernumber}->{'email'} =
547
                      $notice_email;
548
                    push
549
                      @{ $reminders_email->{$borrowernumber}->{'itemnumbers'} },
550
                      $itemnumber;
551
                }
552
            } elsif ($mail) {
553
                print "\nLetter template not found\n";
554
            }
555
502
            $count++;
556
            $count++;
503
        }
557
        }
504
        push @report, {
558
        push @report, {
Lines 533-536 if (!$quiet){ Link Here
533
    print "\nTOTAL: $total items\n";
587
    print "\nTOTAL: $total items\n";
534
}
588
}
535
589
536
cronlogaction({ action => 'End', info => "COMPLETED" });
590
if ($reminders_email) {
591
    foreach ( keys %$reminders_email ) {
592
        my $items_due =
593
          join( ";", @{ %$reminders_email{$_}->{'itemnumbers'} } );
594
595
        C4::Letters::EnqueueLetter(
596
            {
597
                letter                 => $letter,
598
                borrowernumber         => $_,
599
                message_transport_type => 'email',
600
                from_address           => $admin_email_address,
601
                to_address             => %$reminders_email{$_}->{'email'},
602
                items                  => $items_due,
603
            }
604
        );
605
606
        printf(
607
"\nEnqueue mail to %s - borrowernumber %s for longoverdue on item(s): %s\n",
608
            %$reminders_email{$_}->{'email'},
609
            $_, $items_due
610
        );
611
    }
612
}
613
else {
614
    if ($mail) {
615
        print "\nNo mail add to enqueue list\n";
616
    }
617
}
618
619
cronlogaction({ action => 'End', info => "COMPLETED" });
537
- 

Return to bug 31487