View | Details | Raw Unified | Return to bug 38689
Collapse All | Expand All

(-)a/Koha/EDI.pm (-12 / +44 lines)
Lines 290-296 sub process_invoice { Link Here
290
                )->single;
290
                )->single;
291
            }
291
            }
292
            if ( !$vendor_acct ) {
292
            if ( !$vendor_acct ) {
293
                carp "Cannot find vendor with ean $vendor_ean for invoice $invoicenumber in ".$invoice_message->filename;
293
                $invoice_message->add_to_edifact_errors({ details => "Cannot find vendor with ean $vendor_ean" });
294
                $logger->error("Cannot find vendor with ean $vendor_ean for invoice $invoicenumber in ".$invoice_message->filename);
294
                next;
295
                next;
295
            }
296
            }
296
            $invoice_message->edi_acct( $vendor_acct->id );
297
            $invoice_message->edi_acct( $vendor_acct->id );
Lines 313-318 sub process_invoice { Link Here
313
            foreach my $line ( @{$lines} ) {
314
            foreach my $line ( @{$lines} ) {
314
                my $ordernumber = $line->ordernumber;
315
                my $ordernumber = $line->ordernumber;
315
                if ( !$ordernumber ) {
316
                if ( !$ordernumber ) {
317
                    $invoice_message->add_to_edifact_errors(
318
                        {
319
                            section => $line->line_item_number,
320
                            details => "Message missing ordernumber"
321
                        }
322
                    );
316
                    $logger->error("Skipping invoice line, no associated ordernumber");
323
                    $logger->error("Skipping invoice line, no associated ordernumber");
317
                    next;
324
                    next;
318
                }
325
                }
Lines 320-331 sub process_invoice { Link Here
320
                # ModReceiveOrder does not validate that $ordernumber exists validate here
327
                # ModReceiveOrder does not validate that $ordernumber exists validate here
321
                my $order = $schema->resultset('Aqorder')->find($ordernumber);
328
                my $order = $schema->resultset('Aqorder')->find($ordernumber);
322
                if ( !$order ) {
329
                if ( !$order ) {
330
                    $invoice_message->add_to_edifact_errors(
331
                        {
332
                            section => $line->line_item_number,
333
                            details => "Koha order $ordernumber missing"
334
                        }
335
                    );
323
                    $logger->error("Skipping invoice line, no order found for $ordernumber, invoice:$invoicenumber");
336
                    $logger->error("Skipping invoice line, no order found for $ordernumber, invoice:$invoicenumber");
324
                    next;
337
                    next;
325
                }
338
                }
326
339
327
                my $bib = $order->biblionumber;
340
                my $bib = $order->biblionumber;
328
                if ( !$bib ) {
341
                if ( !$bib ) {
342
                    $invoice_message->add_to_edifact_errors(
343
                        {
344
                            section => $line->line_item_number,
345
                            details => "Koha biblio missing"
346
                        }
347
                    );
329
                    $logger->error(
348
                    $logger->error(
330
                        "Skipping invoice line, no bibliographic record found for $ordernumber, invoice:$invoicenumber"
349
                        "Skipping invoice line, no bibliographic record found for $ordernumber, invoice:$invoicenumber"
331
                    );
350
                    );
Lines 384-396 sub process_invoice { Link Here
384
                            tax_value_on_receiving => $quantity * $price_excl_tax * $tax_rate->{rate},
403
                            tax_value_on_receiving => $quantity * $price_excl_tax * $tax_rate->{rate},
385
                        }
404
                        }
386
                    );
405
                    );
387
                    transfer_items(
406
                    transfer_items( $schema, $line, $order, $received_order, $quantity );
388
                        $schema,         $line, $order,
389
                        $received_order, $quantity
390
                    );
391
                    receipt_items(
407
                    receipt_items(
392
                        $schema,                      $line,
408
                        $schema, $line,
393
                        $received_order->ordernumber, $quantity
409
                        $received_order->ordernumber, $quantity, $invoice_message
394
                    );
410
                    );
395
                } else {    # simple receipt all copies on order
411
                } else {    # simple receipt all copies on order
396
                    $order->quantityreceived($quantity);
412
                    $order->quantityreceived($quantity);
Lines 403-409 sub process_invoice { Link Here
403
                    $order->tax_value_on_receiving( $quantity * $price_excl_tax * $tax_rate->{rate} );
419
                    $order->tax_value_on_receiving( $quantity * $price_excl_tax * $tax_rate->{rate} );
404
                    $order->orderstatus('complete');
420
                    $order->orderstatus('complete');
405
                    $order->update;
421
                    $order->update;
406
                    receipt_items( $schema, $line, $ordernumber, $quantity );
422
                    receipt_items( $schema, $line, $ordernumber, $quantity, $invoice_message );
407
                }
423
                }
408
            }
424
            }
