Bug 11271 - Serials table off the screen in smaller viewports
[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 booksellerid
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;
47 use C4::Biblio;
48 use C4::Output;
49 use CGI;
50
51 use C4::Bookseller qw( GetBookSellerFromId DelBookseller );
52 use C4::Bookseller::Contact;
53 use C4::Budgets;
54
55 my $query    = CGI->new;
56 my $op = $query->param('op') || 'display';
57 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
58     {   template_name   => 'acqui/supplier.tt',
59         query           => $query,
60         type            => 'intranet',
61         authnotrequired => 0,
62         flagsrequired   => { acquisition => '*' },
63         debug           => 1,
64     }
65 );
66 my $booksellerid       = $query->param('booksellerid');
67 my $supplier = {};
68 if ($booksellerid) {
69     $supplier = GetBookSellerFromId($booksellerid);
70     foreach ( keys %{$supplier} ) {
71         $template->{'VARS'}->{$_} = $supplier->{$_};
72     }
73     $template->{'VARS'}->{'booksellerid'} = $booksellerid;
74 }
75 $template->{'VARS'}->{'contacts'} = C4::Bookseller::Contact->new() unless $template->{'VARS'}->{'contacts'};
76
77 #build array for currencies
78 if ( $op eq 'display' ) {
79     my $contracts = GetContracts( { booksellerid => $booksellerid } );
80
81     $template->param(
82         active        => $supplier->{'active'},
83         gstrate       => $supplier->{'gstrate'} + 0.0,
84         invoiceprice  => $supplier->{'invoiceprice'},
85         listprice     => $supplier->{'listprice'},
86         basketcount   => $supplier->{'basketcount'},
87         subscriptioncount   => $supplier->{'subscriptioncount'},
88         contracts     => $contracts,
89     );
90 } elsif ( $op eq 'delete' ) {
91     # no further message needed for the user
92     # the DELETE button only appears in the template if basketcount == 0
93     if ( $supplier->{'basketcount'} == 0 ) {
94         DelBookseller($booksellerid);
95     }
96     print $query->redirect('/cgi-bin/koha/acqui/acqui-home.pl');
97     exit;
98 } else {
99     my @currencies = GetCurrencies();
100     my $loop_currency;
101     my $active_currency = GetCurrency();
102     my $active_listprice = $supplier->{'listprice'};
103     my $active_invoiceprice = $supplier->{'invoiceprice'};
104     if (!$supplier->{listprice}) {
105         $active_listprice =  $active_currency->{currency};
106     }
107     if (!$supplier->{invoiceprice}) {
108         $active_invoiceprice =  $active_currency->{currency};
109     }
110     for (@currencies) {
111         push @{$loop_currency},
112             { 
113             currency     => $_->{currency},
114             listprice    => ( $_->{currency} eq $active_listprice ),
115             invoiceprice => ( $_->{currency} eq $active_invoiceprice ),
116             };
117     }
118
119     # get option values from gist syspref
120     my @gst_values = map {
121         option => $_ + 0.0
122     }, split( '\|', C4::Context->preference("gist") );
123
124     $template->param(
125         # set active ON by default for supplier add (id empty for add)
126         active       => $booksellerid ? $supplier->{'active'} : 1,
127         gstrate       => $supplier->{gstrate} ? $supplier->{'gstrate'}+0.0 : 0,
128         gst_values    => \@gst_values,
129         loop_currency => $loop_currency,
130         enter         => 1,
131     );
132 }
133
134 output_html_with_http_headers $query, $cookie, $template->output;