From 8cf36a24d2561feddeaa6dd813584ebaf6255b10 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 23 Jan 2026 12:45:40 +0000 Subject: [PATCH] Bug 29800: Add calculation and update of fine to LostItem This patch adds a call to 'CalculateAndUpdateFine' to LostItem, checking if the new syspref WhenLostUpdateFine is enabled Test plan: 1 - define a circ rule with an overdue fine, confirm FinesMode is set to "Calculate and charge." 2 - check out an item with a due date in the past such that it would incur an overdue fine if checked in 3 - edit your item to apply a lost status, 4 - confirm no fine is generated 5 - check out an item with a due date in the past such that it would incur an overdue fine if checked in 6 - mark your item lost via the longoverdue cron 7 - confirm no fine is generated 8 - check out an item with a due date in the past such that it would incur an overdue fine if checked in 9 - run fines.pl, confirm an accruing fine has been generated 10 - edit your circ rule to change the fine amount 11 - edit your item to apply a lost status 12 - confirm your fine is now marked "Lost" rather than "Accruing" but the amount has not updated to reflect your changes from step 10 13 - apply patch, updatedatabse, restart_all 14 - confirm new system preference WhenLostUpdateFine is set to No 15 - repeat steps 2 - 12, confirm no change in behavior 16 - set WhenLostUpdateFine to Yes 17 - check out an item with a due date in the past such that it would incur an overdue fine if checked in 18 - edit your item to apply a lost status, 19 - confirm a fine is generated 20 - check out an item with a due date in the past such that it would incur an overdue fine if checked in 21 - mark your item lost via the longoverdue cron 22 - confirm a fine is generated 23 - check out an item with a due date in the past such that it would incur an overdue fine if checked in 24 - run fines.pl, confirm an accruing fine has been generated 25 - edit your circ rule to change the fine amount 26 - edit your item to apply a lost status 27 - confirm your fine is now marked "Lost" rather than "Accruing" and the amount has updated to reflect your changes from step 25 --- C4/Circulation.pm | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 1e025cc56a7..8227f3b7434 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -4408,6 +4408,8 @@ $params: sub LostItem { my ( $itemnumber, $mark_lost_from, $force_mark_returned, $params ) = @_; + my $item = Koha::Items->find($itemnumber); + unless ($mark_lost_from) { # Temporary check to avoid regressions @@ -4422,20 +4424,20 @@ sub LostItem { $mark_returned = ( $pref =~ m|$mark_lost_from| ); } - my $dbh = C4::Context->dbh(); - my $sth = $dbh->prepare( - "SELECT issues.*,items.*,biblio.title - FROM issues - JOIN items USING (itemnumber) - JOIN biblio USING (biblionumber) - WHERE issues.itemnumber=?" - ); - $sth->execute($itemnumber); - my $issues = $sth->fetchrow_hashref(); + my $issue = $item->checkout; # If a borrower lost the item, add a replacement cost to the their record - if ( my $borrowernumber = $issues->{borrowernumber} ) { - my $patron = Koha::Patrons->find($borrowernumber); + if ($issue) { + my $patron = $issue->patron; + my $borrowernumber = $patron->borrowernumber; + + _CalculateAndUpdateFine( + { + issue => $issue, + item => $item->unblessed, + borrower => $patron->unblessed, + } + ) if C4::Context->preference('WhenLostUpdateFine'); my $fix = _FixOverduesOnReturn( $borrowernumber, $itemnumber, C4::Context->preference('WhenLostForgiveFine'), @@ -4448,12 +4450,12 @@ sub LostItem { C4::Accounts::chargelostitem( $borrowernumber, $itemnumber, - $issues->{'replacementprice'}, + $item->replacementprice, sprintf( "%s %s %s", - $issues->{'title'} || q{}, - $issues->{'barcode'} || q{}, - $issues->{'itemcallnumber'} || q{}, + $item->biblio->title || q{}, + $item->barcode || q{}, + $item->itemcallnumber || q{}, ), ); @@ -4465,7 +4467,6 @@ sub LostItem { } # When an item is marked as lost, we should automatically cancel its outstanding transfers. - my $item = Koha::Items->find($itemnumber); my $transfers = $item->get_transfers; while ( my $transfer = $transfers->next ) { $transfer->cancel( { reason => 'ItemLost', force => 1 } ); -- 2.39.5