Bug 19228: Trigger confirm delete when removing item from course
[koha.git] / acqui / supplier.pl
blobe0addbca2d3329e3e2881cf37b6c0f2db22f938b
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 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::Budgets;
53 use Koha::Acquisition::Bookseller::Contacts;
54 use Koha::Acquisition::Booksellers;
55 use Koha::Acquisition::Currencies;
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::Booksellers->find( $booksellerid );
72 my $supplier_hashref = $supplier->unblessed;
73 foreach ( keys %{$supplier_hashref} ) {
74 $template->{'VARS'}->{$_} = $supplier->$_;
76 $template->{VARS}->{contacts} = $supplier->contacts if $supplier->contacts->count;
77 $template->{'VARS'}->{'booksellerid'} = $booksellerid;
80 $template->{VARS}->{contacts} ||= Koha::Acquisition::Bookseller::Contact->new;
82 if ( $op eq 'display' ) {
83 my $contracts = GetContracts( { booksellerid => $booksellerid } );
85 $template->param(
86 active => $supplier->active,
87 tax_rate => $supplier->tax_rate + 0.0,
88 invoiceprice => $supplier->invoiceprice,
89 listprice => $supplier->listprice,
90 basketcount => $supplier->baskets->count,
91 subscriptioncount => $supplier->subscriptions->count,
92 contracts => $contracts,
94 } elsif ( $op eq 'delete' ) {
95 # no further message needed for the user
96 # the DELETE button only appears in the template if basketcount == 0
97 if ( $supplier->baskets->count == 0 ) {
98 Koha::Acquisition::Booksellers->find($booksellerid)->delete;
100 print $query->redirect('/cgi-bin/koha/acqui/acqui-home.pl');
101 exit;
102 } else {
103 my @currencies = Koha::Acquisition::Currencies->search;
105 # get option values from gist syspref
106 my @gst_values = map {
107 option => $_ + 0.0
108 }, split( '\|', C4::Context->preference("gist") );
110 $template->param(
111 # set active ON by default for supplier add (id empty for add)
112 active => $supplier ? $supplier->active : 1,
113 tax_rate => $supplier ? $supplier->tax_rate + 0.0 : 0,
114 gst_values => \@gst_values,
115 currencies => \@currencies,
116 enter => 1,
120 output_html_with_http_headers $query, $cookie, $template->output;