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

Allow updating of location for documents

Alan Lam 2 лет назад
Родитель
Сommit
0b8c1b8c76
4 измененных файлов с 77 добавлено и 47 удалено
  1. 6 0
      controllers/document.php
  2. 4 0
      engine/Helpers/HtmlHelper.php
  3. 15 0
      engine/Location.php
  4. 52 47
      views/document.php

+ 6 - 0
controllers/document.php

@@ -205,6 +205,12 @@ $controller = new class($document_type, $document_number) {
 			$document->company_id = $company->id;
 		}
 
+		$location_id = $this->request->int("location_id");
+		if($document->location_id && $location_id) {
+			$location = $this->requireLocation($location_id);
+			$document->location_id = $location->id;
+		}
+
 		if($document->isSalesOrder()) {
 			$document->invoice_status = $this->request->int("invoice_status");
 			$document->terms = $this->request->string("terms");

+ 4 - 0
engine/Helpers/HtmlHelper.php

@@ -32,4 +32,8 @@ class HtmlHelper {
 		return $value ? "hidden" : "";
 	}
 
+	public static function required($value): string {
+		return $value ? "required" : "";
+	}
+
 }

+ 15 - 0
engine/Location.php

@@ -37,9 +37,24 @@ class Location extends Model {
 	use DateTimeTrait;
 	use SoftDeleteTrait;
 
+	/**
+	 * @return string[]
+	 * @throws Exception
+	 */
+	public static function getOptions(): array {
+		$options = [];
+		foreach(Customer::getAll() as $customer) {
+			foreach($customer->getLocations() as $location) {
+				$options[$location->id] = $location->getDisplayName();
+			}
+		}
+		return $options;
+	}
+
 	/**
 	 * @param Request $request
 	 * @param Location $location
+	 * @param Customer|null $customer_override
 	 * @return Location
 	 * @throws Exception
 	 */

+ 52 - 47
views/document.php

@@ -18,8 +18,6 @@ $user = $core->getUser();
 $sale = $document->getSale();
 $related_document = $document->getRelatedDocument();
 
-$location = $document->getLocation();
-
 ?>
 <section class="mb-4">
 	<h3 class="mb-3">
@@ -50,44 +48,62 @@ $location = $document->getLocation();
 
 				<?php
 				$user->insertCsrfToken();
-
-				if($document->isSalesOrder()) {
-					?>
-					<div class="mb-3">
-						<label for="invoice-status" class="form-label">
-							<b><?=htmlspecialchars(__("Status"))?></b>
-						</label>
-						<span class="ms-1"></span>
-						<span class="badge rounded-pill text-bg-danger">
-							<?=htmlspecialchars(__("Important"))?>
-						</span>
-						<select class="form-select" name="invoice_status" id="invoice-status">
-							<?php
-							HtmlHelper::renderOptions(SalesOrderStatuses::options(), $document->invoice_status);
+				?>
+				<div class="row">
+					<div class="col-sm-6">
+						<?php
+						if($document->isSalesOrder()) {
 							?>
-						</select>
-					</div>
-					<?php
-				}
-				else if($document->isAru()) {
-					?>
-					<div class="mb-3">
-						<label for="aru-status" class="form-label">
-							<b><?=htmlspecialchars(__("Status"))?></b>
-						</label>
-						<span class="ms-1"></span>
-						<span class="badge rounded-pill text-bg-danger">
-							<?=htmlspecialchars(__("Important"))?>
-						</span>
-						<select class="form-select" name="aru_status" id="aru-status">
+							<div class="mb-3">
+								<label for="invoice-status" class="form-label">
+									<b><?=htmlspecialchars(__("Status"))?></b>
+								</label>
+								<span class="ms-1"></span>
+								<span class="badge rounded-pill text-bg-danger">
+									<?=htmlspecialchars(__("Important"))?>
+								</span>
+								<select class="form-select" name="invoice_status" id="invoice-status">
+									<?php
+									HtmlHelper::renderOptions(SalesOrderStatuses::options(), $document->invoice_status);
+									?>
+								</select>
+							</div>
 							<?php
-							HtmlHelper::renderOptions(AruStatuses::options(), $document->aru_status);
+						}
+						else if($document->isAru()) {
 							?>
-						</select>
+							<div class="mb-3">
+								<label for="aru-status" class="form-label">
+									<b><?=htmlspecialchars(__("Status"))?></b>
+								</label>
+								<span class="ms-1"></span>
+								<span class="badge rounded-pill text-bg-danger">
+									<?=htmlspecialchars(__("Important"))?>
+								</span>
+								<select class="form-select" name="aru_status" id="aru-status">
+									<?php
+									HtmlHelper::renderOptions(AruStatuses::options(), $document->aru_status);
+									?>
+								</select>
+							</div>
+							<?php
+						}
+						?>
 					</div>
-					<?php
-				}
-				?>
+					<div class="col-sm-6">
+						<div class="mb-3">
+							<label for="location" class="form-label">
+								<?=htmlspecialchars(__("Location"))?>
+							</label>
+							<select class="form-select" name="location_id" id="location" <?=HtmlHelper::required($document->location_id)?>>
+							    <option value=""><?=htmlspecialchars(__("Select Location"))?></option>
+								<?php
+								HtmlHelper::renderOptions(Location::getOptions(), $document->location_id);
+								?>
+							</select>
+						</div>
+					</div>
+				</div>
 
 				<div class="row">
 					<?php
@@ -334,17 +350,6 @@ $location = $document->getLocation();
 
 								<dt><?=htmlspecialchars(__("Date/Time Created"))?></dt>
 								<dd><?=htmlspecialchars($user->formatDateTime($document->getDateTimeCreated()))?></dd>
-
-								<?php
-								if($location) {
-									?>
-									<dt><?=htmlspecialchars(__("Location"))?></dt>
-									<dd>
-										<a href="<?=htmlspecialchars($location->getUrl())?>"><?=htmlspecialchars($location->getDisplayName())?></a>
-									</dd>
-									<?php
-								}
-								?>
 							</dl>
 						</section>
 					</div>