Giter Site home page Giter Site logo

edifact's Introduction

edifact

Tools to process EDI messages in UN/EDIFACT format

Supported syntax is version 3.

It's provided in a Composer package:

composer require sabas/edifact

The mapping XML files are provided in a separate package:

composer require php-edifact/edifact-mapping

EDI\Parser

Given an EDI message checks the syntax, outputs errors and returns the message as a multidimensional array.

INPUT

$p = new EDI\Parser();
$p->load($location);     // a local path to a file or a URL (if file_get_contents() allows for remote access)
$p->loadString($string); // a full message (single line text)
$p->loadArray($array);   // an array of strings (one segment per entry)

OUTPUT

Errors

$c->errors();

Array

$c->get();

EDI\Encoder

Given a multidimensional array (formatted as the output of the parser), returns an EDI string, optionally one segment per line.

INPUT

$c = new EDI\Encoder($x, $compact = true);

$x is a multidimensional array where first dimension is the EDI segment, second contains elements:

  • single value
  • array (representing composite elements)

$compact is a boolean, if you need a segment per line. Set to false to enable wrapped lines.

OR

$c = new EDI\Encoder();
$c->encode($array, false);

OUTPUT

$c->get(); // returns String

EDI\Analyser

Create human-readable, structured text with comments from segments.xml. Requires the EDI\Mapping package.

        $parser = new EDI\Parser();
        $parser->load($file);
        $segments = $parser->getRawSegments();
        $parsed = $parser->get();
        $analyser = new EDI\Analyser();
        $mapping = new EDI\MappingProvider('D95B');
        $analyser->loadSegmentsXml($mapping->getSegments());
        $analyser->loadMessageXml($mapping->getMessage('coparn'));
        $analyser->loadCodesXml($mapping->getCodes());
        $analyser->directory = 'D95B';
        $result = $analyser->process($parsed, $segments);                   
  • $file is the path to orginal EDI message file

Example INPUT

UNA:+,? '
UNB+UNOA:1+MAEU+LVRIXBCT+200813:0816+1412605'
UNH+141260500001+COPARN:D:95B:UN'
BGM+12+20200813081626+9'
RFF+BN:204549739'
NAD+CA+MAE:172:20'
EQD+CN++45G1:102:5+2+2+4'
RFF+BN:204549739'
RFF+SQ:7G3JTL39O0M3B'
TMD+++2'
DTM+201:202008130000:203'
LOC+98+LVRIX:139:6+RIGA TERMINAL:TER:ZZZ'
CNT+16:1'
UNT+12+141260500001'
UNZ+1+1412605'

Example Output


UNA:+,? '
UNB - InterchangeHeader
  (To start, identify and specify an interchange)
  [0] UNOA,1
      unb1 - syntaxIdentifier
      Syntax identifier
    [0] UNOA
        id: unb11 - syntaxIdentifier
        Syntax identifier
        type: a
        required: true
        length: 4
    [1] 1
        id: unb12 - syntaxVersionNumber
        Syntax version number
        type: n
        required: true
        length: 1
  [1] MAEU
      unb2 - interchangeSender
      Interchange sender
  [2] LVRIXBCT
      unb3 - interchangeRecipient
      Interchange recipient
  [3] 200813,0816
      unb4 - dateTimePreparation
      Date Time of preparation
    [0] 200813
        id: unb41 - date
        
        type: n
        required: true
        length: 6
    [1] 0816
        id: unb42 - time
        
        type: n
        required: true
        length: 4
  [4] 1412605
      unb5 - interchangeControlReference
      

UNB+UNOA:1+MAEU+LVRIXBCT+200813:0816+1412605'
UNH - messageHeader http://www.unece.org/trade/untdid/d95b/trsd/trsdunh.htm
  (To head, identify and specify a message.)
  [0] 141260500001
      unh1 - messageReferenceNumber
      
  [1] COPARN,D,95B,UN
      unh2 - messageType
      
    [0] COPARN
        id: unh21 - messageType
        
        type: an
        maxlen: 6
        required: true
    [1] D
        id: unh22 - messageVersion
        
        type: an
        maxlen: 3
        required: true
    [2] 95B
        id: unh23 - messageRelease
        
        type: an
        maxlen: 3
        required: true
    [3] UN
        id: unh24 - controllingAgency
        
        type: an
        maxlen: 3
        required: true

UNH+141260500001+COPARN:D:95B:UN'
BGM - beginningOfMessage http://www.unece.org/trade/untdid/d95b/trsd/trsdbgm.htm
  (To indicate the type and function of a message and to transmit the
  identifying number.)
  [0] 12
      C002 - documentmessageName
      Identification of a type of document/message by code or name. Code
      preferred.
  [1] 20200813081626
      1004 - documentmessageNumber
      Reference number assigned to the document/message by the issuer.
  [2] 9
      1225 - messageFunctionCoded
      Code indicating the function of the message.

BGM+12+20200813081626+9'
RFF - reference http://www.unece.org/trade/untdid/d95b/trsd/trsdrff.htm
  (To specify a reference.)
  [0] BN,204549739
      C506 - reference
      Identification of a reference.
    [0] BN - Booking reference number
        id: 1153 - referenceQualifier
        Code giving specific meaning to a reference segment or a reference
        number.
        type: an
        maxlen: 3
        required: true
    [1] 204549739
        id: 1154 - referenceNumber
        Identification number the nature and function of which can be
        qualified by an entry in data element 1153 Reference qualifier.
        type: an
        maxlen: 35

