Bug 13517 - Show waiting date on reserve/request.pl
[koha.git] / Koha / Hold.pm
1 package Koha::Hold;
2
3 # Copyright ByWater Solutions 2014
4 #
5 # This file is part of Koha.
6 #
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.
11 #
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.
15 #
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.
19
20 use Modern::Perl;
21
22 use Carp;
23
24 use C4::Context qw(preference);
25 use Koha::DateUtils qw(dt_from_string);
26
27 use Koha::Borrowers;
28 use Koha::Biblios;
29 use Koha::Branches;
30 use Koha::Items;
31
32 use base qw(Koha::Object);
33
34 =head1 NAME
35
36 Koha::Hold - Koha Hold object class
37
38 =head1 API
39
40 =head2 Class Methods
41
42 =cut
43
44 =head3 waiting_expires_on
45
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' ).
49
50 =cut
51
52 sub waiting_expires_on {
53     my ($self) = @_;
54
55     my $found = $self->found;
56     return unless $found && $found eq 'W';
57
58     my $ReservesMaxPickUpDelay = C4::Context->preference('ReservesMaxPickUpDelay');
59     return unless $ReservesMaxPickUpDelay;
60
61     my $dt = dt_from_string( $self->waitingdate() );
62
63     $dt->add( days => $ReservesMaxPickUpDelay );
64
65     return $dt;
66 }
67
68 =head3 is_found
69
70 Returns true if hold is a waiting or in transit
71
72 =cut
73
74 sub is_found {
75     my ($self) = @_;
76
77     return 0 unless $self->found();
78     return 1 if $self->found() eq 'W';
79     return 1 if $self->found() eq 'T';
80 }
81
82 =head3 is_waiting
83
84 Returns true if hold is a waiting hold
85
86 =cut
87
88 sub is_waiting {
89     my ($self) = @_;
90
91     my $found = $self->found;
92     return $found && $found eq 'W';
93 }
94
95 =head3 is_in_transit
96
97 Returns true if hold is a in_transit hold
98
99 =cut
100
101 sub is_in_transit {
102     my ($self) = @_;
103
104     return 0 unless $self->found();
105     return $self->found() eq 'T';
106 }
107
108 =head3 biblio
109
110 Returns the related Koha::Biblio object for this hold
111
112 =cut
113
114 sub biblio {
115     my ($self) = @_;
116
117     $self->{_biblio} ||= Koha::Biblios->find( $self->biblionumber() );
118
119     return $self->{_biblio};
120 }
121
122 =head3 item
123
124 Returns the related Koha::Item object for this Hold
125
126 =cut
127
128 sub item {
129     my ($self) = @_;
130
131     $self->{_item} ||= Koha::Items->find( $self->itemnumber() );
132
133     return $self->{_item};
134 }
135
136 =head3 branch
137
138 Returns the related Koha::Branch object for this Hold
139
140 =cut
141
142 sub branch {
143     my ($self) = @_;
144
145     $self->{_branch} ||= Koha::Branches->find( $self->branchcode() );
146
147     return $self->{_branch};
148 }
149
150 =head3 borrower
151
152 Returns the related Koha::Borrower object for this Hold
153
154 =cut
155
156 sub borrower {
157     my ($self) = @_;
158
159     $self->{_borrower} ||= Koha::Borrowers->find( $self->borrowernumber() );
160
161     return $self->{_borrower};
162 }
163
164 =head3 type
165
166 =cut
167
168 sub type {
169     return 'Reserve';
170 }
171
172 =head1 AUTHOR
173
174 Kyle M Hall <kyle@bywatersolutions.com>
175
176 =cut
177
178 1;