From ce587dceeb8f8f113a73311bd894c1e27f898f5e Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 7 May 2020 14:24:35 -0400 Subject: [PATCH] Bug 25417: Prevent backdating returns and forgiving fines as the same time from causing an internal server error --- C4/Circulation.pm | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 8db887db2e..40f4af68c9 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -2433,24 +2433,26 @@ sub _FixOverduesOnReturn { if ($exemptfine) { my $amountoutstanding = $accountline->amountoutstanding; - my $account = Koha::Account->new({patron_id => $borrowernumber}); - my $credit = $account->add_credit( - { - amount => $amountoutstanding, - user_id => C4::Context->userenv ? C4::Context->userenv->{'number'} : undef, - library_id => C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef, - interface => C4::Context->interface, - type => 'FORGIVEN', - item_id => $item - } - ); + if ( $amountoutstanding > 0 ) { + my $account = Koha::Account->new({patron_id => $borrowernumber}); + my $credit = $account->add_credit( + { + amount => $amountoutstanding, + user_id => C4::Context->userenv ? C4::Context->userenv->{'number'} : undef, + library_id => C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef, + interface => C4::Context->interface, + type => 'FORGIVEN', + item_id => $item + } + ); - $credit->apply({ debits => [ $accountline ], offset_type => 'Forgiven' }); + $credit->apply({ debits => [ $accountline ], offset_type => 'Forgiven' }); - $accountline->status('FORGIVEN'); + $accountline->status('FORGIVEN'); - if (C4::Context->preference("FinesLog")) { - &logaction("FINES", 'MODIFY',$borrowernumber,"Overdue forgiven: item $item"); + if (C4::Context->preference("FinesLog")) { + &logaction("FINES", 'MODIFY',$borrowernumber,"Overdue forgiven: item $item"); + } } } else { $accountline->status($status); -- 2.24.2 (Apple Git-127)