3 # Copyright ByWater Solutions 2014
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 use Data::Dumper qw(Dumper);
25 use C4::Context qw(preference);
28 use Koha::DateUtils qw(dt_from_string output_pref);
34 use base qw(Koha::Object);
38 Koha::Hold - Koha Hold object class
48 my $hold = $hold->suspend_hold( $suspend_until_dt );
53 my ( $self, $dt ) = @_;
55 $dt = $dt ? $dt->clone()->truncate( to => 'day' ) : undef;
57 if ( $self->is_waiting ) { # We can't suspend waiting holds
58 carp "Unable to suspend waiting hold!";
63 $self->suspend_until( $dt );
67 logaction( 'HOLDS', 'SUSPEND', $self->reserve_id, Dumper($self->unblessed) )
68 if C4::Context->preference('HoldsLog');
75 my $hold = $hold->resume();
83 $self->suspend_until( undef );
87 logaction( 'HOLDS', 'RESUME', $self->reserve_id, Dumper($self->unblessed) )
88 if C4::Context->preference('HoldsLog');
102 my $deleted = $self->SUPER::delete($self);
104 logaction( 'HOLDS', 'DELETE', $self->reserve_id, Dumper($self->unblessed) )
105 if C4::Context->preference('HoldsLog');
110 =head3 waiting_expires_on
112 Returns a DateTime for the date a waiting holds expires on.
113 Returns undef if the system peference ReservesMaxPickUpDelay is not set.
114 Returns undef if the hold is not waiting ( found = 'W' ).
118 sub waiting_expires_on {
121 my $found = $self->found;
122 return unless $found && $found eq 'W';
124 my $ReservesMaxPickUpDelay = C4::Context->preference('ReservesMaxPickUpDelay');
125 return unless $ReservesMaxPickUpDelay;
127 my $dt = dt_from_string( $self->waitingdate() );
129 $dt->add( days => $ReservesMaxPickUpDelay );
139 my ( $self, $transferToDo ) = @_;
144 $self->found('T')->store();
148 my $today = dt_from_string();
151 waitingdate => $today->ymd,
154 if ( C4::Context->preference("ExpireReservesMaxPickUpDelay") ) {
155 my $max_pickup_delay = C4::Context->preference("ReservesMaxPickUpDelay");
156 my $cancel_on_holidays = C4::Context->preference('ExpireReservesOnHolidays');
157 my $calendar = Koha::Calendar->new( branchcode => $self->branchcode );
159 my $expirationdate = $today->clone;
160 $expirationdate->add(days => $max_pickup_delay);
162 if ( C4::Context->preference("ExcludeHolidaysFromMaxPickUpDelay") ) {
163 $expirationdate = $calendar->days_forward( dt_from_string($self->waitingdate), $max_pickup_delay );
166 $values->{expirationdate} = $expirationdate->ymd;
169 $self->set($values)->store();
176 Returns true if hold is a waiting or in transit
183 return 0 unless $self->found();
184 return 1 if $self->found() eq 'W';
185 return 1 if $self->found() eq 'T';
190 Returns true if hold is a waiting hold
197 my $found = $self->found;
198 return $found && $found eq 'W';
203 Returns true if hold is a in_transit hold
210 return 0 unless $self->found();
211 return $self->found() eq 'T';
216 Returns true if hold is a cancelable hold
218 Holds may be canceled if they not found, or
219 are found and waiting. A hold found but in
220 transit cannot be canceled.
227 return 1 unless $self->is_found();
228 return 0 if $self->is_in_transit();
229 return 1 if $self->is_waiting();
233 =head3 is_at_destination
235 Returns true if hold is waiting
236 and the hold's pickup branch matches
237 the hold item's holding branch
241 sub is_at_destination {
244 return $self->is_waiting() && ( $self->branchcode() eq $self->item()->holdingbranch() );
249 Returns the related Koha::Biblio object for this hold
256 $self->{_biblio} ||= Koha::Biblios->find( $self->biblionumber() );
258 return $self->{_biblio};
263 Returns the related Koha::Item object for this Hold
270 $self->{_item} ||= Koha::Items->find( $self->itemnumber() );
272 return $self->{_item};
277 Returns the related Koha::Library object for this Hold
284 $self->{_branch} ||= Koha::Libraries->find( $self->branchcode() );
286 return $self->{_branch};
291 Returns the related Koha::Patron object for this Hold
298 $self->{_borrower} ||= Koha::Patrons->find( $self->borrowernumber() );
300 return $self->{_borrower};
305 my $bool = $hold->is_suspended();
312 return $self->suspend();
325 Kyle M Hall <kyle@bywatersolutions.com>