<?php
namespace Modules\Admin\AutoProcessRules\BulkUpdate\InvoiceInsert;

class View_Utils_FormAdmin extends \App\Mvc\View_Utils_FormAbstract
{

	public function getForm()
	{

		// global cfgs
		$_LANG = \App\Loader_Lang::getInstance()->getAll();

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

		// INFO FIELDSET
		$fieldset = \Engine\Form\Container\Fieldset::create();
		$form->addContainer($fieldset);

		$formInfo = new \Engine\Form\Input\Label();
		$formInfo->setStyle('noLabel', true);
		$formInfo->setDetails($this->lang['index']['formFields']['formInfo']);
		$fieldset->addElement($formInfo);

		$values = [];
		foreach ($this->values['rulesIds'] as $id) {
			$entName = \Entity\AutoProcessRule::select($id)->name;
			if ($entName) {
				$values[] = '<span class="remoteLoadLink" onclick="RemoteLoad.loadEntity(this, \'autoProcessRule\', '.$id.')">'.$entName.'</span>';
			}
			else {
				$values[] = '<span class="remoteLoadLink" onclick="RemoteLoad.loadEntity(this, \'autoProcessRule\', '.$id.')">#'.$id.'</span>';
			}
		}

		$info = new \Engine\Form\Input\Label();
		$info->setStyle('noLabel', true);
		$info->setValue(sprintf($this->lang['index']['formFields']['info'], count($this->values['rulesIds']), implode(', ', $values)));
		$fieldset->addElement($info);


		// INVOICE RESPONSIBLE USER
		$fieldsetRespUser = \Engine\Form\Container\Fieldset::create($this->lang['index']['formFields']['fieldset']['responsibleUser']);
		$form->addContainer($fieldsetRespUser);

		$selectRespUser = new \Engine\Form\Input\Select($this->lang['index']['formFields']['selectResponsibleUser'], 'selectRespUser', $this->values['selectRespUser']);
		$selectRespUser->setPossibleValues([
			'skip'		=> $this->lang['index']['formFields']['selectValues']['skip'],
			'update' 	=> $this->lang['index']['formFields']['selectValues']['update'],
		]);
		$fieldsetRespUser->addElement($selectRespUser);

		$respUser = new \App\Form\Input\Autocomplete_User($this->lang['index']['formFields']['responsibleUser'], 'respUser', $this->values['respUser']);
		$respUser->setMandatory();
		$fieldsetRespUser->addElement($respUser);

		$selectRespUser->setControlledElements( ['update'=> [$respUser]]);

		// INVOICE CURRENCY
		$fieldsetInvCurr = \Engine\Form\Container\Fieldset::create($this->lang['index']['formFields']['fieldset']['invoiceCurrency']);
		$form->addContainer($fieldsetInvCurr);

		$selectInvCurr = new \Engine\Form\Input\Select($this->lang['index']['formFields']['selectInvoiceCurrency'], 'selectInvCurr', $this->values['selectInvCurr']);
		$selectInvCurr->setPossibleValues([
			'skip'		=> $this->lang['index']['formFields']['selectValues']['skip'],
			'update' 	=> $this->lang['index']['formFields']['selectValues']['update'],
		]);
		$fieldsetInvCurr->addElement($selectInvCurr);

		$invCurr = new \App\Form\Input\Select_Currency($this->lang['index']['formFields']['invoiceCurrency'], 'invoiceCurrency', $this->values['invoiceCurrency']);
		$currenciesList['offerCurrency'] = $this->lang['index']['formFields']['offerCurrency'];
		$currenciesList = array_merge($currenciesList, $invCurr->getPossibleValues());
		$invCurr->setPossibleValues($currenciesList);
		$invCurr->showDefaultOption(true);
		$invCurr->setMandatory();
		$fieldsetInvCurr->addElement($invCurr);

		$selectInvCurr->setControlledElements( ['update'=> [$invCurr]]);

		// INVOICE SERIES
		$fieldsetInvSeries = \Engine\Form\Container\Fieldset::create($this->lang['index']['formFields']['fieldset']['invoiceSeries']);
		$form->addContainer($fieldsetInvSeries);

		$selectInvSeries = new \Engine\Form\Input\Select($this->lang['index']['formFields']['selectInvoiceSeries'], 'selectInvSeries', $this->values['selectInvSeries']);
		$selectInvSeries->setPossibleValues([
			'skip'		=> $this->lang['index']['formFields']['selectValues']['skip'],
			'update' 	=> $this->lang['index']['formFields']['selectValues']['update'],
		]);
		$fieldsetInvSeries->addElement($selectInvSeries);

		$invSeries = new \App\Form\Input\Select_DocumentSeries($this->lang['index']['formFields']['invoiceSeries'], 'idInvoiceSeries', $this->values['idInvoiceSeries']);
		$invSeries->showDefaultOption(true);
		$invSeries->setDocTypesFilter(['invoice']);
		$invSeries->setMandatory();
		$fieldsetInvSeries->addElement($invSeries);

		$selectInvSeries->setControlledElements( ['update'=> [$invSeries]]);

		// FORM OF PAYMENT
		$fieldsetFormOfPayment = \Engine\Form\Container\Fieldset::create($this->lang['index']['formFields']['fieldset']['formOfPayment']);
		$form->addContainer($fieldsetFormOfPayment);

		$selectFormOfPayment = new \Engine\Form\Input\Select($this->lang['index']['formFields']['selectFormOfPayment'], 'selectFormOfPayment', $this->values['selectFormOfPayment']);
		$selectFormOfPayment->setPossibleValues([
			'skip'		=> $this->lang['index']['formFields']['selectValues']['skip'],
			'update' 	=> $this->lang['index']['formFields']['selectValues']['update'],
		]);
		$fieldsetFormOfPayment->addElement($selectFormOfPayment);

		$formOfPayment = new \App\Form\Input\Select_FormOfPayment($this->lang['index']['formFields']['formOfPayment'], 'formOfPayment', $this->values['formOfPayment']);
		$formOfPayment->showDefaultOption(true);
		$fieldsetFormOfPayment->addElement($formOfPayment);

		$selectFormOfPayment->setControlledElements( ['update'=> [$formOfPayment]]);

		// TEMPORARY INVOICE
		$fieldsetTempInvoice = \Engine\Form\Container\Fieldset::create($this->lang['index']['formFields']['fieldset']['temporaryInvoice']);
		$form->addContainer($fieldsetTempInvoice);

		$selectTempInv = new \Engine\Form\Input\Select($this->lang['index']['formFields']['selectTemporaryInvoice'], 'selectTempInv', $this->values['selectTempInv']);
		$selectTempInv->setPossibleValues([
			'skip'		=> $this->lang['index']['formFields']['selectValues']['skip'],
			'update' 	=> $this->lang['index']['formFields']['selectValues']['update'],
		]);
		$fieldsetTempInvoice->addElement($selectTempInv);

		$temporaryInv = new \Engine\Form\Input\Checkbox($this->lang['index']['formFields']['temporaryInvoice'], 'temporaryInvoice', $this->values['temporaryInvoice']);
		$fieldsetTempInvoice->addElement($temporaryInv);

		$selectTempInv->setControlledElements( ['update'=> [$temporaryInv]]);

		// INVOICE CURRENCY EXCHANGE TYPE
		$fieldsetCurrExchangeType = \Engine\Form\Container\Fieldset::create($this->lang['index']['formFields']['fieldset']['currencyType']);
		$form->addContainer($fieldsetCurrExchangeType);

		$selectCurrType = new \Engine\Form\Input\Select($this->lang['index']['formFields']['selectCurrencyType'], 'selectCurrType', $this->values['selectCurrType']);
		$selectCurrType->setPossibleValues([
			'skip'		=> $this->lang['index']['formFields']['selectValues']['skip'],
			'update' 	=> $this->lang['index']['formFields']['selectValues']['update'],
		]);
		$fieldsetCurrExchangeType->addElement($selectCurrType);

		$currencyType = new \App\Form\Input\Select_CurrencyType($this->lang['index']['formFields']['currencyType'], 'invoiceRowsCurrencyType', $this->values['invoiceRowsCurrencyType']);
		$currencyType->showDefaultOption(true);
		$currencyType->setDefaultOptionText($this->lang['index']['formFields']['offerCurrencyExchangeType']);
		$currencyType->setTooltip($_LANG['Admin']['AutoProcessRules']['formFields']['InvoiceInsert']['currencyTypeTooltip']);
		$fieldsetCurrExchangeType->addElement($currencyType);

		$selectCurrType->setControlledElements( ['update'=> [$currencyType]]);

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


	}

}