<?php
namespace App\Amadeus\FileParser;

class Line_KN extends \App\Amadeus\FileParser\LineAbstract
{
	/**
	 * 4.77. KN- Nett Fare Line
	 * see page 233(275)
	 *
	 * This field is used to transmit Nett Fare Data.
	 * For Negotiated Fare Data, when pricing indicator in the C- line reference 9 is "F" this field will contain the Nett Fare.
	 * For Net Fare Data, when pricing indicator in the C- line reference 9 is "M" or "N"and the NF field of the TST is populated,
	 * this field will contain the Nett Fare.
	 */
	protected $structure = [
		['name'=> 'MSGTAG',     'val' => 'KN-',   'type' => 'AN',   'req' => 'M',                                'len' => 3,],                    // 1 : Message Tag (KN-)
		['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'=> 'CURRTYP',                      'type' => 'AN',                                                'len' => 3,],                    // 3 : Currency Type Code
		['name'=> 'BASE',                         'type' => 'N',    'req' => 'M',                                'len' => 11,],                   // 4 : Base Fare
		['name'=> 'DELIM',      'val' => ';',     'type' => 'AN',   'req' => 'M',                                'len' => 1,],                    // 5 : Delimiter (Constant value of ';')
		['name'=> 'CURCODE',                      'type' => 'AN',                                                'len' => 3,],                    // 6 : Currency code.
		['name'=> 'EQVAMT',                       'type' => 'N',                                                 'len' => 11,],                   // 7 : Equivalent Amount or One/Two Currency Codes
		['name'=> 'DELIM',      'val' => ';',     'type' => 'AN',   'req' => 'M',                                'len' => 1,],                    // 8 : Delimiter (Constant value of ';')
		['name' => 'TAXFLD',                      'type' =>'composite',                                          'rep' =>10,                      // 9 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 COMPOSITE ELEMENT...
		 'childs' => [
		   ['name'=> 'OTAXI',                     'type' => 'S:trim',                                            'len' => 1,],                    // 10 : Tax Indicator (blank = new tax) (refer to A-02-3500-AMD for specific details)
		   ['name'=> 'TCURR',                     'type' => 'AN',                                                'len' => 3,],                    // 11 : Currency Type Code
		   ['name'=> 'TAXA',                      'type' => 'S:trim',                                            'len' => 7,],                    // 12 : Tax Amount
		   ['name'=> 'TAXC',                      'type' => 'S:trim',              'requires' => ['TAXA'], 'len' => 3,],                    // 13 : Tax Code
		   ['name'=> 'TAXN',                      'type' => 'AN',                  'requires' => ['TAXC'], 'len' => 2,],                    // 14 : Nature Code. Blanks if no nature code.
		   ['name'=> 'DELIM',   'val' => ';',     'type' => 'AN',   'req' => 'M',                                'len' => 1,],                    // 15 : Delimiter (Constant value of ';')
		 ]],                                                                                                                                             // 16 END OF COMPOSITE ELEMENT
		['name'=> 'CURRCDE',                      'type' => 'AN',                                                'len' => 3,],                    // 17 : Currency Type Code
		['name'=> 'TOTAMT',                       'type' => 'N',    'req' => 'M',                                'len' => 11,],                   // 18 : Total Amount Collected
		['name'=> 'DELIM',      'val' => ';',     'type' => 'AN',   'req' => 'M',                                'len' => 1,],                    // 19 : Delimiter (Constant value of ';')
		['name'=> 'SELLBUY1',                     'type' => 'NS',],                              // 20 : Bankers Selling/Buying Rate (First)
		['name'=> 'DELIM',      'val' => ';',     'type' => 'AN',   'req' => 'M',                                'len' => 1,],                    // 21 : Delimiter (Constant value of ';')
		['name'=> 'SELLBUY2',                     'type' => 'NS',],                              // 22 : Bankers Selling/Buying Rate (Second)
		['name'=> 'DELIM',      'val' => ';',     'type' => 'AN',   'req' => 'M',                                'len' => 1,],                    // 23 : Delimiter (Constant value of ';')
		['name'=> 'TRANCURR',                     'type' => 'S:trim',                                            'len' => 3,],                    // 24 : Transitional Currency Code Indicates transitional currency when second bankers selling/buying rate exists.
		['name'=> 'extra delim','val' => ';',     'type' => 'AN',                                                'len' => 1,],					// custom added so it would validate a weird line containing an extra ';' (@see 2011-03-04_181546_192.168.1.22__@0400117.AIR), (@see MAIL:FW: Emailing: 2011-03-04_181546_192.168.1.22__@0400117.AIR)
		['name'=> 'extra spaces',                 'type' => 'S:trim',],
	];

	/**
	 * (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();
		}
	}
}
