From 1782560c9a3a706c82168143d9700729ade0f711 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 --- C4/Circulation.pm | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 163e1560d1f..9f0a3833567 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -4410,6 +4410,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 @@ -4424,20 +4426,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'), @@ -4450,12 +4452,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{}, ), ); @@ -4467,7 +4469,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