<?php
namespace Modules\Admin\Config\ImportedDocuments\Compensate;

class View_Utils_FormAdmin extends \App\Mvc\View_Utils_FormAbstract
{

	/**
	 * Creates the form for balances VATs update.
	 * @see \App\Mvc\View_Utils_FormAbstract::getForm()
	 */
	public function getForm()
	{

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

		// fieldset service and offer
		$fieldsetSeviceAndOffer = \Engine\Form\Container\Fieldset::create($this->lang['form']['serviceAndOffer']);

		// service code
		$fld = new \App\Form\Input\Select_Service($this->lang['form']['fields']['serviceDetails']['serviceCode']['label'], 'service_code', $this->values['service_code']);
		$fld->setMandatory();
		$fld->showDefaultOption();
		$fieldsetSeviceAndOffer->addElement($fld);

		// offer supplier
		$fld = new \App\Form\Input\Autocomplete_Supplier($this->lang['form']['fields']['serviceDetails']['offerIdSupplier']['label'], 'offer_idSupplier', $this->values['offer_idSupplier']);
		$fld->setMandatory();
		$fieldsetSeviceAndOffer->addElement($fld);
		$form->addContainer($fieldsetSeviceAndOffer);

		// fieldset invoices
		$fieldsetInvoices = \Engine\Form\Container\Fieldset::create($this->lang['form']['invoices']);

		// invoice series
		$fld = new \App\Form\Input\Select_DocumentSeries($this->lang['form']['fields']['serviceDetails']['invoiceIdSeries']['label'], 'invoiceInsert_idSeries', $this->values['invoiceInsert_idSeries']);
		$fld->setMandatory();
		$fld->showDefaultOption();
		$fld->setDocTypesFilter(['invoice']);
		$fieldsetInvoices->addElement($fld);

		// invoice form of payment
		$fld = new \App\Form\Input\Select_FormOfPayment($this->lang['form']['fields']['serviceDetails']['invoiceFormOfPayment']['label'], 'invoiceInsert_formOfPayment', $this->values['invoiceInsert_formOfPayment']);
		$fld->showDefaultOption();
		$fieldsetInvoices->addElement($fld);

		// invoice agency bank account
		$fld = new \App\Form\Input\Select_AgencyBankAccount($this->lang['form']['fields']['serviceDetails']['invoiceIdBankAccount']['label'], 'invoiceInsert_idBankAccount', $this->values['invoiceInsert_idBankAccount']);
		$fld->showDefaultOption();
		$fieldsetInvoices->addElement($fld);

		$form->addContainer($fieldsetInvoices);

		// fieldset invoice issue
		$fieldsetInvoiceIssue = \Engine\Form\Container\Fieldset::create($this->lang['form']['invoiceIssue']);

		// automatically issue invoices
		$fld = new \Engine\Form\Input\Checkbox($this->lang['form']['fields']['invoice']['issueInvoice'], 'invoiceIssue_active', $this->values['invoiceIssue_active']);
		$fieldsetInvoiceIssue->addElement($fld);

		// document type
		$fld = new \App\Form\Input\Select_DocumentType($this->lang['form']['fields']['invoice']['documentType'], 'invoiceIssue_docType', $this->values['invoiceIssue_docType']);
		$fld->setPivot('invoice');
		$fld->showDefaultOption(true);
		$fieldsetInvoiceIssue->addElement($fld);

		// document template
		$fld = new \App\Form\Input\Select_DocumentTemplate($this->lang['form']['fields']['invoice']['documentTemplate'], 'invoiceIssue_idTemplate', $this->values['invoiceIssue_idTemplate']);
		$fld->showDefaultOption(true);
		$fld->setDocTypeFilter(['invoice']);
		$fieldsetInvoiceIssue->addElement($fld);

		// invoice series
		$fld = new \App\Form\Input\Select_DocumentSeries($this->lang['form']['fields']['invoice']['invoiceSeries'], 'invoiceIssue_idSeries', $this->values['invoiceIssue_idSeries']);
		$fld->showDefaultOption(true);
		$fld->setDocTypesFilter(['invoice']);
		$fieldsetInvoiceIssue->addElement($fld);

		$form->addContainer($fieldsetInvoiceIssue);

		// fieldset credit note issue
		$fieldsetCreditNoteIssue = \Engine\Form\Container\Fieldset::create($this->lang['form']['crediNoteIssue']);

		// automatically issue credit notes
		$fld = new \Engine\Form\Input\Checkbox($this->lang['form']['fields']['creditNote']['creditNoteIssue'], 'creditNoteIssue_active', $this->values['creditNoteIssue_active']);
		$fieldsetCreditNoteIssue->addElement($fld);

		// document type
		$fld = new \App\Form\Input\Select_DocumentType($this->lang['form']['fields']['creditNote']['documentType'], 'creditNoteIssue_docType', $this->values['creditNoteIssue_docType']);
		$fld->showDefaultOption(true);
		$fld->setPivot('invoice');
		$fieldsetCreditNoteIssue->addElement($fld);

		// document template
		$fld = new \App\Form\Input\Select_DocumentTemplate($this->lang['form']['fields']['creditNote']['documentTemplate'], 'creditNoteIssue_idTemplate', $this->values['creditNoteIssue_idTemplate']);
		$fld->showDefaultOption(true);
		$fld->setDocTypeFilter(['creditNote']);
		$fieldsetCreditNoteIssue->addElement($fld);

		// credit note series
		$fld = new \App\Form\Input\Select_DocumentSeries($this->lang['form']['fields']['creditNote']['creditNoteSeries'], 'creditNoteIssue_idSeries', $this->values['creditNoteIssue_idSeries']);
		$fld->showDefaultOption(true);
		$fld->setDocTypesFilter(['creditNote']);
		$fieldsetCreditNoteIssue->addElement($fld);

		$form->addContainer($fieldsetCreditNoteIssue);

		// fieldset cancel
		$fieldsetCancel = \Engine\Form\Container\Fieldset::create($this->lang['form']['cancel']);

		// automatically cancel order
		$fld = new \Engine\Form\Input\Checkbox($this->lang['form']['fields']['serviceDetails']['cancelOrder']['label'], 'cancel_active', $this->values['cancel_active']);
		$fieldsetCancel->addElement($fld);

		// service cancel reason
		$fld = new \App\Form\Input\Select_ServiceCancelReason($this->lang['form']['fields']['serviceDetails']['cancelServiceReason']['label'], 'cancel_serviceReason', $this->values['cancel_serviceReason']);
		$fld->showDefaultOption();
		$fieldsetCancel->addElement($fld);

		$form->addContainer($fieldsetCancel);

		// submit button
		$form->addElement(new \Engine\Form\Input\Hidden(null, 'save', 1));
		$form->addButton(new \Engine\Form\Button\Submit('save'));

		return $form;
	}
}