فهرست منبع

Merge branch 'develop'

Alan Lam 8 سال پیش
والد
کامیت
7654505515
3فایلهای تغییر یافته به همراه34 افزوده شده و 4 حذف شده
  1. 2 0
      controllers/reports.php
  2. 13 3
      controllers/reports_presentation.php
  3. 19 1
      engine/chart.php

+ 2 - 0
controllers/reports.php

@@ -734,6 +734,7 @@ if($submit) {
 
 			$chart->setDatalabelSuffixes("%");
 			$chart->print = true;
+			$chart->printTotalColumn = true;
 			$charts[] = $chart;
 
 			// Region Pass Rate Period
@@ -812,6 +813,7 @@ if($submit) {
 			$chart->addPrintDataset("Fail", $fail_counts);
 			$chart->setDatalabelSuffixes("%");
 			$chart->print = true;
+			$chart->printTotalColumn = true;
 			$charts[] = $chart;
 
 			// Area Pass Rate Period

+ 13 - 3
controllers/reports_presentation.php

@@ -75,6 +75,7 @@ foreach($charts_b64 as $index => $b64) {
 
 	if($chart->print) {
 		// Table
+		if($chart->printTotalColumn) ++$column_count;
 
 		$shape = $slide->createTableShape($column_count)
 			->setWidth(900)
@@ -87,6 +88,8 @@ foreach($charts_b64 as $index => $b64) {
 
 		$labels = $chart->getPrintLabels() ?? $chart->getLabels();
 
+		if($chart->printTotalColumn) $labels[] = "Total";
+
 		foreach($labels as $label) {
 			$cell = $row->nextCell();
 			$cell->getActiveParagraph()->getAlignment()
@@ -104,9 +107,15 @@ foreach($charts_b64 as $index => $b64) {
 		foreach($datasets as $index => $dataset) {
 			$label = $dataset->label;
 			$data = $dataset->data;
+			$print_data = array_slice($data, 0);
 
+			$total = array_sum($data);
 			$suffix = $suffixes[$index] ?? "";
 
+			if($chart->printTotalColumn) {
+				$print_data[] = ($suffix == "%") ? "" : number_format(array_sum($data)) . $suffix;
+			}
+
 			$row = $shape->createRow();
 			$row->setHeight(20);
 			$cell = $row->nextCell();
@@ -117,7 +126,9 @@ foreach($charts_b64 as $index => $b64) {
 				->setMarginTop(4);
 			$cell->createTextRun($label)
 				->getFont()->setBold(true);
-			foreach($data as $value) {
+			foreach($print_data as $value) {
+				$string = strlen($value) == 0 ? "" : $value . $suffix;
+
 				$cell = $row->nextCell();
 				$cell->getActiveParagraph()->getAlignment()
 					->setHorizontal(Alignment::HORIZONTAL_RIGHT)
@@ -125,11 +136,10 @@ foreach($charts_b64 as $index => $b64) {
 					->setMarginLeft(4)
 					->setMarginRight(4)
 					->setMarginTop(4);
-				$cell->createTextRun($value . $suffix);
+				$cell->createTextRun($string);
 			}
 
 			if($chart->printPercentages) {
-				$total = array_sum($data);
 
 				$percentages = [];
 				foreach($data as $value) {

+ 19 - 1
engine/chart.php

@@ -28,8 +28,10 @@ class Chart {
 
 	public $beforeHtml = null;
 	public $afterHtml = null;
+
 	public $print = false;
 	public $printPercentages = false;
+	public $printTotalColumn = false;
 
 	public function __construct() {
 		$this->id = bin2hex(random_bytes(8));
@@ -263,6 +265,13 @@ class Chart {
 						<th><?=htmlspecialchars($label)?></th>
 						<?php
 					}
+
+					if($this->printTotalColumn) {
+						?>
+						<th>Total</th>
+						<?php
+					}
+
 					?>
 				</tr>
 			</thead>
@@ -289,7 +298,16 @@ class Chart {
 					<?php
 					foreach($data as $value) {
 						?>
-						<td class="text-right"><?=htmlspecialchars($value)?><?=htmlspecialchars($suffix)?></td>
+						<td class="text-right"><?=number_format($value)?><?=htmlspecialchars($suffix)?></td>
+						<?php
+					}
+
+					if($this->printTotalColumn) {
+
+						$string = ($suffix == "%") ? "" : number_format(array_sum($data)) . $suffix;
+
+						?>
+						<td class="text-right"><?=htmlspecialchars($string)?></td>
 						<?php
 					}
 					?>