<?php
 namespace App\ImportedOrder; class RefundDetails extends EntityAbstract { public $date; public $currency; public ?\App\ImportedOrder\User $issueUser = null; public ?\App\ImportedOrder\Office $issueOffice = null; public $fareUsedSupplierValue; public $fareUsedSupplierVat; public $fareUsedCommissionValue; public $fareUsedTaxValue; public ?array $fareUsedTaxCodes = null; public $fareUsedTaxVat; public $penaltyValue; public $serviceFeeValue; public $returnOriginalServiceFee; public $formOfPayment; public $auxReference; public ?array $extraInfo = null; public function addFareUsedTaxCode($code, $value, $currency) :void { if (!$this->fareUsedTaxCodes) { $this->fareUsedTaxCodes = []; } $this->fareUsedTaxCodes[]= ['code'=>$code, 'value'=>$value, 'currency'=>$currency]; } protected function validateEntityFields(\App\MessagesCollector $messagesCollector): void { if ($this->fareUsedSupplierValue or $this->fareUsedCommissionValue or $this->fareUsedTaxValue or $this->penaltyValue or $this->serviceFeeValue) { if (!$this->currency) { $messagesCollector->addError('Currency not set for refund details.'); } elseif (!\App\Config\Currencies::getInstance()->check($this->currency)) { $messagesCollector->addError("The currency `{$this->currency}` is not valid for refund details."); } } if ($this->fareUsedSupplierVat and !$this->fareUsedSupplierValue) { $messagesCollector->addWarning('If the fare-used supplier price VAT is set, then the value (total) must also be set.'); } if ($this->fareUsedTaxVat and !$this->fareUsedTaxValue) { $messagesCollector->addWarning('If the fare-used tax VAT is set, then the value (total) must also be set for.'); } if (!$this->date) { $messagesCollector->addWarning('The refund date is not set.'); } elseif (!validDate($this->date)) { $messagesCollector->addWarning('The refund date is not valid.'); } elseif ($this->date>\Engine\DateTime::create('+1 day')->formatDateIso()) { $messagesCollector->addWarning('The refund date cannot be in the future.'); } } public function getMatchedFormOfPayment($idExternalSystem) { if ($idExternalSystem) { $matchedId = \App\Config\ImportedOrders_Matches::getInstance()->getOfferFormOfPayment($idExternalSystem, $this->formOfPayment); if ($matchedId) { return $matchedId; } } $CFG = \Engine\Loader_Cfg::getInstance()->getGlobal(); if (in_array($this->formOfPayment, $CFG['offers']['formOfPaymentList'])) { return $this->formOfPayment; } return null; } }