Bug 13853: Show waiting hold expiration date for waiting holds in holds ajax datatable
[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::Branches;
26 use Koha::Biblios;
27 use Koha::Items;
28 use Koha::DateUtils qw(dt_from_string);
29
30 use base qw(Koha::Object);
31
32 =head1 NAME
33
34 Koha::Hold - Koha Hold object class
35
36 =head1 API
37
38 =head2 Class Methods
39
40 =cut
41
42 =head3 waiting_expires_on
43
44 Returns a DateTime for the date a waiting holds expires on.
45 Returns undef if the system peference ReservesMaxPickUpDelay is not set.
46 Returns undef if the hold is not waiting ( found = 'W' ).
47
48 =cut
49
50 sub waiting_expires_on {
51     my ($self) = @_;
52
53     return unless $self->found() eq 'W';
54
55     my $ReservesMaxPickUpDelay = C4::Context->preference('ReservesMaxPickUpDelay');
56     return unless $ReservesMaxPickUpDelay;
57
58     my $dt = dt_from_string( $self->waitingdate() );
59
60     $dt->add( days => $ReservesMaxPickUpDelay );
61
62     return $dt;
63 }
64
65 =head3 is_waiting
66
67 Returns true if hold is a waiting hold
68
69 =cut
70
71 sub is_waiting {
72     my ($self) = @_;
73
74     return $self->found() eq 'W';
75 }
76
77 =head3 biblio
78
79 Returns the related Koha::Biblio object for this hold
80
81 =cut
82
83 sub biblio {
84     my ($self) = @_;
85
86     $self->{_biblio} ||= Koha::Biblios->find( $self->biblionumber() );
87
88     return $self->{_biblio};
89 }
90
91 =head3 item
92
93 Returns the related Koha::Item object for this Hold
94
95 =cut
96
97 sub item {
98     my ($self) = @_;
99
100     $self->{_item} ||= Koha::Items->find( $self->itemnumber() );
101
102     return $self->{_item};
103 }
104
105 =head3 branch
106
107 Returns the related Koha::Branch object for this Hold
108
109 =cut
110
111 sub branch {
112     my ($self) = @_;
113
114     $self->{_branch} ||= Koha::Branches->find( $self->branchcode() );
115
116     return $self->{_branch};
117 }
118
119 =head3 type
120
121 =cut
122
123 sub type {
124     return 'Reserve';
125 }
126
127 =head1 AUTHOR
128
129 Kyle M Hall <kyle@bywatersolutions.com>
130
131 =cut
132
133 1;