RFF+BN:204549739'
NAD - nameAndAddress http://www.unece.org/trade/untdid/d95b/trsd/trsdnad.htm
  (To specify the name/address and their related function, either by CO82 only
  and/or unstructured by CO58 or structured by CO80 thru 3207. be permitted
  to use the ADR segment and/or the PNA segment.  After the conclusion of the
  Brazil JRT (scheduled for April 1996), this NAD segment shall NO LONGER BE
  PERMITTED FOR USE IN ANY NEW MESSAGES submitted for Status 1 in the
  UN/EDIFACT Directories. This means that either the ADR and/or the PNA
  segments shall be used in place of this NAD segment by the message
  designers. (See Rapporteurs' decision on the proposed ADR & PNA segments
  and the existing NAD segment - Sydney, April 1995).)
  [0] CA
      3035 - partyQualifier
      Code giving specific meaning to a party.
  [1] MAE,172,20
      C082 - partyIdentificationDetails
      Identification of a transaction party by code.
    [0] MAE
        id: 3039 - partyIdIdentification
        Code identifying a party involved in a transaction.
        type: an
        maxlen: 35
        required: true
    [1] 172 - Carrier code
        id: 1131 - codeListQualifier
        Identification of a code list.
        type: an
        maxlen: 3
    [2] 20 - BIC (Bureau International des Containeurs)
        id: 3055 - codeListResponsibleAgencyCoded
        Code identifying the agency responsible for a code list.
        type: an
        maxlen: 3

NAD+CA+MAE:172:20'
EQD - equipmentDetails http://www.unece.org/trade/untdid/d95b/trsd/trsdeqd.htm
  (To identify a unit of equipment.)
  [0] CN
      8053 - equipmentQualifier
      Code identifying type of equipment.
  [1] 
      C237 - equipmentIdentification
      Marks (letters and/or numbers) identifying equipment used for transport
      such as a container.
  [2] 45G1,102,5
      C224 - equipmentSizeAndType
      Code and/or name identifying size and type of equipment used in
      transport. Code preferred.
    [0] 45G1
        id: 8155 - equipmentSizeAndTypeIdentification
        Coded description of the size and type of equipment e.g. unit load
        device.
        type: an
        maxlen: 10
    [1] 102 - Size and type
        id: 1131 - codeListQualifier
        Identification of a code list.
        type: an
        maxlen: 3
    [2] 5 - ISO (International Organization for Standardization)
        id: 3055 - codeListResponsibleAgencyCoded
        Code identifying the agency responsible for a code list.
        type: an
        maxlen: 3
  [3] 2
      8077 - equipmentSupplierCoded
      To indicate the party that is the supplier of the equipment.
  [4] 2
      8249 - equipmentStatusCoded
      Indication of the action related to the equipment.
  [5] 4
      8169 - fullemptyIndicatorCoded
      To indicate the extent to which the equipment is full or empty.

EQD+CN++45G1:102:5+2+2+4'
RFF - reference http://www.unece.org/trade/untdid/d95b/trsd/trsdrff.htm
  (To specify a reference.)
  [0] BN,204549739
      C506 - reference
      Identification of a reference.
    [0] BN - Booking reference number
        id: 1153 - referenceQualifier
        Code giving specific meaning to a reference segment or a reference
        number.
        type: an
        maxlen: 3
        required: true
    [1] 204549739
        id: 1154 - referenceNumber
        Identification number the nature and function of which can be
        qualified by an entry in data element 1153 Reference qualifier.
        type: an
        maxlen: 35

RFF+BN:204549739'
RFF - reference http://www.unece.org/trade/untdid/d95b/trsd/trsdrff.htm
  (To specify a reference.)
  [0] SQ,7G3JTL39O0M3B
      C506 - reference
      Identification of a reference.
    [0] SQ - Container sequence number
        id: 1153 - referenceQualifier
        Code giving specific meaning to a reference segment or a reference
        number.
        type: an
        maxlen: 3
        required: true
    [1] 7G3JTL39O0M3B
        id: 1154 - referenceNumber
        Identification number the nature and function of which can be
        qualified by an entry in data element 1153 Reference qualifier.
        type: an
        maxlen: 35

RFF+SQ:7G3JTL39O0M3B'
TMD - transportMovementDetails http://www.unece.org/trade/untdid/d95b/trsd/trsdtmd.htm
  (To specify transport movement details for a goods item or equipment.)
  [0] 
      C219 - movementType
      Description of type of service for movement of cargo.
  [1] 
      8332 - equipmentPlan
      Description indicating equipment plan, e.g. FCL or LCL.
  [2] 2
      8341 - haulageArrangementsCoded
      Specification of the type of equipment haulage arrangements.

TMD+++2'
DTM - datetimeperiod http://www.unece.org/trade/untdid/d95b/trsd/trsddtm.htm
  (To specify date, and/or time, or period.)
  [0] 201,202008130000,203
      C507 - datetimeperiod
      Date and/or time, or period relevant to the specified date/time/period
      type.
    [0] 201 - Pick-up date/time of equipment
        id: 2005 - datetimeperiodQualifier
        Code giving specific meaning to a date, time or period.
        type: an
        maxlen: 3
        required: true
    [1] 202008130000
        id: 2380 - datetimeperiod
        The value of a date, a date and time, a time or of a period in a
        specified representation.
        type: an
        maxlen: 35
    [2] 203 - CCYYMMDDHHMM
        id: 2379 - datetimeperiodFormatQualifier
        Specification of the representation of a date, a date and time or of
        a period.
        type: an
        maxlen: 3

