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
44 =head3 waiting_expires_on
46 Returns a DateTime for the date a waiting holds expires on.
47 Returns undef if the system peference ReservesMaxPickUpDelay is not set.
48 Returns undef if the hold is not waiting ( found = 'W' ).
52 sub waiting_expires_on {
55 my $found = $self->found;
56 return unless $found && $found eq 'W';
58 my $ReservesMaxPickUpDelay = C4::Context->preference('ReservesMaxPickUpDelay');
59 return unless $ReservesMaxPickUpDelay;
61 my $dt = dt_from_string( $self->waitingdate() );
63 $dt->add( days => $ReservesMaxPickUpDelay );
70 Returns true if hold is a waiting or in transit
77 return 0 unless $self->found();
78 return 1 if $self->found() eq 'W';
79 return 1 if $self->found() eq 'T';
84 Returns true if hold is a waiting hold
91 my $found = $self->found;
92 return $found && $found eq 'W';
97 Returns true if hold is a in_transit hold
104 return 0 unless $self->found();
105 return $self->found() eq 'T';
110 Returns true if hold is a cancelable hold
112 Holds may be canceled if they not found, or
113 are found and waiting. A hold found but in
114 transit cannot be canceled.
121 return 1 unless $self->is_found();
122 return 0 if $self->is_in_transit();
123 return 1 if $self->is_waiting();
127 =head3 is_at_destination
129 Returns true if hold is waiting
130 and the hold's pickup branch matches
131 the hold item's holding branch
135 sub is_at_destination {
138 return $self->is_waiting() && ( $self->branchcode() eq $self->item()->holdingbranch() );
143 Returns the related Koha::Biblio object for this hold
150 $self->{_biblio} ||= Koha::Biblios->find( $self->biblionumber() );
152 return $self->{_biblio};
157 Returns the related Koha::Item object for this Hold
164 $self->{_item} ||= Koha::Items->find( $self->itemnumber() );
166 return $self->{_item};
171 Returns the related Koha::Library object for this Hold
178 $self->{_branch} ||= Koha::Libraries->find( $self->branchcode() );
180 return $self->{_branch};
185 Returns the related Koha::Borrower object for this Hold
192 $self->{_borrower} ||= Koha::Borrowers->find( $self->borrowernumber() );
194 return $self->{_borrower};
207 Kyle M Hall <kyle@bywatersolutions.com>