Bug 24545: Fix license statements
[koha.git] / 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
25 use base qw( Koha::Object Koha::Object::Mixin::AdditionalFields );
26
27 =head1 NAME
28
29 Koha::Acquisition::Basket - Koha Basket Object class
30
31 =head1 API
32
33 =head2 Class Methods
34
35 =cut
36
37 =head3 bookseller
38
39 Returns the vendor
40
41 =cut
42
43 sub bookseller {
44     my ($self) = @_;
45     my $bookseller_rs = $self->_result->booksellerid;
46     return Koha::Acquisition::Bookseller->_new_from_dbic( $bookseller_rs );
47 }
48
49 =head3 basket_group
50
51 Returns the basket group associated to this basket
52
53 =cut
54
55 sub basket_group {
56     my ($self) = @_;
57     my $basket_group_rs = $self->_result->basketgroupid;
58     return unless $basket_group_rs;
59     return Koha::Acquisition::BasketGroup->_new_from_dbic( $basket_group_rs );
60 }
61
62 =head3 effective_create_items
63
64 Returns C<create_items> for this basket, falling back to C<AcqCreateItem> if unset.
65
66 =cut
67
68 sub effective_create_items {
69     my ( $self ) = @_;
70
71     return $self->create_items || C4::Context->preference('AcqCreateItem');
72 }
73
74 =head3 to_api
75
76     my $json = $basket->to_api;
77
78 Overloaded method that returns a JSON representation of the Koha::Acquisition::Basket object,
79 suitable for API output.
80
81 =cut
82
83 sub to_api {
84     my ( $self, $params ) = @_;
85
86     my $json = $self->SUPER::to_api( $params );
87
88     $json->{closed} = ( $self->closedate )
89                                     ? Mojo::JSON->true
90                                     : Mojo::JSON->false;
91
92     return $json;
93 }
94
95 =head3 to_api_mapping
96
97 This method returns the mapping for representing a Koha::Acquisition::Basket object
98 on the API.
99
100 =cut
101
102 sub to_api_mapping {
103     return {
104         basketno                => 'basket_id',
105         basketname              => 'name',
106         booksellernote          => 'vendor_note',
107         contractnumber          => 'contract_id',
108         creationdate            => 'creation_date',
109         closedate               => 'close_date',
110         booksellerid            => 'vendor_id',
111         authorisedby            => 'authorised_by',
112         booksellerinvoicenumber => undef,
113         basketgroupid           => 'basket_group_id',
114         deliveryplace           => 'delivery_place',
115         billingplace            => 'billing_place',
116         branch                  => 'library_id',
117         is_standing             => 'standing'
118     };
119 }
120
121 =head2 Internal methods
122
123 =head3 _type
124
125 =cut
126
127 sub _type {
128     return 'Aqbasket';
129 }
130
131 =head1 AUTHOR
132
133 Aleisha Amohia <aleisha@catalyst.net.nz>
134 Catalyst IT
135
136 =cut
137
138 1;