<?php
 namespace App\Config; class Services_Calculations_OfferDefaults extends XmlBasicAbstract { protected $fileName=CONFIG_FILE_SERVICE_CALCULATION_OFFER_DEFAULT; protected function getAll_rawData_extractDataFromFile(\SimpleXMLElement $xml) { $return=[]; foreach($xml->service as $serviceDetails) { foreach ($serviceDetails as $calcCurrencyDetails) { $offerDetailsList = []; $offerDetailsList['offerCurrency'] = (string)$calcCurrencyDetails->offerCurrency; $offerDetailsList['serviceFeeCurrency'] = (string)$calcCurrencyDetails->serviceFeeCurrency; $offerDetailsList['totalCurrency'] = (string)$calcCurrencyDetails->totalCurrency; $offerDetailsList['currencyType'] = (string)$calcCurrencyDetails->currencyType; $return[(String)$serviceDetails['code'].'_'.(String)$calcCurrencyDetails['location'].'_'.(string)$calcCurrencyDetails['code']]=$offerDetailsList; } } return $return; } protected function save_check() { global $_LANG; foreach (Services_Calculations::getAdmin()->getAll() as $calculationCode => $calculationDetails) { if ( !$calculationDetails['deleted'] ) { if ( !Currencies::getInstance()->check($this->itemsList[$calculationCode]['offerCurrency']) ) { $this->addErrorMessage(sprintf('When setting the service offer details, the currency `%s` for service default offer is not valid for calculation type `%s` of service `%s` at location `%s` ', $this->itemsList[$calculationCode]['offerCurrency'], $calculationDetails['name'], Services_Basic::getInstance()->getServiceName($calculationDetails['serviceCode']), $_LANG['locations']['countriesCriteria']['long'][$calculationDetails['location']] )); } if ( !Currencies::getInstance()->check($this->itemsList[$calculationCode]['serviceFeeCurrency']) ) { $this->addErrorMessage(sprintf('When setting the service offer details, the currency `%s` for service default fee is not valid for calculation type `%s` of service `%s` at location `%s`', $this->itemsList[$calculationCode]['serviceFeeCurrency'], $calculationDetails['name'], Services_Basic::getInstance()->getServiceName($calculationDetails['serviceCode']), $_LANG['locations']['countriesCriteria']['long'][$calculationDetails['location']] )); } if ( !Currencies::getInstance()->check($this->itemsList[$calculationCode]['totalCurrency'] )) { $this->addErrorMessage(sprintf('When setting the service offer details, the currency `%s` for offer default total is not valid for calculation type `%s` of service `%s` at location `%s`', $this->itemsList[$calculationCode]['totalCurrency'], $calculationDetails['name'], Services_Basic::getInstance()->getServiceName($calculationDetails['serviceCode']), $_LANG['locations']['countriesCriteria']['long'][$calculationDetails['location']] )); } if ( !CurrencyTypes::getInstance()->check($this->itemsList[$calculationCode]['currencyType']) ) { $this->addErrorMessage(sprintf('When setting the service offer details, the currency type `%s` for offer default details is not valid for calculation type `%s` of service `%s` at location `%s`', $this->itemsList[$calculationCode]['currencyType'], $calculationDetails['name'], Services_Basic::getInstance()->getServiceName($calculationDetails['serviceCode']), $_LANG['locations']['countriesCriteria']['long'][$calculationDetails['location']] )); } } } } protected function save_write_do_getXml() { $xml=simplexml_load_string('<?xml version="1.0" encoding="UTF-8"?><calculationsCurrencies />'); foreach (Services_Calculations::getAdmin()->getExtendedList() as $serviceCode => $locationDetails) { $serviceObj=$xml->addChild('service'); $serviceObj['code']=$serviceCode; foreach ($locationDetails as $locationCode => $calculationDetails) { foreach ($calculationDetails as $calculationCode => $nothing) { $calcCurrencyObj=$serviceObj->addChild('calculationCurrency'); $calcCurrencyObj['location']=$locationCode; $calcCurrencyObj['code']=$calculationCode; $calcCurrencyObj->offerCurrency = $this->itemsList[$serviceCode.'_'.$locationCode.'_'.$calculationCode]['offerCurrency']; $calcCurrencyObj->serviceFeeCurrency = $this->itemsList[$serviceCode.'_'.$locationCode.'_'.$calculationCode]['serviceFeeCurrency']; $calcCurrencyObj->totalCurrency = $this->itemsList[$serviceCode.'_'.$locationCode.'_'.$calculationCode]['totalCurrency']; $calcCurrencyObj->currencyType = $this->itemsList[$serviceCode.'_'.$locationCode.'_'.$calculationCode]['currencyType']; } } } return $xml; } public function getCalculationDetails($serviceCode, $location, $calculation) { if (!$serviceCode) throw new \Exception('The service code was not set.'); if (!$location) throw new \Exception('The location code was not set.'); if (!strlen((string)$calculation)) throw new \Exception('The calculation code was not set.'); $searchKey = $serviceCode.'_'.$location.'_'.$calculation; $allCfg = $this->getAll(); return (Array)$allCfg[$searchKey]; } } 