{extends file=$smarty.const.SMARTY_LAYOUT_CONTENT_LIST_TABLE_CURRENT_DATA}

{block name="listing-tr-class"}
	{if $rowFields['entity']->autoIgnored=='conjunction'}
		disabled
	{/if}
{/block}

{block name="listing-tr-extraData"}
	data-importedServiceId="{if $rowFields['entity']->importedServiceId}{$rowFields['entity']->importedServiceId}{elseif $rowFields['entity']->refundedService->recordExists()}{$rowFields['entity']->refundedService->importedServiceId}{/if}"
{/block}

{block name="listing-td-content-RECLOC"}
	<div class='fileType'>
		{if $rowFields['entity']->file->isAIR}
			AIR
		{else}
			IMR
		{/if}
	</div>

	<div>{amadeusServiceLabel ref=$rowFields['id']}</div>
	<div>{$rowFields['entity']->transactionDocData->issueDate|default:$rowFields['entity']->transactionDocData->docDate|dateTimeFormat}</div>
{/block}

{block name="listing-td-content-passengers"}
	<div class="passenger-{$rowFields['entity']->transactionStatus}">
		<div>{nameFormat firstName=$rowFields['entity']->passengerFirstName lastName=$rowFields['entity']->passengerLastName}</div>
		<div class='bold'>{strip}
			{$rowFields['entity']->docNumber}
			{if $rowFields['entity']->conjunctions}
				{$lastConjunction=$rowFields['entity']->conjunctions|end}
				-{$lastConjunction->docNumber|substr:-2}
			{/if}
		</div>{/strip}
	</div>
{/block}

{block name="listing-td-content-operation"}
	<div class="transactionStatus transactionStatus-{$rowFields['entity']->transactionStatus}">
		{if $rowFields['entity']->transactionStatus=='new'}issue{else}{$rowFields['entity']->transactionStatus}{/if}

		{if in_array($rowFields['entity']->transactionStatus, ['reissue'])}
			<span class='transactionDetailsFor-{$rowFields['entity']->transactionStatus}' tooltip="{$_LANG['Orders']['Amadeus']['ServicesList']['index']['listing']['originalTicket']}">
				{if $rowFields['transactionReferences']}
					{$showField=true}
					{foreach $rowFields['transactionReferences'] as $ref}
						{if $showField && $ref['relationType']=='reissueOf'}
							[{$ref['entity']->docNumber}]
							{$showField=false}
						{/if}
					{/foreach}
				{/if}
			</span>
		{/if}
	</div>

	<div>{$rowFields['entity']->serviceCode}</div>
{/block}

{block name="listing-td-content-supplier"}
	<div>
		{$rowFields['entity']->transactionSupplierData->name}
	</div>
	<div>
		{if $rowFields['entity']->transactionSupplierData->codeAirline}
			<div>
				iata: {$rowFields['entity']->transactionSupplierData->codeAirline}
			</div>
		{/if}
		{if $rowFields['entity']->transactionSupplierData->code3}
			<div>
				airline prefix code: {$rowFields['entity']->transactionSupplierData->code3}
			</div>
		{/if}
	</div>
{/block}


{block name="listing-td-content-itinerary"}
	{$segments=$rowFields['entity']->transactionSegmentData->getSegments()}
	{$destination=$rowFields['entity']->transactionSegmentData->getDestination()}
	{$lastArrival=''}
	{foreach $segments as $segment}
		{if $lastArrival!=$segment->departure->airportCode}
			<div>
				{$segment->departure->airportCode}
			</div>
		{/if}
		<div class="{if $destination->airportCode==$segment->destination->airportCode}bold{/if}">
			{$segment->destination->airportCode}
			{$lastArrival=$segment->destination->airportCode}
		</div>
	{/foreach}
{/block}


