Lines 39-45
use C4::Context;
Link Here
|
39 |
use C4::Dates qw/format_date/; |
39 |
use C4::Dates qw/format_date/; |
40 |
use C4::Debug; |
40 |
use C4::Debug; |
41 |
use C4::Letters; |
41 |
use C4::Letters; |
42 |
use C4::Overdues qw(GetFine); |
42 |
use C4::Overdues qw(GetFine GetOverdueMessageTransportTypes); |
43 |
use C4::Budgets qw(GetCurrency); |
43 |
use C4::Budgets qw(GetCurrency); |
44 |
|
44 |
|
45 |
use Koha::Borrower::Debarments qw(AddUniqueDebarment); |
45 |
use Koha::Borrower::Debarments qw(AddUniqueDebarment); |
Lines 435-440
END_SQL
Link Here
|
435 |
# my $outfile = 'overdues_' . ( $mybranch || $branchcode || 'default' ); |
435 |
# my $outfile = 'overdues_' . ( $mybranch || $branchcode || 'default' ); |
436 |
while ( my $overdue_rules = $rqoverduerules->fetchrow_hashref ) { |
436 |
while ( my $overdue_rules = $rqoverduerules->fetchrow_hashref ) { |
437 |
PERIOD: foreach my $i ( 1 .. 3 ) { |
437 |
PERIOD: foreach my $i ( 1 .. 3 ) { |
|
|
438 |
my $print_sent = 0; # We never sent a print notice |
438 |
|
439 |
|
439 |
$verbose and warn "branch '$branchcode', pass $i\n"; |
440 |
$verbose and warn "branch '$branchcode', pass $i\n"; |
440 |
my $mindays = $overdue_rules->{"delay$i"}; # the notice will be sent after mindays days (grace period) |
441 |
my $mindays = $overdue_rules->{"delay$i"}; # the notice will be sent after mindays days (grace period) |
Lines 456-462
END_SQL
Link Here
|
456 |
# <date> <itemcount> <firstname> <lastname> <address1> <address2> <address3> <city> <postcode> <country> |
457 |
# <date> <itemcount> <firstname> <lastname> <address1> <address2> <address3> <city> <postcode> <country> |
457 |
|
458 |
|
458 |
my $borrower_sql = <<'END_SQL'; |
459 |
my $borrower_sql = <<'END_SQL'; |
459 |
SELECT distinct(issues.borrowernumber), firstname, surname, address, address2, city, zipcode, country, email, emailpro, B_email |
460 |
SELECT distinct(issues.borrowernumber), firstname, surname, address, address2, city, zipcode, country, email, emailpro, B_email, smsalertnumber |
460 |
FROM issues,borrowers,categories |
461 |
FROM issues,borrowers,categories |
461 |
WHERE issues.borrowernumber=borrowers.borrowernumber |
462 |
WHERE issues.borrowernumber=borrowers.borrowernumber |
462 |
AND borrowers.categorycode=categories.categorycode |
463 |
AND borrowers.categorycode=categories.categorycode |
Lines 552-614
END_SQL
Link Here
|
552 |
} |
553 |
} |
553 |
$sth2->finish; |
554 |
$sth2->finish; |
554 |
|
555 |
|
555 |
$letter = parse_letter( |
556 |
my @message_transport_types = @{ GetOverdueMessageTransportTypes( $branchcode, $overdue_rules->{categorycode}, $i) }; |
556 |
{ letter_code => $overdue_rules->{"letter$i"}, |
557 |
@message_transport_types = @{ GetOverdueMessageTransportTypes( q{}, $overdue_rules->{categorycode}, $i) } |
557 |
borrowernumber => $borrowernumber, |
558 |
unless @message_transport_types; |
558 |
branchcode => $branchcode, |
559 |
|
559 |
items => \@items, |
560 |
for my $mtt ( @message_transport_types ) { |
560 |
substitute => { # this appears to be a hack to overcome incomplete features in this code. |
561 |
|
561 |
bib => $branch_details->{'branchname'}, # maybe 'bib' is a typo for 'lib<rary>'? |
562 |
my $letter = parse_letter( |
562 |
'items.content' => $titles, |
563 |
{ letter_code => $overdue_rules->{"letter$i"}, |
563 |
'count' => $itemcount, |
564 |
borrowernumber => $borrowernumber, |
564 |
} |
565 |
branchcode => $branchcode, |
|
|
566 |
items => \@items, |
567 |
substitute => { # this appears to be a hack to overcome incomplete features in this code. |
568 |
bib => $branch_details->{'branchname'}, # maybe 'bib' is a typo for 'lib<rary>'? |
569 |
'items.content' => $titles, |
570 |
'count' => $itemcount, |
571 |
}, |
572 |
message_transport_type => $mtt, |
573 |
} |
574 |
); |
575 |
unless ($letter) { |
576 |
$verbose and warn "Message '$overdue_rules->{letter$i}' content not found"; |
577 |
|
578 |
# might as well skip while PERIOD, no other borrowers are going to work. |
579 |
# FIXME : Does this mean a letter must be defined in order to trigger a debar ? |
580 |
next PERIOD; |
565 |
} |
581 |
} |
566 |
); |
|
|
567 |
unless ($letter) { |
568 |
$verbose and warn "Message '$overdue_rules->{letter$i}' content not found"; |
569 |
|
582 |
|
570 |
# might as well skip while PERIOD, no other borrowers are going to work. |
583 |
if ( $exceededPrintNoticesMaxLines ) { |
571 |
# FIXME : Does this mean a letter must be defined in order to trigger a debar ? |
584 |
$letter->{'content'} .= "List too long for form; please check your account online for a complete list of your overdue items."; |
572 |
next PERIOD; |
585 |
} |
573 |
} |
|
|
574 |
|
575 |
if ( $exceededPrintNoticesMaxLines ) { |
576 |
$letter->{'content'} .= "List too long for form; please check your account online for a complete list of your overdue items."; |
577 |
} |
578 |
|
586 |
|
579 |
my @misses = grep { /./ } map { /^([^>]*)[>]+/; ( $1 || '' ); } split /\</, $letter->{'content'}; |
587 |
my @misses = grep { /./ } map { /^([^>]*)[>]+/; ( $1 || '' ); } split /\</, $letter->{'content'}; |
580 |
if (@misses) { |
588 |
if (@misses) { |
581 |
$verbose and warn "The following terms were not matched and replaced: \n\t" . join "\n\t", @misses; |
589 |
$verbose and warn "The following terms were not matched and replaced: \n\t" . join "\n\t", @misses; |
582 |
} |
590 |
} |
583 |
|
591 |
|
584 |
if ( !$nomail && scalar @emails_to_use ) { |
592 |
if ($nomail) { |
585 |
C4::Letters::EnqueueLetter( |
593 |
push @output_chunks, |
586 |
{ letter => $letter, |
594 |
prepare_letter_for_printing( |
587 |
borrowernumber => $borrowernumber, |
595 |
{ letter => $letter, |
588 |
message_transport_type => 'email', |
596 |
borrowernumber => $borrowernumber, |
589 |
from_address => $admin_email_address, |
597 |
firstname => $data->{'firstname'}, |
590 |
to_address => join(',', @emails_to_use), |
598 |
lastname => $data->{'surname'}, |
|
|
599 |
address1 => $data->{'address'}, |
600 |
address2 => $data->{'address2'}, |
601 |
city => $data->{'city'}, |
602 |
postcode => $data->{'zipcode'}, |
603 |
country => $data->{'country'}, |
604 |
email => $notice_email, |
605 |
itemcount => $itemcount, |
606 |
titles => $titles, |
607 |
outputformat => defined $csvfilename ? 'csv' : defined $htmlfilename ? 'html' : '', |
608 |
} |
609 |
); |
610 |
} else { |
611 |
if ( ($mtt eq 'email' and not scalar @emails_to_use) or ($mtt eq 'sms' and not $data->{smsalertnumber}) ) { |
612 |
# email or sms is requested but not exist, do a print. |
613 |
$mtt = 'print'; |
591 |
} |
614 |
} |
592 |
); |
615 |
unless ( $mtt eq 'print' and $print_sent == 1 ) { |
593 |
} else { |
616 |
# Just sent a print if not already done. |
594 |
# if not sent by email then print |
617 |
C4::Letters::EnqueueLetter( |
595 |
push @output_chunks, |
618 |
{ letter => $letter, |
596 |
prepare_letter_for_printing( |
619 |
borrowernumber => $borrowernumber, |
597 |
{ letter => $letter, |
620 |
message_transport_type => $mtt, |
598 |
borrowernumber => $borrowernumber, |
621 |
from_address => $admin_email_address, |
599 |
firstname => $data->{'firstname'}, |
622 |
to_address => join(',', @emails_to_use), |
600 |
lastname => $data->{'surname'}, |
623 |
} |
601 |
address1 => $data->{'address'}, |
624 |
); |
602 |
address2 => $data->{'address2'}, |
625 |
# A print notice should be sent only once per overdue level. |
603 |
city => $data->{'city'}, |
626 |
# Without this check, a print could be sent twice or more if the library checks sms and email and print and the patron has no email or sms number. |
604 |
postcode => $data->{'zipcode'}, |
627 |
$print_sent = 1 if $mtt eq 'print'; |
605 |
country => $data->{'country'}, |
|
|
606 |
email => $notice_email, |
607 |
itemcount => $itemcount, |
608 |
titles => $titles, |
609 |
outputformat => defined $csvfilename ? 'csv' : defined $htmlfilename ? 'html' : '', |
610 |
} |
628 |
} |
611 |
); |
629 |
} |
612 |
} |
630 |
} |
613 |
} |
631 |
} |
614 |
$sth->finish; |
632 |
$sth->finish; |
Lines 732-737
sub parse_letter {
Link Here
|
732 |
tables => \%tables, |
750 |
tables => \%tables, |
733 |
substitute => $substitute, |
751 |
substitute => $substitute, |
734 |
repeat => { item => \@item_tables }, |
752 |
repeat => { item => \@item_tables }, |
|
|
753 |
message_transport_type => $params->{message_transport_type}, |
735 |
); |
754 |
); |
736 |
} |
755 |
} |
737 |
|
756 |
|
Lines 761-766
sub prepare_letter_for_printing {
Link Here
|
761 |
} |
780 |
} |
762 |
|
781 |
|
763 |
my $return; |
782 |
my $return; |
|
|
783 |
chomp $params->{titles}; |
764 |
if ( exists $params->{'outputformat'} && $params->{'outputformat'} eq 'csv' ) { |
784 |
if ( exists $params->{'outputformat'} && $params->{'outputformat'} eq 'csv' ) { |
765 |
if ($csv->combine( |
785 |
if ($csv->combine( |
766 |
$params->{'firstname'}, $params->{'lastname'}, $params->{'address1'}, $params->{'address2'}, $params->{'postcode'}, |
786 |
$params->{'firstname'}, $params->{'lastname'}, $params->{'address1'}, $params->{'address2'}, $params->{'postcode'}, |
767 |
- |
|
|