<?php
$availableTableColumns = array_keys($tableColumns);
// PREPROCESS FILTERS /////////////////////////////////////////////////////////////////////////////
// cleanup dates
$reportFilters['clientInv_invoiceDate']['startDate'] = standard2mysqlDateConversion($reportFilters['clientInv_invoiceDate']['startDate']);
$reportFilters['clientInv_invoiceDate']['endDate'] = standard2mysqlDateConversion($reportFilters['clientInv_invoiceDate']['endDate']);

$reportFilters['suppInv_invoiceDate']['startDate'] = standard2mysqlDateConversion($reportFilters['suppInv_invoiceDate']['startDate']);
$reportFilters['suppInv_invoiceDate']['endDate'] = standard2mysqlDateConversion($reportFilters['suppInv_invoiceDate']['endDate']);

// cleanup offer start date
if ($reportFilters['clientInv_offerStartDate']['startDate']) {
	$reportFilters['clientInv_offerStartDate']['startDate'] = standard2mysqlDateConversion($reportFilters['clientInv_offerStartDate']['startDate'])." 00:00:00";
}
if ($reportFilters['clientInvv_offerStartDate']['endDate']) {
	$reportFilters['clientInv_offerStartDate']['endDate'] = standard2mysqlDateConversion($reportFilters['clientInv_offerStartDate']['endDate'])." 23:59:59";
}

$reportFilters['suppInv_checkInDate']['startDate'] = standard2mysqlDateConversion($reportFilters['suppInv_checkInDate']['startDate']);
$reportFilters['suppInv_checkInDate']['endDate'] = standard2mysqlDateConversion($reportFilters['suppInv_checkInDate']['endDate']);

// cleanup responsible user
list($reportFilters['inv_respUserOffice']['idOffice'], $reportFilters['inv_respUserOffice']['idUser']) = explode("|", $reportFilters['inv_respUserOffice']['id']);

try {

	// EXCUTE MAIN SQLs ---------------------------------------------------------------------------
	include(__DIR__."/reportData_executeSQL_clientInvoices.php");
	include(__DIR__."/reportData_executeSQL_supplierInvoices.php");

	// FILL IN OTHER FIELDS -----------------------------------------------------------------------
	include(__DIR__."/reportData_otherFields.php");

	// LOOP RECORDS -------------------------------------------------------------------------------
	include(__DIR__."/reportData_loopRecords.php");

} catch (\DBException $e) {
	killReport("Could not run SQL in report. SQL error: ".$e->getMessage());
} catch (\Exception $e) {
	killReport("Could not process report. Error: ".$e->getMessage());
}
