<?php
namespace Modules\Invoices\BalancesList;

class View_Utils_FormFilters extends \App\Mvc\View_Utils_FormAbstract
{
	/**
	 * Creates the form for document series filters.
	 * @see \App\Mvc\View_Utils_FormAbstract::getForm()
	 */
	public function getForm()
	{
		$fieldsValues = $this->values['listingParams']->getFilters();

		$form=\Engine\Form\Filters::create();
		$form->setColumns(3);

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

		// generation
		$generation = new \Engine\Form\Input\Select($this->lang['index']['filters']['generation'], 'filters[generation]', $fieldsValues['generation']);
		$generation->setPossibleValues([
			'' => 			$this->lang['index']['filters']['all'],
			'manual' => 	$this->lang['index']['generation']['manual'],
			'auto' => 		$this->lang['index']['generation']['auto'],
		]);
		$form->addElement($generation);

		// confirmed
		$confirmed = new \Engine\Form\Input\Select($this->lang['index']['filters']['confirmed'], 'filters[confirmed]', $fieldsValues['confirmed']);
		$confirmed->setPossibleValues([
			'' => 				$this->lang['index']['filters']['all'],
			'confirmed' => 		$this->lang['index']['confirmedStatus']['confirmed'],
			'notConfirmed' => 	$this->lang['index']['confirmedStatus']['notConfirmed'],
		]);
		$form->addElement($confirmed);

		// responsible user
		$responsibleUser = new \App\Form\Input\Autocomplete_User($this->lang['index']['filters']['responsibleUser'], 'filters[responsibleUser]', $fieldsValues['responsibleUser']);
		$form->addElement($responsibleUser);

		// balance status
		$balanceStatus = new \Engine\Form\Input\Select($this->lang['index']['filters']['balanceStatus'], 'filters[balanceStatus]', $fieldsValues['balanceStatus']);
		$balanceStatus->setPossibleValues([
			'' => 		$this->lang['index']['filters']['all'],
			'final'=> 	$this->lang['index']['balanceStatus']['final'],
			'partial'=> $this->lang['index']['balanceStatus']['partial'],
		]);
		$form->addElement($balanceStatus);

		// balance type
		$balanceType = new \Engine\Form\Input\Select($this->lang['index']['filters']['balanceType'], 'filters[balanceType]', $fieldsValues['balanceType']);
		$balanceType->setPossibleValues([
			'' =>		$this->lang['index']['filters']['all'],
			'simple' => $this->lang['index']['balanceType']['simple'],
			'bulk' => 	$this->lang['index']['balanceType']['bulk'],
		]);
		$form->addElement($balanceType);

		// text
		$text = new \Engine\Form\Input\TextWithElements($this->lang['index']['filters']['text'], "filters[text]", $fieldsValues['text']);
		$text->addElement(\Engine\Form\Input\Select::create("", "filters[searchMode]", $fieldsValues['searchField'], [
			'starts' => 	$this->lang['index']['filters']['searchMode']['starts'],
			'contains' => 	$this->lang['index']['filters']['searchMode']['contains'],
			'exact' => 		$this->lang['index']['filters']['searchMode']['exact'],
		]),'post');
		$text->addElement(\Engine\Form\Input\Select::create("", "filters[searchField]", $fieldsValues['searchMode'], [
			'balanceNumber' => 	$this->lang['index']['filters']['searchFields']['balanceNumber'],
			'balanceCode' => 	$this->lang['index']['filters']['searchFields']['balanceCode'],
			'balanceName' => 	$this->lang['index']['filters']['searchFields']['balanceName'],
		]),'post');
		$form->addElement($text);

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

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


		// reset button
		$form->showResetButton(true);

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