<?php
namespace Modules\Admin\Config\Services\Advanced\Offer; class Controller extends \App\Mvc\Controller\Form\PopupAbstract { protected function initialize() { parent::initialize(); $this->actionsCfg['index'] = [ 'checkSection' => 'Modules/Admin/Config/Services/Advanced', 'checkOption' => false ]; } protected function getDefaultFormData($R) { $formData = []; $formData['calculation'] = $R['calculation']; $formData['serviceCode'] = $R['serviceCode']; $formData['location'] = $R['location']; $clientType = \App\Config\Services_Calculations_ClientTypes::getAdmin()->getClientType($R['serviceCode'], $R['location'], $R['calculation']); $offerDeafultDetails = \App\Config\Services_Calculations_OfferDefaults::getAdmin()->getCalculationDetails($R['serviceCode'], $R['location'], $R['calculation']); $offerVATDetails = \App\Config\Services_Calculations_OfferVat::getAdmin()->getCalculationDetails($R['serviceCode'], $R['location'], $R['calculation']); $formData['defaultDetails'] = $offerDeafultDetails; if ($clientType == 'customers' or $clientType == 'corporates') { $formData['clientType'] = [$clientType]; } else { $formData['clientType'] = ['customers', 'corporates']; } $formData['vatDetails'] = $offerVATDetails; return $formData; } protected function processFormData(Array $R, \App\MessagesCollector $msgs) { $calcCode = $R['serviceCode'].'_'.$R['location'].'_'.$R['calculation']; \App\Config\Services_Calculations_OfferDefaults::getAdmin()->set($calcCode, $R['defaultDetails']); if (is_array($R['clientType']) and count($R['clientType'])==2) { $clientType='both'; } elseif($R['clientType']['customers']) { $clientType='customers'; } elseif ($R['clientType']['corporates']) { $clientType='corporates'; } else { $clientType=null; } $setVatDetails=$R['vatDetails']; foreach (['supplier', 'commission', 'serviceFee', 'discount', 'tax'] as $offRow) { if (!$setVatDetails[$offRow]) { $setVatDetails[$offRow]= ['percent' => 0, 'included' => false]; } } try { \App\Config\Services_Calculations_ClientTypes::getAdmin()->set($calcCode, $clientType); \App\Config\Services_Calculations_OfferVat::getAdmin()->setCalculationDetails($R['serviceCode'], $R['location'], $R['calculation'], $setVatDetails); $msgs->addSuccess($this->lang['index']['messages']['updatedOK']); return true; } catch (\App\Config\MessageException $e) { $msgs->addError($e->getMessage()); } } protected function preRenderOperations(\App\Mvc\ViewAbstract $view, array $formData) { $_LANG = \App\Loader_Lang::getInstance()->getGlobal(); $servName = \App\Config\Services_Basic::getInstance()->getServiceName($formData['serviceCode']); $servLoc = $_LANG['locations']['countriesCriteria']['long'][$formData['location']]; $servCalc = \App\Config\Services_Calculations::getAdmin()->getServiceLocationCalculationName($formData['serviceCode'], $formData['location'], $formData['calculation']); $view->setPageTitle(sprintf($this->lang['index']['pageTitle'], $servName, $servLoc, $servCalc)); } } 