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
12 # under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 3 of the License, or
14 # (at your option) any later version.
16 # Koha is distributed in the hope that it will be useful, but
17 # WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with Koha; if not, see <http://www.gnu.org/licenses>.
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
46 =item id or booksellerid
48 The id of the supplier whose baskets we will display
62 use C4
::Acquisition qw
/ GetBasketsInfosByBookseller CanUserManageBasket /;
65 use Koha
::Acquisition
::Booksellers
;
69 my ( $template, $loggedinuser, $cookie, $userflags ) = get_template_and_user
(
70 { template_name
=> 'acqui/booksellers.tt',
74 flagsrequired
=> { acquisition
=> '*' },
80 my $supplier = $query->param('supplier');
81 my $booksellerid = $query->param('booksellerid');
82 my $allbaskets= $query->param('allbaskets')||0;
86 push @suppliers, scalar Koha
::Acquisition
::Booksellers
->find( $booksellerid );
88 @suppliers = Koha
::Acquisition
::Booksellers
->search(
89 { name
=> { -like
=> "%$supplier%" } },
90 { order_by
=> { -asc
=> 'name' } } );
93 my $supplier_count = @suppliers;
94 if ( $supplier_count == 1 ) {
96 supplier_name
=> $suppliers[0]->name,
97 booksellerid
=> $suppliers[0]->id,
98 basketcount
=> $suppliers[0]->baskets->count,
99 active
=> $suppliers[0]->active,
104 # FIXME This script should only be accessed by a valid logged in patron
106 # FIXME Should not be needed, logged in patron should be cached
107 $uid = Koha
::Patrons
->find( $loggedinuser )->userid;
110 my $userenv = C4
::Context
::userenv
;
111 my $viewbaskets = C4
::Context
->preference('AcqViewBaskets');
113 my $userbranch = $userenv->{branch
};
115 my $budgets = GetBudgetHierarchy
;
117 foreach my $r (@
{$budgets}) {
118 if (!defined $r->{budget_amount
} || $r->{budget_amount
} == 0) {
121 next unless (CanUserUseBudget
($loggedinuser, $r, $userflags));
128 my $loop_suppliers = [];
130 for my $vendor (@suppliers) {
131 my $baskets = GetBasketsInfosByBookseller
( $vendor->id, $allbaskets );
133 my $loop_basket = [];
135 for my $basket ( @
{$baskets} ) {
136 if (CanUserManageBasket
($loggedinuser, $basket, $userflags)) {
137 my $patron = Koha
::Patrons
->find( $basket->{authorisedby
} );
138 foreach (qw(total_items total_biblios expected_items)) {
142 $basket->{authorisedby_firstname
} = $patron->firstname;
143 $basket->{authorisedby_surname
} = $patron->surname;
145 if ($basket->{basketgroupid
}) {
146 my $basketgroup = C4
::Acquisition
::GetBasketgroup
($basket->{basketgroupid
});
148 $basket->{basketgroup
} = $basketgroup;
151 push @
{$loop_basket}, $basket;
155 push @
{$loop_suppliers},
156 { loop_basket
=> $loop_basket,
157 booksellerid
=> $vendor->id,
158 name
=> $vendor->name,
159 active
=> $vendor->active,
164 loop_suppliers
=> $loop_suppliers,
165 supplier
=> ( $booksellerid || $supplier ),
166 count
=> $supplier_count,
167 has_budgets
=> $has_budgets,
169 $template->{VARS
}->{'allbaskets'} = $allbaskets;
171 output_html_with_http_headers
$query, $cookie, $template->output;