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

Add machine count field for locations

Alan Lam 2 лет назад
Родитель
Сommit
524acb8a56

+ 3 - 0
controllers/location_add.php

@@ -43,6 +43,9 @@ if($submit) {
 		$location->area_manager = http::value("area_manager", "trim");
 		$location->area_manager_email = http::value("area_manager_email", "email");
 
+		$location->machine_count = http::value("machine_count", "int");
+		$location->annual_test_count = Util::clamp(http::value("annual_test_count", "int") ?: 1, 1, 200);
+
 		$location->do_not_test = http::value("do_not_test", "int") ? 1 : 0;
 		$location->closed = http::value("closed", "int") ? 1 : 0;
 		$location->archived = http::value("archived", "int") ? 1 : 0;

+ 1 - 0
controllers/location_edit.php

@@ -46,6 +46,7 @@ if($submit) {
 		$location->area_manager = http::value("area_manager", "trim");
 		$location->area_manager_email = http::value("area_manager_email", "email");
 
+		$location->machine_count = http::value("machine_count", "int");
 		$location->annual_test_count = Util::clamp(http::value("annual_test_count", "int") ?: 1, 1, 200);
 
 		$location->do_not_test = http::value("do_not_test", "int") ? 1 : 0;

+ 11 - 0
db/migrations/20231206124840_add_machine_count_field_to_location_table.php

@@ -0,0 +1,11 @@
+<?php
+
+use Phinx\Migration\AbstractMigration;
+
+class AddMachineCountFieldToLocationTable extends AbstractMigration {
+	public function change() {
+		$this->table("location")
+			->addColumn("machine_count", "integer", ["signed" => false, "null" => true, "after" => "operations_manager_name"])
+			->update();
+	}
+}

+ 2 - 1
engine/location.php

@@ -26,6 +26,7 @@
  * @property string $area_manager_name
  * @property string $area_manager_email
  * @property string $operations_manager_name
+ * @property int $machine_count
  * @property int $annual_test_count
  * @property bool $do_not_test
  * @property bool $closed
@@ -39,7 +40,7 @@ class Location extends Model {
 
 	protected static $table = "location";
 	protected static $id_field = "id";
-	protected static $fillable_fields = ["customer_id", "name", "legal_entity_name", "address_1", "address_2", "city", "county", "postal_code", "state", "country", "email", "phone", "opening_hours", "notes", "shop_left", "shop_right", "brand", "region", "region_name", "internal_id", "area_manager", "area_manager_name", "area_manager_email", "operations_manager_name", "annual_test_count", "do_not_test", "closed", "archived", "latitude", "longitude", "dts_verified"];
+	protected static $fillable_fields = ["customer_id", "name", "legal_entity_name", "address_1", "address_2", "city", "county", "postal_code", "state", "country", "email", "phone", "opening_hours", "notes", "shop_left", "shop_right", "brand", "region", "region_name", "internal_id", "area_manager", "area_manager_name", "area_manager_email", "operations_manager_name", "machine_count", "annual_test_count", "do_not_test", "closed", "archived", "latitude", "longitude", "dts_verified"];
 
 	// Object methods
 

+ 8 - 0
tasks/import_venues.php

@@ -134,6 +134,8 @@ for($i = 0; $data = fgetcsv($handle); $i++) {
 				case "Latitude": $latitude_column = $index; break;
 				case "Longitude": $longitude_column = $index; break;
 
+				case "Machine Count": $machine_count_column = $index; break;
+
 				case "Ignore":
 					break;
 
@@ -173,6 +175,8 @@ for($i = 0; $data = fgetcsv($handle); $i++) {
 	$region_name = isset($region_name_column) ? $data[$region_name_column] : null;
 	$operations_manager_name = isset($operations_manager_name_column) ? $data[$operations_manager_name_column] : null;
 
+	$machine_count = isset($machine_count_column) ? $data[$machine_count_column] : null;
+
 	if($address) {
 		// Try to determine address parts from address
 		$parts = explode(",", $address);
@@ -288,6 +292,10 @@ for($i = 0; $data = fgetcsv($handle); $i++) {
 		}
 	}
 
+	if($machine_count !== null) {
+		$location->machine_count = $machine_count;
+	}
+
 	if($dry_run) {
 		$success = true;
 	}

+ 8 - 0
views/location_form.php

@@ -222,6 +222,14 @@ if($is_edit) {
 								<input class="form-control" type="email" name="area_manager_email" id="area-manager-email" placeholder="Enter area manager email address" value="<?=htmlspecialchars($location->area_manager_email)?>" />
 							</div>
 						</div>
+
+						<div class="row mb-1">
+							<label class="col-sm-4 col-form-label" for="machine-count">Machine Count</label>
+							<div class="col-sm">
+								<input class="form-control" type="number" name="machine_count" id="machine-count" placeholder="Enter machine count" value="<?=htmlspecialchars($location->machine_count)?>" min="0" max="400" />
+							</div>
+						</div>
+
 						<div class="row mb-1">
 							<label class="col-sm-4 col-form-label" for="annual-test-count">Tests Per Year</label>
 							<div class="col-sm">