Bug 10174: Add a tooltip to explain what is a digest
[koha.git] / acqui / updatesupplier.pl
blob65093d8ba243104565ca916ac864763072dea75e
1 #!/usr/bin/perl
3 #script to show suppliers and orders
4 #written by chris@katipo.co.nz 23/2/2000
7 # Copyright 2000-2002 Katipo Communications
8 # Copyright 2008-2009 BibLibre SARL
10 # This file is part of Koha.
12 # Koha is free software; you can redistribute it and/or modify it
13 # under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 3 of the License, or
15 # (at your option) any later version.
17 # Koha is distributed in the hope that it will be useful, but
18 # WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with Koha; if not, see <http://www.gnu.org/licenses>.
25 =head1 NAME
27 updatesupplier.pl
29 =head1 DESCRIPTION
31 this script allow to update or create (if id == 0)
32 a supplier. This script is called from acqui/supplier.pl.
34 =head1 CGI PARAMETERS
36 All informations regarding this supplier are listed on input parameter.
37 Here is the list :
39 supplier, id, company, company_postal, physical, company_phone,
40 physical, company_phone, company_fax, website, company_email, notes,
41 status, publishers_imprints, list_currency, gst, list_gst, invoice_gst,
42 discount, gstrate, contact_name, contact_position, contact_phone,
43 contact_altphone, contact_fax, contact_email, contact_notes,
44 contact_claimacquisition, contact_claimissues, contact_acqprimary,
45 contact_serialsprimary.
47 =cut
49 use strict;
50 use warnings;
51 use List::Util;
52 use C4::Context;
53 use C4::Auth;
55 use C4::Bookseller qw( ModBookseller AddBookseller );
56 use C4::Bookseller::Contact;
57 use C4::Biblio;
58 use C4::Output;
59 use CGI qw ( -utf8 );
61 my $input=new CGI;
62 my ($template, $loggedinuser, $cookie) = get_template_and_user(
63 { template_name => "",
64 query => $input,
65 type => "intranet",
66 authnotrequired => 0,
67 flagsrequired => { acquisition => 'vendors_manage' },
68 debug => 1,
72 #print $input->header();
73 my $booksellerid=$input->param('booksellerid');
74 #print startpage;
75 my %data;
76 $data{'id'}=$booksellerid;
78 $data{'name'}=$input->param('company');
79 $data{'postal'}=$input->param('company_postal');
80 my $address=$input->param('physical');
81 my @addresses=split('\n',$address);
82 $data{'address1'}=$addresses[0];
83 $data{'address2'}=$addresses[1];
84 $data{'address3'}=$addresses[2];
85 $data{'address4'}=$addresses[3];
86 $data{'phone'}=$input->param('company_phone');
87 $data{'accountnumber'}=$input->param('accountnumber');
88 $data{'fax'}=$input->param('company_fax');
89 $data{'url'}=$input->param('website');
90 # warn "".$data{'contnotes'};
91 $data{'notes'}=$input->param('notes');
92 $data{'active'}=$input->param('status');
94 $data{'listprice'}=$input->param('list_currency');
95 $data{'invoiceprice'}=$input->param('invoice_currency');
96 $data{'gstreg'}=$input->param('gst');
97 $data{'listincgst'}=$input->param('list_gst');
98 $data{'invoiceincgst'}=$input->param('invoice_gst');
99 #have to transform this into fraction so it's easier to use
100 $data{'gstrate'} = $input->param('gstrate');
101 $data{'discount'} = $input->param('discount');
102 $data{deliverytime} = $input->param('deliverytime');
103 $data{'active'}=$input->param('status');
104 my @contacts;
105 my %contact_info;
107 foreach (qw(id name position phone altphone fax email notes claimacquisition claimissues acqprimary serialsprimary)) {
108 $contact_info{$_} = [ $input->param('contact_' . $_) ];
111 for my $cnt (0..scalar(@{$contact_info{'id'}})) {
112 my %contact;
113 my $real_contact;
114 foreach (qw(id name position phone altphone fax email notes claimacquisition claimissues acqprimary serialsprimary)) {
115 $contact{$_} = $contact_info{$_}->[$cnt];
116 $real_contact = 1 if $contact{$_};
118 push @contacts, C4::Bookseller::Contact->new(\%contact) if $real_contact;
121 if($data{'name'}) {
122 if ($data{'id'}){
123 ModBookseller(\%data, \@contacts);
124 } else {
125 $data{id}=AddBookseller(\%data, \@contacts);
127 #redirect to booksellers.pl
128 print $input->redirect("booksellers.pl?booksellerid=".$data{id});
129 } else {
130 print $input->redirect("supplier.pl?op=enter"); # fail silently.