1
0
Эх сурвалжийг харах

Added support for marking locations as closed.

Alan Lam 8 жил өмнө
parent
commit
c3dd29f4ed

+ 2 - 0
controllers/location_edit.php

@@ -34,6 +34,8 @@ if($submit) {
 		$location->internal_id = http::value("internal_id", "trim");
 		$location->area_manager = http::value("area_manager", "trim");
 
+		$location->closed = http::value("closed", "int");
+
 		if(empty($location->name)) $form_exception->addError("Name is required.");
 		if(empty($location->address_1)) $form_exception->addError("Location line 1 is required.");
 		if(empty($location->city)) $form_exception->addError("City is required.");

+ 1 - 1
controllers/project_add.php

@@ -102,7 +102,7 @@ if($submit) {
 	}
 }
 
-$locations = $customer->getLocations();
+$locations = $customer->getLocations(["closed" => 0]);
 
 View::includeOnce("header", compact("page_title"));
 View::include("project_form", compact("project", "templates", "locations", "location_ids"));

+ 3 - 2
engine/customer.php

@@ -38,8 +38,9 @@ class Customer extends Model {
 	}
 
 	// Object methods
-	public function getLocations() {
-		return Location::query(["customer_id" => $this->id], ["sort" => "name"]);
+	public function getLocations($query = []) {
+		$nvp = array_merge(["customer_id" => $this->id], $query);
+		return Location::query($nvp, ["sort" => "name"]);
 	}
 
 	public function getProjects() {

+ 1 - 4
engine/location.php

@@ -4,10 +4,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", "shop_left", "shop_right", "region", "internal_id", "area_manager", "latitude", "longitude", "dts_verified"];
-
-	protected static $field_map = [
-	];
+	protected static $fillable_fields = ["customer_id", "name", "legal_entity_name", "address_1", "address_2", "city", "county", "postal_code", "state", "country", "email", "phone", "opening_hours", "shop_left", "shop_right", "region", "internal_id", "area_manager", "closed", "latitude", "longitude", "dts_verified"];
 
 	// Object methods
 	public function getCustomer() {

+ 7 - 0
views/location.php

@@ -26,6 +26,13 @@ $photos = $location->getPhotos();
 		<div class="col">
 			<h2>
 				<?=htmlspecialchars($location->name)?>
+				<?php
+				if($location->closed) {
+					?>
+					<span class="badge badge-danger">Closed</span>
+					<?php
+				}
+				?>
 			</h2>
 		</div>
 		<div class="col-auto">

+ 73 - 46
views/location_form.php

@@ -24,7 +24,7 @@ $tabs = [
 		?>
 		</ul>
 
-		<div class="tab-content mb-3" id="tab-content">
+		<div class="tab-content" id="tab-content">
 			<div class="tab-pane fade show active" id="details" role="tabpanel" aria-labelledby="details-tab">
 				<div class="row">
 					<div class="col-lg mb-3 mb-lg-0">
@@ -96,6 +96,16 @@ $tabs = [
 								<textarea class="form-control" name="opening_hours" id="opening-hours" placeholder="Enter opening hours" rows="4" maxlength="100"><?=htmlspecialchars($location->opening_hours)?></textarea>
 							</div>
 						</div>
+
+						<div class="row mb-1">
+							<div class="col-sm offset-sm-4">
+								<div class="form-check">
+									<input class="form-check-input" type="checkbox" name="closed" id="closed" value="1" <?=Form::checked($location->closed)?> />
+									<label for="closed">Closed</label>
+								</div>
+								<small class="text-muted form-text">By marking a location as closed, they will no longer appear for selection in new Projects.</small>
+							</div>
+						</div>
 					</div>
 					<div class="col-lg">
 
@@ -146,67 +156,84 @@ $tabs = [
 			</div>
 
 			<div class="tab-pane fade" id="photos" role="tabpanel" aria-labelledby="photos-tab">
-				<div class="row mb-1">
-					<label class="col-sm-4 col-form-label" for="shop-left">Shop Name (Left)</label>
-					<div class="col-sm">
-						<input class="form-control" type="text" name="shop_left" id="shop-left" placeholder="Enter shop name (left)" value="<?=htmlspecialchars($location->shop_left)?>" />
-					</div>
-				</div>
-				<div class="row mb-1">
-					<label class="col-sm-4 col-form-label" for="shop-right">Shop Name (Right)</label>
-					<div class="col-sm">
-						<input class="form-control" type="text" name="shop_right" id="shop-right" placeholder="Enter shop name (right)" value="<?=htmlspecialchars($location->shop_right)?>" />
-					</div>
-				</div>
-			<?php
-			if($location->id) {
-				?>
-				<div class="row mb-3">
-					<label class="col-sm-4 col-form-label" for="photo">JPEG File</label>
-					<div class="col-sm">
-						<input class="form-control-file" type="file" name="photo" id="photo" />
-					</div>
-				</div>
-				<?php
-				if(!empty($photos)) {
-					?>
-					<h3>Manage Photos</h3>
+				<div class="row">
+					<div class="col-lg">
+						<div class="row mb-1">
+							<label class="col-sm-4 col-form-label" for="shop-left">Shop Name (Left)</label>
+							<div class="col-sm">
+								<input class="form-control" type="text" name="shop_left" id="shop-left" placeholder="Enter shop name (left)" value="<?=htmlspecialchars($location->shop_left)?>" />
+							</div>
+						</div>
+						<div class="row mb-1">
+							<label class="col-sm-4 col-form-label" for="shop-right">Shop Name (Right)</label>
+							<div class="col-sm">
+								<input class="form-control" type="text" name="shop_right" id="shop-right" placeholder="Enter shop name (right)" value="<?=htmlspecialchars($location->shop_right)?>" />
+							</div>
+						</div>
 
-					<div class="row">
+					</div>
+					<div class="col-lg">
 					<?php
-					foreach($photos as $photo) {
+					if($location->id) {
 						?>
-						<div class="col-md-6">
-							<div class="card">
-								<img class="card-img-top img-cover" src="/img/blank_4_3.png" alt="Photo" style="background-image: url(/account/locations/6/photos/<?=$photo->id?>)" />
-								<div class="card-body">
-									<div class="form-check">
-										<input class="form-check-input" type="checkbox" name="delete_file_ids[]" id="photo-<?=$photo->id?>" value="<?=$photo->id?>" />
-										<label class="form-check-label" for="photo-<?=$photo->id?>">Delete</label>
+						<div class="row mb-3">
+							<label class="col-sm-4 col-form-label" for="photo">JPEG File</label>
+							<div class="col-sm">
+								<input class="form-control-file" type="file" name="photo" id="photo" />
+							</div>
+						</div>
+						<?php
+						if(!empty($photos)) {
+							?>
+							<h3>Manage Photos</h3>
+
+							<div class="row">
+							<?php
+							foreach($photos as $photo) {
+								?>
+								<div class="col-md-6">
+									<div class="card">
+										<img class="card-img-top img-cover" src="/img/blank_4_3.png" alt="Photo" style="background-image: url(/account/locations/6/photos/<?=$photo->id?>)" />
+										<div class="card-body">
+											<div class="form-check">
+												<input class="form-check-input" type="checkbox" name="delete_file_ids[]" id="photo-<?=$photo->id?>" value="<?=$photo->id?>" />
+												<label class="form-check-label" for="photo-<?=$photo->id?>">Delete</label>
+											</div>
+										</div>
 									</div>
 								</div>
+								<?php
+							}
+							?>
 							</div>
+							<?php
+						}
+					}
+					else {
+						?>
+						<div class="alert alert-info">
+							<i class="fal fa-fw fa-info-circle"></i> Adding photos will become available when location is added.
 						</div>
 						<?php
 					}
 					?>
 					</div>
-					<?php
-				}
-			}
-			else {
-				?>
-				<div class="alert alert-info">
-					<i class="fal fa-fw fa-info-circle"></i> Adding photos will become available when location is added.
 				</div>
-				<?php
-			}
-			?>
 			</div>
 
 		</div>
 
+		<div class="row">
+			<div class="col-lg">
+				<div class="row">
+					<div class="col-sm offset-sm-4">
+						<button class="btn btn-primary" type="submit" name="submit" value="<?=$_SESSION["csrf_token"]?>">Submit</button>
+					</div>
+				</div>
+			</div>
+			<div class="col-lg">
+			</div>
+		</div>
 
-		<button class="btn btn-primary" type="submit" name="submit" value="<?=$_SESSION["csrf_token"]?>">Submit</button>
 	</form>
 </div>

+ 9 - 1
views/location_list.php

@@ -16,7 +16,15 @@
 					<?=$location->id?>
 				</td>
 				<td>
-					<a href="/account/locations/<?=$location->id?>"><?=htmlspecialchars($location->name)?></a><br />
+					<a href="/account/locations/<?=$location->id?>"><?=htmlspecialchars($location->name)?></a>
+					<?php
+					if($location->closed) {
+						?>
+						<span class="badge badge-danger">Closed</span>
+						<?php
+					}
+					?>
+					<br />
 					<?php
 					if($location->internal_id) {
 						?>