-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinventoryEnd.js
More file actions
83 lines (68 loc) · 2.56 KB
/
Copy pathinventoryEnd.js
File metadata and controls
83 lines (68 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* global $ */
async function fetchAndPopulateTable() {
$.ajax({
type: "POST",
url: "http://localhost:5000/get_inventory",
success: function(response) {
if (response.status === "success") {
let inventory = response.inventory;
let tableBody = $("#inventory-table tbody");
inventory.forEach(item => {
let row = "<tr>";
row += `<td>${item[0]}</td>`;
row += `<td>${item[1]}</td>`;
row += `<td>${item[2]}</td>`;
row += `<td>${item[3]}</td>`;
row += `<td>${item[4]}</td>`;
row += "</tr>";
tableBody.append(row);
});
} else {
console.log("Error:", response.message);
}
},
error: function(xhr, status, error) {
console.error("Error:", error);
}
});
}
document.addEventListener('DOMContentLoaded', fetchAndPopulateTable);
async function fetchSupplier(itemValue, searchType) {
const data = searchType === "id" ? { itemid: itemValue } : { itemname: itemValue };
$.ajax({
type: "POST",
url: "http://localhost:5000/get_supplier_by_itemname",
contentType: 'application/json',
data: JSON.stringify(data),
success: function(response) {
console.log("Response:", response);
let supplierField = $("#supplierData");
if (response.status === "success") {
let supplier = response.supplier;
let supplierInfo = `Name: ${supplier[0]}, Phone: ${supplier[1]}, Email: ${supplier[2]}`;
supplierField.val(supplierInfo);
} else {
supplierField.val("No supplier found.");
console.log("Error:", response.message);
}
},
error: function(xhr, status, error) {
console.error("Error:", error);
$("#supplierData").val("Error fetching supplier data.");
}
});
}
$(document).ready(function() {
$("#formItemID").on("submit", function(event) {
event.preventDefault();
let itemId = $("#itemid").val().trim();
$("#itemid").val(itemId);
if (itemId) fetchSupplier(itemId, "id");
});
$("#formItemName").on("submit", function(event) {
event.preventDefault();
let itemName = $("#itemname").val().trim();
$("#itemname").val(itemName);
if (itemName) fetchSupplier(itemName, "name");
});
});