From a108d56f9179ed1be299affb7535e4c198b4aeff Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 30 Jul 2020 09:35:38 -0400 Subject: [PATCH] Bug 26076: (QA Follow up) Prevent error by using a fresh resultset Signed-off-by: Katrin Fischer Signed-off-by: Jonathan Druart (cherry picked from commit c9887a87538b2113c48db8cd2751a4bcf2bd2168) Signed-off-by: Lucas Gass (cherry picked from commit 3a4f76b60d880fabb5bb6637839d1a83e673e1d6) Signed-off-by: Aleisha Amohia --- members/paycollect.pl | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/members/paycollect.pl b/members/paycollect.pl index d8139bd1e7..2538d94878 100755 --- a/members/paycollect.pl +++ b/members/paycollect.pl @@ -143,21 +143,27 @@ if ( $selected_accts ) { } my @acc = split /,/, $selected_accts; - my $selected_accountlines = Koha::Account::Lines->search( - { - borrowernumber => $borrowernumber, + my $search_params = { + borrowernumber => $borrowernumber, amountoutstanding => { '<>' => 0 }, accountlines_id => { 'in' => \@acc }, - }, + }; + + my @selected_accountlines = Koha::Account::Lines->search( + $search_params, { order_by => 'date' } ); - $total_due = $selected_accountlines->_resultset->get_column('amountoutstanding')->sum(); - - @selected_accountlines = $selected_accountlines->as_list; + my $sum = Koha::Account::Lines->search( + $search_params, + { + select => [ { sum => 'amountoutstanding' } ], + as => [ 'total_amountoutstanding'], + } + ); + $total_due = $sum->_resultset->first->get_column('total_amountoutstanding'); } - if ( $total_paid and $total_paid ne '0.00' ) { $total_paid = $total_due if (abs($total_paid - $total_due) < 0.01) && C4::Context->preference('RoundFinesAtPayment'); if ( $total_paid < 0 or $total_paid > $total_due ) { -- 2.39.5