Bug 33974: (QA follow-up) Remove superflous import
[koha.git] / Koha / Acquisition / Bookseller.pm
1 package Koha::Acquisition::Bookseller;
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::Acquisition::Bookseller::Aliases;
21 use Koha::Acquisition::Bookseller::Contacts;
22 use Koha::Acquisition::Bookseller::Interfaces;
23 use Koha::Subscriptions;
24
25 use base qw( Koha::Object );
26
27 =head1 NAME
28
29 Koha::Acquisition::Bookseller Object class
30
31 =head1 API
32
33 =head2 Class methods
34
35 =head3 baskets
36
37     my $vendor  = Koha::Acquisition::Booksellers->find( $id );
38     my @baskets = $vendor->baskets();
39
40 Returns the list of baskets for the vendor
41
42 =cut
43
44 sub baskets {
45     my ( $self ) = @_;
46     my $baskets_rs = $self->_result->aqbaskets;
47     return Koha::Acquisition::Baskets->_new_from_dbic( $baskets_rs );
48 }
49
50 =head3 contacts
51
52     my $vendor   = Koha::Acquisition::Booksellers->find( $id );
53     my @contacts = $vendor->contacts();
54
55 Returns the list of contacts for the vendor
56
57 =cut
58
59 sub contacts {
60     my ($self) = @_;
61     my $contacts_rs = $self->_result->aqcontacts;
62     return Koha::Acquisition::Bookseller::Contacts->_new_from_dbic( $contacts_rs );
63 }
64
65 =head3 subscriptions
66
67     my $vendor        = Koha::Acquisition::Booksellers->find( $id );
68     my $subscriptions = $vendor->subscriptions();
69
70 Returns the list of subscriptions for the vendor
71
72 =cut
73
74 sub subscriptions {
75     my ($self) = @_;
76
77     # FIXME FK missing at DB level
78     return Koha::Subscriptions->search( { aqbooksellerid => $self->id } );
79 }
80
81 =head3 aliases
82
83     my $aliases = $vendor->aliases
84
85     $vendor->aliases([{ alias => 'one alias'}]);
86
87 =cut
88
89 sub aliases {
90     my ($self, $aliases) = @_;
91
92     if ($aliases) {
93         my $schema = $self->_result->result_source->schema;
94         $schema->txn_do(
95             sub {
96                 $self->aliases->delete;
97                 for my $alias (@$aliases) {
98                     $self->_result->add_to_aqbookseller_aliases($alias);
99                 }
100             }
101         );
102     }
103
104     my $rs = $self->_result->aqbookseller_aliases;
105     return Koha::Acquisition::Bookseller::Aliases->_new_from_dbic( $rs );
106 }
107
108 =head3 interfaces
109
110     my $interfaces = $vendor->interfaces
111
112     $vendor->interfaces(\@interfaces);
113
114 =cut
115
116 sub interfaces {
117     my ($self, $interfaces) = @_;
118
119     if ($interfaces) {
120         my $schema = $self->_result->result_source->schema;
121         $schema->txn_do(
122             sub {
123                 $self->interfaces->delete;
124                 for my $interface (@$interfaces) {
125                     Koha::Acquisition::Bookseller::Interface->new(
126                         {
127                             %$interface,
128                             vendor_id => $self->id,
129                         }
130                     )->store;
131                 }
132             }
133         );
134     }
135
136     my $rs = $self->_result->aqbookseller_interfaces;
137     return Koha::Acquisition::Bookseller::Interfaces->_new_from_dbic( $rs );
138 }
139
140
141 =head3 to_api_mapping
142
143 This method returns the mapping for representing a Koha::Acquisition::Bookseller object
144 on the API.
145
146 =cut
147
148 sub to_api_mapping {
149     return {
150         listprice       => 'list_currency',
151         invoiceprice    => 'invoice_currency',
152         gstreg          => 'gst',
153         listincgst      => 'list_includes_gst',
154         invoiceincgst   => 'invoice_includes_gst'
155     };
156 }
157
158 =head2 Internal methods
159
160 =head3 _type
161
162 =cut
163
164 sub _type {
165     return 'Aqbookseller';
166 }
167
168 1;