DTM+201:202008130000:203'
LOC - placelocationIdentification http://www.unece.org/trade/untdid/d95b/trsd/trsdloc.htm
  (To identify a country/place/location/related location one/related location
  two.)
  [0] 98
      3227 - placelocationQualifier
      Code identifying the function of a location.
  [1] LVRIX,139,6
      C517 - locationIdentification
      Identification of a location by code or name.
    [0] LVRIX
        id: 3225 - placelocationIdentification
        Identification of the name of place/location, other than 3164 City
        name.
        type: an
        maxlen: 25
    [1] 139 - Port
        id: 1131 - codeListQualifier
        Identification of a code list.
        type: an
        maxlen: 3
    [2] 6 - UN/ECE (United Nations - Economic Commission for Europe)
        id: 3055 - codeListResponsibleAgencyCoded
        Code identifying the agency responsible for a code list.
        type: an
        maxlen: 3
  [2] RIGA TERMINAL,TER,ZZZ
      C519 - relatedLocationOneIdentification
      Identification the first related location by code or name.
    [0] RIGA TERMINAL
        id: 3223 - relatedPlacelocationOneIdentification
        Specification of the first related place/location by code.
        type: an
        maxlen: 25
    [1] TER
        id: 1131 - codeListQualifier
        Identification of a code list.
        type: an
        maxlen: 3
    [2] ZZZ - Mutually defined
        id: 3055 - codeListResponsibleAgencyCoded
        Code identifying the agency responsible for a code list.
        type: an
        maxlen: 3

LOC+98+LVRIX:139:6+RIGA TERMINAL:TER:ZZZ'
CNT - controlTotal http://www.unece.org/trade/untdid/d95b/trsd/trsdcnt.htm
  (To provide control total.)
  [0] 16,1
      C270 - control
      Control total for checking integrity of a message or part of a message.
    [0] 16 - Total number of equipment
        id: 6069 - controlQualifier
        Determines the source data elements in the message which forms the
        basis for 6066 Control value.
        type: an
        maxlen: 3
        required: true
    [1] 1
        id: 6066 - controlValue
        Value obtained from summing the values specified by the Control
        Qualifier throughout the message (Hash total).
        type: n
        maxlen: 18
        required: true

CNT+16:1'
UNT - MessageTrailer http://www.unece.org/trade/untdid/d95b/trsd/trsdunt.htm
  (MessageTrailer)
  [0] 12
      9900 - segmentsNumber
      segmentsNumber
  [1] 141260500001
      9901 - msgRefNumber
      msgRefNumber

UNT+12+141260500001'
UNZ - InterchangeTrailer http://www.unece.org/trade/untdid/d95b/trsd/trsdunz.htm
  (InterchangeTrailer)
  [0] 1
      9902 - interchangeControlCount
      interchangeControlCount
  [1] 1412605
      9903 - interchangeControlRef
      interchangeControlRef

EDI\Reader

Read specific segment element values from parsed EDI file. Pass the reader a parser with a message already loaded.

INPUT

$p = new EDI\Parser();
$p->load($x);
$r = new EDI\Reader($p);
$sender = $r->readEdiDataValue('UNB', 2);
$Dt = $r->readUNBDateTimeOfPreperation();

See section about EDI\Parser above on how to load a file into a parser.

OUTPUT

Errors

$r->errors();

Array

$r->getParsedFile();

EDI\Interpreter

Organizes the data parsed by EDI/Parser using the XML description of the message and the XML segments.

INPUT

$p = new EDI\Parser();
$p->load($edifile);
$edi = $p->get();

$mapping = new EDI\Mapping\MappingProvider('D95B');

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

$interpreter = new EDI\Interpreter($mapping->getMessage('CODECO'), $segs, $svc);
$prep = $interpreter->prepare($edi);

OUTPUT

JSON

$interpreter->getJson()

JSON for interchange service segments (UNB / UNZ)

$interpreter->getJsonServiceSegments()

Errors (per message)

$interpreter->getErrors()

Example

Edifact

DTM+7:201309200717:203'

Array

['DTM',['7','201309200717','203']]

Testing

The package should be required with composer, alongside edifact-mapping. The tests then can be run simply with phpunit in the root of the package.

Notes

Valid characters are: A-Za-z0-9.,-()/'+:=?!"%&*;<> UNECE

edifact's People

Contributors

emilv avatar gaxweb avatar groberts84 avatar homer8173 avatar jbrooksuk avatar killerkent avatar lazytyper avatar michaelachrisco avatar mtdavidson avatar puggan avatar repat avatar sabas avatar sahat81 avatar sebastien-vitry avatar sunmar avatar swiffer avatar szocsbarni avatar tophsic avatar uldisn avatar voku avatar wendelin avatar xiro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

edifact's Issues

Analyser breaks on EDI file with no newlines

I have an EDI file without line breaks which breaks the Analyser on line 178. Newlines are optional and Wikipedia even states that:

