<?php
namespace App\Worldspan\StructureParser\Types; class Price extends \App\Utils\BaseParser\Structure\StructureParser\Types\Price { protected function createPriceTaxObject() { return new PriceTax(); } protected function createPriceFormOfPaymentObject() { return new PriceFormOfPayment(); } public function convert($initialAmount, $initialCurrency, $finalCurrency, ?\App\Utils\BaseParser\Structure\StructureParser\Structures\Transaction $transaction = null) { $return = null; if ($transaction) { list($parsedStructure, $transactionType, $transactionIndexes, $internalAssociations, $processor) = $transaction->getTransactionDetails(); if ($initialCurrency === $finalCurrency) { $return = $initialAmount; } else { $extractedData = $processor->getFileParser()->getExtractedData(); $bankersRates = []; foreach ($extractedData['passenger'] as $P) { if ($P['RB'] && $P['RB']['OriginCityCurrencyCode']) { $bankersRates[]= [ 'OriginCityCurrencyCode' => $P['RB']['OriginCityCurrencyCode'], 'TicketingCurrencyRatio' => $P['RB']['TicketingCurrencyRatio'], 'TicketingCurrencyCode' => $P['RB']['TicketingCurrencyCode'], ]; } } foreach ($bankersRates as $bankersRate) { if ($bankersRate['OriginCityCurrencyCode'] === $initialCurrency && $bankersRate['TicketingCurrencyCode'] === $finalCurrency ) { $return = $initialAmount*$bankersRate['TicketingCurrencyRatio']; $transaction->getMessagesCollector()->addInfo(sprintf("[%s] Using in-file currency conversion for %.4f%s. 1%s=%.4f%s", __METHOD__, $initialAmount, $initialCurrency, $bankersRate['OriginCityCurrencyCode'], $bankersRate['TicketingCurrencyRatio'], $bankersRate['TicketingCurrencyCode'] )); } elseif ($bankersRate['OriginCityCurrencyCode'] === $finalCurrency && $bankersRate['TicketingCurrencyCode'] === $initialCurrency ) { $return = $initialAmount*(1/$bankersRate['TicketingCurrencyRatio']); $transaction->getMessagesCollector()->addInfo(sprintf("[%s] Using in-file currency conversion for %.4f%s. 1%s=%.4f%s", __METHOD__, $initialAmount, $initialCurrency, $bankersRate['OriginCityCurrencyCode'], $bankersRate['TicketingCurrencyRatio'], $bankersRate['TicketingCurrencyCode'] )); } } } } if ($return===null) { $return = $this->convertUsingTINAConvertor($initialAmount, $initialCurrency, $finalCurrency, $transaction); } return $return; } } 