<?php
namespace App\Amadeus\StructureParser\Structures\Refund; class Document extends \App\Amadeus\StructureParser\Parser\Document { public function document() { $index = $this->transaction->getIndex(); if ($index and $index->distribuiteTransaction) { $doc = $this->document_RFD_distribuited(); if($doc){ return $doc; } } $doc = $this->document_RFD(); if($doc){ return $doc; } throw new \Exception("Unknown refund document"); } protected function document_RFD_distribuited() { $index = $this->transaction->getIndex(); $item = $this->document_RFD(); $reference = \Entity\AmadeusService::select($index->referenceTransaction); if ($reference->recordExists()) { if ($reference->docNumber != $item->docNumber) { $item->docNumber = $reference->docNumber; $item->docNumbers = [$item->docNumber, ]; $item->autoIgnored = 'fakeRefund'; $item->transactionCode = $reference->transactionCode; } return $item; } return null; } protected function document_RFD() { $parsedStructure = $this->transaction->getParsedStructure(); $item = null; if (count($parsedStructure['I'])>1) { $this->transaction->addLog(__METHOD__.": This reservation has more than one passenger, picking the first one as 'owner'"); } $I = $parsedStructure['I'][0]; if (isset($I['R'])) { $item = new \App\Amadeus\StructureParser\Types\Document(); $item->createDate= $parsedStructure['D']['PNRDTE']; $item->issueDate= $parsedStructure['D']['AIRDTE']; if ($I['T']['TKTNBR_']) { $item->docDate = $I['R']['RFDDATE']; $item->docNumber = $I['T']['TKTNBR']; foreach($I['T']['TKTNBR_'] as $TKT){ $item->docNumbers[] = $TKT; } } elseif ($I['R']['RFDDATE']) { $item->docDate = $I['R']['RFDDATE']; $item->docNumber = $I['R']['RFDNBR_TKTNBR']; $item->docNumbers[] = $item->docNumber; } $transactions = \App\Amadeus\Storage\StorageHandler::selectByDocNumber($item->docNumber, $item->docDate); if(!$transactions){ $transactions = \App\Amadeus\Storage\StorageHandler::selectByDocNumber($item->docNumber); } $last = end($transactions); $item->transactionCode = \Entity\AmadeusService::select($last['id']??null)->transactionCode; } return $item; } public function supplier() { $parsedStructure = $this->transaction->getParsedStructure(); $item = null; $I = $parsedStructure['I'][0]; if( $I['R']) { $item = new \App\Amadeus\StructureParser\Types\Supplier(); $item->code3 = $I['R']['RFDNBR_NUMAIR']; } return $item; } } 