<?php
namespace App\Amadeus\FileParser;

class Line_KTR extends \App\Amadeus\FileParser\LineAbstract
{
	/**
	 * KTR Refundable Tax Data - KTR_Booking_RefundableTaxData
	 *
	 * This line is used to transmit refundable taxes linked to a booking in case of Issuance.
	 */
		protected $structure = [
		['name'=>  'MSGTAG',     'val' => 'KTR-', 'type' => 'AN',   'req' => 'M',                                'len' => 4,],
		['name' => 'TAXFLD',                      'type' =>'composite',                                          'rep'=> 198,
		 'childs' => [
			['name'=> 'TRCURR',                    'type' => 'S:trim',                                            'len' => 3,],
		   	['name'=> 'TAXA',                      'type' => 'S:trim',                                            'len' => 9,],
		   	['name'=> 'TAXC',                      'type' => 'S:trim',                                            'len' => 3,],
		   	['name'=> 'TAXN',                      'type' => 'S:trim',                                            'len' => 2,],
			['name'=> 'TIND',   'val'=>'T',        'type' => 'S:trim',                                            'len' => 2,],
			['name'=> 'TAXNAME',                   'type' => 'S:trim',                                            'len_min' => 1, 'len_max' => 25,],
		   	['name'=> 'DELIM',  'val' => ';',      'type' => 'AN',                                                'len' => 1,],
		 ]],
		['name'=> 'TSCURR',                      'type' => 'S:trim',                                            'len' => 3,],
		['name'=> 'TAXSUM',                      'type' => 'S:trim',                                            'len' => 9,],
		];

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