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

(-)a/misc/cronjobs/overdue_notices.pl (-12 / +11 lines)
Lines 447-463 if(@myborcatout){ Link Here
447
## collect everything in meaningful hashes
447
## collect everything in meaningful hashes
448
##
448
##
449
my $hrBorrowers = $dbh->selectall_hashref($sqlBorrowers, 'borrowernumber');
449
my $hrBorrowers = $dbh->selectall_hashref($sqlBorrowers, 'borrowernumber');
450
VERBOSE("$sqlBorrowers\nReturned " . (scalar keys $hrBorrowers) . " borrowers with issues.");
450
VERBOSE("$sqlBorrowers\nReturned " . (scalar keys %$hrBorrowers) . " borrowers with issues.");
451
my $hrOverdueIssues = $dbh->selectall_hashref($sqlIssues, 'itemnumber' );
451
my $hrOverdueIssues = $dbh->selectall_hashref($sqlIssues, 'itemnumber' );
452
VERBOSE("$sqlIssues\nReturned " . (scalar keys $hrOverdueIssues) . " overdue issues.");
452
VERBOSE("$sqlIssues\nReturned " . (scalar keys %$hrOverdueIssues) . " overdue issues.");
453
my $arRules = $dbh->selectall_arrayref($sqlRules, { Slice => {} } );
453
my $arRules = $dbh->selectall_arrayref($sqlRules, { Slice => {} } );
454
VERBOSE("\nRule order:\nId\tBranch\tCat\tItem\tHold\tDelay\tDebarred\tLetter");
454
VERBOSE("\nRule order:\nId\tBranch\tCat\tItem\tHold\tDelay\tDebarred\tLetter");
455
foreach my $rule (@$arRules){
455
foreach my $rule (@$arRules){
456
    $rule->{mtt} = $dbh->selectcol_arrayref($sqlMTT, undef, $rule->{overduerules_id});
456
    $rule->{mtt} = $dbh->selectcol_arrayref($sqlMTT, undef, $rule->{overduerules_id});
457
    VERBOSE("$rule->{id}\t$rule->{branchcode}\t$rule->{categorycode}\t$rule->{itemtype}\t$rule->{onhold}\t$rule->{delay}\t$rule->{debarred}\t$rule->{letter}");
457
    VERBOSE("$rule->{overduerules_id}\t$rule->{branchcode}\t$rule->{categorycode}\t$rule->{itemtype}\t$rule->{onhold}\t$rule->{delay}\t$rule->{debarred}\t$rule->{letter}");
458
}
458
}
459
my $hrReserves = $dbh->selectall_hashref($sqlReserves, 'biblionumber');
459
my $hrReserves = $dbh->selectall_hashref($sqlReserves, 'biblionumber');
460
VERBOSE("$sqlReserves\nReturned " . (scalar keys $hrReserves) . " unique reserves.");
460
VERBOSE("$sqlReserves\nReturned " . (scalar keys %$hrReserves) . " unique reserves.");
461
my %hBranches;
461
my %hBranches;
462
my %hChunks; # messages to send once per branch to the administrator
462
my %hChunks; # messages to send once per branch to the administrator
463
463
Lines 467-473 my %hChunks; # messages to send once per branch to the administrator Link Here
467
##
467
##
468
468
469
my $whichItemType = C4::Context->preference('item-level_itypes') ? 'itype' : 'itemtype';
469
my $whichItemType = C4::Context->preference('item-level_itypes') ? 'itype' : 'itemtype';
470
foreach my $in (keys $hrOverdueIssues){
470
foreach my $in (keys %$hrOverdueIssues){
471
    my $issue = $hrOverdueIssues->{$in};
471
    my $issue = $hrOverdueIssues->{$in};
472
    VERBOSE("Processing issue $in.  branchcode: $issue->{branchcode}, borrower: $issue->{borrowernumber}.");
472
    VERBOSE("Processing issue $in.  branchcode: $issue->{branchcode}, borrower: $issue->{borrowernumber}.");
473
    foreach my $rule(@$arRules){
473
    foreach my $rule(@$arRules){
Lines 499-505 foreach my $in (keys $hrOverdueIssues){ Link Here
499
499
500
            # we found the best rule to apply, let's store the branchcode/lettter combo into the borrower
500
            # we found the best rule to apply, let's store the branchcode/lettter combo into the borrower
501
            my $arItems = $hrBorrowers->{$issue->{borrowernumber}}{NOTICES}{$issue->{branchcode}}{$rule->{letter}}{ITEMS} ||= [];
501
            my $arItems = $hrBorrowers->{$issue->{borrowernumber}}{NOTICES}{$issue->{branchcode}}{$rule->{letter}}{ITEMS} ||= [];
502
            push $arItems, $issue->{itemnumber};
502
            push @$arItems, $issue->{itemnumber};
503
            # And note that we union the transport types, so IF the user set two similar alerts (except for delay and mtt), then
503
            # And note that we union the transport types, so IF the user set two similar alerts (except for delay and mtt), then
504
            # only one message will be sent to each of the transport specified by both rules together
504
            # only one message will be sent to each of the transport specified by both rules together
505
            my $hrMtts = $hrBorrowers->{$issue->{borrowernumber}}{NOTICES}{$issue->{branchcode}}{$rule->{letter}}{MTTS} ||= {};
505
            my $hrMtts = $hrBorrowers->{$issue->{borrowernumber}}{NOTICES}{$issue->{branchcode}}{$rule->{letter}}{MTTS} ||= {};
Lines 527-539 foreach my $in (keys $hrOverdueIssues){ Link Here
527
## Main loop
527
## Main loop
528
##
528
##
529
VERBOSE("Main loop.");
529
VERBOSE("Main loop.");
530
foreach my $borrowernumber(keys $hrBorrowers){
530
foreach my $borrowernumber(keys %$hrBorrowers){
531
    if(!defined $hrBorrowers->{$borrowernumber}{NOTICES}){
531
    if(!defined $hrBorrowers->{$borrowernumber}{NOTICES}){
532
        VERBOSE("User $hrBorrowers->{$borrowernumber}{surname} has no notice.");
532
        VERBOSE("User $hrBorrowers->{$borrowernumber}{surname} has no notice.");
533
        next;
533
        next;
534
    }
534
    }
535
    # for each branch
535
    # for each branch
536
    foreach my $branchcode (keys $hrBorrowers->{$borrowernumber}{NOTICES}){
536
    foreach my $branchcode (keys %{$hrBorrowers->{$borrowernumber}{NOTICES}}){
537
        my $admin_email_address = $hBranches{$branchcode}{'branchemail'} || C4::Context->preference('KohaAdminEmailAddress');
537
        my $admin_email_address = $hBranches{$branchcode}{'branchemail'} || C4::Context->preference('KohaAdminEmailAddress');
538
        if($hBranches{$branchcode}{CALENDAR}->is_holiday($date_to_run)){
538
        if($hBranches{$branchcode}{CALENDAR}->is_holiday($date_to_run)){
539
            VERBOSE("$date_to_run is a holiday at branch $branchcode");
539
            VERBOSE("$date_to_run is a holiday at branch $branchcode");
Lines 541-547 foreach my $borrowernumber(keys $hrBorrowers){ Link Here
541
        }
541
        }
542
542
543
        # for each letter
543
        # for each letter
544
        foreach my $lettercode (keys $hrBorrowers->{$borrowernumber}{NOTICES}{$branchcode}){
544
        foreach my $lettercode (keys %{$hrBorrowers->{$borrowernumber}{NOTICES}{$branchcode}}){
545
            @emails_to_use = ();
545
            @emails_to_use = ();
546
            my $notice_email = C4::Members::GetNoticeEmailAddress($borrowernumber);
546
            my $notice_email = C4::Members::GetNoticeEmailAddress($borrowernumber);
547
            unless ($nomail) {
547
            unless ($nomail) {
Lines 581-587 foreach my $borrowernumber(keys $hrBorrowers){ Link Here
581
            }
581
            }
582
582
583
            # the transport types (email, sms...)
583
            # the transport types (email, sms...)
584
            my @message_transport_types = keys $hrBorrowers->{$borrowernumber}{NOTICES}{$branchcode}{$lettercode}{MTTS};
584
            my @message_transport_types = keys %{$hrBorrowers->{$borrowernumber}{NOTICES}{$branchcode}{$lettercode}{MTTS}};
585
            my $print_sent = 0; # A print notice is not yet sent for this patron
585
            my $print_sent = 0; # A print notice is not yet sent for this patron
586
            for my $mtt ( @message_transport_types ) {
586
            for my $mtt ( @message_transport_types ) {
587
                my $letter = parse_letter( {
587
                my $letter = parse_letter( {
Lines 612-618 foreach my $borrowernumber(keys $hrBorrowers){ Link Here
612
612
613
                if ($nomail) {
613
                if ($nomail) {
614
                    $hChunks{$admin_email_address} ||= [];
614
                    $hChunks{$admin_email_address} ||= [];
615
                    push $hChunks{$admin_email_address}, prepare_letter_for_printing( {
615
                    push @{$hChunks{$admin_email_address}}, prepare_letter_for_printing( {
616
                        letter         => $letter,
616
                        letter         => $letter,
617
                        borrowernumber => $borrowernumber,
617
                        borrowernumber => $borrowernumber,
618
                        firstname      => $hrBorrowers->{$borrowernumber}->{'firstname'},
618
                        firstname      => $hrBorrowers->{$borrowernumber}->{'firstname'},
619
- 

Return to bug 12772