From 8cf3d258f4da3e9c6357c26b8f71bd1c736f3b68 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur <eldy@destailleur.fr> Date: Mon, 17 Mar 2014 15:13:24 +0100 Subject: [PATCH] Fix: Bug into calculation of total of time for tasks --- htdocs/core/lib/project.lib.php | 28 +++++++++++++++++++--------- htdocs/projet/tasks/index.php | 2 +- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/htdocs/core/lib/project.lib.php b/htdocs/core/lib/project.lib.php index 39c8cd80dd0..7838a3597d1 100644 --- a/htdocs/core/lib/project.lib.php +++ b/htdocs/core/lib/project.lib.php @@ -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++) { @@ -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 @@ -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 '<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 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>'; diff --git a/htdocs/projet/tasks/index.php b/htdocs/projet/tasks/index.php index 8edb2c6f71e..ac25e601d14 100644 --- a/htdocs/projet/tasks/index.php +++ b/htdocs/projet/tasks/index.php @@ -98,7 +98,7 @@ print '<table class="noborder" width="100%">'; 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>'; -- GitLab