Переглянути джерело

Add support for excluding retests or including retests only in Reports

Alan Lam 7 роки тому
батько
коміт
ef707f6df5
4 змінених файлів з 73 додано та 10 видалено
  1. 7 1
      controllers/reports.php
  2. 17 7
      controllers/reports_presentation.php
  3. 5 0
      engine/chart.php
  4. 44 2
      views/reports.php

+ 7 - 1
controllers/reports.php

@@ -38,6 +38,8 @@ if(!empty($location_ids)) {
 	$location_ids = array_filter($location_ids);
 }
 
+$retests = http::value("retests", "int");
+
 if(!is_array($location_ids)) {
 	$location_ids = [];
 }
@@ -104,6 +106,10 @@ if($submit) {
 			$test_nvp["location_id"] = $location_ids;
 		}
 
+		if($retests !== false) {
+			$test_nvp["retest"] = $retests;
+		}
+
 		$tests = Test::query($test_nvp);
 		$test_count = count($tests);
 
@@ -384,5 +390,5 @@ if($submit) {
 }
 
 View::includeOnce("header", compact("page_title"));
-View::include("reports", compact("customer", "date_range", "date_start", "date_end", "date_resolution", "all_projects", "project_table_data", "exclude_project_ids", "location_ids", "charts", "data", "total_data", "locations_missing_region", "locations_missing_area_manager", "region_data", "area_manager_data", "key_labels", "has_pass_fail"));
+View::include("reports", compact("customer", "date_range", "date_start", "date_end", "date_resolution", "all_projects", "project_table_data", "exclude_project_ids", "location_ids", "retests", "charts", "data", "total_data", "locations_missing_region", "locations_missing_area_manager", "region_data", "area_manager_data", "key_labels", "has_pass_fail"));
 View::includeOnce("footer");

+ 17 - 7
controllers/reports_presentation.php

@@ -1,10 +1,14 @@
-<?php
+<?php /** @noinspection PhpUnhandledExceptionInspection */
+/** @noinspection PhpUndefinedMethodInspection */
+
+/**
+ * @var string $date_range_label
+ * @var string[] $key_labels
+ */
 
 use PhpOffice\PhpPresentation\PhpPresentation;
 use PhpOffice\PhpPresentation\IOFactory;
-use PhpOffice\PhpPresentation\Style\Color;
 use PhpOffice\PhpPresentation\Style\Alignment;
-use PhpOffice\PhpPresentation\Shape\Drawing\Base64;
 
 $presentation = new PhpPresentation(); // 960x720
 
@@ -20,7 +24,15 @@ $shape->setName(APP_NAME . " logo")
 	  ->setOffsetX(380)
 	  ->setOffsetY(10);
 
-$title = $customer->name . " " . $template->name . " " . date("F Y") . " Tests";
+$retests_title = "All Tests";
+if($retests !== false) {
+	switch($retests) {
+		case 0: $retests_title = "Excluding Retests"; break;
+		case 1: $retests_title = "Retests Only"; break;
+	}
+}
+
+$title = sprintf("%s %s %s Tests (%s)", $customer->name, $template->name, date("F Y"), $retests_title);
 
 if($has_logo) {
 
@@ -52,7 +64,7 @@ else {
 	$shape->getActiveParagraph()->getAlignment()->setHorizontal( Alignment::HORIZONTAL_CENTER );
 	$run = $shape->createTextRun($title);
 	$run->getFont()->setBold(true)
-					   ->setSize(24);
+					   ->setSize(16);
 }
 
 // Create summary slide
@@ -236,5 +248,3 @@ foreach($names as $name) {
 }
 
 exit;
-
-?>

+ 5 - 0
engine/chart.php

@@ -499,6 +499,11 @@ class Chart {
 
 				$percentages = [];
 				foreach($data as $value) {
+					if($total == 0) {
+						$percentages[] = 0;
+						continue;
+					}
+
 					$percentages[] = (floor(($value * 10000) / $total) / 100) . "%";
 				}
 

+ 44 - 2
views/reports.php

@@ -16,6 +16,11 @@ $date_ranges = [
 	"custom" => "Custom",
 ];
 
+$retests_options = [
+	"0" => "Exclude",
+	"1" => "Retests Only"
+];
+
 $years = range(2018, date("Y"));
 
 $date_range_custom_style = ($date_range == "custom") ? "" : "display: none";
@@ -122,12 +127,26 @@ let projectData = <?=json_encode($project_table_data)?>;
 					</select>
 				</div>
 				<div class="form-group">
-					<label class="form-label" for="location-ids">
+					<label for="location-ids">
 						Location IDs
 					</label>
 					<input class="form-control" name="location_ids" type="text" id="location-ids" value="<?=htmlspecialchars(implode(" ", $location_ids))?>" placeholder="Enter location IDs" />
 					<small class="form-text text-muted">Separate each location ID with a space.<br />Leave blank to generate a report for all locations.</small>
 				</div>
+				<div class="form-group">
+					<label for="retests">Retests</label>
+					<select name="retests" id="retests" class="form-control">
+						<option value="">Include</option>
+						<?php
+						foreach($retests_options as $value => $display) {
+							$selected = $value === $retests ? "selected" : "";
+							?>
+							<option value="<?=$value?>" <?=$selected?>><?=htmlspecialchars($display)?></option>
+							<?php
+						}
+						?>
+					</select>
+				</div>
 				<button class="btn btn-primary" type="submit" name="submit" value="<?=htmlspecialchars($_SESSION["csrf_token"])?>">
 					Submit
 				</button>
@@ -194,7 +213,29 @@ let projectData = <?=json_encode($project_table_data)?>;
 	if($charts) {
 		?>
 
-		<h2>Charts / Statistics</h2>
+		<h2>
+			Report
+		</h2>
+
+		<p>
+		<?php
+		if($retests === 0) {
+			?>
+			<span class="badge badge-warning">Retests Excluded</span>
+			<?php
+		}
+		else if($retests === 1) {
+			?>
+			<span class="badge badge-warning">Retests Only</span>
+			<?php
+		}
+		else {
+			?>
+			<span class="badge badge-success">Retests Included</span>
+			<?php
+		}
+		?>
+		</p>
 
 		<div class="row">
 			<div class="col-md-6">
@@ -285,6 +326,7 @@ let projectData = <?=json_encode($project_table_data)?>;
 				<input type="hidden" name="date_start" id="date-start" value="<?=htmlspecialchars($date_start)?>" />
 				<input type="hidden" name="date_end" id="date-end" value="<?=htmlspecialchars($date_end)?>" />
 				<input type="hidden" name="date_resolution" value="<?=htmlspecialchars($date_resolution)?>" />
+				<input type="hidden" name="retests" value="<?=htmlspecialchars($retests)?>" />
 				<?php
 				foreach($exclude_project_ids as $project_id) {
 					?>