public function readEdiData($edi_id)
 {
     echo '$edi_id=' . $edi_id . PHP_EOL;
     $error = array();
     $edifact = Edifact::model()->FindByPk($edi_id);
     $parser = new EDI\Parser();
     $f = explode(PHP_EOL, $edifact->message);
     $parser->parse($f);
     $EdiReader = new ContainerReader($f);
     $dateTimePreparation = $EdiReader->readDateTimePreparation();
     $terminal = $EdiReader->readEdiDataValue('UNB', 2);
     $MessageType = $EdiReader->readUNHmessageType();
     $MessageCode = $EdiReader->readEdiDataValue('BGM', 1);
     if ($terminal == 'RIXBCT' || $terminal == 'LVRIXKRA') {
         if ($MessageType == 'COARRI') {
             //TDT        8067 Mode of transport, coded: codes
             //                '1' maritime transport
             //                '8' inland water transport
             $ModeOfTransport = $EdiReader->readEdiDataValue(['TDT', [1 => 20]], 3, 1);
             $container_count = $EdiReader->readEdiDataValue('CNT', 1, 1);
             if ($container_count == 1) {
                 $containers = [$EdiReader->getParsedFile()];
             } else {
                 $containers = $EdiReader->readGroups('NAD', 'EQD', 'NAD', 'CNT');
             }
             if ($container_count != count($containers)) {
                 $error[] = 'Mismatch contaier count. CNT=' . $container_count . ' groups=' . count($containers);
                 EcntContainer::saveEdiData(array(), $EdiReader, $error, $edifact);
                 return false;
             }
             foreach ($containers as $container) {
                 $error = [];
                 $ecnt_data = [];
                 $EdiReader->resetErrors();
                 //PARTY QUALIFIER
                 //CA Carrier
                 //(3126) Party undertaking or arranging transport of goods between named points.
                 $ecnt_data['ecnt_fwd'] = $EdiReader->readEdiDataValue(['NAD', ['1' => 'CA']], 2, 0);
                 //8051 TRANSPORT STAGE QUALIFIER:
                 //  '20' (main carriage)
                 // Read: 8028 CONVEYANCE REFERENCE NUMBER: the vessel operator's loading voyage number
                 $ecnt_data['ecnt_transport_id'] = $EdiReader->readEdiDataValue(['TDT', ['1' => 20]], 2);
                 //var_dump($container);
                 $ConEdiReader = new ContainerReader();
                 $ConEdiReader->setParsedFile($container);
                 $container_number = $ConEdiReader->readEdiDataValue('EQD', 2);
                 $ecnt_data['ecnt_edifact_id'] = $edifact->id;
                 $ecnt_data['ecnt_container_nr'] = $container_number;
                 $ecnt_data['ecnt_terminal'] = $terminal;
                 $ecnt_data['ecnt_message_type'] = $MessageType;
                 $ecnt_data['ecnt_iso_type'] = $ConEdiReader->readEdiDataValue('EQD', 3, 0);
                 //2005 Date/time/period qualifier: code
                 //‘203' Execution date
                 $ecnt_data['ecnt_datetime'] = $ConEdiReader->readEdiSegmentDTM(203);
                 //$LoadingLocationIdentification = $EdiReader->readEdiDataValue(['LOC',[1=>9]],2,0);
                 //$DischargingLocationIdentification = $ConEdiReader->readEdiDataValue(['LOC',[1=>11]],2,0);
                 if ($MessageCode == 270) {
                     $ecnt_data['ecnt_operation'] = EcntContainer::ECNT_OPERATION_VESSEL_LOAD;
                     $ecnt_data['ecnt_ib_carrier'] = 'TRUCK';
                 } elseif ($MessageCode == 98) {
                     $ecnt_data['ecnt_operation'] = EcntContainer::ECNT_OPERATION_VESSEL_DISCHARGE;
                     $ecnt_data['ecnt_ob_carrier'] = 'TRUCK';
                 } else {
                     $error[] = 'Neatrada operation - vessel load/unload!' . '/Loading:' . $LoadingLocationIdentification . '/Discharging:' . $DischargingLocationIdentification . '/MessageCode:' . $MessageCode;
                 }
                 $ecnt_data['ecnt_weight'] = $ConEdiReader->readEdiDataValue(['MEA', ['2' => 'G']], 3, 1);
                 $ecnt_data['ecnt_booking'] = $ConEdiReader->readEdiDataValue(['RFF', ['1.0' => 'BN']], 1, 1);
                 $ecnt_data['ecnt_statuss'] = $ConEdiReader->readFullEmpty();
                 EcntContainer::saveEdiData($ecnt_data, $EdiReader, $error, $edifact);
             }
             return;
         } elseif ($MessageType == 'CODECO') {
             //get count of containers
             $container_count = $EdiReader->readEdiDataValue('CNT', 1, 1);
             //get container group detais
             if ($container_count == 1) {
                 $containers = [$EdiReader->getParsedFile()];
             } else {
                 $containers = $EdiReader->readGroups('NAD', 'EQD', 'TDT', 'CNT');
             }
             if ($container_count != count($containers)) {
                 $error[] = 'Mismatch contaier count. CNT=' . $container_count . ' groups=' . count($containers);
                 EcntContainer::saveEdiData(array(), $EdiReader, $error, $edifact);
                 return false;
             }
             //LOC Place of loading
             // 9 - [3334] Seaport, airport, freight terminal,
             //              rail station or other place at which the goods (cargo)
             //              are loaded on to the means of transport being used for their carriage.
             //    TRUCK IN
             //11 - Place of discharge
             //      [3392] Seaport, airport, freight terminal, rail station or other
             //      place at which goods are unloaded from the means of transport
             //      having been used for their carriage.
             // TRUCK OUT
             $LocationFunctionPlaceLoading = $EdiReader->readEdiDataValue(['LOC', [1 => 9]], 2);
             $LocationFunctionPlaceDischarge = $EdiReader->readEdiDataValue(['LOC', [1 => 11]], 2);
             $LocationFunctionKS = $EdiReader->readEdiDataValue(['LOC', [1 => 165]], 2);
             if (!empty($LocationFunctionPlaceLoading)) {
                 $ecnt_operation = EcntContainer::ECNT_OPERATION_TRUCK_IN;
             } elseif (!empty($LocationFunctionPlaceDischarge)) {
                 $ecnt_operation = EcntContainer::ECNT_OPERATION_TRUCK_OUT;
             } elseif (!empty($LocationFunctionKS)) {
                 $ecnt_operation = EcntContainer::ECNT_OPERATION_TRUCK_OUT;
             } else {
                 $error[] = 'Neatrada operation - truck in/out';
             }
             //PARTY QUALIFIER
             //CF Container operator/lessee
             // Party to whom the possession of specified property (e.g. container) has been conveyed for a period of time in return for rental payments.
             $ecnt_fwd = $EdiReader->readEdiDataValue(['NAD', ['1' => 'CF']], 2);
             //process all containers
             foreach ($containers as $container) {
                 $error = [];
                 $EdiReader->resetErrors();
                 $ConEdiReader = new ContainerReader();
                 $ConEdiReader->setParsedFile($container);
                 $ecnt_data = [];
                 $ecnt_data['ecnt_terminal'] = $terminal;
                 $ecnt_data['ecnt_container_nr'] = $ConEdiReader->readEdiDataValue('EQD', 2);
                 $ecnt_data['ecnt_iso_type'] = $ConEdiReader->readEdiDataValue('EQD', 3, 0);
                 $ecnt_data['ecnt_message_type'] = $MessageType;
                 $ecnt_data['ecnt_operation'] = $ecnt_operation;
                 $ecnt_data['ecnt_fwd'] = $ecnt_fwd;
                 //2005 Date/time/period qualifier: code
                 // 7 - efective datetime
                 $ecnt_data['ecnt_datetime'] = $ConEdiReader->readEdiSegmentDTM(7);
                 $ecnt_data['ecnt_transport_id'] = $ConEdiReader->readTDTtransportIdentification(1);
                 if (!empty($ecnt_data['ecnt_transport_id'])) {
                     $ecnt_data['ecnt_ib_carrier'] = 'TRUCK';
                 }
                 $ecnt_data['ecnt_statuss'] = $ConEdiReader->readFullEmpty();
                 EcntContainer::saveEdiData($ecnt_data, $EdiReader, $error, $edifact);
             }
             return;
         } else {
             $error[] = 'Unknown message type:' . $MessageType;
             EcntContainer::saveEdiData(array(), $EdiReader, $error, $edifact);
             return;
         }
     } elseif ($terminal == 'RIXCT') {
         if ($MessageType == 'COARRI') {
             $ecnt_data = [];
             $ecnt_data['ecnt_terminal'] = $terminal;
             $ecnt_data['ecnt_message_type'] = $MessageType;
             $ecnt_data['ecnt_fwd'] = $EdiReader->readEdiDataValue(['NAD', ['1' => 'CA']], 2, 0);
             $ecnt_data['ecnt_transport_id'] = $EdiReader->readEdiDataValue(['TDT', ['1' => 20]], 2);
             $ecnt_data['ecnt_edifact_id'] = $edifact->id;
             $ecnt_data['ecnt_container_nr'] = $EdiReader->readEdiDataValue('EQD', 2);
             $ecnt_data['ecnt_iso_type'] = $EdiReader->readEdiDataValue('EQD', 3, 0);
             $ecnt_data['ecnt_datetime'] = $EdiReader->readEdiSegmentDTM(203);
             //2005 Date/time/period qualifier: code
             //‘203' Execution date
             $ecnt_data['ecnt_datetime'] = $EdiReader->readEdiSegmentDTM(203);
             if ($MessageCode == 270) {
                 $ecnt_data['ecnt_operation'] = EcntContainer::ECNT_OPERATION_VESSEL_LOAD;
                 $ecnt_data['ecnt_ib_carrier'] = 'TRUCK';
             } elseif ($MessageCode == 98) {
                 $ecnt_data['ecnt_operation'] = EcntContainer::ECNT_OPERATION_VESSEL_DISCHARGE;
                 $ecnt_data['ecnt_ob_carrier'] = 'TRUCK';
             } else {
                 $error[] = 'Neatrada operation - vessel load/unload!' . '/Loading:' . $LoadingLocationIdentification . '/Discharging:' . $DischargingLocationIdentification . '/MessageCode:' . $MessageCode;
             }
             $ecnt_data['ecnt_weight'] = $EdiReader->readEdiDataValue(['MEA', ['2' => 'G']], 3, 1);
             $ecnt_data['ecnt_statuss'] = $EdiReader->readFullEmpty();
             EcntContainer::saveEdiData($ecnt_data, $EdiReader, $error, $edifact);
             return true;
         } elseif ($MessageType == 'CODECO') {
             $ecnt_data = [];
             $ecnt_data['ecnt_terminal'] = $terminal;
             $ecnt_data['ecnt_message_type'] = $MessageType;
             $ecnt_data['ecnt_container_nr'] = $EdiReader->readEdiDataValue('EQD', 2);
             $ecnt_data['ecnt_iso_type'] = $EdiReader->readEdiDataValue('EQD', 3, 0);
             $ecnt_data['ecnt_fwd'] = $EdiReader->readEdiDataValue(['NAD', ['1' => 'CF']], 2);
             // 1001 Document name code
             $DocumentNameCode = $EdiReader->readEdiDataValue('BGM', 1);
             if ($DocumentNameCode == 34) {
                 $ecnt_data['ecnt_operation'] = EcntContainer::ECNT_OPERATION_TRUCK_IN;
             } elseif ($DocumentNameCode == 36) {
                 $ecnt_data['ecnt_operation'] = EcntContainer::ECNT_OPERATION_TRUCK_OUT;
             } else {
                 $error[] = 'Neatrada operation - truck in/out';
             }
             $ecnt_data['ecnt_statuss'] = $EdiReader->readFullEmpty();
             //Effective from date/time
             $ecnt_data['ecnt_datetime'] = $EdiReader->readEdiSegmentDTM('181');
             $ecnt_data['ecnt_transport_id'] = $EdiReader->readEdiDataValue(['TDT', ['1' => '1']], 8, 0);
             if (!empty($ecnt_data['ecnt_transport_id'])) {
                 $ecnt_data['ecnt_ib_carrier'] = 'TRUCK';
             }
             $ecnt_data['ecnt_weight'] = $EdiReader->readEdiDataValue(['MEA', ['2' => 'AAE']], 3, 1);
             $ecnt_data['ecnt_booking'] = $EdiReader->readEdiDataValue(['RFF', ['1.0' => 'BN']], 1, 1);
             EcntContainer::saveEdiData($ecnt_data, $EdiReader, $error, $edifact);
             return true;
         } else {
             $error[] = 'Unknown message type:' . $MessageType;
             EcntContainer::saveEdiData(array(), $EdiReader, $error, $edifact);
             return true;
         }
     }
     $error[] = 'Unrecognised message';
     EcntContainer::saveEdiData(array(), $EdiReader, $error, $edifact);
     return false;
 }
