From 0e1ab73a9e50bb99d6763f1ed5370c708eab4b4b Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 12 Dec 2018 12:09:46 +0000 Subject: [PATCH] Bug 21727: Add handling for cases requireing patron refunds As it is possible to partially pay off a fine that is still incrementing we can end up in a position (when dropbox mode is enabled) where the patron may be owed money by the library should they have paid off the fine between dropping the item off in dropbox mode and the increment that reverts the increase on the dropbox day. Signed-off-by: Tomas Cohen Arazi --- Koha/Account/Line.pm | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Koha/Account/Line.pm b/Koha/Account/Line.pm index 26c97e346b..502499a8a7 100644 --- a/Koha/Account/Line.pm +++ b/Koha/Account/Line.pm @@ -256,6 +256,21 @@ sub adjust { my $difference = $amount - $amount_before; my $new_outstanding = $amount_outstanding_before + $difference; + # Catch cases that require patron refunds + if ( $new_outstanding < 0 ) { + my $account = + Koha::Patrons->find( $self->borrowernumber )->account; + my $credit = $account->add_credit( + { + amount => $new_outstanding * -1, + description => 'Overpayment refund', + type => 'credit', + ( $update_type eq 'fine_increment' ? ( item_id => $self->itemnumber ) : ()), + } + ); + $new_outstanding = 0; + } + # Update the account line $self->set( { -- 2.20.0