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