Merge branch 'master' into new/bug_7164
[koha.git] / acqui / supplier.pl
blob3faa560f25ef8ec50e185f57ac7023eaf3ceb891
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 supplierid
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 qw/GetContract/;
47 use C4::Biblio;
48 use C4::Output;
49 use C4::Dates qw/format_date /;
50 use CGI;
52 use C4::Bookseller qw( GetBookSellerFromId DelBookseller );
53 use C4::Budgets;
55 my $query = CGI->new;
56 my $id = $query->param('supplierid');
57 my $supplier = {};
58 if ($id) {
59 $supplier = GetBookSellerFromId($id);
61 my $op = $query->param('op') || 'display';
62 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
63 { template_name => 'acqui/supplier.tmpl',
64 query => $query,
65 type => 'intranet',
66 authnotrequired => 0,
67 flagsrequired => { acquisition => '*' },
68 debug => 1,
71 my $seller_gstrate = $supplier->{'gstrate'};
73 # ensure the scalar isn't flagged as a string
74 $seller_gstrate = ( defined $seller_gstrate ) ? $seller_gstrate + 0 : undef;
75 my $tax_rate = $seller_gstrate // C4::Context->preference('gist') // 0;
76 $tax_rate *= 100;
77 #build array for currencies
78 if ( $op eq 'display' ) {
80 my $contracts = GetContract( { booksellerid => $id } );
82 for ( @{$contracts} ) {
83 $_->{contractstartdate} = format_date( $_->{contractstartdate} );
84 $_->{contractenddate} = format_date( $_->{contractenddate} );
87 $template->param(
88 id => $id,
89 name => $supplier->{'name'},
90 postal => $supplier->{'postal'},
91 address1 => $supplier->{'address1'},
92 address2 => $supplier->{'address2'},
93 address3 => $supplier->{'address3'},
94 address4 => $supplier->{'address4'},
95 phone => $supplier->{'phone'},
96 accountnumber => $supplier->{'accountnumber'},
97 fax => $supplier->{'fax'},
98 url => $supplier->{'url'},
99 contact => $supplier->{'contact'},
100 contpos => $supplier->{'contpos'},
101 contphone => $supplier->{'contphone'},
102 contaltphone => $supplier->{'contaltphone'},
103 contfax => $supplier->{'contfax'},
104 contemail => $supplier->{'contemail'},
105 contnotes => $supplier->{'contnotes'},
106 notes => $supplier->{'notes'},
107 active => $supplier->{'active'},
108 gstreg => $supplier->{'gstreg'},
109 listincgst => $supplier->{'listincgst'},
110 invoiceincgst => $supplier->{'invoiceincgst'},
111 discount => $supplier->{'discount'},
112 invoiceprice => $supplier->{'invoiceprice'},
113 listprice => $supplier->{'listprice'},
114 GST => $tax_rate,
115 default_tax => defined($seller_gstrate),
116 basketcount => $supplier->{'basketcount'},
117 contracts => $contracts,
119 } elsif ( $op eq 'delete' ) {
120 DelBookseller($id);
121 print $query->redirect('/cgi-bin/koha/acqui/acqui-home.pl');
122 exit;
123 } else {
124 my @currencies = GetCurrencies();
125 my $loop_currency;
126 my $active_currency = GetCurrency();
127 my $active_listprice = $supplier->{'listprice'};
128 my $active_invoiceprice = $supplier->{'invoiceprice'};
129 if (!$supplier->{listprice}) {
130 $active_listprice = $active_currency->{currency};
132 if (!$supplier->{invoiceprice}) {
133 $active_invoiceprice = $active_currency->{currency};
135 for (@currencies) {
136 push @{$loop_currency},
138 currency => $_->{currency},
139 listprice => ( $_->{currency} eq $active_listprice ),
140 invoiceprice => ( $_->{currency} eq $active_invoiceprice ),
144 my $default_gst_rate = (C4::Context->preference('gist') * 100) || '0.0';
146 my $gstrate = defined $supplier->{gstrate} ? $supplier->{gstrate} * 100 : '';
147 $template->param(
148 id => $id,
149 name => $supplier->{'name'},
150 postal => $supplier->{'postal'},
151 address1 => $supplier->{'address1'},
152 address2 => $supplier->{'address2'},
153 address3 => $supplier->{'address3'},
154 address4 => $supplier->{'address4'},
155 phone => $supplier->{'phone'},
156 accountnumber=> $supplier->{'accountnumber'},
157 fax => $supplier->{'fax'},
158 url => $supplier->{'url'},
159 contact => $supplier->{'contact'},
160 contpos => $supplier->{'contpos'},
161 contphone => $supplier->{'contphone'},
162 contaltphone => $supplier->{'contaltphone'},
163 contfax => $supplier->{'contfax'},
164 contemail => $supplier->{'contemail'},
165 contnotes => $supplier->{'contnotes'},
166 notes => $supplier->{'notes'},
167 # set active ON by default for supplier add (id empty for add)
168 active => $id ? $supplier->{'active'} : 1,
169 gstreg => $supplier->{'gstreg'},
170 listincgst => $supplier->{'listincgst'},
171 invoiceincgst => $supplier->{'invoiceincgst'},
172 gstrate => $gstrate,
173 discount => $supplier->{'discount'},
174 loop_currency => $loop_currency,
175 GST => $tax_rate,
176 enter => 1,
177 default_gst_rate => $default_gst_rate,
181 output_html_with_http_headers $query, $cookie, $template->output;