From 9744690da41ba2977805806c937ebd3714a1d131 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 16 Aug 2019 08:32:55 +0100 Subject: [PATCH] Bug 23382: Fix logic in C4::Circulation::CanBookBeIssued It looks like over progressive rebases of bug 20912 a clause was lost within CanBookBeIssued such that a fatal error may be triggered if an item with no corresponding itemtype was passed into the routine. Additionally the we were passing a Koha::Library object to CalcDateDue rather than a branchcode which resulted in a different duedate being used in 'CanBookBeIssued' when compared to 'AddIssue'. Signed-off-by: Jonathan Druart Signed-off-by: Nick Clemens Signed-off-by: Martin Renvoize (cherry picked from commit f8e2c489cb668aab9e7484c2dd67c1c05f37b2a5) Signed-off-by: Lucas Gass --- C4/Circulation.pm | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index cd725bda1f..88794b49fd 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -708,8 +708,7 @@ sub CanBookBeIssued { unless ( $duedate ) { my $issuedate = $now->clone(); - my $branch = $circ_library; - $duedate = CalcDateDue( $issuedate, $effective_itemtype, $branch, $patron_unblessed ); + $duedate = CalcDateDue( $issuedate, $effective_itemtype, $circ_library->branchcode, $patron_unblessed ); # Offline circ calls AddIssue directly, doesn't run through here # So issuingimpossible should be ok. @@ -999,16 +998,23 @@ sub CanBookBeIssued { if ( $patron->branchcode ne $userenv->{branch} ); } } + # # CHECK IF THERE IS RENTAL CHARGES. RENTAL MUST BE CONFIRMED BY THE BORROWER # my $rentalConfirmation = C4::Context->preference("RentalFeesCheckoutConfirmation"); - - if ( $rentalConfirmation ){ + if ($rentalConfirmation) { my ($rentalCharge) = GetIssuingCharges( $item_object->itemnumber, $patron->borrowernumber ); - my $itemtype = Koha::ItemTypes->find( $item_object->itype ); # GetItem sets effective itemtype - $rentalCharge += $fees->accumulate_rentalcharge({ from => dt_from_string(), to => $duedate }); - if ( $rentalCharge > 0 ){ + + my $itemtype_object = Koha::ItemTypes->find( $item_object->effective_itemtype ); + if ($itemtype_object) { + my $accumulate_charge = $fees->accumulate_rentalcharge(); + if ( $accumulate_charge > 0 ) { + $rentalCharge += $accumulate_charge; + } + } + + if ( $rentalCharge > 0 ) { $needsconfirmation{RENTALCHARGE} = $rentalCharge; } } @@ -1477,7 +1483,7 @@ sub AddIssue { if ( $itemtype_object ) { my $accumulate_charge = $fees->accumulate_rentalcharge(); if ( $accumulate_charge > 0 ) { - AddIssuingCharge( $issue, $accumulate_charge, 'Daily rental' ) if $accumulate_charge > 0; + AddIssuingCharge( $issue, $accumulate_charge, 'RENT_DAILY' ); $charge += $accumulate_charge; $item_unblessed->{charge} = $charge; } -- 2.39.5