Note: The line breaks after each segment in this example have been added for readability. There are typically no line breaks in EDI data.

This is not caught by the unit tests since example.edi does indeed contain line breaks.

I understand that the purpose is to show only the current segment in raw format before each explanation. Just putting line 178 inside an if statement would solve the problem but also remove that feature. I'm not really sure what the best course of action would be here. Perhaps making loadEdiMessage split on the segment separator instead of linebreaks? But that would also mean we have to actually parse parts of the message inside the Analyser.

Perhaps some refactoring is in order:

  • Remove Analyser::loadEdiMessage
  • Add functionality to read raw segment from Parser

This would also remove the need to load the file twice for analysis since the Parser already have it.

What do you think?

Adding package via composer returns: "Could not find package in any version"

If I try to add the project via the composer by executing composer require sabas/edifact I get the following error:

[InvalidArgumentException]
Could not find package sabas/edifact at any version for your minimum-stability (stable). Check the package spelling or your minimum stability

Even if I add --dev the composer won't add the package. This error usually occurs if you don't tag your commits with a version name before pushing them. The only way to get the package at the moment is:

  "require": {
    "sabas/edifact": "*@dev"
  },

The tags don't need to be stable, but the composer needs tags in order to pull the package and won't look for the version you defined in composer.json

EDI Reader

What is preferred method for reading multiple segments, for example if I want to get an array of all LIN segments? Should I write my own script for finding needed segments or it is done with EDI Reader?

Thanks!

[question] INOVERT standard

Hi,

