diff --git a/C4/SIP/ILS/Patron.pm b/C4/SIP/ILS/Patron.pm index f3dfea74bd..f61c855ed2 100644 --- a/C4/SIP/ILS/Patron.pm +++ b/C4/SIP/ILS/Patron.pm @@ -121,6 +121,9 @@ sub new { } } + # Get currency 3 chars max + my $currency = substr Koha::Acquisition::Currencies->get_active->currency, 0, 3; + my $circ_blocked =( C4::Context->preference('OverduesBlockCirc') ne "noblock" && defined $flags->{ODUES}->{itemlist} ) ? 1 : 0; { no warnings; # any of these $kp->{fields} being concat'd could be undef @@ -164,6 +167,7 @@ sub new { fine_blocked => $fine_blocked, fee_limit => $fee_limit, userid => $kp->{userid}, + currency => $currency, ); } @@ -205,9 +209,17 @@ sub new { } } - # FIXME: populate fine_items recall_items + # FIXME: populate recall_items $ilspatron{unavail_holds} = _get_outstanding_holds($kp->{borrowernumber}); + # fine items + my $debits = $patron->account->outstanding_debits; + my @fine_items; + while ( my $debit = $debits->next ) { + push @fine_items, { account_line => sprintf '%s %.02f', $debit->description, $debit->amountoutstanding }; + } + $ilspatron{fine_items} =\@fine_items; + my $pending_checkouts = $patron->pending_checkouts; my @barcodes; while ( my $c = $pending_checkouts->next ) { @@ -390,6 +402,7 @@ sub x_items { my $item_list = []; if ($self->{$array_var}) { + if ($start && $start > 1) { --$start; } @@ -397,6 +410,7 @@ sub x_items { $start = 0; } if ( $end && $end < @{$self->{$array_var}} ) { + --$end; } else { $end = @{$self->{$array_var}}; @@ -430,38 +444,8 @@ sub charged_items { return $self->x_items('items', @_); } sub fine_items { - require Koha::Database; - require Template; - my $self = shift; - my $start = shift; - my $end = shift; - my $server = shift; - - my @fees = Koha::Database->new()->schema()->resultset('Accountline')->search( - { - borrowernumber => $self->{borrowernumber}, - amountoutstanding => { '>' => '0' }, - } - ); - - $start = $start ? $start - 1 : 0; - $end = $end ? $end - 1 : scalar @fees - 1; - - my $av_field_template = $server ? $server->{account}->{av_field_template} : undef; - $av_field_template ||= "[% accountline.description %] [% accountline.amountoutstanding | format('%.2f') %]"; - - my @return_values; - for ( my $i = $start; $i <= $end; $i++ ) { - my $fee = $fees[$i]; - - next unless $fee; - - my $output = process_tt( $av_field_template, { accountline => $fee } ); - push( @return_values, { barcode => $output } ); - } - - return \@return_values; + return $self->x_items('fine_items', @_); } sub recall_items { my $self = shift; diff --git a/C4/SIP/Sip/MsgType.pm b/C4/SIP/Sip/MsgType.pm index 6fb0e936dd..7978f9593d 100644 --- a/C4/SIP/Sip/MsgType.pm +++ b/C4/SIP/Sip/MsgType.pm @@ -958,11 +958,12 @@ sub summary_info { { func => $patron->can("fine_items"), fid => FID_FINE_ITEMS }, { func => $patron->can("recall_items"), fid => FID_RECALL_ITEMS }, { func => $patron->can("unavail_holds"), fid => FID_UNAVAILABLE_HOLD_ITEMS }, + { func => $patron->can("fine_items"), fid => FID_FINE_ITEMS }, ); my $summary_type = index( $summary, 'Y' ); return q{} if $summary_type == -1; # No detailed information required. - return q{} if $summary_type > 5; # Positions 6-9 are not defined in the sip spec, + return q{} if $summary_type > 6; # Positions 7-9 are not defined in the sip spec, # and we have no extensions to handle them. siplog( "LOG_DEBUG", "Summary_info: index == '%d', field '%s'", $summary_type, $summary_map[$summary_type]->{fid} ); @@ -971,9 +972,17 @@ sub summary_info { my $fid = $summary_map[$summary_type]->{fid}; my $itemlist = &$func( $patron, $start, $end, $server ); - siplog( "LOG_DEBUG", "summary_info: list = (%s)", join( ", ", map{ $_->{barcode} } @{$itemlist} ) ); - foreach my $i ( @{$itemlist} ) { - $resp .= add_field( $fid, $i->{barcode}, $server ); + # fine items use account_line as key + if ( $summary_type == 6 ) { + siplog( "LOG_DEBUG", "summary_info: list = (%s)", join( ", ", map { $_->{account_line} } @{$itemlist} ) ); + foreach my $i ( @{$itemlist} ) { + $resp .= add_field( $fid, $i->{account_line}, $server ); + } + } else { + siplog( "LOG_DEBUG", "summary_info: list = (%s)", join( ", ", map { $_->{barcode} } @{$itemlist} ) ); + foreach my $i ( @{$itemlist} ) { + $resp .= add_field( $fid, $i->{barcode}, $server ); + } } return $resp;