فهرست منبع

Add number of tests completed during the current year cycle when editing a project

Alan Lam 3 سال پیش
والد
کامیت
d069976054
3فایلهای تغییر یافته به همراه40 افزوده شده و 4 حذف شده
  1. 9 0
      engine/customer.php
  2. 1 2
      engine/searches/location_search.php
  3. 30 2
      views/project_form.php

+ 9 - 0
engine/customer.php

@@ -145,6 +145,15 @@ class Customer extends Model {
 		];
 	}
 
+	public function getYearCycleConstraint(string $tz): Constraint {
+		[$min_date, $max_date] = $this->getYearCycleDates();
+
+		$dt_min = CarbonImmutable::parse($min_date, $tz)->startOfDay()->utc();
+		$dt_max = CarbonImmutable::parse($max_date, $tz)->endOfDay()->utc();
+
+		return Constraint::between($dt_min, $dt_max);
+	}
+
 	public function getDisplayYearCycle(): string {
 		[$date_start, $date_end] = $this->getYearCycleDates();
 

+ 1 - 2
engine/searches/location_search.php

@@ -215,8 +215,7 @@ class LocationSearch {
 			$constraint = Constraint::between($this->minTestDate, $this->maxTestDate);
 		}
 		else {
-			[$min_dts, $max_dts] = $this->customer->getYearCycleDates();
-			$constraint = Constraint::between($min_dts, $max_dts);
+			$constraint = $this->customer->getYearCycleConstraint(TIMEZONE);
 		}
 
 		return $constraint;

+ 30 - 2
views/project_form.php

@@ -9,6 +9,24 @@
  * @var Template $template
  */
 
+// Get test counts for current year cycle
+$tests = Test::query([
+	"status" => Constraint::notEquals(Test::STATUS_CANCELLED),
+	"location_id" => array_column($locations, "id"),
+	"dts_start" => $customer->getYearCycleConstraint(TIMEZONE),
+]);
+
+$test_counts = [];
+foreach($tests as $test) {
+	if(!isset($test_counts[$test->location_id])) {
+		$test_counts[$test->location_id] = 0;
+	}
+
+	if($test->isCompleted()) {
+		$test_counts[$test->location_id]++;
+	}
+}
+
 $dt_start = $project->getDateTimeStart();
 $dt_deadline = $project->getDateTimeDeadline();
 
@@ -18,6 +36,7 @@ $date_report = $dt_report ? $dt_report->format("Y-m-d") : "";
 $name_readonly = $project->id ? "" : "readonly";
 $autogen_checked = $project->id ? "" : "checked";
 
+// Figure out which locations are selected
 $tests = [];
 $location_test = [];
 if($project->id) {
@@ -30,7 +49,12 @@ if($project->id) {
 $selected_locations = array_filter($locations, static function(Location $l) use ($location_ids) { return in_array($l->id, $location_ids, false); });
 $deselected_locations = array_filter($locations, static function(Location $l) use ($location_ids) { return !in_array($l->id, $location_ids, false); });
 
-$output_locations = static function(array $locations, bool $selected) use ($location_test) {
+/**
+ * @param Location[] $locations
+ * @param bool $selected
+ * @return void
+ */
+$output_locations = static function(array $locations, bool $selected) use ($location_test, $test_counts, $customer) {
 	foreach($locations as $location) {
 		$address = $location->getDisplayAddress(["address_1", "address_2", "city", "postal_code"]);
 
@@ -75,7 +99,11 @@ $output_locations = static function(array $locations, bool $selected) use ($loca
 						}
 						?>
 					</div>
-					<small><?=htmlspecialchars($address)?></small>
+					<small><?=htmlspecialchars($address)?></small><br />
+					<small title="<?=htmlspecialchars(__("Number of tests completed between %s", $customer->getDisplayYearCycle()))?>">
+						<strong>Completed:</strong>
+						<?=htmlspecialchars(sprintf("%d / %d", $test_counts[$location->id] ?? 0, $location->annual_test_count))?>
+					</small>
 				</div>
 				<div class="col-auto align-self-center text-right">
 					<button class="btn btn-outline-<?=$button_class?>" type="button">