Browse Source

Add "New Lead" button

Alan Lam 3 years ago
parent
commit
ae48c089f5
3 changed files with 36 additions and 10 deletions
  1. 7 0
      public/js/new-sale-modal.js
  2. 18 1
      views/entity_form.php
  3. 11 9
      views/modals/new_sale.php

+ 7 - 0
public/js/new-sale-modal.js

@@ -19,6 +19,13 @@ class NewSaleModal {
 			theme: "bootstrap-5",
 			dropdownParent: this.$locationDropdown.closest("div")
 		});
+
+		const parameters = new URLSearchParams(window.location.search);
+		const locationId = parameters.get("add_location_id");
+		if(locationId) {
+			this.$modal.modal("show");
+		}
+
 	}
 
 	getField(name) {

+ 18 - 1
views/entity_form.php

@@ -26,7 +26,24 @@ if($is_location) {
 }
 
 ?>
-<h3><?=htmlspecialchars($title)?></h3>
+
+<div class="row">
+	<div class="col">
+		<h3><?=htmlspecialchars($title)?></h3>
+	</div>
+	<div class="col-auto">
+		<?php
+		if($is_location && !$model->isNew()) {
+			?>
+			<a class="btn btn-success" href="/leads?add_location_id=<?=$model->id?>">
+				<i class="fa fa-fw fa-plus"></i>
+				<?=htmlspecialchars(__("Add Lead"))?>
+			</a>
+			<?php
+		}
+		?>
+	</div>
+</div>
 
 <form method="post">
 

+ 11 - 9
views/modals/new_sale.php

@@ -9,9 +9,19 @@ use App\Helpers\HtmlHelper;
 
 $customers = isset($customer) ? [$customer] : Customer::getAll();
 
+$request = Request::fromRequest();
+
 $core = Core::getInstance();
 $settings = $core->getSettings();
 $default_company_id = $settings->defaultCompanyId ?? null;
+$default_location_id = $request->int("add_location_id");
+
+$location_options = [];
+foreach($customers as $customer) {
+	foreach($customer->getLocations() as $location) {
+		$location_options[$location->id] = $location->getDisplayName();
+	}
+}
 
 ?>
 <div class="modal fade" role="dialog" tabindex="-1" data-backdrop="static" id="new-sale-modal">
@@ -37,15 +47,7 @@ $default_company_id = $settings->defaultCompanyId ?? null;
 					<label class="form-label" for="location-id"><?= htmlspecialchars(__("Location")) ?></label>
 					<select class="form-select" name="location_id" id="location-id">
 						<?php
-						foreach($customers as $customer) {
-							foreach($customer->getLocations() as $location) {
-								?>
-								<option value="<?=$location->id?>">
-									<?=htmlspecialchars($location->getDisplayName())?>
-								</option>
-								<?php
-							}
-						}
+						HtmlHelper::renderOptions($location_options, $default_location_id);
 						?>
 					</select>
 				</div>