Bug 33103: Add the ability to create vendor aliases
[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::Subscriptions;
23
24 use base qw( Koha::Object );
25
26 =head1 NAME
27
28 Koha::Acquisition::Bookseller Object class
29
30 =head1 API
31
32 =head2 Class methods
33
34 =head3 baskets
35
36     my $vendor  = Koha::Acquisition::Booksellers->find( $id );
37     my @baskets = $vendor->baskets();
38
39 Returns the list of baskets for the vendor
40
41 =cut
42
43 sub baskets {
44     my ( $self ) = @_;
45     my $baskets_rs = $self->_result->aqbaskets;
46     return Koha::Acquisition::Baskets->_new_from_dbic( $baskets_rs );
47 }
48
49 =head3 contacts
50
51     my $vendor   = Koha::Acquisition::Booksellers->find( $id );
52     my @contacts = $vendor->contacts();
53
54 Returns the list of contacts for the vendor
55
56 =cut
57
58 sub contacts {
59     my ($self) = @_;
60     my $contacts_rs = $self->_result->aqcontacts;
61     return Koha::Acquisition::Bookseller::Contacts->_new_from_dbic( $contacts_rs );
62 }
63
64 =head3 subscriptions
65
66     my $vendor        = Koha::Acquisition::Booksellers->find( $id );
67     my $subscriptions = $vendor->subscriptions();
68
69 Returns the list of subscriptions for the vendor
70
71 =cut
72
73 sub subscriptions {
74     my ($self) = @_;
75
76     # FIXME FK missing at DB level
77     return Koha::Subscriptions->search( { aqbooksellerid => $self->id } );
78 }
79
80 =head3 aliases
81
82     my $aliases = $vendor->aliases
83
84     $vendor->aliases([{ alias => 'one alias'}]);
85
86 =cut
87
88 sub aliases {
89     my ($self, $aliases) = @_;
90
91     if ($aliases) {
92         my $schema = $self->_result->result_source->schema;
93         $schema->txn_do(
94             sub {
95                 $self->aliases->delete;
96                 for my $alias (@$aliases) {
97                     $self->_result->add_to_aqbookseller_aliases($alias);
98                 }
99             }
100         );
101     }
102
103     my $rs = $self->_result->aqbookseller_aliases;
104     return Koha::Acquisition::Bookseller::Aliases->_new_from_dbic( $rs );
105 }
106
107
108 =head3 to_api_mapping
109
110 This method returns the mapping for representing a Koha::Acquisition::Bookseller object
111 on the API.
112
113 =cut
114
115 sub to_api_mapping {
116     return {
117         listprice       => 'list_currency',
118         invoiceprice    => 'invoice_currency',
119         gstreg          => 'gst',
120         listincgst      => 'list_includes_gst',
121         invoiceincgst   => 'invoice_includes_gst'
122     };
123 }
124
125 =head2 Internal methods
126
127 =head3 _type
128
129 =cut
130
131 sub _type {
132     return 'Aqbookseller';
133 }
134
135 1;