Bug 12222: members-update.tt has a giant hash variable
[koha.git] / acqui / supplier.pl
blobe2c688f435d254b346cde54b83eb760eb2986f46
1 #!/usr/bin/perl
3 # Copyright 2000-2002 Katipo Communications
4 # Copyright 2008-2009 BibLibre SARL
5 # Copyright 2010 PTFS Europe Ltd
7 # This file is part of Koha.
9 # Koha is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
12 # version.
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License along
19 # with Koha; if not, write to the Free Software Foundation, Inc.,
20 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 =head1 NAME
24 supplier.pl
26 =head1 DESCRIPTION
28 this script shows the details for a bookseller given on input arg.
29 It allows to edit & save information about this bookseller.
31 =head1 CGI PARAMETERS
33 =over 4
35 =item booksellerid
37 To know the bookseller this script has to display details.
39 =back
41 =cut
43 use strict;
44 use warnings;
45 use C4::Auth;
46 use C4::Contract;
47 use C4::Biblio;
48 use C4::Output;
49 use CGI;
51 use C4::Bookseller qw( GetBookSellerFromId DelBookseller );
52 use C4::Budgets;
54 my $query = CGI->new;
55 my $booksellerid = $query->param('booksellerid');
56 my $supplier = {};
57 if ($booksellerid) {
58 $supplier = GetBookSellerFromId($booksellerid);
60 my $op = $query->param('op') || 'display';
61 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
62 { template_name => 'acqui/supplier.tt',
63 query => $query,
64 type => 'intranet',
65 authnotrequired => 0,
66 flagsrequired => { acquisition => '*' },
67 debug => 1,
71 #build array for currencies
72 if ( $op eq 'display' ) {
73 my $contracts = GetContracts( { booksellerid => $booksellerid } );
75 $template->param(
76 booksellerid => $booksellerid,
77 name => $supplier->{'name'},
78 postal => $supplier->{'postal'},
79 address1 => $supplier->{'address1'},
80 address2 => $supplier->{'address2'},
81 address3 => $supplier->{'address3'},
82 address4 => $supplier->{'address4'},
83 phone => $supplier->{'phone'},
84 accountnumber => $supplier->{'accountnumber'},
85 fax => $supplier->{'fax'},
86 url => $supplier->{'url'},
87 contact => $supplier->{'contact'},
88 contpos => $supplier->{'contpos'},
89 contphone => $supplier->{'contphone'},
90 contaltphone => $supplier->{'contaltphone'},
91 contfax => $supplier->{'contfax'},
92 contemail => $supplier->{'contemail'},
93 contnotes => $supplier->{'contnotes'},
94 notes => $supplier->{'notes'},
95 active => $supplier->{'active'},
96 gstreg => $supplier->{'gstreg'},
97 listincgst => $supplier->{'listincgst'},
98 invoiceincgst => $supplier->{'invoiceincgst'},
99 gstrate => $supplier->{'gstrate'} + 0.0,
100 discount => $supplier->{'discount'},
101 deliverytime => $supplier->{deliverytime},
102 invoiceprice => $supplier->{'invoiceprice'},
103 listprice => $supplier->{'listprice'},
104 basketcount => $supplier->{'basketcount'},
105 subscriptioncount => $supplier->{'subscriptioncount'},
106 contracts => $contracts,
108 } elsif ( $op eq 'delete' ) {
109 # no further message needed for the user
110 # the DELETE button only appears in the template if basketcount == 0
111 if ( $supplier->{'basketcount'} == 0 ) {
112 DelBookseller($booksellerid);
114 print $query->redirect('/cgi-bin/koha/acqui/acqui-home.pl');
115 exit;
116 } else {
117 my @currencies = GetCurrencies();
118 my $loop_currency;
119 my $active_currency = GetCurrency();
120 my $active_listprice = $supplier->{'listprice'};
121 my $active_invoiceprice = $supplier->{'invoiceprice'};
122 if (!$supplier->{listprice}) {
123 $active_listprice = $active_currency->{currency};
125 if (!$supplier->{invoiceprice}) {
126 $active_invoiceprice = $active_currency->{currency};
128 for (@currencies) {
129 push @{$loop_currency},
131 currency => $_->{currency},
132 listprice => ( $_->{currency} eq $active_listprice ),
133 invoiceprice => ( $_->{currency} eq $active_invoiceprice ),
137 # get option values from gist syspref
138 my @gst_values = map {
139 option => $_ + 0.0
140 }, split( '\|', C4::Context->preference("gist") );
142 $template->param(
143 booksellerid => $booksellerid,
144 name => $supplier->{'name'},
145 postal => $supplier->{'postal'},
146 address1 => $supplier->{'address1'},
147 address2 => $supplier->{'address2'},
148 address3 => $supplier->{'address3'},
149 address4 => $supplier->{'address4'},
150 phone => $supplier->{'phone'},
151 accountnumber=> $supplier->{'accountnumber'},
152 fax => $supplier->{'fax'},
153 url => $supplier->{'url'},
154 contact => $supplier->{'contact'},
155 contpos => $supplier->{'contpos'},
156 contphone => $supplier->{'contphone'},
157 contaltphone => $supplier->{'contaltphone'},
158 contfax => $supplier->{'contfax'},
159 contemail => $supplier->{'contemail'},
160 contnotes => $supplier->{'contnotes'},
161 notes => $supplier->{'notes'},
162 # set active ON by default for supplier add (id empty for add)
163 active => $booksellerid ? $supplier->{'active'} : 1,
164 gstreg => $supplier->{'gstreg'},
165 listincgst => $supplier->{'listincgst'},
166 invoiceincgst => $supplier->{'invoiceincgst'},
167 gstrate => $supplier->{gstrate} ? $supplier->{'gstrate'}+0.0 : 0,
168 gst_values => \@gst_values,
169 discount => $supplier->{'discount'},
170 deliverytime => $supplier->{deliverytime},
171 loop_currency => $loop_currency,
172 enter => 1,
176 output_html_with_http_headers $query, $cookie, $template->output;