Skip to content

Commit

Permalink
#282 [ODT] fix: fatal if nbtasks empty
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-eoxia committed Jun 7, 2023
1 parent dc82b02 commit 1d23193
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -326,21 +326,24 @@ public function write_file(SaturneDocuments $objectDocument, Translate $outputLa
$totalProgress = 0;
$totalPlannedWorkload = 0;
$totalConsumedTime = 0;
$nbTasks = 0;
if (is_array($tasksArray) && !empty($tasksArray)) {
$nbTasks = count($tasksArray);
foreach ($tasksArray as $task) {
$totalProgress += $task->progress;
$totalPlannedWorkload += $task->planned_workload;
$totalConsumedTime += $task->duration;
}
$tmpArray['project_progress'] = (($totalProgress) ? price2num($totalProgress / $nbTasks, 2) . ' %' : '0 %');
$tmpArray['project_status'] = $object->getLibStatut();
$tmpArray['project_planned_workload'] = convertSecondToTime($totalPlannedWorkload, 'allhourmin');
$tmpArray['project_timespent'] = convertSecondToTime($totalConsumedTime, 'allhourmin');
} else {
$tmpArray['project_progress'] = '';
$tmpArray['project_status'] = '';
$tmpArray['project_planned_workload'] = '';
$tmpArray['project_timespent'] = '';
}

$tmpArray['project_progress'] = (($totalProgress) ? price2num($totalProgress / $nbTasks, 2) . ' %' : '0 %');
$tmpArray['project_status'] = $object->getLibStatut();
$tmpArray['project_planned_workload'] = convertSecondToTime($totalPlannedWorkload, 'allhourmin');
$tmpArray['project_timespent'] = convertSecondToTime($totalConsumedTime, 'allhourmin');

$moreParam['tmparray'] = $tmpArray;

return parent::write_file($objectDocument, $outputLangs, $srcTemplatePath, $hideDetails, $hideDesc, $hideRef, $moreParam);
Expand Down
Binary file not shown.

0 comments on commit 1d23193

Please sign in to comment.