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

Add product lookup for populating ARU item description

Alan Lam 3 лет назад
Родитель
Сommit
dfa5db98ee
2 измененных файлов с 32 добавлено и 1 удалено
  1. 10 0
      public/js/new-document-modal.js
  2. 22 1
      views/modals/new_document.php

+ 10 - 0
public/js/new-document-modal.js

@@ -24,6 +24,16 @@ class NewDocumentModal {
 		this.$itemDescriptionField = this.getField("item_description");
 		this.$itemDescriptionField = this.getField("item_description");
 		this.$itemSerialNumberField = this.getField("item_serial_number");
 		this.$itemSerialNumberField = this.getField("item_serial_number");
 
 
+		this.$productLookupDropdown = $("#new-document-product-lookup");
+		this.$productLookupDropdown.select2({
+			theme: "bootstrap-5",
+			dropdownParent: this.$modal
+		});
+		this.$productLookupDropdown.on("change", () => {
+			const $option = this.$productLookupDropdown.find("option:selected");
+			this.$itemDescriptionField.val($option.data("name"));
+		});
+
 		this.$locationDropdown.select2({
 		this.$locationDropdown.select2({
 			theme: "bootstrap-5",
 			theme: "bootstrap-5",
 			dropdownParent: this.$locationDropdown.closest("div")
 			dropdownParent: this.$locationDropdown.closest("div")

+ 22 - 1
views/modals/new_document.php

@@ -1,9 +1,12 @@
-<?php
+<?php /** @noinspection PhpUnhandledExceptionInspection */
 namespace App;
 namespace App;
 use App\Helpers\HtmlHelper;
 use App\Helpers\HtmlHelper;
 
 
 $core = Core::getInstance();
 $core = Core::getInstance();
 $settings = $core->getSettings();
 $settings = $core->getSettings();
+
+$products = Product::query([], ["sort" => "name"]);
+
 ?>
 ?>
 <div class="modal fade" role="dialog" tabindex="-1" data-backdrop="static" id="new-document-modal">
 <div class="modal fade" role="dialog" tabindex="-1" data-backdrop="static" id="new-document-modal">
 	<div class="modal-dialog modal-lg">
 	<div class="modal-dialog modal-lg">
@@ -62,6 +65,24 @@ $settings = $core->getSettings();
 
 
 					<p><?=htmlspecialchars(__("Enter details of the part that is being returned if known."))?></p>
 					<p><?=htmlspecialchars(__("Enter details of the part that is being returned if known."))?></p>
 
 
+					<div class="mb-3">
+						<label class="form-label" for="new-document-product-lookup">
+							<?=htmlspecialchars(__("Product Lookup"))?>
+						</label>
+						<select class="form-control" id="new-document-product-lookup" data-placeholder="<?=htmlspecialchars(__("Select Product"))?>">
+							<option value=""></option>
+							<?php
+							foreach($products as $product) {
+								?>
+								<option value="<?=$product->id?>" data-name="<?=htmlspecialchars($product->name)?>">
+									<?=htmlspecialchars($product->name)?> / <?=htmlspecialchars($product->sku)?>
+								</option>
+								<?php
+							}
+							?>
+						</select>
+					</div>
+
 					<div class="mb-3">
 					<div class="mb-3">
 						<label class="form-label" for="new-document-item-description">
 						<label class="form-label" for="new-document-item-description">
 							<?=htmlspecialchars(__("Description"))?>
 							<?=htmlspecialchars(__("Description"))?>