<?php
$availableTableColumns = array_keys($tableColumns);

// PREPROCESS FILTERS /////////////////////////////////////////////////////////////////////////////
// cleanup dates
$reportFilters['docDate']['startDate'] = standard2mysqlDateConversion($reportFilters['docDate']['startDate']);
$reportFilters['docDate']['endDate'] = standard2mysqlDateConversion($reportFilters['docDate']['endDate']);

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

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

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

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

// cleanup financial status
$reportFilters['invFinStatus'] = array_keys((array)$reportFilters['invFinStatus']);

// cleanup invoice supplier filter
$reportFilters['invSupplier'] = $reportFilters['invSupplier']['id'];

$reportFilters['docType'] = (array)$reportFilters['docType'];

// PREPARE EXTRA FILTERS
$reportExtraFilters = [];
if ($reportFilters['invSupplier']) {
	$reportExtraFilters['invSupplier'] = \Entity\Supplier::select($reportFilters['invSupplier'])->fullDuplicatedSuppliersGroup;
}

try {

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

	// FILL IN OTHER FIELDS -----------------------------------------------------------------------
	include(__DIR__."/reportData_otherFields.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());
}
