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 open) or display (if it is close) the basketgroup basketgroupid |
315 |
# the template will know if basketgroup must be displayed or edited, depending on closed value |
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 |
} |
355 |
$template->param(grouping => 1); |
375 |
$template->param(grouping => 1); # the template will display a unique basketgroup |
356 |
my $basketgroups = &GetBasketgroups($booksellerid); |
376 |
my $basketgroups = &GetBasketgroups($booksellerid); |
357 |
my $bookseller = &GetBookSellerFromId($booksellerid); |
377 |
my $bookseller = &GetBookSellerFromId($booksellerid); |
358 |
my $baskets = &GetBasketsByBookseller($booksellerid); |
378 |
my $baskets = &GetBasketsByBookseller($booksellerid); |
359 |
|
|
|
360 |
displaybasketgroups($basketgroups, $bookseller, $baskets); |
379 |
displaybasketgroups($basketgroups, $bookseller, $baskets); |
361 |
} elsif ($op eq 'mod_basket') { |
380 |
} elsif ($op eq 'mod_basket') { |
362 |
#we want to modify an individual basket's group |
381 |
# |
|
|
382 |
# edit an individual basket contained in this basketgroup |
383 |
# |
363 |
my $basketno=$input->param('basketno'); |
384 |
my $basketno=$input->param('basketno'); |
364 |
my $basketgroupid=$input->param('basketgroupid'); |
385 |
my $basketgroupid=$input->param('basketgroupid'); |
365 |
ModBasket( { basketno => $basketno, |
386 |
ModBasket( { basketno => $basketno, basketgroupid => $basketgroupid } ); |
366 |
basketgroupid => $basketgroupid } ); |
|
|
367 |
print $input->redirect("basket.pl?basketno=" . $basketno); |
387 |
print $input->redirect("basket.pl?basketno=" . $basketno); |
368 |
} elsif ($op eq 'validate') { |
388 |
} elsif ($op eq 'validate') { |
|
|
389 |
# |
390 |
# FIXME dead code |
391 |
# |
369 |
if(! $booksellerid){ |
392 |
if(! $booksellerid){ |
370 |
$template->param( booksellererror => 1); |
393 |
$template->param( booksellererror => 1); |
371 |
} else { |
394 |
} else { |
Lines 374-380
if ( $op eq "add" ) {
Link Here
|
374 |
my $baskets = parseinputbaskets($booksellerid); |
397 |
my $baskets = parseinputbaskets($booksellerid); |
375 |
my ($basketgroups, $newbasketgroups) = parseinputbasketgroups($booksellerid, $baskets); |
398 |
my ($basketgroups, $newbasketgroups) = parseinputbasketgroups($booksellerid, $baskets); |
376 |
foreach my $nbgid (keys %$newbasketgroups){ |
399 |
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 |
400 |
#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}); |
401 |
my $bgid = NewBasketgroup($newbasketgroups->{$nbgid}); |
379 |
${$newbasketgroups->{$nbgid}}->{'id'} = $bgid; |
402 |
${$newbasketgroups->{$nbgid}}->{'id'} = $bgid; |
380 |
${$newbasketgroups->{$nbgid}}->{'oldid'} = $nbgid; |
403 |
${$newbasketgroups->{$nbgid}}->{'oldid'} = $nbgid; |
Lines 400-420
if ( $op eq "add" ) {
Link Here
|
400 |
$basketgroups = &GetBasketgroups($booksellerid); |
423 |
$basketgroups = &GetBasketgroups($booksellerid); |
401 |
my $bookseller = &GetBookSellerFromId($booksellerid); |
424 |
my $bookseller = &GetBookSellerFromId($booksellerid); |
402 |
$baskets = &GetBasketsByBookseller($booksellerid); |
425 |
$baskets = &GetBasketsByBookseller($booksellerid); |
|
|
426 |
# keep ungroupedbaskets |
403 |
|
427 |
|
404 |
displaybasketgroups($basketgroups, $bookseller, $baskets); |
428 |
displaybasketgroups($basketgroups, $bookseller, $baskets); |
405 |
} elsif ( $op eq 'closeandprint') { |
429 |
} elsif ( $op eq 'closeandprint') { |
|
|
430 |
# |
431 |
# close an open basketgroup and generates a pdf |
432 |
# |
406 |
my $basketgroupid = $input->param('basketgroupid'); |
433 |
my $basketgroupid = $input->param('basketgroupid'); |
407 |
|
|
|
408 |
CloseBasketgroup($basketgroupid); |
434 |
CloseBasketgroup($basketgroupid); |
409 |
|
|
|
410 |
printbasketgrouppdf($basketgroupid); |
435 |
printbasketgrouppdf($basketgroupid); |
411 |
exit; |
436 |
exit; |
412 |
}elsif ($op eq 'print'){ |
437 |
}elsif ($op eq 'print'){ |
|
|
438 |
# |
439 |
# print a closed basketgroup |
440 |
# |
413 |
my $basketgroupid = $input->param('basketgroupid'); |
441 |
my $basketgroupid = $input->param('basketgroupid'); |
414 |
|
|
|
415 |
printbasketgrouppdf($basketgroupid); |
442 |
printbasketgrouppdf($basketgroupid); |
416 |
exit; |
443 |
exit; |
417 |
}elsif ( $op eq "export" ) { |
444 |
}elsif ( $op eq "export" ) { |
|
|
445 |
# |
446 |
# export a closed basketgroup in csv |
447 |
# |
418 |
my $basketgroupid = $input->param('basketgroupid'); |
448 |
my $basketgroupid = $input->param('basketgroupid'); |
419 |
print $input->header( |
449 |
print $input->header( |
420 |
-type => 'text/csv', |
450 |
-type => 'text/csv', |
Lines 423-442
if ( $op eq "add" ) {
Link Here
|
423 |
print GetBasketGroupAsCSV( $basketgroupid, $input ); |
453 |
print GetBasketGroupAsCSV( $basketgroupid, $input ); |
424 |
exit; |
454 |
exit; |
425 |
}elsif( $op eq "delete"){ |
455 |
}elsif( $op eq "delete"){ |
|
|
456 |
# |
457 |
# delete an closed basketgroup |
458 |
# |
426 |
my $basketgroupid = $input->param('basketgroupid'); |
459 |
my $basketgroupid = $input->param('basketgroupid'); |
427 |
DelBasketgroup($basketgroupid); |
460 |
DelBasketgroup($basketgroupid); |
428 |
print $input->redirect('/cgi-bin/koha/acqui/basketgroup.pl?booksellerid=' . $booksellerid); |
461 |
print $input->redirect('/cgi-bin/koha/acqui/basketgroup.pl?booksellerid=' . $booksellerid.'&listclosed=1'); |
429 |
|
|
|
430 |
}elsif ( $op eq 'reopen'){ |
462 |
}elsif ( $op eq 'reopen'){ |
|
|
463 |
# |
464 |
# reopen a closed basketgroup |
465 |
# |
431 |
my $basketgroupid = $input->param('basketgroupid'); |
466 |
my $basketgroupid = $input->param('basketgroupid'); |
432 |
my $booksellerid = $input->param('booksellerid'); |
467 |
my $booksellerid = $input->param('booksellerid'); |
433 |
|
|
|
434 |
ReOpenBasketgroup($basketgroupid); |
468 |
ReOpenBasketgroup($basketgroupid); |
435 |
|
469 |
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'); |
470 |
print $input->redirect($redirectpath); |
437 |
|
|
|
438 |
} elsif ( $op eq 'attachbasket') { |
471 |
} elsif ( $op eq 'attachbasket') { |
439 |
|
472 |
# |
|
|
473 |
# save a modified basketgroup, or creates a new basketgroup when a basket is closed. called from basket page |
474 |
# |
440 |
# Getting parameters |
475 |
# Getting parameters |
441 |
my $basketgroup = {}; |
476 |
my $basketgroup = {}; |
442 |
my @baskets = $input->param('basket'); |
477 |
my @baskets = $input->param('basket'); |
Lines 447-455
if ( $op eq "add" ) {
Link Here
|
447 |
my $deliveryplace = $input->param('deliveryplace'); |
482 |
my $deliveryplace = $input->param('deliveryplace'); |
448 |
my $freedeliveryplace = $input->param('freedeliveryplace'); |
483 |
my $freedeliveryplace = $input->param('freedeliveryplace'); |
449 |
my $deliverycomment = $input->param('deliverycomment'); |
484 |
my $deliverycomment = $input->param('deliverycomment'); |
450 |
my $close = $input->param('close') ? 1 : 0; |
485 |
my $closedbg = $input->param('closedbg') ? 1 : 0; |
451 |
# If we got a basketgroupname, we create a basketgroup |
|
|
452 |
if ($basketgroupid) { |
486 |
if ($basketgroupid) { |
|
|
487 |
# If we have a basketgroupid we edit the basketgroup |
453 |
$basketgroup = { |
488 |
$basketgroup = { |
454 |
name => $basketgroupname, |
489 |
name => $basketgroupname, |
455 |
id => $basketgroupid, |
490 |
id => $basketgroupid, |
Lines 458-470
if ( $op eq "add" ) {
Link Here
|
458 |
deliveryplace => $deliveryplace, |
493 |
deliveryplace => $deliveryplace, |
459 |
freedeliveryplace => $freedeliveryplace, |
494 |
freedeliveryplace => $freedeliveryplace, |
460 |
deliverycomment => $deliverycomment, |
495 |
deliverycomment => $deliverycomment, |
461 |
closed => $close, |
496 |
closed => $closedbg, |
462 |
}; |
497 |
}; |
463 |
ModBasketgroup($basketgroup); |
498 |
ModBasketgroup($basketgroup); |
464 |
if($close){ |
499 |
if($closedbg){ |
465 |
|
500 |
# FIXME |
466 |
} |
501 |
} |
467 |
}else{ |
502 |
}else{ |
|
|
503 |
# we create a new basketgroup (whith a closed basket) |
468 |
$basketgroup = { |
504 |
$basketgroup = { |
469 |
name => $basketgroupname, |
505 |
name => $basketgroupname, |
470 |
booksellerid => $booksellerid, |
506 |
booksellerid => $booksellerid, |
Lines 473-494
if ( $op eq "add" ) {
Link Here
|
473 |
deliveryplace => $deliveryplace, |
509 |
deliveryplace => $deliveryplace, |
474 |
freedeliveryplace => $freedeliveryplace, |
510 |
freedeliveryplace => $freedeliveryplace, |
475 |
deliverycomment => $deliverycomment, |
511 |
deliverycomment => $deliverycomment, |
476 |
closed => $close, |
512 |
closed => $closedbg, |
477 |
}; |
513 |
}; |
478 |
$basketgroupid = NewBasketgroup($basketgroup); |
514 |
$basketgroupid = NewBasketgroup($basketgroup); |
479 |
} |
515 |
} |
480 |
|
516 |
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; |
517 |
$redirectpath .= "&listclosed=1" if $closedbg ; |
482 |
$url .= "&closed=1" if ($input->param("closed")); |
518 |
print $input->redirect($redirectpath ); |
483 |
print $input->redirect($url); |
|
|
484 |
|
519 |
|
485 |
}else{ |
520 |
}else{ |
|
|
521 |
# no param : display the list of all basketgroups for a given vendor |
486 |
my $basketgroups = &GetBasketgroups($booksellerid); |
522 |
my $basketgroups = &GetBasketgroups($booksellerid); |
487 |
my $bookseller = &GetBookSellerFromId($booksellerid); |
523 |
my $bookseller = &GetBookSellerFromId($booksellerid); |
488 |
my $baskets = &GetBasketsByBookseller($booksellerid); |
524 |
my $baskets = &GetBasketsByBookseller($booksellerid); |
489 |
|
525 |
|
490 |
displaybasketgroups($basketgroups, $bookseller, $baskets); |
526 |
displaybasketgroups($basketgroups, $bookseller, $baskets); |
491 |
} |
527 |
} |
492 |
$template->param(closed => $input->param("closed")); |
528 |
$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 |
529 |
#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; |
530 |
output_html_with_http_headers $input, $cookie, $template->output; |