Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple SG2 segments not allowed #130

Closed
szocsbarni opened this issue Mar 5, 2024 · 8 comments
Closed

Multiple SG2 segments not allowed #130

szocsbarni opened this issue Mar 5, 2024 · 8 comments

Comments

@szocsbarni
Copy link
Contributor

szocsbarni commented Mar 5, 2024

Given the below, short edi content, D01B version, pricat type:

UNA:+.?'
UNB+UNOC:3+0000000000000:14+0000000000000:14+231126:1830+502+0000++++PRICAT'
UNH+1+PRICAT:D:01B:UN:EAN009'
BGM+9:::PREISLISTE+11+4'
DTM+137:20231126:102'
NAD+BY+1111111111111::9'
NAD+SU+2222222222222::9'
UNT+0+1'
UNZ+1+502'

the current code version on the master (d4c8450) skips the 2nd NAD command with the below warning:

Array
(
    [0] => Array
        (
            [text] => The message has some additional segments beyond the maximum repetition allowed (skipped)
            [position] => 4
            [segmentId] => NAD
        )

)

while the release v1 (2949865), parses them, without any warnings. According to the PRICAT documentation, there can be multiple SG2 segments, each of them containing one NAD command.

@sabas
Copy link
Collaborator

sabas commented Mar 6, 2024

You are right..
You can mantain the segment disabling the patching $interpreter->togglePatching(false);
The problem lies here
https://github.com/php-edifact/edifact/blob/master/src/EDI/Interpreter.php#L660
The issue is that the code doesn't check currently if the first element of the next group (or a repetition of the same) is the same.

@sabas
Copy link
Collaborator

sabas commented Mar 6, 2024

@szocsbarni I pushed a commit which should deal with this case, can you test with a larger sample? Thanks :)

@szocsbarni
Copy link
Contributor Author

@sabas the fix is ok, parsing does not stop on the double NAD command and processes larger files. I am still getting a warning though, will it be eliminated?

Array
(
    [0] => Array
        (
            [text] => The message has some additional segments beyond the maximum repetition allowed (skipped)
            [position] => 4
            [segmentId] => NAD
        )

)

@sabas
Copy link
Collaborator

sabas commented Mar 6, 2024

On the same file? Strange..
Here's my sample (yes I should write tests.... :/)

require('vendor/autoload.php');

$c = new EDI\Parser();
$file = <<<END
UNA:+.?'
UNB+UNOC:3+0000000000000:14+0000000000000:14+231126:1830+502+0000++++PRICAT'
UNH+1+PRICAT:D:01B:UN:EAN009'
BGM+9:::PREISLISTE+11+4'
DTM+137:20231126:102'
NAD+BY+1111111111111::9'
NAD+SU+2222222222222::9'
UNT+0+1'
UNZ+1+502'
END;

$c->loadString($file);
$o = $c->get();
d($o);
d($c->errors());

$mapping = new EDI\Mapping\MappingProvider($c->getMessageDirectory());

$analyser = new EDI\Analyser();
$segs = $analyser->loadSegmentsXml($mapping->getSegments());
$svc = $analyser->loadSegmentsXml($mapping->getServiceSegments(3));

$interpreter = new EDI\Interpreter($mapping->getMessage($c->getMessageFormat()), $segs, $svc);
//$interpreter->togglePatching(false);
$prep = $interpreter->prepare($o);


d($prep);
d($interpreter->getErrors());

@szocsbarni
Copy link
Contributor Author

yes, even running this concrete code segment of yours (replaced function calls of d() to print_r()). Below is my full output:

