<?php
namespace Modules\Admin\KamSalesTargets;

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

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

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

		// year (2020 > +2 years in the future)
		$fld = new \Engine\Form\Input\Select($this->lang['index']['filters']['year'], 'filters[year]', $fieldsValues['year']);
		$start = 2020;
		$end   = TODAY_YEAR+2;
		for ($y=$start; $y<=$end; $y++) {
			$fld->setPossibleValue($y, $y);
		}
		$fld->showDefaultOption();
		$form->addElement($fld);

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