<?php

namespace Modules\Invoices\Cashings\Listing;

class View_Utils_FormFilters extends \App\Mvc\View_Utils_FormAbstract
{

	/**
	 * Creates the form for cashing docs insert/update.
	 * @see \App\Mvc\View_Utils_FormAbstract::getForm()
	 */
	public function getForm()
	{
		$_LANG = \Engine\Loader_Lang::getInstance()->getGlobal();

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

		$form=\Engine\Form\Filters::create();
		$form->setColumns(3);
        $form->showResetButton(true);
		$form->setStyle('filtersWidth', '100');

		// doc date
		$fld=new \Engine\Form\Input\DateInterval($this->lang['index']['filters']['docDate'], 'filters[docDate]', $fieldsValues['docDate']);
		$fld
   			->setValidatorParam('denyOpenIntervals', true)
   			->setValidatorParam('maxDifference', $this->cfg['listingParams']['filters']['docDate']['maxDifference'])
   			->setMandatory();
		$form->addElement($fld);

		// doc series
		$fld=new \App\Form\Input\Select_DocumentSeries($this->lang['index']['filters']['series'], 'filters[idSeries]', $fieldsValues['idSeries']);
		$fld->showDefaultOption(true)->setDefaultOptionText($this->globalLang['defaultSelectValue']['any']);
		$fld->setDocTypesFilter( array_keys( \App\Config\IssueDocuments::getInstance()->getCashingDocsList() ) );
		$form->addElement($fld);

		// doc date
		$fld=new \Engine\Form\Input\Text($this->lang['index']['filters']['docNo'], 'filters[docNumber]', $fieldsValues['docNumber']);
		$form->addElement($fld);

		// doc user
		$fld=new \App\Form\Input\Autocomplete_OfficeAndUser($this->lang['index']['filters']['docResp'], 'filters[idOfficeUser]', $fieldsValues['idOfficeUser']);
		$form->addElement($fld);

		// doc type
		$fld=new \App\Form\Input\Select_CashingDocType($this->lang['index']['filters']['docType'], 'filters[docType]', $fieldsValues['docType']);
		$fld->showDefaultOption(true)->setDefaultOptionText($this->globalLang['defaultSelectValue']['all']);
		$form->addElement($fld);

		// doc currency
		$fld=new \App\Form\Input\Select_Currency($this->lang['index']['filters']['docCurr'], 'filters[currency]', $fieldsValues['currency']);
		$fld->showDefaultOption(true)->setDefaultOptionText($this->globalLang['defaultSelectValue']['all']);
		$form->addElement($fld);

		// doc voided
		$fld=new \Engine\Form\Input\Select($this->lang['index']['filters']['voided'], 'filters[voided]', $fieldsValues['voided']);
		$fld->setPossibleValues([
			'all' => 		$this->globalLang['defaultSelectValue']['all'],
			'notVoided' => 	$this->lang['index']['filters']['voided0'],
			'voided' => 	$this->lang['index']['filters']['voided1']]
		);
		$form->addElement($fld);

		// doc issued
		$fld=new \Engine\Form\Input\Select($this->lang['index']['filters']['issued'], 'filters[issued]', $fieldsValues['issued']);
		$fld->setPossibleValues([
			'all' => 		$this->globalLang['defaultSelectValue']['all'],
			'notIssued' => 	$this->lang['index']['filters']['issued0'],
			'issued' => 	$this->lang['index']['filters']['issued1']]
		);
		$form->addElement($fld);

		// doc blocked
		$fld=new \Engine\Form\Input\Select($this->lang['index']['filters']['blocked'], 'filters[blocked]', $fieldsValues['blocked']);
		$fld->setPossibleValues([
			'all' => 			$this->globalLang['defaultSelectValue']['all'],
			'notBlocked' => 	$this->lang['index']['filters']['blocked0'],
			'blocked' => 		$this->lang['index']['filters']['blocked1']]);
		$form->addElement($fld);

		// inv date
		$fld=new \Engine\Form\Input\DateInterval($this->lang['index']['filters']['invDate'], 'filters[invDate]', $fieldsValues['invDate']);
		$form->addElement($fld);

		// inv number
		$fld=new \Engine\Form\Input\Text($this->lang['index']['filters']['invNo'], 'filters[invNumber]', $fieldsValues['invNumber']);
		$form->addElement($fld);

		// invoice id(s)
		$idInvoices = new \Engine\Form\Input\Text($this->lang['index']['filters']['idInvoices'], 'filters[idInvoices]', $fieldsValues['idInvoices']);
		$idInvoices->setTooltip($this->lang['index']['filters']['invoicesTooltip']);
		$form->addElement($idInvoices);

		// doc bank account
		$fld=new \App\Form\Input\Select_AgencyBankAccount($this->lang['index']['filters']['ba'], 'filters[idBankAccount]', $fieldsValues['idBankAccount']);
		$fld->showDefaultOption(true)->setDefaultOptionText($this->globalLang['defaultSelectValue']['any']);
		$form->addElement($fld);

		// document imported
		$fld=new \Engine\Form\Input\Select($this->lang['index']['filters']['documentImported'], 'filters[documentImported]', $fieldsValues['documentImported']);
		$fld->showDefaultOption();
		$fld->setPossibleValues([
				'yes' 	=> $_LANG['yes'],
				'no' 	=> $_LANG['no'],
		]);
		$form->addElement($fld);

		// id imported doc
		$idImpDoc = new \Engine\Form\Input\Text($this->lang['index']['filters']['idImpDoc'], 'filters[idImpDoc]', $fieldsValues['idImpDoc']);
		$form->addElement($idImpDoc);

		// text filter
		$fld=new \Engine\Form\Input\Text($this->lang['index']['filters']['text'], 'filters[text]', $fieldsValues['text']);
		$fld->setTooltip($this->lang['index']['filters']['textTooltip']);
		$form->addElement($fld);

		// document add date
		$fld = new \Engine\Form\Input\DateInterval($this->lang['index']['filters']['docAddDate'], 'filters[docAddDate]', $fieldsValues['docAddDate']);
		$form->addElement($fld);

		// doc id
		$idDoc = new \Engine\Form\Input\Text($this->lang['index']['filters']['idDoc'], 'filters[id]', $fieldsValues['id']);
		$form->addElement($idDoc);

		// customer
		$fld = new \App\Form\Input\Autocomplete_Customer($this->lang['index']['filters']['customer'], 'filters[customer]', $fieldsValues['customer']);
		$fld->setFilters('hideDuplicates', 1);
		$form->addElement($fld);

		// corporate
		$fld = new \App\Form\Input\Autocomplete_Corporate($this->lang['index']['filters']['corporate'], 'filters[corporate]', $fieldsValues['corporate']);
		$fld->setFilters('hideDuplicates', 1);
		$form->addElement($fld);

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

	}

}

