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

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

		$fieldsValues = $this->values['listingParams']->getFilters();

		$form = \Engine\Form\Filters::create($this->lang['list']['filters']['title']);
		$form->setColumns(3);

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


		$officeFld = new \App\Form\Input\Select_AgencyOffice($this->lang['fields']['idOffice'], 'filters[idOffice]', $fieldsValues['idOffice']);
		$officeFld->showDefaultOption();
		$officeFld->setDefaultOptionText($this->lang['list']['filters']['searchAll']);
		$officeFld->setPossibleValues(["*"=>"*"]+$officeFld->getPossibleValues());
		$form->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'], 'filters[clientType]', $fieldsValues['clientType']);
		$clientTypeFld->showDefaultOption(true);
		$clientTypeFld->setDefaultOptionText($this->lang['list']['filters']['searchAll']);
		$clientTypeFld->setPossibleValues(array_merge(['*' => '*'], $clientTypes));
		$form->addElement($clientTypeFld);

		// bank account
		$bankAccFld = new \App\Form\Input\Select_AgencyBankAccount($this->lang['fields']['idBankAccount'], 'filters[idBankAccount]', $fieldsValues['idBankAccount']);
		$bankAccFld->showDefaultOption(true);
		$bankAccFld->setDefaultOptionText($this->lang['list']['filters']['searchAll']);
		$bankAccFld->setPossibleValues(["*"=>"*"]+$bankAccFld->getPossibleValues());
		$form->addElement($bankAccFld);

		// CASHING currency
		$currencyFld = new \App\Form\Input\Select_Currency($this->lang['fields']['currency'], 'filters[currency]', $fieldsValues['currency']);
		$currencyFld->showDefaultOption(true);
		$currencyFld->setDefaultOptionText($this->lang['list']['filters']['searchAll']);
		$currencyFld->setPossibleValues(array_merge(['*' => '*'], $currencyFld->getPossibleValues()));
		$form->addElement($currencyFld);

		// field name
		$fieldFldValues = [];
		$fieldsPossibValues = \App\Config\ExportData_Fields::getInstance()->getFieldsAll('cashings');
		foreach ($fieldsPossibValues as $fieldCode => $fieldPossibValue) {
			$active = $fieldPossibValue['active'] ? $this->lang['form']['fields']['active'] : $this->lang['form']['fields']['inactive'];
			$fieldFldValues[$fieldCode] = implode('', [$fieldPossibValue['name'], $active]);
		}

		$fieldFld = new \Engine\Form\Input\Select($this->lang['fields']['field'], 'filters[field]', $fieldsValues['field']);
		$fieldFld->showDefaultOption(true);
		$fieldFld->setDefaultOptionText($this->lang['list']['filters']['searchAll']);
		$fieldFld->setPossibleValues($fieldFldValues);
		$form->addElement($fieldFld);

		// field value
		$valueFld = new \Engine\Form\Input\Text($this->lang['fields']['value'], 'filters[value]', $fieldsValues['value']);
		$form->addElement($valueFld);

		$form->setJsCallback('MVC.listing.installedHandlers["listing"].reloadAndResetListing');
		$form->loadMissingDefaultValues($this->values['listingParams']->getDefaultFilters());
		return $form;
	}
}