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.
24 use C4
::Context
qw(preference);
26 use Koha
::DateUtils
qw(dt_from_string);
32 use base
qw(Koha::Object);
36 Koha::Hold - Koha Hold object class
46 my $hold = $hold->suspend_hold( $suspend_until_dt );
51 my ( $self, $dt ) = @_;
53 $dt = $dt ?
$dt->clone()->truncate( to
=> 'day' ) : undef;
55 if ( $self->is_waiting ) { # We can't suspend waiting holds
56 carp
"Unable to suspend waiting hold!";
61 $self->suspend_until( $dt );
70 my $hold = $hold->resume();
78 $self->suspend_until( undef );
85 =head3 waiting_expires_on
87 Returns a DateTime for the date a waiting holds expires on.
88 Returns undef if the system peference ReservesMaxPickUpDelay is not set.
89 Returns undef if the hold is not waiting ( found = 'W' ).
93 sub waiting_expires_on
{
96 my $found = $self->found;
97 return unless $found && $found eq 'W';
99 my $ReservesMaxPickUpDelay = C4
::Context
->preference('ReservesMaxPickUpDelay');
100 return unless $ReservesMaxPickUpDelay;
102 my $dt = dt_from_string
( $self->waitingdate() );
104 $dt->add( days
=> $ReservesMaxPickUpDelay );
111 Returns true if hold is a waiting or in transit
118 return 0 unless $self->found();
119 return 1 if $self->found() eq 'W';
120 return 1 if $self->found() eq 'T';
125 Returns true if hold is a waiting hold
132 my $found = $self->found;
133 return $found && $found eq 'W';
138 Returns true if hold is a in_transit hold
145 return 0 unless $self->found();
146 return $self->found() eq 'T';
151 Returns true if hold is a cancelable hold
153 Holds may be canceled if they not found, or
154 are found and waiting. A hold found but in
155 transit cannot be canceled.
162 return 1 unless $self->is_found();
163 return 0 if $self->is_in_transit();
164 return 1 if $self->is_waiting();
168 =head3 is_at_destination
170 Returns true if hold is waiting
171 and the hold's pickup branch matches
172 the hold item's holding branch
176 sub is_at_destination
{
179 return $self->is_waiting() && ( $self->branchcode() eq $self->item()->holdingbranch() );
184 Returns the related Koha::Biblio object for this hold
191 $self->{_biblio
} ||= Koha
::Biblios
->find( $self->biblionumber() );
193 return $self->{_biblio
};
198 Returns the related Koha::Item object for this Hold
205 $self->{_item
} ||= Koha
::Items
->find( $self->itemnumber() );
207 return $self->{_item
};
212 Returns the related Koha::Library object for this Hold
219 $self->{_branch
} ||= Koha
::Libraries
->find( $self->branchcode() );
221 return $self->{_branch
};
226 Returns the related Koha::Patron object for this Hold
233 $self->{_borrower
} ||= Koha
::Patrons
->find( $self->borrowernumber() );
235 return $self->{_borrower
};
240 my $bool = $hold->is_suspended();
247 return $self->suspend();
260 Kyle M Hall <kyle@bywatersolutions.com>