Просмотр исходного кода

Add support for additional tester invoice fields

Alan Lam 7 лет назад
Родитель
Сommit
b2e676cf99

+ 17 - 7
controllers/test_invoice.php

@@ -15,16 +15,22 @@ $values = $test->getValues(true);
 
 $location_address = $location->name . ", " . $location->getDisplayAddress(["address_1", "address_2", "city", "postal_code"]);
 
+// Base cost
 $fee = floatval($test->test_fee) > 0 ? $test->test_fee : $project->default_tester_fee;
 $fee = (float) $fee;
 
-$play_spent = (float) ($values["play_spent"] ?? 0);
 $travel_cost = (float) http::value("travel_cost", "float");
+$test->test_travel_cost = $travel_cost;
 
-$invoice_total = $fee + $play_spent + $travel_cost;
+$invoice_total = $fee + $travel_cost;
 
-$test->test_travel_cost = $travel_cost;
+// Additional tester invoice fields
+$tester_invoice_fields = $template->getTesterInvoiceFields();
+foreach($tester_invoice_fields as $field) {
+	$invoice_total += (float) $values[$field->name] ?? 0;
+}
 
+// Get invoice address
 $address = $tester->getInvoiceAddress();
 if(!$address) throw new Exception(_("Invoice address not found. Please set an address as the invoice address then try again."));
 if(!$tester->hasValidPaymentMethod()) throw new Exception(_("No valid payment method found. Please go to the Settings page and make sure all respective fields are filled in and then try again."));
@@ -175,18 +181,22 @@ ob_start();
 					<td align="right" valign="top">£<?=number_format($fee, 2)?></td>
 				</tr>
 				<?php
-				if($play_spent) {
+
+				foreach($tester_invoice_fields as $field) {
+					$value = $values[$field->name] ?? 0;
+					if(!$value) continue;
 					?>
 					<tr>
 						<td>
-							<strong>Play Costs</strong>
+							<strong><?=htmlspecialchars($field->label)?></strong>
 						</td>
 						<td align="right" valign="top">1</td>
-						<td align="right" valign="top">£<?=number_format($play_spent, 2)?></td>
-						<td align="right" valign="top">£<?=number_format($play_spent, 2)?></td>
+						<td align="right" valign="top">£<?=number_format($value, 2)?></td>
+						<td align="right" valign="top">£<?=number_format($value, 2)?></td>
 					</tr>
 					<?php
 				}
+
 				if($travel_cost) {
 					?>
 					<tr>

+ 7 - 0
engine/template.php

@@ -45,6 +45,13 @@ class Template extends Model {
 		return $fields;
 	}
 
+	public function getTesterInvoiceFields() {
+		$json = json_decode($this->json);
+		if(!$json) throw new Exception("Failed to decode template JSON.");
+
+		return $json->testerInvoiceFields ?? [];
+	}
+
 	public function setOverrides($overrides) {
 		$this->overrides = $overrides;
 	}

+ 4 - 1
json/age_verification.json

@@ -1,4 +1,7 @@
 {
+	"testerInvoiceFields": [
+		{"name": "play_spent", "label": "Play Costs"}
+	],
 	"beforeTest": [
 		{
 			"type": "header",
@@ -195,4 +198,4 @@
 			"maxLength": 600
 		}
 	]
-}
+}

+ 5 - 1
json/age_verification_mitchells_and_butlers.json

@@ -1,4 +1,8 @@
 {
+	"testerInvoiceFields": [
+		{"name": "play_spent", "label": "Play Costs"},
+		{"name": "bar_expenditure", "label": "Bar Expenditure"}
+	],
 	"beforeTest": [
 		{
 			"type": "header",
@@ -249,4 +253,4 @@
 			"maxLength": 600
 		}
 	]
-}
+}

+ 4 - 1
json/mystery_shop.json

@@ -1,4 +1,7 @@
 {
+	"testerInvoiceFields": [
+		{"name": "play_spent", "label": "Play Costs"}
+	],
 	"beforeTest": [
 		{
 			"type": "header",
@@ -170,4 +173,4 @@
 			"maxLength": 600
 		}
 	]
-}
+}