-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArabicPurchase.html
499 lines (432 loc) · 19.9 KB
/
ArabicPurchase.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
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
<!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;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
font-family: 'Cairo', sans-serif;
background-color: #F4E1BC;
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: #E8D3A5;
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: #F4E1BC;
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: #E8D3A5;
}
.camera-preview {
width: 300px;
height: 300px;
background-color: black;
}
.barcode-textbox {
width: 300px;
height: 35px;
font-size: 18px;
padding: 5px;
text-align: right;
border: none;
outline: none;
background-color: #F4E1BC;
}
.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: #F4E1BC;
-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;
}
.another-item-button {
background-color: #90EE90; /* Light green */
color: black;
border: none;
padding: 10px 20px;
font-size: 18px;
cursor: pointer;
}
.submit-button:hover,
.another-item-button:hover {
opacity: 0.8; /* Optional: Add hover effect */
}
</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">
<video id="camera-preview" class="camera-preview" autoplay></video>
<label for="barcode-textbox" class="form-label">باركود</label>
<input type="text" id="barcode-textbox" class="barcode-textbox" placeholder="" readonly>
<!-- Dropdown menu with custom style -->
<label for="category-dropdown" class="form-label">الفئة</label>
<select id="category-dropdown" class="custom-dropdown">
<option value="" disabled selected></option>
<!-- Options will be populated by JavaScript -->
</select>
<label for="category-dropdown" class="form-label">اسم الصنف</label>
<input type="text" id="item-name-textbox" class="barcode-textbox" list="item-suggestion-list">
<datalist id="item-suggestion-list"></datalist>
<label for="category-dropdown" class="form-label">وحدة القياس</label>
<select id="measurement-unit-dropdown" class="custom-dropdown">
<option value="" disabled selected></option>
<option value="وحدة">وحدة</option>
<option value="كيلو">كيلو</option>
<option value="متر">متر</option>
<option value="متر مربع">متر مربع</option>
<option value="كيس">كيس</option>
<option value="علبة">علبة</option>
<option value="زجاجة">زجاجة</option>
<option value="كرتونة">كرتونة</option>
<option value="شكارة">شكارة</option>
<option value="لفة">لفة</option>
<option value="دستة">دستة</option>
<option value="شنطة">شنطة</option>
<option value="قطعة">قطعة</option>
<option value="طن">طن</option>
<option value="جرام">جرام</option>
<option value="سيخ">سيخ</option>
<option value="رول">رول</option>
<option value="صندوق">صندوق</option>
<option value="عبوة">عبوة</option>
<option value="لوح">لوح</option>
<option value="برميل">برميل</option>
<option value="طرد">طرد</option>
<option value="قالب">قالب</option>
<option value="حزمة">حزمة</option>
<option value="باكو">باكو</option>
<option value="أنبوبة">أنبوبة</option>
<option value="جالون">جالون</option>
<option value="جركن">جركن</option>
<option value="شوال">شوال</option>
<option value="جردل">جردل</option>
<option value="كرتون">كرتون</option>
</select>
<label for="category-dropdown" class="form-label">الكمية</label>
<input type="number" id="quantity" class="barcode-textbox">
<label for="category-dropdown" class="form-label">سعر الشراء</label>
<input type="number" id="purchase-price-textbox" class="barcode-textbox">
<label for="category-dropdown" class="form-label">الإجمالي</label>
<input type="number" id="itemtotal" class="barcode-textbox" readonly>
<label for="category-dropdown" class="form-label">سعر البيع</label>
<input type="number" id="sell-price-textbox" class="barcode-textbox">
<!-- Buttons at the bottom -->
<div class="button-container">
<button id="submit-button" class="submit-button">حفظ الفاتورة</button>
<button id="another-item-button" class="another-item-button">صنف آخر</button>
</div>
</div>
<audio id="beep-sound" src="Media/beep.mp3"></audio> <!-- Audio element for beep sound -->
<script>
// Set the textbox value with the username from the URL and initialize events
window.onload = function () {
const username = getQueryParameter('username');
if (username) {
document.getElementById('emailTextbox')?.setAttribute('placeholder', username);
}
startCamera();
// Add event listeners for real-time calculation
const quantityField = document.getElementById('quantity');
const priceField = document.getElementById('purchase-price-textbox');
quantityField.addEventListener('input', updateTotal);
priceField.addEventListener('input', updateTotal);
// Ensure total is updated on page load
updateTotal();
populateCategoryDropdown();
};
// Update the total value based on quantity and purchase price
function updateTotal() {
const quantity = parseFloat(document.getElementById('quantity').value) || 0;
const purchasePrice = parseFloat(document.getElementById('purchase-price-textbox').value) || 0;
const itemTotal = document.getElementById('itemtotal');
itemTotal.value = (quantity * purchasePrice).toFixed(2); // Calculate and format to 2 decimal places
}
//cattttegory
async function fetchCategoryOptions(sheetName) {
const webAppUrl = 'https://script.google.com/macros/s/AKfycbw2RLYJhOfHzfEsDtU6GDloVkqnlM4_DIoSnN21iCSjjQaRvfTaCf9JZ4PwAnIE9Bpm/exec'; // Replace with your actual web app URL
const response = await fetch(`${webAppUrl}?sheetName=${encodeURIComponent(sheetName)}&range=BQ1:CY1`, {
method: 'GET',
});
if (!response.ok) {
throw new Error(`Error fetching data from Google Sheets: ${response.statusText}`);
}
const data = await response.json();
return data; // Assumed that data is an array of options from BQ1:CY1
}
async function populateCategoryDropdown() {
const sheetName = document.getElementById('emailTextbox').placeholder;
try {
// Fetch options from Google Sheets
const options = await fetchCategoryOptions(sheetName);
// Get the dropdown element
const categoryDropdown = document.getElementById('category-dropdown');
// Clear existing options
categoryDropdown.innerHTML = '';
// Add default "Select Category" option
const defaultOption = document.createElement('option');
defaultOption.textContent = '';
categoryDropdown.appendChild(defaultOption);
// Populate dropdown with fetched options
options.forEach(option => {
const optionElement = document.createElement('option');
optionElement.value = option;
optionElement.textContent = option;
categoryDropdown.appendChild(optionElement);
});
} catch (error) {
console.error("Error populating category dropdown:", error);
alert("حدث خطأ أثناء تحميل الخيارات.");
}
}
//itttttem
// Fetch items for the selected category
async function fetchItemsForCategory(sheetName, category) {
const webAppUrl = 'https://script.google.com/macros/s/AKfycbwKpj2nTFpq1wdhV-kE3YcYXPa7TUF0wPc2pVYYTPSgGxBJp_1fdCU-wNf4vqQoY0jP/exec'; // Replace with your actual web app URL
const response = await fetch(`${webAppUrl}?sheetName=${encodeURIComponent(sheetName)}&category=${encodeURIComponent(category)}`, {
method: 'GET',
});
if (!response.ok) {
throw new Error(`Error fetching items for category: ${response.statusText}`);
}
return await response.json(); // Assumed that data is an array of items for the category
}
// Trigger on category change
async function handleCategoryChange() {
const sheetName = document.getElementById('emailTextbox').placeholder;
const categoryDropdown = document.getElementById('category-dropdown');
const selectedCategory = categoryDropdown.value;
if (!selectedCategory) return; // Do nothing if no category is selected
try {
// Fetch items for the selected category
const items = await fetchItemsForCategory(sheetName, selectedCategory);
// Populate the datalist for item suggestions
const itemSuggestionList = document.getElementById('item-suggestion-list');
itemSuggestionList.innerHTML = ''; // Clear existing suggestions
items.forEach(item => {
const option = document.createElement('option');
option.value = item;
itemSuggestionList.appendChild(option);
});
} catch (error) {
console.error("Error populating items:", error);
alert("حدث خطأ أثناء تحميل العناصر.");
}
}
// Attach the event listener to the category dropdown
document.getElementById('category-dropdown').addEventListener('change', handleCategoryChange);
function getQueryParameter(name) {
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get(name);
}
async function startCamera() {
try {
const constraints = {
video: {
facingMode: 'environment',
},
};
const stream = await navigator.mediaDevices.getUserMedia(constraints);
const videoElement = document.getElementById('camera-preview');
videoElement.srcObject = stream;
startBarcodeDetection();
} catch (error) {
console.error('Error accessing the camera:', error);
}
}
function startBarcodeDetection() {
Quagga.init({
inputStream: {
type: 'LiveStream',
target: document.querySelector('#camera-preview'),
},
decoder: {
readers: ['code_128_reader', 'ean_reader', 'ean_8_reader', 'code_39_reader', 'code_39_vin_reader', 'upc_reader', 'upc_e_reader', 'i2of5_reader'],
},
}, (err) => {
if (err) {
console.error(err);
return;
}
Quagga.start();
console.log('Barcode detection started');
});
Quagga.onDetected((data) => {
const code = data.codeResult.code;
const barcodeTextbox = document.getElementById('barcode-textbox');
barcodeTextbox.value = code;
const beepSound = document.getElementById('beep-sound');
beepSound.currentTime = 0;
beepSound.play();
});
}
document.getElementById('another-item-button').addEventListener('click', async function() {
// Select necessary elements
const categoryDropdown = document.getElementById('category-dropdown');
const itemNameTextbox = document.getElementById('item-name-textbox');
const unitDropdown = document.getElementById('measurement-unit-dropdown');
const quantityTextbox = document.getElementById('quantity');
const purchasePriceTextbox = document.getElementById('purchase-price-textbox');
const sellPriceTextbox = document.getElementById('sell-price-textbox');
const barcodeTextbox = document.getElementById('barcode-textbox');
const sheetName = document.getElementById('emailTextbox').placeholder;
// If the barcode textbox is empty, set it to "NA"
if (!barcodeTextbox.value) {
barcodeTextbox.value = "NA";
}
// Check for empty fields (barcode is now ensured to have a value)
if (!categoryDropdown.value || !itemNameTextbox.value || !unitDropdown.value || !quantityTextbox.value || !purchasePriceTextbox.value || !sellPriceTextbox.value) {
alert("البيانات غير كاملة، فقط الباركود اختياري");
return;
}
// Check if the sheet exists and copy all values
const { exists, message } = await checkSheetExists(sheetName, barcodeTextbox.value || barcodeTextbox.placeholder, categoryDropdown.value, itemNameTextbox.value, unitDropdown.value, quantityTextbox.value, purchasePriceTextbox.value, sellPriceTextbox.value);
// Notify the user
alert("تم الحفظ بنجاح");
// Clear the input fields
categoryDropdown.selectedIndex = 0; // Reset category dropdown
itemNameTextbox.value = ""; // Clear item name textbox
unitDropdown.selectedIndex = 0; // Reset unit dropdown
quantityTextbox.value = ""; // Clear quantity textbox
purchasePriceTextbox.value = ""; // Clear purchase price textbox
sellPriceTextbox.value = ""; // Clear sell price textbox
barcodeTextbox.value = ""; // Clear barcode textbox (optional)
updateTotal();
});
// Function to check if a sheet exists and copy multiple values using Google Apps Script web app
async function checkSheetExists(sheetName, barcodeValue, categoryValue, itemNameValue, unitValue, quantityValue, purchasePriceValue, sellPriceValue) {
const webAppUrl = 'https://script.google.com/macros/s/AKfycby-AE0RaEjh8Qu3y_iCSTBgAHKmh8JcixGcp3C67dj3TC5vNfHLcSmXa_51Dhw1eo1s/exec'; // Replace with your actual web app URL
const response = await fetch(`${webAppUrl}?sheetName=${encodeURIComponent(sheetName)}&barcodeValue=${encodeURIComponent(barcodeValue)}&categoryValue=${encodeURIComponent(categoryValue)}&itemNameValue=${encodeURIComponent(itemNameValue)}&unitValue=${encodeURIComponent(unitValue)}&quantityValue=${encodeURIComponent(quantityValue)}&purchasePriceValue=${encodeURIComponent(purchasePriceValue)}&sellPriceValue=${encodeURIComponent(sellPriceValue)}`, {
method: 'GET',
});
if (!response.ok) {
throw new Error(`Error fetching from web app: ${response.statusText}`);
}
const data = await response.json();
return data;
}
// Event listener for the submit button
document.getElementById('submit-button').addEventListener('click', async function () {
// Select necessary elements
const categoryDropdown = document.getElementById('category-dropdown');
const itemNameTextbox = document.getElementById('item-name-textbox');
const unitDropdown = document.getElementById('measurement-unit-dropdown');
const quantityTextbox = document.getElementById('quantity');
const purchasePriceTextbox = document.getElementById('purchase-price-textbox');
const sellPriceTextbox = document.getElementById('sell-price-textbox');
const barcodeTextbox = document.getElementById('barcode-textbox');
const sheetName = document.getElementById('emailTextbox').placeholder;
// Check for empty fields (barcode is now ensured to have a value)
if (!barcodeTextbox.value || !categoryDropdown.value || !itemNameTextbox.value || !unitDropdown.value || !quantityTextbox.value || !purchasePriceTextbox.value || !sellPriceTextbox.value) {
alert("البيانات غير كاملة، يجب إدخال كل البيانات");
return;
}
try {
// Wait for the checkSheetExists function to complete
const { exists, message } = await checkSheetExists(
sheetName,
barcodeTextbox.value,
categoryDropdown.value,
itemNameTextbox.value,
unitDropdown.value,
quantityTextbox.value,
purchasePriceTextbox.value,
sellPriceTextbox.value
);
// Clear the input fields
categoryDropdown.selectedIndex = 0; // Reset category dropdown
itemNameTextbox.value = ""; // Clear item name textbox
unitDropdown.selectedIndex = 0; // Reset unit dropdown
quantityTextbox.value = ""; // Clear quantity textbox
purchasePriceTextbox.value = ""; // Clear purchase price textbox
sellPriceTextbox.value = ""; // Clear sell price textbox
barcodeTextbox.value = ""; // Clear barcode textbox (optional)
updateTotal();
// Get the username from the placeholder in the textbox
const username = document.getElementById('emailTextbox').placeholder;
// Redirect after saving
window.location.href = `ArabicPostPurchase.html?username=${encodeURIComponent(username)}`;
} catch (error) {
console.error("Error saving data:", error);
alert("حدث خطأ أثناء الحفظ. حاول مرة أخرى.");
}
});
</script>
</body>
</html>