function support_pm_plan_overview_weekly in Support Ticketing System 6
Same name and namespace in other branches
- 7 support_pm/support_pm.module \support_pm_plan_overview_weekly()
1 string reference to 'support_pm_plan_overview_weekly'
- support_pm_menu in support_pm/
support_pm.module - Implementation of hook_menu(). TODO: Include date in 'view' and 'edit' tabs
File
- support_pm/
support_pm.module, line 401 - Support Project Management. @author Jeremy Andrews <jeremy@tag1consulting.com> @package Support
Code
function support_pm_plan_overview_weekly($account) {
$output = NULL;
$week = isset($_GET['week']) ? _support_pm_first_day((int) $_GET['week']) : _support_pm_first_day(time());
// Set the page title (keep it consisten with the editing page)
drupal_set_title(t('@start - @end', array(
'@start' => format_date($week, 'medium'),
'@end' => format_date($week + 86400 * 6, 'medium'),
)));
$header = array(
'',
);
$row = array(
'<strong>' . t('Plan') . '</strong>',
);
$row2 = array(
'<strong>' . t('Actual') . '</strong>',
);
$totals = array();
$hours = array();
// TODO: Allow for 5 day weeks, etc
for ($i = 0; $i < 7; $i++) {
$date = $week + 86400 * $i;
$header[] = t('!day<br />!date', array(
'!day' => format_date($date, 'custom', 'l'),
'!date' => format_date($date, 'custom', 'M d'),
));
$day = support_pm_day_load($date, $account);
if (is_array($day[$account->uid])) {
$row[] = theme('support_pm_user_client_hours_details', $day[$account->uid]);
}
else {
$row[] = '';
}
// Add up totals
if (is_array($day[$account->uid])) {
foreach ($day[$account->uid] as $clid => $data) {
$totals['plan'][$clid] += $data->hours;
}
}
else {
if (!is_array($totals['plan'])) {
$totals['plan'] = array();
}
}
// Integrate with the support_timer module, if enabled
$hour = array();
if (module_exists('support_timer')) {
// The support_timer module uses a slightly different date format
$convert = strtotime(date('d M Y', $date));
$result = db_query('SELECT tt.time, t.client FROM {support_ticket_timer} tt LEFT JOIN {support_ticket} t ON tt.nid = t.nid LEFT JOIN {node} n ON t.nid = n.nid WHERE tt.date = %d AND n.uid = %d', $convert, $account->uid);
while ($timer = db_fetch_object($result)) {
$hour[$timer->client]->hours += support_pm_timer_to_hours($timer->time);
$hours[$timer->client]->hours += support_pm_timer_to_hours($timer->time);
}
$result = db_query('SELECT tt.time, t.client FROM {support_ticket_comment_timer} tt LEFT JOIN {support_ticket_comment} t ON tt.cid = t.cid LEFT JOIN {comments} c ON t.cid = c.cid WHERE tt.date = %d AND c.uid = %d', $convert, $account->uid);
while ($timer = db_fetch_object($result)) {
$hour[$timer->client]->hours += support_pm_timer_to_hours($timer->time);
$hours[$timer->client]->hours += support_pm_timer_to_hours($timer->time);
}
$row2[] = theme('support_pm_user_client_hours_details', $hour);
}
}
$rows = array(
$row,
);
// Only display actual data if support_timer is enabled to collect it
if (count($row2) > 1) {
$rows[] = $row2;
foreach ($hours as $clid => $data) {
// Add up totals
$totals['actual'][$clid] = $data->hours;
}
}
$output = theme('support_pm_pager', t('‹ previous'), '<');
$header2 = array(
t('Plan'),
);
$plan_sum = is_array($totals['plan']) ? array_sum($totals['plan']) : 0;
$actual_sum = is_array($totals['actual']) ? array_sum($totals['actual']) : 0;
$max = $plan_sum > $actual_sum ? $plan_sum : $actual_sum;
$row = array(
theme('support_pm_user_hours_summary', $totals['plan'], 'support_client_load', $max, t('Not scheduled')),
);
if (count($row2) > 1) {
$header2[] = t('Actual');
$row[] = theme('support_pm_user_hours_summary', $totals['actual'], 'support_client_load', $max, t('Not worked'));
}
$rows2 = array(
$row,
);
$output .= theme('table', $header2, $rows2, array(
'id' => 'support_pm_summary',
));
$output .= theme('table', $header, $rows, array(
'id' => 'support_pm_week',
));
$header = array(
t('Client'),
);
if (function_exists('imagecreatetruecolor')) {
$header[] = t('Color');
}
$header[] = t('Planned');
$header[] = t('Worked');
$header[] = t('Difference');
if (isset($totals['plan']) || isset($totals['actual'])) {
if (isset($totals['plan']) && isset($totals['actual'])) {
$all_clients = $totals['plan'] + $totals['actual'];
}
else {
$all_clients = isset($totals['plan']) ? $totals['plan'] : $totals['actual'];
}
}
else {
$all_clients = array();
}
$rows = $clients = array();
foreach ($all_clients as $clid => $data) {
$client = support_client_load($clid);
$clients[$clid] = $client->name;
}
asort($clients);
$rows = array();
foreach ($clients as $clid => $name) {
$row = array();
$client = support_client_load($clid);
$row[] = l($name, "support/{$client->path}");
$comments = db_result(db_query('SELECT comment FROM {support_plan} WHERE clid = %d AND uid = %d AND day = %d', $clid, $account->uid, $week));
if (!empty($comments)) {
$row[0] .= '<br />' . check_plain($comments);
}
if (function_exists('imagecreatetruecolor')) {
$row[] = "<img src='" . url('support_pm/image/') . support_pm_chartapi_color($clid) . "' alt='swatch' height='15' width='15' />";
}
$row[] = isset($totals['plan'][$clid]) ? number_format($totals['plan'][$clid], 2) : "0.00";
$row[] = isset($totals['actual'][$clid]) ? number_format($totals['actual'][$clid], 2) : "0.00";
if (isset($totals['plan'][$clid])) {
if (isset($totals['actual'][$clid])) {
$diff = $totals['actual'][$clid] - $totals['plan'][$clid];
}
else {
$diff = -$totals['plan'][$clid];
}
}
else {
if (isset($totals['actual'][$clid])) {
$diff = $totals['actual'][$clid];
}
else {
$diff = 0.0;
}
}
$plan = isset($totals['plan'][$clid]) ? $totals['plan'][$clid] : 0;
$row[] = theme('support_pm_plan_diff', $diff, $plan);
$rows[] = $row;
}
$row = array(
'<strong>' . t('Total') . '</strong>',
);
if (function_exists('imagecreatetruecolor')) {
$row[] = "<img src='" . url('support_pm/image/DDDDDD') . "' alt='swatch' height='15' width='15' />";
}
$plan = isset($totals['plan']) ? array_sum($totals['plan']) : 0;
$actual = isset($totals['actual']) ? array_sum($totals['actual']) : 0;
$row[] = '<strong>' . number_format($plan, 2) . '</strong>';
$row[] = '<strong>' . number_format($actual, 2) . '</strong>';
$diff = $actual - $plan;
$row[] = '<strong>' . theme('support_pm_plan_diff', $diff, $plan);
$rows[] = $row;
$output .= theme('table', $header, $rows, array(
'id' => 'support_pm_clients',
));
$output .= theme('support_pm_pager', t('next ›'), '>');
return $output;
}