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 233-252
sub generate_edifact_orders {
Link Here
|
233 |
return; |
234 |
return; |
234 |
} |
235 |
} |
235 |
|
236 |
|
236 |
my $op = $input->param('op') || 'display'; |
|
|
237 |
# possible values of $op : |
237 |
# possible values of $op : |
238 |
# - add : adds a new basketgroup, or edit an open basketgroup, or display a closed basketgroup |
|
|
239 |
# - mod_basket : modify an individual basket of the basketgroup |
238 |
# - mod_basket : modify an individual basket of the basketgroup |
240 |
# - closeandprint : close and print an closed basketgroup in pdf. called by clicking on "Close and print" button in closed basketgroups list |
239 |
# - closeandprint : close and print an closed basketgroup in pdf. called by |
241 |
# - print : print a closed basketgroup. called by clicking on "Print" button in closed basketgroups list |
240 |
# clicking on "Close and print" button in closed basketgroups list |
|
|
241 |
# - print : print a closed basketgroup. called by clicking on "Print" button in |
242 |
# closed basketgroups list |
242 |
# - ediprint : generate edi order messages for the baskets in the group |
243 |
# - ediprint : generate edi order messages for the baskets in the group |
243 |
# - export : export in CSV a closed basketgroup. called by clicking on "Export" button in closed basketgroups list |
244 |
# - export : export in CSV a closed basketgroup. called by clicking on "Export" |
244 |
# - delete : delete an open basketgroup. called by clicking on "Delete" button in open basketgroups list |
245 |
# button in closed basketgroups list |
245 |
# - reopen : reopen a closed basketgroup. called by clicking on "Reopen" button in closed basketgroup list |
246 |
# - delete : delete an open basketgroup. called by clicking on "Delete" button |
246 |
# - attachbasket : save a modified basketgroup, or creates a new basketgroup when a basket is closed. called from basket page |
247 |
# in open basketgroups list |
247 |
# - display : display the list of all basketgroups for a vendor |
248 |
# - reopen : reopen a closed basketgroup. called by clicking on "Reopen" button |
|
|
249 |
# in closed basketgroup list |
250 |
# - attachbasket : save a modified basketgroup, or creates a new basketgroup |
251 |
# when a basket is closed. called from basket page |
252 |
my $op = $input->param('op'); |
248 |
my $booksellerid = $input->param('booksellerid'); |
253 |
my $booksellerid = $input->param('booksellerid'); |
249 |
$template->param(booksellerid => $booksellerid); |
|
|
250 |
my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); |
254 |
my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); |
251 |
|
255 |
|
252 |
my $schema = Koha::Database->new()->schema(); |
256 |
my $schema = Koha::Database->new()->schema(); |
Lines 254-308
my $rs = $schema->resultset('VendorEdiAccount')->search(
Link Here
|
254 |
{ vendor_id => $booksellerid, } ); |
258 |
{ vendor_id => $booksellerid, } ); |
255 |
$template->param( ediaccount => ($rs->count > 0)); |
259 |
$template->param( ediaccount => ($rs->count > 0)); |
256 |
|
260 |
|
257 |
if ( $op eq "add" ) { |
261 |
if ($op eq 'mod_basket') { |
258 |
# |
|
|
259 |
# if no param('basketgroupid') is not defined, adds a new basketgroup |
260 |
# else, edit (if it is open) or display (if it is close) the basketgroup basketgroupid |
261 |
# the template will know if basketgroup must be displayed or edited, depending on the value of closed key |
262 |
# |
263 |
my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); |
264 |
my $basketgroupid = $input->param('basketgroupid'); |
265 |
my $billingplace; |
266 |
my $deliveryplace; |
267 |
my $freedeliveryplace; |
268 |
if ( $basketgroupid ) { |
269 |
# Get the selected baskets in the basketgroup to display them |
270 |
my $selecteds = GetBasketsByBasketgroup($basketgroupid); |
271 |
foreach my $basket(@{$selecteds}){ |
272 |
$basket->{total} = BasketTotal($basket->{basketno}, $bookseller); |
273 |
} |
274 |
$template->param(basketgroupid => $basketgroupid, |
275 |
selectedbaskets => $selecteds); |
276 |
|
277 |
# Get general informations about the basket group to prefill the form |
278 |
my $basketgroup = GetBasketgroup($basketgroupid); |
279 |
$template->param( |
280 |
name => $basketgroup->{name}, |
281 |
deliverycomment => $basketgroup->{deliverycomment}, |
282 |
freedeliveryplace => $basketgroup->{freedeliveryplace}, |
283 |
); |
284 |
$billingplace = $basketgroup->{billingplace}; |
285 |
$deliveryplace = $basketgroup->{deliveryplace}; |
286 |
$freedeliveryplace = $basketgroup->{freedeliveryplace}; |
287 |
$template->param( closedbg => ($basketgroup ->{'closed'}) ? 1 : 0); |
288 |
} else { |
289 |
$template->param( closedbg => 0); |
290 |
} |
291 |
# determine default billing and delivery places depending on librarian homebranch and existing basketgroup data |
292 |
my $patron = Koha::Patrons->find( $loggedinuser ); # FIXME Not needed if billingplace and deliveryplace are set |
293 |
$billingplace = $billingplace || $patron->branchcode; |
294 |
$deliveryplace = $deliveryplace || $patron->branchcode; |
295 |
|
296 |
$template->param( billingplace => $billingplace ); |
297 |
$template->param( deliveryplace => $deliveryplace ); |
298 |
$template->param( booksellerid => $booksellerid ); |
299 |
|
300 |
# the template will display a unique basketgroup |
301 |
$template->param(grouping => 1); |
302 |
my $basketgroups = &GetBasketgroups($booksellerid); |
303 |
my $baskets = &GetBasketsByBookseller($booksellerid); |
304 |
displaybasketgroups($basketgroups, $bookseller, $baskets); |
305 |
} elsif ($op eq 'mod_basket') { |
306 |
# |
262 |
# |
307 |
# edit an individual basket contained in this basketgroup |
263 |
# edit an individual basket contained in this basketgroup |
308 |
# |
264 |
# |
Lines 343-349
if ( $op eq "add" ) {
Link Here
|
343 |
# |
299 |
# |
344 |
my $basketgroupid = $input->param('basketgroupid'); |
300 |
my $basketgroupid = $input->param('basketgroupid'); |
345 |
DelBasketgroup($basketgroupid); |
301 |
DelBasketgroup($basketgroupid); |
346 |
print $input->redirect('/cgi-bin/koha/acqui/basketgroup.pl?booksellerid=' . $booksellerid.'&listclosed=1'); |
302 |
print $input->redirect('/cgi-bin/koha/acqui/basketgroups.pl?booksellerid=' . $booksellerid); |
|
|
303 |
exit; |
347 |
}elsif ( $op eq 'reopen'){ |
304 |
}elsif ( $op eq 'reopen'){ |
348 |
# |
305 |
# |
349 |
# reopen a closed basketgroup |
306 |
# reopen a closed basketgroup |
Lines 351-358
if ( $op eq "add" ) {
Link Here
|
351 |
my $basketgroupid = $input->param('basketgroupid'); |
308 |
my $basketgroupid = $input->param('basketgroupid'); |
352 |
my $booksellerid = $input->param('booksellerid'); |
309 |
my $booksellerid = $input->param('booksellerid'); |
353 |
ReOpenBasketgroup($basketgroupid); |
310 |
ReOpenBasketgroup($basketgroupid); |
354 |
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'; |
311 |
my $redirectpath; |
|
|
312 |
my $mode = $input->param('mode'); |
313 |
if (defined $mode && $mode eq 'singlebg') { |
314 |
$redirectpath = '/cgi-bin/koha/acqui/basketgroup.pl?op=add&basketgroupid='.$basketgroupid.'&booksellerid='.$booksellerid; |
315 |
} else { |
316 |
$redirectpath = '/cgi-bin/koha/acqui/basketgroups.pl?booksellerid=' .$booksellerid; |
317 |
} |
355 |
print $input->redirect($redirectpath); |
318 |
print $input->redirect($redirectpath); |
|
|
319 |
exit; |
356 |
} elsif ( $op eq 'attachbasket') { |
320 |
} elsif ( $op eq 'attachbasket') { |
357 |
# |
321 |
# |
358 |
# save a modified basketgroup, or creates a new basketgroup when a basket is closed. called from basket page |
322 |
# save a modified basketgroup, or creates a new basketgroup when a basket is closed. called from basket page |
Lines 398-407
if ( $op eq "add" ) {
Link Here
|
398 |
}; |
362 |
}; |
399 |
$basketgroupid = NewBasketgroup($basketgroup); |
363 |
$basketgroupid = NewBasketgroup($basketgroup); |
400 |
} |
364 |
} |
401 |
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; |
365 |
my $redirectpath; |
402 |
$redirectpath .= "&listclosed=1" if $closedbg ; |
366 |
my $mode = $input->param('mode'); |
403 |
print $input->redirect($redirectpath ); |
367 |
if (defined $mode && $mode eq 'singlebg') { |
404 |
|
368 |
$redirectpath = '/cgi-bin/koha/acqui/basketgroup.pl?op=add&basketgroupid='.$basketgroupid.'&booksellerid='.$booksellerid; |
|
|
369 |
} else { |
370 |
$redirectpath = '/cgi-bin/koha/acqui/basketgroups.pl?booksellerid=' . $booksellerid; |
371 |
} |
372 |
print $input->redirect($redirectpath); |
373 |
exit; |
405 |
} elsif ( $op eq 'ediprint') { |
374 |
} elsif ( $op eq 'ediprint') { |
406 |
my $basketgroupid = $input->param('basketgroupid'); |
375 |
my $basketgroupid = $input->param('basketgroupid'); |
407 |
if ($template->param( 'ediaccount' )) { |
376 |
if ($template->param( 'ediaccount' )) { |
Lines 415-428
if ( $op eq "add" ) {
Link Here
|
415 |
|
384 |
|
416 |
displaybasketgroups($basketgroups, $bookseller, $baskets); |
385 |
displaybasketgroups($basketgroups, $bookseller, $baskets); |
417 |
} |
386 |
} |
418 |
}else{ |
387 |
} |
419 |
# no param : display the list of all basketgroups for a given vendor |
|
|
420 |
my $basketgroups = &GetBasketgroups($booksellerid); |
421 |
my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); |
422 |
my $baskets = &GetBasketsByBookseller($booksellerid); |
423 |
|
388 |
|
424 |
displaybasketgroups($basketgroups, $bookseller, $baskets); |
389 |
# if no param('basketgroupid') is not defined, adds a new basketgroup else, edit |
|
|
390 |
# (if it is open) or display (if it is close) the basketgroup basketgroupid the |
391 |
# template will know if basketgroup must be displayed or edited, depending on |
392 |
# the value of closed key |
393 |
|
394 |
my $bookseller = Koha::Acquisition::Booksellers->find($booksellerid); |
395 |
my $basketgroupid = $input->param('basketgroupid'); |
396 |
my $billingplace; |
397 |
my $deliveryplace; |
398 |
my $freedeliveryplace; |
399 |
if ( $basketgroupid ) { |
400 |
# Get the selected baskets in the basketgroup to display them |
401 |
my $selecteds = GetBasketsByBasketgroup($basketgroupid); |
402 |
foreach my $basket(@{$selecteds}){ |
403 |
$basket->{total} = BasketTotal($basket->{basketno}, $bookseller); |
404 |
} |
405 |
$template->param(basketgroupid => $basketgroupid, |
406 |
selectedbaskets => $selecteds); |
407 |
|
408 |
# Get general informations about the basket group to prefill the form |
409 |
my $basketgroup = GetBasketgroup($basketgroupid); |
410 |
$template->param( |
411 |
name => $basketgroup->{name}, |
412 |
billingplace => $basketgroup->{billingplace}, |
413 |
deliveryplace => $basketgroup->{deliveryplace}, |
414 |
deliverycomment => $basketgroup->{deliverycomment}, |
415 |
freedeliveryplace => $basketgroup->{freedeliveryplace}, |
416 |
closedbg => $basketgroup->{closed} ? 1 : 0 |
417 |
); |
418 |
} else { |
419 |
$template->param( closedbg => 0); |
425 |
} |
420 |
} |
426 |
$template->param(listclosed => ((defined $input->param('listclosed')) && ($input->param('listclosed') eq '1'))? 1:0 ); |
421 |
# determine default billing and delivery places depending on librarian homebranch and existing basketgroup data |
427 |
#prolly won't use all these, maybe just use print, the rest can be done inside validate |
422 |
my $borrower = Koha::Patrons->find( $loggedinuser ); |
|
|
423 |
$billingplace = $billingplace || $borrower->branchcode; |
424 |
$deliveryplace = $deliveryplace || $borrower->branchcode; |
425 |
|
426 |
$template->param( booksellerid => $booksellerid ); |
427 |
|
428 |
# the template will display a unique basketgroup |
429 |
my $basketgroups = &GetBasketgroups($booksellerid); |
430 |
my $baskets = &GetBasketsByBookseller($booksellerid); |
431 |
displaybasketgroups($basketgroups, $bookseller, $baskets, $template); |
432 |
|
428 |
output_html_with_http_headers $input, $cookie, $template->output; |
433 |
output_html_with_http_headers $input, $cookie, $template->output; |