<?php
namespace Modules\Admin\Config\Services\Advanced\Offer;

class View_Utils_FormAdmin extends \App\Mvc\View_Utils_FormAbstract
{

	/**
	 * (non-PHPdoc)
	 * @see \App\Mvc\View_Utils_FormAbstract::getForm()
	 */
	public function getForm()
	{

		$form = \Engine\Form\General::create();

		// OFFER CURRENCY  FIELDSET ///////////////////////////////////////////////////////////////
		$fieldset = \Engine\Form\Container\Fieldset::create($this->lang['index']['fieldsets']['offerCurrencies']);
		$form->addContainer($fieldset);

		// offer currency
		$currency = new \App\Form\Input\Select_Currency($this->lang['index']['formFields']['offerCurrency'], 'defaultDetails[offerCurrency]', $this->values['defaultDetails']['offerCurrency']);
		$currency->setStyle('width', 200);
		$currency->setMandatory();
		$currency->setTooltip($this->lang['index']['tooltips']['defaultCurrency']);
		$fieldset->addElement($currency);

		// service fee currency
		$serviceFeeCurrency=new \App\Form\Input\Select_Currency($this->lang['index']['formFields']['serviceFeeCurrency'], 'defaultDetails[serviceFeeCurrency]', $this->values['defaultDetails']['serviceFeeCurrency']);
		$serviceFeeCurrency->setStyle('width', 200);
		$serviceFeeCurrency->setMandatory();
		$serviceFeeCurrency->setTooltip($this->lang['index']['tooltips']['serviceFeeCurrency']);
		$fieldset->addElement($serviceFeeCurrency);

		// total currency
		$totalCurrency = new \App\Form\Input\Select_Currency($this->lang['index']['formFields']['totalCurrency'], 'defaultDetails[totalCurrency]', $this->values['defaultDetails']['totalCurrency']);
		$totalCurrency->setStyle('width', '200');
		$totalCurrency->setMandatory();
		$totalCurrency->setTooltip($this->lang['index']['tooltips']['totalCurrency']);
		$fieldset->addElement($totalCurrency);

		// currency type
		$currencyType=new \App\Form\Input\Select_CurrencyType($this->lang['index']['formFields']['currencyType'], 'defaultDetails[currencyType]', $this->values['defaultDetails']['currencyType']);
		$currencyType->setStyle('width', '100');
		$currencyType->setMandatory();
		$currencyType->setTooltip($this->lang['index']['formFields']['currencyType']);
		$fieldset->addElement($currencyType);

		// OFFER DETAILS FIELDSET /////////////////////////////////////////////////////////////////
		$fieldset = \Engine\Form\Container\Fieldset::create($this->lang['index']['fieldsets']['offerDetails']);
		$form->addContainer($fieldset);

		// row types
		$clientTypes=new \Engine\Form\Input\Checkboxes($this->lang['index']['formFields']['clientType'], 'clientType', $this->values['clientType']);
		$clientTypes->setPossibleValues([
			'customers'		=> $this->lang['index']['titles']['customers'],
			'corporates' 	=> $this->lang['index']['titles']['corporates'],
		]);
		$clientTypes->setMandatory();
		$fieldset->addElement($clientTypes);


		// OFFER VAT FIELDSET /////////////////////////////////////////////////////////////////////
		$fieldset = \Engine\Form\Container\Fieldset::create($this->lang['index']['fieldsets']['offerVat']);
		$form->addContainer($fieldset);

		// SUPPLIER
		$vatSuppPercent = new \Engine\Form\Input\Text($this->lang['index']['formFields']['supplierPercent'], 'vatDetails[supplier][percent]', $this->values['vatDetails']['supplier']['percent']);
		$vatSuppPercent->setStyle('width', '50');
		$vatSuppPercent->setCustomHTML('% ');
		$vatSuppPercent->setValidatorParam('type', 'float')
			->setValidatorParam('minValue', -1)
			->setValidatorParam('maxValue', 100)
			->setValidatorParam('allowedValues', ['0','-1']);
		$vatSuppPercent->setTooltip($this->lang['index']['tooltips']['supplierPercent']);
		$fieldset->addElement($vatSuppPercent);

		$vatSuppIncluded = new \Engine\Form\Input\Checkbox($this->lang['index']['formFields']['supplierIncluded'], 'vatDetails[supplier][included]', $this->values['vatDetails']['supplier']['included']);
		$fieldset->addElement($vatSuppIncluded);

		$vatSuppPercent->setControlledElements(['0' => [$vatSuppIncluded]], 'enable');

		// COMMISSION
		$vatCommissionPercent=new \Engine\Form\Input\Text($this->lang['index']['formFields']['commPercent'], 'vatDetails[commission][percent]', $this->values['vatDetails']['commission']['percent']);
		$vatCommissionPercent->setStyle('width', '50');
		$vatCommissionPercent->setCustomHTML('% ');
		$vatCommissionPercent->setValidatorParam('type', 'float')
			->setValidatorParam('minValue', 0)
			->setValidatorParam('maxValue', 100)
			->setValidatorParam('allowedValues', ['0']);
		$vatCommissionPercent->setTooltip($this->lang['index']['tooltips']['commPercent']);
		$fieldset->addElement($vatCommissionPercent);

		// included
		$vatCommissionIncluded=new \Engine\Form\Input\Checkbox($this->lang['index']['formFields']['commIncluded'], 'vatDetails[commission][included]', $this->values['vatDetails']['commission']['included']);
		$fieldset->addElement($vatCommissionIncluded);

		$vatCommissionPercent->setControlledElements(['0' => [$vatCommissionIncluded]], 'enable');

		// SERVICE FEE
		$vatServiceFeePercent=new \Engine\Form\Input\Text($this->lang['index']['formFields']['serviceFeePercent'], 'vatDetails[serviceFee][percent]', $this->values['vatDetails']['serviceFee']['percent']);
		$vatServiceFeePercent->setStyle('width', '50');
		$vatServiceFeePercent->setCustomHTML('% ');
		$vatServiceFeePercent->setValidatorParam('type', 'float')
			->setValidatorParam('minValue', 0)
			->setValidatorParam('maxValue', 100)
			->setValidatorParam('allowedValues', ['0']);

		$vatServiceFeePercent->setTooltip($this->lang['index']['tooltips']['serviceFeePercent']);
		$fieldset->addElement($vatServiceFeePercent);

		// included
		$vatServiceFeeIncluded=new \Engine\Form\Input\Checkbox($this->lang['index']['formFields']['serviceFeeIncluded'], 'vatDetails[serviceFee][included]', $this->values['vatDetails']['serviceFee']['included']);
		$fieldset->addElement($vatServiceFeeIncluded);

		$vatServiceFeePercent->setControlledElements(['0' => [$vatServiceFeeIncluded]], 'enable');

		// DISCOUNT
		$vatDiscountPercent=new \Engine\Form\Input\Text($this->lang['index']['formFields']['discountPercent'], 'vatDetails[discount][percent]', $this->values['vatDetails']['discount']['percent']);
		$vatDiscountPercent->setStyle('width', '50');
		$vatDiscountPercent->setCustomHTML('% ');
		$vatDiscountPercent->setValidatorParam('type', 'float')
			->setValidatorParam('minValue', 0)
			->setValidatorParam('maxValue', 100)
			->setValidatorParam('allowedValues', ['0']);
		$vatDiscountPercent->setTooltip($this->lang['index']['tooltips']['discountPercent']);
		$fieldset->addElement($vatDiscountPercent);

		// included
		$vatDiscountIncluded=new \Engine\Form\Input\Checkbox($this->lang['index']['formFields']['discountIncluded'], 'vatDetails[discount][included]', $this->values['vatDetails']['discount']['included']);
		$fieldset->addElement($vatDiscountIncluded);

		$vatDiscountPercent->setControlledElements(['0' => [$vatDiscountIncluded]], 'enable');

		// TAX
		$vatTaxPercent=new \Engine\Form\Input\Text($this->lang['index']['formFields']['taxPercent'], 'vatDetails[tax][percent]', $this->values['vatDetails']['tax']['percent']);
		$vatTaxPercent->setStyle('width', '50');
		$vatTaxPercent->setCustomHTML('% ');
		$vatTaxPercent->setValidatorParam('type', 'float')
			->setValidatorParam('minValue', -1)
			->setValidatorParam('maxValue', 100)
			->setValidatorParam('allowedValues', ['0','-1']);
		$vatTaxPercent->setTooltip($this->lang['index']['tooltips']['taxPercent']);
		$fieldset->addElement($vatTaxPercent);

		// included
		$vatTaxIncluded=new \Engine\Form\Input\Checkbox($this->lang['index']['formFields']['taxIncluded'], 'vatDetails[tax][included]', $this->values['vatDetails']['tax']['included']);
		$fieldset->addElement($vatTaxIncluded);

		$vatTaxPercent->setControlledElements(['0' => [$vatTaxIncluded]], 'enable');

		$form->addElement(new \Engine\Form\Input\Hidden('', $this->submitButtonName, 1));

		return $form;
	}

}