From 2e992847e031aee6a66d0694918de5ed59a9f5e9 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 7 Jan 2025 10:41:07 +0000 Subject: [PATCH] Bug 38689: Add section to output We attempt to add the relevant part of the EDI message to the 'section' field of the edifact_errors record and then display this alongside the error details. Signed-off-by: Kyle M Hall --- Koha/EDI.pm | 90 ++++++++++++------- .../prog/en/modules/acqui/edifactmsgs.tt | 7 +- 2 files changed, 62 insertions(+), 35 deletions(-) diff --git a/Koha/EDI.pm b/Koha/EDI.pm index 00cf5f95dde..60d5e966a51 100644 --- a/Koha/EDI.pm +++ b/Koha/EDI.pm @@ -110,6 +110,11 @@ sub create_edi_order { )->single; } + unless ( $ean_obj ) { + carp "No matching EAN found for $ean"; + return; + } + my $dbh = C4::Context->dbh; my $arr_ref = $dbh->selectcol_arrayref( 'select id from edifact_messages where basketno = ? and message_type = \'QUOTE\'', @@ -292,7 +297,7 @@ sub process_invoice { if ( !$vendor_acct ) { $invoice_message->add_to_edifact_errors( { - section => '', + section => "NAD+SU+" . $msg->supplier_ean, details => "Skipped invoice $invoicenumber with unmatched vendor san: $vendor_ean" } ); @@ -300,7 +305,7 @@ sub process_invoice { next; } $invoice_message->edi_acct( $vendor_acct->id ); - $logger->trace("Adding invoice:$invoicenumber"); + $logger->trace("Adding invoice: $invoicenumber"); my $new_invoice = $schema->resultset('Aqinvoice')->create( { invoicenumber => $invoicenumber, @@ -321,8 +326,8 @@ sub process_invoice { if ( !$ordernumber ) { $invoice_message->add_to_edifact_errors( { - section => $line->line_item_number, - details => "Message missing ordernumber" + section => join("\n", map { $_->as_string } @{$line->{segs}}), + details => "Skipped invoice line " . $line->line_item_number . ", missing ordernumber" } ); $logger->error("Skipping invoice line, no associated ordernumber"); @@ -334,8 +339,11 @@ sub process_invoice { if ( !$order ) { $invoice_message->add_to_edifact_errors( { - section => $line->line_item_number, - details => "Koha order $ordernumber missing" + section => join( "\n", map { $_->as_string } @{ $line->{segs} } ), + details => "Skipped invoice line " + . $line->line_item_number + . ", cannot find order with ordernumber " + . $ordernumber } ); $logger->error("Skipping invoice line, no order found for $ordernumber, invoice:$invoicenumber"); @@ -346,8 +354,11 @@ sub process_invoice { if ( !$bib ) { $invoice_message->add_to_edifact_errors( { - section => $line->line_item_number, - details => "Koha biblio missing" + section => join( "\n", map { $_->as_string } @{ $line->{segs} } ), + details => "Skipped invoice line " + . $line->line_item_number + . ", cannot find biblio for ordernumber " + . $ordernumber } ); $logger->error( @@ -477,8 +488,12 @@ sub receipt_items { my $i = $ilink->itemnumber; $invoice_message->add_to_edifact_errors( { - section => $inv_line->line_item_number, - details => "Cannot fine aqorder item" + section => join( "\n", map { $_->as_string } @{ $inv_line->{segs} } ), + details => "Skipped invoice line " + . $inv_line->line_item_number + . ", Koha item with itemnumber " + . $i + . "is missing" } ); $logger->warn( @@ -522,8 +537,12 @@ sub receipt_items { if ( $rs->count > 0 ) { $invoice_message->add_to_edifact_errors( { - section => $inv_line->line_item_number . " : " . $gir_occurrence, - details => "Duplicate barcode found $barcode" + section => join( "\n", map { $_->as_string } @{ $inv_line->{segs} } ), + details => "Failed to assign barcode " + . $barcode + . "for invoice line " + . $inv_line->line_item_number + . ", duplicate found" } ); $logger->warn("Barcode $barcode is a duplicate"); @@ -552,8 +571,11 @@ sub receipt_items { else { $invoice_message->add_to_edifact_errors( { - section => $inv_line->line_item_number, - details => "Unmatched item at branch $branch" + section => join("\n", map { $_->as_string } @{$inv_line->{segs}}), + details => "No matching item found for invoice line " + . $inv_line->line_item_number . ":" + . $gir_occurrence + . " at branch $branch" } ); $logger->warn("Unmatched item at branch:$branch"); @@ -722,10 +744,10 @@ sub quote_item { details => "Failed to create basket" } ); - $logger->error('Skipping order creation no valid basketno'); + $logger->error('Skipped order creation no valid basketno'); return; } - $logger->trace( 'Checking db for matches with ', $item->item_number_id() ); + $logger->trace( 'Checking db for matches with ' . $item->item_number_id() ); my $bib = _check_for_existing_bib( $item->item_number_id() ); if ( !defined $bib ) { $bib = {}; @@ -736,10 +758,10 @@ sub quote_item { ( $bib->{biblionumber}, $bib->{biblioitemnumber} ) = AddBiblio( $bib_record, q{} ); - $logger->trace("New biblio added $bib->{biblionumber}"); + $logger->trace("Added biblio: ". $bib->{biblionumber}); } else { - $logger->trace("Match found: $bib->{biblionumber}"); + $logger->trace("Match found: " .$bib->{biblionumber}); } # Create an orderline @@ -752,7 +774,7 @@ sub quote_item { if ( $gir_count != $order_quantity ) { $quote_message->add_to_edifact_errors( { - section => "GIR", + section => join('\n', @{$item->{GIR}}), details => "Order for $order_quantity items, $gir_count segments present" } ); @@ -838,20 +860,20 @@ sub quote_item { if ( $item->quantity > 1 ) { $quote_message->add_to_edifact_errors( { - section => "GIR", + section => join( '\n', @{ $item->{GIR} } ), details => "Skipped GIR line with invalid budget: " . $item->girfield('fund_allocation') } ); - $logger->trace('girfield skipped for invalid budget'); + $logger->trace( 'Skipping item with invalid budget: ' . $item->girfield('fund_allocation') ); $skip++; } else { $quote_message->add_to_edifact_errors( { - section => "GIR", + section => join( "\n", map { $_->as_string } @{ $item->{segs} } ), details => "Skipped orderline line with invalid budget: " . $item->girfield('fund_allocation') } ); - $logger->trace('orderline skipped for invalid budget'); + $logger->trace( 'Skipping orderline with invalid budget: ' . $item->girfield('fund_allocation') ); return; } } @@ -885,7 +907,7 @@ sub quote_item { $item_hash->{biblioitemnumber} = $bib->{biblioitemnumber}; my $kitem = Koha::Item->new( $item_hash )->store; my $itemnumber = $kitem->itemnumber; - $logger->trace("Added item:$itemnumber"); + $logger->trace("Added item: ". $itemnumber); $schema->resultset('AqordersItem')->create( { ordernumber => $first_order->ordernumber, @@ -902,12 +924,12 @@ sub quote_item { ); if ($rota) { $rota->add_item($itemnumber); - $logger->trace("Item added to rota $rota->id"); + $logger->trace("Item added to rota " . $rota->title); } else { $quote_message->add_to_edifact_errors( { - section => "LRP", - details => "No rota found for passed $lrp in orderline" + section => "$item->{GIR}->[0]", + details => "No rota found for passed LRP:$lrp in orderline" } ); $logger->error("No rota found matching $lrp in orderline"); @@ -930,12 +952,12 @@ sub quote_item { $item->girfield( 'fund_allocation', $occurrence ); $quote_message->add_to_edifact_errors( { - section => "GIR", - details => "Skipped GIR line with invalid budget: $bad_budget" + section => "$item->{GIR}->[$occurrence]", + details => "Invalid budget $bad_budget found" } ); $logger->trace( - "girfield skipped for invalid budget:$bad_budget"); + "Skipping item with invalid budget: " . $bad_budget); ++$occurrence; ## lets look at the next one not this one again next; } @@ -1025,8 +1047,8 @@ sub quote_item { else { $quote_message->add_to_edifact_errors( { - section => "LRP", - details => "No rota found for passed $lrp in orderline" + section => "$item->{GIR}->[$occurrence]", + details => "No rota found for passed LRP:$lrp in orderline" } ); $logger->error( @@ -1101,8 +1123,8 @@ sub quote_item { else { $quote_message->add_to_edifact_errors( { - section => "LRP", - details => "No rota found for passed $lrp in orderline" + section => "$item->{GIR}->[$occurrence]", + details => "No rota found for passed LRP:$lrp in orderline" } ); $logger->error( diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/edifactmsgs.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/edifactmsgs.tt index 94a9ca180ca..8147dc7119b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/edifactmsgs.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/edifactmsgs.tt @@ -130,7 +130,12 @@ let errorsList = ''; -- 2.47.1