Lines 293-298
sub printbasketgrouppdf{
Link Here
|
293 |
|
293 |
|
294 |
} |
294 |
} |
295 |
|
295 |
|
|
|
296 |
sub order_mail { |
297 |
#use Data::Dumper; |
298 |
my ($booksellerid, $mail_orders) = @_; |
299 |
#print "order_mail\n"; |
300 |
#print "booksellerid: $booksellerid\n", "mail_orders: ", Dumper($mail_orders); |
301 |
my $mail_order_total = shift @$mail_orders; |
302 |
|
303 |
my $bookseller = GetBookSellerFromId($booksellerid); |
304 |
|
305 |
my $letter = C4::Letters::getletter('orders', 'ORDERMAIL') || return; |
306 |
#print "letter: ", Dumper(\$letter); |
307 |
|
308 |
eval "use Mail::Sendmail"; |
309 |
eval "use C4::Log"; |
310 |
eval "use Carp"; |
311 |
eval "use Encode"; |
312 |
|
313 |
# branch info |
314 |
my $userenv = C4::Context->userenv; |
315 |
C4::Letters::parseletter($letter, 'branches', $userenv->{branch}); |
316 |
|
317 |
# librarian name |
318 |
$letter->{content} =~ s/<<LibrarianFirstname>>/$userenv->{firstname}/g; |
319 |
$letter->{content} =~ s/<<LibrarianSurname>>/$userenv->{surname}/g; |
320 |
$letter->{content} =~ s/<<LibrarianEmailaddress>>/$userenv->{emailaddress}/g; |
321 |
|
322 |
# booksellers |
323 |
C4::Letters::parseletter($letter, 'aqbooksellers', $booksellerid); |
324 |
|
325 |
# items and total |
326 |
return unless $letter->{'content'} =~ m/(<item>(.*)<\/item>)/sm; |
327 |
my $item_place = $1; my $item_format = $2; |
328 |
my ($total_place, $total_format); |
329 |
if ($letter->{'content'} =~ m/(<total>(.*)<\/total>)/sm) { |
330 |
$total_place = $1; $total_format = $2; |
331 |
} |
332 |
|
333 |
my @items; |
334 |
foreach my $mail_order (@$mail_orders) { |
335 |
my $item = $item_format; |
336 |
while (my ($key, $value) = each %$mail_order) { |
337 |
#print "$key: $value\n"; |
338 |
$item =~ s/<<orders.$key>>/$value/g; |
339 |
} |
340 |
push @items, $item; |
341 |
} |
342 |
#print "items: ", Dumper(@items); |
343 |
$letter->{'content'} =~ s/\Q$item_place\E/join "\n",@items/e; |
344 |
if ($total_format) { |
345 |
#print "total_place: $total_place\n"; |
346 |
#print "total_format: $total_format\n"; |
347 |
my $total = $total_format; |
348 |
while (my ($key, $value) = each %$mail_order_total) { |
349 |
$total =~ s/<<orders.total.$key>>/$value/g; |
350 |
} |
351 |
#print "total: $total\n"; |
352 |
$letter->{'content'} =~ s/\Q$total_place\E/$total/; |
353 |
} |
354 |
my %mail = ( |
355 |
To => $bookseller->{bookselleremail} || |
356 |
$bookseller->{contemail} || |
357 |
$userenv->{emailaddress}, |
358 |
From => $userenv->{emailaddress}, |
359 |
Subject => $letter->{title}, |
360 |
Message => Encode::encode("UTF-8", $letter->{content}), |
361 |
'Content-Type' => 'text/plain; charset="utf8"', |
362 |
); |
363 |
#print "mail: ", Dumper(\%mail); |
364 |
sendmail(%mail) or carp $Mail::Sendmail::error; |
365 |
logaction( |
366 |
"ORDER", |
367 |
"Send email order", |
368 |
undef, |
369 |
"To=%mail{To}\nSubject=%mail{Subject}\nMessage=%mail{Message}" |
370 |
) if C4::Context->preference("LetterLog"); |
371 |
} |
372 |
|
373 |
sub mailbasketgroup { |
374 |
my ($basketgroupid) = @_; |
375 |
|
376 |
eval "use C4::Branch"; |
377 |
eval "use C4::Biblio"; |
378 |
eval "use C4::Koha"; |
379 |
eval "use Number::Format qw(format_number format_price)"; |
380 |
|
381 |
my $num = FormatNumber; # C4::Output |
382 |
|
383 |
my $itemtypes = GetItemTypes(); |
384 |
|
385 |
my $basketgroup = GetBasketgroup($basketgroupid); |
386 |
my $booksellerid = $basketgroup->{booksellerid}; |
387 |
my $bookseller = GetBookSellerFromId($booksellerid); |
388 |
my $baskets = GetBasketsByBasketgroup($basketgroupid); |
389 |
|
390 |
my $gstrate = $bookseller->{gstrate} || C4::Context->preference("gist") || 0; |
391 |
my $discount = $bookseller->{'discount'} / 100; |
392 |
|
393 |
my $total_ecost; # Total, its value will be assigned to $total_ecost_gsti or $total_ecost_gste depending of $bookseller->{'listincgst'} |
394 |
my $total_ecost_gsti; # Total, GST included |
395 |
my $total_ecost_gste; # Total, GST excluded |
396 |
my $total_quantity; # Total quantity |
397 |
|
398 |
my @mail_orders; |
399 |
for my $basket (@$baskets) { |
400 |
my $basketno = $basket->{basketno}; |
401 |
my @orders = &GetOrders($basketno); |
402 |
for my $order (@orders) { |
403 |
my %mail_order; |
404 |
|
405 |
my $quantity = $order->{quantity} || 0; |
406 |
next if $quantity <= 0; |
407 |
my $ecost = $order->{ecost} || 0; |
408 |
|
409 |
for (qw(quantity quantityreceived author title volume seriestitle isbn publishercode)) { |
410 |
$mail_order{$_} = $order->{$_} if defined $order->{$_}; |
411 |
} |
412 |
for (qw(listprice ecost)) { |
413 |
$mail_order{$_} = $num->format_price($order->{$_}) if defined $order->{$_}; |
414 |
} |
415 |
my $full_title = $order->{title}; |
416 |
$full_title .= (" " . $order->{seriestitle}) if $order->{seriestitle}; |
417 |
$full_title .= (" " . $order->{volume}) if $order->{volume}; |
418 |
$mail_order{full_title} = $full_title; |
419 |
if ($order->{biblionumber}) { |
420 |
my $bibliodata = GetBiblioData($order->{biblionumber}); |
421 |
if ($bibliodata->{itemtype}) { |
422 |
$mail_order{itemtype} = $itemtypes->{$bibliodata->{itemtype}}->{description}; |
423 |
} |
424 |
} |
425 |
|
426 |
my $quantity_ecost = $quantity * $ecost; |
427 |
$mail_order{quantity_ecost} = $num->format_price($quantity_ecost); |
428 |
$mail_order{basketno} = $basketno; |
429 |
$total_ecost += $quantity_ecost; |
430 |
$total_quantity += $quantity; |
431 |
push @mail_orders, \%mail_order; |
432 |
} |
433 |
} |
434 |
|
435 |
my %total; |
436 |
$total{quantity} = $total_quantity; |
437 |
$total{gstrate} = $num->format_number($gstrate); |
438 |
$total{currency} = $bookseller->{listprice}; |
439 |
$total{discount} = $num->format_number($bookseller->{discount}); |
440 |
|
441 |
my $total_gist; |
442 |
|
443 |
if ($bookseller->{listincgst}) { # prices already includes GST |
444 |
$total_ecost_gsti = $total_ecost; |
445 |
$total_ecost_gste = $total_ecost_gsti / ($gstrate + 1); |
446 |
$total_gist = $total_ecost_gsti - $total_ecost_gste; |
447 |
} else { # prices does not include GST |
448 |
$total_ecost_gste = $total_ecost; |
449 |
$total_gist = $total_ecost_gste * $gstrate; |
450 |
$total_ecost_gsti = $total_ecost_gste + $total_gist; |
451 |
} |
452 |
$total{ecost_gste} = $num->format_price($total_ecost_gste); |
453 |
$total{ecost_gsti} = $num->format_price($total_ecost_gsti); |
454 |
$total{gist} = $num->format_number($total_gist); |
455 |
|
456 |
unshift @mail_orders, \%total; |
457 |
|
458 |
order_mail($booksellerid, \@mail_orders); |
459 |
} |
460 |
|
296 |
my $op = $input->param('op') || 'display'; |
461 |
my $op = $input->param('op') || 'display'; |
297 |
my $booksellerid = $input->param('booksellerid'); |
462 |
my $booksellerid = $input->param('booksellerid'); |
298 |
$template->param(booksellerid => $booksellerid); |
463 |
$template->param(booksellerid => $booksellerid); |
Lines 409-414
if ( $op eq "add" ) {
Link Here
|
409 |
|
574 |
|
410 |
printbasketgrouppdf($basketgroupid); |
575 |
printbasketgrouppdf($basketgroupid); |
411 |
exit; |
576 |
exit; |
|
|
577 |
} elsif ( $op eq 'closeandmail') { |
578 |
my $basketgroupid = $input->param('basketgroupid'); |
579 |
|
580 |
CloseBasketgroup($basketgroupid); |
581 |
|
582 |
mailbasketgroup($basketgroupid); |
583 |
|
584 |
print $input->redirect('/cgi-bin/koha/acqui/basketgroup.pl?booksellerid=' . $booksellerid); |
412 |
}elsif ($op eq 'print'){ |
585 |
}elsif ($op eq 'print'){ |
413 |
my $basketgroupid = $input->param('basketgroupid'); |
586 |
my $basketgroupid = $input->param('basketgroupid'); |
414 |
|
587 |
|
Lines 422-440
if ( $op eq "add" ) {
Link Here
|
422 |
); |
595 |
); |
423 |
print GetBasketGroupAsCSV( $basketgroupid, $input ); |
596 |
print GetBasketGroupAsCSV( $basketgroupid, $input ); |
424 |
exit; |
597 |
exit; |
|
|
598 |
}elsif ($op eq 'mail'){ |
599 |
my $basketgroupid = $input->param('basketgroupid'); |
600 |
mailbasketgroup($basketgroupid); |
601 |
print $input->redirect('/cgi-bin/koha/acqui/basketgroup.pl?booksellerid=' . $booksellerid); |
425 |
}elsif( $op eq "delete"){ |
602 |
}elsif( $op eq "delete"){ |
426 |
my $basketgroupid = $input->param('basketgroupid'); |
603 |
my $basketgroupid = $input->param('basketgroupid'); |
427 |
DelBasketgroup($basketgroupid); |
604 |
DelBasketgroup($basketgroupid); |
428 |
print $input->redirect('/cgi-bin/koha/acqui/basketgroup.pl?booksellerid=' . $booksellerid); |
605 |
print $input->redirect('/cgi-bin/koha/acqui/basketgroup.pl?booksellerid=' . $booksellerid); |
429 |
|
|
|
430 |
}elsif ( $op eq 'reopen'){ |
606 |
}elsif ( $op eq 'reopen'){ |
431 |
my $basketgroupid = $input->param('basketgroupid'); |
607 |
my $basketgroupid = $input->param('basketgroupid'); |
432 |
my $booksellerid = $input->param('booksellerid'); |
608 |
my $booksellerid = $input->param('booksellerid'); |
433 |
|
|
|
434 |
ReOpenBasketgroup($basketgroupid); |
609 |
ReOpenBasketgroup($basketgroupid); |
435 |
|
|
|
436 |
print $input->redirect('/cgi-bin/koha/acqui/basketgroup.pl?booksellerid=' . $booksellerid . '#closed'); |
610 |
print $input->redirect('/cgi-bin/koha/acqui/basketgroup.pl?booksellerid=' . $booksellerid . '#closed'); |
437 |
|
|
|
438 |
} elsif ( $op eq 'attachbasket') { |
611 |
} elsif ( $op eq 'attachbasket') { |
439 |
|
612 |
|
440 |
# Getting parameters |
613 |
# Getting parameters |