Lines 315-354
sub process_invoice {
Link Here
|
315 |
} |
315 |
} |
316 |
); |
316 |
); |
317 |
} |
317 |
} |
|
|
318 |
# If quantity_invoiced is present use it in preference |
319 |
my $quantity = $line->quantity_invoiced; |
320 |
if (!$quantity) { |
321 |
$quantity = $line->quantity; |
322 |
} |
318 |
|
323 |
|
319 |
my $price = _get_invoiced_price($line); |
324 |
my ( $price, $price_excl_tax ) = _get_invoiced_price($line, $quantity); |
|
|
325 |
my $tax_rate = $line->tax_rate; |
326 |
if ($tax_rate && $tax_rate->{rate} != 0) { |
327 |
$tax_rate->{rate} /= 100; |
328 |
} |
320 |
|
329 |
|
321 |
if ( $order->quantity > $line->quantity ) { |
330 |
if ( $order->quantity > $quantity ) { |
322 |
my $ordered = $order->quantity; |
331 |
my $ordered = $order->quantity; |
323 |
|
332 |
|
324 |
# part receipt |
333 |
# part receipt |
325 |
$order->orderstatus('partial'); |
334 |
$order->orderstatus('partial'); |
326 |
$order->quantity( $ordered - $line->quantity ); |
335 |
$order->quantity( $ordered - $quantity ); |
327 |
$order->update; |
336 |
$order->update; |
328 |
my $received_order = $order->copy( |
337 |
my $received_order = $order->copy( |
329 |
{ |
338 |
{ |
330 |
ordernumber => undef, |
339 |
ordernumber => undef, |
331 |
quantity => $line->quantity, |
340 |
quantity => $quantity, |
332 |
quantityreceived => $line->quantity, |
341 |
quantityreceived => $quantity, |
333 |
orderstatus => 'complete', |
342 |
orderstatus => 'complete', |
334 |
unitprice => $price, |
343 |
unitprice => $price, |
335 |
invoiceid => $invoiceid, |
344 |
unitprice_tax_included => $price, |
336 |
datereceived => $msg_date, |
345 |
unitprice_tax_excluded => $price_excl_tax, |
|
|
346 |
invoiceid => $invoiceid, |
347 |
datereceived => $msg_date, |
348 |
tax_rate_on_receiving => $tax_rate->{rate}, |
349 |
tax_value_on_receiving => $quantity * $price_excl_tax * $tax_rate->{rate}, |
337 |
} |
350 |
} |
338 |
); |
351 |
); |
339 |
transfer_items( $schema, $line, $order, |
352 |
transfer_items( $schema, $line, $order, |
340 |
$received_order ); |
353 |
$received_order, $quantity ); |
341 |
receipt_items( $schema, $line, |
354 |
receipt_items( $schema, $line, |
342 |
$received_order->ordernumber ); |
355 |
$received_order->ordernumber, $quantity ); |
343 |
} |
356 |
} |
344 |
else { # simple receipt all copies on order |
357 |
else { # simple receipt all copies on order |
345 |
$order->quantityreceived( $line->quantity ); |
358 |
$order->quantityreceived( $quantity ); |
346 |
$order->datereceived($msg_date); |
359 |
$order->datereceived($msg_date); |
347 |
$order->invoiceid($invoiceid); |
360 |
$order->invoiceid($invoiceid); |
348 |
$order->unitprice($price); |
361 |
$order->unitprice($price); |
|
|
362 |
$order->unitprice_tax_excluded($price_excl_tax); |
363 |
$order->unitprice_tax_included($price); |
364 |
$order->tax_rate_on_receiving($tax_rate->{rate}); |
365 |
$order->tax_value_on_receiving( $quantity * $price_excl_tax * $tax_rate->{rate}); |
349 |
$order->orderstatus('complete'); |
366 |
$order->orderstatus('complete'); |
350 |
$order->update; |
367 |
$order->update; |
351 |
receipt_items( $schema, $line, $ordernumber ); |
368 |
receipt_items( $schema, $line, $ordernumber, $quantity ); |
352 |
} |
369 |
} |
353 |
} |
370 |
} |
354 |
else { |
371 |
else { |
Lines 369-389
sub process_invoice {
Link Here
|
369 |
} |
386 |
} |
370 |
|
387 |
|
371 |
sub _get_invoiced_price { |
388 |
sub _get_invoiced_price { |
372 |
my $line = shift; |
389 |
my $line = shift; |
373 |
my $price = $line->price_net; |
390 |
my $qty = shift; |
374 |
if ( !defined $price ) { # no net price so generate it from lineitem amount |
391 |
my $line_total = $line->amt_total; |
375 |
$price = $line->amt_lineitem; |
392 |
my $excl_tax = $line->amt_lineitem; |
376 |
if ( $price and $line->quantity > 1 ) { |
393 |
|
377 |
$price /= $line->quantity; # div line cost by qty |
394 |
# If no tax some suppliers omit the total owed |
|
|
395 |
# If no total given calculate from cost exclusive of tax |
396 |
# + tax amount (if present, sometimes omitted if 0 ) |
397 |
if ( !defined $line_total ) { |
398 |
my $x = $line->amt_taxoncharge; |
399 |
if ( !defined $x ) { |
400 |
$x = 0; |
378 |
} |
401 |
} |
|
|
402 |
$line_total = $excl_tax + $x; |
403 |
} |
404 |
|
405 |
# invoices give amounts per orderline, Koha requires that we store |
406 |
# them per item |
407 |
if ( $qty != 1 ) { |
408 |
return ( $line_total / $qty, $excl_tax / $qty ); |
379 |
} |
409 |
} |
380 |
return $price; |
410 |
return ( $line_total, $excl_tax ); # return as is for most common case |
381 |
} |
411 |
} |
382 |
|
412 |
|
383 |
sub receipt_items { |
413 |
sub receipt_items { |
384 |
my ( $schema, $inv_line, $ordernumber ) = @_; |
414 |
my ( $schema, $inv_line, $ordernumber, $quantity ) = @_; |
385 |
my $logger = Log::Log4perl->get_logger(); |
415 |
my $logger = Log::Log4perl->get_logger(); |
386 |
my $quantity = $inv_line->quantity; |
|
|
387 |
|
416 |
|
388 |
# itemnumber is not a foreign key ??? makes this a bit cumbersome |
417 |
# itemnumber is not a foreign key ??? makes this a bit cumbersome |
389 |
my @item_links = $schema->resultset('AqordersItem')->search( |
418 |
my @item_links = $schema->resultset('AqordersItem')->search( |
Lines 469-478
sub receipt_items {
Link Here
|
469 |
} |
498 |
} |
470 |
|
499 |
|
471 |
sub transfer_items { |
500 |
sub transfer_items { |
472 |
my ( $schema, $inv_line, $order_from, $order_to ) = @_; |
501 |
my ( $schema, $inv_line, $order_from, $order_to, $quantity ) = @_; |
473 |
|
502 |
|
474 |
# Transfer x items from the orig order to a completed partial order |
503 |
# Transfer x items from the orig order to a completed partial order |
475 |
my $quantity = $inv_line->quantity; |
|
|
476 |
my $gocc = 0; |
504 |
my $gocc = 0; |
477 |
my %mapped_by_branch; |
505 |
my %mapped_by_branch; |
478 |
while ( $gocc < $quantity ) { |
506 |
while ( $gocc < $quantity ) { |
Lines 638-663
sub quote_item {
Link Here
|
638 |
} |
666 |
} |
639 |
$order_quantity = 1; # attempts to create an orderline for each gir |
667 |
$order_quantity = 1; # attempts to create an orderline for each gir |
640 |
} |
668 |
} |
|
|
669 |
my $price = $item->price_info; |
670 |
# Howells do not send an info price but do have a gross price |
671 |
if (!$price) { |
672 |
$price = $item->price_gross; |
673 |
} |
641 |
my $vendor = Koha::Acquisition::Booksellers->find( $quote->vendor_id ); |
674 |
my $vendor = Koha::Acquisition::Booksellers->find( $quote->vendor_id ); |
642 |
|
675 |
|
|
|
676 |
# NB quote will not include tax info it only contains the list price |
677 |
my $ecost = _discounted_price( $vendor->discount, $price, $item->price_info_inclusive ); |
678 |
|
643 |
# database definitions should set some of these defaults but dont |
679 |
# database definitions should set some of these defaults but dont |
644 |
my $order_hash = { |
680 |
my $order_hash = { |
645 |
biblionumber => $bib->{biblionumber}, |
681 |
biblionumber => $bib->{biblionumber}, |
646 |
entrydate => dt_from_string()->ymd(), |
682 |
entrydate => dt_from_string()->ymd(), |
647 |
basketno => $basketno, |
683 |
basketno => $basketno, |
648 |
listprice => $item->price, |
684 |
listprice => $price, |
649 |
quantity => $order_quantity, |
685 |
quantity => $order_quantity, |
650 |
quantityreceived => 0, |
686 |
quantityreceived => 0, |
651 |
order_vendornote => q{}, |
687 |
order_vendornote => q{}, |
652 |
order_internalnote => $order_note, |
688 |
order_internalnote => $order_note, |
653 |
replacementprice => $item->price, |
689 |
replacementprice => $price, |
654 |
rrp_tax_included => $item->price, |
690 |
rrp_tax_included => $price, |
655 |
rrp_tax_excluded => $item->price, |
691 |
rrp_tax_excluded => $price, |
656 |
ecost => _discounted_price( $quote->vendor->discount, $item->price ), |
692 |
rrp => $price, |
657 |
uncertainprice => 0, |
693 |
ecost => $ecost, |
658 |
sort1 => q{}, |
694 |
ecost_tax_included => $ecost, |
659 |
sort2 => q{}, |
695 |
ecost_tax_excluded => $ecost, |
660 |
currency => $vendor->listprice(), |
696 |
uncertainprice => 0, |
|
|
697 |
sort1 => q{}, |
698 |
sort2 => q{}, |
699 |
currency => $vendor->listprice(), |
661 |
}; |
700 |
}; |
662 |
|
701 |
|
663 |
# suppliers references |
702 |
# suppliers references |
Lines 884-891
sub quote_item {
Link Here
|
884 |
notforloan => -1, |
923 |
notforloan => -1, |
885 |
cn_sort => q{}, |
924 |
cn_sort => q{}, |
886 |
cn_source => 'ddc', |
925 |
cn_source => 'ddc', |
887 |
price => $item->price, |
926 |
price => $price, |
888 |
replacementprice => $item->price, |
927 |
replacementprice => $price, |
889 |
itype => |
928 |
itype => |
890 |
$item->girfield( 'stock_category', $occurrence ), |
929 |
$item->girfield( 'stock_category', $occurrence ), |
891 |
location => |
930 |
location => |
Lines 946-952
sub get_edifact_ean {
Link Here
|
946 |
|
985 |
|
947 |
# We should not need to have a routine to do this here |
986 |
# We should not need to have a routine to do this here |
948 |
sub _discounted_price { |
987 |
sub _discounted_price { |
949 |
my ( $discount, $price ) = @_; |
988 |
my ( $discount, $price, $discounted_price ) = @_; |
|
|
989 |
if (defined $discounted_price) { |
990 |
return $discounted_price; |
991 |
} |
992 |
if (!$price) { |
993 |
return 0; |
994 |
} |
950 |
return $price - ( ( $discount * $price ) / 100 ); |
995 |
return $price - ( ( $discount * $price ) / 100 ); |
951 |
} |
996 |
} |
952 |
|
997 |
|
Lines 1180-1186
Koha::EDI
Link Here
|
1180 |
|
1225 |
|
1181 |
=head2 receipt_items |
1226 |
=head2 receipt_items |
1182 |
|
1227 |
|
1183 |
receipt_items( schema_obj, invoice_line, ordernumber) |
1228 |
receipt_items( schema_obj, invoice_line, ordernumber, $quantity) |
1184 |
|
1229 |
|
1185 |
receipts the items recorded on this invoice line |
1230 |
receipts the items recorded on this invoice line |
1186 |
|
1231 |
|
Lines 1188-1194
Koha::EDI
Link Here
|
1188 |
|
1233 |
|
1189 |
=head2 transfer_items |
1234 |
=head2 transfer_items |
1190 |
|
1235 |
|
1191 |
transfer_items(schema, invoice_line, originating_order, receiving_order) |
1236 |
transfer_items(schema, invoice_line, originating_order, receiving_order, $quantity) |
1192 |
|
1237 |
|
1193 |
Transfer the items covered by this invoice line from their original |
1238 |
Transfer the items covered by this invoice line from their original |
1194 |
order to another order recording the partial fulfillment of the original |
1239 |
order to another order recording the partial fulfillment of the original |
Lines 1241-1256
Koha::EDI
Link Here
|
1241 |
|
1286 |
|
1242 |
=head2 _get_invoiced_price |
1287 |
=head2 _get_invoiced_price |
1243 |
|
1288 |
|
1244 |
_get_invoiced_price(line_object) |
1289 |
(price, price_tax_excluded) = _get_invoiced_price(line_object, $quantity) |
1245 |
|
1290 |
|
1246 |
Returns the net price or an equivalent calculated from line cost / qty |
1291 |
Returns an array of unitprice and unitprice_tax_excluded derived from the lineitem |
|
|
1292 |
monetary fields |
1247 |
|
1293 |
|
1248 |
=head2 _discounted_price |
1294 |
=head2 _discounted_price |
1249 |
|
1295 |
|
1250 |
ecost = _discounted_price(discount, item_price) |
1296 |
ecost = _discounted_price(discount, item_price, discounted_price) |
1251 |
|
1297 |
|
1252 |
utility subroutine to return a price calculated from the |
1298 |
utility subroutine to return a price calculated from the |
1253 |
vendors discount and quoted price |
1299 |
vendors discount and quoted price |
|
|
1300 |
if invoice has a field containing discounted price that is returned |
1301 |
instead of recalculating |
1254 |
|
1302 |
|
1255 |
=head2 _check_for_existing_bib |
1303 |
=head2 _check_for_existing_bib |
1256 |
|
1304 |
|