small 1st changes in basketgrouping (#3622)
[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 with
21 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA  02111-1307 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 C4::Auth;
45 use C4::Acquisition;
46 use C4::Biblio;
47 use C4::Output;
48 use CGI;
49
50 use C4::Bookseller;
51 use C4::Budgets;
52
53 my $query       = new CGI;
54 my $id          = $query->param('supplierid');
55 my @booksellers = GetBookSellerFromId($id) if $id;
56 my $count       = scalar @booksellers;
57 my $op          = $query->param('op') || "display";
58 my ($template, $loggedinuser, $cookie) = get_template_and_user(
59         {   template_name   => "acqui/supplier.tmpl",
60                 query           => $query,
61                 type            => "intranet",
62                 authnotrequired => 0,
63                 flagsrequired   => { acquisition => 'vendors_manage' },
64                 debug           => 1,
65         }
66 );
67 my $GST = $booksellers[0]->{'gstrate'} || C4::Context->preference("gist");
68 $GST *= 100;
69 #build array for currencies
70 if ($op eq "display") {
71         $template->param(
72                 id            => $id,
73                 name          => $booksellers[0]->{'name'},
74                 postal        => $booksellers[0]->{'postal'},
75                 address1      => $booksellers[0]->{'address1'},
76                 address2      => $booksellers[0]->{'address2'},
77                 address3      => $booksellers[0]->{'address3'},
78                 address4      => $booksellers[0]->{'address4'},
79                 phone         => $booksellers[0]->{'phone'},
80                 fax           => $booksellers[0]->{'fax'},
81                 url           => $booksellers[0]->{'url'},
82                 contact       => $booksellers[0]->{'contact'},
83                 contpos       => $booksellers[0]->{'contpos'},
84                 contphone     => $booksellers[0]->{'contphone'},
85                 contaltphone  => $booksellers[0]->{'contaltphone'},
86                 contfax       => $booksellers[0]->{'contfax'},
87                 contemail     => $booksellers[0]->{'contemail'},
88                 contnotes     => $booksellers[0]->{'contnotes'},
89                 notes         => $booksellers[0]->{'notes'},
90                 active        => $booksellers[0]->{'active'},
91                 specialty     => $booksellers[0]->{'specialty'},
92                 gstreg        => $booksellers[0]->{'gstreg'},
93                 listincgst    => $booksellers[0]->{'listincgst'},
94                 invoiceincgst => $booksellers[0]->{'invoiceincgst'},
95                 gstrate                 => $booksellers[0]->{'gstrate'},
96                 discount      => $booksellers[0]->{'discount'},
97                 invoiceprice  => $booksellers[0]->{'invoiceprice'},
98                 listprice     => $booksellers[0]->{'listprice'},
99                 GST           => $GST,
100                 basketcount   => $booksellers[0]->{'basketcount'},
101         );
102 }
103 elsif ($op eq 'delete') {
104   &DelBookseller($id);
105   print $query->redirect("/cgi-bin/koha/acqui/acqui-home.pl");
106   exit;
107 } else {
108     my @currencies = GetCurrencies();
109     my $count = scalar @currencies;
110     
111     my @loop_pricescurrency;
112     my @loop_invoicecurrency;
113     for (my $i=0;$i<$count;$i++) {
114         if ($booksellers[0]->{'listprice'} eq $currencies[$i]->{'currency'}) {
115             push @loop_pricescurrency, { currency => "<option selected=\"selected\" value=\"$currencies[$i]->{'currency'}\">$currencies[$i]->{'currency'}</option>" };
116         } else {
117             push @loop_pricescurrency, { currency => "<option value=\"$currencies[$i]->{'currency'}\">$currencies[$i]->{'currency'}</option>"};
118         }
119         if ($booksellers[0]->{'invoiceprice'} eq $currencies[$i]->{'currency'}) {
120             push @loop_invoicecurrency, { currency => "<option selected=\"selected\" value=\"$currencies[$i]->{'currency'}\">$currencies[$i]->{'currency'}</option>"};
121         } else {
122             push @loop_invoicecurrency, { currency => "<option value=\"$currencies[$i]->{'currency'}\">$currencies[$i]->{'currency'}</option>"};
123         }
124     }
125     my $GST = $booksellers[0]->{'gstrate'} || C4::Context->preference("gist");
126     $GST *= 100;
127         $template->param(
128                 id                   => $id,
129                 name                 => $booksellers[0]->{'name'},
130                 postal               => $booksellers[0]->{'postal'},
131                 address1             => $booksellers[0]->{'address1'},
132                 address2             => $booksellers[0]->{'address2'},
133                 address3             => $booksellers[0]->{'address3'},
134                 address4             => $booksellers[0]->{'address4'},
135                 phone                => $booksellers[0]->{'phone'},
136                 fax                  => $booksellers[0]->{'fax'},
137                 url                  => $booksellers[0]->{'url'},
138                 contact              => $booksellers[0]->{'contact'},
139                 contpos              => $booksellers[0]->{'contpos'},
140                 contphone            => $booksellers[0]->{'contphone'},
141                 contaltphone         => $booksellers[0]->{'contaltphone'},
142                 contfax              => $booksellers[0]->{'contfax'},
143                 contemail            => $booksellers[0]->{'contemail'},
144                 contnotes            => $booksellers[0]->{'contnotes'},
145                 notes                => $booksellers[0]->{'notes'},
146                 active               => $booksellers[0]->{'active'},
147                 specialty            => $booksellers[0]->{'specialty'},
148                 gstreg               => $booksellers[0]->{'gstreg'},
149                 listincgst           => $booksellers[0]->{'listincgst'},
150                 invoiceincgst        => $booksellers[0]->{'invoiceincgst'},
151                 gstrate                 => $booksellers[0]->{'gstrate'},
152                 discount             => $booksellers[0]->{'discount'},
153                 loop_pricescurrency  => \@loop_pricescurrency,
154                 loop_invoicecurrency => \@loop_invoicecurrency,
155                 GST                  => $GST,
156                 enter                => 1,
157         );
158 }
159 output_html_with_http_headers $query, $cookie, $template->output;