edifact
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
EDIParser
Given an edi message checks the syntax, outputs errors and returns the message as a multidimensional array.
INPUT
$c = new Parser($x);
Where $x
could be:
- a url
- a string (wrapped message)
- an array of strings (a segment per entry)
OR
$c = new Parser(); $c->load($file); $c->loadString($string);
OUTPUT
Errors
$c->errors();
Array
$c->get();
EDIEncoder
Given a multidimensional array (formatted as the output of the parser), returns an EDI string, optionally one segment per line.
INPUT
$c = new Encoder($x, $wrap = true);
$x
is a multidimensional array where first dimension is the EDI segment, second contains elements:
- single value
- array (representing composite elements)
$wrap
is a boolean, if you need a segment per line. Set to false to disable wrapping
OR
$c = new Encoder(); $c->encode($array, $wrap);
OUTPUT
$c->get(); // returns String
EDIAnalyser
Create from EDI file readable structured text with comments from segments.xml
.
Requires the EDIMapping package.
$parser = new Parser($file); $parsed = $parser->get(); $segments = $parser->getRawSegments(); $analyser = new Analyser(); $mapping = new 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...