From 05a83010d8aff67241794ce15f6a8320ea338264 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 22 Nov 2019 12:31:09 +0000 Subject: [PATCH] Bug 24075: Backdating a return to the exact due date and time results in the fine not being refunded When you use the date picker or book drop mode and check in an item that is due on that date, a fine is assessed and not refunded. For example: item 12345 is due on 11/19/2109 23:59. On 11/20/2019 I check the item in using date picker/book drop setting the check in date to 11/19/2019 23:59, the patron is charged a fine, and the fine is not cleared as would be expected, since the item is being checked in before it is overdue. Test Plan: 1) Back date a checkout so it is overdue 2) Run fines.pl to generate the fine 3) Return the item, backdating to the same date/time is was due 4) Note the fine was not removed 5) Apply this patch 6) Repeat steps 1-3 7) Fine should be zeroed out now! Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi Signed-off-by: Martin Renvoize (cherry picked from commit 39cc13d070e1613b4a903ec5e0e2513ebd561285) Signed-off-by: Fridolin Somers --- C4/Circulation.pm | 6 ++---- C4/Overdues.pm | 4 ++++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index e1cf7bf07b..41472682ef 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -1948,17 +1948,15 @@ sub AddReturn { # case of a return of document (deal with issues and holdingbranch) if ($doreturn) { - my $is_overdue; die "The item is not issed and cannot be returned" unless $issue; # Just in case... $patron or warn "AddReturn without current borrower"; - $is_overdue = $issue->is_overdue( $return_date ); if ($patron) { eval { MarkIssueReturned( $borrowernumber, $item->itemnumber, $return_date, $patron->privacy ); }; unless ( $@ ) { - if ( C4::Context->preference('CalculateFinesOnReturn') && $is_overdue && !$item->itemlost ) { + if ( C4::Context->preference('CalculateFinesOnReturn') && !$item->itemlost ) { _CalculateAndUpdateFine( { issue => $issue, item => $item_unblessed, borrower => $patron_unblessed, return_date => $return_date } ); } } else { @@ -2860,7 +2858,7 @@ sub AddRenewal { my $circ_library = Koha::Libraries->find( _GetCircControlBranch($item_unblessed, $patron_unblessed) ); - if ( C4::Context->preference('CalculateFinesOnReturn') && $issue->is_overdue ) { + if ( C4::Context->preference('CalculateFinesOnReturn') ) { _CalculateAndUpdateFine( { issue => $issue, item => $item_unblessed, borrower => $patron_unblessed } ); } _FixOverduesOnReturn( $borrowernumber, $itemnumber ); diff --git a/C4/Overdues.pm b/C4/Overdues.pm index 2a617335bc..437df34957 100644 --- a/C4/Overdues.pm +++ b/C4/Overdues.pm @@ -232,6 +232,10 @@ or "Final Notice". But CalcFine never defined any value. sub CalcFine { my ( $item, $bortype, $branchcode, $due_dt, $end_date ) = @_; + + # Skip calculations if item is not overdue + return ( 0, 0, 0 ) unless (DateTime->compare( $due_dt, $end_date ) == -1); + my $start_date = $due_dt->clone(); # get issuingrules (fines part will be used) my $itemtype = $item->{itemtype} || $item->{itype}; -- 2.39.5