php-edifact / edifact

Tools to process EDI messages in UN/EDIFACT format
GNU Lesser General Public License v3.0
268 stars 86 forks source link

Duplicate segments error after updating to v1.0/v1.1 #139

Closed olelis closed 2 weeks ago

olelis commented 3 weeks ago

Hello,

In our system, we have noticed that after updating to version 1.x of this package, all our purchase order's have empty delivery address. It was working correctly for version 0.70.

I have found example edifact file that have exact same error: https://developer.kramp.com/edi-edifact-d96a-purchase-order

As you can see, it has three NAD+ lines:

NAD+SU+8712199999999::9++Supplier Name+Supplier Street+SuppliCity++Postalcode'
NAD+IV+8716106198405::9++Kramp Groep B.V. 07+P.O box 248+Leek++9350 AE+NL'
NAD+DP+8716106053926::9++Kramp Groep B.V.+ZONE REPUBLIQUE III 1 RUE DE GALILE+POITIERS CEDEX++86011+FR'

Each meaning different party.

Here is the example code:

<?php
$data = parseString('editest.txt');
print_r($data);

function parseString(string $filename): array
{
    $parser = new Parser();
    $parser->load($filename);
    $parsed = $parser->get();

    $analyser = new Analyser();
    $mapping = new MappingProvider('D96A');
    $segs = $analyser->loadSegmentsXml($mapping->getSegments());
    $svc = $analyser->loadSegmentsXml($mapping->getServiceSegments());

    $interpreter = new Interpreter($mapping->getMessage('ORDERS'), $segs, $svc);
    $groups = $interpreter->prepare($parsed);

    return [
        'errors' => $interpreter->getErrors(),
        'groups' =>$groups,
    ];
}

If you run same code between different versions Please compare editest.json files in both folders you will see some differences:

  1. Errors: The message has some additional segments beyond the maximum repetition allowed (skipped)
  2. Missing two NAD segments
  3. segmentGroup is quite often empty for child items

Here is working example that compares between two paths. https://github.com/olelis/phpedifacttest

I have also compared output of Interpreter and Analyzer and looks like Analyzer reads all addresses correctly.

How can this be fixed in our end, or is there an error in interpreter?

sabas commented 3 weeks ago

Hi, it's strange! I did it in my side both with 0.7.0 and master and they're the same (and no errors).... Did you do any more customization? Can you please test with dev-master? Have you upgraded edifact-mapping package?

olelis commented 3 weeks ago

@sabas Yes, it works with dev-master! Should it be released under 1.1.1 ? And yes, it was latest released version of edifact-mapping (v0.5.0)

The only minor issue left is that in the end of groups, under sectionControl and messageTrailer,, there is no segment group: It is not an issue for us, but I am not sure why it is empty. image Left: dev-master Right: v0.7.0

And yes, there are no modifications (you can see original code in linked repositotory)

sabas commented 3 weeks ago

@olelis published a 1.1.1 tag The empty segment group is correct there after further analysis, since in the segment table they're at the same level of the header fields https://service.unece.org/trade/untdid/d96a/trmd/orders_s.htm

olelis commented 2 weeks ago

@sabas Thank you , 1.1.1 works correctly!

And thank you for the work you do and fast responses!