From 3f7db16eab306fce589368e6f5c06421b058fadd Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Sun, 30 Sep 2018 12:20:54 +0000 Subject: [PATCH] Bug 8367: Altered expirationdate calc in Koha/Hold.pm and altered C4/Reserves/CancelExpiredReserves() Added check for holidays to expirationdate calculation in Koha/Hold.pm so the expirationdate respects holidays as the lastpickupdate does. Changed C4/Reserve/CancelExpiredReserves() to check the reserves.lastpickupdate rather than rserves.expirationdate. Therefore it will now automatically expire holds if they have not been picked up within the time period specified in the hold pickup delay defined in the issuing rules (which is added to reserves.waitingdate to calculate the reserves.lastpickupdate) AND the ExpireReservesMaxPickUpDelay syspref is enabled. Sponsored-By: Brimbank Library, Australia --- C4/Reserves.pm | 10 ++-------- Koha/Hold.pm | 22 ++++++++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 1e17052..a8e12bb 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -765,10 +765,6 @@ sub GetLastPickupDate { } elsif ( $controlbranch eq "PatronLibrary" ) { $branchcode = $borrower->branchcode; } - warn 'getlastpickup'; - warn $branchcode; - warn $borrower->{'categorycode'}; - warn $item->{itype}; my $issuingrule = Koha::IssuingRules->get_effective_issuing_rule({ branchcode => $branchcode, categorycode => $borrower->{'categorycode'}, @@ -961,7 +957,7 @@ sub CheckReserves { CancelExpiredReserves(); -Cancels all reserves with an expiration date from before today. +Cancels all reserves with an lastpickupdate value from before today. =cut @@ -969,14 +965,12 @@ sub CancelExpiredReserves { my $today = dt_from_string(); my $cancel_on_holidays = C4::Context->preference('ExpireReservesOnHolidays'); my $expireWaiting = C4::Context->preference('ExpireReservesMaxPickUpDelay'); - my $dtf = Koha::Database->new->schema->storage->datetime_parser; - my $params = { expirationdate => { '<', $dtf->format_date($today) } }; + my $params = { lastpickupdate => { '<', $dtf->format_date($today) } }; $params->{found} = undef unless $expireWaiting; # FIXME To move to Koha::Holds->search_expired (?) my $holds = Koha::Holds->search( $params ); - while ( my $hold = $holds->next ) { my $calendar = Koha::Calendar->new( branchcode => $hold->branchcode ); next if !$cancel_on_holidays && $calendar->is_holiday( $today ); diff --git a/Koha/Hold.pm b/Koha/Hold.pm index 0618afd..7d15529 100644 --- a/Koha/Hold.pm +++ b/Koha/Hold.pm @@ -163,7 +163,6 @@ sub set_waiting { $requested_expiration = dt_from_string($self->expirationdate); } - my $max_pickup_delay = C4::Context->preference("ReservesMaxPickUpDelay"); my $cancel_on_holidays = C4::Context->preference('ExpireReservesOnHolidays'); my $calendar = Koha::Calendar->new( branchcode => $self->branchcode ); @@ -172,7 +171,6 @@ sub set_waiting { my $patron = Koha::Patrons->find( {borrowernumber => $self->borrowernumber} ); my $item = Koha::Items->find( $self->itemnumber() ); my $hold = Koha::Holds->find( $self->reserve_id ); -# my $lastpickupdate = C4::Reserves->GetLastPickupDate( $hold, $item, $patron); # Get the controlbranch my $controlbranch = C4::Reserves->GetReservesControlBranch( $item, $patron ); @@ -184,17 +182,25 @@ sub set_waiting { $branchcode = $patron->branchcode; } - warn $branchcode; - warn $patron->categorycode; - warn $item->itype; - my $issuingrule = Koha::IssuingRules->get_effective_issuing_rule({ + my $issuingrule = Koha::IssuingRules->get_effective_issuing_rule({ branchcode => $branchcode, categorycode => $patron->categorycode, itemtype => $item->itype, - }); + }); if ( defined $issuingrule->holdspickupwait && $issuingrule->holdspickupwait > 0) { - $expirationdate->add(days => $issuingrule->holdspickupwait); + if ( defined($issuingrule) && defined $issuingrule->holdspickupwait && $issuingrule->holdspickupwait > 0 ) { #If holdspickupwait is <= 0, it means this feature is disabled for this type of material. + if ($cancel_on_holidays) { + $expirationdate->add(days => $issuingrule->holdspickupwait); + } else { + $expirationdate->add(days => $issuingrule->holdspickupwait); + my $is_holiday = $calendar->is_holiday( $expirationdate ); + while ( $is_holiday ) { + $expirationdate->add( days => 1 ); + $is_holiday = $calendar->is_holiday( $expirationdate ); + } + } + } } if ( C4::Context->preference("ExcludeHolidaysFromMaxPickUpDelay") ) { -- 2.1.4