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

(-)a/misc/cronjobs/overdue_notices.pl (-5 / +41 lines)
Lines 47-53 overdue_notices.pl - prepare messages to be sent to patrons for overdue items Link Here
47
47
48
=head1 SYNOPSIS
48
=head1 SYNOPSIS
49
49
50
overdue_notices.pl [ -n ] [ -library <branchcode> ] [ -library <branchcode>...] [ -max <number of days> ] [ -csv [ <filename> ] ] [ -itemscontent <field list> ]
50
overdue_notices.pl 
51
  [ -n ][ -library <branchcode> ][ -library <branchcode> ... ]
52
  [ -max <number of days> ][ -csv [<filename>] ][ -itemscontent <field list> ]
53
  [ -email <email_type> ... ]
51
54
52
 Options:
55
 Options:
53
   -help                          brief help message
56
   -help                          brief help message
Lines 60-65 overdue_notices.pl [ -n ] [ -library <branchcode> ] [ -library <branchcode>...] Link Here
60
   -itemscontent <list of fields> item information in templates
63
   -itemscontent <list of fields> item information in templates
61
   -borcat       <categorycode>   category code that must be included
64
   -borcat       <categorycode>   category code that must be included
62
   -borcatout    <categorycode>   category code that must be excluded
65
   -borcatout    <categorycode>   category code that must be excluded
66
   -email        <email_type>     type of email that will be used. Can be 'email', 'emailpro' or 'B_email'. Repeatable.
63
67
64
=head1 OPTIONS
68
=head1 OPTIONS
65
69
Lines 147-152 Choose list-all to include all overdue items in the list (limited by B<-max> set Link Here
147
151
148
use it in order to send overdues on a specific date and not Now.
152
use it in order to send overdues on a specific date and not Now.
149
153
154
=item B<-email>
155
156
Allows to specify which type of email will be used. Can be email, emailpro or B_email. Repeatable.
157
150
=back
158
=back
151
159
152
=head1 DESCRIPTION
160
=head1 DESCRIPTION
Lines 256-261 my $verbose = 0; Link Here
256
my $nomail  = 0;
264
my $nomail  = 0;
257
my $MAX     = 90;
265
my $MAX     = 90;
258
my @branchcodes; # Branch(es) passed as parameter
266
my @branchcodes; # Branch(es) passed as parameter
267
my @emails_to_use;    # Emails to use for messaging
268
my @emails;           # Emails given in command-line parameters
259
my $csvfilename;
269
my $csvfilename;
260
my $htmlfilename;
270
my $htmlfilename;
261
my $triggered = 0;
271
my $triggered = 0;
Lines 280-285 GetOptions( Link Here
280
    'date'           => \$date,
290
    'date'           => \$date,
281
    'borcat=s'       => \@myborcat,
291
    'borcat=s'       => \@myborcat,
282
    'borcatout=s'    => \@myborcatout,
292
    'borcatout=s'    => \@myborcatout,
293
    'email=s'        => \@emails,
283
) or pod2usage(2);
294
) or pod2usage(2);
284
pod2usage(1) if $help;
295
pod2usage(1) if $help;
285
pod2usage( -verbose => 2 ) if $man;
296
pod2usage( -verbose => 2 ) if $man;
Lines 478-483 END_SQL Link Here
478
                    ) = $sth->fetchrow )
489
                    ) = $sth->fetchrow )
479
            {
490
            {
480
                $verbose and warn "borrower $firstname, $lastname ($borrowernumber) has items triggering level $i.";
491
                $verbose and warn "borrower $firstname, $lastname ($borrowernumber) has items triggering level $i.";
492
                @emails_to_use = ();
493
                if ( !$nomail) {
494
                    if ( @emails ) {
495
                        my $memberinfos = C4::Members::GetMember(borrowernumber => $borrowernumber);
496
                        foreach (@emails) {
497
                            push @emails_to_use, $memberinfos->{$_}
498
                              if ($memberinfos->{$_} ne '');
499
                        }
500
                    }
501
                    else {
502
                        $email =
503
                          C4::Members::GetFirstValidEmailAddress($borrowernumber);
504
                        push @emails_to_use, $email if ($email ne '');
505
                    }
506
                }
507
508
                my $letter = C4::Letters::getletter( 'circulation', $overdue_rules->{"letter$i"}, $branchcode );
509
510
                unless ($letter) {
511
                    $verbose and warn "Message '$overdue_rules->{letter$i}' content not found";
512
    
513
                    # might as well skip while PERIOD, no other borrowers are going to work.
514
                    # FIXME : Does this mean a letter must be defined in order to trigger a debar ?
515
                    next PERIOD;
516
                }
481
    
517
    
482
                if ( $overdue_rules->{"debarred$i"} ) {
518
                if ( $overdue_rules->{"debarred$i"} ) {
483
    
519
    
Lines 495-501 END_SQL Link Here
495
                my $j = 0;
531
                my $j = 0;
496
                my $exceededPrintNoticesMaxLines = 0;
532
                my $exceededPrintNoticesMaxLines = 0;
497
                while ( my $item_info = $sth2->fetchrow_hashref() ) {
533
                while ( my $item_info = $sth2->fetchrow_hashref() ) {
498
                    if ( ( !$email || $nomail ) && $PrintNoticesMaxLines && $j >= $PrintNoticesMaxLines ) {
534
                    if ( ( scalar(@emails_to_use) == 0 || $nomail ) && $PrintNoticesMaxLines && $j >= $PrintNoticesMaxLines ) {
499
                      $exceededPrintNoticesMaxLines = 1;
535
                      $exceededPrintNoticesMaxLines = 1;
500
                      last;
536
                      last;
501
                    }
537
                    }
Lines 507-513 END_SQL Link Here
507
                }
543
                }
508
                $sth2->finish;
544
                $sth2->finish;
509
545
510
                my $letter = parse_letter(
546
                $letter = parse_letter(
511
                    {   letter_code     => $overdue_rules->{"letter$i"},
547
                    {   letter_code     => $overdue_rules->{"letter$i"},
512
                        letter          => $letter_template,
548
                        letter          => $letter_template,
513
                        borrowernumber  => $borrowernumber,
549
                        borrowernumber  => $borrowernumber,
Lines 558-569 END_SQL Link Here
558
                        }
594
                        }
559
                      );
595
                      );
560
                } else {
596
                } else {
561
                    if ($email) {
597
                    if (scalar(@emails_to_use) > 0 ) {
562
                        C4::Letters::EnqueueLetter(
598
                        C4::Letters::EnqueueLetter(
563
                            {   letter                 => $letter,
599
                            {   letter                 => $letter,
564
                                borrowernumber         => $borrowernumber,
600
                                borrowernumber         => $borrowernumber,
565
                                message_transport_type => 'email',
601
                                message_transport_type => 'email',
566
                                from_address           => $admin_email_address,
602
                                from_address           => $admin_email_address,
603
                                to_address             => join(',', @emails_to_use),
567
                            }
604
                            }
568
                        );
605
                        );
569
                    } else {
606
                    } else {
570
- 

Return to bug 6835