Lines 29-35
basketgroup.pl
Link Here
|
29 |
=head1 DESCRIPTION |
29 |
=head1 DESCRIPTION |
30 |
|
30 |
|
31 |
This script lets the user group (closed) baskets into basket groups for easier order management. Note that the grouped baskets have to be from the same bookseller and |
31 |
This script lets the user group (closed) baskets into basket groups for easier order management. Note that the grouped baskets have to be from the same bookseller and |
32 |
have to be closed. |
32 |
have to be closed to be printed or exported. |
33 |
|
33 |
|
34 |
=head1 CGI PARAMETERS |
34 |
=head1 CGI PARAMETERS |
35 |
|
35 |
|
Lines 294-304
sub printbasketgrouppdf{
Link Here
|
294 |
} |
294 |
} |
295 |
|
295 |
|
296 |
my $op = $input->param('op') || 'display'; |
296 |
my $op = $input->param('op') || 'display'; |
|
|
297 |
# possible values of $op : |
298 |
# - add : adds a new basketgroup, or edit an open basketgroup, or display a closed basketgroup |
299 |
# - mod_basket : modify an individual basket of the basketgroup |
300 |
# - validate : FIXME dead code |
301 |
# - closeandprint : close and print an closed basketgroup in pdf. called by clicking on "Close and print" button in closed basketgroups list |
302 |
# - print : print a closed basketgroup. called by clicking on "Print" button in closed basketgroups list |
303 |
# - export : export in CSV a closed basketgroup. called by clicking on "Export" button in closed basketgroups list |
304 |
# - delete : delete an open basketgroup. called by clicking on "Delete" button in open basketgroups list |
305 |
# - reopen : reopen a closed basketgroup. called by clicking on "Reopen" button in closed basketgroup list |
306 |
# - attachbasket : save a modified basketgroup, or creates a new basketgroup when a basket is closed. called from basket page |
307 |
# - display : display the list of all basketgroups for a vendor |
297 |
my $booksellerid = $input->param('booksellerid'); |
308 |
my $booksellerid = $input->param('booksellerid'); |
298 |
$template->param(booksellerid => $booksellerid); |
309 |
$template->param(booksellerid => $booksellerid); |
299 |
|
310 |
|
300 |
if ( $op eq "add" ) { |
311 |
if ( $op eq "add" ) { |
|
|
312 |
# |
313 |
# if no param('basketgroupid') is not defined, adds a new basketgroup |
314 |
# else, edit (if it is open) or display (if it is close) the basketgroup basketgroupid |
315 |
# the template will know if basketgroup must be displayed or edited, depending on the value of closed key |
316 |
# |
301 |
if(! $booksellerid){ |
317 |
if(! $booksellerid){ |
|
|
318 |
# Unknown bookseller |
319 |
# FIXME : ungroupedlist does not seem to be used in this file nor in template |
302 |
$template->param( ungroupedlist => 1); |
320 |
$template->param( ungroupedlist => 1); |
303 |
my @booksellers = GetBookSeller(''); |
321 |
my @booksellers = GetBookSeller(''); |
304 |
for (my $i=0; $i < scalar @booksellers; $i++) { |
322 |
for (my $i=0; $i < scalar @booksellers; $i++) { |
Lines 315-320
if ( $op eq "add" ) {
Link Here
|
315 |
} |
333 |
} |
316 |
} |
334 |
} |
317 |
} else { |
335 |
} else { |
|
|
336 |
# Known bookseller |
318 |
my $basketgroupid = $input->param('basketgroupid'); |
337 |
my $basketgroupid = $input->param('basketgroupid'); |
319 |
my $billingplace; |
338 |
my $billingplace; |
320 |
my $deliveryplace; |
339 |
my $deliveryplace; |
Lines 338-345
if ( $op eq "add" ) {
Link Here
|
338 |
$billingplace = $basketgroup->{billingplace}; |
357 |
$billingplace = $basketgroup->{billingplace}; |
339 |
$deliveryplace = $basketgroup->{deliveryplace}; |
358 |
$deliveryplace = $basketgroup->{deliveryplace}; |
340 |
$freedeliveryplace = $basketgroup->{freedeliveryplace}; |
359 |
$freedeliveryplace = $basketgroup->{freedeliveryplace}; |
|
|
360 |
$template->param( closedbg => ($basketgroup ->{'closed'}) ? 1 : 0); |
361 |
} else { |
362 |
$template->param( closedbg => 0); |
341 |
} |
363 |
} |
342 |
|
|
|
343 |
# determine default billing and delivery places depending on librarian homebranch and existing basketgroup data |
364 |
# determine default billing and delivery places depending on librarian homebranch and existing basketgroup data |
344 |
my $borrower = GetMember( ( 'borrowernumber' => $loggedinuser ) ); |
365 |
my $borrower = GetMember( ( 'borrowernumber' => $loggedinuser ) ); |
345 |
$billingplace = $billingplace || $borrower->{'branchcode'}; |
366 |
$billingplace = $billingplace || $borrower->{'branchcode'}; |
Lines 349-371
if ( $op eq "add" ) {
Link Here
|
349 |
$template->param( billingplaceloop => $branches ); |
370 |
$template->param( billingplaceloop => $branches ); |
350 |
$branches = C4::Branch::GetBranchesLoop( $deliveryplace ); |
371 |
$branches = C4::Branch::GetBranchesLoop( $deliveryplace ); |
351 |
$template->param( deliveryplaceloop => $branches ); |
372 |
$template->param( deliveryplaceloop => $branches ); |
352 |
|
|
|
353 |
$template->param( booksellerid => $booksellerid ); |
373 |
$template->param( booksellerid => $booksellerid ); |
354 |
} |
374 |
} |
|
|
375 |
# the template will display a unique basketgroup |
355 |
$template->param(grouping => 1); |
376 |
$template->param(grouping => 1); |
356 |
my $basketgroups = &GetBasketgroups($booksellerid); |
377 |
my $basketgroups = &GetBasketgroups($booksellerid); |
357 |
my $bookseller = &GetBookSellerFromId($booksellerid); |
378 |
my $bookseller = &GetBookSellerFromId($booksellerid); |
358 |
my $baskets = &GetBasketsByBookseller($booksellerid); |
379 |
my $baskets = &GetBasketsByBookseller($booksellerid); |
359 |
|
|
|
360 |
displaybasketgroups($basketgroups, $bookseller, $baskets); |
380 |
displaybasketgroups($basketgroups, $bookseller, $baskets); |
361 |
} elsif ($op eq 'mod_basket') { |
381 |
} elsif ($op eq 'mod_basket') { |
362 |
#we want to modify an individual basket's group |
382 |
# |
|
|
383 |
# edit an individual basket contained in this basketgroup |
384 |
# |
363 |
my $basketno=$input->param('basketno'); |
385 |
my $basketno=$input->param('basketno'); |
364 |
my $basketgroupid=$input->param('basketgroupid'); |
386 |
my $basketgroupid=$input->param('basketgroupid'); |
365 |
ModBasket( { basketno => $basketno, |
387 |
ModBasket( { basketno => $basketno, |
366 |
basketgroupid => $basketgroupid } ); |
388 |
basketgroupid => $basketgroupid } ); |
367 |
print $input->redirect("basket.pl?basketno=" . $basketno); |
389 |
print $input->redirect("basket.pl?basketno=" . $basketno); |
368 |
} elsif ($op eq 'validate') { |
390 |
} elsif ($op eq 'validate') { |
|
|
391 |
# |
392 |
# FIXME dead code |
393 |
# |
369 |
if(! $booksellerid){ |
394 |
if(! $booksellerid){ |
370 |
$template->param( booksellererror => 1); |
395 |
$template->param( booksellererror => 1); |
371 |
} else { |
396 |
} else { |
Lines 374-380
if ( $op eq "add" ) {
Link Here
|
374 |
my $baskets = parseinputbaskets($booksellerid); |
399 |
my $baskets = parseinputbaskets($booksellerid); |
375 |
my ($basketgroups, $newbasketgroups) = parseinputbasketgroups($booksellerid, $baskets); |
400 |
my ($basketgroups, $newbasketgroups) = parseinputbasketgroups($booksellerid, $baskets); |
376 |
foreach my $nbgid (keys %$newbasketgroups){ |
401 |
foreach my $nbgid (keys %$newbasketgroups){ |
377 |
#javascript just picks an ID that's higher than anything else, the ID might not be correct..chenge it and change all the basket's basketgroupid as well |
402 |
#javascript just picks an ID that's higher than anything else, the ID might not be correct..change it and change all the basket's basketgroupid as well |
378 |
my $bgid = NewBasketgroup($newbasketgroups->{$nbgid}); |
403 |
my $bgid = NewBasketgroup($newbasketgroups->{$nbgid}); |
379 |
${$newbasketgroups->{$nbgid}}->{'id'} = $bgid; |
404 |
${$newbasketgroups->{$nbgid}}->{'id'} = $bgid; |
380 |
${$newbasketgroups->{$nbgid}}->{'oldid'} = $nbgid; |
405 |
${$newbasketgroups->{$nbgid}}->{'oldid'} = $nbgid; |
Lines 400-420
if ( $op eq "add" ) {
Link Here
|
400 |
$basketgroups = &GetBasketgroups($booksellerid); |
425 |
$basketgroups = &GetBasketgroups($booksellerid); |
401 |
my $bookseller = &GetBookSellerFromId($booksellerid); |
426 |
my $bookseller = &GetBookSellerFromId($booksellerid); |
402 |
$baskets = &GetBasketsByBookseller($booksellerid); |
427 |
$baskets = &GetBasketsByBookseller($booksellerid); |
|
|
428 |
# keep ungroupedbaskets |
403 |
|
429 |
|
404 |
displaybasketgroups($basketgroups, $bookseller, $baskets); |
430 |
displaybasketgroups($basketgroups, $bookseller, $baskets); |
405 |
} elsif ( $op eq 'closeandprint') { |
431 |
} elsif ( $op eq 'closeandprint') { |
|
|
432 |
# |
433 |
# close an open basketgroup and generates a pdf |
434 |
# |
406 |
my $basketgroupid = $input->param('basketgroupid'); |
435 |
my $basketgroupid = $input->param('basketgroupid'); |
407 |
|
|
|
408 |
CloseBasketgroup($basketgroupid); |
436 |
CloseBasketgroup($basketgroupid); |
409 |
|
|
|
410 |
printbasketgrouppdf($basketgroupid); |
437 |
printbasketgrouppdf($basketgroupid); |
411 |
exit; |
438 |
exit; |
412 |
}elsif ($op eq 'print'){ |
439 |
}elsif ($op eq 'print'){ |
|
|
440 |
# |
441 |
# print a closed basketgroup |
442 |
# |
413 |
my $basketgroupid = $input->param('basketgroupid'); |
443 |
my $basketgroupid = $input->param('basketgroupid'); |
414 |
|
|
|
415 |
printbasketgrouppdf($basketgroupid); |
444 |
printbasketgrouppdf($basketgroupid); |
416 |
exit; |
445 |
exit; |
417 |
}elsif ( $op eq "export" ) { |
446 |
}elsif ( $op eq "export" ) { |
|
|
447 |
# |
448 |
# export a closed basketgroup in csv |
449 |
# |
418 |
my $basketgroupid = $input->param('basketgroupid'); |
450 |
my $basketgroupid = $input->param('basketgroupid'); |
419 |
print $input->header( |
451 |
print $input->header( |
420 |
-type => 'text/csv', |
452 |
-type => 'text/csv', |
Lines 423-442
if ( $op eq "add" ) {
Link Here
|
423 |
print GetBasketGroupAsCSV( $basketgroupid, $input ); |
455 |
print GetBasketGroupAsCSV( $basketgroupid, $input ); |
424 |
exit; |
456 |
exit; |
425 |
}elsif( $op eq "delete"){ |
457 |
}elsif( $op eq "delete"){ |
|
|
458 |
# |
459 |
# delete an closed basketgroup |
460 |
# |
426 |
my $basketgroupid = $input->param('basketgroupid'); |
461 |
my $basketgroupid = $input->param('basketgroupid'); |
427 |
DelBasketgroup($basketgroupid); |
462 |
DelBasketgroup($basketgroupid); |
428 |
print $input->redirect('/cgi-bin/koha/acqui/basketgroup.pl?booksellerid=' . $booksellerid); |
463 |
print $input->redirect('/cgi-bin/koha/acqui/basketgroup.pl?booksellerid=' . $booksellerid.'&listclosed=1'); |
429 |
|
|
|
430 |
}elsif ( $op eq 'reopen'){ |
464 |
}elsif ( $op eq 'reopen'){ |
|
|
465 |
# |
466 |
# reopen a closed basketgroup |
467 |
# |
431 |
my $basketgroupid = $input->param('basketgroupid'); |
468 |
my $basketgroupid = $input->param('basketgroupid'); |
432 |
my $booksellerid = $input->param('booksellerid'); |
469 |
my $booksellerid = $input->param('booksellerid'); |
433 |
|
|
|
434 |
ReOpenBasketgroup($basketgroupid); |
470 |
ReOpenBasketgroup($basketgroupid); |
435 |
|
471 |
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'; |
436 |
print $input->redirect('/cgi-bin/koha/acqui/basketgroup.pl?booksellerid=' . $booksellerid . '#closed'); |
472 |
print $input->redirect($redirectpath); |
437 |
|
|
|
438 |
} elsif ( $op eq 'attachbasket') { |
473 |
} elsif ( $op eq 'attachbasket') { |
439 |
|
474 |
# |
|
|
475 |
# save a modified basketgroup, or creates a new basketgroup when a basket is closed. called from basket page |
476 |
# |
440 |
# Getting parameters |
477 |
# Getting parameters |
441 |
my $basketgroup = {}; |
478 |
my $basketgroup = {}; |
442 |
my @baskets = $input->param('basket'); |
479 |
my @baskets = $input->param('basket'); |
Lines 447-455
if ( $op eq "add" ) {
Link Here
|
447 |
my $deliveryplace = $input->param('deliveryplace'); |
484 |
my $deliveryplace = $input->param('deliveryplace'); |
448 |
my $freedeliveryplace = $input->param('freedeliveryplace'); |
485 |
my $freedeliveryplace = $input->param('freedeliveryplace'); |
449 |
my $deliverycomment = $input->param('deliverycomment'); |
486 |
my $deliverycomment = $input->param('deliverycomment'); |
450 |
my $close = $input->param('close') ? 1 : 0; |
487 |
my $closedbg = $input->param('closedbg') ? 1 : 0; |
451 |
# If we got a basketgroupname, we create a basketgroup |
|
|
452 |
if ($basketgroupid) { |
488 |
if ($basketgroupid) { |
|
|
489 |
# If we have a basketgroupid we edit the basketgroup |
453 |
$basketgroup = { |
490 |
$basketgroup = { |
454 |
name => $basketgroupname, |
491 |
name => $basketgroupname, |
455 |
id => $basketgroupid, |
492 |
id => $basketgroupid, |
Lines 458-470
if ( $op eq "add" ) {
Link Here
|
458 |
deliveryplace => $deliveryplace, |
495 |
deliveryplace => $deliveryplace, |
459 |
freedeliveryplace => $freedeliveryplace, |
496 |
freedeliveryplace => $freedeliveryplace, |
460 |
deliverycomment => $deliverycomment, |
497 |
deliverycomment => $deliverycomment, |
461 |
closed => $close, |
498 |
closed => $closedbg, |
462 |
}; |
499 |
}; |
463 |
ModBasketgroup($basketgroup); |
500 |
ModBasketgroup($basketgroup); |
464 |
if($close){ |
501 |
if($closedbg){ |
465 |
|
502 |
# FIXME |
466 |
} |
503 |
} |
467 |
}else{ |
504 |
}else{ |
|
|
505 |
# we create a new basketgroup (whith a closed basket) |
468 |
$basketgroup = { |
506 |
$basketgroup = { |
469 |
name => $basketgroupname, |
507 |
name => $basketgroupname, |
470 |
booksellerid => $booksellerid, |
508 |
booksellerid => $booksellerid, |
Lines 473-494
if ( $op eq "add" ) {
Link Here
|
473 |
deliveryplace => $deliveryplace, |
511 |
deliveryplace => $deliveryplace, |
474 |
freedeliveryplace => $freedeliveryplace, |
512 |
freedeliveryplace => $freedeliveryplace, |
475 |
deliverycomment => $deliverycomment, |
513 |
deliverycomment => $deliverycomment, |
476 |
closed => $close, |
514 |
closed => $closedbg, |
477 |
}; |
515 |
}; |
478 |
$basketgroupid = NewBasketgroup($basketgroup); |
516 |
$basketgroupid = NewBasketgroup($basketgroup); |
479 |
} |
517 |
} |
480 |
|
518 |
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; |
481 |
my $url = '/cgi-bin/koha/acqui/basketgroup.pl?booksellerid=' . $booksellerid; |
519 |
$redirectpath .= "&listclosed=1" if $closedbg ; |
482 |
$url .= "&closed=1" if ($input->param("closed")); |
520 |
print $input->redirect($redirectpath ); |
483 |
print $input->redirect($url); |
|
|
484 |
|
521 |
|
485 |
}else{ |
522 |
}else{ |
|
|
523 |
# no param : display the list of all basketgroups for a given vendor |
486 |
my $basketgroups = &GetBasketgroups($booksellerid); |
524 |
my $basketgroups = &GetBasketgroups($booksellerid); |
487 |
my $bookseller = &GetBookSellerFromId($booksellerid); |
525 |
my $bookseller = &GetBookSellerFromId($booksellerid); |
488 |
my $baskets = &GetBasketsByBookseller($booksellerid); |
526 |
my $baskets = &GetBasketsByBookseller($booksellerid); |
489 |
|
527 |
|
490 |
displaybasketgroups($basketgroups, $bookseller, $baskets); |
528 |
displaybasketgroups($basketgroups, $bookseller, $baskets); |
491 |
} |
529 |
} |
492 |
$template->param(closed => $input->param("closed")); |
530 |
$template->param(listclosed => ((defined $input->param('listclosed')) && ($input->param('listclosed') eq '1'))? 1:0 ); |
493 |
#prolly won't use all these, maybe just use print, the rest can be done inside validate |
531 |
#prolly won't use all these, maybe just use print, the rest can be done inside validate |
494 |
output_html_with_http_headers $input, $cookie, $template->output; |
532 |
output_html_with_http_headers $input, $cookie, $template->output; |