Fix: Bug into calculation of total of time for tasks

This commit is contained in:
Laurent Destailleur 2014-03-17 15:13:24 +01:00
parent e7e5a93906
commit 8cf3d258f4
2 changed files with 20 additions and 10 deletions

View File

@ -222,8 +222,14 @@ function projectLinesa(&$inc, $parent, &$lines, &$level, $var, $showproject, &$t
$numlines=count($lines); $numlines=count($lines);
$total=0; // We declare counter as global because we want to edit them into recursive call
$total_planned=0; global $total_projectlinesa_spent,$total_projectlinesa_planned,$total_projectlinesa_spent_if_planned;
if ($level == 0)
{
$total_projectlinesa_spent=0;
$total_projectlinesa_planned=0;
$total_projectlinesa_spent_if_planned=0;
}
for ($i = 0 ; $i < $numlines ; $i++) for ($i = 0 ; $i < $numlines ; $i++)
{ {
@ -391,9 +397,9 @@ function projectLinesa(&$inc, $parent, &$lines, &$level, $var, $showproject, &$t
$level++; $level++;
if ($lines[$i]->id) projectLinesa($inc, $lines[$i]->id, $lines, $level, $var, $showproject, $taskrole, $projectsListId, $addordertick); if ($lines[$i]->id) projectLinesa($inc, $lines[$i]->id, $lines, $level, $var, $showproject, $taskrole, $projectsListId, $addordertick);
$level--; $level--;
$total += $lines[$i]->duration; $total_projectlinesa_spent += $lines[$i]->duration;
$total_planned += $lines[$i]->planned_workload; $total_projectlinesa_planned += $lines[$i]->planned_workload;
// TODO fix totals in recursive calls if ($lines[$i]->planned_workload) $total_projectlinesa_spent_if_planned += $lines[$i]->duration;
} }
} }
else else
@ -402,7 +408,7 @@ function projectLinesa(&$inc, $parent, &$lines, &$level, $var, $showproject, &$t
} }
} }
if ($total>0 && $level==0) if (($total_projectlinesa_planned > 0 || $total_projectlinesa_spent > 0) && $level==0)
{ {
print '<tr class="liste_total">'; print '<tr class="liste_total">';
print '<td class="liste_total">'.$langs->trans("Total").'</td>'; print '<td class="liste_total">'.$langs->trans("Total").'</td>';
@ -410,11 +416,15 @@ function projectLinesa(&$inc, $parent, &$lines, &$level, $var, $showproject, &$t
print '<td></td>'; print '<td></td>';
print '<td></td>'; print '<td></td>';
print '<td></td>'; print '<td></td>';
print '<td align="center" class="nowrap liste_total">'.convertSecondToTime($total_planned, 'allhourmin').'</td>'; print '<td align="center" class="nowrap liste_total">';
print convertSecondToTime($total_projectlinesa_planned, 'allhourmin');
print '</td>';
print '<td></td>'; print '<td></td>';
print '<td align="right" class="nowrap liste_total">'.convertSecondToTime($total, 'allhourmin').'</td>';
print '<td align="right" class="nowrap liste_total">'; print '<td align="right" class="nowrap liste_total">';
if($total_planned) print round(100 * $total / $total_planned,2).' %'; print convertSecondToTime($total_projectlinesa_spent, 'allhourmin');
print '</td>';
print '<td align="right" class="nowrap liste_total">';
if ($total_projectlinesa_planned) print round(100 * $total_projectlinesa_spent_if_planned / $total_projectlinesa_planned,2).' %';
print '</td>'; print '</td>';
if ($addordertick) print '<td class="hideonsmartphone"></td>'; if ($addordertick) print '<td class="hideonsmartphone"></td>';
print '</tr>'; print '</tr>';

View File

@ -98,7 +98,7 @@ print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Project").'</td>'; print '<td>'.$langs->trans("Project").'</td>';
print '<td>'.$langs->trans("Status").'</td>'; print '<td>'.$langs->trans("Status").'</td>';
print '<td width="80">'.$langs->trans("RefTask").'</td>'; print '<td>'.$langs->trans("RefTask").'</td>';
print '<td>'.$langs->trans("LabelTask").'</td>'; print '<td>'.$langs->trans("LabelTask").'</td>';
print '<td align="center">'.$langs->trans("DateStart").'</td>'; print '<td align="center">'.$langs->trans("DateStart").'</td>';
print '<td align="center">'.$langs->trans("DateEnd").'</td>'; print '<td align="center">'.$langs->trans("DateEnd").'</td>';