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.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
(cherry picked from commit e5bd8aec41)
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Jan Kissig 2024-11-07 12:42:59 +00:00 committed by Lucas Gass
parent 3dec3a9cb8
commit 2685372f23
2 changed files with 42 additions and 23 deletions

View File

@ -212,14 +212,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 ) {
@ -444,9 +436,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', @_);

View File

@ -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;