-=head2 parse_letter
-
-parses the letter template, replacing the placeholders with data
-specific to this patron, biblio, or item
-
-named parameters:
- letter - required hashref
- borrowernumber - required integer
- substitute - optional hashref of other key/value pairs that should
- be substituted in the letter content
-
-returns the C<letter> hashref, with the content updated to reflect the
-substituted keys and values.
-
-
-=cut
-
-sub parse_letter {
- my $params = shift;
- foreach my $required (qw( letter_code borrowernumber )) {
- return unless ( exists $params->{$required} && $params->{$required} );
- }
-
- my $substitute = $params->{'substitute'} || {};
- $substitute->{today} ||= C4::Dates->new()->output("syspref");
-
- my %tables = ( 'borrowers' => $params->{'borrowernumber'} );
- if ( my $p = $params->{'branchcode'} ) {
- $tables{'branches'} = $p;
- }
-
- my $currencies = GetCurrency();
- my $currency_format;
- $currency_format = $currencies->{currency} if defined($currencies);
-
- my @item_tables;
- if ( my $i = $params->{'items'} ) {
- my $item_format = '';
- foreach my $item (@$i) {
- my $fine = GetFine($item->{'itemnumber'}, $params->{'borrowernumber'});
- if ( !$item_format and defined $params->{'letter'}->{'content'} ) {
- $params->{'letter'}->{'content'} =~ m/(<item>.*<\/item>)/;
- $item_format = $1;
- }
-
- $item->{'fine'} = currency_format($currency_format, "$fine", FMT_SYMBOL);
- # if active currency isn't correct ISO code fallback to sprintf
- $item->{'fine'} = sprintf('%.2f', $fine) unless $item->{'fine'};
-
- push @item_tables, {
- 'biblio' => $item->{'biblionumber'},
- 'biblioitems' => $item->{'biblionumber'},
- 'items' => $item,
- 'issues' => $item->{'itemnumber'},
- };
- }
- }
-
- return C4::Letters::GetPreparedLetter (
- module => 'circulation',
- letter_code => $params->{'letter_code'},
- branchcode => $params->{'branchcode'},
- tables => \%tables,
- substitute => $substitute,
- repeat => { item => \@item_tables },
- message_transport_type => $params->{message_transport_type},
- );
-}
-