409
        }
425
        }
Lines 440-446 sub _get_invoiced_price { Link Here
440
}
456
}
441
457
442
sub receipt_items {
458
sub receipt_items {
443
    my ( $schema, $inv_line, $ordernumber, $quantity ) = @_;
459
    my ( $schema, $inv_line, $ordernumber, $quantity, $invoice_message ) = @_;
444
    my $logger   = Koha::Logger->get({ interface => 'edi' });
460
    my $logger   = Koha::Logger->get({ interface => 'edi' });
445
461
446
    # itemnumber is not a foreign key ??? makes this a bit cumbersome
462
    # itemnumber is not a foreign key ??? makes this a bit cumbersome
Lines 454-459 sub receipt_items { Link Here
454
        my $item = $schema->resultset('Item')->find( $ilink->itemnumber );
470
        my $item = $schema->resultset('Item')->find( $ilink->itemnumber );
455
        if ( !$item ) {
471
        if ( !$item ) {
456
            my $i = $ilink->itemnumber;
472
            my $i = $ilink->itemnumber;
473
            $invoice_message->add_to_edifact_errors(
474
                {
475
                    section => $inv_line->line_item_number,
476
                    details => "Cannot fine aqorder item"
477
                }
478
            );
457
            $logger->warn(
479
            $logger->warn(
458
                "Cannot find aqorder item for $i :Order:$ordernumber");
480
                "Cannot find aqorder item for $i :Order:$ordernumber");
459
            next;
481
            next;
Lines 493-498 sub receipt_items { Link Here
493
                    }
515
                    }
494
                );
516
                );
495
                if ( $rs->count > 0 ) {
517
                if ( $rs->count > 0 ) {
518
                    $invoice_message->add_to_edifact_errors(
519
                        {
520
                            section => $inv_line->line_item_number . " : " . $gir_occurrence,
521
                            details => "Duplicate barcode found $barcode"
522
                        }
523
                    );
496
                    $logger->warn("Barcode $barcode is a duplicate");
524
                    $logger->warn("Barcode $barcode is a duplicate");
497
                }
525
                }
498
                else {
526
                else {
Lines 517-528 sub receipt_items { Link Here
517
            $item->update;
545
            $item->update;
518
        }
546
        }
519
        else {
547
        else {
548
            $invoice_message->add_to_edifact_errors(
549
                {
550
                    section => $inv_line->line_item_number,
551
                    details => "Unmatched item at branch $branch"
552
                }
553
            );
520
            $logger->warn("Unmatched item at branch:$branch");
554
            $logger->warn("Unmatched item at branch:$branch");
521
        }
555
        }
522
        ++$gir_occurrence;
556
        ++$gir_occurrence;
523
    }
557
    }
524
    return;
558
    return;
525
526
}
559
}
527
560
528
sub transfer_items {
561
sub transfer_items {
Lines 1298-1304 Koha::EDI Link Here
1298
1331
1299
=head2 receipt_items
1332
=head2 receipt_items
1300
1333
1301
    receipt_items( schema_obj, invoice_line, ordernumber, $quantity)
1334
    receipt_items( schema_obj, invoice_line, ordernumber, $quantity, $invoice_message)
1302
1335
1303
    receipts the items recorded on this invoice line
1336
    receipts the items recorded on this invoice line
1304
1337
1305
- 

Return to bug 38689