Bug 10810 - Fix synopsis for -html option to overdue_notices.pl
[koha.git] / acqui / booksellers.pl
blobbb65dbc803bd7639d08645b5a463da26e23f7b83
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 booksellerid
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::Budgets;
57 use C4::Output;
58 use CGI;
60 use C4::Acquisition qw/ GetBasketsInfosByBookseller /;
61 use C4::Bookseller qw/ GetBookSellerFromId GetBookSeller /;
62 use C4::Members qw/GetMember/;
63 use C4::Context;
65 my $query = CGI->new;
66 my ( $template, $loggedinuser, $cookie, $userflags ) = get_template_and_user(
67 { template_name => 'acqui/booksellers.tmpl',
68 query => $query,
69 type => 'intranet',
70 authnotrequired => 0,
71 flagsrequired => { acquisition => '*' },
72 debug => 1,
76 #parameters
77 my $supplier = $query->param('supplier');
78 my $booksellerid = $query->param('booksellerid');
79 my $allbaskets= $query->param('allbaskets')||0;
80 my @suppliers;
82 if ($booksellerid) {
83 push @suppliers, GetBookSellerFromId($booksellerid);
84 } else {
85 @suppliers = GetBookSeller($supplier);
88 my $supplier_count = @suppliers;
89 if ( $supplier_count == 1 ) {
90 $template->param(
91 supplier_name => $suppliers[0]->{'name'},
92 booksellerid => $suppliers[0]->{'id'},
93 basketcount => $suppliers[0]->{'basketcount'}
97 my $uid;
98 if ($loggedinuser) {
99 $uid = GetMember( borrowernumber => $loggedinuser )->{userid};
102 my $userenv = C4::Context::userenv;
103 my $viewbaskets = C4::Context->preference('AcqViewBaskets');
105 my $userbranch = $userenv->{branch};
107 my $budgets = GetBudgetHierarchy;
108 my $has_budgets = 0;
109 foreach my $r (@{$budgets}) {
110 if (!defined $r->{budget_amount} || $r->{budget_amount} == 0) {
111 next;
113 next unless (CanUserUseBudget($loggedinuser, $r, $userflags));
115 $has_budgets = 1;
116 last;
119 #build result page
120 my $loop_suppliers = [];
122 for my $vendor (@suppliers) {
123 my $baskets = GetBasketsInfosByBookseller( $vendor->{id}, $allbaskets );
125 my $loop_basket = [];
127 for my $basket ( @{$baskets} ) {
128 my $authorisedby = $basket->{authorisedby};
129 my $basketbranch = ''; # set a blank branch to start with
130 my $member = GetMember( borrowernumber => $authorisedby );
131 if ( $member ) {
132 $basketbranch = $member->{branchcode};
135 if ($userenv->{'flags'} & 1 || #user is superlibrarian
136 (haspermission( $uid, { acquisition => q{*} } ) && #user has acq permissions and
137 ($viewbaskets eq 'all' || #user is allowed to see all baskets
138 ($viewbaskets eq 'branch' && $authorisedby && $userbranch eq $basketbranch) || #basket belongs to user's branch
139 ($basket->{authorisedby} && $viewbaskets eq 'user' && $authorisedby == $loggedinuser) #user created this basket
142 ) {
143 foreach (qw(total_items total_biblios expected_items)) {
144 $basket->{$_} ||= 0;
146 if($member) {
147 $basket->{authorisedby_firstname} = $member->{firstname};
148 $basket->{authorisedby_surname} = $member->{surname};
150 push @{$loop_basket}, $basket;
154 push @{$loop_suppliers},
155 { loop_basket => $loop_basket,
156 booksellerid => $vendor->{id},
157 name => $vendor->{name},
158 active => $vendor->{active},
162 $template->param(
163 loop_suppliers => $loop_suppliers,
164 supplier => ( $booksellerid || $supplier ),
165 count => $supplier_count,
166 has_budgets => $has_budgets,
168 $template->{VARS}->{'allbaskets'} = $allbaskets;
170 output_html_with_http_headers $query, $cookie, $template->output;