<?php
namespace Modules\Admin\ExportData\Cashings;

class View_Utils_FormExport extends \App\Mvc\View_Utils_FormAbstract
{
	/**
	 *
	 * {@inheritDoc}
	 * @see \App\Mvc\View_Utils_FormAbstract::getForm()
	 */
	public function getForm()
	{

		$form = \Engine\Form\General::create();
		$fieldset = \Engine\Form\Container\Fieldset::create($this->lang['export']['fieldset']['criteria']);
		$form->addContainer($fieldset);

		$docTypeFld = new \App\Form\Input\Select_CashingDocType($this->lang['fields']['docType'], 'docType', $this->values['docType']);
		$docTypeFld->showDefaultOption();
		$docTypeFld->setDefaultOptionText($this->lang['list']['filters']['searchAll']);
		$fieldset->addElement($docTypeFld);

		$officeFld = new \App\Form\Input\Select_AgencyOffice($this->lang['fields']['idOffice'], 'idOffice', $this->values['idOffice']);
		$officeFld->showDefaultOption();
		$officeFld->setDefaultOptionText($this->lang['list']['filters']['searchAll']);
		$officeFld->setPossibleValues($officeFld->getPossibleValues());
		$fieldset->addElement($officeFld);

		// CASHING client type
		$clientTypesList = ['individual', 'legalEntity'];
		// invoice client type
		foreach ($clientTypesList as $clientType) {
			$clientTypes[$clientType] = $this->lang['clientTypes'][$clientType];
		}
		$clientTypeFld = new \Engine\Form\Input\Select($this->lang['fields']['clientType'], 'clientType', $this->values['clientType']);
		$clientTypeFld->showDefaultOption();
		$clientTypeFld->setDefaultOptionText($this->lang['list']['filters']['searchAll']);
		$clientTypeFld->setPossibleValues($clientTypes);
		$fieldset->addElement($clientTypeFld);

		// CASHING bank account
		$bankAccountFld = new \App\Form\Input\Select_AgencyBankAccount($this->lang['fields']['idBankAccount'], 'idBankAccount', $this->values['idBankAccount']);
		$bankAccountFld->showDefaultOption();
		$bankAccountFld->setDefaultOptionText($this->lang['list']['filters']['searchAll']);
		$bankAccountFld->setPossibleValues($bankAccountFld->getPossibleValues());
		$fieldset->addElement($bankAccountFld);

		// cashing currency
		$currencyFld = new \App\Form\Input\Select_Currency($this->lang['fields']['currency'], 'currency', $this->values['currency']);
		$currencyFld->showDefaultOption();
		$currencyFld->setDefaultOptionText($this->lang['list']['filters']['searchAll']);
		$currencyFld->setPossibleValues($currencyFld->getPossibleValues());
		$fieldset->addElement($currencyFld);

		$fieldsFieldset = \Engine\Form\Container\Fieldset::create($this->lang['insert']['exportFields']);
		$form->addContainer($fieldsFieldset);

		$fieldCodes = \App\Config\ExportData_Fields::getInstance()->getFieldsAll('cashings');
		$activeFieldCodes = \App\Config\ExportData_Fields::getInstance()->getFieldsActive('cashings');
		$inactiveFieldCodesKeys = array_diff_key($fieldCodes, $activeFieldCodes);

		foreach ($activeFieldCodes as $fieldCode => $fieldName) {
			$fieldFld = new \Engine\Form\Input\Checkbox($fieldName, 'fields['.$fieldCode.']', $this->values['fields'][$fieldCode]);
			$fieldsFieldset->addElement($fieldFld);
		}
		foreach ($inactiveFieldCodesKeys as $fieldCode => $fieldDetails) {
			$fieldFld = new \Engine\Form\Input\Checkbox($fieldDetails['name'].$this->lang['form']['fields']['inactive'], 'fields['.$fieldCode.']', $this->values['fields'][$fieldCode]);
			$fieldsFieldset->addElement($fieldFld);
		}

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