Bug 18925: (follow-up) Fix null/empty behavior
[koha.git] / acqui / supplier.pl
blob40235dfacd1fdac63d82ef4f085179cfb5191cb6
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
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 # Koha is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with Koha; if not, see <http://www.gnu.org/licenses>.
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 Modern::Perl;
44 use C4::Auth;
45 use C4::Contract;
46 use C4::Biblio;
47 use C4::Output;
48 use CGI qw ( -utf8 );
50 use C4::Budgets;
52 use Koha::Acquisition::Bookseller::Contacts;
53 use Koha::Acquisition::Booksellers;
54 use Koha::Acquisition::Currencies;
56 my $query = CGI->new;
57 my $op = $query->param('op') || 'display';
58 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
59 { template_name => 'acqui/supplier.tt',
60 query => $query,
61 type => 'intranet',
62 authnotrequired => 0,
63 flagsrequired => { acquisition => '*' },
64 debug => 1,
67 my $booksellerid = $query->param('booksellerid');
68 my $supplier;
69 if ($booksellerid) {
70 $supplier = Koha::Acquisition::Booksellers->find( $booksellerid );
71 my $supplier_hashref = $supplier->unblessed;
72 foreach ( keys %{$supplier_hashref} ) {
73 $template->{'VARS'}->{$_} = $supplier->$_;
75 $template->{VARS}->{contacts} = $supplier->contacts if $supplier->contacts->count;
76 $template->{'VARS'}->{'booksellerid'} = $booksellerid;
79 $template->{VARS}->{contacts} ||= Koha::Acquisition::Bookseller::Contact->new;
81 if ( $op eq 'display' ) {
82 my $contracts = GetContracts( { booksellerid => $booksellerid } );
84 $template->param(
85 active => $supplier->active,
86 tax_rate => $supplier->tax_rate + 0.0,
87 invoiceprice => $supplier->invoiceprice,
88 listprice => $supplier->listprice,
89 basketcount => $supplier->baskets->count,
90 subscriptioncount => $supplier->subscriptions->count,
91 contracts => $contracts,
93 } elsif ( $op eq 'delete' ) {
94 # no further message needed for the user
95 # the DELETE button only appears in the template if basketcount == 0
96 if ( $supplier->baskets->count == 0 ) {
97 Koha::Acquisition::Booksellers->find($booksellerid)->delete;
99 print $query->redirect('/cgi-bin/koha/acqui/acqui-home.pl');
100 exit;
101 } else {
102 my @currencies = Koha::Acquisition::Currencies->search;
104 # get option values from gist syspref
105 my @gst_values = map {
106 option => $_ + 0.0
107 }, split( '\|', C4::Context->preference("gist") );
109 $template->param(
110 # set active ON by default for supplier add (id empty for add)
111 active => $supplier ? $supplier->active : 1,
112 tax_rate => $supplier ? $supplier->tax_rate + 0.0 : 0,
113 gst_values => \@gst_values,
114 currencies => \@currencies,
115 enter => 1,
119 output_html_with_http_headers $query, $cookie, $template->output;