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

// PREPROCESS FILTERS /////////////////////////////////////////////////////////////////////////////
// TODO: this is the final format for the date filter /////////////////////////////////////////////
// contact datetime
if ($reportFilters['contactDate']['startDate']) {
	$reportFilters['contactDate']['start'] = standard2mysqlDateConversion($reportFilters['contactDate']['startDate']);
}
if ($reportFilters['contactDate']['endDate']) {
	$reportFilters['contactDate']['end'] = standard2mysqlDateConversion($reportFilters['contactDate']['endDate']);
}

// add date datetime
if ($reportFilters['addDate']['startDate']) {
	$reportFilters['addDate']['start'] = standard2mysqlDateConversion($reportFilters['addDate']['startDate']);
}
if ($reportFilters['addDate']['endDate']) {
	$reportFilters['addDate']['end'] = standard2mysqlDateConversion($reportFilters['addDate']['endDate']);
}

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


// PREPARE EXTRA FILTERS
$reportExtraFilters = [];

if ($reportFilters['corporate']['id']) {
	$reportExtraFilters['corporate'] = \Entity\Corporate::select($reportFilters['corporate']['id'])->fullDuplicatedCorporatesGroup;
}

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