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
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.
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.
40 C<$supplier> is the string with which we search for a supplier
44 =item id or supplierid
46 The id of the supplier whose baskets we will display
59 use C4::Dates qw/format_date/;
60 use C4::Bookseller qw/ GetBookSellerFromId GetBookSeller /;
61 use C4::Members qw/GetMember/;
64 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
65 { template_name => 'acqui/booksellers.tmpl',
69 flagsrequired => { acquisition => '*' },
75 my $supplier = $query->param('supplier');
76 my $id = $query->param('id') || $query->param('supplierid');
80 push @suppliers, GetBookSellerFromId($id);
82 @suppliers = GetBookSeller($supplier);
85 my $supplier_count = @suppliers;
86 if ( $supplier_count == 1 ) {
88 supplier_name => $suppliers[0]->{'name'},
89 id => $suppliers[0]->{'id'}
95 $uid = GetMember( borrowernumber => $loggedinuser )->{userid};
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, { 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},
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
149 return $dbh->selectall_arrayref( $sql, { Slice => {} }, $supplier_id );