Array
(
    [0] => Array
        (
            [0] => UNB
            [1] => Array
                (
                    [0] => UNOC
                    [1] => 3
                )

            [2] => Array
                (
                    [0] => 0000000000000
                    [1] => 14
                )

            [3] => Array
                (
                    [0] => 0000000000000
                    [1] => 14
                )

            [4] => Array
                (
                    [0] => 231126
                    [1] => 1830
                )

            [5] => 502
            [6] => 0000
            [7] =>
            [8] =>
            [9] =>
            [10] => PRICAT'
        )

    [1] => Array
        (
            [0] => UNH
            [1] => 1
            [2] => Array
                (
                    [0] => PRICAT
                    [1] => D
                    [2] => 01B
                    [3] => UN
                    [4] => EAN009'
                )

        )

    [2] => Array
        (
            [0] => BGM
            [1] => Array
                (
                    [0] => 9
                    [1] =>
                    [2] =>
                    [3] => PREISLISTE
                )

            [2] => 11
            [3] => 4'
        )

    [3] => Array
        (
            [0] => DTM
            [1] => Array
                (
                    [0] => 137
                    [1] => 20231126
                    [2] => 102'
                )

        )

    [4] => Array
        (
            [0] => NAD
            [1] => BY
            [2] => Array
                (
                    [0] => 1111111111111
                    [1] =>
                    [2] => 9'
                )

        )

    [5] => Array
        (
            [0] => NAD
            [1] => SU
            [2] => Array
                (
                    [0] => 2222222222222
                    [1] =>
                    [2] => 9'
                )

        )

    [6] => Array
        (
            [0] => UNT
            [1] => 0
            [2] => 1'
        )

    [7] => Array
        (
            [0] => UNZ
            [1] => 1
            [2] => 502'
        )

)
Array
(
)
Array
(
    [0] => Array
        (
            [messageHeader] => Array
                (
                    [segmentIdx] => 0
                    [segmentCode] => UNH
                    [segmentGroup] =>
                    [messageReferenceNumber] => 1
                    [messageIdentifier] => Array
                        (
                            [messageType] => PRICAT
                            [messageVersionNumber] => D
                            [messageReleaseNumber] => 01B
                            [controllingAgency] => UN
                            [associationAssignedCode] => EAN009'
                        )

                )

            [beginningOfMessage] => Array
                (
                    [segmentIdx] => 1
                    [segmentCode] => BGM
                    [segmentGroup] =>
                    [document] => Array
                        (
                            [documentNameCode] => 9
                            [codeListIdentificationCode] =>
                            [codeListResponsibleAgencyCode] =>
                            [documentName] => PREISLISTE
                        )

                    [document1] => Array
                        (
                            [documentIdentifier] => 11
                        )

                    [messageFunctionCode] => 4'
                )

            [dateOrtimeOrperiod] => Array
                (
                    [segmentIdx] => 2
                    [segmentCode] => DTM
                    [segmentGroup] =>
                    [date] => Array
                        (
                            [dateOrTimeOrPeriodFunctionCodeQualifier] => 137
                            [dateOrTimeOrPeriodValue] => 20231126
                            [dateOrTimeOrPeriodFormatCode] => 102'
                        )

                )

            [SG2] => Array
                (
                    [0] => Array
                        (
                            [nameAndAddress] => Array
                                (
                                    [segmentIdx] => 3
                                    [segmentCode] => NAD
                                    [segmentGroup] => SG2
                                    [partyFunctionCodeQualifier] => BY
                                    [partyIdentificationDetails] => Array
                                        (
                                            [partyIdentifier] => 1111111111111
                                            [codeListIdentificationCode] =>
                                            [codeListResponsibleAgencyCode] => 9'
                                        )

                                )

                        )

                )

            [messageTrailer] => Array
                (
                    [segmentIdx] => 5
                    [segmentCode] => UNT
                    [segmentGroup] => SG2
                    [numberOfSegmentsInTheMessage] => 0
                    [messageReferenceNumber] => 1'
                )

        )

)
Array
(
    [0] => Array
        (
            [text] => The message has some additional segments beyond the maximum repetition allowed (skipped)
            [position] => 4
            [segmentId] => NAD
        )

)

@szocsbarni
Copy link
Contributor Author

Can I help you anything with this issue? @sabas

@sabas
Copy link
Collaborator

sabas commented Mar 13, 2024

With the commit dffa093 in the test case you provided it seemed fixed.
Do you replicate it with the same test or with another file? If it's private you can share by email..

@szocsbarni
Copy link
Contributor Author

yes, that commit indeed solves it, my fault, sorry!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants