Bug 32482: (follow-up) Add markup comments
[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
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.
13 #
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.
18 #
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>.
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 Modern::Perl;
44 use C4::Auth qw( get_template_and_user );
45 use C4::Contract qw( GetContracts GetContract );
46 use C4::Output qw( output_html_with_http_headers );
47 use CGI qw ( -utf8 );
48
49 use C4::Budgets;
50
51 use Koha::Acquisition::Bookseller::Contacts;
52 use Koha::Acquisition::Booksellers;
53 use Koha::Acquisition::Currencies;
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         flagsrequired   => { acquisition => '*' },
62     }
63 );
64 my $booksellerid       = $query->param('booksellerid');
65 my $supplier;
66 if ($booksellerid) {
67     $supplier = Koha::Acquisition::Booksellers->find( $booksellerid );
68     my $supplier_hashref = $supplier->unblessed;
69     foreach ( keys %{$supplier_hashref} ) {
70         $template->{'VARS'}->{$_} = $supplier->$_;
71     }
72     $template->{VARS}->{contacts} = $supplier->contacts if $supplier->contacts->count;
73     $template->{'VARS'}->{'booksellerid'} = $booksellerid;
74 }
75
76 $template->{VARS}->{contacts} ||= Koha::Acquisition::Bookseller::Contact->new;
77
78 if ( $op eq 'display' ) {
79     my $contracts = GetContracts( { booksellerid => $booksellerid } );
80
81     $template->param(
82         active        => $supplier->active,
83         tax_rate      => $supplier->tax_rate + 0.0,
84         invoiceprice  => $supplier->invoiceprice,
85         listprice     => $supplier->listprice,
86         basketcount   => $supplier->baskets->count,
87         subscriptioncount => $supplier->subscriptions->count,
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 AND subscriptioncount == 0
93     if ( $supplier->baskets->count == 0 && $supplier->subscriptions->count == 0) {
94         Koha::Acquisition::Booksellers->find($booksellerid)->delete;
95     }
96     print $query->redirect('/cgi-bin/koha/acqui/acqui-home.pl');
97     exit;
98 } else {
99
100     # get option values from TaxRates syspref
101     my @gst_values = map {
102         option => $_ + 0.0
103     }, split( '\|', C4::Context->preference("TaxRates") );
104
105     $template->param(
106         # set active ON by default for supplier add (id empty for add)
107         active     => $supplier ? $supplier->active         : 1,
108         tax_rate   => $supplier ? $supplier->tax_rate + 0.0 : 0,
109         gst_values    => \@gst_values,
110         currencies    => Koha::Acquisition::Currencies->search,
111         enter         => 1,
112     );
113 }
114
115 output_html_with_http_headers $query, $cookie, $template->output;