/**
* @TODO
*
* @param <type> $name
* @param <type> $params
* @return string
*/
public static function getTableData($name, $params)
{
switch ($name) {
case 'hours':
$time_data = $GLOBALS['injector']->getInstance('Hermes_Driver')->getHours($params);
$subtotal_column = null;
if ($search_mode = $GLOBALS['session']->get('hermes', 'search_mode')) {
switch ($search_mode) {
case 'date':
$subtotal_column = 'date';
break;
case 'employee':
$subtotal_column = 'employee';
break;
case 'client':
$subtotal_column = '_client_name';
break;
case 'jobtype':
$subtotal_column = '_type_name';
break;
case 'costobject':
$subtotal_column = '_costobject_name';
break;
}
$clients = Hermes::listClients();
$column = array();
foreach ($time_data as $key => $row) {
if (empty($row['client'])) {
$time_data[$key]['_client_name'] = _("no client");
} elseif (isset($clients[$row['client']])) {
$time_data[$key]['_client_name'] = $clients[$row['client']];
} else {
$time_data[$key]['_client_name'] = $row['client'];
}
if (!is_null($subtotal_column)) {
$column[$key] = $time_data[$key][$subtotal_column] . $time_data[$key]['date'];
}
}
if (!is_null($subtotal_column)) {
array_multisort($column, SORT_ASC, $time_data);
}
}
$total_hours = 0.0;
$total_billable_hours = 0.0;
$subtotal_hours = 0.0;
$subtotal_billable_hours = 0.0;
$subtotal_control = null;
$result['data'] = array();
foreach ($time_data as $k => $vals) {
// Initialize subtotal break value.
if (is_null($subtotal_control) && isset($vals[$subtotal_column])) {
$subtotal_control = $vals[$subtotal_column];
}
if (!empty($subtotal_column) && $vals[$subtotal_column] != $subtotal_control) {
Hermes_Api::renderSubtotals($result['data'], $subtotal_hours, $subtotal_billable_hours, $subtotal_column == 'date' ? strftime("%m/%d/%Y", $subtotal_control) : $subtotal_control);
$subtotal_hours = 0.0;
$subtotal_billable_hours = 0.0;
$subtotal_control = $vals[$subtotal_column];
}
// Set up edit/delete icons.
if (Hermes::canEditTimeslice($vals['id'])) {
$edit_link = Horde::url('entry.php', true)->add(array('id' => $vals['id'], 'url' => Horde::selfUrl(true, true, true)));
$vals['icons'] = Horde::link($edit_link, _("Edit Entry")) . Horde::img('edit.png', _("Edit Entry"), '') . '</a>';
if (empty($vals['submitted'])) {
$vals['checkbox'] = '<input type="checkbox" name="item[' . htmlspecialchars($vals['id']) . ']" checked="checked" />';
} else {
$vals['checkbox'] = '';
}
}
// Add to totals.
$subtotal_hours += (double) $vals['hours'];
$total_hours += (double) $vals['hours'];
if ($vals['billable']) {
$subtotal_billable_hours += (double) $vals['hours'];
$total_billable_hours += (double) $vals['hours'];
}
// Localize hours.
$vals['hours'] = sprintf('%.02f', $vals['hours']);
$result['data'][] = $vals;
}
if (!empty($subtotal_column)) {
Hermes_Api::renderSubtotals($result['data'], $subtotal_hours, $subtotal_billable_hours, $subtotal_column == 'date' ? strftime("%m/%d/%Y", $subtotal_control) : $subtotal_control);
}
// Avoid a divide by zero.
if ($total_hours == 0.0) {
$billable_pct = 0.0;
} else {
$billable_pct = round($total_billable_hours / $total_hours * 100.0);
}
$descr = _("Billable Hours") . ' (' . $billable_pct . '%)';
$result['footer'] = array();
$result['footer'][] = array('hours' => sprintf('%.02f', $total_billable_hours), 'description' => $descr);
$descr = _("Non-billable Hours") . ' (' . (100.0 - $billable_pct) . '%)';
$result['footer'][] = array('hours' => sprintf('%.02f', $total_hours - $total_billable_hours), 'description' => $descr);
$result['footer'][] = array('hours' => sprintf('%.02f', $total_hours), 'description' => _("Total Hours"), 'approval' => '<div id="approval">' . _("Approved By:") . ' ________________________________________ ' . ' </div>');
break;
}
return $result;
}