<?php
namespace Modules\Bsp\Settlement;

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(2);

		// bsp date
		$ticketDate = new \Engine\Form\Input\DateInterval($this->lang['index']['filters']['ticketDate'], 'filters[ticketDate]', $fieldsValues['ticketDate']);
		$ticketDate->setTooltip($this->lang['index']['filters']['ticketDate_warning']);
		$form->addElement($ticketDate);

		// office
		$idOffice = new \App\Form\Input\Autocomplete_Office($this->lang['index']['filters']['idOffice'], 'filters[idOffice]', $fieldsValues['idOffice']);
		if (!\App\UserAccess\CurrentUserAccessFast::getInstance()->hasAccessToOption('Modules/Bsp/Listing-completeAccess')) {
			$idOffice->setDisabled();
		}
		$form->addElement($idOffice);

		// match status
		$balanceStatus = new \Engine\Form\Input\Checkboxes($this->lang['index']['filters']['balanceStatus'], 'filters[balanceStatus]', $fieldsValues['balanceStatus']);
		$balanceStatus->setPossibleValues([
			'matched' => 			$this->lang['index']['filters']['balanceStatus_matched'],
			'unmatched' => 			$this->lang['index']['filters']['balanceStatus_unmatched'],
			'diff:operation' => 	$this->lang['index']['filters']['balanceStatus_diff:operation'],
			'diff:supplier' => 		$this->lang['index']['filters']['balanceStatus_diff:supplier'],
			'diff:supplierData' => 	$this->lang['index']['filters']['balanceStatus_diff:supplierData'],
			'diff:price' => 		$this->lang['index']['filters']['balanceStatus_diff:price'],
			'others' => 			$this->lang['index']['filters']['balanceStatus_others'],
		]);
		$form->addElement($balanceStatus);

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


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

		// service id, ther id & others
		$fld = new \Engine\Form\Input\ElementWithElements($this->lang['index']['filters']['id']);
		$fld->setTooltip($this->lang['index']['filters']['id_tooltip']);
		$fld->addElement( \Engine\Form\Input\Text::create(null, 'filters[id]', $fieldsValues['id']), 'main' );
		$fld->addElement( \Engine\Form\Input\Select::create(null, 'filters[idType]', $fieldsValues['idType'], [
			'importedServiceId' => 	$this->lang['index']['filters']['id_importedServiceId'],
			'importedOrderId' => 	$this->lang['index']['filters']['id_importedOrderId'],
			'TINAServiceId' => 		$this->lang['index']['filters']['id_TINAServiceId'],
			'TINAOrderId' => 		$this->lang['index']['filters']['id_TINAOrderId'],
		]), 'post');
		$fld->setStyle('renderMode', 'inline');
		$form->addElement($fld);

		// manual status
		$operationalStatus = new \Engine\Form\Input\Checkboxes($this->lang['index']['filters']['operationalStatus'], 'filters[operationalStatus]', $fieldsValues['operationalStatus']);
		$operationalStatus->setPossibleValues([
			'' => 					$this->lang['index']['filters']['operationalStatus_none'],
			'inProgress' => 		$this->lang['index']['filters']['operationalStatus_inProgress'],
			'closed' => 			$this->lang['index']['filters']['operationalStatus_closed'],
		]);
		$form->addElement($operationalStatus);


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

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