Add koha-post-install-setup, a script to be run by sysadmin post-install.
[koha.git] / acqui / supplier.pl
1 #!/usr/bin/perl
2
3 # Copyright 2000-2002 Katipo Communications
4 # Copyright 2008-2009 BibLibre SARL
5 # Copyright 2010 PTFS Europe Ltd
6 #
7 # This file is part of Koha.
8 #
9 # Koha is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
12 # version.
13 #
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License along
19 # with Koha; if not, write to the Free Software Foundation, Inc.,
20 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
22 =head1 NAME
23
24 supplier.pl
25
26 =head1 DESCRIPTION
27 this script shows the details for a bookseller given on input arg.
28 It allows to edit & save information about this bookseller.
29
30 =head1 CGI PARAMETERS
31
32 =over 4
33
34 =item supplierid
35 To know the bookseller this script has to display details.
36
37 =back
38
39 =cut
40
41 use strict;
42 use warnings;
43 use C4::Auth;
44 use C4::Contract qw/GetContract/;
45 use C4::Biblio;
46 use C4::Output;
47 use C4::Dates qw/format_date /;
48 use CGI;
49
50 use C4::Bookseller;
51 use C4::Budgets;
52
53 my $query    = CGI->new;
54 my $id       = $query->param('supplierid');
55 my $supplier = {};
56 if ($id) {
57     $supplier = GetBookSellerFromId($id);
58 }
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 $seller_gstrate = $supplier->{'gstrate'};
70
71 # ensure the scalar isn't flagged as a string
72 $seller_gstrate = ( defined $seller_gstrate ) ? $seller_gstrate + 0 : 0;
73 my $tax_rate = $seller_gstrate || C4::Context->preference('gist');
74 $tax_rate *= 100;
75
76 #build array for currencies
77 if ( $op eq 'display' ) {
78
79     my $contracts = GetContract( { booksellerid => $id } );
80
81     for ( @{$contracts} ) {
82         $_->{contractstartdate} = format_date( $_->{contractstartdate} );
83         $_->{contractenddate}   = format_date( $_->{contractenddate} );
84     }
85
86     my $gstrate = defined $supplier->{gstrate} ? $supplier->{gstrate} * 100 : 0;
87
88     $template->param(
89         id            => $id,
90         name          => $supplier->{'name'},
91         postal        => $supplier->{'postal'},
92         address1      => $supplier->{'address1'},
93         address2      => $supplier->{'address2'},
94         address3      => $supplier->{'address3'},
95         address4      => $supplier->{'address4'},
96         phone         => $supplier->{'phone'},
97         fax           => $supplier->{'fax'},
98         url           => $supplier->{'url'},
99         contact       => $supplier->{'contact'},
100         contpos       => $supplier->{'contpos'},
101         contphone     => $supplier->{'contphone'},
102         contaltphone  => $supplier->{'contaltphone'},
103         contfax       => $supplier->{'contfax'},
104         contemail     => $supplier->{'contemail'},
105         contnotes     => $supplier->{'contnotes'},
106         notes         => $supplier->{'notes'},
107         active        => $supplier->{'active'},
108         gstreg        => $supplier->{'gstreg'},
109         listincgst    => $supplier->{'listincgst'},
110         invoiceincgst => $supplier->{'invoiceincgst'},
111         gstrate       => $gstrate,
112         discount      => $supplier->{'discount'},
113         invoiceprice  => $supplier->{'invoiceprice'},
114         listprice     => $supplier->{'listprice'},
115         GST           => $tax_rate,
116         basketcount   => $supplier->{'basketcount'},
117         contracts     => $contracts
118     );
119 } elsif ( $op eq 'delete' ) {
120     DelBookseller($id);
121     print $query->redirect('/cgi-bin/koha/acqui/acqui-home.pl');
122     exit;
123 } else {
124     my @currencies = GetCurrencies();
125     my $loop_currency;
126     for (@currencies) {
127         push @{$loop_currency},
128           { currency     => $_->{currency},
129             listprice    => ( $_->{currency} eq $supplier->{listprice} ),
130             invoiceprice => ( $_->{currency} eq $supplier->{invoiceprice} ),
131           };
132     }
133
134     my $gstrate = defined $supplier->{gstrate} ? $supplier->{gstrate} * 100 : 0;
135     $template->param(
136         id           => $id,
137         name         => $supplier->{'name'},
138         postal       => $supplier->{'postal'},
139         address1     => $supplier->{'address1'},
140         address2     => $supplier->{'address2'},
141         address3     => $supplier->{'address3'},
142         address4     => $supplier->{'address4'},
143         phone        => $supplier->{'phone'},
144         fax          => $supplier->{'fax'},
145         url          => $supplier->{'url'},
146         contact      => $supplier->{'contact'},
147         contpos      => $supplier->{'contpos'},
148         contphone    => $supplier->{'contphone'},
149         contaltphone => $supplier->{'contaltphone'},
150         contfax      => $supplier->{'contfax'},
151         contemail    => $supplier->{'contemail'},
152         contnotes    => $supplier->{'contnotes'},
153         notes        => $supplier->{'notes'},
154         # set active ON by default for supplier add (id empty for add)
155         active       => $id ? $supplier->{'active'} : 1,
156         gstreg        => $supplier->{'gstreg'},
157         listincgst    => $supplier->{'listincgst'},
158         invoiceincgst => $supplier->{'invoiceincgst'},
159         gstrate       => $gstrate,
160         discount      => $supplier->{'discount'},
161         loop_currency => $loop_currency,
162         GST           => $tax_rate,
163         enter         => 1,
164     );
165 }
166
167 output_html_with_http_headers $query, $cookie, $template->output;