<?php
loadcontroller('base/module');
class ControllerShippingfretedinamico extends ControllerBaseModule 
{
	protected $referencePathFile = 'shipping/fretedinamico';
	private $error = array();

	public function loadData() {
		
		$this->document->setTitle($this->language->get('heading_title'));
		$this->load->model('setting/setting');
		
		$this->load->helper('ftr_geral');

		$this->dataVue['ftr_geral'] = new ftr_geral();
		
		$this->dataVue['Type_Status'] = Type_Status::getEnumList();
        $this->dataVue['Type_DsimDnao'] = Type_DsimDnao::getEnumList();

		$this->dataVue['configurations'] = $this->model_setting_setting->getSetting('fretedinamico');

		
		
	}

	protected function loadModel()
    {
        parent::loadModel();
        $this->load->model('localisation/order_status');
    }

	protected function saveSetting()
	{

		$this->load->language('shipping/fretedinamico');

		$response = [];

		if (!$this->user->hasPermission('modify', 'shipping/fretedinamico')) {
			$this->error['warning'] = $this->language->get('error_permission');
		}

		

         $this->load->model('setting/setting');
		$this->model_setting_setting->editSetting('fretedinamico', $this->request->post);

		if (isset($this->request->post['fretedinamico_valcalc'])) {
			$this->request->post['fretedinamico_valcalc'] = ftr_geral::removeMaskToDouble($this->request->post['fretedinamico_valcalc']);
			$this->model_setting_setting->editSetting('fretedinamico', $this->request->post);
		}
		
		return $this->response->setOutputJson($response);
	}

	protected function validate() {
	 
		$this->loadLanguage();
		$this->load->type('tipocomum');



		
		extract($this->request->post);

		$errors = [];
	

      $errors = $this->validate->execute([
		'fretedinamico_opcao' => [
			'value' => $fretedinamico_opcao,
			'validates' => ['isEmpty']
		],
		'fretedinamico_subopcao' => [
			'value' => $fretedinamico_subopcao,
			'validates' => ['isEmpty']
		],
		'fretedinamico_valvisu' => [
			'value' => $fretedinamico_valvisu,
			'validates' => ['isEmpty']
		],
		'fretedinamico_valcalc' => [
			'value' => $fretedinamico_valcalc,
			'validates' => ['isEmpty']
		],
	]);
	 
		return $errors;
	}

}
