|
Lines 38-44
use DateTime;
Link Here
|
| 38 |
use DateTime::Duration; |
38 |
use DateTime::Duration; |
| 39 |
|
39 |
|
| 40 |
use C4::Context; |
40 |
use C4::Context; |
| 41 |
use C4::Dates qw/format_date/; |
|
|
| 42 |
use C4::Debug; |
41 |
use C4::Debug; |
| 43 |
use C4::Letters; |
42 |
use C4::Letters; |
| 44 |
use C4::Overdues qw(GetFine GetOverdueMessageTransportTypes); |
43 |
use C4::Overdues qw(GetFine GetOverdueMessageTransportTypes); |
|
Lines 527-533
END_SQL
Link Here
|
| 527 |
my $borrowernumber; |
526 |
my $borrowernumber; |
| 528 |
while ( my $data = $sth->fetchrow_hashref ) { |
527 |
while ( my $data = $sth->fetchrow_hashref ) { |
| 529 |
|
528 |
|
| 530 |
next unless ( DateTime->compare( $date_to_run, dt_from_string($data->{date_due})) ) == 1; |
529 |
next unless ( DateTime->compare( $date_to_run, dt_from_string($data->{date_due})) ) == 1; |
| 531 |
|
530 |
|
| 532 |
# check the borrower has at least one item that matches |
531 |
# check the borrower has at least one item that matches |
| 533 |
my $days_between; |
532 |
my $days_between; |
|
Lines 536-547
END_SQL
Link Here
|
| 536 |
my $calendar = |
535 |
my $calendar = |
| 537 |
Koha::Calendar->new( branchcode => $branchcode ); |
536 |
Koha::Calendar->new( branchcode => $branchcode ); |
| 538 |
$days_between = |
537 |
$days_between = |
| 539 |
$calendar->days_between( dt_from_string($data->{date_due}), |
538 |
$calendar->days_between( dt_from_string($data->{date_due}), |
| 540 |
$date_to_run ); |
539 |
$date_to_run ); |
| 541 |
} |
540 |
} |
| 542 |
else { |
541 |
else { |
| 543 |
$days_between = |
542 |
$days_between = |
| 544 |
$date_to_run->delta_days( dt_from_string($data->{date_due}) ); |
543 |
$date_to_run->delta_days( dt_from_string($data->{date_due}) ); |
| 545 |
} |
544 |
} |
| 546 |
$days_between = $days_between->in_units('days'); |
545 |
$days_between = $days_between->in_units('days'); |
| 547 |
if ($triggered) { |
546 |
if ($triggered) { |
|
Lines 657-663
END_SQL
Link Here
|
| 657 |
last; |
656 |
last; |
| 658 |
} |
657 |
} |
| 659 |
$j++; |
658 |
$j++; |
| 660 |
my @item_info = map { $_ =~ /^date|date$/ ? format_date( $item_info->{$_} ) : $item_info->{$_} || '' } @item_content_fields; |
659 |
my @item_info = map { $_ =~ /^date|date$/ ? |
|
|
660 |
eval { output_pref( { dt => dt_from_string( $item_info->{$_} ), dateonly => 1 } ); } |
| 661 |
: |
| 662 |
$item_info->{$_} || '' } @item_content_fields; |
| 661 |
$titles .= join("\t", @item_info) . "\n"; |
663 |
$titles .= join("\t", @item_info) . "\n"; |
| 662 |
$itemcount++; |
664 |
$itemcount++; |
| 663 |
push @items, $item_info; |
665 |
push @items, $item_info; |
|
Lines 829-834
if ( defined $htmlfilename ) {
Link Here
|
| 829 |
|
831 |
|
| 830 |
These methods are internal to the operation of overdue_notices.pl. |
832 |
These methods are internal to the operation of overdue_notices.pl. |
| 831 |
|
833 |
|
|
|
834 |
=head2 parse_letter |
| 835 |
|
| 836 |
parses the letter template, replacing the placeholders with data |
| 837 |
specific to this patron, biblio, or item |
| 838 |
|
| 839 |
named parameters: |
| 840 |
letter - required hashref |
| 841 |
borrowernumber - required integer |
| 842 |
substitute - optional hashref of other key/value pairs that should |
| 843 |
be substituted in the letter content |
| 844 |
|
| 845 |
returns the C<letter> hashref, with the content updated to reflect the |
| 846 |
substituted keys and values. |
| 847 |
|
| 848 |
|
| 849 |
=cut |
| 850 |
|
| 851 |
sub parse_letter { |
| 852 |
my $params = shift; |
| 853 |
foreach my $required (qw( letter_code borrowernumber )) { |
| 854 |
return unless ( exists $params->{$required} && $params->{$required} ); |
| 855 |
} |
| 856 |
|
| 857 |
my $substitute = $params->{'substitute'} || {}; |
| 858 |
$substitute->{today} ||= output_pref( { dt => dt_from_string , dateonly => 1 } ); |
| 859 |
|
| 860 |
my %tables = ( 'borrowers' => $params->{'borrowernumber'} ); |
| 861 |
if ( my $p = $params->{'branchcode'} ) { |
| 862 |
$tables{'branches'} = $p; |
| 863 |
} |
| 864 |
|
| 865 |
my $currencies = GetCurrency(); |
| 866 |
my $currency_format; |
| 867 |
$currency_format = $currencies->{currency} if defined($currencies); |
| 868 |
|
| 869 |
my @item_tables; |
| 870 |
if ( my $i = $params->{'items'} ) { |
| 871 |
my $item_format = ''; |
| 872 |
foreach my $item (@$i) { |
| 873 |
my $fine = GetFine($item->{'itemnumber'}, $params->{'borrowernumber'}); |
| 874 |
if ( !$item_format and defined $params->{'letter'}->{'content'} ) { |
| 875 |
$params->{'letter'}->{'content'} =~ m/(<item>.*<\/item>)/; |
| 876 |
$item_format = $1; |
| 877 |
} |
| 878 |
|
| 879 |
$item->{'fine'} = currency_format($currency_format, "$fine", FMT_SYMBOL); |
| 880 |
# if active currency isn't correct ISO code fallback to sprintf |
| 881 |
$item->{'fine'} = sprintf('%.2f', $fine) unless $item->{'fine'}; |
| 882 |
|
| 883 |
push @item_tables, { |
| 884 |
'biblio' => $item->{'biblionumber'}, |
| 885 |
'biblioitems' => $item->{'biblionumber'}, |
| 886 |
'items' => $item, |
| 887 |
'issues' => $item->{'itemnumber'}, |
| 888 |
}; |
| 889 |
} |
| 890 |
} |
| 891 |
|
| 892 |
return C4::Letters::GetPreparedLetter ( |
| 893 |
module => 'circulation', |
| 894 |
letter_code => $params->{'letter_code'}, |
| 895 |
branchcode => $params->{'branchcode'}, |
| 896 |
tables => \%tables, |
| 897 |
substitute => $substitute, |
| 898 |
repeat => { item => \@item_tables }, |
| 899 |
message_transport_type => $params->{message_transport_type}, |
| 900 |
); |
| 901 |
} |
| 902 |
|
| 832 |
=head2 prepare_letter_for_printing |
903 |
=head2 prepare_letter_for_printing |
| 833 |
|
904 |
|
| 834 |
returns a string of text appropriate for printing in the event that an |
905 |
returns a string of text appropriate for printing in the event that an |