Bug 2505 - Add commented use warnings where missing in the acqui/ directory
[koha.git] / acqui / supplier.pl
1 #!/usr/bin/perl
2
3
4 #script to show display basket of orders
5
6 # Copyright 2000-2002 Katipo Communications
7 # Copyright 2008-2009 BibLibre SARL
8 #
9 # This file is part of Koha.
10 #
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.
15 #
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.
19 #
20 # You should have received a copy of the GNU General Public License along
21 # with Koha; if not, write to the Free Software Foundation, Inc.,
22 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23
24 =head1 NAME
25
26 supplier.pl
27
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.
31
32 =head1 CGI PARAMETERS
33
34 =over 4
35
36 =item supplierid
37 To know the bookseller this script has to display details.
38
39 =back
40
41 =cut
42
43 use strict;
44 #use warnings; FIXME - Bug 2505
45 use C4::Auth;
46 use C4::Acquisition;
47 use C4::Contract;
48 use C4::Biblio;
49 use C4::Output;
50 use C4::Dates qw/format_date /;
51 use CGI;
52
53 use C4::Bookseller;
54 use C4::Budgets;
55
56 my $query       = new CGI;
57 my $id          = $query->param('supplierid');
58 my @booksellers = GetBookSellerFromId($id) if $id;
59 my $count       = scalar @booksellers;
60 my $op          = $query->param('op') || "display";
61 my ($template, $loggedinuser, $cookie) = get_template_and_user(
62         {   template_name   => "acqui/supplier.tmpl",
63                 query           => $query,
64                 type            => "intranet",
65                 authnotrequired => 0,
66                 flagsrequired   => { acquisition => 'vendors_manage' },
67                 debug           => 1,
68         }
69 );
70 my $GST = $booksellers[0]->{'gstrate'} || C4::Context->preference("gist");
71 $GST *= 100;
72
73 my @contracts = GetContracts($id);
74 my $contractcount = scalar(@contracts);
75 $template->param(hascontracts => 1) if ($contractcount > 0);
76
77 #build array for currencies
78 if ($op eq "display") {
79
80     # get contracts
81     my @contracts = @{GetContract( { booksellerid => $id } )};
82
83     # format dates
84     for ( @contracts ) {
85         $$_{contractstartdate} = format_date($$_{contractstartdate});
86         $$_{contractenddate}   = format_date($$_{contractenddate});
87     }
88
89         $template->param(
90                 id            => $id,
91                 name          => $booksellers[0]->{'name'},
92                 postal        => $booksellers[0]->{'postal'},
93                 address1      => $booksellers[0]->{'address1'},
94                 address2      => $booksellers[0]->{'address2'},
95                 address3      => $booksellers[0]->{'address3'},
96                 address4      => $booksellers[0]->{'address4'},
97                 phone         => $booksellers[0]->{'phone'},
98                 fax           => $booksellers[0]->{'fax'},
99                 url           => $booksellers[0]->{'url'},
100                 contact       => $booksellers[0]->{'contact'},
101                 contpos       => $booksellers[0]->{'contpos'},
102                 contphone     => $booksellers[0]->{'contphone'},
103                 contaltphone  => $booksellers[0]->{'contaltphone'},
104                 contfax       => $booksellers[0]->{'contfax'},
105                 contemail     => $booksellers[0]->{'contemail'},
106                 contnotes     => $booksellers[0]->{'contnotes'},
107                 notes         => $booksellers[0]->{'notes'},
108                 active        => $booksellers[0]->{'active'},
109                 gstreg        => $booksellers[0]->{'gstreg'},
110                 listincgst    => $booksellers[0]->{'listincgst'},
111                 invoiceincgst => $booksellers[0]->{'invoiceincgst'},
112                 gstrate       => $booksellers[0]->{'gstrate'}*100,
113                 discount      => $booksellers[0]->{'discount'},
114                 invoiceprice  => $booksellers[0]->{'invoiceprice'},
115                 listprice     => $booksellers[0]->{'listprice'},
116                 GST           => $GST,
117                 basketcount   => $booksellers[0]->{'basketcount'},
118                 contracts     => \@contracts
119         );
120 }
121 elsif ($op eq 'delete') {
122   &DelBookseller($id);
123   print $query->redirect("/cgi-bin/koha/acqui/acqui-home.pl");
124   exit;
125 } else {
126     my @currencies = GetCurrencies();
127     my $count = scalar @currencies;
128     
129     my @loop_pricescurrency;
130     my @loop_invoicecurrency;
131     for (my $i=0;$i<$count;$i++) {
132         if ($booksellers[0]->{'listprice'} eq $currencies[$i]->{'currency'}) {
133             push @loop_pricescurrency, { currency => "<option selected=\"selected\" value=\"$currencies[$i]->{'currency'}\">$currencies[$i]->{'currency'}</option>" };
134         } else {
135             push @loop_pricescurrency, { currency => "<option value=\"$currencies[$i]->{'currency'}\">$currencies[$i]->{'currency'}</option>"};
136         }
137         if ($booksellers[0]->{'invoiceprice'} eq $currencies[$i]->{'currency'}) {
138             push @loop_invoicecurrency, { currency => "<option selected=\"selected\" value=\"$currencies[$i]->{'currency'}\">$currencies[$i]->{'currency'}</option>"};
139         } else {
140             push @loop_invoicecurrency, { currency => "<option value=\"$currencies[$i]->{'currency'}\">$currencies[$i]->{'currency'}</option>"};
141         }
142     }
143     my $GST = $booksellers[0]->{'gstrate'} || C4::Context->preference("gist");
144     $GST *= 100;
145         $template->param(
146                 id                   => $id,
147                 name                 => $booksellers[0]->{'name'},
148                 postal               => $booksellers[0]->{'postal'},
149                 address1             => $booksellers[0]->{'address1'},
150                 address2             => $booksellers[0]->{'address2'},
151                 address3             => $booksellers[0]->{'address3'},
152                 address4             => $booksellers[0]->{'address4'},
153                 phone                => $booksellers[0]->{'phone'},
154                 fax                  => $booksellers[0]->{'fax'},
155                 url                  => $booksellers[0]->{'url'},
156                 contact              => $booksellers[0]->{'contact'},
157                 contpos              => $booksellers[0]->{'contpos'},
158                 contphone            => $booksellers[0]->{'contphone'},
159                 contaltphone         => $booksellers[0]->{'contaltphone'},
160                 contfax              => $booksellers[0]->{'contfax'},
161                 contemail            => $booksellers[0]->{'contemail'},
162                 contnotes            => $booksellers[0]->{'contnotes'},
163                 notes                => $booksellers[0]->{'notes'},
164                 active               => $id?$booksellers[0]->{'active'}:1, # set active ON by default for supplier add (id empty for add)
165                 gstreg               => $booksellers[0]->{'gstreg'},
166                 listincgst           => $booksellers[0]->{'listincgst'},
167                 invoiceincgst        => $booksellers[0]->{'invoiceincgst'},
168                 gstrate              => $booksellers[0]->{'gstrate'}*100,
169                 discount             => $booksellers[0]->{'discount'},
170                 loop_pricescurrency  => \@loop_pricescurrency,
171                 loop_invoicecurrency => \@loop_invoicecurrency,
172                 GST                  => $GST,
173                 enter                => 1,
174         );
175 }
176
177
178
179 output_html_with_http_headers $query, $cookie, $template->output;