Fix for Bug 6531 - clicking print button in opac causes 404 error
[koha.git] / acqui / booksellers.pl
blobcc5c08450869d3ee4ce8a05d50a6c11cf17f1652
1 #!/usr/bin/perl
3 #script to show suppliers and orders
5 # Copyright 2000-2002 Katipo Communications
6 # Copyright 2008-2009 BibLibre SARL
7 # Copyright 2010 PTFS Europe
9 # This file is part of Koha.
11 # Koha is free software; you can redistribute it and/or modify it under the
12 # terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
14 # version.
16 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License along
21 # with Koha; if not, write to the Free Software Foundation, Inc.,
22 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 =head1 NAME
26 booksellers.pl
28 =head1 DESCRIPTION
30 this script displays the list of suppliers & baskets like C<$supplier> given on input arg.
31 thus, this page brings differents features like to display supplier's details,
32 to add an order for a specific supplier or to just add a new supplier.
34 =head1 CGI PARAMETERS
36 =over 4
38 =item supplier
40 C<$supplier> is the string with which we search for a supplier
42 =back
44 =item id or supplierid
46 The id of the supplier whose baskets we will display
48 =back
50 =cut
52 use strict;
53 use warnings;
54 use C4::Auth;
55 use C4::Biblio;
56 use C4::Output;
57 use CGI;
59 use C4::Dates qw/format_date/;
60 use C4::Bookseller qw/ GetBookSellerFromId GetBookSeller /;
61 use C4::Members qw/GetMember/;
63 my $query = CGI->new;
64 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
65 { template_name => 'acqui/booksellers.tmpl',
66 query => $query,
67 type => 'intranet',
68 authnotrequired => 0,
69 flagsrequired => { acquisition => '*' },
70 debug => 1,
74 #parameters
75 my $supplier = $query->param('supplier');
76 my $id = $query->param('id') || $query->param('supplierid');
77 my @suppliers;
79 if ($id) {
80 push @suppliers, GetBookSellerFromId($id);
81 } else {
82 @suppliers = GetBookSeller($supplier);
85 my $supplier_count = @suppliers;
86 if ( $supplier_count == 1 ) {
87 $template->param(
88 supplier_name => $suppliers[0]->{'name'},
89 id => $suppliers[0]->{'id'}
93 my $uid;
94 if ($loggedinuser) {
95 $uid = GetMember( borrowernumber => $loggedinuser )->{userid};
98 #build result page
99 my $loop_suppliers = [];
101 for my $vendor (@suppliers) {
102 my $baskets = get_vendors_baskets( $vendor->{id} );
104 my $loop_basket = [];
105 for my $basket ( @{$baskets} ) {
106 if (( $basket->{authorisedby}
107 && $basket->{authorisedby} eq $loggedinuser
109 || haspermission( $uid, { flagsrequired => { acquisition => q{*} } } )
111 for my $date_field (qw( creationdate closedate)) {
112 if ( $basket->{$date_field} ) {
113 $basket->{$date_field} =
114 format_date( $basket->{$date_field} );
117 push @{$loop_basket}, $basket;
121 push @{$loop_suppliers},
122 { loop_basket => $loop_basket,
123 supplierid => $vendor->{id},
124 name => $vendor->{name},
125 active => $vendor->{active},
129 $template->param(
130 loop_suppliers => $loop_suppliers,
131 supplier => ( $id || $supplier ),
132 count => $supplier_count,
135 output_html_with_http_headers $query, $cookie, $template->output;
137 sub get_vendors_baskets {
138 my $supplier_id = shift;
139 my $dbh = C4::Context->dbh;
140 my $sql = <<'ENDSQL';
141 select aqbasket.*, count(*) as total, borrowers.firstname, borrowers.surname
142 from aqbasket left join aqorders on aqorders.basketno = aqbasket.basketno
143 left join borrowers on aqbasket.authorisedby = borrowers.borrowernumber
144 where booksellerid = ?
145 AND ( aqorders.quantity > aqorders.quantityreceived OR quantityreceived IS NULL)
146 AND datecancellationprinted IS NULL
147 group by basketno
148 ENDSQL
149 return $dbh->selectall_arrayref( $sql, { Slice => {} }, $supplier_id );