Bug 30807: Migrate to patron-title in pay and paycollect
[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 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 anonymize
94
95     $checkout->anonymize();
96
97 Anonymize the given I<Koha::Old::Checkout> object.
98
99 =cut
100
101 sub anonymize {
102     my ($self) = @_;
103
104     my $anonymous_id = C4::Context->preference('AnonymousPatron');
105
106     Koha::Exceptions::SysPref::NotSet->throw( syspref => 'AnonymousPatron' )
107         unless $anonymous_id;
108
109     return $self->update( { borrowernumber => $anonymous_id } );
110 }
111
112 =head3 to_api_mapping
113
114 This method returns the mapping for representing a Koha::Old::Checkout object
115 on the API.
116
117 =cut
118
119 sub to_api_mapping {
120     return {
121         issue_id        => 'checkout_id',
122         borrowernumber  => 'patron_id',
123         itemnumber      => 'item_id',
124         date_due        => 'due_date',
125         branchcode      => 'library_id',
126         returndate      => 'checkin_date',
127         lastreneweddate => 'last_renewed_date',
128         issuedate       => 'checkout_date',
129         notedate        => 'note_date',
130         noteseen        => 'note_seen',
131     };
132 }
133
134 =head2 Internal methods
135
136 =head3 _type
137
138 =cut
139
140 sub _type {
141     return 'OldIssue';
142 }
143
144 1;