From 4db47ed9dcff6cbb7f93a24cb2863e99863496cc Mon Sep 17 00:00:00 2001 From: Jan Kissig Date: Thu, 7 Nov 2024 12:42:59 +0000 Subject: [PATCH] Bug 23426: (follow-up) This patch reintroduces the former implementation of fine items The original implementation of fine items was accidently overwritten with this patch. This follow up reverts these changes but keeps additional improvements that were also part of this patch. These are: - Returning the active currency as part of the response (BH) - Fixing the number of items in the response which are specified in BP and BQ when other items as fine items are requested. --- C4/SIP/ILS/Patron.pm | 48 ++++++++++++++++++++++++++++++++++--------- C4/SIP/Sip/MsgType.pm | 17 ++++----------- 2 files changed, 42 insertions(+), 23 deletions(-) diff --git a/C4/SIP/ILS/Patron.pm b/C4/SIP/ILS/Patron.pm index 1483f0ebf9..19412ebac1 100644 --- a/C4/SIP/ILS/Patron.pm +++ b/C4/SIP/ILS/Patron.pm @@ -215,14 +215,6 @@ sub new { # 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 ) { @@ -447,9 +439,45 @@ sub charged_items { return $self->x_items('items', @_); } sub fine_items { - my $self = shift; - return $self->x_items('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; + } + sub recall_items { my $self = shift; return $self->x_items('recall_items', @_); diff --git a/C4/SIP/Sip/MsgType.pm b/C4/SIP/Sip/MsgType.pm index 6ad48672fd..5e9b5d6b63 100644 --- a/C4/SIP/Sip/MsgType.pm +++ b/C4/SIP/Sip/MsgType.pm @@ -958,12 +958,11 @@ 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 > 6; # Positions 7-9 are not defined in the sip spec, + return q{} if $summary_type > 5; # Positions 6-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} ); @@ -972,17 +971,9 @@ sub summary_info { my $fid = $summary_map[$summary_type]->{fid}; my $itemlist = &$func( $patron, $start, $end, $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 ); - } + siplog( "LOG_DEBUG", "summary_info: list = (%s)", join( ", ", map { $_->{barcode} } @{$itemlist} ) ); + foreach my $i ( @{$itemlist} ) { + $resp .= add_field( $fid, $i->{barcode}, $server ); } return $resp; -- 2.39.5