<?php
namespace App\Amadeus\FileParser;

class Line_KFT extends \App\Amadeus\FileParser\LineAbstract
{
	/**
	 * 4.76. KFT Tax Data
	 * see page 231(273)
	 *
	 * This field is used to transmit NEW and OLD tax data.
	 * For Negotiated Fare Data, when pricing indicator in the C- line reference 9 is "F" this field will contain the Published Taxes.
	 */
	protected $structure = [
		['name'=> 'MSGTAG',     'val' => 'KFT',   'type' => 'AN',   'req' => 'M',                                'len' => 3,],                    // 1 : Message Tag (KFT)
		['name'=> 'ISSUE',                        'type' => 'AN',   'req' => 'M',                                'len' => 1,],                    // 2 : Issue Identifier from the pricing record (refer to A-02-3500-AMD for specific details) F if blank in the TSTB if the value is U in the TSTValue of the TST in other cases
		['name'=> 'DELIM',      'val' => ';',     'type' => 'AN',   'req' => 'M',                                'len' => 1,],                    // 3 : Delimiter (Constant value of ';')
		['name' => 'TAXFLD',                      'type' =>'composite',                                          'rep_min' =>1, 'rep_max' =>198,  // 4 TAX FIELD IF NO DATA, NO BLANKS ARE IN BETWEEN DELIMITERS. IF DATA IS ENTERED, BUT SOME FIELDS ARE NOT USED, THEY ARE BLANK FILLED. THIS IS A
		 'childs' => [
		   ['name'=> 'OTAXI',                     'type' => 'S:trim',                                            'len' => 1,],                    // 5 : Tax Indicator blank = new tax O = old tax G = reissue tax (refer to A-02-3500-AMD for specific details)
		   ['name'=> 'TCURR',                     'type' => 'AN',                                                'len' => 3,],                    // 6 : Currency Type Code
		   ['name'=> 'TAXA',                      'type' => 'S:trim',                                            'len' => 9,],                    // 7 : Tax Amount
		   ['name'=> 'TAXC',                      'type' => 'S:trim',              'requires' => ['TAXA'], 'len' => 3,],                    // 8 : Tax Code
		   ['name'=> 'TAXN',                      'type' => 'AN',                  'requires' => ['TAXC'], 'len' => 2,],                    // 9 : Nature Code. Blanks if no nature code.
		   ['name'=> 'DELIM',   'val' => ';',     'type' => 'AN',   'req' => 'M',                                'len' => 1,],                    // 10 : Delimiter (Constant value of ';') (No delimiter follows the last Tax Field Item)
		 ]],                                                                                                                                             // 11 END OF COMPOSITE ELEMENT
	];

	/**
	 * (non-PHPdoc)
	 * @see \App\Amadeus\FileParser\LineAbstract::postParse()
	 */
	protected function postParse()
	{
		// call the parent first
		parent::postParse();

		if($this->tree['TAXFLD']){
			$this->tree['TAXFLD'] = self::rtrimArrDeep($this->tree['TAXFLD']);
			$this->tree['TAXFLD'] = self::extractTaxNameFromCode($this->tree['TAXFLD']);
			$this->tree['TAXFLD'] = self::fillTAXA($this->tree['TAXFLD']);

			$this->computeStats_taxes();
		}
	}
}
