<?php
namespace App\Amadeus\FileParser;

class Line_KRF extends \App\Amadeus\FileParser\LineAbstract
{
	/**
	 * 4.81. KRF Refundable Tax Data
	 * see page 241(283)
	 *
	 * This field is used to transmit REFUND tax data.
	 */
		protected $structure = [
		['name'=> 'MSGTAG',     'val' => 'KRF',   'type' => 'AN',   'req' => 'M',                                'len' => 3,],                    // 1 : Message Tag (KRF)
		['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'=> 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 (Q, T or H) (refer to A-02-3500-AMD for specific details)
		   ['name'=> 'TCURRAC',                   'type' => 'AN',                                                'len' => 3,],                    // 6 : Currency Type/PFC Airport Code If OTAXI=Q/T, Value is Currency Type Code If OTAXI=H, Value is PFC Airport Code
		   ['name'=> 'TAXA',                      'type' => 'S:trim',                                            'len' => 9,],                    // 7 : Tax Amount
		   ['name'=> 'TAXC',                      'type' => 'S:trim',                                            'len' => 3,],                    // 8 : Tax Code
		   ['name'=> 'TAXN',                      'type' => 'S:trim',                                            'len' => 2,],                    // 9 : Nature Code. Blanks if no nature code.
		   ['name'=> 'DELIM',   'val' => ';',     'type' => 'AN',                                                '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'], 2);
			$this->tree['TAXFLD'] = self::extractTaxNameFromCode($this->tree['TAXFLD']);
			$this->tree['TAXFLD'] = self::fillTAXA($this->tree['TAXFLD']);

			$this->computeStats_taxes();
		}
	}
}
