Bug 13745: Fix serial collection page to always show branch name
[koha.git] / acqui / supplier.pl
blob30a3d3ea57600d09ddb95a86cf521656bb0bcdb1
1 #!/usr/bin/perl
3 # Copyright 2000-2002 Katipo Communications
4 # Copyright 2008-2009 BibLibre SARL
5 # Copyright 2010 PTFS Europe Ltd
7 # This file is part of Koha.
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.
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.
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.
22 =head1 NAME
24 supplier.pl
26 =head1 DESCRIPTION
28 this script shows the details for a bookseller given on input arg.
29 It allows to edit & save information about this bookseller.
31 =head1 CGI PARAMETERS
33 =over 4
35 =item booksellerid
37 To know the bookseller this script has to display details.
39 =back
41 =cut
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 qw ( -utf8 );
51 use C4::Bookseller qw( DelBookseller );
52 use C4::Bookseller::Contact;
53 use C4::Budgets;
55 use Koha::Acquisition::Bookseller;
57 my $query = CGI->new;
58 my $op = $query->param('op') || 'display';
59 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
60 { template_name => 'acqui/supplier.tt',
61 query => $query,
62 type => 'intranet',
63 authnotrequired => 0,
64 flagsrequired => { acquisition => '*' },
65 debug => 1,
68 my $booksellerid = $query->param('booksellerid');
69 my $supplier = {};
70 if ($booksellerid) {
71 $supplier = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid });
72 foreach ( keys %{$supplier} ) {
73 $template->{'VARS'}->{$_} = $supplier->{$_};
75 $template->{'VARS'}->{'booksellerid'} = $booksellerid;
77 $template->{'VARS'}->{'contacts'} = C4::Bookseller::Contact->new() unless $template->{'VARS'}->{'contacts'};
79 #build array for currencies
80 if ( $op eq 'display' ) {
81 my $contracts = GetContracts( { booksellerid => $booksellerid } );
83 $template->param(
84 active => $supplier->{'active'},
85 gstrate => $supplier->{'gstrate'} + 0.0,
86 invoiceprice => $supplier->{'invoiceprice'},
87 listprice => $supplier->{'listprice'},
88 basketcount => $supplier->{'basketcount'},
89 subscriptioncount => $supplier->{'subscriptioncount'},
90 contracts => $contracts,
92 } elsif ( $op eq 'delete' ) {
93 # no further message needed for the user
94 # the DELETE button only appears in the template if basketcount == 0
95 if ( $supplier->{'basketcount'} == 0 ) {
96 DelBookseller($booksellerid);
98 print $query->redirect('/cgi-bin/koha/acqui/acqui-home.pl');
99 exit;
100 } else {
101 my @currencies = GetCurrencies();
102 my $loop_currency;
103 my $active_currency = GetCurrency();
104 my $active_listprice = $supplier->{'listprice'};
105 my $active_invoiceprice = $supplier->{'invoiceprice'};
106 if (!$supplier->{listprice}) {
107 $active_listprice = $active_currency->{currency};
109 if (!$supplier->{invoiceprice}) {
110 $active_invoiceprice = $active_currency->{currency};
112 for (@currencies) {
113 push @{$loop_currency},
115 currency => $_->{currency},
116 listprice => ( $_->{currency} eq $active_listprice ),
117 invoiceprice => ( $_->{currency} eq $active_invoiceprice ),
121 # get option values from gist syspref
122 my @gst_values = map {
123 option => $_ + 0.0
124 }, split( '\|', C4::Context->preference("gist") );
126 $template->param(
127 # set active ON by default for supplier add (id empty for add)
128 active => $booksellerid ? $supplier->{'active'} : 1,
129 gstrate => $supplier->{gstrate} ? $supplier->{'gstrate'}+0.0 : 0,
130 gst_values => \@gst_values,
131 loop_currency => $loop_currency,
132 enter => 1,
136 output_html_with_http_headers $query, $cookie, $template->output;