Skip to content

Commit

Permalink
#1690 [Survey] add: ODT change average calcul
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-eoxia committed Jan 27, 2024
1 parent 3094b95 commit ce0b718
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -304,24 +304,28 @@ public function write_file(SaturneDocuments $objectDocument, Translate $outputLa

$sheet->fetchQuestionsLinked($object->fk_sheet, 'digiquali_' . $sheet->element);

$questionCounter = count($sheet->linkedObjectsIds['digiquali_question']);

$average = 0;
$averagePercentageQuestions = 0;
$percentQuestionCounter = 0;
foreach ($sheet->linkedObjects['digiquali_question'] as $questionLinked) {
if ($questionLinked->type !== 'Percentage') {
continue; // Skip non-percentage questions
}

$percentQuestionCounter++;
foreach ($object->lines as $line) {
if ($line->fk_question === $questionLinked->id) {
$average += $line->answer;
$averagePercentageQuestions += $line->answer;
}
}
}

$average = ($questionCounter > 0) ? ($average / $questionCounter) : 0;
$averagePercentageQuestions = ($percentQuestionCounter > 0) ? ($averagePercentageQuestions / $percentQuestionCounter) : 0;

$tmpArray['average'] = price2num($average) . ' %';
if ($percentQuestionCounter > 0) {
$tmpArray['average'] = price2num($averagePercentageQuestions) . ' %';
} else {
$tmpArray['average'] = '';
}
$tmpArray['project_label'] = $project->ref . ' - ' . $project->title;
$tmpArray['sheet_ref'] = $sheet->ref;
$tmpArray['sheet_label'] = $sheet->label;
Expand Down

0 comments on commit ce0b718

Please sign in to comment.