<?php

$availableTableColumns = array_keys($tableColumns);

// PREPROCESS FILTERS /////////////////////////////////////////////////////////////////////////////
if (is_array($reportFilters['docGroupType']) and $reportFilters['docGroupType']['d']) {
	$reportFilters['docGroupType'] = $reportFilters['docGroupType']['d'];
}
if (!$reportFilters['docGroupType'] or !in_array($reportFilters['docGroupType'], ['noGroup', 'groupByPivotDoc'])) {
	$reportFilters['docGroupType'] = "noGroup";
}

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

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

try {
	// EXCUTE MAIN SQLs ---------------------------------------------------------------------------
	include(__DIR__."/reportData_executeSQL.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());
}
