Lines 58-63
use Koha::Acquisition::Booksellers;
Link Here
|
58 |
use Koha::ItemTypes; |
58 |
use Koha::ItemTypes; |
59 |
use Koha::Patrons; |
59 |
use Koha::Patrons; |
60 |
|
60 |
|
|
|
61 |
use List::MoreUtils qw/uniq/; |
62 |
|
61 |
our $input=new CGI; |
63 |
our $input=new CGI; |
62 |
|
64 |
|
63 |
our ($template, $loggedinuser, $cookie) |
65 |
our ($template, $loggedinuser, $cookie) |
Lines 87-95
sub BasketTotal {
Link Here
|
87 |
|
89 |
|
88 |
#displays all basketgroups and all closed baskets (in their respective groups) |
90 |
#displays all basketgroups and all closed baskets (in their respective groups) |
89 |
sub displaybasketgroups { |
91 |
sub displaybasketgroups { |
90 |
my $basketgroups = shift; |
92 |
my ($basketgroups, $bookseller, $baskets, $template) = @_; |
91 |
my $bookseller = shift; |
|
|
92 |
my $baskets = shift; |
93 |
if (scalar @$basketgroups != 0) { |
93 |
if (scalar @$basketgroups != 0) { |
94 |
foreach my $basketgroup (@$basketgroups){ |
94 |
foreach my $basketgroup (@$basketgroups){ |
95 |
my $i = 0; |
95 |
my $i = 0; |
Lines 123-151
sub displaybasketgroups {
Link Here
|
123 |
|
123 |
|
124 |
sub printbasketgrouppdf{ |
124 |
sub printbasketgrouppdf{ |
125 |
my ($basketgroupid) = @_; |
125 |
my ($basketgroupid) = @_; |
126 |
|
126 |
|
127 |
my $pdfformat = C4::Context->preference("OrderPdfFormat"); |
127 |
my $pdfformat = C4::Context->preference("OrderPdfFormat"); |
128 |
if ($pdfformat eq 'pdfformat::layout3pages' || $pdfformat eq 'pdfformat::layout2pages' || $pdfformat eq 'pdfformat::layout3pagesfr' |
128 |
if ($pdfformat eq 'pdfformat::layout3pages' || $pdfformat eq 'pdfformat::layout2pages' || $pdfformat eq 'pdfformat::layout3pagesfr' |
129 |
|| $pdfformat eq 'pdfformat::layout2pagesde'){ |
129 |
|| $pdfformat eq 'pdfformat::layout2pagesde'){ |
130 |
eval { |
130 |
eval { |
131 |
eval "require $pdfformat"; |
131 |
my $pdfformatfile = './' . ($pdfformat =~ s,::,/,gr) . '.pm'; |
132 |
import $pdfformat; |
132 |
require $pdfformatfile; |
133 |
}; |
133 |
import $pdfformat; |
134 |
if ($@){ |
134 |
}; |
135 |
} |
135 |
if ($@){ |
|
|
136 |
warn $@; |
137 |
} |
136 |
} |
138 |
} |
137 |
else { |
139 |
else { |
138 |
print $input->header; |
140 |
print $input->header; |
139 |
print $input->start_html; # FIXME Should do a nicer page |
141 |
print $input->start_html; # FIXME Should do a nicer page |
140 |
print "<h1>Invalid PDF Format set</h1>"; |
142 |
print "<h1>Invalid PDF Format set</h1>"; |
141 |
print "Please go to the systempreferences and set a valid pdfformat"; |
143 |
print "Please go to the systempreferences and set a valid pdfformat"; |
142 |
exit; |
144 |
exit; |
143 |
} |
145 |
} |
144 |
|
146 |
|
145 |
my $basketgroup = GetBasketgroup($basketgroupid); |
147 |
my $basketgroup = GetBasketgroup($basketgroupid); |
146 |
my $bookseller = Koha::Acquisition::Booksellers->find( $basketgroup->{booksellerid} ); |
148 |
my $bookseller = Koha::Acquisition::Booksellers->find( $basketgroup->{booksellerid} ); |
147 |
my $baskets = GetBasketsByBasketgroup($basketgroupid); |
149 |
my $baskets = GetBasketsByBasketgroup($basketgroupid); |
148 |
|
150 |
|
149 |
my %orders; |
151 |
my %orders; |
150 |
for my $basket (@$baskets) { |
152 |
for my $basket (@$baskets) { |
151 |
my @ba_orders; |
153 |
my @ba_orders; |
Lines 212-218
sub printbasketgrouppdf{
Link Here
|
212 |
); |
214 |
); |
213 |
my $pdf = printpdf($basketgroup, $bookseller, $baskets, \%orders, $bookseller->tax_rate // C4::Context->preference("gist")) || die "pdf generation failed"; |
215 |
my $pdf = printpdf($basketgroup, $bookseller, $baskets, \%orders, $bookseller->tax_rate // C4::Context->preference("gist")) || die "pdf generation failed"; |
214 |
print $pdf; |
216 |
print $pdf; |
215 |
|
|
|
216 |
} |
217 |
} |
217 |
|
218 |
|
218 |
sub generate_edifact_orders { |
219 |
sub generate_edifact_orders { |
Lines 226-295
sub generate_edifact_orders {
Link Here
|
226 |
return; |
227 |
return; |
227 |
} |
228 |
} |
228 |
|
229 |
|
229 |
my $op = $input->param('op') || 'display'; |
|
|
230 |
# possible values of $op : |
230 |
# possible values of $op : |
231 |
# - add : adds a new basketgroup, or edit an open basketgroup, or display a closed basketgroup |
|
|
232 |
# - mod_basket : modify an individual basket of the basketgroup |
231 |
# - mod_basket : modify an individual basket of the basketgroup |
233 |
# - closeandprint : close and print an closed basketgroup in pdf. called by clicking on "Close and print" button in closed basketgroups list |
232 |
# - closeandprint : close and print an closed basketgroup in pdf. called by |
234 |
# - print : print a closed basketgroup. called by clicking on "Print" button in closed basketgroups list |
233 |
# clicking on "Close and print" button in closed basketgroups list |
|
|
234 |
# - print : print a closed basketgroup. called by clicking on "Print" button in |
235 |
# closed basketgroups list |
235 |
# - ediprint : generate edi order messages for the baskets in the group |
236 |
# - ediprint : generate edi order messages for the baskets in the group |
236 |
# - export : export in CSV a closed basketgroup. called by clicking on "Export" button in closed basketgroups list |
237 |
# - export : export in CSV a closed basketgroup. called by clicking on "Export" |
237 |
# - delete : delete an open basketgroup. called by clicking on "Delete" button in open basketgroups list |
238 |
# button in closed basketgroups list |
238 |
# - reopen : reopen a closed basketgroup. called by clicking on "Reopen" button in closed basketgroup list |
239 |
# - delete : delete an open basketgroup. called by clicking on "Delete" button |
239 |
# - attachbasket : save a modified basketgroup, or creates a new basketgroup when a basket is closed. called from basket page |
240 |
# in open basketgroups list |
240 |
# - display : display the list of all basketgroups for a vendor |
241 |
# - reopen : reopen a closed basketgroup. called by clicking on "Reopen" button |
|
|
242 |
# in closed basketgroup list |
243 |
# - attachbasket : save a modified basketgroup, or creates a new basketgroup |
244 |
# when a basket is closed. called from basket page |
245 |
my $op = $input->param('op'); |
241 |
my $booksellerid = $input->param('booksellerid'); |
246 |
my $booksellerid = $input->param('booksellerid'); |
242 |
$template->param(booksellerid => $booksellerid); |
|
|
243 |
|
247 |
|
244 |
if ( $op eq "add" ) { |
248 |
if ($op eq 'mod_basket') { |
245 |
# |
|
|
246 |
# if no param('basketgroupid') is not defined, adds a new basketgroup |
247 |
# else, edit (if it is open) or display (if it is close) the basketgroup basketgroupid |
248 |
# the template will know if basketgroup must be displayed or edited, depending on the value of closed key |
249 |
# |
250 |
my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); |
251 |
my $basketgroupid = $input->param('basketgroupid'); |
252 |
my $billingplace; |
253 |
my $deliveryplace; |
254 |
my $freedeliveryplace; |
255 |
if ( $basketgroupid ) { |
256 |
# Get the selected baskets in the basketgroup to display them |
257 |
my $selecteds = GetBasketsByBasketgroup($basketgroupid); |
258 |
foreach my $basket(@{$selecteds}){ |
259 |
$basket->{total} = BasketTotal($basket->{basketno}, $bookseller); |
260 |
} |
261 |
$template->param(basketgroupid => $basketgroupid, |
262 |
selectedbaskets => $selecteds); |
263 |
|
264 |
# Get general informations about the basket group to prefill the form |
265 |
my $basketgroup = GetBasketgroup($basketgroupid); |
266 |
$template->param( |
267 |
name => $basketgroup->{name}, |
268 |
deliverycomment => $basketgroup->{deliverycomment}, |
269 |
freedeliveryplace => $basketgroup->{freedeliveryplace}, |
270 |
); |
271 |
$billingplace = $basketgroup->{billingplace}; |
272 |
$deliveryplace = $basketgroup->{deliveryplace}; |
273 |
$freedeliveryplace = $basketgroup->{freedeliveryplace}; |
274 |
$template->param( closedbg => ($basketgroup ->{'closed'}) ? 1 : 0); |
275 |
} else { |
276 |
$template->param( closedbg => 0); |
277 |
} |
278 |
# determine default billing and delivery places depending on librarian homebranch and existing basketgroup data |
279 |
my $patron = Koha::Patrons->find( $loggedinuser ); # FIXME Not needed if billingplace and deliveryplace are set |
280 |
$billingplace = $billingplace || $patron->branchcode; |
281 |
$deliveryplace = $deliveryplace || $patron->branchcode; |
282 |
|
283 |
$template->param( billingplace => $billingplace ); |
284 |
$template->param( deliveryplace => $deliveryplace ); |
285 |
$template->param( booksellerid => $booksellerid ); |
286 |
|
287 |
# the template will display a unique basketgroup |
288 |
$template->param(grouping => 1); |
289 |
my $basketgroups = &GetBasketgroups($booksellerid); |
290 |
my $baskets = &GetBasketsByBookseller($booksellerid); |
291 |
displaybasketgroups($basketgroups, $bookseller, $baskets); |
292 |
} elsif ($op eq 'mod_basket') { |
293 |
# |
249 |
# |
294 |
# edit an individual basket contained in this basketgroup |
250 |
# edit an individual basket contained in this basketgroup |
295 |
# |
251 |
# |
Lines 330-336
if ( $op eq "add" ) {
Link Here
|
330 |
# |
286 |
# |
331 |
my $basketgroupid = $input->param('basketgroupid'); |
287 |
my $basketgroupid = $input->param('basketgroupid'); |
332 |
DelBasketgroup($basketgroupid); |
288 |
DelBasketgroup($basketgroupid); |
333 |
print $input->redirect('/cgi-bin/koha/acqui/basketgroup.pl?booksellerid=' . $booksellerid.'&listclosed=1'); |
289 |
print $input->redirect('/cgi-bin/koha/acqui/basketgroups.pl?booksellerid=' . $booksellerid); |
|
|
290 |
exit; |
334 |
}elsif ( $op eq 'reopen'){ |
291 |
}elsif ( $op eq 'reopen'){ |
335 |
# |
292 |
# |
336 |
# reopen a closed basketgroup |
293 |
# reopen a closed basketgroup |
Lines 338-345
if ( $op eq "add" ) {
Link Here
|
338 |
my $basketgroupid = $input->param('basketgroupid'); |
295 |
my $basketgroupid = $input->param('basketgroupid'); |
339 |
my $booksellerid = $input->param('booksellerid'); |
296 |
my $booksellerid = $input->param('booksellerid'); |
340 |
ReOpenBasketgroup($basketgroupid); |
297 |
ReOpenBasketgroup($basketgroupid); |
341 |
my $redirectpath = ((defined $input->param('mode'))&& ($input->param('mode') eq 'singlebg')) ?'/cgi-bin/koha/acqui/basketgroup.pl?op=add&basketgroupid='.$basketgroupid.'&booksellerid='.$booksellerid : '/cgi-bin/koha/acqui/basketgroup.pl?booksellerid=' .$booksellerid.'&listclosed=1'; |
298 |
my $redirectpath; |
|
|
299 |
my $mode = $input->param('mode'); |
300 |
if (defined $mode && $mode eq 'singlebg') { |
301 |
$redirectpath = '/cgi-bin/koha/acqui/basketgroup.pl?op=add&basketgroupid='.$basketgroupid.'&booksellerid='.$booksellerid; |
302 |
} else { |
303 |
$redirectpath = '/cgi-bin/koha/acqui/basketgroups.pl?booksellerid=' .$booksellerid; |
304 |
} |
342 |
print $input->redirect($redirectpath); |
305 |
print $input->redirect($redirectpath); |
|
|
306 |
exit; |
343 |
} elsif ( $op eq 'attachbasket') { |
307 |
} elsif ( $op eq 'attachbasket') { |
344 |
# |
308 |
# |
345 |
# save a modified basketgroup, or creates a new basketgroup when a basket is closed. called from basket page |
309 |
# save a modified basketgroup, or creates a new basketgroup when a basket is closed. called from basket page |
Lines 385-406
if ( $op eq "add" ) {
Link Here
|
385 |
}; |
349 |
}; |
386 |
$basketgroupid = NewBasketgroup($basketgroup); |
350 |
$basketgroupid = NewBasketgroup($basketgroup); |
387 |
} |
351 |
} |
388 |
my $redirectpath = ((defined $input->param('mode')) && ($input->param('mode') eq 'singlebg')) ?'/cgi-bin/koha/acqui/basketgroup.pl?op=add&basketgroupid='.$basketgroupid.'&booksellerid='.$booksellerid : '/cgi-bin/koha/acqui/basketgroup.pl?booksellerid=' . $booksellerid; |
352 |
my $redirectpath; |
389 |
$redirectpath .= "&listclosed=1" if $closedbg ; |
353 |
my $mode = $input->param('mode'); |
390 |
print $input->redirect($redirectpath ); |
354 |
if (defined $mode && $mode eq 'singlebg') { |
391 |
|
355 |
$redirectpath = '/cgi-bin/koha/acqui/basketgroup.pl?op=add&basketgroupid='.$basketgroupid.'&booksellerid='.$booksellerid; |
|
|
356 |
} else { |
357 |
$redirectpath = '/cgi-bin/koha/acqui/basketgroups.pl?booksellerid=' . $booksellerid; |
358 |
} |
359 |
print $input->redirect($redirectpath); |
360 |
exit; |
392 |
} elsif ( $op eq 'ediprint') { |
361 |
} elsif ( $op eq 'ediprint') { |
393 |
my $basketgroupid = $input->param('basketgroupid'); |
362 |
my $basketgroupid = $input->param('basketgroupid'); |
394 |
generate_edifact_orders( $basketgroupid ); |
363 |
generate_edifact_orders( $basketgroupid ); |
395 |
exit; |
364 |
exit; |
396 |
}else{ |
365 |
} |
397 |
# no param : display the list of all basketgroups for a given vendor |
|
|
398 |
my $basketgroups = &GetBasketgroups($booksellerid); |
399 |
my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); |
400 |
my $baskets = &GetBasketsByBookseller($booksellerid); |
401 |
|
366 |
|
402 |
displaybasketgroups($basketgroups, $bookseller, $baskets); |
367 |
# if no param('basketgroupid') is not defined, adds a new basketgroup else, edit |
|
|
368 |
# (if it is open) or display (if it is close) the basketgroup basketgroupid the |
369 |
# template will know if basketgroup must be displayed or edited, depending on |
370 |
# the value of closed key |
371 |
|
372 |
my $bookseller = Koha::Acquisition::Booksellers->find($booksellerid); |
373 |
my $basketgroupid = $input->param('basketgroupid'); |
374 |
my $billingplace; |
375 |
my $deliveryplace; |
376 |
my $freedeliveryplace; |
377 |
if ( $basketgroupid ) { |
378 |
# Get the selected baskets in the basketgroup to display them |
379 |
my $selecteds = GetBasketsByBasketgroup($basketgroupid); |
380 |
foreach my $basket(@{$selecteds}){ |
381 |
$basket->{total} = BasketTotal($basket->{basketno}, $bookseller); |
382 |
} |
383 |
$template->param(basketgroupid => $basketgroupid, |
384 |
selectedbaskets => $selecteds); |
385 |
|
386 |
# Get general informations about the basket group to prefill the form |
387 |
my $basketgroup = GetBasketgroup($basketgroupid); |
388 |
$template->param( |
389 |
name => $basketgroup->{name}, |
390 |
billingplace => $basketgroup->{billingplace}, |
391 |
deliveryplace => $basketgroup->{deliveryplace}, |
392 |
deliverycomment => $basketgroup->{deliverycomment}, |
393 |
freedeliveryplace => $basketgroup->{freedeliveryplace}, |
394 |
closedbg => $basketgroup->{closed} ? 1 : 0 |
395 |
); |
396 |
} else { |
397 |
$template->param( closedbg => 0); |
403 |
} |
398 |
} |
404 |
$template->param(listclosed => ((defined $input->param('listclosed')) && ($input->param('listclosed') eq '1'))? 1:0 ); |
399 |
# determine default billing and delivery places depending on librarian homebranch and existing basketgroup data |
405 |
#prolly won't use all these, maybe just use print, the rest can be done inside validate |
400 |
my $borrower = Koha::Patrons->find( $loggedinuser ); |
|
|
401 |
$billingplace = $billingplace || $borrower->branchcode; |
402 |
$deliveryplace = $deliveryplace || $borrower->branchcode; |
403 |
|
404 |
$template->param( booksellerid => $booksellerid ); |
405 |
|
406 |
# the template will display a unique basketgroup |
407 |
my $basketgroups = &GetBasketgroups($booksellerid); |
408 |
my $baskets = &GetBasketsByBookseller($booksellerid); |
409 |
displaybasketgroups($basketgroups, $bookseller, $baskets, $template); |
410 |
|
406 |
output_html_with_http_headers $input, $cookie, $template->output; |
411 |
output_html_with_http_headers $input, $cookie, $template->output; |