Przeglądaj źródła

Add ability to hide customers from "Map Overview" page; flip order of project list

Alan Lam 5 lat temu
rodzic
commit
de6643c38f

+ 2 - 0
controllers/customer_add.php

@@ -8,6 +8,7 @@ Core::addBreadcrumb("/account/customers/add", $page_title);
 
 $customer = new Customer;
 $customer->country = DEFAULT_COUNTRY;
+$customer->show_in_map_overview = 1;
 $customer->email_after_test = 1;
 $customer->email_locations_after_test = 1;
 
@@ -30,6 +31,7 @@ if($submit) {
 		$customer->email_after_test = http::value("email_after_test", "int");
 		$customer->email_locations_after_test = http::value("email_locations_after_test", "int");
 		$customer->year_cycle_month = http::value("year_cycle_month", "int");
+		$customer->show_in_map_overview = (int) http::value("show_in_map_overview", "int");
 
 		if(empty($customer->name)) $form_exception->addError("Name is required.");
 

+ 1 - 0
controllers/customer_edit.php

@@ -30,6 +30,7 @@ if($submit) {
 		$customer->email_after_test = http::value("email_after_test", "int");
 		$customer->email_locations_after_test = http::value("email_locations_after_test", "int");
 		$customer->year_cycle_month = http::value("year_cycle_month", "int");
+		$customer->show_in_map_overview = (int) http::value("show_in_map_overview", "int");
 
 		if(empty($customer->name)) $form_exception->addError("Name is required.");
 

+ 10 - 6
controllers/map_overview.php

@@ -9,17 +9,21 @@ Core::addBreadcrumb("/account/map-overview", $page_title);
 
 $today = gmdate("Y-m-d") . " 00:00:00";
 
+$customers = Customer::query([
+	"show_in_map_overview" => "1"
+], ["sort" => "name"]);
+
+$customer_ids = array_column($customers, "id");
+
+Customer::load($customer_ids);
+
 $projects = Project::query([
+	"customer_id" => $customer_ids,
 	"dts_deadline" => (new Constraint("MORE_THAN_OR_EQUAL"))->setValues($today)
 ], [
-	"sort" => "dts_deadline",
-	"order" => "desc",
+	"sort" => "dts_deadline"
 ]);
 
-Customer::load(array_column($projects, "customer_id"));
-
-$customers = Customer::query([], ["sort" => "name"]);
-
 View::includeOnce("header", compact("page_title"));
 View::include("map_overview", compact("customers", "projects"));
 View::includeOnce("footer");

+ 11 - 0
db/migrations/20210916164413_add_show_in_map_overview_field_to_customer_table.php

@@ -0,0 +1,11 @@
+<?php
+
+use Phinx\Migration\AbstractMigration;
+
+class AddShowInMapOverviewFieldToCustomerTable extends AbstractMigration {
+	public function change() {
+		$this->table("customer")
+			->addColumn("show_in_map_overview", "boolean", ["signed" => false, "default" => 1])
+			->update();
+	}
+}

+ 2 - 0
engine/customer.php

@@ -18,6 +18,7 @@
  * @property string $region_field_name
  * @property string $area_manager_field_name
  * @property int $year_cycle_month
+ * @property int $show_in_map_overview
  */
 
 class Customer extends Model {
@@ -30,6 +31,7 @@ class Customer extends Model {
 		"email_after_test", "email_locations_after_test",
 		"internal_id_field_name", "region_field_name", "area_manager_field_name",
 		"year_cycle_month",
+		"show_in_map_overview",
 	];
 
 	// Static methods

+ 14 - 2
views/customer_form.php

@@ -1,3 +1,9 @@
+<?php
+/**
+ * @var Customer $customer
+ * @var string $page_title
+ */
+?>
 <div class="container mt-3 py-4">
 	<h2><?=htmlspecialchars($page_title)?></h2>
 
@@ -42,7 +48,9 @@
 			<label class="col-sm-4 col-form-label" for="country">Country</label>
 			<div class="col-sm">
 				<select class="form-control" name="country" id="country">
-				<?=Form::renderCountryOptions($customer->country)?>
+				<?php
+				Form::renderCountryOptions($customer->country);
+				?>
 				</select>
 			</div>
 		</div>
@@ -75,7 +83,7 @@
                     <?php
                     foreach(range(1, 12) as $month) {
                         $display_month = sprintf("%02d", $month);
-                        $selected = ($customer->year_cycle_month == $month) ? "selected" : "";
+                        $selected = ((int) $customer->year_cycle_month === $month) ? "selected" : "";
                         ?>
                         <option value="<?=$month?>" <?=$selected?>><?=$display_month?></option>
                         <?php
@@ -88,6 +96,10 @@
 
 		<div class="row my-3">
 			<div class="col-sm offset-sm-4">
+				<div class="form-check">
+					<input class="form-check-input" type="checkbox" name="show_in_map_overview" id="show-in-map-overview" value="1" <?=Form::checked($customer->show_in_map_overview)?> />
+					<label for="show-in-map-overview">Show in Map Overview</label>
+				</div>
 				<div class="form-check">
 					<input class="form-check-input" type="checkbox" name="email_after_test" id="email-after-test" value="1" <?=Form::checked($customer->email_after_test)?> />
 					<label for="email-after-test">Email After Test</label>

+ 7 - 1
views/map_overview.php

@@ -1,3 +1,9 @@
+<?php /** @noinspection PhpUnhandledExceptionInspection */
+/**
+ * @var Customer[] $customers
+ * @var Project[] $projects
+ */
+?>
 <div class="container mt-3 py-4">
 
 	<input type="hidden" id="submit" value="<?=$_SESSION["csrf_token"]?>" />
@@ -70,7 +76,7 @@
 				$deadline = date("d/m/Y", $unix_deadline);
 
 				$icon = null;
-				if($project->time_of_day != "A") {
+				if(!$project->isAnytime()) {
 					$icon = $project->getTimeOfDayIcon();
 				}