d3yii2 / d3edi
There is no license information available for the latest version (dev-master) of this package.
EDI
dev-master
2022-04-01 12:38 UTC
Requires
- d3yii2/d3system: dev-master
- php-edifact/edifact-mapping: dev-master
- phpseclib/phpseclib: 2.0.29
- sabas/edifact: dev-master
- unyii2/yii2-panel: dev-master
- yiisoft/yii2: *
This package is auto-updated.
Last update: 2024-10-29 06:05:54 UTC
README
Features
- Collect EDI messages in DB
- Other processes process collected messages and registries
- status processed and ref records
- status error and error message
used packages
- sabas/edifac - Tools to process EDI messages in UN/EDIFACT format
- php-edifact/edifact-mapping - xml files for EDIFACT messages
- unyii2/yii2-panel - panel controller and widget
DB Schema
Installation
The preferred way to install this extension is through composer.
Either run
$ composer require d3yii2/d3edi "*"
or add
"d3yii2/d3edi": "*"
to the require
section of your composer.json
file.
Methods
Usage
map edi fata to model attributes
class DepoEdiBooking extends BaseDepoEdiBooking { public function loadEdi($ediMessage): void { $r = $ediMessage->readEdiMessage(); $this->booking_ref_number = $r->readEdiDataValue(['RFF',['1'=>'BN']],1,0); $this->carier = $r->readEdiDataValue(['NAD',['1'=>'CA']],2,0); $this->containerType = $r->readEdiDataValue(['EQD',['1'=>'CN']],3,0); if(!$this->cont_type_id = CargoContTypeDictionary::getIdByEdiCode($containerType)){ $this->cont_type_id = null; $this->addError('cont_type_id','Undefined container type: ' . $containerType); } } }
procesing
$cnt = 0; foreach(EdiMessage::find()->allNews() as $ediMessage){ if(!$transaction = $this->module->db->begintransaction()){ throw new \yii\db\Exception('can not start Begin transaction'); } try { $ediBooking = new DepoEdiBooking(); $ediBooking->loadEdi($ediMessage); if ($ediBooking->hasErrors() || !$ediBooking->validate()) { $ediMessage->saveError($ediBooking->getErrors()); continue; } if (!$ediBooking->save()) { throw new D3ActiveRecordException($ediBooking); } $ediMessage->saveProcessed($ediBooking); $transaction->commit(); $cnt ++; continue; }catch (Exception $e){ $transaction->rollBack(); Yii::error($e->getMessage()); Yii::error($e->getTraceAsString()); $ediMessage->saveError($e->getMessage()); } } return $cnt; }
Panle for unprocessed messages
For showing unprocessed messages can use panel solution Yii2Panel
add widget
echo \unyii2\yii2panel\PanelWidget::widget([ 'name' => 'MyAllerts', ]);
to module add parameter panels
class MyModule extends Module { /** * @var array panels for PanelWidgets */ public $panels;
in module config add widget
'mymodule' => [ 'class' => 'MyModule', 'panels' => [ 'MyAllerts' => [ [ 'route' => 'edi/panel/message', ] ] ], ],
in EDI module can set role for access to panel. Otherwise every authorised user has access to panle widget
'edi' => [ 'class' => 'd3yii2\d3edi\Module', 'accessRulesMessageRoles' => ['Depo3EdiFull'] ],