Bläddra i källkod

Add support for specifying location IDs for a report

Alan Lam 8 år sedan
förälder
incheckning
36df6bfecb
2 ändrade filer med 32 tillägg och 6 borttagningar
  1. 20 3
      controllers/reports.php
  2. 12 3
      views/reports.php

+ 20 - 3
controllers/reports.php

@@ -29,6 +29,17 @@ $to_quarter = http::value("to_quarter");
 $project_ids = http::value("project_ids", "int");
 $project_ids = http::value("project_ids", "int");
 if(!is_array($project_ids)) $project_ids = [];
 if(!is_array($project_ids)) $project_ids = [];
 
 
+$location_ids = http::value("location_ids");
+if(!empty($location_ids)) {
+	$location_ids = explode(" ", $location_ids);
+	$location_ids = array_map("intval", $location_ids);
+	$location_ids = array_filter($location_ids);
+}
+
+if(!is_array($location_ids)) {
+	$location_ids = [];
+}
+
 $all_projects = Project::query([
 $all_projects = Project::query([
 	"customer_id" => $customer->id
 	"customer_id" => $customer->id
 ]);
 ]);
@@ -97,10 +108,16 @@ if($submit) {
 		if($form_exception->hasErrors()) throw $form_exception;
 		if($form_exception->hasErrors()) throw $form_exception;
 
 
 		// Get all completed tests
 		// Get all completed tests
-		$tests = Test::query([
+		$test_nvp = [
 			"project_id" => $project_ids,
 			"project_id" => $project_ids,
 			"status" => Test::STATUS_COMPLETED
 			"status" => Test::STATUS_COMPLETED
-		]);
+		];
+
+		if($location_ids) {
+			$test_nvp["location_id"] = $location_ids;
+		}
+
+		$tests = Test::query($test_nvp);
 		$test_count = count($tests);
 		$test_count = count($tests);
 
 
 		// Get test values
 		// Get test values
@@ -393,7 +410,7 @@ if($submit) {
 }
 }
 
 
 View::includeOnce("header", compact("page_title"));
 View::includeOnce("header", compact("page_title"));
-View::include("reports", compact("customer", "date_range", "from_quarter", "to_quarter", "date_resolution", "all_projects", "project_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", "from_quarter", "to_quarter", "date_resolution", "all_projects", "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::includeOnce("footer");
 View::includeOnce("footer");
 
 
 ?>
 ?>

+ 12 - 3
views/reports.php

@@ -46,7 +46,7 @@ $date_range_custom_style = ($date_range == "custom") ? "" : "display: none";
 		<div class="row">
 		<div class="row">
 			<div class="col-md">
 			<div class="col-md">
 				<div class="row mb-1">
 				<div class="row mb-1">
-					<label class="col-sm-4 col-form-label text-sm-right">
+					<label class="col-sm-4 text-sm-right">
 						Date Range
 						Date Range
 					</label>
 					</label>
 					<div class="col-sm">
 					<div class="col-sm">
@@ -127,7 +127,7 @@ $date_range_custom_style = ($date_range == "custom") ? "" : "display: none";
 					</div>
 					</div>
 				</div>
 				</div>
 				<div class="row mb-1">
 				<div class="row mb-1">
-					<label class="col-sm-4 col-form-label text-sm-right" for="date-resolution">
+					<label class="col-sm-4 text-sm-right" for="date-resolution">
 						Date Resolution
 						Date Resolution
 					</label>
 					</label>
 					<div class="col-sm">
 					<div class="col-sm">
@@ -144,7 +144,7 @@ $date_range_custom_style = ($date_range == "custom") ? "" : "display: none";
 					</div>
 					</div>
 				</div>
 				</div>
 				<div class="row mb-1">
 				<div class="row mb-1">
-					<label class="col-sm-4 col-form-label text-sm-right" for="project-ids">
+					<label class="col-sm-4 text-sm-right" for="project-ids">
 						Projects
 						Projects
 					</label>
 					</label>
 					<div class="col-sm">
 					<div class="col-sm">
@@ -161,6 +161,15 @@ $date_range_custom_style = ($date_range == "custom") ? "" : "display: none";
 						<small class="form-text text-muted">Hint: Ctrl+Click / Cmd+Click to select multiple projects.</small>
 						<small class="form-text text-muted">Hint: Ctrl+Click / Cmd+Click to select multiple projects.</small>
 					</div>
 					</div>
 				</div>
 				</div>
+				<div class="row mb-1">
+					<label class="col-sm-4 text-sm-right" for="location-ids">
+						Location IDs
+					</label>
+					<div class="col-sm">
+						<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. Leave blank to generate a report for all locations.</small>
+					</div>
+				</div>
 				<div class="row">
 				<div class="row">
 					<div class="col-sm offset-sm-4">
 					<div class="col-sm offset-sm-4">
 						<button class="btn btn-primary" type="submit" name="submit" value="<?=htmlspecialchars($_SESSION["csrf_token"])?>">
 						<button class="btn btn-primary" type="submit" name="submit" value="<?=htmlspecialchars($_SESSION["csrf_token"])?>">