<?php
 namespace Modules\Invoices\InvoiceInsert; class View_Step2 extends \App\Mvc\View_Window_GeneralAbstract { protected $renderingTemplate = ''; public function getPageTitle() { $_LANG = \App\Loader_Lang::getInstance()->getGlobal(); return $_LANG['Invoices']['InvoiceInsert']['index']['pageTitle2']; } protected function render_smarty($templateName=null) { $this->setMoreInputVars(); return parent::render_smarty($templateName); } private function setMoreInputVars() :void { $formData = $this->output['formData']; $inputs = []; $invoiceCfgs = \Entity\Invoice::loadCFG(); $inputs['series'] = new \App\Form\Input\Select_DocumentSeries(null, 'idSeries', $formData['idSeries']); $issueDocsCfgObj = \App\Config\IssueDocuments::getInstance(); $invoiceDocsList = array_filter( array_keys($issueDocsCfgObj->getInvoiceDocsList()), function ($docType) use ($issueDocsCfgObj) { return $issueDocsCfgObj->isMainDocOnPivot($docType); } ) ; $inputs['series']->setDocTypesFilter($invoiceDocsList); $inputs['series']->setIdUser(CURRENT_ID_USER); $inputs['series']->showDefaultOption(); if ($invoiceCfgs['idInvoiceSeries']['invisible']) { $inputs['series']->setDisabled(); } $inputs['series']->setWidth(130); $inputs['invoiceDate'] = new \Engine\Form\Input\Date(null, 'invoiceDate', $formData['invoiceDate']); $inputs['invoiceDate']->onChange('refreshInvoiceDueDate()'); $inputs['invoiceDate']->setWidth(130); $inputs['dueDate'] = new \Engine\Form\Input\Date(null, 'dueDate', $formData['dueDate']); if ($invoiceCfgs['dueDate']['invisible']) { $inputs['dueDate']->setDisabled(); } $inputs['dueDate']->setWidth(130); $inputs['fulfillmentDate'] = new \Engine\Form\Input\Date(null, 'fulfillmentDate', $formData['fulfillmentDate']); if ($invoiceCfgs['fulfillmentDate']['invisible']) { $inputs['fulfillmentDate']->setDisabled(); } $inputs['fulfillmentDate']->setWidth(130); $inputs['temporary'] = new \Engine\Form\Input\Checkbox(null, 'temporary', $formData['temporary']); $inputs['temporary']->setDetails('<label for="temporary"><span id="temporaryInvoiceSpan" class="temporaryInvoice '.($formData['temporary']?'temporaryChecked':'').'">'.$this->lang['index']['step2']['headerFields']['tempLabel'].'</span></label>'); $inputs['temporary']->onChange("
			if ($(this).checked) {
				$('temporaryInvoiceSpan').addClassName('temporaryChecked');
 			} else {
				$('temporaryInvoiceSpan').removeClassName('temporaryChecked');
			}
		"); $inputs['formOfPayment'] = new \App\Form\Input\Select_FormOfPayment(null, 'formOfPayment', $formData['formOfPayment']); $inputs['formOfPayment']->setMandatory( \App\Config\FormsOfPayment::getInstance()->getMandatory() ); $inputs['formOfPayment']->showDefaultOption(); if ($invoiceCfgs['formOfPayment']['invisible']) { $inputs['formOfPayment']->setDisabled(); } $inputs['formOfPayment']->setWidth(250); $inputs['bankAccount'] = new \App\Form\Input\Select_AgencyBankAccount(null, 'idBankAccount', $formData['idBankAccount']); $inputs['bankAccount']->showDefaultOption(); if ($invoiceCfgs['idBankAccount']['invisible']) { $inputs['bankAccount']->setDisabled(); } $inputs['bankAccount']->setWidth(250); $inputs['user'] = new \App\Form\Input\Autocomplete_User(null, 'user', $formData['user']); $inputs['user']->setWidth(250); $inputs['comments'] = new \Engine\Form\Input\Textarea(null, 'comments', $formData['comments']); if ($invoiceCfgs['comments']['invisible']) { $inputs['comments']->setDisabled(); } $inputs['comments']->setWidth(200); $inputs['remarks'] = new \App\Form\Input\Remarks(null, 'remarks', $formData['remarks']); $inputs['remarks']->setRemarksType('invoice'); $inputs['remarks']->setAutoExpand(false); if ($invoiceCfgs['remarks']['invisible']) { $inputs['remarks']->setDisabled(); } $inputs['remarks']->setWidth(200); $inputs['remarks']->setHeight(62); $inputs['invoiceCurrency'] = new \App\Form\Input\Select_Currency(null, 'invoiceCurrency', $formData['invoiceCurrency']); $inputs['invoiceCurrency']->onChange('enableRefreshButton()'); $inputs['roundTotal'] = new \Engine\Form\Input\Checkbox(null, 'roundTotal', $formData['roundTotal']); $inputs['roundTotal']->setCheckboxLabel($this->lang['index']['step2']['roundingLabel']); $inputs['roundTotal']->setDisabled(!\App\Config\InvoiceRounding::getInstance()->isEnabled()); $inputs['roundTotal']->onChange('enableRefreshButton()'); $descrSchemes = \App\Config\InvoiceRowsDescription::getInstance()->getSchemesName(); if (count($descrSchemes)>1) { $inputs['rowDescriptionScheme'] = new \App\Form\Input\Select_InvoiceRowDescriptionScheme(null, 'rowDescriptionScheme'); $inputs['rowDescriptionScheme']->showDefaultOption(); $inputs['rowDescriptionScheme']->onChange('enableRefreshButton()'); $inputs['rowDescriptionScheme']->setStyle('width', 250); } $inputs['corporateInsert'] = new \App\Form\Input\Autocomplete_Corporate(null, 'idCorporateInsert', ''); $inputs['corporateInsert']->setStyle('buttons', false); $inputs['corporateInsert']->setWidth(200); $inputs['corporateInsert']->onPostSelect("$('refreshField').value=1;$('mainForm').submit();"); $inputs['customerInsert'] = new \App\Form\Input\Autocomplete_Customer(null, 'idCustomerInsert', ''); $inputs['customerInsert']->setStyle('buttons', false); $inputs['customerInsert']->setWidth(200); $inputs['customerInsert']->onPostSelect("$('refreshField').value=1;$('mainForm').submit();"); $inputs['invoiceRows'] = []; $totals = ['val'=>0, 'vat'=>0, 'ttl'=>0]; if ($this->output['invoiceRows']) { $famFields = []; foreach ($this->output['invoiceRows'] as $idx=>$row) { $hiddenFld = new \Engine\Form\Input\Checkbox(null, "hidden[{$idx}]", ($row['hiddenOnRowIdx']!=-1)); if ($row['canHideInto']==-1) { $hiddenFld->setDisabled(); } $inputs['invoiceRows'][$idx]['hidden'] = $hiddenFld; $descriptionFld = new \Engine\Form\Input\Textarea(null, "description[{$idx}]", $row['description']); $inputs['invoiceRows'][$idx]['description'] = $descriptionFld; if ($row['serviceAdvanceFinalizationId'] and !$famFields[$row['serviceAdvanceFinalizationId']]) { $famFld = new \Engine\Form\Input\Select(null, "finalizeAdvanceMode[{$row['idReservationService']}]", $row['finalizeAdvanceMode']); $famFld->setPossibleValues(['total'=>$this->lang['index']['step2']['finalizeAdvMode']['total'], 'rest'=>$this->lang['index']['step2']['finalizeAdvMode']['rest']]); $famFld->onChange("enableRefreshButton();"); $inputs['invoiceRows'][$idx]['finalizeAdvanceMode'] = $famFld; $famFields[$row['serviceAdvanceFinalizationId']] = true; } $currencyTypeFld = new \App\Form\Input\Select_CurrencyType(null, "currencyType[{$idx}]", $row['currencyType']); $currencyTypeFld->setWidth(120); $currencyTypeFld->onChange("
					if ($('connectCurrencyDetails').checked) {
						cloneConnectedCurrencyTypes(this.value);
					}
					enableRefreshButton();
				"); $inputs['invoiceRows'][$idx]['currencyType'] = $currencyTypeFld; $currencyDateFld = new \Engine\Form\Input\Date(null, "currencyDate[{$idx}]", $row['currencyDate']); $currencyDateFld->setWidth(120); $currencyDateFld->onChange("
					if ($('connectCurrencyDetails').checked) {
						cloneConnectedCurrencyDates(\$F('currencyDate_{$idx}_'), \$F('currencyDate_{$idx}__title'));
					}
					enableRefreshButton();
				"); $inputs['invoiceRows'][$idx]['currencyDate'] = $currencyDateFld; $muFld = new \Engine\Form\Input\Text(null, "measureUnit[{$idx}]", $row['measureUnit']); $muFld->setWidth(40); $inputs['invoiceRows'][$idx]['measureUnit'] = $muFld; $totals['val'] += $row['printValue']; $totals['vat'] += $row['printVat']; $totals['ttl'] += $row['printValue'] + $row['printVat']; } } $firstRow = reset($this->output['invoiceRows']); $firstServiceCode = ''; if ($firstRow) { $firstServiceEnt = \Entity\Service::select($firstRow['idReservationService']); $firstServiceCode = $firstServiceEnt->chosenOffer->serviceCode; if (!$firstServiceCode) { $firstServiceCode = $firstServiceEnt->serviceCode; } } $this->setOutputVar('inputs', $inputs); $this->setOutputVar('totals', $totals); $this->setOutputVar('firstServiceCode', $firstServiceCode); } } 