From f94b32f074df1dbded3e074877418aaae7a55315 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 6 Dec 2019 15:10:17 +0000 Subject: [PATCH] Bug 24146: Corrections to UpdateFine logic concerning maxFine The `maxFine` system preference actually refers to the amount of outsanding debt (in fines) a patron may have at a given time. This patch corrects the functionality of UpdateFine such that it properly respects that counter given the payment of accruing fines scenario. Signed-off-by: Nick Clemens Signed-off-by: Jonathan Druart Signed-off-by: Martin Renvoize --- C4/Overdues.pm | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/C4/Overdues.pm b/C4/Overdues.pm index 9ab0bdc6b1..cd4f838cfd 100644 --- a/C4/Overdues.pm +++ b/C4/Overdues.pm @@ -551,12 +551,19 @@ sub UpdateFine { $total_amount_other += $overdue->amountoutstanding; } - if (my $maxfine = C4::Context->preference('MaxFine')) { - if ($total_amount_other + $amount > $maxfine) { - my $new_amount = $maxfine - $total_amount_other; - return if $new_amount <= 0.00; - $debug and warn "Reducing fine for item $itemnum borrower $borrowernumber from $amount to $new_amount - MaxFine reached"; - $amount = $new_amount; + if ( my $maxfine = C4::Context->preference('MaxFine') ) { + my $maxIncrease = $maxfine - $total_amount_other; + return if $maxIncrease <= 0.00; + if ($accountline) { + if ( ( $amount - $accountline->amount ) > $maxIncrease ) { + my $new_amount = $accountline->amount + $maxIncrease; + $debug and warn "Reducing fine for item $itemnum borrower $borrowernumber from $amount to $new_amount - MaxFine reached"; + $amount = $new_amount; + } + } + elsif ( $amount > $maxIncrease ) { + $debug and warn "Reducing fine for item $itemnum borrower $borrowernumber from $amount to $maxIncrease - MaxFine reached"; + $amount = $maxIncrease; } } -- 2.39.5