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

(-)a/misc/cronjobs/longoverdue.pl (-3 / +85 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
        print "### TEST MODE -- NO ACTIONS TAKEN ###\n";	
279
}
296
 }
280
297
281
cronlogaction();
298
cronlogaction();
282
299
Lines 368-373 if ( @$skip_itemtype ) { Link Here
368
    %itemtype_to_process = ( %itemtype_to_process, map { $_ => 0 } @$skip_itemtype );
385
    %itemtype_to_process = ( %itemtype_to_process, map { $_ => 0 } @$skip_itemtype );
369
}
386
}
370
387
388
if ( $mail && !$code || $mail && !$branchcode) {
389
    print "Argument -code or -branchcode missing for mail option\n";
390
} else {
391
    $letter_template = Koha::Notice::Templates->find_effective_template(
392
            {
393
                module     => 'circulation',
394
                code       => $code,
395
                branchcode => $branchcode,
396
            }
397
        );        
398
}
399
371
my $filter_itemtypes = ( scalar @$itemtype || scalar @$skip_itemtype );
400
my $filter_itemtypes = ( scalar @$itemtype || scalar @$skip_itemtype );
372
401
373
my $count;
402
my $count;
Lines 379-384 my $i = 0; Link Here
379
#         We need a better way to handle this.
408
#         We need a better way to handle this.
380
#
409
#
381
my $sth_items = longoverdue_sth({ skip_lost_values => \@skip_lost_values });
410
my $sth_items = longoverdue_sth({ skip_lost_values => \@skip_lost_values });
411
my $reminders_email;
412
my $letter;
413
my $admin_email_address;
382
414
383
foreach my $startrange (sort keys %$lost) {
415
foreach my $startrange (sort keys %$lost) {
384
    if( my $lostvalue = $lost->{$startrange} ) {
416
    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)
442
                    MarkIssueReturned($row->{borrowernumber},$row->{itemnumber},undef,$patron->privacy)
411
                }
443
                }
412
            }
444
            }
445
            if ($letter_template) {
446
447
                $letter = $letter_template->unblessed;
448
                my $library = Koha::Libraries->find($branchcode);
449
                $admin_email_address = $library->from_email_address;
450
451
                my $borrowernumber = $row->{borrowernumber};
452
                my $itemnumber     = $row->{itemnumber};
453
                my $patron         = Koha::Patrons->find($borrowernumber);
454
                my $notice_email   = $patron->email;
455
456
                if ($notice_email) {
457
                    $reminders_email->{$borrowernumber}->{'email'} =
458
                      $notice_email;
459
                    push
460
                      @{ $reminders_email->{$borrowernumber}->{'itemnumbers'} },
461
                      $itemnumber;
462
                }
463
            } elsif ($mail) {
464
                print "\nLetter template not found\n";
465
            }
466
413
            $count++;
467
            $count++;
414
        }
468
        }
415
        push @report, {
469
        push @report, {
Lines 443-445 if (!$quiet){ Link Here
443
    summarize (\@report, 1);
497
    summarize (\@report, 1);
444
    print "\nTOTAL: $total items\n";
498
    print "\nTOTAL: $total items\n";
445
}
499
}
446
- 
500
501
if ($reminders_email) {
502
    foreach ( keys %$reminders_email ) {
503
        my $items_due =
504
          join( ";", @{ %$reminders_email{$_}->{'itemnumbers'} } );
505
506
        C4::Letters::EnqueueLetter(
507
            {
508
                letter                 => $letter,
509
                borrowernumber         => $_,
510
                message_transport_type => 'email',
511
                from_address           => $admin_email_address,
512
                to_address             => %$reminders_email{$_}->{'email'},
513
                items                  => $items_due,
514
            }
515
        );
516
517
        printf(
518
"\nEnqueue mail to %s - borrowernumber %s for longoverdue on item(s): %s\n",
519
            %$reminders_email{$_}->{'email'},
520
            $_, $items_due
521
        );
522
    }
523
}
524
else {
525
    if ($mail) {
526
        print "\nNo mail add to enqueue list\n";
527
    }
528
}

Return to bug 31487