Enhancement Bug 4444: Centralize Code Handling Perl Dependencies
[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;
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 $seller_gstrate = $booksellers[0]->{'gstrate'};
71 # A perl-ism: '0'==false, '0.000'==true, but 0=='0.000' - this accounts for that
72 undef $seller_gstrate if ($seller_gstrate == 0);
73 my $GST = $seller_gstrate || C4::Context->preference("gist");
74 $GST *= 100;
75
76 my @contracts = GetContracts($id);
77 my $contractcount = scalar(@contracts);
78 $template->param(hascontracts => 1) if ($contractcount > 0);
79
80 #build array for currencies
81 if ($op eq "display") {
82
83     # get contracts
84     my @contracts = @{GetContract( { booksellerid => $id } )};
85
86     # format dates
87     for ( @contracts ) {
88         $$_{contractstartdate} = format_date($$_{contractstartdate});
89         $$_{contractenddate}   = format_date($$_{contractenddate});
90     }
91
92         $template->param(
93                 id            => $id,
94                 name          => $booksellers[0]->{'name'},
95                 postal        => $booksellers[0]->{'postal'},
96                 address1      => $booksellers[0]->{'address1'},
97                 address2      => $booksellers[0]->{'address2'},
98                 address3      => $booksellers[0]->{'address3'},
99                 address4      => $booksellers[0]->{'address4'},
100                 phone         => $booksellers[0]->{'phone'},
101                 fax           => $booksellers[0]->{'fax'},
102                 url           => $booksellers[0]->{'url'},
103                 contact       => $booksellers[0]->{'contact'},
104                 contpos       => $booksellers[0]->{'contpos'},
105                 contphone     => $booksellers[0]->{'contphone'},
106                 contaltphone  => $booksellers[0]->{'contaltphone'},
107                 contfax       => $booksellers[0]->{'contfax'},
108                 contemail     => $booksellers[0]->{'contemail'},
109                 contnotes     => $booksellers[0]->{'contnotes'},
110                 notes         => $booksellers[0]->{'notes'},
111                 active        => $booksellers[0]->{'active'},
112                 gstreg        => $booksellers[0]->{'gstreg'},
113                 listincgst    => $booksellers[0]->{'listincgst'},
114                 invoiceincgst => $booksellers[0]->{'invoiceincgst'},
115                 gstrate       => $booksellers[0]->{'gstrate'}*100,
116                 discount      => $booksellers[0]->{'discount'},
117                 invoiceprice  => $booksellers[0]->{'invoiceprice'},
118                 listprice     => $booksellers[0]->{'listprice'},
119                 GST           => $GST,
120                 basketcount   => $booksellers[0]->{'basketcount'},
121                 contracts     => \@contracts
122         );
123 }
124 elsif ($op eq 'delete') {
125   &DelBookseller($id);
126   print $query->redirect("/cgi-bin/koha/acqui/acqui-home.pl");
127   exit;
128 } else {
129     my @currencies = GetCurrencies();
130     my $count = scalar @currencies;
131     
132     my @loop_pricescurrency;
133     my @loop_invoicecurrency;
134     for (my $i=0;$i<$count;$i++) {
135         if ($booksellers[0]->{'listprice'} eq $currencies[$i]->{'currency'}) {
136             push @loop_pricescurrency, { currency => "<option selected=\"selected\" value=\"$currencies[$i]->{'currency'}\">$currencies[$i]->{'currency'}</option>" };
137         } else {
138             push @loop_pricescurrency, { currency => "<option value=\"$currencies[$i]->{'currency'}\">$currencies[$i]->{'currency'}</option>"};
139         }
140         if ($booksellers[0]->{'invoiceprice'} eq $currencies[$i]->{'currency'}) {
141             push @loop_invoicecurrency, { currency => "<option selected=\"selected\" value=\"$currencies[$i]->{'currency'}\">$currencies[$i]->{'currency'}</option>"};
142         } else {
143             push @loop_invoicecurrency, { currency => "<option value=\"$currencies[$i]->{'currency'}\">$currencies[$i]->{'currency'}</option>"};
144         }
145     }
146         $template->param(
147                 id                   => $id,
148                 name                 => $booksellers[0]->{'name'},
149                 postal               => $booksellers[0]->{'postal'},
150                 address1             => $booksellers[0]->{'address1'},
151                 address2             => $booksellers[0]->{'address2'},
152                 address3             => $booksellers[0]->{'address3'},
153                 address4             => $booksellers[0]->{'address4'},
154                 phone                => $booksellers[0]->{'phone'},
155                 fax                  => $booksellers[0]->{'fax'},
156                 url                  => $booksellers[0]->{'url'},
157                 contact              => $booksellers[0]->{'contact'},
158                 contpos              => $booksellers[0]->{'contpos'},
159                 contphone            => $booksellers[0]->{'contphone'},
160                 contaltphone         => $booksellers[0]->{'contaltphone'},
161                 contfax              => $booksellers[0]->{'contfax'},
162                 contemail            => $booksellers[0]->{'contemail'},
163                 contnotes            => $booksellers[0]->{'contnotes'},
164                 notes                => $booksellers[0]->{'notes'},
165                 active               => $id?$booksellers[0]->{'active'}:1, # set active ON by default for supplier add (id empty for add)
166                 gstreg               => $booksellers[0]->{'gstreg'},
167                 listincgst           => $booksellers[0]->{'listincgst'},
168                 invoiceincgst        => $booksellers[0]->{'invoiceincgst'},
169                 gstrate              => $booksellers[0]->{'gstrate'}*100,
170                 discount             => $booksellers[0]->{'discount'},
171                 loop_pricescurrency  => \@loop_pricescurrency,
172                 loop_invoicecurrency => \@loop_invoicecurrency,
173                 GST                  => $GST,
174                 enter                => 1,
175         );
176 }
177
178
179
180 output_html_with_http_headers $query, $cookie, $template->output;