|
Lines 43-48
use warnings;
Link Here
|
| 43 |
use Getopt::Long; |
43 |
use Getopt::Long; |
| 44 |
use Pod::Usage; |
44 |
use Pod::Usage; |
| 45 |
use Data::Dumper; |
45 |
use Data::Dumper; |
|
|
46 |
use Locale::Currency::Format 1.28; |
| 46 |
BEGIN { |
47 |
BEGIN { |
| 47 |
# find Koha's Perl modules |
48 |
# find Koha's Perl modules |
| 48 |
# test carefully before changing this |
49 |
# test carefully before changing this |
|
Lines 55-60
use C4::Letters;
Link Here
|
| 55 |
use C4::Members; |
56 |
use C4::Members; |
| 56 |
use C4::Members::Messaging; |
57 |
use C4::Members::Messaging; |
| 57 |
use C4::Overdues; |
58 |
use C4::Overdues; |
|
|
59 |
use C4::Budgets qw(GetCurrency); |
| 58 |
use Koha::DateUtils; |
60 |
use Koha::DateUtils; |
| 59 |
use C4::Log; |
61 |
use C4::Log; |
| 60 |
|
62 |
|
|
Lines 235-240
UPCOMINGITEM: foreach my $upcoming ( @$upcoming_dues ) {
Link Here
|
| 235 |
|
237 |
|
| 236 |
my $from_address = $upcoming->{branchemail} || $admin_adress; |
238 |
my $from_address = $upcoming->{branchemail} || $admin_adress; |
| 237 |
|
239 |
|
|
|
240 |
my $sth2 = $dbh->prepare(' |
| 241 |
SELECT * |
| 242 |
FROM accountlines |
| 243 |
WHERE borrowernumber = ? AND amountoutstanding > 0 |
| 244 |
'); |
| 245 |
$sth2->execute($upcoming->{'borrowernumber'}); |
| 246 |
my @accountlines = (); |
| 247 |
while ( my $accountline = $sth2->fetchrow_hashref() ) { |
| 248 |
push(@accountlines, $accountline); |
| 249 |
} |
| 250 |
$sth2->finish; |
| 251 |
|
| 238 |
my $borrower_preferences; |
252 |
my $borrower_preferences; |
| 239 |
if ( 0 == $upcoming->{'days_until_due'} ) { |
253 |
if ( 0 == $upcoming->{'days_until_due'} ) { |
| 240 |
# This item is due today. Send an 'item due' message. |
254 |
# This item is due today. Send an 'item due' message. |
|
Lines 265-270
UPCOMINGITEM: foreach my $upcoming ( @$upcoming_dues ) {
Link Here
|
| 265 |
itemnumber => $upcoming->{'itemnumber'}, |
279 |
itemnumber => $upcoming->{'itemnumber'}, |
| 266 |
substitute => { 'items.content' => $titles }, |
280 |
substitute => { 'items.content' => $titles }, |
| 267 |
message_transport_type => $transport, |
281 |
message_transport_type => $transport, |
|
|
282 |
accountlines => \@accountlines, |
| 268 |
} ) |
283 |
} ) |
| 269 |
or warn "no letter of type '$letter_type' found. Please see sample_notices.sql"; |
284 |
or warn "no letter of type '$letter_type' found. Please see sample_notices.sql"; |
| 270 |
push @letters, $letter if $letter; |
285 |
push @letters, $letter if $letter; |
|
Lines 299-304
UPCOMINGITEM: foreach my $upcoming ( @$upcoming_dues ) {
Link Here
|
| 299 |
itemnumber => $upcoming->{'itemnumber'}, |
314 |
itemnumber => $upcoming->{'itemnumber'}, |
| 300 |
substitute => { 'items.content' => $titles }, |
315 |
substitute => { 'items.content' => $titles }, |
| 301 |
message_transport_type => $transport, |
316 |
message_transport_type => $transport, |
|
|
317 |
accountlines => \@accountlines, |
| 302 |
} ) |
318 |
} ) |
| 303 |
or warn "no letter of type '$letter_type' found. Please see sample_notices.sql"; |
319 |
or warn "no letter of type '$letter_type' found. Please see sample_notices.sql"; |
| 304 |
push @letters, $letter if $letter; |
320 |
push @letters, $letter if $letter; |
|
Lines 342-347
PATRON: while ( my ( $borrowernumber, $digest ) = each %$upcoming_digest ) {
Link Here
|
| 342 |
my $count = $digest->{count}; |
358 |
my $count = $digest->{count}; |
| 343 |
my $from_address = $digest->{email}; |
359 |
my $from_address = $digest->{email}; |
| 344 |
|
360 |
|
|
|
361 |
my $sth2 = $dbh->prepare(' |
| 362 |
SELECT * |
| 363 |
FROM accountlines |
| 364 |
WHERE borrowernumber = ? AND amountoutstanding > 0 |
| 365 |
'); |
| 366 |
$sth2->execute($borrowernumber); |
| 367 |
my @accountlines = (); |
| 368 |
while ( my $accountline = $sth2->fetchrow_hashref() ) { |
| 369 |
push(@accountlines, $accountline); |
| 370 |
} |
| 371 |
$sth2->finish; |
| 372 |
|
| 345 |
my $borrower_preferences = C4::Members::Messaging::GetMessagingPreferences( { borrowernumber => $borrowernumber, |
373 |
my $borrower_preferences = C4::Members::Messaging::GetMessagingPreferences( { borrowernumber => $borrowernumber, |
| 346 |
message_name => 'advance_notice' } ); |
374 |
message_name => 'advance_notice' } ); |
| 347 |
next PATRON unless $borrower_preferences; # how could this happen? |
375 |
next PATRON unless $borrower_preferences; # how could this happen? |
|
Lines 371-376
PATRON: while ( my ( $borrowernumber, $digest ) = each %$upcoming_digest ) {
Link Here
|
| 371 |
}, |
399 |
}, |
| 372 |
branchcode => $branch_info{"branches.branchcode"}, |
400 |
branchcode => $branch_info{"branches.branchcode"}, |
| 373 |
message_transport_type => $transport, |
401 |
message_transport_type => $transport, |
|
|
402 |
accountlines => \@accountlines, |
| 374 |
} |
403 |
} |
| 375 |
) |
404 |
) |
| 376 |
or warn "no letter of type '$letter_type' found. Please see sample_notices.sql"; |
405 |
or warn "no letter of type '$letter_type' found. Please see sample_notices.sql"; |
|
Lines 401-406
PATRON: while ( my ( $borrowernumber, $digest ) = each %$due_digest ) {
Link Here
|
| 401 |
my $count = $digest->{count}; |
430 |
my $count = $digest->{count}; |
| 402 |
my $from_address = $digest->{email}; |
431 |
my $from_address = $digest->{email}; |
| 403 |
|
432 |
|
|
|
433 |
my $sth2 = $dbh->prepare(' |
| 434 |
SELECT * |
| 435 |
FROM accountlines |
| 436 |
WHERE borrowernumber = ? AND amountoutstanding > 0 |
| 437 |
'); |
| 438 |
$sth2->execute($borrowernumber); |
| 439 |
my @accountlines = (); |
| 440 |
while ( my $accountline = $sth2->fetchrow_hashref() ) { |
| 441 |
push(@accountlines, $accountline); |
| 442 |
} |
| 443 |
$sth2->finish; |
| 444 |
|
| 404 |
my $borrower_preferences = C4::Members::Messaging::GetMessagingPreferences( { borrowernumber => $borrowernumber, |
445 |
my $borrower_preferences = C4::Members::Messaging::GetMessagingPreferences( { borrowernumber => $borrowernumber, |
| 405 |
message_name => 'item_due' } ); |
446 |
message_name => 'item_due' } ); |
| 406 |
next PATRON unless $borrower_preferences; # how could this happen? |
447 |
next PATRON unless $borrower_preferences; # how could this happen? |
|
Lines 428-433
PATRON: while ( my ( $borrowernumber, $digest ) = each %$due_digest ) {
Link Here
|
| 428 |
}, |
469 |
}, |
| 429 |
branchcode => $branch_info{"branches.branchcode"}, |
470 |
branchcode => $branch_info{"branches.branchcode"}, |
| 430 |
message_transport_type => $transport, |
471 |
message_transport_type => $transport, |
|
|
472 |
accountlines => \@accountlines, |
| 431 |
} |
473 |
} |
| 432 |
) |
474 |
) |
| 433 |
or warn "no letter of type '$letter_type' found. Please see sample_notices.sql"; |
475 |
or warn "no letter of type '$letter_type' found. Please see sample_notices.sql"; |
|
Lines 479-490
sub parse_letter {
Link Here
|
| 479 |
$table_params{'biblioitems'} = $p; |
521 |
$table_params{'biblioitems'} = $p; |
| 480 |
} |
522 |
} |
| 481 |
|
523 |
|
|
|
524 |
my $currencies = GetCurrency(); |
| 525 |
my $currency_format = $currencies->{currency} if defined($currencies); |
| 526 |
|
| 527 |
my $amountoutstanding_total = 0; |
| 528 |
my @accountlines_tables = (); |
| 529 |
foreach my $accountline (@{$params->{'accountlines'}}) { |
| 530 |
$amountoutstanding_total += $accountline->{'amountoutstanding'}; |
| 531 |
|
| 532 |
$accountline->{'amountoutstanding'} = currency_format($currency_format, $accountline->{'amountoutstanding'}, FMT_SYMBOL); |
| 533 |
# if active currency isn't correct ISO code fallback to sprintf |
| 534 |
$accountline->{'amountoutstanding'} = sprintf('%.2f', $accountline->{'amountoutstanding'}) unless $accountline->{'amountoutstanding'}; |
| 535 |
|
| 536 |
push @accountlines_tables, { |
| 537 |
'accountlines' => $accountline |
| 538 |
}; |
| 539 |
} |
| 540 |
$amountoutstanding_total = currency_format($currency_format, $amountoutstanding_total, FMT_SYMBOL); |
| 541 |
# if active currency isn't correct ISO code fallback to sprintf |
| 542 |
$amountoutstanding_total = sprintf('%.2f', $amountoutstanding_total) unless $amountoutstanding_total; |
| 543 |
|
| 544 |
$params->{'substitute'}->{'accountlines.total'} = $amountoutstanding_total; |
| 545 |
|
| 482 |
return C4::Letters::GetPreparedLetter ( |
546 |
return C4::Letters::GetPreparedLetter ( |
| 483 |
module => 'circulation', |
547 |
module => 'circulation', |
| 484 |
letter_code => $params->{'letter_code'}, |
548 |
letter_code => $params->{'letter_code'}, |
| 485 |
branchcode => $table_params{'branches'}, |
549 |
branchcode => $table_params{'branches'}, |
| 486 |
substitute => $params->{'substitute'}, |
550 |
substitute => $params->{'substitute'}, |
| 487 |
tables => \%table_params, |
551 |
tables => \%table_params, |
|
|
552 |
repeat => {accountline => \@accountlines_tables}, |
| 488 |
message_transport_type => $params->{message_transport_type}, |
553 |
message_transport_type => $params->{message_transport_type}, |
| 489 |
); |
554 |
); |
| 490 |
} |
555 |
} |