{block name="listing-td-content-prices"}
	{function name="printPrice" label="" currency="" amount="" VAT="" total=false highlight=false force=false}
		{if $amount || $force}
			<div class="row {if $total}total{/if}">
				<span class="label">{$label}</span><span class="amount">{$amount|priceFormat:$currency:1}</span><span class="currency">{$currency}</span>
			</div>
		{/if}
	{/function}

	<div class="pricesContainer">
		{if $rowFields['entity']->transactionStatus=='refund'}
			<div class="priceDetailsFor-{$rowFields['entity']->transactionStatus}">
				{if $rowFields['entity']->file->fileExists}
					{printPrice label=$lang['index']['listing']['prices']['farePaid'] force=true
						amount=-1*$rowFields['entity']->file->parsedFile['RFD']['FPAID']
						VAT=false
						currency=$rowFields['entity']->file->parsedFile['RFD']['CURRTYP']}

					{printPrice label=$lang['index']['listing']['prices']['fareUsed'] force=true
						amount=$rowFields['entity']->file->parsedFile['RFD']['FUSED']
						VAT=false
						currency=$rowFields['entity']->file->parsedFile['RFD']['CURRTYP']}

					{printPrice label=$lang['index']['listing']['prices']['fareRefund'] force=true
						amount=$rowFields['entity']->file->parsedFile['RFD']['FRFD']
						VAT=false
						currency=$rowFields['entity']->file->parsedFile['RFD']['CURRTYP']}

					{if $rowFields['entity']->transactionPriceData and $rowFields['entity']->transactionPriceData->tax}
						{printPrice label=$lang['index']['listing']['prices']['tax']
							amount=$rowFields['entity']->transactionPriceData->tax->getAmount()
							VAT=$rowFields['entity']->transactionPriceData->tax->getVAT()
							currency=$rowFields['entity']->transactionPriceData->tax->getCurrency()}
					{/if}

					{if $rowFields['entity']->transactionPriceData}
						{printPrice label=$lang['index']['listing']['prices']['penalty']
							amount=$rowFields['entity']->transactionPriceData->penalty
							VAT=$rowFields['entity']->transactionPriceData->penaltyVAT
							currency=$rowFields['entity']->transactionPriceData->penaltyCurrency}
					{/if}

					{if $rowFields['entity']->transactionPriceData}
						<div class="row total">
							<span class="label">
								{$lang['index']['listing']['prices']['total']}
								{if $rowFields['entity']->transactionPriceData->formOfPayment && $rowFields['entity']->transactionPriceData->formOfPayment->getShortNotation()}
									<span class="formOfPayment">({$rowFields['entity']->transactionPriceData->formOfPayment->getShortNotation()})</span>
								{/if}
							</span>
							<span class="amount">{$rowFields['entity']->transactionPriceData->total|priceFormat:$rowFields['entity']->transactionPriceData->totalCurrency:1}</span>
							<span class="currency">{$rowFields['entity']->transactionPriceData->totalCurrency}</span>
						</div>
					{/if}

				{else}
					{* file doesn't exist *}
				{/if}
			</div>
		{elseif $rowFields['entity']->transactionStatus=='void'}
			&nbsp;
		{else}

			{if $rowFields['entity']->transactionPriceData}
				{printPrice label=$lang['index']['listing']['prices']['fare']
					amount=$rowFields['entity']->transactionPriceData->supplier+$rowFields['entity']->transactionPriceData->commission
					VAT=$rowFields['entity']->transactionPriceData->supplierVAT+$rowFields['entity']->transactionPriceData->commissionVAT
					currency=$rowFields['entity']->transactionPriceData->supplierCurrency}

				{if $rowFields['entity']->transactionPriceData->tax}
					{printPrice label=$lang['index']['listing']['prices']['tax']
						amount=$rowFields['entity']->transactionPriceData->tax->getAmount()
						VAT=$rowFields['entity']->transactionPriceData->tax->getVAT()
						currency=$rowFields['entity']->transactionPriceData->tax->getCurrency()}
				{/if}

				{printPrice label=$lang['index']['listing']['prices']['penalty']
					amount=$rowFields['entity']->transactionPriceData->penalty
					VAT=$rowFields['entity']->transactionPriceData->penaltyVAT
					currency=$rowFields['entity']->transactionPriceData->penaltyCurrency}

				<div class="row total">
					<span class="label">
						{$lang['index']['listing']['prices']['total']}
						{if $rowFields['entity']->transactionPriceData->formOfPayment && $rowFields['entity']->transactionPriceData->formOfPayment->getShortNotation()}
							<span class="formOfPayment">({$rowFields['entity']->transactionPriceData->formOfPayment->getShortNotation()})</span>
						{/if}
					</span>
					<span class="amount">{$rowFields['entity']->transactionPriceData->total|priceFormat:$rowFields['entity']->transactionPriceData->totalCurrency:1}</span>
					<span class="currency">{$rowFields['entity']->transactionPriceData->totalCurrency}</span>
				</div>
			{/if}

		{/if}
	</div>
{/block}

{block name="listing-td-content-user"}
	{if $rowFields['entity']->idAmadeusBookUser}
		<div>{userLabel ref=$rowFields['entity']->idTINABookUser} ({$rowFields['entity']->idAmadeusBookUser})</div>
	{/if}

	{if $rowFields['entity']->idAmadeusIssueUser}
		<div>{userLabel ref=$rowFields['entity']->idTINAIssueUser} ({$rowFields['entity']->idAmadeusIssueUser})</div>
	{/if}
{/block}
