![]() |
|---|
| [ Index ] |
Source Code Reference for V1.00 |
[Summary view] [Print] [Text view]
1 <?php /* $Id: userperformance.php 135 2008-04-04 13:49:13Z pedroix $ $URL: https://web2project.svn.sourceforge.net/svnroot/web2project/trunk/modules/reports/reports/userperformance.php $ */ 2 if (!defined('W2P_BASE_DIR')) { 3 die('You should not access this file directly.'); 4 } 5 global $AppUI, $cal_sdf; 6 $AppUI->loadCalendarJS(); 7 8 $do_report = w2PgetParam($_POST, 'do_report', 0); 9 $log_start_date = w2PgetParam($_POST, 'log_start_date', 0); 10 $log_end_date = w2PgetParam($_POST, 'log_end_date', 0); 11 $log_all = w2PgetParam($_POST['log_all'], 0); 12 $group_by_unit = w2PgetParam($_POST['group_by_unit'], 'day'); 13 14 // create Date objects from the datetime fields 15 $start_date = intval($log_start_date) ? new CDate($log_start_date) : new CDate(); 16 $end_date = intval($log_end_date) ? new CDate($log_end_date) : new CDate(); 17 18 if (!$log_start_date) { 19 $start_date->subtractSpan(new Date_Span('14,0,0,0')); 20 } 21 $end_date->setTime(23, 59, 59); 22 ?> 23 24 <script language="javascript"> 25 function setDate( frm_name, f_date ) { 26 fld_date = eval( 'document.' + frm_name + '.' + f_date ); 27 fld_real_date = eval( 'document.' + frm_name + '.' + 'log_' + f_date ); 28 if (fld_date.value.length>0) { 29 if ((parseDate(fld_date.value))==null) { 30 alert('The Date/Time you typed does not match your prefered format, please retype.'); 31 fld_real_date.value = ''; 32 fld_date.style.backgroundColor = 'red'; 33 } else { 34 fld_real_date.value = formatDate(parseDate(fld_date.value), 'yyyyMMdd'); 35 fld_date.value = formatDate(parseDate(fld_date.value), '<?php echo $cal_sdf ?>'); 36 fld_date.style.backgroundColor = ''; 37 } 38 } else { 39 fld_real_date.value = ''; 40 } 41 } 42 </script> 43 44 <form name="editFrm" action="index.php?m=reports" method="post"> 45 <input type="hidden" name="project_id" value="<?php echo $project_id; ?>" /> 46 <input type="hidden" name="report_type" value="<?php echo $report_type; ?>" /> 47 48 <?php 49 if (function_exists('styleRenderBoxTop')) { 50 echo styleRenderBoxTop(); 51 } 52 ?> 53 <table cellspacing="0" cellpadding="4" border="0" width="100%" class="std"> 54 <tr> 55 <td align="right" nowrap="nowrap"><?php echo $AppUI->_('For period'); ?>:</td> 56 <td nowrap="nowrap"> 57 <input type="hidden" name="log_start_date" id="log_start_date" value="<?php echo $start_date ? $start_date->format(FMT_TIMESTAMP_DATE) : ''; ?>" /> 58 <input type="text" name="start_date" id="start_date" onchange="setDate('editFrm', 'start_date');" value="<?php echo $start_date ? $start_date->format($df) : ''; ?>" class="text" /> 59 <a href="javascript: void(0);" onclick="return showCalendar('start_date', '<?php echo $df ?>', 'editFrm', null, true)"> 60 <img src="<?php echo w2PfindImage('calendar.gif'); ?>" width="24" height="12" alt="<?php echo $AppUI->_('Calendar'); ?>" border="0" /> 61 </a> 62 </td> 63 <td align="right" nowrap="nowrap"><?php echo $AppUI->_('to'); ?></td> 64 <td nowrap="nowrap"> 65 <input type="hidden" name="log_end_date" id="log_end_date" value="<?php echo $end_date ? $end_date->format(FMT_TIMESTAMP_DATE) : ''; ?>" /> 66 <input type="text" name="end_date" id="end_date" onchange="setDate('editFrm', 'end_date');" value="<?php echo $end_date ? $end_date->format($df) : ''; ?>" class="text" /> 67 <a href="javascript: void(0);" onclick="return showCalendar('end_date', '<?php echo $df ?>', 'editFrm', null, true)"> 68 <img src="<?php echo w2PfindImage('calendar.gif'); ?>" width="24" height="12" alt="<?php echo $AppUI->_('Calendar'); ?>" border="0" /> 69 </a> 70 </td> 71 72 <td nowrap="nowrap"> 73 <input type="checkbox" name="log_all" id="log_all" <?php if ($log_all) 74 echo "checked" ?> /> 75 <label for="log_all"><?php echo $AppUI->_('Log All'); ?></label> 76 </td> 77 78 <td align="right" width="50%" nowrap="nowrap"> 79 <input class="button" type="submit" name="do_report" value="<?php echo $AppUI->_('submit'); ?>" /> 80 </td> 81 </tr> 82 </table> 83 </form> 84 <?php 85 if ($do_report) { 86 if (function_exists('styleRenderBoxBottom')) { 87 echo styleRenderBoxBottom(); 88 } 89 echo '<br />'; 90 if (function_exists('styleRenderBoxTop')) { 91 echo styleRenderBoxTop(); 92 } 93 echo '<table cellspacing="0" cellpadding="4" border="0" width="100%" class="std"> 94 <tr> 95 <td>'; 96 97 // Let's figure out which users we have 98 $user_list = w2PgetUsersHashList(); 99 100 // Now which tasks will we need and the real allocated hours (estimated time / number of users) 101 // Also we will use tasks with duration_type = 1 (hours) and those that are not marked 102 // as milstones 103 // GJB: Note that we have to special case duration type 24 and this refers to the hours in a day, NOT 24 hours 104 $working_hours = $w2Pconfig['daily_working_hours']; 105 106 $q = new DBQuery; 107 $q->addTable('tasks', 't'); 108 $q->addTable('user_tasks', 'ut'); 109 $q->addJoin('projects', '', 'project_id = task_project', 'inner'); 110 $q->addQuery('t.task_id, round(t.task_duration * IF(t.task_duration_type = 24, ' . $working_hours . ', t.task_duration_type)/count(ut.task_id),2) as hours_allocated'); 111 $q->addWhere('t.task_id = ut.task_id'); 112 $q->addWhere('t.task_milestone = 0'); 113 $q->addWhere('project_active = 1'); 114 if (($template_status = w2PgetConfig('template_projects_status_id')) != '') { 115 $q->addWhere('project_status <> ' . (int)$template_status); 116 } 117 118 if ($project_id != 0) { 119 $q->addWhere('t.task_project = ' . (int)$project_id); 120 } 121 122 if (!$log_all) { 123 $q->addWhere('t.task_start_date >= \'' . $start_date->format(FMT_DATETIME_MYSQL) . '\''); 124 $q->addWhere('t.task_start_date <= \'' . $end_date->format(FMT_DATETIME_MYSQL) . '\''); 125 } 126 $q->addGroup('t.task_id'); 127 128 $task_list = $q->loadHashList('task_id'); 129 $q->clear(); 130 ?> 131 132 <table cellspacing="1" cellpadding="4" border="0" class="tbl"> 133 <tr> 134 <th colspan='2'><?php echo $AppUI->_('User'); ?></th> 135 <th><?php echo $AppUI->_('Hours allocated'); ?></th> 136 <th><?php echo $AppUI->_('Hours worked'); ?></th> 137 <th><?php echo $AppUI->_('% of work done (based on duration)'); ?></th> 138 <th><?php echo $AppUI->_('User Efficiency (based on completed tasks)'); ?></th> 139 </tr> 140 141 <?php 142 if (count($user_list)) { 143 $percentage_sum = $hours_allocated_sum = $hours_worked_sum = 0; 144 $sum_total_hours_allocated = $sum_total_hours_worked = 0; 145 $sum_hours_allocated_complete = $sum_hours_worked_complete = 0; 146 147 //TODO: Split times for which more than one users were working... 148 foreach ($user_list as $user_id => $user) { 149 $q->addTable('user_tasks', 'ut'); 150 $q->addQuery('task_id'); 151 $q->addWhere('user_id = ' . (int)$user_id); 152 $tasks_id = $q->loadColumn(); 153 $q->clear(); 154 155 $total_hours_allocated = $total_hours_worked = 0; 156 $hours_allocated_complete = $hours_worked_complete = 0; 157 158 foreach ($tasks_id as $task_id) { 159 if (isset($task_list[$task_id])) { 160 // Now let's figure out how many time did the user spent in this task 161 $q->addTable('task_log'); 162 $q->addQuery('SUM(task_log_hours)'); 163 $q->addWhere('task_log_task =' . (int)$task_id); 164 $q->addWhere('task_log_creator =' . (int)$user_id); 165 $hours_worked = round($q->loadResult(), 2); 166 $q->clear(); 167 168 $q->addTable('tasks'); 169 $q->addQuery('task_percent_complete'); 170 $q->addWhere('task_id =' . (int)$task_id); 171 $percent = $q->loadColumn(); 172 $q->clear(); 173 $complete = ($percent[0] == 100); 174 175 if ($complete) { 176 $hours_allocated_complete += $task_list[$task_id]['hours_allocated']; 177 $hours_worked_complete += $hours_worked; 178 } 179 180 $total_hours_allocated += $task_list[$task_id]['hours_allocated']; 181 $total_hours_worked += $hours_worked; 182 } 183 } 184 185 $sum_total_hours_allocated += $total_hours_allocated; 186 $sum_total_hours_worked += $total_hours_worked; 187 188 $sum_hours_allocated_complete += $hours_allocated_complete; 189 $sum_hours_worked_complete += $hours_worked_complete; 190 191 if ($total_hours_allocated > 0 || $total_hours_worked > 0) { 192 $percentage = 0; 193 $percentage_e = 0; 194 if ($total_hours_worked > 0) { 195 $percentage = ($total_hours_worked / $total_hours_allocated) * 100; 196 if ($hours_worked_complete > 0) { 197 $percentage_e = ($hours_allocated_complete / $hours_worked_complete) * 100; 198 } 199 } 200 ?> 201 <tr> 202 <td><?php echo '(' . $user['user_username'] . ') </td><td> ' . $user['contact_first_name'] . ' ' . $user['contact_last_name']; ?></td> 203 <td align='right'><?php echo $total_hours_allocated; ?> </td> 204 <td align='right'><?php echo $total_hours_worked; ?> </td> 205 <td align='right'><?php echo number_format($percentage, 0); ?>% </td> 206 <td align='right'><?php echo number_format($percentage_e, 0); ?>% </td> 207 </tr> 208 <?php 209 } 210 } 211 $sum_percentage = 0; 212 $sum_efficiency = 0; 213 if ($sum_total_hours_worked > 0) { 214 $sum_percentage = ($sum_total_hours_worked / $sum_total_hours_allocated) * 100; 215 if ($sum_hours_worked_complete > 0) 216 $sum_efficiency = ($sum_hours_allocated_complete / $sum_hours_worked_complete) * 100; 217 } 218 ?> 219 <tr> 220 <td colspan='2'><?php echo $AppUI->_('Total'); ?></td> 221 <td align='right'><?php echo $sum_total_hours_allocated; ?></td> 222 <td align='right'><?php echo $sum_total_hours_worked; ?></td> 223 <td align='right'><?php echo number_format($sum_percentage, 0); ?>%</td> 224 <td align='right'><?php echo number_format($sum_efficiency, 0); ?>%</td> 225 </tr> 226 <?php 227 } else { 228 ?> 229 <tr> 230 <td><p><?php echo $AppUI->_('There are no tasks that fulfill selected filters'); ?></p></td> 231 </tr> 232 <?php 233 } 234 echo '</table>'; 235 echo '</td> 236 </tr> 237 </table>'; 238 } 239 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Jan 8 03:00:03 2009 | Cross-referenced by PHPXref 0.7 |