Exemple #2
0
 function load($url)
 {
     $Parser = new \EDI\Parser($url);
     $this->parsedfile = $Parser->get();
 }
Exemple #3
0
 /**
  * @param $url string url to edi file, path to edi file or EDI message
  * @return bool
  */
 public function load($url)
 {
     $Parser = new \EDI\Parser($url);
     $this->parsedfile = $Parser->get();
     return $this->preValidate();
 }
Exemple #4
0
</div>
<?php 
if (!empty($model->ecnt_edifact_id)) {
    ?>
    <div class="space-12"></div>
    <div class="row">

        <h3 class="header blue lighter smaller">
            EDI File Readable
        </h3>        
        <div class="span12">
            <pre>
                <?php 
    $edifact = Edifact::model()->FindByPk($model->ecntEdifact->id);
    $EdiParser = new EDI\Parser();
    $f = explode(PHP_EOL, $edifact->message);
    $parsed = $EdiParser->parse($f);
    $analyser = new EDI\Analyser();
    $analyser->edi_message = $edifact->message;
    $mapping_segments = realpath(Yii::getPathOfAlias('edifact-data')) . '/D95B/segments.xml';
    $analyser->loadSegmentsXml($mapping_segments);
    echo $analyser->process($parsed);
    ?>
    
            </pre>
        </div>
    </div>
    <?php 
}
?>