Lines 56-126
use Koha::EDI qw/create_edi_order get_edifact_ean/;
Link Here
|
56 |
|
56 |
|
57 |
use Koha::Biblioitems; |
57 |
use Koha::Biblioitems; |
58 |
use Koha::Acquisition::Booksellers; |
58 |
use Koha::Acquisition::Booksellers; |
|
|
59 |
use Koha::Acquisition::BasketGroups; |
59 |
use Koha::ItemTypes; |
60 |
use Koha::ItemTypes; |
60 |
use Koha::Patrons; |
61 |
use Koha::Patrons; |
61 |
|
62 |
|
62 |
our $input=new CGI; |
63 |
my $input = new CGI; |
63 |
|
|
|
64 |
our ($template, $loggedinuser, $cookie) |
65 |
= get_template_and_user({template_name => "acqui/basketgroup.tt", |
66 |
query => $input, |
67 |
type => "intranet", |
68 |
authnotrequired => 0, |
69 |
flagsrequired => {acquisition => 'group_manage'}, |
70 |
debug => 1, |
71 |
}); |
72 |
|
73 |
sub BasketTotal { |
74 |
my $basketno = shift; |
75 |
my $bookseller = shift; |
76 |
my $total = 0; |
77 |
my @orders = GetOrders($basketno); |
78 |
for my $order (@orders){ |
79 |
# FIXME The following is wrong |
80 |
if ( $bookseller->listincgst ) { |
81 |
$total = $total + ( get_rounded_price($order->{ecost_tax_included}) * $order->{quantity} ); |
82 |
} else { |
83 |
$total = $total + ( get_rounded_price($order->{ecost_tax_excluded}) * $order->{quantity} ); |
84 |
} |
85 |
} |
86 |
return $total; |
87 |
} |
88 |
|
64 |
|
89 |
#displays all basketgroups and all closed baskets (in their respective groups) |
65 |
our ($template, $loggedinuser, $cookie) = get_template_and_user({ |
90 |
sub displaybasketgroups { |
66 |
template_name => "acqui/basketgroup.tt", |
91 |
my $basketgroups = shift; |
67 |
query => $input, |
92 |
my $bookseller = shift; |
68 |
type => "intranet", |
93 |
my $baskets = shift; |
69 |
authnotrequired => 0, |
94 |
if (scalar @$basketgroups != 0) { |
70 |
flagsrequired => {acquisition => 'group_manage'}, |
95 |
foreach my $basketgroup (@$basketgroups){ |
71 |
debug => 1, |
96 |
my $i = 0; |
72 |
}); |
97 |
my $basketsqty = 0; |
|
|
98 |
while($i < scalar(@$baskets)){ |
99 |
my $basket = @$baskets[$i]; |
100 |
if($basket->{'basketgroupid'} && $basket->{'basketgroupid'} == $basketgroup->{'id'}){ |
101 |
$basket->{total} = BasketTotal($basket->{basketno}, $bookseller); |
102 |
push(@{$basketgroup->{'baskets'}}, $basket); |
103 |
splice(@$baskets, $i, 1); |
104 |
++$basketsqty; |
105 |
--$i; |
106 |
} |
107 |
++$i; |
108 |
} |
109 |
$basketgroup -> {'basketsqty'} = $basketsqty; |
110 |
} |
111 |
$template->param(basketgroups => $basketgroups); |
112 |
} |
113 |
for(my $i=0; $i < scalar @$baskets; ++$i) { |
114 |
if( ! @$baskets[$i]->{'closedate'} ) { |
115 |
splice(@$baskets, $i, 1); |
116 |
--$i; |
117 |
}else{ |
118 |
@$baskets[$i]->{total} = BasketTotal(@$baskets[$i]->{basketno}, $bookseller); |
119 |
} |
120 |
} |
121 |
$template->param(baskets => $baskets); |
122 |
$template->param( booksellername => $bookseller->name); |
123 |
} |
124 |
|
73 |
|
125 |
sub printbasketgrouppdf{ |
74 |
sub printbasketgrouppdf{ |
126 |
my ($basketgroupid) = @_; |
75 |
my ($basketgroupid) = @_; |
Lines 211-217
sub printbasketgrouppdf{
Link Here
|
211 |
); |
160 |
); |
212 |
my $pdf = printpdf($basketgroup, $bookseller, $baskets, \%orders, $bookseller->tax_rate // C4::Context->preference("gist")) || die "pdf generation failed"; |
161 |
my $pdf = printpdf($basketgroup, $bookseller, $baskets, \%orders, $bookseller->tax_rate // C4::Context->preference("gist")) || die "pdf generation failed"; |
213 |
print $pdf; |
162 |
print $pdf; |
214 |
|
|
|
215 |
} |
163 |
} |
216 |
|
164 |
|
217 |
sub generate_edifact_orders { |
165 |
sub generate_edifact_orders { |
Lines 232-335
sub generate_edifact_orders {
Link Here
|
232 |
return; |
180 |
return; |
233 |
} |
181 |
} |
234 |
|
182 |
|
235 |
my $op = $input->param('op') || 'display'; |
|
|
236 |
# possible values of $op : |
183 |
# possible values of $op : |
237 |
# - add : adds a new basketgroup, or edit an open basketgroup, or display a closed basketgroup |
|
|
238 |
# - mod_basket : modify an individual basket of the basketgroup |
184 |
# - mod_basket : modify an individual basket of the basketgroup |
239 |
# - closeandprint : close and print an closed basketgroup in pdf. called by clicking on "Close and print" button in closed basketgroups list |
185 |
# - closeandprint : close and print an closed basketgroup in pdf. called by |
240 |
# - print : print a closed basketgroup. called by clicking on "Print" button in closed basketgroups list |
186 |
# clicking on "Close and print" button in closed basketgroups list |
|
|
187 |
# - print : print a closed basketgroup. called by clicking on "Print" button in |
188 |
# closed basketgroups list |
241 |
# - ediprint : generate edi order messages for the baskets in the group |
189 |
# - ediprint : generate edi order messages for the baskets in the group |
242 |
# - export : export in CSV a closed basketgroup. called by clicking on "Export" button in closed basketgroups list |
190 |
# - export : export in CSV a closed basketgroup. called by clicking on "Export" |
243 |
# - delete : delete an open basketgroup. called by clicking on "Delete" button in open basketgroups list |
191 |
# button in closed basketgroups list |
244 |
# - reopen : reopen a closed basketgroup. called by clicking on "Reopen" button in closed basketgroup list |
192 |
# - delete : delete an open basketgroup. called by clicking on "Delete" button |
245 |
# - attachbasket : save a modified basketgroup, or creates a new basketgroup when a basket is closed. called from basket page |
193 |
# in open basketgroups list |
246 |
# - display : display the list of all basketgroups for a vendor |
194 |
# - reopen : reopen a closed basketgroup. called by clicking on "Reopen" button |
|
|
195 |
# in closed basketgroup list |
196 |
# - attachbasket : save a modified basketgroup, or creates a new basketgroup |
197 |
# when a basket is closed. called from basket page |
198 |
my $op = $input->param('op'); |
199 |
my $basketgroupid = $input->param('basketgroupid'); |
247 |
my $booksellerid = $input->param('booksellerid'); |
200 |
my $booksellerid = $input->param('booksellerid'); |
248 |
$template->param(booksellerid => $booksellerid); |
201 |
|
249 |
my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); |
202 |
my $basketgroup; |
|
|
203 |
my $bookseller; |
204 |
if ($basketgroupid) { |
205 |
$basketgroup = Koha::Acquisition::BasketGroups->find($basketgroupid); |
206 |
$bookseller = $basketgroup->vendor; |
207 |
} elsif ($booksellerid) { |
208 |
$bookseller = Koha::Acquisition::Booksellers->find($booksellerid); |
209 |
} |
250 |
|
210 |
|
251 |
my $schema = Koha::Database->new()->schema(); |
211 |
my $schema = Koha::Database->new()->schema(); |
252 |
my $rs = $schema->resultset('VendorEdiAccount')->search( |
212 |
my $rs = $schema->resultset('VendorEdiAccount')->search( |
253 |
{ vendor_id => $booksellerid, } ); |
213 |
{ vendor_id => $booksellerid, } ); |
254 |
$template->param( ediaccount => ($rs->count > 0)); |
214 |
$template->param( ediaccount => ($rs->count > 0)); |
255 |
|
215 |
|
256 |
if ( $op eq "add" ) { |
216 |
if ($op eq 'mod_basket') { |
257 |
# |
217 |
# edit an individual basket contained in this basketgroup |
258 |
# if no param('basketgroupid') is not defined, adds a new basketgroup |
218 |
|
259 |
# else, edit (if it is open) or display (if it is close) the basketgroup basketgroupid |
219 |
my $basketno=$input->param('basketno'); |
260 |
# the template will know if basketgroup must be displayed or edited, depending on the value of closed key |
220 |
ModBasket( { basketno => $basketno, |
261 |
# |
221 |
basketgroupid => $basketgroupid } ); |
262 |
my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); |
222 |
print $input->redirect("basket.pl?basketno=" . $basketno); |
263 |
my $basketgroupid = $input->param('basketgroupid'); |
|
|
264 |
my $billingplace; |
265 |
my $deliveryplace; |
266 |
my $freedeliveryplace; |
267 |
if ( $basketgroupid ) { |
268 |
# Get the selected baskets in the basketgroup to display them |
269 |
my $selecteds = GetBasketsByBasketgroup($basketgroupid); |
270 |
foreach my $basket(@{$selecteds}){ |
271 |
$basket->{total} = BasketTotal($basket->{basketno}, $bookseller); |
272 |
} |
273 |
$template->param(basketgroupid => $basketgroupid, |
274 |
selectedbaskets => $selecteds); |
275 |
|
276 |
# Get general informations about the basket group to prefill the form |
277 |
my $basketgroup = GetBasketgroup($basketgroupid); |
278 |
$template->param( |
279 |
name => $basketgroup->{name}, |
280 |
deliverycomment => $basketgroup->{deliverycomment}, |
281 |
freedeliveryplace => $basketgroup->{freedeliveryplace}, |
282 |
); |
283 |
$billingplace = $basketgroup->{billingplace}; |
284 |
$deliveryplace = $basketgroup->{deliveryplace}; |
285 |
$freedeliveryplace = $basketgroup->{freedeliveryplace}; |
286 |
$template->param( closedbg => ($basketgroup ->{'closed'}) ? 1 : 0); |
287 |
} else { |
288 |
$template->param( closedbg => 0); |
289 |
} |
290 |
# determine default billing and delivery places depending on librarian homebranch and existing basketgroup data |
291 |
my $patron = Koha::Patrons->find( $loggedinuser ); # FIXME Not needed if billingplace and deliveryplace are set |
292 |
$billingplace = $billingplace || $patron->branchcode; |
293 |
$deliveryplace = $deliveryplace || $patron->branchcode; |
294 |
|
295 |
$template->param( billingplace => $billingplace ); |
296 |
$template->param( deliveryplace => $deliveryplace ); |
297 |
$template->param( booksellerid => $booksellerid ); |
298 |
|
299 |
# the template will display a unique basketgroup |
300 |
$template->param(grouping => 1); |
301 |
my $basketgroups = &GetBasketgroups($booksellerid); |
302 |
my $baskets = &GetBasketsByBookseller($booksellerid); |
303 |
displaybasketgroups($basketgroups, $bookseller, $baskets); |
304 |
} elsif ($op eq 'mod_basket') { |
305 |
# |
306 |
# edit an individual basket contained in this basketgroup |
307 |
# |
308 |
my $basketno=$input->param('basketno'); |
309 |
my $basketgroupid=$input->param('basketgroupid'); |
310 |
ModBasket( { basketno => $basketno, |
311 |
basketgroupid => $basketgroupid } ); |
312 |
print $input->redirect("basket.pl?basketno=" . $basketno); |
313 |
} elsif ( $op eq 'closeandprint') { |
223 |
} elsif ( $op eq 'closeandprint') { |
314 |
# |
224 |
# close an open basketgroup and generates a pdf |
315 |
# close an open basketgroup and generates a pdf |
225 |
|
316 |
# |
|
|
317 |
my $basketgroupid = $input->param('basketgroupid'); |
318 |
CloseBasketgroup($basketgroupid); |
226 |
CloseBasketgroup($basketgroupid); |
319 |
printbasketgrouppdf($basketgroupid); |
227 |
printbasketgrouppdf($basketgroupid); |
320 |
exit; |
228 |
exit; |
321 |
}elsif ($op eq 'print'){ |
229 |
}elsif ($op eq 'print'){ |
322 |
# |
230 |
# print a closed basketgroup |
323 |
# print a closed basketgroup |
231 |
|
324 |
# |
|
|
325 |
my $basketgroupid = $input->param('basketgroupid'); |
326 |
printbasketgrouppdf($basketgroupid); |
232 |
printbasketgrouppdf($basketgroupid); |
327 |
exit; |
233 |
exit; |
328 |
}elsif ( $op eq "export" ) { |
234 |
}elsif ( $op eq "export" ) { |
329 |
# |
235 |
# export a closed basketgroup in csv |
330 |
# export a closed basketgroup in csv |
236 |
|
331 |
# |
|
|
332 |
my $basketgroupid = $input->param('basketgroupid'); |
333 |
print $input->header( |
237 |
print $input->header( |
334 |
-type => 'text/csv', |
238 |
-type => 'text/csv', |
335 |
-attachment => 'basketgroup' . $basketgroupid . '.csv', |
239 |
-attachment => 'basketgroup' . $basketgroupid . '.csv', |
Lines 337-365
if ( $op eq "add" ) {
Link Here
|
337 |
print GetBasketGroupAsCSV( $basketgroupid, $input ); |
241 |
print GetBasketGroupAsCSV( $basketgroupid, $input ); |
338 |
exit; |
242 |
exit; |
339 |
}elsif( $op eq "delete"){ |
243 |
}elsif( $op eq "delete"){ |
340 |
# |
244 |
# delete an closed basketgroup |
341 |
# delete an closed basketgroup |
245 |
|
342 |
# |
|
|
343 |
my $basketgroupid = $input->param('basketgroupid'); |
344 |
DelBasketgroup($basketgroupid); |
246 |
DelBasketgroup($basketgroupid); |
345 |
print $input->redirect('/cgi-bin/koha/acqui/basketgroup.pl?booksellerid=' . $booksellerid.'&listclosed=1'); |
247 |
print $input->redirect('/cgi-bin/koha/acqui/basketgroups.pl?booksellerid=' . $bookseller->id); |
|
|
248 |
exit; |
346 |
}elsif ( $op eq 'reopen'){ |
249 |
}elsif ( $op eq 'reopen'){ |
347 |
# |
250 |
# reopen a closed basketgroup |
348 |
# reopen a closed basketgroup |
251 |
|
349 |
# |
|
|
350 |
my $basketgroupid = $input->param('basketgroupid'); |
351 |
my $booksellerid = $input->param('booksellerid'); |
352 |
ReOpenBasketgroup($basketgroupid); |
252 |
ReOpenBasketgroup($basketgroupid); |
353 |
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'; |
253 |
my $redirectpath; |
|
|
254 |
my $mode = $input->param('mode'); |
255 |
if (defined $mode && $mode eq 'singlebg') { |
256 |
$redirectpath = '/cgi-bin/koha/acqui/basketgroup.pl?op=add&basketgroupid='.$basketgroupid.'&booksellerid='.$bookseller->id; |
257 |
} else { |
258 |
$redirectpath = '/cgi-bin/koha/acqui/basketgroups.pl?booksellerid=' .$bookseller->id; |
259 |
} |
354 |
print $input->redirect($redirectpath); |
260 |
print $input->redirect($redirectpath); |
|
|
261 |
exit; |
355 |
} elsif ( $op eq 'attachbasket') { |
262 |
} elsif ( $op eq 'attachbasket') { |
356 |
# |
263 |
# save a modified basketgroup, or creates a new basketgroup when a basket is closed. called from basket page |
357 |
# save a modified basketgroup, or creates a new basketgroup when a basket is closed. called from basket page |
264 |
|
358 |
# |
|
|
359 |
# Getting parameters |
360 |
my $basketgroup = {}; |
265 |
my $basketgroup = {}; |
361 |
my @baskets = $input->multi_param('basket'); |
266 |
my @baskets = $input->multi_param('basket'); |
362 |
my $basketgroupid = $input->param('basketgroupid'); |
|
|
363 |
my $basketgroupname = $input->param('basketgroupname'); |
267 |
my $basketgroupname = $input->param('basketgroupname'); |
364 |
my $booksellerid = $input->param('booksellerid'); |
268 |
my $booksellerid = $input->param('booksellerid'); |
365 |
my $billingplace = $input->param('billingplace'); |
269 |
my $billingplace = $input->param('billingplace'); |
Lines 368-374
if ( $op eq "add" ) {
Link Here
|
368 |
my $deliverycomment = $input->param('deliverycomment'); |
272 |
my $deliverycomment = $input->param('deliverycomment'); |
369 |
my $closedbg = $input->param('closedbg') ? 1 : 0; |
273 |
my $closedbg = $input->param('closedbg') ? 1 : 0; |
370 |
if ($basketgroupid) { |
274 |
if ($basketgroupid) { |
371 |
# If we have a basketgroupid we edit the basketgroup |
275 |
# If we have a basketgroupid we edit the basketgroup |
372 |
$basketgroup = { |
276 |
$basketgroup = { |
373 |
name => $basketgroupname, |
277 |
name => $basketgroupname, |
374 |
id => $basketgroupid, |
278 |
id => $basketgroupid, |
Lines 380-393
if ( $op eq "add" ) {
Link Here
|
380 |
closed => $closedbg, |
284 |
closed => $closedbg, |
381 |
}; |
285 |
}; |
382 |
ModBasketgroup($basketgroup); |
286 |
ModBasketgroup($basketgroup); |
383 |
if($closedbg){ |
287 |
} else { |
384 |
# FIXME |
288 |
# we create a new basketgroup (with a closed basket) |
385 |
} |
|
|
386 |
}else{ |
387 |
# we create a new basketgroup (with a closed basket) |
388 |
$basketgroup = { |
289 |
$basketgroup = { |
389 |
name => $basketgroupname, |
290 |
name => $basketgroupname, |
390 |
booksellerid => $booksellerid, |
291 |
booksellerid => $bookseller->id, |
391 |
basketlist => \@baskets, |
292 |
basketlist => \@baskets, |
392 |
billingplace => $billingplace, |
293 |
billingplace => $billingplace, |
393 |
deliveryplace => $deliveryplace, |
294 |
deliveryplace => $deliveryplace, |
Lines 397-427
if ( $op eq "add" ) {
Link Here
|
397 |
}; |
298 |
}; |
398 |
$basketgroupid = NewBasketgroup($basketgroup); |
299 |
$basketgroupid = NewBasketgroup($basketgroup); |
399 |
} |
300 |
} |
400 |
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; |
301 |
my $redirectpath; |
401 |
$redirectpath .= "&listclosed=1" if $closedbg ; |
302 |
my $mode = $input->param('mode'); |
402 |
print $input->redirect($redirectpath ); |
303 |
if (defined $mode && $mode eq 'singlebg') { |
403 |
|
304 |
$redirectpath = '/cgi-bin/koha/acqui/basketgroup.pl?op=add&basketgroupid='.$basketgroupid.'&booksellerid='.$booksellerid; |
|
|
305 |
} else { |
306 |
$redirectpath = '/cgi-bin/koha/acqui/basketgroups.pl?booksellerid=' . $booksellerid; |
307 |
} |
308 |
print $input->redirect($redirectpath); |
309 |
exit; |
404 |
} elsif ( $op eq 'ediprint') { |
310 |
} elsif ( $op eq 'ediprint') { |
405 |
my $basketgroupid = $input->param('basketgroupid'); |
|
|
406 |
if ($template->param( 'ediaccount' )) { |
311 |
if ($template->param( 'ediaccount' )) { |
407 |
generate_edifact_orders( $basketgroupid ); |
312 |
generate_edifact_orders( $basketgroupid ); |
408 |
exit; |
313 |
exit; |
409 |
} else { |
314 |
} else { |
410 |
$template->param('NoEDIMessage' => 1); |
315 |
$template->param('NoEDIMessage' => 1); |
411 |
my $basketgroups = &GetBasketgroups($booksellerid); |
|
|
412 |
my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); |
413 |
my $baskets = &GetBasketsByBookseller($booksellerid); |
414 |
|
415 |
displaybasketgroups($basketgroups, $bookseller, $baskets); |
416 |
} |
316 |
} |
417 |
}else{ |
|
|
418 |
# no param : display the list of all basketgroups for a given vendor |
419 |
my $basketgroups = &GetBasketgroups($booksellerid); |
420 |
my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); |
421 |
my $baskets = &GetBasketsByBookseller($booksellerid); |
422 |
|
423 |
displaybasketgroups($basketgroups, $bookseller, $baskets); |
424 |
} |
317 |
} |
425 |
$template->param(listclosed => ((defined $input->param('listclosed')) && ($input->param('listclosed') eq '1'))? 1:0 ); |
318 |
|
426 |
#prolly won't use all these, maybe just use print, the rest can be done inside validate |
319 |
my $borrower = Koha::Patrons->find( $loggedinuser ); |
|
|
320 |
$template->param( |
321 |
bookseller => $bookseller, |
322 |
basketgroup => $basketgroup, |
323 |
billingplace => $basketgroup ? $basketgroup->billingplace : $borrower->branchcode, |
324 |
deliveryplace => $basketgroup ? $basketgroup->deliveryplace : $borrower->branchcode, |
325 |
baskets => [ Koha::Acquisition::Baskets->search({booksellerid => $bookseller->id, basketgroupid => undef}) ], |
326 |
); |
327 |
|
427 |
output_html_with_http_headers $input, $cookie, $template->output; |
328 |
output_html_with_http_headers $input, $cookie, $template->output; |