|
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 592-597
sub quote_item {
Link Here
|
| 592 |
order_internalnote => $order_note, |
642 |
order_internalnote => $order_note, |
| 593 |
rrp => $item->price, |
643 |
rrp => $item->price, |
| 594 |
ecost => _discounted_price( $quote->vendor->discount, $item->price ), |
644 |
ecost => _discounted_price( $quote->vendor->discount, $item->price ), |
|
|
645 |
discount => $quote->vendor->discount, |
| 595 |
uncertainprice => 0, |
646 |
uncertainprice => 0, |
| 596 |
sort1 => q{}, |
647 |
sort1 => q{}, |
| 597 |
sort2 => q{}, |
648 |
sort2 => q{}, |
|
Lines 655-660
sub quote_item {
Link Here
|
| 655 |
|
706 |
|
| 656 |
if ( !$skip ) { |
707 |
if ( !$skip ) { |
| 657 |
$order_hash->{budget_id} = $budget->budget_id; |
708 |
$order_hash->{budget_id} = $budget->budget_id; |
|
|
709 |
$order_hash = populate_order_with_prices( |
| 710 |
{ |
| 711 |
order => $order_hash, |
| 712 |
booksellerid => $quote->vendor_id, |
| 713 |
ordering => 1, |
| 714 |
} |
| 715 |
); |
| 658 |
my $first_order = $schema->resultset('Aqorder')->create($order_hash); |
716 |
my $first_order = $schema->resultset('Aqorder')->create($order_hash); |
| 659 |
my $o = $first_order->ordernumber(); |
717 |
my $o = $first_order->ordernumber(); |
| 660 |
$logger->trace("Order created :$o"); |
718 |
$logger->trace("Order created :$o"); |
| 661 |
- |
|
|