From c7df4b49434d000c4cf43283f4abc26fedb6f2e8 Mon Sep 17 00:00:00 2001 From: Jan Kissig Date: Thu, 25 Apr 2024 11:13:55 +0200 Subject: [PATCH] Bug 23426: Add fine items to patron information response in SIP2 This patch adds fine items (AV) to patron information response in SIP2 In addition the active currency we be part of the response (BH) This also fixes the number of items in the response which are specified in BP and BQ in the request to test: a) create a manual invoice for patron 23529000035676 : http://localhost:8081/cgi-bin/koha/members/maninvoice.pl?borrowernumber=19 b) in ktd call: perl /usr/share/koha/bin/sip_cli_emulator.pl -a 127.0.0.1 -p 6001 -su term1 -sp term1 -l CPL --patron 23529000035676 -m patron_information -s " Y " c) verify that no |AV field is in response d) apply patch e) in ktd call: perl /usr/share/koha/bin/sip_cli_emulator.pl -a 127.0.0.1 -p 6001 -su term1 -sp term1 -l CPL --patron 23529000035676 -m patron_information -s " Y " f) verify that response includes fields like '|AVManual fee ' Signed-off-by: David Nind Signed-off-by: Marcel de Rooy [EDIT] Tidied inline Signed-off-by: Katrin Fischer (cherry picked from commit 1d80470105e709e729a41ff52512dbcfd2992c69) Signed-off-by: Lucas Gass (cherry picked from commit d140000c989ee9ff09f7ba05003c7becd036c66d) Signed-off-by: Fridolin Somers --- C4/SIP/ILS/Patron.pm | 48 +++++++++++++++---------------------------- C4/SIP/Sip/MsgType.pm | 17 +++++++++++---- 2 files changed, 29 insertions(+), 36 deletions(-) diff --git a/C4/SIP/ILS/Patron.pm b/C4/SIP/ILS/Patron.pm index 9bcb1c0124..93a1a34207 100644 --- a/C4/SIP/ILS/Patron.pm +++ b/C4/SIP/ILS/Patron.pm @@ -103,6 +103,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 @@ -146,6 +149,7 @@ sub new { fine_blocked => $fine_blocked, fee_limit => $fee_limit, userid => $kp->{userid}, + currency => $currency, ); } @@ -187,9 +191,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 ) { @@ -372,6 +384,7 @@ sub x_items { my $item_list = []; if ($self->{$array_var}) { + if ($start && $start > 1) { --$start; } @@ -379,6 +392,7 @@ sub x_items { $start = 0; } if ( $end && $end < @{$self->{$array_var}} ) { + --$end; } else { $end = @{$self->{$array_var}}; @@ -412,38 +426,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 ba8ecd5579..7b19de31fe 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;