Bug 4133 Ensure that orders have a valid quantity received
[koha.git] / acqui / supplier.pl
blob42b23b038a4e7ec28bf602f088c471e261a24038
1 #!/usr/bin/perl
4 #script to show display basket of orders
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 under the
12 # terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
14 # version.
16 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License along with
21 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA 02111-1307 USA
24 =head1 NAME
26 supplier.pl
28 =head1 DESCRIPTION
29 this script shows the details for a bookseller given on input arg.
30 It allows to edit & save information about this bookseller.
32 =head1 CGI PARAMETERS
34 =over 4
36 =item supplierid
37 To know the bookseller this script has to display details.
39 =back
41 =cut
43 use strict;
44 use C4::Auth;
45 use C4::Acquisition;
46 use C4::Contract;
47 use C4::Biblio;
48 use C4::Output;
49 use C4::Dates qw/format_date /;
50 use CGI;
52 use C4::Bookseller;
53 use C4::Budgets;
55 my $query = new CGI;
56 my $id = $query->param('supplierid');
57 my @booksellers = GetBookSellerFromId($id) if $id;
58 my $count = scalar @booksellers;
59 my $op = $query->param('op') || "display";
60 my ($template, $loggedinuser, $cookie) = get_template_and_user(
61 { template_name => "acqui/supplier.tmpl",
62 query => $query,
63 type => "intranet",
64 authnotrequired => 0,
65 flagsrequired => { acquisition => 'vendors_manage' },
66 debug => 1,
69 my $GST = $booksellers[0]->{'gstrate'} || C4::Context->preference("gist");
70 $GST *= 100;
72 my @contracts = GetContracts($id);
73 my $contractcount = scalar(@contracts);
74 $template->param(hascontracts => 1) if ($contractcount > 0);
76 #build array for currencies
77 if ($op eq "display") {
79 # get contracts
80 my @contracts = @{GetContract( { booksellerid => $id } )};
82 # format dates
83 for ( @contracts ) {
84 $$_{contractstartdate} = format_date($$_{contractstartdate});
85 $$_{contractenddate} = format_date($$_{contractenddate});
88 $template->param(
89 id => $id,
90 name => $booksellers[0]->{'name'},
91 postal => $booksellers[0]->{'postal'},
92 address1 => $booksellers[0]->{'address1'},
93 address2 => $booksellers[0]->{'address2'},
94 address3 => $booksellers[0]->{'address3'},
95 address4 => $booksellers[0]->{'address4'},
96 phone => $booksellers[0]->{'phone'},
97 fax => $booksellers[0]->{'fax'},
98 url => $booksellers[0]->{'url'},
99 contact => $booksellers[0]->{'contact'},
100 contpos => $booksellers[0]->{'contpos'},
101 contphone => $booksellers[0]->{'contphone'},
102 contaltphone => $booksellers[0]->{'contaltphone'},
103 contfax => $booksellers[0]->{'contfax'},
104 contemail => $booksellers[0]->{'contemail'},
105 contnotes => $booksellers[0]->{'contnotes'},
106 notes => $booksellers[0]->{'notes'},
107 active => $booksellers[0]->{'active'},
108 gstreg => $booksellers[0]->{'gstreg'},
109 listincgst => $booksellers[0]->{'listincgst'},
110 invoiceincgst => $booksellers[0]->{'invoiceincgst'},
111 gstrate => $booksellers[0]->{'gstrate'}*100,
112 discount => $booksellers[0]->{'discount'},
113 invoiceprice => $booksellers[0]->{'invoiceprice'},
114 listprice => $booksellers[0]->{'listprice'},
115 GST => $GST,
116 basketcount => $booksellers[0]->{'basketcount'},
117 contracts => \@contracts
120 elsif ($op eq 'delete') {
121 &DelBookseller($id);
122 print $query->redirect("/cgi-bin/koha/acqui/acqui-home.pl");
123 exit;
124 } else {
125 my @currencies = GetCurrencies();
126 my $count = scalar @currencies;
128 my @loop_pricescurrency;
129 my @loop_invoicecurrency;
130 for (my $i=0;$i<$count;$i++) {
131 if ($booksellers[0]->{'listprice'} eq $currencies[$i]->{'currency'}) {
132 push @loop_pricescurrency, { currency => "<option selected=\"selected\" value=\"$currencies[$i]->{'currency'}\">$currencies[$i]->{'currency'}</option>" };
133 } else {
134 push @loop_pricescurrency, { currency => "<option value=\"$currencies[$i]->{'currency'}\">$currencies[$i]->{'currency'}</option>"};
136 if ($booksellers[0]->{'invoiceprice'} eq $currencies[$i]->{'currency'}) {
137 push @loop_invoicecurrency, { currency => "<option selected=\"selected\" value=\"$currencies[$i]->{'currency'}\">$currencies[$i]->{'currency'}</option>"};
138 } else {
139 push @loop_invoicecurrency, { currency => "<option value=\"$currencies[$i]->{'currency'}\">$currencies[$i]->{'currency'}</option>"};
142 my $GST = $booksellers[0]->{'gstrate'} || C4::Context->preference("gist");
143 $GST *= 100;
144 $template->param(
145 id => $id,
146 name => $booksellers[0]->{'name'},
147 postal => $booksellers[0]->{'postal'},
148 address1 => $booksellers[0]->{'address1'},
149 address2 => $booksellers[0]->{'address2'},
150 address3 => $booksellers[0]->{'address3'},
151 address4 => $booksellers[0]->{'address4'},
152 phone => $booksellers[0]->{'phone'},
153 fax => $booksellers[0]->{'fax'},
154 url => $booksellers[0]->{'url'},
155 contact => $booksellers[0]->{'contact'},
156 contpos => $booksellers[0]->{'contpos'},
157 contphone => $booksellers[0]->{'contphone'},
158 contaltphone => $booksellers[0]->{'contaltphone'},
159 contfax => $booksellers[0]->{'contfax'},
160 contemail => $booksellers[0]->{'contemail'},
161 contnotes => $booksellers[0]->{'contnotes'},
162 notes => $booksellers[0]->{'notes'},
163 active => $id?$booksellers[0]->{'active'}:1, # set active ON by default for supplier add (id empty for add)
164 gstreg => $booksellers[0]->{'gstreg'},
165 listincgst => $booksellers[0]->{'listincgst'},
166 invoiceincgst => $booksellers[0]->{'invoiceincgst'},
167 gstrate => $booksellers[0]->{'gstrate'}*100,
168 discount => $booksellers[0]->{'discount'},
169 loop_pricescurrency => \@loop_pricescurrency,
170 loop_invoicecurrency => \@loop_invoicecurrency,
171 GST => $GST,
172 enter => 1,
178 output_html_with_http_headers $query, $cookie, $template->output;