enable EnhancedMessagingPreferences to turn notification on/off
[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
28 this script shows the details for a bookseller given on input arg.
29 It allows to edit & save information about this bookseller.
30
31 =head1 CGI PARAMETERS
32
33 =over 4
34
35 =item supplierid
36
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::Contract qw/GetContract/;
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    = CGI->new;
56 my $id       = $query->param('supplierid');
57 my $supplier = {};
58 if ($id) {
59     $supplier = GetBookSellerFromId($id);
60 }
61 my $op = $query->param('op') || 'display';
62 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
63     {   template_name   => 'acqui/supplier.tmpl',
64         query           => $query,
65         type            => 'intranet',
66         authnotrequired => 0,
67         flagsrequired   => { acquisition => '*' },
68         debug           => 1,
69     }
70 );
71 my $seller_gstrate = $supplier->{'gstrate'};
72
73 # ensure the scalar isn't flagged as a string
74 $seller_gstrate = ( defined $seller_gstrate ) ? $seller_gstrate + 0 : 0;
75 my $tax_rate = $seller_gstrate || C4::Context->preference('gist');
76 $tax_rate *= 100;
77
78 #build array for currencies
79 if ( $op eq 'display' ) {
80
81     my $contracts = GetContract( { booksellerid => $id } );
82
83     for ( @{$contracts} ) {
84         $_->{contractstartdate} = format_date( $_->{contractstartdate} );
85         $_->{contractenddate}   = format_date( $_->{contractenddate} );
86     }
87
88     my $gstrate = defined $supplier->{gstrate} ? $supplier->{gstrate} * 100 : 0;
89
90     $template->param(
91         id            => $id,
92         name          => $supplier->{'name'},
93         postal        => $supplier->{'postal'},
94         address1      => $supplier->{'address1'},
95         address2      => $supplier->{'address2'},
96         address3      => $supplier->{'address3'},
97         address4      => $supplier->{'address4'},
98         phone         => $supplier->{'phone'},
99         fax           => $supplier->{'fax'},
100         url           => $supplier->{'url'},
101         contact       => $supplier->{'contact'},
102         contpos       => $supplier->{'contpos'},
103         contphone     => $supplier->{'contphone'},
104         contaltphone  => $supplier->{'contaltphone'},
105         contfax       => $supplier->{'contfax'},
106         contemail     => $supplier->{'contemail'},
107         contnotes     => $supplier->{'contnotes'},
108         notes         => $supplier->{'notes'},
109         active        => $supplier->{'active'},
110         gstreg        => $supplier->{'gstreg'},
111         listincgst    => $supplier->{'listincgst'},
112         invoiceincgst => $supplier->{'invoiceincgst'},
113         gstrate       => $gstrate,
114         discount      => $supplier->{'discount'},
115         invoiceprice  => $supplier->{'invoiceprice'},
116         listprice     => $supplier->{'listprice'},
117         GST           => $tax_rate,
118         basketcount   => $supplier->{'basketcount'},
119         contracts     => $contracts
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 $loop_currency;
128     for (@currencies) {
129         push @{$loop_currency},
130           { currency     => $_->{currency},
131             listprice    => ( $_->{currency} eq $supplier->{listprice} ),
132             invoiceprice => ( $_->{currency} eq $supplier->{invoiceprice} ),
133           };
134     }
135
136     my $gstrate = defined $supplier->{gstrate} ? $supplier->{gstrate} * 100 : 0;
137     $template->param(
138         id           => $id,
139         name         => $supplier->{'name'},
140         postal       => $supplier->{'postal'},
141         address1     => $supplier->{'address1'},
142         address2     => $supplier->{'address2'},
143         address3     => $supplier->{'address3'},
144         address4     => $supplier->{'address4'},
145         phone        => $supplier->{'phone'},
146         fax          => $supplier->{'fax'},
147         url          => $supplier->{'url'},
148         contact      => $supplier->{'contact'},
149         contpos      => $supplier->{'contpos'},
150         contphone    => $supplier->{'contphone'},
151         contaltphone => $supplier->{'contaltphone'},
152         contfax      => $supplier->{'contfax'},
153         contemail    => $supplier->{'contemail'},
154         contnotes    => $supplier->{'contnotes'},
155         notes        => $supplier->{'notes'},
156         # set active ON by default for supplier add (id empty for add)
157         active       => $id ? $supplier->{'active'} : 1,
158         gstreg        => $supplier->{'gstreg'},
159         listincgst    => $supplier->{'listincgst'},
160         invoiceincgst => $supplier->{'invoiceincgst'},
161         gstrate       => $gstrate,
162         discount      => $supplier->{'discount'},
163         loop_currency => $loop_currency,
164         GST           => $tax_rate,
165         enter         => 1,
166     );
167 }
168
169 output_html_with_http_headers $query, $cookie, $template->output;