|
Lines 27-33
use Business::ISBN;
Link Here
|
| 27 |
use DateTime; |
27 |
use DateTime; |
| 28 |
use C4::Context; |
28 |
use C4::Context; |
| 29 |
use Koha::Database; |
29 |
use Koha::Database; |
| 30 |
use C4::Acquisition qw( NewBasket CloseBasket ModOrder); |
30 |
use C4::Acquisition qw( NewBasket CloseBasket ModOrder populate_order_with_prices ); |
| 31 |
use C4::Suggestions qw( ModSuggestion ); |
31 |
use C4::Suggestions qw( ModSuggestion ); |
| 32 |
use C4::Items qw(AddItem); |
32 |
use C4::Items qw(AddItem); |
| 33 |
use C4::Biblio qw( AddBiblio TransformKohaToMarc GetMarcBiblio ); |
33 |
use C4::Biblio qw( AddBiblio TransformKohaToMarc GetMarcBiblio ); |
|
Lines 307-312
sub process_invoice {
Link Here
|
| 307 |
datereceived => $msg_date, |
307 |
datereceived => $msg_date, |
| 308 |
} |
308 |
} |
| 309 |
); |
309 |
); |
|
|
310 |
my $p_updates = |
| 311 |
update_price_from_invoice( $received_order, |
| 312 |
$invoice_message->vendor_id ); |
| 313 |
if ( keys %{$p_updates} ) { |
| 314 |
$received_order->set_columns($p_updates); |
| 315 |
$received_order->update; |
| 316 |
} |
| 310 |
transfer_items( $schema, $line, $order, |
317 |
transfer_items( $schema, $line, $order, |
| 311 |
$received_order ); |
318 |
$received_order ); |
| 312 |
receipt_items( $schema, $line, |
319 |
receipt_items( $schema, $line, |
|
Lines 318-323
sub process_invoice {
Link Here
|
| 318 |
$order->invoiceid($invoiceid); |
325 |
$order->invoiceid($invoiceid); |
| 319 |
$order->unitprice($price); |
326 |
$order->unitprice($price); |
| 320 |
$order->orderstatus('complete'); |
327 |
$order->orderstatus('complete'); |
|
|
328 |
my $p_updates = update_price_from_invoice( $order, |
| 329 |
$invoice_message->vendor_id ); |
| 330 |
foreach my $col ( keys %{$p_updates} ) { |
| 331 |
$order->set_column( $col, $p_updates->{$col} ); |
| 332 |
} |
| 321 |
$order->update; |
333 |
$order->update; |
| 322 |
receipt_items( $schema, $line, $ordernumber ); |
334 |
receipt_items( $schema, $line, $ordernumber ); |
| 323 |
} |
335 |
} |
|
Lines 351-356
sub _get_invoiced_price {
Link Here
|
| 351 |
return $price; |
363 |
return $price; |
| 352 |
} |
364 |
} |
| 353 |
|
365 |
|
|
|
366 |
sub update_price_from_invoice { |
| 367 |
my $ord = shift; |
| 368 |
my $booksellerid = shift; |
| 369 |
|
| 370 |
# wrapper around populate_order_with_prices as we are using dbic Row objects |
| 371 |
my $ord_hash_ref = { |
| 372 |
discount => $ord->discount, |
| 373 |
tax_rate_on_receiving => $ord->tax_rate_on_receiving, |
| 374 |
tax_value_on_receiving => $ord->tax_value_on_receiving, |
| 375 |
tax_rate => $ord->tax_rate_bak, |
| 376 |
unitprice => $ord->unitprice, |
| 377 |
ecost_tax_included => $ord->ecost_tax_included, |
| 378 |
ecost_tax_excluded => $ord->ecost_tax_excluded, |
| 379 |
unitprice_tax_included => $ord->unitprice_tax_included, |
| 380 |
unitprice_tax_excluded => $ord->unitprice_tax_excluded, |
| 381 |
quantity => $ord->quantity, |
| 382 |
}; |
| 383 |
my %pre_hash = %{$ord_hash_ref}; |
| 384 |
$ord_hash_ref = populate_order_with_prices( |
| 385 |
{ |
| 386 |
order => $ord_hash_ref, |
| 387 |
booksellerid => $booksellerid, |
| 388 |
receiving => 1, |
| 389 |
} |
| 390 |
); |
| 391 |
foreach my $k ( keys %pre_hash ) { |
| 392 |
if ( !defined $ord_hash_ref->{$k} |
| 393 |
|| $ord_hash_ref->{$k} == $pre_hash{$k} ) |
| 394 |
{ |
| 395 |
delete $ord_hash_ref->{$k}; |
| 396 |
} |
| 397 |
} |
| 398 |
delete $ord_hash_ref->{quantity}; |
| 399 |
delete $ord_hash_ref->{discount}; |
| 400 |
|
| 401 |
return $ord_hash_ref; |
| 402 |
} |
| 403 |
|
| 354 |
sub receipt_items { |
404 |
sub receipt_items { |
| 355 |
my ( $schema, $inv_line, $ordernumber ) = @_; |
405 |
my ( $schema, $inv_line, $ordernumber ) = @_; |
| 356 |
my $logger = Log::Log4perl->get_logger(); |
406 |
my $logger = Log::Log4perl->get_logger(); |
|
Lines 579-597
sub quote_item {
Link Here
|
| 579 |
$order_quantity = 1; # attempts to create an orderline for each gir |
629 |
$order_quantity = 1; # attempts to create an orderline for each gir |
| 580 |
} |
630 |
} |
| 581 |
my $vendor = Koha::Acquisition::Booksellers->find( $quote->vendor_id ); |
631 |
my $vendor = Koha::Acquisition::Booksellers->find( $quote->vendor_id ); |
|
|
632 |
my $ecost = _discounted_price( $quote->vendor->discount, |
| 633 |
$item->price_info, $item->price_info_inclusive ); |
| 582 |
|
634 |
|
| 583 |
# database definitions should set some of these defaults but dont |
635 |
# database definitions should set some of these defaults but dont |
| 584 |
my $order_hash = { |
636 |
my $order_hash = { |
| 585 |
biblionumber => $bib->{biblionumber}, |
637 |
biblionumber => $bib->{biblionumber}, |
| 586 |
entrydate => DateTime->now( time_zone => 'local' )->ymd(), |
638 |
entrydate => DateTime->now( time_zone => 'local' )->ymd(), |
| 587 |
basketno => $basketno, |
639 |
basketno => $basketno, |
| 588 |
listprice => $item->price, |
640 |
listprice => $item->price_info, |
| 589 |
quantity => $order_quantity, |
641 |
quantity => $order_quantity, |
| 590 |
quantityreceived => 0, |
642 |
quantityreceived => 0, |
| 591 |
order_vendornote => q{}, |
643 |
order_vendornote => q{}, |
| 592 |
order_internalnote => $order_note, |
644 |
order_internalnote => $order_note, |
| 593 |
rrp => $item->price, |
645 |
rrp => $item->price_info, |
| 594 |
ecost => _discounted_price( $quote->vendor->discount, $item->price ), |
646 |
rrp_tax_included => $item->price_info, |
|
|
647 |
ecost => $ecost, |
| 648 |
ecost_tax_included => $ecost, |
| 649 |
discount => $quote->vendor->discount, |
| 595 |
uncertainprice => 0, |
650 |
uncertainprice => 0, |
| 596 |
sort1 => q{}, |
651 |
sort1 => q{}, |
| 597 |
sort2 => q{}, |
652 |
sort2 => q{}, |
|
Lines 802-809
sub quote_item {
Link Here
|
| 802 |
notforloan => -1, |
857 |
notforloan => -1, |
| 803 |
cn_sort => q{}, |
858 |
cn_sort => q{}, |
| 804 |
cn_source => 'ddc', |
859 |
cn_source => 'ddc', |
| 805 |
price => $item->price, |
860 |
price => $item->price_info, |
| 806 |
replacementprice => $item->price, |
861 |
replacementprice => $item->price_info, |
| 807 |
itype => |
862 |
itype => |
| 808 |
$item->girfield( 'stock_category', $occurrence ), |
863 |
$item->girfield( 'stock_category', $occurrence ), |
| 809 |
location => |
864 |
location => |
|
Lines 847-853
sub get_edifact_ean {
Link Here
|
| 847 |
|
902 |
|
| 848 |
# We should not need to have a routine to do this here |
903 |
# We should not need to have a routine to do this here |
| 849 |
sub _discounted_price { |
904 |
sub _discounted_price { |
| 850 |
my ( $discount, $price ) = @_; |
905 |
my ( $discount, $price, $discounted_price ) = @_; |
|
|
906 |
if (defined $discounted_price) { |
| 907 |
return $discounted_price; |
| 908 |
} |
| 851 |
return $price - ( ( $discount * $price ) / 100 ); |
909 |
return $price - ( ( $discount * $price ) / 100 ); |
| 852 |
} |
910 |
} |
| 853 |
|
911 |
|
|
Lines 997-1003
sub _create_item_from_quote {
Link Here
|
| 997 |
cn_sort => q{}, |
1055 |
cn_sort => q{}, |
| 998 |
}; |
1056 |
}; |
| 999 |
$item_hash->{booksellerid} = $quote->vendor_id; |
1057 |
$item_hash->{booksellerid} = $quote->vendor_id; |
| 1000 |
$item_hash->{price} = $item_hash->{replacementprice} = $item->price; |
1058 |
$item_hash->{price} = $item_hash->{replacementprice} = $item->price_info; |
| 1001 |
$item_hash->{itype} = $item->girfield('stock_category'); |
1059 |
$item_hash->{itype} = $item->girfield('stock_category'); |
| 1002 |
$item_hash->{location} = $item->girfield('collection_code'); |
1060 |
$item_hash->{location} = $item->girfield('collection_code'); |
| 1003 |
|
1061 |
|