Bug 18177: remove aqbooksellers.booksellerfax
[srvgit] / Koha / Acquisition / Basket.pm
1 package Koha::Acquisition::Basket;
2
3 # Copyright 2017 Aleisha Amohia <aleisha@catalyst.net.nz>
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20 use Modern::Perl;
21
22 use Koha::Database;
23 use Koha::Acquisition::BasketGroups;
24 use Koha::Patrons;
25
26 use base qw( Koha::Object Koha::Object::Mixin::AdditionalFields );
27
28 =head1 NAME
29
30 Koha::Acquisition::Basket - Koha Basket Object class
31
32 =head1 API
33
34 =head2 Class methods
35
36 =cut
37
38 =head3 bookseller
39
40 Returns the vendor
41
42 =cut
43
44 sub bookseller {
45     my ($self) = @_;
46     my $bookseller_rs = $self->_result->booksellerid;
47     return Koha::Acquisition::Bookseller->_new_from_dbic( $bookseller_rs );
48 }
49
50 =head3 creator
51
52     my $creator = $basket->creator;
53
54 Returns the I<Koha::Patron> for the basket creator.
55
56 =cut
57
58 sub creator {
59     my ($self) = @_;
60     my $borrowernumber = $self->authorisedby; # FIXME missing FK here
61     return unless $borrowernumber;
62     return Koha::Patrons->find( $borrowernumber );
63 }
64
65 =head3 basket_group
66
67 Returns the basket group associated to this basket
68
69 =cut
70
71 sub basket_group {
72     my ($self) = @_;
73
74     my $basket_group_rs = $self->_result->basket_group;
75     return unless $basket_group_rs;
76     return Koha::Acquisition::BasketGroup->_new_from_dbic( $basket_group_rs );
77 }
78
79 =head3 effective_create_items
80
81 Returns C<create_items> for this basket, falling back to C<AcqCreateItem> if unset.
82
83 =cut
84
85 sub effective_create_items {
86     my ( $self ) = @_;
87
88     return $self->create_items || C4::Context->preference('AcqCreateItem');
89 }
90
91 =head3 to_api
92
93     my $json = $basket->to_api;
94
95 Overloaded method that returns a JSON representation of the Koha::Acquisition::Basket object,
96 suitable for API output.
97
98 =cut
99
100 sub to_api {
101     my ( $self, $params ) = @_;
102
103     my $json = $self->SUPER::to_api( $params );
104
105     $json->{closed} = ( $self->closedate )
106                                     ? Mojo::JSON->true
107                                     : Mojo::JSON->false;
108
109     return $json;
110 }
111
112 =head3 to_api_mapping
113
114 This method returns the mapping for representing a Koha::Acquisition::Basket object
115 on the API.
116
117 =cut
118
119 sub to_api_mapping {
120     return {
121         basketno                => 'basket_id',
122         basketname              => 'name',
123         booksellernote          => 'vendor_note',
124         contractnumber          => 'contract_id',
125         creationdate            => 'creation_date',
126         closedate               => 'close_date',
127         booksellerid            => 'vendor_id',
128         authorisedby            => 'creator_id',
129         booksellerinvoicenumber => undef,
130         basketgroupid           => 'basket_group_id',
131         deliveryplace           => 'delivery_library_id',
132         billingplace            => 'billing_library_id',
133         branch                  => 'library_id',
134         is_standing             => 'standing'
135     };
136 }
137
138 =head2 Internal methods
139
140 =head3 _type
141
142 =cut
143
144 sub _type {
145     return 'Aqbasket';
146 }
147
148 =head1 AUTHOR
149
150 Aleisha Amohia <aleisha@catalyst.net.nz>
151 Catalyst IT
152
153 =cut
154
155 1;