3 #script to show suppliers and orders
4 #written by chris@katipo.co.nz 23/2/2000
6 # Copyright 2000-2002 Katipo Communications
7 # Copyright 2008-2009 BibLibre SARL
9 # This file is part of Koha.
11 # Koha is free software; you can redistribute it and/or modify it
12 # under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 3 of the License, or
14 # (at your option) any later version.
16 # Koha is distributed in the hope that it will be useful, but
17 # WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with Koha; if not, see <http://www.gnu.org/licenses>.
30 this script allow to update or create (if id == 0)
31 a supplier. This script is called from acqui/supplier.pl.
35 All informations regarding this supplier are listed on input parameter.
38 supplier, id, company, company_postal, physical, company_phone,
39 physical, company_phone, company_fax, website, company_email, notes,
40 status, publishers_imprints, list_currency, gst, list_gst, invoice_gst,
41 discount, tax_rate, contact_name, contact_position, contact_phone,
42 contact_altphone, contact_fax, contact_email, contact_notes,
43 contact_claimacquisition, contact_claimissues, contact_acqprimary,
44 contact_serialsprimary.
49 use List::MoreUtils qw( any );
51 use C4::Auth qw( checkauth );
55 use Koha::Acquisition::Bookseller::Contacts;
56 use Koha::Acquisition::Booksellers;
61 checkauth( $input, 0, { acquisition => 'vendors_manage' }, 'intranet' );
63 my $op = $input->param('op') // q{};
65 my $booksellerid = $input->param('booksellerid');
67 my $address = $input->param('physical');
68 my @addresses = split( '\n', $address );
71 $data{'id'} = $booksellerid;
73 $data{'name'} = $input->param('company');
74 $data{'postal'} = $input->param('company_postal');
75 $data{'address1'} = $addresses[0];
76 $data{'address2'} = $addresses[1];
77 $data{'address3'} = $addresses[2];
78 $data{'address4'} = $addresses[3];
79 $data{'phone'} = $input->param('company_phone');
80 $data{'accountnumber'} = $input->param('accountnumber');
81 $data{'type'} = $input->param('vendor_type');
82 $data{'fax'} = $input->param('company_fax');
83 $data{'url'} = $input->param('website');
84 $data{'notes'} = $input->param('notes');
85 $data{'active'} = $input->param('status');
86 $data{'listprice'} = $input->param('list_currency');
87 $data{'invoiceprice'} = $input->param('invoice_currency');
88 $data{'gstreg'} = $input->param('gst');
89 $data{'listincgst'} = $input->param('list_gst');
90 $data{'invoiceincgst'} = $input->param('invoice_gst');
91 $data{'tax_rate'} = $input->param('tax_rate'); #have to transform this into fraction so it's easier to use
92 $data{'discount'} = $input->param('discount');
93 $data{deliverytime} = $input->param('deliverytime');
94 $data{'active'} = $input->param('status');
96 my @aliases = $input->multi_param('alias');
101 qw(id name position phone altphone fax email notes orderacquisition claimacquisition claimissues acqprimary serialsprimary)
104 $contact_info{$_} = [ $input->multi_param( 'contact_' . $_ ) ];
107 for my $cnt ( 0 .. scalar( @{ $contact_info{'id'} } ) ) {
111 qw(id name position phone altphone fax email notes orderacquisition claimacquisition claimissues acqprimary serialsprimary)
114 $contact{$_} = $contact_info{$_}->[$cnt];
115 $real_contact = 1 if $contact{$_};
117 push @contacts, \%contact if $real_contact;
120 if ( $op eq 'cud-add' ) {
125 $bookseller = Koha::Acquisition::Booksellers->find( $data{id} )->set( \%data )->store;
127 # Delete existing contacts
128 $bookseller->contacts->delete;
132 delete $data{id}; # Remove the key if exists
133 $bookseller = Koha::Acquisition::Bookseller->new( \%data )->store;
134 $data{id} = $bookseller->id;
138 for my $contact (@contacts) {
139 $contact->{booksellerid} = $data{id};
140 Koha::Acquisition::Bookseller::Contact->new($contact)->store;
144 $bookseller->aliases( [ map { { alias => $_ } } @aliases ] );
147 my @interface_counters = $input->multi_param('interface_counter');
149 for my $counter (@interface_counters) {
151 for my $attr (qw(name type uri login password account_email notes)) {
152 my $v = $input->param("interface_${attr}_${counter}");
153 $interface->{$attr} = $v;
155 push @interfaces, $interface if any { defined && length } values %$interface;
157 $bookseller->interfaces( \@interfaces );
159 #redirect to booksellers.pl
160 print $input->redirect( "booksellers.pl?booksellerid=" . $data{id} );
162 print $input->redirect("supplier.pl?op=enter"); # fail silently.