Bug 15552: Better wording of intranetreadinghistory
[koha.git] / Koha / Hold.pm
blob871f3e1e6eedf3a5c9bbed8fee84dc9279561ee1
1 package Koha::Hold;
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
10 # version.
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.
20 use Modern::Perl;
22 use Carp;
24 use C4::Context qw(preference);
26 use Koha::DateUtils qw(dt_from_string);
27 use Koha::Borrowers;
28 use Koha::Biblios;
29 use Koha::Items;
30 use Koha::Libraries;
32 use base qw(Koha::Object);
34 =head1 NAME
36 Koha::Hold - Koha Hold object class
38 =head1 API
40 =head2 Class Methods
42 =cut
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' ).
50 =cut
52 sub waiting_expires_on {
53 my ($self) = @_;
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 );
65 return $dt;
68 =head3 is_found
70 Returns true if hold is a waiting or in transit
72 =cut
74 sub is_found {
75 my ($self) = @_;
77 return 0 unless $self->found();
78 return 1 if $self->found() eq 'W';
79 return 1 if $self->found() eq 'T';
82 =head3 is_waiting
84 Returns true if hold is a waiting hold
86 =cut
88 sub is_waiting {
89 my ($self) = @_;
91 my $found = $self->found;
92 return $found && $found eq 'W';
95 =head3 is_in_transit
97 Returns true if hold is a in_transit hold
99 =cut
101 sub is_in_transit {
102 my ($self) = @_;
104 return 0 unless $self->found();
105 return $self->found() eq 'T';
108 =head3 is_cancelable
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.
116 =cut
118 sub is_cancelable {
119 my ($self) = @_;
121 return 1 unless $self->is_found();
122 return 0 if $self->is_in_transit();
123 return 1 if $self->is_waiting();
124 return 0;
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
133 =cut
135 sub is_at_destination {
136 my ($self) = @_;
138 return $self->is_waiting() && ( $self->branchcode() eq $self->item()->holdingbranch() );
141 =head3 biblio
143 Returns the related Koha::Biblio object for this hold
145 =cut
147 sub biblio {
148 my ($self) = @_;
150 $self->{_biblio} ||= Koha::Biblios->find( $self->biblionumber() );
152 return $self->{_biblio};
155 =head3 item
157 Returns the related Koha::Item object for this Hold
159 =cut
161 sub item {
162 my ($self) = @_;
164 $self->{_item} ||= Koha::Items->find( $self->itemnumber() );
166 return $self->{_item};
169 =head3 branch
171 Returns the related Koha::Library object for this Hold
173 =cut
175 sub branch {
176 my ($self) = @_;
178 $self->{_branch} ||= Koha::Libraries->find( $self->branchcode() );
180 return $self->{_branch};
183 =head3 borrower
185 Returns the related Koha::Borrower object for this Hold
187 =cut
189 sub borrower {
190 my ($self) = @_;
192 $self->{_borrower} ||= Koha::Borrowers->find( $self->borrowernumber() );
194 return $self->{_borrower};
197 =head3 type
199 =cut
201 sub type {
202 return 'Reserve';
205 =head1 AUTHOR
207 Kyle M Hall <kyle@bywatersolutions.com>
209 =cut