Bug 15260: Modify next/prev_open_day
[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 use Koha::Items;
29
30 use base qw(Koha::Object);
31
32 =head1 NAME
33
34 Koha::Checkout - Koha Checkout object class
35
36 =head1 API
37
38 =head2 Class Methods
39
40 =cut
41
42 =head3 is_overdue
43
44 my  $is_overdue = $checkout->is_overdue( [ $reference_dt ] );
45
46 Return 1 if the checkout is overdue.
47
48 A reference date can be passed, in this case it will be used, otherwise today
49 will be the reference date.
50
51 =cut
52
53 sub is_overdue {
54     my ( $self, $dt ) = @_;
55     $dt ||= DateTime->now( time_zone => C4::Context->tz );
56     my $is_overdue =
57       DateTime->compare( dt_from_string( $self->date_due, 'sql' ), $dt ) == -1
58       ? 1
59       : 0;
60     return $is_overdue;
61 }
62
63 =head3 item
64
65 my $item = $checkout->item;
66
67 Return the checked out item
68
69 =cut
70
71 sub item {
72     my ( $self ) = @_;
73     my $item_rs = $self->_result->item;
74     return Koha::Item->_new_from_dbic( $item_rs );
75 }
76
77 =head3 patron
78
79 my $patron = $checkout->patron
80
81 Return the patron for who the checkout has been done
82
83 =cut
84
85 sub patron {
86     my ( $self ) = @_;
87     my $patron_rs = $self->_result->borrower;
88     return Koha::Patron->_new_from_dbic( $patron_rs );
89 }
90
91 =head3 to_api_mapping
92
93 This method returns the mapping for representing a Koha::Checkout object
94 on the API.
95
96 =cut
97
98 sub to_api_mapping {
99     return {
100         issue_id        => 'checkout_id',
101         borrowernumber  => 'patron_id',
102         itemnumber      => 'item_id',
103         date_due        => 'due_date',
104         branchcode      => 'library_id',
105         returndate      => 'checkin_date',
106         lastreneweddate => 'last_renewed_date',
107         issuedate       => 'checkout_date',
108         notedate        => 'note_date',
109     };
110 }
111
112 =head2 Internal methods
113
114 =head3 _type
115
116 =cut
117
118 sub _type {
119     return 'Issue';
120 }
121
122 =head1 AUTHOR
123
124 Kyle M Hall <kyle@bywatersolutions.com>
125
126 Jonathan Druart <jonathan.druart@bugs.koha-community.org>
127
128 =cut
129
130 1;