ab958985e797921c09d967264f413bfc405ad94d
[koha-ffzg.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 Koha::Item->_new_from_dbic( $item_rs );
46 }
47
48 =head3 library
49
50 my $library = $checkout->library;
51
52 Return the library in which the transaction took place. Might return I<undef>.
53
54 =cut
55
56 sub library {
57     my ( $self ) = @_;
58     my $library_rs = $self->_result->library;
59     return unless $library_rs;
60     return Koha::Library->_new_from_dbic( $library_rs );
61 }
62
63 =head3 patron
64
65 my $patron = $checkout->patron
66
67 Return the patron for who the checkout has been done
68
69 =cut
70
71 sub patron {
72     my ( $self ) = @_;
73     my $patron_rs = $self->_result->patron;
74     return unless $patron_rs;
75     return Koha::Patron->_new_from_dbic( $patron_rs );
76 }
77
78 =head3 issuer
79
80 my $issuer = $checkout->issuer
81
82 Return the patron by whom the checkout was done
83
84 =cut
85
86 sub issuer {
87     my ( $self ) = @_;
88     my $issuer_rs = $self->_result->issuer;
89     return unless $issuer_rs;
90     return Koha::Patron->_new_from_dbic( $issuer_rs );
91 }
92
93 =head3 renewals
94
95   my $renewals = $checkout->renewals;
96
97 Return a Koha::Checkouts::Renewals set attached to this checkout
98
99 =cut
100
101 sub renewals {
102     my ( $self ) = @_;
103     my $renewals_rs = $self->_result->renewals;
104     return unless $renewals_rs;
105     return Koha::Checkouts::Renewals->_new_from_dbic( $renewals_rs );
106 }
107
108 =head3 anonymize
109
110     $checkout->anonymize();
111
112 Anonymize the given I<Koha::Old::Checkout> object.
113
114 =cut
115
116 sub anonymize {
117     my ($self) = @_;
118
119     my $anonymous_id = C4::Context->preference('AnonymousPatron');
120
121     Koha::Exceptions::SysPref::NotSet->throw( syspref => 'AnonymousPatron' )
122         unless $anonymous_id;
123
124     return $self->update( { borrowernumber => $anonymous_id } );
125 }
126
127 =head3 to_api_mapping
128
129 This method returns the mapping for representing a Koha::Old::Checkout object
130 on the API.
131
132 =cut
133
134 sub to_api_mapping {
135     return {
136         issue_id        => 'checkout_id',
137         borrowernumber  => 'patron_id',
138         itemnumber      => 'item_id',
139         date_due        => 'due_date',
140         branchcode      => 'library_id',
141         returndate      => 'checkin_date',
142         lastreneweddate => 'last_renewed_date',
143         issuedate       => 'checkout_date',
144         notedate        => 'note_date',
145         noteseen        => 'note_seen',
146     };
147 }
148
149 =head2 Internal methods
150
151 =head3 _type
152
153 =cut
154
155 sub _type {
156     return 'OldIssue';
157 }
158
159 1;