Skip to content

Commit

Permalink
Fix: Bug into calculation of total of time for tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Mar 17, 2014
1 parent e7e5a93 commit 8cf3d25
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
28 changes: 19 additions & 9 deletions htdocs/core/lib/project.lib.php
Expand Up @@ -222,8 +222,14 @@ function projectLinesa(&$inc, $parent, &$lines, &$level, $var, $showproject, &$t

$numlines=count($lines);

$total=0;
$total_planned=0;
// We declare counter as global because we want to edit them into recursive call
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++)
{
Expand Down Expand Up @@ -391,9 +397,9 @@ function projectLinesa(&$inc, $parent, &$lines, &$level, $var, $showproject, &$t
$level++;
if ($lines[$i]->id) projectLinesa($inc, $lines[$i]->id, $lines, $level, $var, $showproject, $taskrole, $projectsListId, $addordertick);
$level--;
$total += $lines[$i]->duration;
$total_planned += $lines[$i]->planned_workload;
// TODO fix totals in recursive calls
$total_projectlinesa_spent += $lines[$i]->duration;
$total_projectlinesa_planned += $lines[$i]->planned_workload;
if ($lines[$i]->planned_workload) $total_projectlinesa_spent_if_planned += $lines[$i]->duration;
}
}
else
Expand All @@ -402,19 +408,23 @@ 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 '<td class="liste_total">'.$langs->trans("Total").'</td>';
if ($showproject) print '<td></td><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 align="right" class="nowrap liste_total">'.convertSecondToTime($total, 'allhourmin').'</td>';
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>';
if ($addordertick) print '<td class="hideonsmartphone"></td>';
print '</tr>';
Expand Down
2 changes: 1 addition & 1 deletion htdocs/projet/tasks/index.php
Expand Up @@ -98,7 +98,7 @@
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Project").'</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 align="center">'.$langs->trans("DateStart").'</td>';
print '<td align="center">'.$langs->trans("DateEnd").'</td>';
Expand Down

0 comments on commit 8cf3d25

Please sign in to comment.