-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpostsale.html
387 lines (336 loc) · 12.8 KB
/
postsale.html
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
<!DOCTYPE html>
<html lang="ar">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>كاشير- حفظ فاتورة بيع</title>
<link href="https://fonts.googleapis.com/css2?family=Cairo:wght@400;700&display=swap" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/quagga/0.12.1/quagga.min.js"></script> <!-- Include QuaggaJS -->
<style>
body {
display: flex;
flex-direction: column; /* Stack elements vertically */
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
font-family: 'Cairo', sans-serif;
background-color: #B8E0CA; /* Soft, slightly darker green */
overflow: auto; /* Enable scrolling for the whole page */
position: relative;
}
.icon-textbox-container {
position: absolute;
top: 10px;
left: 10px;
display: flex;
align-items: center;
background-color: #A2D5B6; /* A soft, slightly darker green */
border-radius: 8px;
box-shadow: 0 0 8px rgba(0, 0, 0, 0.2);
}
.icon {
width: 35px;
height: auto;
cursor: pointer;
}
.textbox {
width: 200px;
height: 20px;
margin-left: 10px;
background-color: #E2F6ED; /* Very light, friendly green */
border: none;
outline: none;
font-size: 12px;
text-align: left;
padding: 5px;
}
.center-container {
display: flex;
flex-direction: column;
align-items: center;
border: 2px solid black;
padding: 20px;
border-radius: 8px;
background-color: #B8E0CA; /* Soft, slightly darker green */
}
.barcode-textbox {
width: 300px;
height: 35px;
font-size: 18px;
padding: 5px;
text-align: right;
border: none;
outline: none;
background-color: #E2F6ED; /* Very light, friendly green */
}
.form-label {
font-size: 14px;
color: #333;
text-align: right;
display: block;
width: 100%;
margin-bottom: 0;
}
/* Custom style for dropdown menu */
.custom-dropdown {
width: 300px;
height: 35px;
font-size: 18px;
padding: 5px;
text-align: right;
border: none;
outline: none;
background-color: #E2F6ED; /* Very light, friendly green */
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="black"><path d="M7 10l5 5 5-5H7z"/></svg>');
background-repeat: no-repeat;
background-position: calc(100% - 10px) center;
background-size: 20px;
}
.button-container {
display: flex;
justify-content: space-between;
margin-top: 20px; /* Add some space above the buttons */
gap: 50px; /* Add gap between buttons */
}
.submit-button {
background-color: #006400; /* Dark green */
color: white;
border: none;
padding: 10px 20px;
font-size: 18px;
cursor: pointer;
}
.submit-button:hover {
opacity: 0.8; /* Optional: Add hover effect */
}
.new-container {
display: flex;
flex-direction: column;
align-items: center;
border: 2px dashed gray;
padding: 20px;
border-radius: 8px;
background-color: #F0F0F0; /* Light gray background */
margin-top: 20px; /* Adds spacing from the above container */
}
</style>
</head>
<body>
<!-- Top left container with off button and username textbox -->
<div class="icon-textbox-container">
<a href="https://fekrasolutions.github.io/Stores-Cashier-ERP-System/">
<img src="Media/off.png" alt="Icon" class="icon">
</a>
<input type="text" class="textbox" id="emailTextbox" placeholder="" readonly />
</div>
<!-- Center container with camera preview and barcode textbox -->
<div class="center-container">
<label for="category-dropdown" class="form-label">إجمالي الفاتورة</label>
<input type="text" id="invoicetotal" class="barcode-textbox" readonly>
<label for="category-dropdown" class="form-label">تم دفع</label>
<input type="number" id="paid" class="barcode-textbox">
<label for="category-dropdown" class="form-label">المتبقي</label>
<input type="number" id="change" class="barcode-textbox" readonly>
<!-- Buttons at the bottom -->
<div class="button-container">
<button id="printbutton" class="submit-button">طباعة</button>
<button id="submit-button" class="submit-button">حفظ الفاتورة</button>
</div>
</div>
<!-- New empty container below the existing one -->
<div class="new-container">
<table id="dynamicTable" style="width: 100%; border-collapse: collapse;">
<thead>
<tr>
<th style="padding: 10px; border: 1px solid #ddd; text-align: center;">الصنف</th>
<th style="padding: 10px; border: 1px solid #ddd; text-align: center;">الكمية</th>
<th style="padding: 10px; border: 1px solid #ddd; text-align: center;">سعر</th>
<th style="padding: 10px; border: 1px solid #ddd; text-align: center;">إجمالي</th>
</tr>
</thead>
<tbody>
<!-- Dynamic rows will be inserted here -->
</tbody>
</table>
</div>
<script>
window.onload = async function () {
const username = getQueryParameter('username');
if (username) {
document.getElementById('emailTextbox')?.setAttribute('placeholder', username);
}
const sheetName = username || "DefaultSheetName"; // Use "DefaultSheetName" as fallback
const url = `https://script.google.com/macros/s/AKfycby1T0_lbAXyQLLBTbTUuNfbVy-x-jo14EUfO5vZkS_LrQsUQWOVDCBBQ3YPrU3A5f9I/exec?sheetName=${sheetName}`;
try {
const response = await fetch(url);
const data = await response.json();
if (data.value) {
const invoiceTotalElement = document.getElementById('invoicetotal');
invoiceTotalElement?.setAttribute('value', data.value);
// Update the change field initially
updateChangeField();
} else {
console.error("Error fetching value:", data.error);
}
} catch (error) {
console.error("Fetch error:", error);
}
// Add event listener for the paid field
document.getElementById('paid')?.addEventListener('input', updateChangeField);
fetchTableData();
};
function getQueryParameter(name) {
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get(name);
}
// Function to update the "change" field
function updateChangeField() {
const invoiceTotalElement = document.getElementById('invoicetotal');
const paidElement = document.getElementById('paid');
const changeElement = document.getElementById('change');
const invoiceTotal = parseFloat(invoiceTotalElement?.value || 0);
const paid = parseFloat(paidElement?.value || 0);
if (changeElement) {
changeElement.setAttribute('value', (paid - invoiceTotal).toFixed(2));
}
}
// Function to fetch data from Google Sheets through the web app
function fetchTableData() {
// Get the sheet name from the placeholder in the emailTextbox
var sheetName = document.getElementById("emailTextbox").placeholder;
// Define the URL of the Google Apps Script Web App
var url = "https://script.google.com/macros/s/AKfycbw4nPVkgDs_iEs7JCY98ySGXYzvkv0C2rLACAc-IFQgxZ-sJtDN2DSHHZAFFsdxsuTr/exec?sheetName=" + sheetName;
// Fetch data from the web app
fetch(url)
.then(response => response.json())
.then(data => {
// Get the table body element
var tableBody = document.querySelector("#dynamicTable tbody");
// Clear any existing rows
tableBody.innerHTML = "";
// Loop through the data and create table rows dynamically
data.forEach(row => {
var tr = document.createElement("tr");
var tdItem = document.createElement("td");
tdItem.textContent = row.item;
tdItem.style.padding = "10px";
tdItem.style.textAlign = "center";
tr.appendChild(tdItem);
var tdQuantity = document.createElement("td");
tdQuantity.textContent = row.quantity;
tdQuantity.style.padding = "10px";
tdQuantity.style.textAlign = "center";
tr.appendChild(tdQuantity);
var tdPrice = document.createElement("td");
tdPrice.textContent = row.price;
tdPrice.style.padding = "10px";
tdPrice.style.textAlign = "center";
tr.appendChild(tdPrice);
var tdTotal = document.createElement("td");
tdTotal.textContent = row.total;
tdTotal.style.padding = "10px";
tdTotal.style.textAlign = "center";
tr.appendChild(tdTotal);
// Append the row to the table body
tableBody.appendChild(tr);
});
})
.catch(error => console.error('Error fetching data:', error));
}
// Function to print only the new container
function printNewContainer() {
const newContainer = document.querySelector('.new-container');
if (!newContainer) {
console.error('New container not found.');
return;
}
// Create a new window for printing
const printWindow = window.open('', '_blank', 'width=800,height=600');
// Write the container's content into the new window
printWindow.document.open();
printWindow.document.write(`
<!DOCTYPE html>
<html lang="ar">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Print Table</title>
<style>
body {
font-family: 'Cairo', sans-serif;
direction: rtl;
text-align: center;
margin: 0;
padding: 20px;
}
table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
}
th, td {
padding: 10px;
border: 1px solid #ddd;
text-align: center;
}
th {
background-color: #f4f4f4;
}
</style>
</head>
<body>
${newContainer.outerHTML}
</body>
</html>
`);
printWindow.document.close();
// Print the content and close the window
printWindow.print();
printWindow.close();
}
// Attach the print function to the button
document.getElementById('printbutton').addEventListener('click', printNewContainer);
// function to save sale
document.getElementById("submit-button").addEventListener("click", function() {
const emailTextbox = document.getElementById("emailTextbox");
const placeholder = emailTextbox.placeholder;
if (!placeholder) {
alert("Placeholder is empty!");
return;
}
const webAppUrl = "https://script.google.com/macros/s/AKfycbwjhBVk5X_FB_1kUkAqeFKe8rVYVtC9OgzVChw6DP2IO3mtfiNsQWv_JY-scbGDCo1b/exec"; // Replace with your deployed Google Apps Script URL
// Check if the sheet exists first
fetch(`${webAppUrl}?placeholder=${encodeURIComponent(placeholder)}`)
.then(response => response.json())
.then(data => {
if (data.exists) {
// Perform the cut and paste action
fetch(`${webAppUrl}?placeholder=${encodeURIComponent(placeholder)}&action=cutPaste`)
.then(response => response.json())
.then(result => {
if (result.success) {
window.history.back();
} else {
alert("An error occurred while performing the cut and paste operation.");
}
})
.catch(error => {
console.error("Error:", error);
alert("An error occurred while performing the cut and paste operation.");
});
} else {
alert(`Sheet/tab "${placeholder}" does not exist.`);
}
})
.catch(error => {
console.error("Error:", error);
alert("An error occurred while checking the sheet/tab.");
});
});
</script>
</body>
</html>