Bug 32482: (follow-up) Add markup comments
[koha.git] / Koha / Old / Checkout.pm
1 package Koha::Old::Checkout;
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18 use Modern::Perl;
19
20 use Koha::Database;
21 use Koha::Exceptions::SysPref;
22 use Koha::Libraries;
23
24 use base qw(Koha::Object);
25
26 =head1 NAME
27
28 Koha::Old:Checkout - Koha checkout object for returned items
29
30 =head1 API
31
32 =head2 Class methods
33
34 =head3 item
35
36 my $item = $checkout->item;
37
38 Return the checked out item
39
40 =cut
41
42 sub item {
43     my ( $self ) = @_;
44     my $item_rs = $self->_result->item;
45     return unless $item_rs;
46     return Koha::Item->_new_from_dbic( $item_rs );
47 }
48
49 =head3 account_lines
50
51 my $account_lines = $checkout->account_lines;
52
53 Return the checked out account_lines
54
55 =cut
56
57 sub account_lines {
58     my ( $self ) = @_;
59     my $account_lines_rs = $self->_result->account_lines;
60     return Koha::Account::Lines->_new_from_dbic( $account_lines_rs );
61 }
62
63 =head3 library
64
65 my $library = $checkout->library;
66
67 Return the library in which the transaction took place. Might return I<undef>.
68
69 =cut
70
71 sub library {
72     my ( $self ) = @_;
73     my $library_rs = $self->_result->library;
74     return unless $library_rs;
75     return Koha::Library->_new_from_dbic( $library_rs );
76 }
77
78 =head3 patron
79
80 my $patron = $checkout->patron
81
82 Return the patron for who the checkout has been done
83
84 =cut
85
86 sub patron {
87     my ( $self ) = @_;
88     my $patron_rs = $self->_result->patron;
89     return unless $patron_rs;
90     return Koha::Patron->_new_from_dbic( $patron_rs );
91 }
92
93 =head3 issuer
94
95 my $issuer = $checkout->issuer
96
97 Return the patron by whom the checkout was done
98
99 =cut
100
101 sub issuer {
102     my ( $self ) = @_;
103     my $issuer_rs = $self->_result->issuer;
104     return unless $issuer_rs;
105     return Koha::Patron->_new_from_dbic( $issuer_rs );
106 }
107
108 =head3 renewals
109
110   my $renewals = $checkout->renewals;
111
112 Return a Koha::Checkouts::Renewals set attached to this checkout
113
114 =cut
115
116 sub renewals {
117     my ( $self ) = @_;
118     my $renewals_rs = $self->_result->renewals;
119     return unless $renewals_rs;
120     return Koha::Checkouts::Renewals->_new_from_dbic( $renewals_rs );
121 }
122
123 =head3 anonymize
124
125     $checkout->anonymize();
126
127 Anonymize the given I<Koha::Old::Checkout> object.
128
129 =cut
130
131 sub anonymize {
132     my ($self) = @_;
133
134     my $anonymous_id = C4::Context->preference('AnonymousPatron');
135
136     Koha::Exceptions::SysPref::NotSet->throw( syspref => 'AnonymousPatron' )
137         unless $anonymous_id;
138
139     return $self->update( { borrowernumber => $anonymous_id } );
140 }
141
142 =head3 to_api_mapping
143
144 This method returns the mapping for representing a Koha::Old::Checkout object
145 on the API.
146
147 =cut
148
149 sub to_api_mapping {
150     return {
151         issue_id        => 'checkout_id',
152         borrowernumber  => 'patron_id',
153         itemnumber      => 'item_id',
154         date_due        => 'due_date',
155         branchcode      => 'library_id',
156         returndate      => 'checkin_date',
157         lastreneweddate => 'last_renewed_date',
158         issuedate       => 'checkout_date',
159         notedate        => 'note_date',
160         noteseen        => 'note_seen',
161     };
162 }
163
164 =head2 Internal methods
165
166 =head3 _type
167
168 =cut
169
170 sub _type {
171     return 'OldIssue';
172 }
173
174 1;