<?php

$filters=$S['balanceInvoices']['client'];
$filtersOK=1;

// INVOICE DATE ///////////////////////////////////////////////////////////////////////////////////
$filters['invoiceStartDateMysql']=standard2mysqlDateConversion($filters['invoiceStartDate']);
$filters['invoiceEndDateMysql']=standard2mysqlDateConversion($filters['invoiceEndDate']);
if (!$filters['invoiceStartDateMysql'] or !$filters['invoiceEndDateMysql']) {
	$filtersOK=0;
	$showMessage['warning']=$_LANG['invoices']['balanceInvoices']['clientInvoicesList']['warnings']['noInvoicesInterval'];
}
if ($filters['invoiceStartDateMysql'] and $filters['invoiceEndDateMysql']) {
	if ($filters['invoiceStartDateMysql']>$filters['invoiceEndDateMysql']) {
		$filtersOK=0;
		$showMessage['warning']=$_LANG['invoices']['balanceInvoices']['clientInvoicesList']['warnings']['invoiceStartDateAfterEndDate'];
	}
}

// CLIENT TYPE ////////////////////////////////////////////////////////////////////////////////////
if ($filters['clientType']!='corp' and $filters['clientType']!='cust') {
	$filters['clientType']='';
}

// INVOICE DUE DATE ///////////////////////////////////////////////////////////////////////////////
$filters['dueStartDateMysql']=standard2mysqlDateConversion($filters['dueStartDate']);
$filters['dueEndDateMysql']=standard2mysqlDateConversion($filters['dueEndDate']);
if ($filters['dueStartDateMysql'] and $filters['dueEndDateMysql']) {
	if ($filters['dueStartDateMysql']>$filters['dueEndDateMysql']) {
		$filtersOK=0;
		$showMessage['warning']=$_LANG['invoices']['balanceInvoices']['clientInvoicesList']['warnings']['dueStartDateAfterEndDate'];
	}
}

// SERVICE START DATE /////////////////////////////////////////////////////////////////////////////
$filters['serviceStartDateMysql']=standard2mysqlDateConversion($filters['serviceStartDate']);
$filters['serviceEndDateMysql']=standard2mysqlDateConversion($filters['serviceEndDate']);
if ($filters['serviceStartDateMysql'] and $filters['serviceEndDateMysql']) {
	if ($filters['serviceStartDateMysql']>$filters['serviceEndDateMysql']) {
		$filtersOK=0;
		$showMessage['warning']=$_LANG['invoices']['balanceInvoices']['clientInvoicesList']['warnings']['servicesStartDateAfterEndDate'];
	}
}

// BREAK SPECIAL IDS (separated by '|') ///////////////////////////////////////////////////////////

// RESPONSIBLE USER & OFFICE ---
$resp=explode('|', $filters['invoiceIdOfficeUser']);
$filters['invoiceIdOffice']=$resp[0];
$filters['invoiceIdUser']=$resp[1];

// CONVERT ID RESERVATION ---
$resList=explodeClean(",", $filters['idReservation']);
foreach($resList as $thisRes) {
	$thisRes=trim($thisRes);
	if ($thisRes) $filters['idReservationsNormal'][]=\App\Utils\Db\TablesUtils::getInstance()->switchIdReservationConversion($thisRes, 'normal');
}


// if some problems found...
if (!$filtersOK) {
	$OK=0;
}


?>