<?php
namespace Modules\Admin\KamSalesTargets;

class View_Utils_FormAdmin extends \App\Mvc\View_Utils_FormAbstract
{
	/**
	 * (non-PHPdoc)
	 * @see \App\Mvc\View_Utils_FormAbstract::getForm()
	 */
	public function getForm()
	{

		// NEW FORM
		$form = \Engine\Form\General::create();

		// NEW CONTAINER
		$fieldset = \Engine\Form\Container\Fieldset::create($this->lang['index']['form']['fieldsetGeneral']);
		$form->addContainer($fieldset);

		// KAM
		$el = new \App\Form\Input\Autocomplete_User($this->lang['index']['formFields']['idKam'], 'idKam', $this->values['idKam']);
		$el->setMandatory();
		if ($this->controller->getAction()=='update') {
			$el->setDisabled();
		}
		$fieldset->addElement($el);

		// YEAR (-1 year -> +2 years in the future)
		if ($this->controller->getAction()=='update') {
			$el = new \Engine\Form\Input\Text($this->lang['index']['formFields']['year'], 'year', $this->values['year']);
			$el->setDisabled();
		}
		else {
			$el = new \Engine\Form\Input\Select($this->lang['index']['formFields']['year'], 'year', $this->values['year']);
			$start = TODAY_YEAR-1;
			$end   = TODAY_YEAR+2;
			for ($y=$start; $y<=$end; $y++) {
				$el->setPossibleValue($y, $y);
			}
			$el->showDefaultOption();
		}
		$el->setMandatory();
		$fieldset->addElement($el);

		// SALES TARGETS PER MONTH
		$fieldset = \Engine\Form\Container\Fieldset::create('SALES TARGETS');
		$form->addContainer($fieldset);

		for ($i=1; $i<=12; $i++) {
			$el = new \Engine\Form\Input\Text($this->globalLang['date']['month']['long'][$i], 'salesTarget['.$i.']', $this->values['salesTarget'][$i]);
			$el->setCustomHTML(\App\Config\Currencies::getInstance()->getDefaultCurrency());
			$fieldset->addElement($el);
		}

		// MEETINGS TARGETS PER MONTH
		$fieldset = \Engine\Form\Container\Fieldset::create('MEETINGS TARGETS');
		$form->addContainer($fieldset);

		for ($i=1; $i<=12; $i++) {
			$el = new \Engine\Form\Input\Text($this->globalLang['date']['month']['long'][$i], 'contactsTarget['.$i.']', $this->values['contactsTarget'][$i]);
			$el->setCustomHTML('meetings');
			$fieldset->addElement($el);
		}


		if ($this->controller->getAction()=='update') {
			$el = new \Engine\Form\Input\Hidden(null, 'idKam', $this->values['idKam']);
			$fieldset->addElement($el);
			$el = new \Engine\Form\Input\Hidden(null, 'year', $this->values['year']);
			$fieldset->addElement($el);
		}


		// submit button
		$form->addElement(new \Engine\Form\Input\Hidden('', $this->submitButtonName, 1));

		return $form;
	}
}