<?php
 include("_config/addCfg.php"); include("_includes/addInc.php"); $OK=1; $idService=$R['idService']; if ($idService) { if ( (is_numeric($idService) and $idService<=10000000) or (!is_numeric($idService) and substr($idService, 1)<=10000000) ) { $OK=0; $showMessage['warning'] = $_LANG['invoices']['balanceInvoices']['balanceManagement']['warnings']['invalidServiceId']; } } $idSupplierRow=$R['idSupplierRow']; if ($idSupplierRow and $idSupplierRow<=10000000) { $OK=0; $showMessage['warning'] = $_LANG['invoices']['balanceInvoices']['balanceManagement']['warnings']['invalidSupplierRowId']; } if (isset($R['destroyBalance'])) { $S['manualBalance']=array(); } if (!isset($S['manualBalance'])) { $S['manualBalance']['idServices']=array(); $S['manualBalance']['idSupplierRows']=array(); } if ($OK and $idService) { if ($CFG['manualBalances']['allowBulkMode']) { if ($S['manualBalance']['idServices'][$idService]) { unset($S['manualBalance']['idServices'][$idService]); } else { $S['manualBalance']['idServices'][$idService]=true; } } else { if ($S['manualBalance']['idServices'][$idService]) { $S['manualBalance']['idServices']=array(); } else { $S['manualBalance']['idServices']=array(); $S['manualBalance']['idServices'][$idService]=true; } } } if ($OK and $idSupplierRow) { if ($S['manualBalance']['idSupplierRows'][$idSupplierRow]) { unset($S['manualBalance']['idSupplierRows'][$idSupplierRow]); } else { $S['manualBalance']['idSupplierRows'][$idSupplierRow]=true; } } $supplierInvoiceRows=array(); if (is_array($S['manualBalance']['idSupplierRows']) and count($S['manualBalance']['idSupplierRows']) ) { $servicesTranslations=servicesCfg_servicesTranslations(); foreach($S['manualBalance']['idSupplierRows'] as $thisRowId=>$active) { $tableMonth=\App\Utils\Db\TablesUtils::getInstance()->getYmFromId($thisRowId); $getRowDetailsSQL="
			SELECT (`rows`.priceValue+`rows`.vatValue) AS totalValue, `rows`.serviceCode, inv.currency, inv.id AS idInvoice
			FROM `$DBTSupplierInvoiceRows$tableMonth` AS `rows`, `$DBTSupplierInvoices$tableMonth` AS inv
			WHERE `rows`.id='".$thisRowId."' AND inv.id=`rows`.idInvoice
		"; $getRowDetailsArr=$db->GetRow($getRowDetailsSQL); if (!is_array($getRowDetailsArr)) { writeLog("Could not get supplier invoice row details. SQL: ".$getRowDetailsSQL, 'events', 10); } $getRowDetailsArr['serviceName']=$servicesTranslations[$getRowDetailsArr['serviceCode']]; $supplierInvoiceRows[$thisRowId]=$getRowDetailsArr; } } $services=array(); if (is_array($S['manualBalance']['idServices']) and count($S['manualBalance']['idServices']) ) { foreach($S['manualBalance']['idServices'] as $thisServiceId=>$active) { if (is_numeric($thisServiceId)) { $tableMonth=\App\Utils\Db\TablesUtils::getInstance()->getYmFromId($thisServiceId); $getServiceDetailsSQL="SELECT service, offerTotal, offerTotalCurrency FROM `$DBTReservationServices$tableMonth` WHERE id='".$thisServiceId."'"; $serviceDetails=$db->GetRow($getServiceDetailsSQL); if (!is_array($serviceDetails)) { writeLog("Could not get service details. SQL: ".$getServiceDetailsSQL, 'events', 10); } $services[$thisServiceId]['idServiceOriginal']=$thisServiceId; $services[$thisServiceId]['serviceName']=$serviceDetails['service']; $services[$thisServiceId]['totalValue']=$serviceDetails['offerTotal']; $services[$thisServiceId]['currency']=$serviceDetails['offerTotalCurrency']; } else { $thisServiceId=substr($thisServiceId, 1); $tableMonth=\App\Utils\Db\TablesUtils::getInstance()->getYmFromId($thisServiceId); $getServiceDetailsSQL="SELECT service FROM `$DBTReservationServices$tableMonth` WHERE id='".$thisServiceId."'"; $serviceDetails=$db->GetRow($getServiceDetailsSQL); if (!is_array($serviceDetails)) { writeLog("Could not get service details. SQL: ".$getServiceDetailsSQL, 'events', 10); } $services['R'.$thisServiceId]['idServiceOriginal']=$thisServiceId; $services['R'.$thisServiceId]['serviceName']=$serviceDetails['service']; $services['R'.$thisServiceId]['refund']=true; $services['R'.$thisServiceId]['totalValue']=0; } } } if (!$S['manualBalance']['idServices'] and !$supplierInvoiceRows) { $showMessage['info'] = $_LANG['invoices']['balanceInvoices']['balanceManagement']['infos']['chooseServicesAndRow']; } $smarty->assign('clientListMode', $S['balanceInvoices']['client']['mode']); $smarty->assign('services', $services); $smarty->assign('supplierInvoiceRows', $supplierInvoiceRows); $smarty->display("balanceManagement.tpl"); ?>