From fdac11b1e88f66b63add2610e25831445c601637 Mon Sep 17 00:00:00 2001 From: Colin Campbell Date: Mon, 5 Aug 2019 13:59:28 +0100 Subject: [PATCH] Bug 23426 Return correct number of Fine Items When subsets of Fine Items are requested in a Patron Info response the server was returning an extra field. The Request specifys the items requested as a closed array based on 1. e.g. to get a single item start and end are both set to 1 The code sets start to start - 1 but left stop unchanged and looped as though in a closed array rather than a half-open one with the result that an extra field is returned. Often this is empty as it tries to read past the end of the main array. This patch cleans up the logic to behave correctly Removed the superfluous brackets around push's arguments to make consistent with other uses in the module --- C4/SIP/ILS/Patron.pm | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/C4/SIP/ILS/Patron.pm b/C4/SIP/ILS/Patron.pm index 30c0e48ac6..061a6395f4 100644 --- a/C4/SIP/ILS/Patron.pm +++ b/C4/SIP/ILS/Patron.pm @@ -352,8 +352,10 @@ sub fine_items { } ); + # start and end are specified as a 1-based indices + # convert them to standard half open array start and terminate values $start = $start ? $start - 1 : 0; - $end = $end ? $end : scalar @fees - 1; + $end = $end ? $end : scalar @fees; my $av_field_template = $server ? $server->{account}->{av_field_template} : undef; $av_field_template ||= "[% accountline.description %] [% accountline.amountoutstanding | format('%.2f') %]"; @@ -361,12 +363,12 @@ sub fine_items { my $tt = Template->new(); my @return_values; - for ( my $i = $start; $i <= $end; $i++ ) { + for ( my $i = $start; $i < $end; $i++ ) { my $fee = $fees[$i]; my $output; $tt->process( \$av_field_template, { accountline => $fee }, \$output ); - push( @return_values, { barcode => $output } ); + push @return_values, { barcode => $output }; } return \@return_values; -- 2.21.0