/** * Function that returns the amount of hours this * task consumes per user each week */ function getTaskDurationPerWeek($use_percent_assigned = false) { $duration = ($this->task_duration_type == 24 ? dPgetConfig('daily_working_hours') : $this->task_duration_type) * $this->task_duration; $task_start_date = new CDate($this->task_start_date); $task_finish_date = new CDate($this->task_end_date); $assigned_users = $this->getAssignedUsers(); if ($use_percent_assigned) { $number_assigned_users = 0; foreach ($assigned_users as $u) { $number_assigned_users += $u['perc_assignment'] / 100; } } else { $number_assigned_users = count($assigned_users); } $number_of_weeks_worked = $task_finish_date->workingDaysInSpan($task_start_date) / count(explode(',', dPgetConfig('cal_working_days'))); $number_of_weeks_worked = $number_of_weeks_worked < 1 ? ceil($number_of_weeks_worked) : $number_of_weeks_worked; // zero adjustment if ($number_of_weeks_worked == 0) { $number_of_weeks_worked = 1; } if ($number_assigned_users == 0) { $number_assigned_users = 1; } return $duration / $number_assigned_users / $number_of_weeks_worked; }
function showWeeks() { global $allocated_hours_sum, $end_date, $start_date, $AppUI, $user_list, $user_names, $user_usage, $hideNonWd, $table_header, $table_rows, $df, $working_days_count, $total_hours_capacity, $total_hours_capacity_all; $working_days_count = 0; $allocated_hours_sum = 0; $ed = new CDate(Date_Calc::endOfWeek($end_date->day, $end_date->month, $end_date->year)); $sd = new CDate(Date_Calc::beginOfWeek($start_date->day, $start_date->month, $start_date->year)); $week_difference = ceil($ed->workingDaysInSpan($sd) / count(explode(",", dPgetConfig("cal_working_days")))); $actual_date = $sd; $table_header = "<tr><th>" . $AppUI->_("User") . "</th>"; for ($i = 0; $i < $week_difference; $i++) { $table_header .= "<th>" . Date_Calc::weekOfYear($actual_date->day, $actual_date->month, $actual_date->year) . "<br><table><td style='font-weight:normal; font-size:70%'>" . $actual_date->format($df) . "</td></table></th>"; $actual_date->addSeconds(168 * 3600); // + one week } $table_header .= "<th nowrap='nowrap' colspan='2'>" . $AppUI->_("Allocated") . "</th></tr>"; $table_rows = ""; foreach ($user_list as $user_id => $user_data) { @($user_names[$user_id] = $user_data["user_username"]); if (isset($user_usage[$user_id])) { $table_rows .= "<tr><td nowrap='nowrap'>(" . $user_data["user_username"] . ") " . $user_data["contact_first_name"] . " " . $user_data["contact_last_name"] . "</td>"; $actual_date = $sd; for ($i = 0; $i < $week_difference; $i++) { $awoy = $actual_date->year . Date_Calc::weekOfYear($actual_date->day, $actual_date->month, $actual_date->year); $table_rows .= "<td align='right'>"; if (isset($user_usage[$user_id][$awoy])) { $hours = number_format($user_usage[$user_id][$awoy], 2); $table_rows .= $hours; $percentage_used = round($hours / (dPgetConfig("daily_working_hours") * count(explode(",", dPgetConfig("cal_working_days")))) * 100); $bar_color = "blue"; if ($percentage_used > 100) { $bar_color = "red"; $percentage_used = 100; } $table_rows .= "<div style='height:2px;width:{$percentage_used}%; background-color:{$bar_color}'> </div>"; } else { $table_rows .= " "; } $table_rows .= "</td>"; $actual_date->addSeconds(168 * 3600); // + one week } $array_sum = array_sum($user_usage[$user_id]); $average_user_usage = number_format($array_sum / ($week_difference * count(explode(",", dPgetConfig("cal_working_days"))) * dPgetConfig("daily_working_hours")) * 100, 2); $allocated_hours_sum += $array_sum; $bar_color = "blue"; if ($average_user_usage > 100) { $bar_color = "red"; $average_user_usage = 100; } $table_rows .= "<td ><div align='left'>" . round($array_sum, 2) . " " . $AppUI->_("hours") . "</td> <td align='right'> " . $average_user_usage; $table_rows .= "%</div>"; $table_rows .= "<div align='left' style='height:2px;width:{$average_user_usage}%; background-color:{$bar_color}'> </div></td>"; $table_rows .= "</tr>"; } } $total_hours_capacity = $week_difference * count(explode(",", dPgetConfig("cal_working_days"))) * dPgetConfig("daily_working_hours") * count($user_usage); $total_hours_capacity_all = $week_difference * count(explode(",", dPgetConfig("cal_working_days"))) * dPgetConfig("daily_working_hours") * count($user_list); }
function showWeeks() { global $allocated_hours_sum, $end_date, $start_date, $AppUI, $user_list, $user_names; global $user_usage, $hideNonWd, $table_header, $table_rows, $df, $working_days_count; global $total_hours_capacity, $total_hours_capacity_all; $working_days_count = 0; $allocated_hours_sum = 0; $AppUI->setBaseLocale(); $ed = new CDate(Date_Calc::endOfWeek($end_date->day, $end_date->month, $end_date->year)); $sd = new CDate(Date_Calc::beginOfWeek($start_date->day, $start_date->month, $start_date->year)); setlocale(LC_ALL, $AppUI->user_lang); $week_difference = ceil($ed->workingDaysInSpan($sd) / count(explode(',', dPgetConfig('cal_working_days')))); $actual_date = $sd; $table_header = '<tr><th>' . $AppUI->_('User') . '</th>'; for ($i = 0; $i < $week_difference; $i++) { $actual_date->addSeconds(168 * 3600); // + one week $working_days_count = $working_days_count + count(explode(',', dPgetConfig('cal_working_days'))); } $table_header .= '<th nowrap="nowrap" colspan="2">' . $AppUI->_('Allocated') . '</th></tr>'; $table_rows = ''; foreach ($user_list as $user_id => $user_data) { @($user_names[$user_id] = $user_data['user_username']); if (isset($user_usage[$user_id])) { $table_rows .= '<tr><td nowrap="nowrap">(' . $user_data['user_username'] . ') ' . $user_data['contact_first_name'] . ' ' . $user_data['contact_last_name'] . '</td>'; $actual_date = $sd; /* for ($i=0; $i<$week_difference; $i++) { setlocale(LC_ALL, 'en_AU'.(($locale_char_set)? ('.' . $locale_char_set) : '.utf8')); $awoy = $actual_date->year.Date_Calc::weekOfYear($actual_date->day,$actual_date->month,$actual_date->year); setlocale(LC_ALL, $AppUI->user_lang); $table_rows .= '<td align="right">'; if (isset($user_usage[$user_id][$awoy])) { $hours = number_format($user_usage[$user_id][$awoy],2); $table_rows .= $hours; $percentage_used = round(($hours/(dPgetConfig('daily_working_hours')*count(explode(',',dPgetConfig('cal_working_days')))))*100); $bar_color = 'blue'; if ($percentage_used > 100) { $bar_color = 'red'; $percentage_used = 100; } $table_rows .= '<div style="height:2px;width:' . $percentage_used . '%; background-color:' . $bar_color . '"> </div>'; } else { $table_rows .= ' '; } $table_rows .= '</td>'; $actual_date->addSeconds(168*3600); // + one week } */ $array_sum = array_sum($user_usage[$user_id]); $average_user_usage = number_format($array_sum / ($week_difference * count(explode(',', dPgetConfig('cal_working_days'))) * dPgetConfig('daily_working_hours')) * 100, 2); $allocated_hours_sum += $array_sum; $bar_color = 'blue'; if ($average_user_usage > 100) { $bar_color = 'red'; $average_user_usage = 100; } $table_rows .= '<td><div align="left">' . round($array_sum, 2) . ' ' . $AppUI->_('hours') . '</td> <td align="right"> ' . $average_user_usage; $table_rows .= '%</div>'; $table_rows .= '<div align="left" style="height:2px;width:' . $average_user_usage . '%; background-color:' . $bar_color . '"> </div></td>'; $table_rows .= '</tr>'; } } /* $total_hours_capacity = $week_difference * count(explode(',',dPgetConfig('cal_working_days'))) * dPgetConfig('daily_working_hours') * count($user_usage); $total_hours_capacity_all = $week_difference * count(explode(',',dPgetConfig('cal_working_days'))) *dPgetConfig('daily_working_hours') * count($user_list); */ $total_hours_capacity = $working_days_count / 2 * dPgetConfig('daily_working_hours') * count($user_usage); $total_hours_capacity_all = $working_days_count / 2 * dPgetConfig('daily_working_hours') * count($user_list); }