浏览代码

Add ability to change a location for a lead

Alan Lam 2 年之前
父节点
当前提交
4ebd071c41
共有 2 个文件被更改,包括 25 次插入 和 4 次删除
  1. 4 2
      controllers/sale.php
  2. 21 2
      views/sale.php

+ 4 - 2
controllers/sale.php

@@ -96,10 +96,11 @@ $controller = new class($number) {
 		$company_id = $this->request->int("company_id");
 		$company = $this->requireCompany($company_id);
 
+		$location_id = $this->request->int("location_id");
+		$location = Location::require($location_id);
+
 		$sale = $this->getSale();
 		if(!$sale) {
-			$location_id = $this->request->int("location_id");
-			$location = Location::require($location_id);
 
 			$sale = new Sale();
 			$sale->location_id = $location->id;
@@ -111,6 +112,7 @@ $controller = new class($number) {
 			$success_message = __("Lead created successfully.");
 		}
 		else {
+			$sale->location_id = $location->id;
 			$sale->status = $this->request->int("status");
 			$sale->currency = $this->request->string("currency");
 			$sale->tax_rate = $this->request->decimal("tax_rate", 2);

+ 21 - 2
views/sale.php

@@ -15,6 +15,15 @@ $user = $core->getUser();
 
 $location = $sale->getLocation();
 
+$customers = Customer::getAll();
+
+$location_options = [];
+foreach($customers as $customer) {
+	foreach($customer->getLocations() as $customer_location) {
+		$location_options[$customer_location->id] = $customer_location->getDisplayName();
+	}
+}
+
 ?>
 
 <section class="mb-4">
@@ -44,7 +53,7 @@ $location = $sale->getLocation();
 				</div>
 
 				<div class="row">
-					<div class="col-md">
+					<div class="col-md-6">
 						<div class="mb-3">
 							<label class="form-label" for="company-id">
 								<?=htmlspecialchars(__("Company"))?>
@@ -57,7 +66,17 @@ $location = $sale->getLocation();
 							</select>
 						</div>
 					</div>
-					<div class="col-md">
+					<div class="col-md-6">
+						<div class="mb-3">
+							<label class="form-label" for="location-id"><?= htmlspecialchars(__("Location")) ?></label>
+							<select class="form-select" name="location_id" id="location-id">
+								<?php
+								HtmlHelper::renderOptions($location_options, $sale->location_id);
+								?>
+							</select>
+						</div>
+					</div>
+					<div class="col-md-6">
 						<div class="mb-3">
 							<label class="form-label" for="date-predicted-sold"><?=htmlspecialchars(__("Predicted Sold Date"))?></label>
 							<input class="form-control" type="date" name="date_predicted_sold" id="date-predicted-sold" value="<?=htmlspecialchars($sale->date_predicted_sold)?>" required />