@@ -, +, @@ altered C4/Reserves/CancelExpiredReserves() --- C4/Reserves.pm | 16 ++++++++-------- Koha/Hold.pm | 20 ++++++++++++++------ 2 files changed, 22 insertions(+), 14 deletions(-) --- a/C4/Reserves.pm +++ a/C4/Reserves.pm @@ -724,10 +724,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'}, @@ -740,6 +736,7 @@ sub GetLastPickupDate { } else { $reservebranch = $reserve->branchcode; } + if ( defined($issuingrule) && defined $issuingrule->holdspickupwait && $issuingrule->holdspickupwait > 0 ) { #If holdspickupwait is <= 0, it means this feature is disabled for this type of material. $date->add( days => $issuingrule->holdspickupwait ); my $calendar = Koha::Calendar->new( branchcode => $reservebranch ); @@ -748,6 +745,11 @@ sub GetLastPickupDate { $date->add( days => 1 ); $is_holiday = $calendar->is_holiday( $date ); } + + if ( C4::Context->preference("ExcludeHolidaysFromMaxPickUpDelay") ) { + $date = $calendar->days_forward( dt_from_string(), $issuingrule->holdspickupwait ); + } + $reserve->{lastpickupdate} = $date->ymd(); return $date; } @@ -920,7 +922,7 @@ sub CheckReserves { CancelExpiredReserves(); -Cancels all reserves with an expiration date from before today. +Cancels all reserves with a lastpickupdate value from before today. =cut @@ -928,14 +930,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} = [ { '!=', 'W' }, 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 ); --- a/Koha/Hold.pm +++ a/Koha/Hold.pm @@ -186,7 +186,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 ); @@ -198,9 +197,6 @@ sub set_waiting { $branchcode = $patron->branchcode; } - warn $branchcode; - warn $patron->categorycode; - warn $item->itype; my $issuingrule = Koha::IssuingRules->get_effective_issuing_rule({ branchcode => $branchcode, categorycode => $patron->categorycode, @@ -208,11 +204,23 @@ sub set_waiting { }); 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") ) { - $expirationdate = $calendar->days_forward( dt_from_string(), $issuingrule->{holdspickupwait} ); + $expirationdate = $calendar->days_forward( dt_from_string(), $issuingrule->holdspickupwait ); } # If patron's requested expiration date is prior to the --