Lines 290-297
sub process_invoice {
Link Here
|
290 |
)->single; |
290 |
)->single; |
291 |
} |
291 |
} |
292 |
if ( !$vendor_acct ) { |
292 |
if ( !$vendor_acct ) { |
293 |
carp |
293 |
carp "Cannot find vendor with ean $vendor_ean for invoice $invoicenumber in $invoice_message->filename"; |
294 |
"Cannot find vendor with ean $vendor_ean for invoice $invoicenumber in $invoice_message->filename"; |
|
|
295 |
next; |
294 |
next; |
296 |
} |
295 |
} |
297 |
$invoice_message->edi_acct( $vendor_acct->id ); |
296 |
$invoice_message->edi_acct( $vendor_acct->id ); |
Lines 313-412
sub process_invoice {
Link Here
|
313 |
|
312 |
|
314 |
foreach my $line ( @{$lines} ) { |
313 |
foreach my $line ( @{$lines} ) { |
315 |
my $ordernumber = $line->ordernumber; |
314 |
my $ordernumber = $line->ordernumber; |
316 |
if (!$ordernumber ) { |
315 |
if ( !$ordernumber ) { |
317 |
$logger->trace( "Skipping invoice line, no associated ordernumber" ); |
316 |
$logger->error("Skipping invoice line, no associated ordernumber"); |
318 |
next; |
317 |
next; |
319 |
} |
318 |
} |
320 |
|
319 |
|
321 |
$logger->trace( "Receipting order:$ordernumber Qty: ", |
320 |
# ModReceiveOrder does not validate that $ordernumber exists validate here |
322 |
$line->quantity ); |
|
|
323 |
|
324 |
my $order = $schema->resultset('Aqorder')->find($ordernumber); |
321 |
my $order = $schema->resultset('Aqorder')->find($ordernumber); |
325 |
if (my $bib = $order->biblionumber) { |
322 |
if ( !$order ) { |
326 |
my $b = $bib->biblionumber; |
323 |
$logger->error("Skipping invoice line, no order found for $ordernumber, invoice:$invoicenumber"); |
327 |
my $id = $line->item_number_id; |
324 |
next; |
328 |
$logger->trace("Updating bib:$b id:$id"); |
|
|
329 |
} |
325 |
} |
330 |
|
326 |
|
331 |
# ModReceiveOrder does not validate that $ordernumber exists validate here |
327 |
my $bib = $order->biblionumber; |
332 |
if ($order) { |
328 |
if ( !$bib ) { |
|
|
329 |
$logger->error( |
330 |
"Skipping invoice line, no bibliographic record found for $ordernumber, invoice:$invoicenumber" |
331 |
); |
332 |
next; |
333 |
} |
334 |
|
335 |
$logger->trace( "Receipting order:$ordernumber Qty: " . $line->quantity ); |
336 |
$logger->trace( "Updating bib:" . $bib->biblionumber . " id:" . $line->item_number_id ); |
333 |
|
337 |
|
334 |
# check suggestions |
338 |
# check suggestions |
335 |
my $s = $schema->resultset('Suggestion')->search( |
339 |
my $s = $schema->resultset('Suggestion')->search( |
|
|
340 |
{ |
341 |
biblionumber => $bib->biblionumber, |
342 |
} |
343 |
)->single; |
344 |
if ($s) { |
345 |
ModSuggestion( |
336 |
{ |
346 |
{ |
337 |
biblionumber => $order->biblionumber->biblionumber, |
347 |
suggestionid => $s->suggestionid, |
|
|
348 |
STATUS => 'AVAILABLE', |
338 |
} |
349 |
} |
339 |
)->single; |
350 |
); |
340 |
if ($s) { |
351 |
} |
341 |
ModSuggestion( |
|
|
342 |
{ |
343 |
suggestionid => $s->suggestionid, |
344 |
STATUS => 'AVAILABLE', |
345 |
} |
346 |
); |
347 |
} |
348 |
# If quantity_invoiced is present use it in preference |
349 |
my $quantity = $line->quantity_invoiced; |
350 |
if (!$quantity) { |
351 |
$quantity = $line->quantity; |
352 |
} |
353 |
|
352 |
|
354 |
my ( $price, $price_excl_tax ) = _get_invoiced_price($line, $quantity); |
353 |
# If quantity_invoiced is present use it in preference |
355 |
my $tax_rate = $line->tax_rate; |
354 |
my $quantity = $line->quantity_invoiced; |
356 |
if ($tax_rate && $tax_rate->{rate} != 0) { |
355 |
if ( !$quantity ) { |
357 |
$tax_rate->{rate} /= 100; |
356 |
$quantity = $line->quantity; |
358 |
} |
357 |
} |
359 |
|
358 |
|
360 |
if ( $order->quantity > $quantity ) { |
359 |
my ( $price, $price_excl_tax ) = _get_invoiced_price( $line, $quantity ); |
361 |
my $ordered = $order->quantity; |
360 |
my $tax_rate = $line->tax_rate; |
362 |
|
361 |
if ( $tax_rate && $tax_rate->{rate} != 0 ) { |
363 |
# part receipt |
362 |
$tax_rate->{rate} /= 100; |
364 |
$order->orderstatus('partial'); |
|
|
365 |
$order->quantity( $ordered - $quantity ); |
366 |
$order->update; |
367 |
my $received_order = $order->copy( |
368 |
{ |
369 |
ordernumber => undef, |
370 |
quantity => $quantity, |
371 |
quantityreceived => $quantity, |
372 |
orderstatus => 'complete', |
373 |
unitprice => $price, |
374 |
unitprice_tax_included => $price, |
375 |
unitprice_tax_excluded => $price_excl_tax, |
376 |
invoiceid => $invoiceid, |
377 |
datereceived => $msg_date, |
378 |
tax_rate_on_receiving => $tax_rate->{rate}, |
379 |
tax_value_on_receiving => $quantity * $price_excl_tax * $tax_rate->{rate}, |
380 |
} |
381 |
); |
382 |
transfer_items( $schema, $line, $order, |
383 |
$received_order, $quantity ); |
384 |
receipt_items( $schema, $line, |
385 |
$received_order->ordernumber, $quantity ); |
386 |
} |
387 |
else { # simple receipt all copies on order |
388 |
$order->quantityreceived( $quantity ); |
389 |
$order->datereceived($msg_date); |
390 |
$order->invoiceid($invoiceid); |
391 |
$order->unitprice($price); |
392 |
$order->unitprice_tax_excluded($price_excl_tax); |
393 |
$order->unitprice_tax_included($price); |
394 |
$order->tax_rate_on_receiving($tax_rate->{rate}); |
395 |
$order->tax_value_on_receiving( $quantity * $price_excl_tax * $tax_rate->{rate}); |
396 |
$order->orderstatus('complete'); |
397 |
$order->update; |
398 |
receipt_items( $schema, $line, $ordernumber, $quantity ); |
399 |
} |
400 |
} |
363 |
} |
401 |
else { |
364 |
|
402 |
$logger->error( |
365 |
if ( $order->quantity > $quantity ) { |
403 |
"No order found for $ordernumber Invoice:$invoicenumber" |
366 |
my $ordered = $order->quantity; |
|
|
367 |
|
368 |
# part receipt |
369 |
$order->orderstatus('partial'); |
370 |
$order->quantity( $ordered - $quantity ); |
371 |
$order->update; |
372 |
my $received_order = $order->copy( |
373 |
{ |
374 |
ordernumber => undef, |
375 |
quantity => $quantity, |
376 |
quantityreceived => $quantity, |
377 |
orderstatus => 'complete', |
378 |
unitprice => $price, |
379 |
unitprice_tax_included => $price, |
380 |
unitprice_tax_excluded => $price_excl_tax, |
381 |
invoiceid => $invoiceid, |
382 |
datereceived => $msg_date, |
383 |
tax_rate_on_receiving => $tax_rate->{rate}, |
384 |
tax_value_on_receiving => $quantity * $price_excl_tax * $tax_rate->{rate}, |
385 |
} |
404 |
); |
386 |
); |
405 |
next; |
387 |
transfer_items( |
|
|
388 |
$schema, $line, $order, |
389 |
$received_order, $quantity |
390 |
); |
391 |
receipt_items( |
392 |
$schema, $line, |
393 |
$received_order->ordernumber, $quantity |
394 |
); |
395 |
} else { # simple receipt all copies on order |
396 |
$order->quantityreceived($quantity); |
397 |
$order->datereceived($msg_date); |
398 |
$order->invoiceid($invoiceid); |
399 |
$order->unitprice($price); |
400 |
$order->unitprice_tax_excluded($price_excl_tax); |
401 |
$order->unitprice_tax_included($price); |
402 |
$order->tax_rate_on_receiving( $tax_rate->{rate} ); |
403 |
$order->tax_value_on_receiving( $quantity * $price_excl_tax * $tax_rate->{rate} ); |
404 |
$order->orderstatus('complete'); |
405 |
$order->update; |
406 |
receipt_items( $schema, $line, $ordernumber, $quantity ); |
406 |
} |
407 |
} |
407 |
|
|
|
408 |
} |
408 |
} |
409 |
|
|
|
410 |
} |
409 |
} |
411 |
} |
410 |
} |
412 |
|
411 |
|
413 |
- |
|
|