Browse Source

Add "Alcohol Test Result" column to customer CSV export

Alan Lam 1 year ago
parent
commit
7a62361750
1 changed files with 32 additions and 8 deletions
  1. 32 8
      template_processing/age_verification/project_customer_csv.php

+ 32 - 8
template_processing/age_verification/project_customer_csv.php

@@ -24,8 +24,12 @@ $field_names = [
 	"All-Time Test Count", "Current Year Period Test Count"
 ];
 
-if($config->hasAlcohol ?? false) {
-	array_splice($field_names, 2, 0, ["Gaming Void", "Alcohol Void"]);
+$has_alcohol = $config->hasAlcohol ?? false;
+
+if($has_alcohol) {
+	$field_names[0] = "Gaming Test Result";
+	array_splice($field_names, 1, 0, ["Alcohol Test Result"]);
+	array_splice($field_names, 3, 0, ["Gaming Void", "Alcohol Void"]);
 }
 
 foreach($fields as $field) {
@@ -53,7 +57,8 @@ foreach($tests as $test) {
 	$test_end = "";
 	$test_duration = "";
 
-	$result = "Pending";
+	$gaming_result = "N/A";
+	$alcohol_result = "N/A";
 
 	$age = "";
 	$gender = "";
@@ -62,9 +67,6 @@ foreach($tests as $test) {
 	$output = [];
 
 	if($test->pass !== null) {
-
-		$result = $test->pass ? "Pass" : "Fail";
-
 		$test_start_dt = new DateTime($test->dts_start);
 		$test_end_dt = new DateTime($test->dts_end);
 		$test_duration_diff = $test_start_dt->diff($test_end_dt, true);
@@ -83,18 +85,40 @@ foreach($tests as $test) {
 		}
 	}
 
+	$test_values = $test->getValues(true);
+
 	if($test->isVoid()) {
 		$gaming_void = "Y";
 		$alcohol_void = "Y";
+		$gaming_result = "Void";
+		$alcohol_result = "Void";
 	}
 	else {
 		$gaming_void = $test->void_primary ? "Y" : "N";
+		if($test->void_primary) {
+			$gaming_result = "Void";
+		}
+		elseif($test->pass !== null) {
+			$gaming_result = $test->pass ? "Pass" : "Fail";
+		}
+
 		$alcohol_void = $test->void_secondary ? "Y" : "N";
+		if($test->void_secondary) {
+			$alcohol_result = "Void";
+		}
+		elseif($test->pass !== null && $has_alcohol) {
+			$alcohol_purchased = (bool) ($test_values["alcohol_purchased"] ?? false);
+			$alcohol_pass = ($alcohol_purchased === false);
+			$alcohol_result = $alcohol_pass ? "Pass" : "Fail";
+		}
 	}
 
-	$output[] = $result;
+	$output[] = $gaming_result;
+	if($has_alcohol) {
+		$output[] = $alcohol_result;
+	}
 	$output[] = $test->isVoid() ? "Y" : "N";
-	if($config->hasAlcohol ?? false) {
+	if($has_alcohol) {
 		$output[] = $gaming_void;
 		$output[] = $alcohol_void;
 	}