<?php
namespace App\Amadeus\FileParser; class Line_FM extends \App\Amadeus\FileParser\LineAbstract { protected $structure = [ ['name'=> 'MSGTAG', 'val' => 'FM', 'type' => 'AN', 'req' => 'M', 'len' => 2,], ['name'=> 'FARECOM', 'type' => 'AN', 'req' => 'M', 'len_min' => 1, 'len_max' => 127,], ['name'=> 'SEGASS', 'val' => ';S', 'type' => 'ASSOC',], ['name'=> 'PSGASS', 'val' => ';P', 'type' => 'ASSOC',], ]; protected $FARECOM_type = [ '*P*' => 'Commission through manual capping or semi-auto capping', '*C*' => 'System generated commission', '*M*' => 'Manual commission', '*F*' => 'Commission data from negotiated fare database', '*G*' => 'Negotiated fare auto-commission generated', '*D*' => 'Dynamic discounted fare commission', '*PR*' => 'Reuse of manual capped or semi-auto capped commission', '*V*' => 'Commission is subject to VAT', '*AM*' => '', ]; protected function postParse() { parent::postParse(); $this->tree['commissionType'] = 'none'; $m = []; if (preg_match("/^(?P<commissionType>\*(P|C|M|F|G|D|V|AM|PR)\*)?(?P<value>[0-9.]+)?(?P<amountType>(A|P|N|S|V))?(?P<old>\/.+)?$/", $this->tree['FARECOM'], $m)) { $this->tree['commissionType'] = $this->FARECOM_type[$m['commissionType']]; if ($m['value']) { $this->tree['amountType'] = ($m['amountType']=='A'?'value':'percent'); if ($this->tree['amountType']=='value') { $this->tree['amountValue'] = (float)$m['value']; } elseif ($this->tree['amountType']=='percent') { $this->tree['amountPercent'] = (float)$m['value']; } else { throw \App\Amadeus\FileParser\ParserException::internal("Unknown commission type detected"); } } else { $this->tree['amountType'] = 'none'; $this->tree['amountValue'] = 0; } } else { throw \App\Amadeus\FileParser\ParserException::internal("Unknown FM line format detected in field FARECOM: '{$this->tree['FARECOM']}'"); } } } 