|
Lines 1-7
Link Here
|
| 1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
| 2 |
|
2 |
|
| 3 |
#script to show suppliers and orders |
|
|
| 4 |
|
| 5 |
# Copyright 2000-2002 Katipo Communications |
3 |
# Copyright 2000-2002 Katipo Communications |
| 6 |
# Copyright 2008-2009 BibLibre SARL |
4 |
# Copyright 2008-2009 BibLibre SARL |
| 7 |
# Copyright 2010 PTFS Europe |
5 |
# Copyright 2010 PTFS Europe |
|
Lines 27-48
booksellers.pl
Link Here
|
| 27 |
|
25 |
|
| 28 |
=head1 DESCRIPTION |
26 |
=head1 DESCRIPTION |
| 29 |
|
27 |
|
| 30 |
this script displays the list of suppliers & baskets like C<$supplier> given on input arg. |
28 |
this script displays the baskets for a vendor |
| 31 |
thus, this page brings different features like to display supplier's details, |
|
|
| 32 |
to add an order for a specific supplier or to just add a new supplier. |
| 33 |
|
29 |
|
| 34 |
=head1 CGI PARAMETERS |
30 |
=head1 CGI PARAMETERS |
| 35 |
|
31 |
|
| 36 |
=over 4 |
32 |
=over 4 |
| 37 |
|
33 |
|
| 38 |
=item supplier |
|
|
| 39 |
|
| 40 |
C<$supplier> is the string with which we search for a supplier |
| 41 |
|
| 42 |
=back |
| 43 |
|
| 44 |
=over 4 |
| 45 |
|
| 46 |
=item id or booksellerid |
34 |
=item id or booksellerid |
| 47 |
|
35 |
|
| 48 |
The id of the supplier whose baskets we will display |
36 |
The id of the supplier whose baskets we will display |
|
Lines 52-68
The id of the supplier whose baskets we will display
Link Here
|
| 52 |
=cut |
40 |
=cut |
| 53 |
|
41 |
|
| 54 |
use Modern::Perl; |
42 |
use Modern::Perl; |
| 55 |
use C4::Auth qw( get_template_and_user haspermission ); |
43 |
use C4::Auth qw( get_template_and_user haspermission ); |
| 56 |
use C4::Budgets qw( GetBudgetHierarchy GetBudget CanUserUseBudget ); |
44 |
use C4::Output qw( output_html_with_http_headers ); |
| 57 |
use C4::Output qw( output_html_with_http_headers ); |
45 |
use CGI qw ( -utf8 ); |
| 58 |
use CGI qw ( -utf8 ); |
|
|
| 59 |
|
46 |
|
| 60 |
use C4::Acquisition qw( GetBasket GetBasketsInfosByBookseller CanUserManageBasket GetBasketgroup ); |
47 |
use C4::Acquisition qw( GetBasket GetBasketsInfosByBookseller CanUserManageBasket GetBasketgroup ); |
| 61 |
use C4::Context; |
|
|
| 62 |
|
48 |
|
| 63 |
use Koha::Acquisition::Booksellers; |
49 |
use Koha::Acquisition::Booksellers; |
| 64 |
use Koha::Patrons; |
50 |
use Koha::Patrons; |
| 65 |
use Koha::Acquisition::Currencies; |
|
|
| 66 |
|
51 |
|
| 67 |
my $query = CGI->new; |
52 |
my $query = CGI->new; |
| 68 |
my ( $template, $loggedinuser, $cookie, $userflags ) = get_template_and_user( |
53 |
my ( $template, $loggedinuser, $cookie, $userflags ) = get_template_and_user( |
|
Lines 75-139
my ( $template, $loggedinuser, $cookie, $userflags ) = get_template_and_user(
Link Here
|
| 75 |
); |
60 |
); |
| 76 |
|
61 |
|
| 77 |
#parameters |
62 |
#parameters |
| 78 |
my $supplier = $query->param('supplier'); |
|
|
| 79 |
my $booksellerid = $query->param('booksellerid'); |
63 |
my $booksellerid = $query->param('booksellerid'); |
| 80 |
my $allbaskets = $query->param('allbaskets') || 0; |
64 |
my $allbaskets = $query->param('allbaskets') || 0; |
| 81 |
my @suppliers; |
65 |
|
|
|
66 |
my $vendor; |
| 67 |
my $loop_suppliers = []; |
| 82 |
|
68 |
|
| 83 |
if ($booksellerid) { |
69 |
if ($booksellerid) { |
| 84 |
push @suppliers, Koha::Acquisition::Booksellers->find($booksellerid); |
70 |
$vendor = Koha::Acquisition::Booksellers->find($booksellerid); |
| 85 |
} else { |
|
|
| 86 |
@suppliers = Koha::Acquisition::Booksellers->search( |
| 87 |
[ |
| 88 |
{ name => { -like => "%$supplier%" } }, |
| 89 |
{ 'aqbookseller_aliases.alias' => { -like => "%$supplier%" } }, |
| 90 |
], |
| 91 |
{ |
| 92 |
order_by => { -asc => 'name' }, |
| 93 |
join => 'aqbookseller_aliases', |
| 94 |
distinct => 1, |
| 95 |
} |
| 96 |
)->as_list; |
| 97 |
} |
| 98 |
|
71 |
|
| 99 |
my $supplier_count = @suppliers; |
|
|
| 100 |
if ( $supplier_count == 1 ) { |
| 101 |
$template->param( |
72 |
$template->param( |
| 102 |
supplier_name => $suppliers[0]->name, |
73 |
supplier_name => $vendor->name, |
| 103 |
booksellerid => $suppliers[0]->id, |
74 |
booksellerid => $vendor->id, |
| 104 |
basketcount => $suppliers[0]->baskets->count, |
75 |
basketcount => $vendor->baskets->count, |
| 105 |
subscriptionscount => $suppliers[0]->subscriptions->count, |
76 |
subscriptionscount => $vendor->subscriptions->count, |
| 106 |
active => $suppliers[0]->active, |
77 |
active => $vendor->active, |
| 107 |
); |
78 |
); |
| 108 |
} |
|
|
| 109 |
|
79 |
|
| 110 |
my $uid; |
|
|
| 111 |
|
| 112 |
# FIXME This script should only be accessed by a valid logged in patron |
| 113 |
if ($loggedinuser) { |
| 114 |
|
| 115 |
# FIXME Should not be needed, logged in patron should be cached |
| 116 |
$uid = Koha::Patrons->find($loggedinuser)->userid; |
| 117 |
} |
| 118 |
|
| 119 |
my $userenv = C4::Context::userenv; |
| 120 |
my $viewbaskets = C4::Context->preference('AcqViewBaskets'); |
| 121 |
|
| 122 |
my $userbranch = $userenv->{branch}; |
| 123 |
|
| 124 |
my $budgets = GetBudgetHierarchy; |
| 125 |
my $has_budgets = 0; |
| 126 |
foreach my $r ( @{$budgets} ) { |
| 127 |
next unless ( CanUserUseBudget( $loggedinuser, $r, $userflags ) ); |
| 128 |
|
| 129 |
$has_budgets = 1; |
| 130 |
last; |
| 131 |
} |
| 132 |
|
| 133 |
#build result page |
| 134 |
my $loop_suppliers = []; |
| 135 |
|
| 136 |
for my $vendor (@suppliers) { |
| 137 |
my $baskets = GetBasketsInfosByBookseller( $vendor->id, $allbaskets ); |
80 |
my $baskets = GetBasketsInfosByBookseller( $vendor->id, $allbaskets ); |
| 138 |
|
81 |
|
| 139 |
my $loop_basket = []; |
82 |
my $loop_basket = []; |
|
Lines 167-180
for my $vendor (@suppliers) {
Link Here
|
| 167 |
basketcount => $vendor->baskets->count, |
110 |
basketcount => $vendor->baskets->count, |
| 168 |
subscriptioncount => $vendor->subscriptions->count, |
111 |
subscriptioncount => $vendor->subscriptions->count, |
| 169 |
}; |
112 |
}; |
| 170 |
|
|
|
| 171 |
} |
113 |
} |
| 172 |
|
114 |
|
| 173 |
$template->param( |
115 |
$template->param( |
| 174 |
loop_suppliers => $loop_suppliers, |
116 |
loop_suppliers => $loop_suppliers, |
| 175 |
supplier => ( $booksellerid || $supplier ), |
117 |
supplier => $booksellerid, |
| 176 |
count => $supplier_count, |
118 |
count => $vendor ? 1 : 0, |
| 177 |
has_budgets => $has_budgets, |
|
|
| 178 |
); |
119 |
); |
| 179 |
$template->{VARS}->{'allbaskets'} = $allbaskets; |
120 |
$template->{VARS}->{'allbaskets'} = $allbaskets; |
| 180 |
|
121 |
|