Bug 13030: Show waiting hold expiration date for waiting holds on circulation.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::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 biblio
66
67 Returns the related Koha::Biblio object for this hold
68
69 =cut
70
71 sub biblio {
72     my ($self) = @_;
73
74     $self->{_biblio} ||= Koha::Biblios->find( $self->biblionumber() );
75
76     return $self->{_biblio};
77 }
78
79 =head3 item
80
81 Returns the related Koha::Item object for this Hold
82
83 =cut
84
85 sub item {
86     my ($self) = @_;
87
88     $self->{_item} ||= Koha::Items->find( $self->itemnumber() );
89
90     return $self->{_item};
91 }
92
93 =head3 branch
94
95 Returns the related Koha::Branch object for this Hold
96
97 =cut
98
99 sub branch {
100     my ($self) = @_;
101
102     $self->{_branch} ||= Koha::Branches->find( $self->branchcode() );
103
104     return $self->{_branch};
105 }
106
107 =head3 type
108
109 =cut
110
111 sub type {
112     return 'Reserve';
113 }
114
115 =head1 AUTHOR
116
117 Kyle M Hall <kyle@bywatersolutions.com>
118
119 =cut
120
121 1;