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