/** * 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; }
/** * Get a combined array with time recordings and expenses to export. * * FIXME this method is the worst nightmare i have seen in month - kevin * * @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 $expense_ext_available, $database; $limit = false; $reverse_order = false; $limitCommentSize = true; $filter_refundable = -1; $timeSheetEntries = array(); $expenses = array(); $timeSheetEntries = $database->get_timeSheet($start, $end, null, null, $projects, null, $limit, $reverse_order, $filter_cleared); if ($expense_ext_available) { $expenses = get_expenses($start, $end, null, null, $projects, $limit, $reverse_order, $filter_refundable, $filter_cleared); } $result_arr = array(); $timeSheetEntries_index = 0; $expenses_index = 0; $keys = array('type', 'desc', 'hour', 'fduration', 'amount', 'date', 'description', 'rate', 'comment', 'username', 'useralias', 'location'); while ($timeSheetEntries_index < count($timeSheetEntries) && $expenses_index < count($expenses)) { $arr = array(); foreach ($keys as $key) { $arr[$key] = null; } if (!$reverse_order && $timeSheetEntries[$timeSheetEntries_index]['start'] > $expenses[$expenses_index]['timestamp'] || $reverse_order && $timeSheetEntries[$timeSheetEntries_index]['start'] < $expenses[$expenses_index]['timestamp']) { if ($timeSheetEntries[$timeSheetEntries_index]['end'] != 0) { // active recordings will be omitted $arr['type'] = 'timeSheet'; $arr['location'] = $timeSheetEntries[$timeSheetEntries_index]['location']; $arr['desc'] = $timeSheetEntries[$timeSheetEntries_index]['activityName']; $arr['hour'] = $timeSheetEntries[$timeSheetEntries_index]['duration'] / 3600; $arr['fDuration'] = $timeSheetEntries[$timeSheetEntries_index]['formattedDuration']; $arr['amount'] = $timeSheetEntries[$timeSheetEntries_index]['wage']; $arr['date'] = date("m/d/Y", $timeSheetEntries[$timeSheetEntries_index]['start']); $arr['description'] = $timeSheetEntries[$timeSheetEntries_index]['description']; $arr['rate'] = $timeSheetEntries[$timeSheetEntries_index]['rate']; $arr['trackingNr'] = $timeSheetEntries[$timeSheetEntries_index]['trackingNumber']; if ($limitCommentSize) { $arr['comment'] = Format::addEllipsis($timeSheetEntries[$timeSheetEntries_index]['comment'], 150); } else { $arr['comment'] = $timeSheetEntries[$timeSheetEntries_index]['comment']; } $arr['username'] = $timeSheetEntries[$timeSheetEntries_index]['userName']; $arr['useralias'] = $timeSheetEntries[$timeSheetEntries_index]['userAlias']; } $timeSheetEntries_index++; } else { $arr['type'] = 'expense'; $arr['desc'] = $expenses[$expenses_index]['designation']; $arr['multiplier'] = $expenses[$expenses_index]['multiplier']; $arr['value'] = $expenses[$expenses_index]['value']; $arr['fDuration'] = $expenses[$expenses_index]['multiplier']; $arr['amount'] = sprintf("%01.2f", $expenses[$expenses_index]['value'] * $expenses[$expenses_index]['multiplier']); $arr['date'] = date("m/d/Y", $expenses[$expenses_index]['timestamp']); $arr['rate'] = $expenses[$expenses_index]['value']; if ($limitCommentSize) { $arr['comment'] = Format::addEllipsis($expenses[$expenses_index]['comment'], 150); } else { $arr['comment'] = $expenses[$expenses_index]['comment']; } $arr['activityName'] = $expenses[$expenses_index]['designation']; $arr['username'] = $expenses[$expenses_index]['userName']; $arr['useralias'] = $expenses[$expenses_index]['userAlias']; $expenses_index++; } invoice_add_to_array($result_arr, $arr, $short_form); } // timesheet entries while ($timeSheetEntries_index < count($timeSheetEntries)) { if ($timeSheetEntries[$timeSheetEntries_index]['end'] != 0) { // active recordings will be omitted $arr = array(); foreach ($keys as $key) { $arr[$key] = null; } $arr['type'] = 'timeSheet'; $arr['location'] = $timeSheetEntries[$timeSheetEntries_index]['location']; $arr['desc'] = $timeSheetEntries[$timeSheetEntries_index]['activityName']; $arr['hour'] = $timeSheetEntries[$timeSheetEntries_index]['duration'] / 3600; $arr['fDuration'] = $timeSheetEntries[$timeSheetEntries_index]['formattedDuration']; $arr['amount'] = $timeSheetEntries[$timeSheetEntries_index]['wage']; $arr['date'] = date("m/d/Y", $timeSheetEntries[$timeSheetEntries_index]['start']); $arr['description'] = $timeSheetEntries[$timeSheetEntries_index]['description']; $arr['rate'] = $timeSheetEntries[$timeSheetEntries_index]['rate']; $arr['trackingNr'] = $timeSheetEntries[$timeSheetEntries_index]['trackingNumber']; if ($limitCommentSize) { $arr['comment'] = Format::addEllipsis($timeSheetEntries[$timeSheetEntries_index]['comment'], 150); } else { $arr['comment'] = $timeSheetEntries[$timeSheetEntries_index]['comment']; } $arr['username'] = $timeSheetEntries[$timeSheetEntries_index]['userName']; $arr['useralias'] = $timeSheetEntries[$timeSheetEntries_index]['userAlias']; invoice_add_to_array($result_arr, $arr, $short_form); } $timeSheetEntries_index++; } // expenses entries while ($expenses_index < count($expenses)) { $arr = array(); foreach ($keys as $key) { $arr[$key] = null; } $arr['type'] = 'expense'; $arr['desc'] = $expenses[$expenses_index]['designation']; $arr['multiplier'] = $expenses[$expenses_index]['multiplier']; $arr['value'] = $expenses[$expenses_index]['value']; $arr['fDuration'] = $expenses[$expenses_index]['multiplier']; $arr['amount'] = sprintf("%01.2f", $expenses[$expenses_index]['value'] * $expenses[$expenses_index]['multiplier']); $arr['date'] = date("m/d/Y", $expenses[$expenses_index]['timestamp']); $arr['rate'] = $expenses[$expenses_index]['value']; if ($limitCommentSize) { $arr['comment'] = Format::addEllipsis($expenses[$expenses_index]['comment'], 150); } else { $arr['comment'] = $expenses[$expenses_index]['comment']; } $arr['activityName'] = $expenses[$expenses_index]['designation']; $arr['username'] = $expenses[$expenses_index]['userName']; $arr['useralias'] = $expenses[$expenses_index]['userAlias']; $expenses_index++; invoice_add_to_array($result_arr, $arr, $short_form); } return $result_arr; }