Repository navigation
Expand file tree
/
Copy pathAddItem.html
More file actions
151 lines (129 loc) · 4.64 KB
/
Copy pathAddItem.html
File metadata and controls
151 lines (129 loc) · 4.64 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Add New Food Item</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
width: 400px;
}
label {
display: block;
margin-top: 10px;
}
input, select {
width: calc(100% - 16px); /* Ensures all inputs have the same width */
padding: 8px;
margin-top: 5px;
box-sizing: border-box;
}
button {
margin-top: 15px;
padding: 10px;
width: 100%;
background-color: green;
color: white;
border: none;
cursor: pointer;
}
*::-webkit-scrollbar {
width: 6px;
}
*::-webkit-scrollbar-track {
background: #f1f1f1;
border-radius: 10px;
}
*::-webkit-scrollbar-thumb {
background: #888;
border-radius: 10px;
}
*::-webkit-scrollbar-thumb:hover {
background: #555;
}
</style>
</head>
<body>
<h2>Add New Food Item</h2>
<form id="addItemForm">
<label for="fname">Food Name:</label>
<input type="text" id="fname" required>
<label for="category">Category:</label>
<select id="category" required>
<option value="">Select a category</option>
</select>
<label for="cost">Cost (₹):</label>
<input type="number" id="cost" step="0.01" required>
<label for="sgst">SGST (%):</label>
<input type="number" id="sgst" step="0.01" value="0">
<label for="cgst">CGST (%):</label>
<input type="number" id="cgst" step="0.01" value="0">
<label for="veg">Veg:</label>
<select id="veg">
<option value="1">Yes</option>
<option value="0">No</option>
</select>
<label for="active">Active:</label>
<select id="active">
<option value="1">Yes</option>
<option value="0">No</option>
</select>
<label for="is_on">Available:</label>
<select id="is_on">
<option value="1">Yes</option>
<option value="0">No</option>
</select>
<button type="submit">Add Item</button>
</form>
<script src="menu.js"></script>
<script>
const { ipcRenderer } = require("electron");
const {createTextPopup} = require("./textPopup");
// Fetch categories from database
async function loadCategories() {
try {
const categories = await ipcRenderer.invoke("get-categories-for-additem");
const categorySelect = document.getElementById("category");
categories.forEach(cat => {
let option = document.createElement("option");
option.value = cat.catid;
option.textContent = cat.catname;
categorySelect.appendChild(option);
});
} catch (error) {
console.error("Failed to load categories:", error);
}
}
document.getElementById("addItemForm").addEventListener("submit", async (event) => {
event.preventDefault();
const newItem = {
fname: document.getElementById("fname").value,
category: document.getElementById("category").value,
cost: parseFloat(document.getElementById("cost").value),
sgst: parseFloat(document.getElementById("sgst").value),
cgst: parseFloat(document.getElementById("cgst").value),
tax: parseFloat(document.getElementById("sgst").value) + parseFloat(document.getElementById("cgst").value),
active: parseInt(document.getElementById("active").value),
is_on: parseInt(document.getElementById("is_on").value),
veg: parseInt(document.getElementById("veg").value)
};
try {
// Add the item to the database
await ipcRenderer.invoke("add-food-item", newItem);
createTextPopup("Item added successfully!");
// After item is added, notify the main window to refresh the menu
ipcRenderer.send("refresh-menu");
// Close the add item window
window.close();
} catch (error) {
console.error("Error adding item:", error);
createTextPopup("Failed to add item.");
}
});
// Load categories on page load
window.onload = loadCategories;
</script>
</body>
</html>