<?php
namespace App\Sabre\StructureParser\Structures\Base; abstract class Documents extends \App\Sabre\StructureParser\Structures\Base\Base { public function populate(\App\Sabre\StructureParser\Types\Document $item, $parsedStructure, $transactionType, $transactionIndexes, $internalAssociations) { $item->createDate = $parsedStructure['M0']['M0']['IU0PDT']; $item->RECLOC = $parsedStructure['M0']['M0']['IU0PNR']; $item = $this->populateTransactionCode($item, $parsedStructure, $transactionType, $transactionIndexes, $internalAssociations); return $item; } public function populateTransactionCode(\App\Sabre\StructureParser\Types\Document $item, $parsedStructure, $transactionType, $transactionIndexes, $internalAssociations) { $transactionCodeComponents = []; $transactionCodeComponents[] = $item->RECLOC; if (is_array($transactionIndexes['km1'])) { if ($transactionIndexes['km1']) { $transactionCodeComponents[] = implode(",", array_map(function($km1) use($parsedStructure) { return sprintf("%02d", (int)$parsedStructure['M1'][$km1]['M1']['IU1PNO']); }, $transactionIndexes['km1'])); } } elseif (isset($transactionIndexes['km1']) && $transactionIndexes['km1']!==null) { $km1 = $transactionIndexes['km1']; $transactionCodeComponents[] = sprintf("%02d", (int)$parsedStructure['M1'][$km1]['M1']['IU1PNO']); } if (is_array($transactionIndexes['km3'])) { $transactionCodeComponents[] = implode(",", array_map(function($km3) use($parsedStructure) { return $this->generateTransactionCodeComponent_02($parsedStructure, $km3); } , $transactionIndexes['km3'])); } elseif (isset($transactionIndexes['km3']) && $transactionIndexes['km3']!==null) { $km3 = $transactionIndexes['km3']; $transactionCodeComponents[] = $this->generateTransactionCodeComponent_02($parsedStructure, $km3); } $passiveSegmentStatuses = ['YK', 'PK', 'GK', ]; if (is_array($transactionIndexes['km3'])) { $extraIndexes = array_map(function($km3) use($parsedStructure, $passiveSegmentStatuses) { if (in_array($parsedStructure['M3'][$km3]['M3Air']['IU3AAC'], $passiveSegmentStatuses)) { return $parsedStructure['M3'][$km3]['M3Air']['IU3OAL']; } return null; }, $transactionIndexes['km3']); if ($extraIndexes && count(array_filter($extraIndexes)) == count($extraIndexes)) { $transactionCodeComponents[] = implode(",", array_unique(array_filter($extraIndexes))); } } $item->transactionCode = implode("-", $transactionCodeComponents); return $item; } private function generateTransactionCodeComponent_02($parsedStructure, $km3) { $ret = null; if ($parsedStructure['M3'][$km3]['M3Air']['IU3ITN']) { $ret = (int)$parsedStructure['M3'][$km3]['M3Air']['IU3ITN']; } elseif ($parsedStructure['M3'][$km3]['M3Hhl']['IU3ITN']) { $ret = (int)$parsedStructure['M3'][$km3]['M3Hhl']['IU3ITN']; } elseif ($parsedStructure['M3'][$km3]['M3Oths']['IU3ITN']) { $ret = (int)$parsedStructure['M3'][$km3]['M3Oths']['IU3ITN']; } else { throw new \Exception("Unable to generate transaction code component for segment index {$km3}"); } return $ret; } } 