Bug 17689: Add the Koha::Checkout->is_overdue method
[koha.git] / Koha / Checkout.pm
1 package Koha::Checkout;
2
3 # Copyright ByWater Solutions 2015
4 # Copyright 2016 Koha Development Team
5 #
6 # This file is part of Koha.
7 #
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 3 of the License, or (at your option) any later
11 # version.
12 #
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License along
18 # with Koha; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
21 use Modern::Perl;
22
23 use Carp;
24
25 use Koha::Database;
26 use DateTime;
27 use Koha::DateUtils;
28
29 use base qw(Koha::Object);
30
31 =head1 NAME
32
33 Koha::Checkout - Koha Checkout object class
34
35 =head1 API
36
37 =head2 Class Methods
38
39 =cut
40
41 =head3 is_overdue
42
43 my  $is_overdue = $checkout->is_overdue( [ $reference_dt ] );
44
45 Return 1 if the checkout is overdue.
46
47 A reference date can be passed, in this case it will be used, otherwise today
48 will be the reference date.
49
50 =cut
51
52 sub is_overdue {
53     my ( $self, $dt ) = @_;
54     $dt ||= DateTime->now( time_zone => C4::Context->tz );
55     my $is_overdue =
56       DateTime->compare( dt_from_string( $self->date_due, 'sql' ), $dt ) == -1
57       ? 1
58       : 0;
59     return $is_overdue;
60 }
61
62 =head3 type
63
64 =cut
65
66 sub _type {
67     return 'Issue';
68 }
69
70 =head1 AUTHOR
71
72 Kyle M Hall <kyle@bywatersolutions.com>
73
74 Jonathan Druart <jonathan.druart@bugs.koha-community.org>
75
76 =cut
77
78 1;