+ $sth->execute( $borrowernumber );
+ my $data;
+ my $total_amount_other = 0.00;
+ my $due_qr = qr/$due/;
+ # Cycle through the fines and
+ # - find line that relates to the requested $itemnum
+ # - accumulate fines for other items
+ # so we can update $itemnum fine taking in account fine caps
+ while (my $rec = $sth->fetchrow_hashref) {
+ if ($rec->{itemnumber} == $itemnum && $rec->{description} =~ /$due_qr/) {
+ if ($data) {
+ warn "Not a unique accountlines record for item $itemnum borrower $borrowernumber";
+ } else {
+ $data = $rec;
+ next;
+ }
+ }
+ $total_amount_other += $rec->{'amount'};
+ }
+ if (my $maxfine = C4::Context->preference('MaxFine')) {
+ if ($total_amount_other + $amount > $maxfine) {
+ my $new_amount = $maxfine - $total_amount_other;
+ warn "Reducing fine for item $itemnum borrower $borrowernumber from $amount to $new_amount - MaxFine reached";
+ return if $new_amount <= 0.00;
+
+ $amount = $new_amount;
+ }
+ }