/**
* Get a combined array with time recordings and expenses to export.
*
* @param int $start Time from which to take entries into account.
* @param int $end Time until which to take entries into account.
* @param array $projects Array of project IDs to filter by.
* @param int $filter_cleared (-1: show all, 0:only cleared 1: only not cleared) entries
* @param bool $short_form should the short form be created
* @return array with time recordings and expenses chronologically sorted
*/
function invoice_get_data($start, $end, $projects, $filter_cleared, $short_form)
{
global $database;
$limitCommentSize = true;
$results = array();
// --------------------------------------------------------------------------------
// timesheet entries
$timeSheetEntries = $database->get_timeSheet($start, $end, null, null, $projects, null, false, false, $filter_cleared);
foreach ($timeSheetEntries as $entry) {
// active recordings will be omitted
if ($entry['end'] == 0) {
continue;
}
$arr = ext_invoice_empty_entry();
$arr['type'] = 'timeSheet';
$arr['desc'] = $entry['activityName'];
$arr['start'] = $entry['start'];
$arr['end'] = $entry['end'];
$arr['hour'] = $entry['duration'] / 3600;
$arr['fDuration'] = $entry['formattedDuration'];
// @deprecated use duration instead
$arr['duration'] = $entry['duration'];
$arr['timestamp'] = $entry['start'];
$arr['amount'] = $entry['wage'];
$arr['description'] = $entry['description'];
$arr['rate'] = $entry['rate'];
$arr['comment'] = $entry['comment'];
$arr['username'] = $entry['userName'];
$arr['useralias'] = $entry['userAlias'];
$arr['location'] = $entry['location'];
$arr['trackingNr'] = $entry['trackingNumber'];
$arr['projectID'] = $entry['projectID'];
$arr['projectName'] = $entry['projectName'];
$arr['projectComment'] = $entry['projectComment'];
invoice_add_to_array($results, $arr, $short_form);
}
// --------------------------------------------------------------------------------
// if expenses extension is used, load expenses as well
if (file_exists('../ki_expenses/private_db_layer_mysql.php')) {
include_once '../ki_expenses/private_db_layer_mysql.php';
$expenses = get_expenses($start, $end, null, null, $projects, false, false, -1, $filter_cleared);
foreach ($expenses as $entry) {
$arr = ext_invoice_empty_entry();
$arr['type'] = 'expense';
$arr['desc'] = $entry['designation'];
$arr['start'] = $entry['timestamp'];
$arr['end'] = $entry['timestamp'];
$arr['hour'] = null;
$arr['fDuration'] = $entry['multiplier'];
// @deprecated use duration instead
$arr['duration'] = $entry['multiplier'];
$arr['timestamp'] = $entry['timestamp'];
$arr['amount'] = sprintf("%01.2f", $entry['value'] * $entry['multiplier']);
$arr['description'] = $entry['designation'];
$arr['rate'] = $entry['value'];
$arr['comment'] = $entry['comment'];
$arr['username'] = $entry['userName'];
$arr['useralias'] = $entry['userAlias'];
$arr['location'] = null;
$arr['trackingNr'] = null;
$arr['projectID'] = $entry['projectID'];
$arr['projectName'] = $entry['projectName'];
$arr['projectComment'] = $entry['projectComment'];
// @deprecated expenses only: will be removed in the future, can be fetched otherwise
$arr['activityName'] = $entry['designation'];
// @deprecated expenses only: will be removed in the future, can be fetched otherwise
$arr['multiplier'] = $entry['multiplier'];
// @deprecated expenses only: will be removed in the future, can be fetched otherwise
$arr['value'] = $entry['value'];
invoice_add_to_array($results, $arr, $short_form);
}
}
$allEntries = array();
foreach ($results as $entry) {
if ($limitCommentSize) {
$entry['comment'] = Kimai_Format::addEllipsis($entry['comment'], 150);
}
// FIXME use date_format_3 instead
$entry['date'] = date("m/d/Y", $entry['timestamp']);
$allEntries[] = $entry;
}
return $allEntries;
}