Fix FSF address in directory acqui/
[wip/koha-chris_n.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 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;
51
52 use C4::Bookseller;
53 use C4::Budgets;
54
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,
67         }
68 );
69 my $GST = $booksellers[0]->{'gstrate'} || C4::Context->preference("gist");
70 $GST *= 100;
71
72 my @contracts = GetContracts($id);
73 my $contractcount = scalar(@contracts);
74 $template->param(hascontracts => 1) if ($contractcount > 0);
75
76 #build array for currencies
77 if ($op eq "display") {
78
79     # get contracts
80     my @contracts = @{GetContract( { booksellerid => $id } )};
81
82     # format dates
83     for ( @contracts ) {
84         $$_{contractstartdate} = format_date($$_{contractstartdate});
85         $$_{contractenddate}   = format_date($$_{contractenddate});
86     }
87
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
118         );
119 }
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;
127     
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>"};
135         }
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>"};
140         }
141     }
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,
173         );
174 }
175
176
177
178 output_html_with_http_headers $query, $cookie, $template->output;