From a3ee8e4f210f9508ecff8488d41bf71bb9a53ce2 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Wed, 9 Oct 2019 13:08:10 -0400 Subject: [PATCH] Bug 23788: Recalculate ammount due for selected accountlines Individual fees cannot be overpaid of over-written off, but it's possible to 'overpay' a writeoff of selected fees. Test Plan: 1) Create 3 fees 2) Pick 2 and choose "Write off selected" 3) Write off more than the total amount of those fees 4) Apply this patch set 5) Restart all the things! 6) Try again, you should no longer be able to! --- members/paycollect.pl | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/members/paycollect.pl b/members/paycollect.pl index e76953caa5..a3be8f9162 100755 --- a/members/paycollect.pl +++ b/members/paycollect.pl @@ -69,9 +69,9 @@ my $total_due = $account->outstanding_debits->total_outstanding; my $total_paid = $input->param('paid'); -my $selected_lines = $input->param('selected'); +my $selected_lines = $input->param('selected'); # comes from pay.pl my $pay_individual = $input->param('pay_individual'); -my $selected_accts = $input->param('selected_accts'); +my $selected_accts = $input->param('selected_accts'); # comes from paycollect.pl my $payment_note = uri_unescape scalar $input->param('payment_note'); my $payment_type = scalar $input->param('payment_type'); my $accountlines_id; @@ -181,18 +181,28 @@ if ( $total_paid and $total_paid ne '0.00' ) { { order_by => 'date' } ); - $payment_id = $account->pay( - { - type => $type, - amount => $total_paid, - library_id => $library_id, - lines => \@lines, - note => $note, - interface => C4::Context->interface, - payment_type => $payment_type, - cash_register => $registerid - } - ); + $total_due = 0; # Reset and recalculate total due + map { $total_due += $_->amountoutstanding } @lines; + + if ( $total_paid > $total_due ) { + $template->param( + error_over => 1, + total_due => $total_due + ); + } else { + $payment_id = $account->pay( + { + type => $type, + amount => $total_paid, + library_id => $library_id, + lines => \@lines, + note => $note, + interface => C4::Context->interface, + payment_type => $payment_type, + cash_register => $registerid + } + ); + } } else { my $note = $input->param('selected_accts_notes'); -- 2.21.0 (Apple Git-122)