I am a total newbie in EDI. As you noticed, I am interested in a PHP library to manipulate UN/EDIFACT messages. To be precise, I have to manage INOVERT messages (http://www.gtff.org/?langue=en, SCONTR and REPORT).

I think the main component I need in php-edifact/edifact firstly is EDI\Interpreter and if I understood well, I have to write messages specification as in php-edifact/edifact-mapping. Am I right?

Thanks for your advice.

Question about PRICAT

Sorry to raise an issue on this. I know it is not the way.

I have a set of messages in fashion PRICAT, ORDERS, DESADV, ORDRSP etc that I would like to process and parse. Can this also be done with this standard?

For instance, can I process PRICAT messages?
https://www.gs1.org/edi-xml-gs1-eancom/eancom-pricat-s4/syntax-4

If so: how would I read in the data (from file)

thanks - see this as a jump starter to get us started ;P

great that this exists!

Recovering MOA Segments

Hi,
I want to recover the MOA segments from a file.
In my file, the MOA segments look like this:
MOA+23:99.99'
and
MOA+125:999.99'
I want to retrieve the value by passing parameter 23 or 125.
Someone can help me ?

Thanks a lot !
arnaud

question marks are not parsed correctly

Hi,

Question marks should be added as ?? because it's an escape character.

In this example the question marks escape the ' and this should not happen:

ATT+1400+??????'
XRH+3'
$c = new \EDI\Parser();
$c->setStripRegex('//');
$c->loadString($edistring);
$message       = $c->get();

$message contains this:

[99] => Array
        (
            [0] => ATT
            [1] => 1400
            [2] => ???'XRH
            [3] => 3
        )

As you can see the question marks are correctly parsed into ??? but the ' is still escaped and this is not correct.

Any idea how this could be fixed ?

[Parser] Regex for finding the encoding matches too much

See Parser line 191:
`$this->analyseUNB(preg_replace("#^UNB#", "", substr($string, 0, 8)));

This line leads to having an invalid parameter in analyseUNB. e.g. UNB+UNOC:3+.... leads to analyseUNB('+UNOC') which doesn't work out.
The regex should consider the +.

EDI Translation for error reporting

Greetings!

Does EDI Analyser somehow can be used to identify errors (for example when some of the elements are too long, missing mandatory segment etc.)?
Or it renders only description about each segment and data element?

File parses in 0.0.6 but fails to parse with no error in dev-master

Hi

We've received an example EDI file from a supplier we are working with and I was just trying out the library to see if it would work.

I've found that in 0.0.6 it seems to work fine

Doing

use EDI\Parser;
$fn="storage/sampleDESADV2.INT";
$p=new EDI\Parser($fn);
echo json_encode($p->get());

results in

[["UNH","1",["DESADV","0","96A","UN"]],["BGM","351","FOM0000123","9"],["DTM",["11","20140313","102"]],["RFF",["ON","MULTI"]],["NAD","SU",["1556150UK","","31B"]],["NAD","BY",["8888888 01UK","","31B"]],["CPS","1"],["LIN","1"],["PIA","5",["9780071744225","EN"]],["QTY",["12","1"]],["RFF",["ON","0000000004000"]],["RFF",["LI","248127"]],["LIN","2"],["PIA","5",["9780091954925","EN"]],["QTY",["12","1"]],["RFF",["ON","0000000004003"]],["RFF",["LI","248230"]],["LIN","3"],["PIA","5",["9780099429760","EN"]],["QTY",["12","1"]],["RFF",["ON","0000000004007"]],["RFF",["LI","248408"]],["LIN","4"],["PIA","5",["9780099441441","EN"]],["QTY",["12","1"]],["RFF",["ON","0000000004007"]],["RFF",["LI","248409"]],["LIN","5"],["PIA","5",["9780099585336","EN"]],["QTY",["12","1"]],["RFF",["ON","0000000004006"]],["RFF",["LI","248349"]],["LIN","6"],["PIA","5",["9780099585336","EN"]],["QTY",["12","1"]],["RFF",["ON","0000000004009"]],["RFF",["LI","248512"]],["LIN","7"],["PIA","5",["9780141186917","EN"]],["QTY",["12","1"]],["RFF",["ON","0000000003990"]],["RFF",["LI","247741"]],["LIN","8"],["PIA","5",["9780143122791","EN"]],["QTY",["12","1"]],["RFF",["ON","0000000003992"]],["RFF",["LI","247874"]],["LIN","9"],["PIA","5",["9780749910549","EN"]],["QTY",["12","1"]],["RFF",["ON","0000000003987"]],["RFF",["LI","247485"]],["LIN","10"],["PIA","5",["9780749910549","EN"]],["QTY",["12","1"]],["RFF",["ON","0000000003988"]],["RFF",["LI","247628"]],["LIN","11"],["PIA","5",["9780749941659","EN"]],["QTY",["12","1"]],["RFF",["ON","0000000003991"]],["RFF",["LI","247751"]],["LIN","12"],["PIA","5",["9780753540329","EN"]],["QTY",["12","1"]],["RFF",["ON","0000000004005"]],["RFF",["LI","248306"]],["LIN","13"],["PIA","5",["9781408248737","EN"]],["QTY",["12","1"]],["RFF",["ON","0000000003985"]],["RFF",["LI","247354"]],["LIN","14"],["PIA","5",["9781591846284","EN"]],["QTY",["12","1"]],["RFF",["ON","0000000003998"]],["RFF",["LI","248030"]],["LIN","15"],["PIA","5",["9781742373386","EN"]],["QTY",["12","1"]],["RFF",["ON","0000000003999"]],["RFF",["LI","248060"]],["CNT",["2","15"]],["UNT","85","1"],["UNE","1","000000312"],["UNZ","1","000000312"]]

however doing the same with the dev-master branch I just see

[]

I've checked the errors and that also shows

[]

I'd question the file but since it worked in the previous version I'm wondering if something that has changed and the file format is no longer parsing correctly?

The sample file I have is https://gist.github.com/mtdavidson/9223b0d083ee4c8e789c420a844a61f6

Any help would be appreciated I'm quite happy to pick through the library try figure out whats going on but I thought I'd better ask first incase someone more experienced with the EDI format might be able to shed some light.

Thanks

Mark

¿How to properly run edifact app?

I'm really new on phpunit and i'm trying to run the app but no success. I'm really interested on read edifact file. Can someone explain a little bit more how to run the app?

Regards

Does IFTMIN:S:93A supported?

Hi,
I need to parse/work with this kind of message, but it seems it is missing from mappings.
Unfortunately as I read a file with this kind of message, I got nothing (empty output).
Until the file has unprintable chars (Danish like), I got non printable error messages as some other user, but after I load the file via utf8_decoder, I got just nothing.

The file has some issues though, like a message has missing UTZ and total numbers of messages are less by 2 pieces than expected in the UNZ.
Does these issues cause the complete file will be ignored?

Thanks.

Notice (8): Undefined index: name

Reading D06A INVOIC messages shows multiple Notices for undefined indexes:

in edifact 0.2.1:

Notice (8): Undefined index: name [ROOT/vendor/sabas/edifact/src/EDI/Interpreter.php, line 265]

in edifact 0.3.0/dev-master:

Notice (8): Undefined index: name [ROOT/vendor/sabas/edifact/src/EDI/Interpreter.php, line 305]
Notice (8): Undefined index: name [ROOT/vendor/sabas/edifact/src/EDI/Interpreter.php, line 304]
Notice (8): Undefined index: name [ROOT/vendor/sabas/edifact/src/EDI/Interpreter.php, line 307]

Mapping

Why deleted src\EDI\Mapping\d95b\segments.xml?
In this file is full segment element definition.
Analyzer don`t work with other segments.xml.

Validate EDI against mapping

Hello,

I am trying to validate an EDI message parsed with EDI\Encoder, get a list of validation errors, is that possible?
I am not sure are the Analyser or Interpreter used for. I thought that the Analyser was for that, but it seems it's not.

I tried calling all the methods but I am blank.

Thank you for the help and the library

Swedish characters utf8 issue

Hi

I'm in need of parsing EDI files and I found your library after a quick google search. However, my EDI files contain swedish characters, which don't seem to survive parsing properly. So for example Ä is turned into .

I double checked and my EDI files are using UTF-8, as is the small PHP script file I am using to test this. I've also set the meta charset of the output html to UTF-8, so the issue doesn't appear to be there.

I also saw this #20 (comment) but I'm unsure how to use this.

Thank you for any help.

Tests not passing

Looks like 94659e1
breaks the Parser Test:

    public function testNotTerminatedSegment()
    {

        $arr= ["LOC+9+VNSGN","LOC+11+ITGOA'"];
        $error="Segment not ended correctly at line 1=>LOC+9+VNSGN";
        $p=new Parser($arr);
        $result=$p->errors();
        $this->assertContains($error, $result);
    }

Interpreter Group Nesting Depth Issue

Hi All,

I'm working with a DESADV message conforming to the D96A standard ( https://www.stylusstudio.com/edifact/D96A/DESADV.htm ) and am trying to use the interpreter to parse this. For the most part it seems to be fine but it was complaining about a missing UNT segment which was in the file. After looking into it in more detail it seems that its giving up parsing the file after a certain point.

This seems to occur when trying to parse SG16 ( https://www.stylusstudio.com/edifact/D96A/DESADV.htm#part4.3.1 ) I believe this is due to the Interpreter only supporting grouping up to two levels and on the third level it's not parsing it right. Looking at the code this seems to confirm my theory ( https://github.com/sabas/edifact/blob/master/src/EDI/Interpreter.php#L128).

Is this the correct diagnosis or am I missing something? If I'm right would there be any drawbacks to rewriting this in a recursive way so that it can support an infinite level of depth in grouping?

Many Thanks

Mark

Tests suite is broken

Hi,

I wanted to give a try to php-edifact/editfact to use it in a future project for a client. Before I code anything to test the library, I tried to run the tests suite. I ran into two problems:

  • I got the following warning which is not blocking
Warning: include_once(/path/to/php-edifact/edifact/tests/../../../autoload.php): failed to open stream: No such file or directory in /home/mapstime/tests/Bootstrap.php on line 2
  • I got the following error which impact AnalyserTest and InterpreterTest
Fatal error: Uncaught Error: Class EDIMappingMappingProvider not found in /path/to/php-edifact/edifact/tests/EDITest/AnalyserTest.php:25
Stack trace:
#0 /path/to/php-edifact/edifact/vendor/phpunit/phpunit/src/Framework/TestCase.php(822): EDITest\AnalyserTest->setUp()
#1 /path/to/php-edifact/edifact/vendor/phpunit/phpunit/src/Framework/TestResult.php(686): PHPUnit_Framework_TestCase->runBare()
#2 /path/to/php-edifact/edifact/vendor/phpunit/phpunit/src/Framework/TestCase.php(760): PHPUnit_Framework_TestResult->run(Object(EDITest\AnalyserTest))
#3 /path/to/php-edifact/edifact/vendor/phpunit/phpunit/src/Framework/TestSuite.php(699): PHPUnit_Framework_TestCase->run(Object(PHPUnit_Framework_TestResult))
#4 /path/to/php-edifact/edifact/vendor/phpunit/phpunit/src/Framework/TestSuite.php(699): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))
#5 /path/to/php-edifact/edifact/vendor/phpunit/phpunit/src/TextUI/TestRunner.php(426): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))
#6 /path/to/php-edifact/edifact/vendor/phpunit/phpunit/src/TextUI/Command.php(179): PHPUnit_TextUI_TestRunner->doRun(Obj in /path/to/php-edifact/edifact/tests/EDITest/AnalyserTest.php on line 25

Other tests passed.

For information, I just ran composer install and vendobr/bin/phpunit into a docker container (based on composer official image) to have a minimal PHP environment (PHP 7.0).

Display JSON Data attribute label

Is there a way to display the data in JSON format, but include the attribute label?

Instead of just this:
[["UNB",["UNOA","2"],"OOCLIES","LBCTI",["160401","1523"],"13","","","","",""]

Something like this for example:
{"SyntaxIdentifier":"UNOA","SyntaxVersionNumber":2,"SenderIdentification":"OOCLIES","RecipientIdentification":"LBCTI","DateOfPreparation":"160401",

(How to) iterate correctly over Segment Group Items

May rather be a question than a real issue.
I have a MSCONS D04B Message (some files with multiple UNH-Messages, if relevant).
I want to process the SG10 QTY segments.
So I tried

$this->ediParser->load($ediFile);
$ediData = $this->ediParser->get();
$this->ediReader->setParsedFile($ediData);    
$this->mappingProvider = new \EDI\Mapping\MappingProvider($ediMessageVersion);
$segments = $this->ediAnalyser->loadSegmentsXml($this->mappingProvider->getSegments());
$serviceSegments = $this->ediAnalyser->loadSegmentsXml($this->mappingProvider->getServiceSegments(3));
$this->ediInterpreter = new \EDI\Interpreter($this->mappingProvider->getMessage($ediMessageType), $segments, $serviceSegments);
$preparedInterpreter = $this->ediInterpreter->prepare($ediData);

http://www.stylusstudio.com/edifact/d04b/MSCONS.htm#part4.3.1

This way I get a nice array in $preparedInterpreter, where I can navigate to SG9. There I would expect to find the QTY Segments.
But there is only one, whereas the file contains 960.

SG9 => array(1 item)
                     0 => array(4 items)
                        lineItem => array(3 items)
                        additionalProductId => array(4 items)
                        quantity => array(3 items)
                           segmentIdx => 13 (integer)
                           segmentCode => 'QTY' (3 chars)
                           quantityDetails => array(2 items)
                              quantityTypeCodeQualifier => '220' (3 chars)
                              quantity => '3.484' (5 chars)
                        date/time/period => array(2 items)
                           0 => array(3 items)
                              segmentIdx => 14 (integer)
                              segmentCode => 'DTM' (3 chars)
                              date => array(3 items)
                           1 => array(3 items)
                              segmentIdx => 15 (integer)
                              segmentCode => 'DTM' (3 chars)
                              date => array(3 items)

What am I missing/doing wrong?

Otherwise I could loop like this:

foreach($this->ediInterpreter->getMessages() as $message) {
   foreach($message as $segmentIndex => $segment) {
      if($segmentName == 'XXX') {
         // do some stuff
      }
   }
}

But I am unsure if this is the intended way with this library. In the Examples I could not find anything suitable.

Thanks for your hints.

Errors after $parser->load($file);

Please take this as a suggestion / question more than an issue.
I expect this usage is legit:

// may be very heavy object
$parser = new \EDI\Parser();

// load file 1/150
$parser->load($file);
$parser->errors();

// load file 2/150
$parser->load($file);
$parser->errors();

But the errors get appended, load() doesn't clear the collection. I am not saying it should be exactly like this, but i think this way of usage is not so good:

foreach ($files as $file) {
    // gets created every time
    $parser = new \EDI\Parser();            
    $parser->load($file);
    $parser->errors();          
}

Thank you for your thoughts..
Josef

EXAMPLES.md semi column is missing

Hi

in EXAMPLES.md on section EDI data element reading

$record = array(
'interchangeSender' => $reader->readEdiDataValue('UNB',2),
'arrivalDateTimeEstimated' => $reader->$EdiReader->readEdiSegmentDTM('132'),
'messageReferenceNumber' => $reader->readEdiDataValue('UNH',1),
'TareWeight' => $reader->readEdiDataValue(['MEA',['2'=>'T']],3,0)
. ' '
. $reader->readEdiDataValue(['MEA',['2'=>'T']],3,1),
'GrossWeight' => $reader->readEdiDataValue(['MEA',['2'=>'G']],3,0)
. ' '
. $reader->readEdiDataValue(['MEA',['2'=>'G']],3,1),
);

the last semi column is missing

regards i thanks for your project

christophe

Encoder double escapes values

In the function "EDI/Encoder->escapeValue" the replace order leads to data separators being replaced before any escape characters.

UNA:+.?*'
"my+value" encodes to "my??+value"

Could someone please change that so escape characters are escaped first before the other characters?

Reading and Creating 810/880 Invoice Messages

I'm trying to understand how the EDI process would work for me to be able to read and also create 810 Invoice Messages, but I'm struggling.

Are there more comprehensive documentation links that I'm missing somewhere to be able to look at?

[Interpreter] Should a segment array appear as an array of arrays with one repetition?

https://github.com/php-edifact/edifact/blob/master/src/EDI/Interpreter.php#L177

If a segment repeats only one time it appears directly as a value of the measurements key. If it repeats twice or more measurements has as value an array of two or more arrays.

        array(5) {
          ["segmentIdx"]=>
          int(11)
          ["segmentCode"]=>
          string(3) "MEA"
          ["measurementApplicationQualifier"]=>
          string(3) "VGM"
          ["measurementDetails"]=>
          string(0) ""
          ["valuerange"]=>
          array(2) {
            ["measureUnitQualifier"]=>
            array(1) {
              [0]=>
              string(3) "KGM"
            }
            ["measurementValue"]=>
            array(1) {
              [1]=>
              string(4) "5951"
            }
          }
        }

readEdiSegmentDTM for SG12

Can i use readEdiSegmentDTM for DTM segements inside SG12 (Inventory movements) ?

Or have i extract the group and go deeper into the array?

JSON looks like:

"SG12": [
          {
            "inventoryManagementRelatedDetails": {
              "segmentIdx": 10,
              "segmentCode": "INV",
              "inventoryMovementDirectionCode": "",
              "inventoryTypeCode": "",
              "inventoryMovementReasonCode": ""
            },
            "quantity": [
              {
                "segmentIdx": 11,
                "segmentCode": "QTY",
                "quantityDetails": {
                  "quantityTypeCodeQualifier": "",
                  "quantity": "",
                  "measurementUnitCode": ""
                }
              },
              {
                "segmentIdx": 12,
                "segmentCode": "QTY",
                "quantityDetails": {
                  "quantityTypeCodeQualifier": "",
                  "quantity": "",
                  "measurementUnitCode": ""
                }
              }
            ],
            "place\/locationIdentification": {
              "segmentIdx": 13,
              "segmentCode": "LOC",
              "locationFunctionCodeQualifier": "",
              "locationIdentification": {
                "locationIdentifier": "",
                "codeListIdentificationCode": "",
                "codeListResponsibleAgencyCode": "",
                "locationName": ""
              }
            },
            "date\/time\/period": {
              "segmentIdx": 14,
              "segmentCode": "DTM",
              "date": {
                "dateOrTimeOrPeriodFunctionCodeQualifier": "179",
                "dateOrTimeOrPeriodText": "20180509",
                "dateOrTimeOrPeriodFormatCode": "102"
              }
            },

THX very much!!

UTF8 characters handling in input edi file

I have an edi file with UTF8 characters, like éáűúőí, even these kind of chars: ØÆ
When I load the into the parser, I got error messages (non-printable chars...) and the error message contains the utf8 encoded character, like: \u00c6 (Æ)

My problem, when I print out (echo) json_encode or var_dump, these characters are missing.

Do I miss something? I read #64 but it seems I have no correct chars in var_dump, for example á simply missing.

Could you help me, how to keep the original characters during the Parsing process?

Relevant code:

$edifile = utf8_decode(file_get_contents("example.edi")); //it's a path!
// $edifile = file_get_contents("example.edi"); //it's a path!
// $p = new EDI\Parser($edifile);
$p = new EDI\Parser();
// $p->setStripRegex("//");
$p->loadString($edifile);

if (count($p->errors()) > 0) {
        echo "Error: ";
        echo json_encode($p->errors());
        // return;
}

echo "JSON:";
echo json_encode($p->get());

How to implement service_codes_v3.xml?

For a project I need to implement the service_codes_v3.xml in Analyser.php, because the lack of these codes results in errors. Is there a way to implement this?

Best regards

Andreas

How to avoid Out of memory

I'm trying to parse a 30MB large (one line) Pricat file.
I just took one of the examples, and went from there. But PHP is running very fast out of memory, any clue how to parse the file in "smaller" chunks without splitting it by hand?

`<?php
ini_set('memory_limit', '2048M');
ini_set('max_execution_time', 3000);
header('Content-Type: text/html; charset=utf-8');

require 'vendor/autoload.php';
use EDI\Parser;
$file='bn_new.96a';

$c = new Parser();
$c->load($file);
echo $c->errors();
echo "
";
echo $c->get();

?>`

This is my code thus "far". Any help is appreciated.

Parser seems to be slow

I think your parser is slow.
It's maybe besser to use the explode() function than regexp's. Or are those regexp's necessary?

Which mapping file to use?

More of a question than an issue - sorry!

I am trying to parse some 271 Health Care Eligibility Benefit Response files, but I am not sure which mapping file I should be using from the edifact-mapping package. I am NOT an EDI expert by any stretch of the imagination. Just trying to get this data into JSON format so I can work with it. Any guidance or advice would be greatly appreciated!

Difficulties with Reader->readGroups()

Hi guys, I've got an INVOIC segmented like this :

  1. UNB before_search
  2. UNH before_search
  3. BGM before_search
  4. DTM before_search
  5. DTM before_search
  6. FTX before_search
  7. NAD before_search
  8. RFF before_search
  9. RFF before_search
  10. NAD before_search
  11. RFF before_search
  12. RFF before_search
  13. RFF before_search
  14. NAD before_search
  15. NAD before_search
  16. CUX before_search
  17. PAT before_search
  18. DTM before_search
  19. PAT before_search
  20. PCD before_search
  21. PAT before_search
  22. PCD before_search
  23. LIN before_search
  24. IMD before_search
  25. QTY before_search
  26. MOA before_search
  27. PRI before_search
  28. PRI before_search
  29. TAX before_search
  30. LIN before_search
  31. IMD before_search
  32. QTY before_search
  33. MOA before_search
  34. PRI before_search
  35. PRI before_search
  36. TAX before_search
  37. ALC before_search
  38. MOA before_search
  39. UNS before_search
  40. MOA before_search
  41. MOA before_search
  42. MOA before_search
  43. TAX before_search
  44. MOA before_search
  45. TAX before_search
  46. MOA before_search
  47. UNT before_search
  48. UNZ before_search

I'm trying to read the products details starting at LIN segments that have various length depending on discount or not.

How do you setup this function to collect the product groups in this case ? is there an other way to do it ?

thanks for your help; regards

Move the packages to an org

I'm thinking of moving edifact + edifact-data to the org PHPEdifact.

I'd modify Packagist to point to the new url, but the other things would be handled by Github.

Interpreter Unrecognised Type for UNH

I've noticed that when using the Interpreter in the JSON result I'm seeing

"UnrecognisedType":["UNH","142",["DESADV","0","96A","UN"]]

for the message header.

It seems that this should perhaps be passed with the services segments instead of as regular segments but this becomes tricky if you're dealing with a multi-message file.

It seems that the specification for the UNH segment used to be in some files in particular D95B segments ( php-edifact/edifact-data@8b0623d#diff-c62143c05b98d29cea5c222856db8f83 ) which has been removed but not on the version that is currently the submodule for this project.

What do people think? The simple fix would be to add UNT, UNH and UCM into the segments.xml for each standard but that seems hacky.

Encoding problem / misunderstanding

Hello,

First of all, thanks a lot for your hard work. It's great.

I'm having a problem parsing an EDI file. It's encoded as Windows-1252 and UNB is set to UNOC.

Processed by the following code, json_encode returns false.

$p = new Parser($fn);
if (count($p->errors()) > 0) {
    echo json_encode($p->errors());
    return;
}
var_dump(json_encode($p->get()));

If I convert (using mb_convert_encoding from Windows-1252 to UTF-8), it works.
But UNOC is supposed to be ISO-8859-1 if I'm not mistaken???

Could you help me solve this problem or misunderstanding please?

Thanks in advance.

Describe validation regex for standard character sets

https://www.stylusstudio.com/edifact/40003/0001.htm

For EDIFACT documents of syntax version UNOA, characters A-Z, 0-9, blank and . , ( ) / - = are allowed. For syntax version UNOB, characters a-z, A-Z, 0-9, blank and . , ( ) / - = : + ` ? are allowed. All other EDIFACT syntaxes are linked to the standard ISO character sets. [https://msdn.microsoft.com/en-us/library/aa559562(v=bts.20).aspx]

UNOB can use these separators: The Information Separator control characters are used as follows. IS 4 hex value '1C' segment terminator IS 3 hex value '1D' data element separator IS 1 hex value '1F' component data element separator

UNOC to UNOK use ISO-8859-*

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.