-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
1333 lines (1106 loc) Β· 53 KB
/
app.js
File metadata and controls
1333 lines (1106 loc) Β· 53 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
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
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
const correctUsername = "Cashier";const correctPassword = "Cashier1234";
const adminUsername = "Admin";
const adminPassword = "Admin1234";
let FinalPrice;
let DiscountPrs;
let newusername="";
let newpassword="";
let SearchCashierBox=document.getElementById("SearchCashierBox");
let toastBoxSearch=document.getElementById("toastBoxSearch");
let toastBox=document.getElementById("toastBox");
let toastBoxOrder=document.getElementById("toastBoxOrder");
let successMsg= '<img src="img/righticon.png" > Cashier Added Successfully';
let cart='<img src="img/righticon.png" > Add To Cart Successfully';
let noItem='<img src="img/xmark.png" >Check the Phone Number ';
let CashierNo='<img src="img/xmark.png" >Cashier Not Found ';
let already='<img src="img/xmark.png" >Cashier Already Exisits ';
function showToast(msg) {
let toastBox=document.getElementById("toastBox");
let toastBoxOrder=document.getElementById("toastBoxOrder");
let toastBoxSearch=document.getElementById("toastBoxSearch");
let SearchCashierBox=document.getElementById("SearchCashierBox");
let toast= document.createElement('div');
toast.classList.add('toast');
toast.innerHTML=msg;
if(toastBoxSearch && msg.includes('Check')){
toast.classList.add('Check');
toastBoxSearch.appendChild(toast);
}else if(SearchCashierBox && msg.includes('Cashier')){
toast.classList.add('Cashier')
SearchCashierBox.appendChild(toast);
}
else if(toastBox && msg.includes('Cashier')){
toast.classList.add('Cashier')
toastBox.appendChild(toast);
}
else if (toastBox ) {
toastBox.appendChild(toast);
} else if (toastBoxOrder) {
toastBoxOrder.appendChild(toast);
} else {
console.error('Neither toastBox nor toastBoxOrder elements found!');
}
setTimeout(()=>{
toast.remove();
},6000)
}
function addCashier(){
console.log("Button clicked");
newusername=document.getElementById("CashierNameTxt").value.trim();
newpassword=document.getElementById("CashierPasswordTxt").value.trim();
if (newusername === "" || newpassword === "") {
console.log("Username or password cannot be empty.");
return;
}
// Retrieve existing cashiers or initialize with an empty array
let cashiers = JSON.parse(localStorage.getItem('cashiers')) || [];
// Check if username already exists
const existingCashier = cashiers.find(cashier => cashier.username === newusername);
if (existingCashier) {
showToast(already)
console.log("Cashier username already exists.");
return;
}
// Add new cashier to the list
cashiers.push({ username: newusername, password: newpassword });
// Save updated array back to localStorage
localStorage.setItem('cashiers', JSON.stringify(cashiers));
console.log("Cashier Added Successfully");
console.log("Username:", newusername);
console.log("Password:", newpassword);
showToast(successMsg);
}
// Function to store data and handle login
function storeData(event) {
event.preventDefault();
console.log("Button clicked"); // Debugging line
let username = document.getElementById("Username").value;
let password = document.getElementById("Password").value;
const cashiers = JSON.parse(localStorage.getItem('cashiers')) || [];
const isCashier = cashiers.some(cashier => cashier.username === username && cashier.password === password);
if (username === correctUsername && password === correctPassword) {
localStorage.setItem('username', username);
localStorage.setItem('password', password);
window.location.href = "page2.html";
}
else if (isCashier) {
console.log("Cashier credentials match.");
window.location.href = "page2.html";
}
else if (username === adminUsername && password === adminPassword) {
localStorage.setItem('username', username);
localStorage.setItem('password', password);
window.location.href = "Admin.html";
}
else {
let errorMessage = document.getElementById('error-message');
errorMessage.style.display = "block";
}
}
function getCredentials() {
var storedUsername = localStorage.getItem('username');
var storedPassword = localStorage.getItem('password');
console.log('Username:', storedUsername);
console.log('Password:', storedPassword);
}
getCredentials();
function searchCashier(){
let searchValue = document.getElementById("SearchCashierTxt").value.trim().toLowerCase();
let cashiers = JSON.parse(localStorage.getItem('cashiers')) || [];
let name="";
let password="";
console.log("Stored Cashiers:", cashiers);
console.log("Search Value:", searchValue);
let foundCashier = cashiers.find(cashier => {
let storedUsername = cashier.username.trim().toLowerCase();
console.log(`Comparing stored username: "${storedUsername}" with search value: "${searchValue}"`);
name=cashier.username;
password=cashier.password;
return storedUsername === searchValue;
});
if (foundCashier) {
console.log("Cashier found:", foundCashier);
document.getElementById("CashierNameSearchTxt").value=name;
document.getElementById("CashierPasswordSearchTxt").value=password;
}else{
showToast(CashierNo);
console.log("Cashier not found");
}
}
function updateCashier(){
const oldName = document.getElementById("SearchCashierTxt").value.trim();
const newName = document.getElementById("CashierNameSearchTxt").value.trim(); // Assuming you have a separate input for new name
const newPassword = document.getElementById("CashierPasswordSearchTxt").value.trim();
const cashiers = JSON.parse(localStorage.getItem('cashiers')) || [];
const Index = cashiers.findIndex(cashier => cashier.username.trim().toLowerCase() === oldName.toLowerCase());
if (Index !== -1) {
if (newName !== "" && newPassword !== "") {
cashiers[Index].username = newName;
cashiers[Index].password = newPassword;
localStorage.setItem('cashiers', JSON.stringify(cashiers));
showAlert("Cashier details updated successfully!");
console.log("Cashier updated:", cashiers[itemIndex]);
} else {
showAlert("New username and password cannot be empty.");
alert("New username and password cannot be empty.");
}
} else {
alert("Cashier not found.");
}
}
function deleteCashier() {
const oldName = document.getElementById("SearchCashierTxt").value.trim();
const cashiers = JSON.parse(localStorage.getItem('cashiers')) || [];
const Index = cashiers.findIndex(cashier => cashier.username.trim().toLowerCase() === oldName.toLowerCase());
if (Index !== -1) {
cashiers.splice(Index, 1);
localStorage.setItem('cashiers', JSON.stringify(cashiers));
showAlert("Cashier deleted successfully.");
console.log("Cashier deleted:", oldName);
} else {
alert("Cashier not Deleted.");
}
}
let OIDCounter = parseInt(localStorage.getItem('OIDCounter')) || 1000;
function Calc() {
showToast(cart);
let OIDCounter = parseInt(localStorage.getItem('OIDCounter')) || 1000;
let Tot;
localStorage.setItem('OIDCounter', OIDCounter);
let Qty = parseFloat(document.getElementById("QTYText").value);
let ItemCode = document.getElementById("ItemCodeText").value;
if (DiscountPrs && DiscountPrs > 0 && Qty) {
let dis = (FinalPrice * Qty * DiscountPrs) / 100;
Tot = (FinalPrice * Qty) - dis;
} else if (DiscountPrs === 0 && Qty) {
Tot = FinalPrice * Qty;
} else {
console.log("Invalid input or discount");
return;
}
document.getElementById("TotalFeild").value = Tot.toFixed(2);
console.log(Tot);
let Customername = document.getElementById("name").value;
localStorage.setItem('Customername', Customername);
let TelephoneNum = document.getElementById("TeleNum").value;
localStorage.setItem('TelephoneNum', TelephoneNum);
let Itemcode=document.getElementById("ItemCodeText").value;
localStorage.setItem('Itemcode',Itemcode);
let price=document.getElementById("PriceText").value;
localStorage.setItem(' price', price);
let dis=document.getElementById("DiscountText").value;
localStorage.setItem(' dis', dis);
localStorage.setItem('Tot', Tot.toFixed(2));
let orders = JSON.parse(localStorage.getItem('orders')) || [];
orders.push({
orderID: OIDCounter,
orderQty: Qty,
total: Tot.toFixed(2),
telephone: TelephoneNum,
customerName: Customername,
priceF:price,
disP:dis,
itemcode:Itemcode,
date: new Date().toLocaleDateString()
});
localStorage.setItem('orders', JSON.stringify(orders));
updateItemQuantity(ItemCode, Qty);
localStorage.setItem('OIDCounter', OIDCounter);
document.getElementById("name").value = Customername;
document.getElementById("TeleNum").value = TelephoneNum;
localStorage.setItem('customerInfo', JSON.stringify({
customerName: Customername,
telephone: TelephoneNum
}));
// generatePDF() ;
}
function updateItemQuantity(itemCode, qtyOrdered) {
// Fetch existing data from local storage
let burgerData = JSON.parse(localStorage.getItem('burgerData')) || [];
let submarineData = JSON.parse(localStorage.getItem('SubmarineData')) || [];
let friesData = JSON.parse(localStorage.getItem('FriesData')) || [];
let pastaData=JSON.parse(localStorage.getItem('PastaData')) || [];
let ChickenData=JSON.parse(localStorage.getItem('ChickenData')) || [];
let BeveargesData=JSON.parse(localStorage.getItem('Beverages')) || [];
// Function to update quantity
function updateData(data) {
let item = data.find(item => item.itemCode === itemCode);
if (item) {
if (item.Qty >= qtyOrdered) {
item.Qty -= qtyOrdered;
console.log(`Updated quantity for ${item.itemName}: ${item.Qty}`);
} else {
console.log(`Not enough stock for ${item.itemName}. Available: ${item.Qty}`);
}
}
}
// Update the data arrays
updateData(burgerData);
updateData(submarineData);
updateData(friesData);
updateData(pastaData);
updateData(ChickenData);
updateData(BeveargesData);
// Save updated data back to local storage
localStorage.setItem('burgerData', JSON.stringify(burgerData));
localStorage.setItem('SubmarineData', JSON.stringify(submarineData));
localStorage.setItem('FriesData', JSON.stringify(friesData));
localStorage.setItem('PastaData', JSON.stringify(pastaData));
localStorage.setItem('ChickenData', JSON.stringify(ChickenData));
localStorage.setItem('Beverages', JSON.stringify(BeveargesData));
}
function getDetailsCustomer() {
let searchValue = document.getElementById("SearchFeild").value;
let orders = JSON.parse(localStorage.getItem('orders')) || [];
let customerOrders = orders.filter(order => order.telephone === searchValue);
if (customerOrders.length > 0) {
document.getElementById("NameSearchField").value = customerOrders[0].customerName;
displayOrderDetails(searchValue);
// displayOrderResults(customerOrders);
} else {
showToast(noItem);
console.log("No customer found with the given telephone number");
}
}
function displayOrderDetails(telephone) {
let orders = JSON.parse(localStorage.getItem('orders')) || [];
let customerOrders = orders.filter(order => order.telephone === telephone);
let table = document.getElementById("CustomerDetails");
let SubTotal=0;
// Clear previous rows
table.querySelectorAll('tr:not(:first-child)').forEach(row => row.remove());
// Populate table with customer orders
customerOrders.forEach(order => {
let row = table.insertRow();
row.insertCell(0).textContent = order.orderID;
row.insertCell(1).textContent = order.orderQty;
row.insertCell(2).textContent = order.total;
row.insertCell(3).textContent = order.date;
SubTotal += parseFloat(order.total) || 0;
});
document.getElementById("SubTotTxt").value = SubTotal.toFixed(2);
let CustomerName=customerOrders[0].customerName;
let BestCustArray = JSON.parse(localStorage.getItem('BestCustArray')) || [];
let bestCustomer = {
name: CustomerName,
subTotal: SubTotal.toFixed(2),
telephone:telephone
};
BestCustArray.push(bestCustomer);
localStorage.setItem('BestCustArray', JSON.stringify(BestCustArray));
}
function itemview(orderID) {
// Implement the view more functionality
console.log(`View more details for order ID: ${orderID}`);
}
function resetOIDCounter() {
OIDCounter = 1000; // Reset to initial value
localStorage.setItem('OIDCounter', OIDCounter);
document.getElementById("OIDText").value = OIDCounter; // Update the OID field if necessary
console.log("OIDCounter reset to", OIDCounter);
}
// Define the array with the given data
const initialBurgerData = [
{ itemCode: "B1001", itemName: "Classic Burger (Large)", price: "750.00", discount: 0,Qty:50 },
{ itemCode: "B1002", itemName: "Classic Burger (Regular)", price: "1500.00", discount: "15%" ,Qty:50},
{ itemCode: "B1003", itemName: "Turkey Burger", price: "1600.00", discount: 0 ,Qty:50},
{ itemCode: "B1004", itemName: "Chicken Burger (Large)", price: "1400.00", discount: 0,Qty:50 },
{ itemCode: "B1005", itemName: "Chicken Burger (Regular)", price: "800.00", discount: "20%",Qty:50 },
{ itemCode: "B1006", itemName: "Cheese Burger (Large)", price: "1000.00", discount: 0,Qty:50 },
{ itemCode: "B1007", itemName: "Cheese Burger (Regular)", price: "600.00", discount:0 ,Qty:50},
{ itemCode: "B1008", itemName: "Bacon Burger", price: "650.00", discount: "15%",Qty:50 },
{ itemCode: "B1009", itemName: "Shawarma Burger", price: "800.00", discount: 0,Qty:50 },
{ itemCode: "B1010", itemName: "Olive Burger", price: "1800.00", discount: 0,Qty:50 },
{ itemCode: "B1012", itemName: "Double-Cheese Burger", price: "1250.00", discount: "20%",Qty:50 },
{ itemCode: "B1013", itemName: "Crispy Chicken Burger (Regular)", price: "1200.00", discount: 0,Qty:50 },
{ itemCode: "B1014", itemName: "Crispy Chicken Burger (Large)", price: "1600.00", discount: 10,Qty:50 },
{ itemCode: "B1015", itemName: "Paneer Burger ", price: "900.00", discount: 0,Qty:50 }
];
const initialSubmarineData = [
{ itemCode: "B1016", itemName: "Crispy Chicken Submarine (Large)", price: "2000.00", discount: 0,Qty:50 },
{ itemCode: "B1017", itemName: "Crispy Chicken Submarine (Regular)", price: "1500.00", discount: 0,Qty:50 },
{ itemCode: "B1018", itemName: "Chicken Submarine (Large)", price: "1800.00", discount: "3%",Qty:50 },
{ itemCode: "B1019", itemName: "Chicken Submarine (Regular)", price: "1400.00", discount: 0,Qty:50 },
{ itemCode: "B1020", itemName: "Grinder Submarine", price: "2300.00", discount: 0,Qty:50 },
{ itemCode: "B1021", itemName: "Cheese Submarine", price: "2200.00", discount: 0,Qty:50 },
{ itemCode: "B1022", itemName: "Double Cheese n Chicken Submarine", price: "1900.00", discount:"16%",Qty:50 },
{ itemCode: "B1023", itemName: "Special Horgie Submarine", price: "2800.00", discount: 0 ,Qty:50 },
{ itemCode: "B1024", itemName: "MOS Special Submarine", price: "3000.00", discount: 0,Qty:50 },
];
const initialFriesData = [
{ itemCode: "B1025", itemName: "Steak Fries (Large)", price: "1200.00", discount: 0 ,Qty:50 },
{ itemCode: "B1026", itemName: "Steak Fries (Medium)", price: "600.00", discount: 0 ,Qty:50 },
{ itemCode: "B1027", itemName: "French Fries (Large)", price: "800.00", discount: 0,Qty:50 },
{ itemCode: "B1028", itemName: "French Fries (Medium)", price: "650.00", discount: 0 ,Qty:50 },
{ itemCode: "B1029", itemName: "French Fries (Small)", price: "450.00", discount: 0 ,Qty:50 },
{ itemCode: "B1030", itemName: "Sweet Potato Fries (Large)", price: "600.00", discount: 0,Qty:50 }
];
const initialPastaData = [
{ itemCode: "B1031", itemName: "Chicken n Cheese Pasta", price: "1600.00", discount:"15%",Qty:50 },
{ itemCode: "B1032", itemName: "Chicken Penne Pasta", price: "1700.00", discount: 0 ,Qty:50 },
{ itemCode: "B1033", itemName: "Ground Turkey Pasta Bake", price: "2900.00", discount:"10%" ,Qty:50 },
{ itemCode: "B1034", itemName: "Creamy Shrimp Pasta", price: "2000.00", discount: 0 ,Qty:50 },
{ itemCode: "B1035", itemName: "Lemon Butter Pasta", price: "1950.00", discount: 0 ,Qty:50 },
{ itemCode: "B1036", itemName: "Tagliatelle Pasta", price: "2400.00", discount:"1%",Qty:50 },
{ itemCode: "B1037", itemName: "Baked Ravioli", price: "2000.00", discount: "1%",Qty:50 },
];
const initialChickenData = [
{ itemCode: "B1038", itemName: "Fried Chicken (Small)", price: "1200.00", discount:0,Qty:50 },
{ itemCode: "B1039", itemName: "Fried Chicken (Regular)", price: "2300.00", discount:"10%" ,Qty:50 },
{ itemCode: "B1040", itemName: "Fried Chicken (Large)", price: "3100.00", discount:"5%" ,Qty:50 },
{ itemCode: "B1041", itemName: "Hot Wings (Large)", price: "2400.00", discount: 0 ,Qty:50 },
{ itemCode: "B1042", itemName: "Devilled Chicken (Large)", price: "900.00", discount: 0 ,Qty:50 },
{ itemCode: "B1043", itemName: "BBQ Chicken (Regular)", price: "2100.00", discount:0,Qty:50 },
];
const initialBeverages = [
{ itemCode: "B1044", itemName: "Pepsi (330ml)", price: "990.00", discount:"5%",Qty:50 },
{ itemCode: "B1045", itemName: "Coca-Cola (330ml)", price: "1230.00", discount:0 ,Qty:50 },
{ itemCode: "B1046", itemName: "Sprite (330ml)", price: "1500.00", discount:"3%" ,Qty:50 },
{ itemCode: "B1047", itemName: "Mirinda (330ml)", price: "850.00", discount:"7%",Qty:50 }
];
if (!localStorage.getItem('Beverages')) {
localStorage.setItem('Beverages', JSON.stringify(initialBeverages));
}
if (!localStorage.getItem('ChickenData')) {
localStorage.setItem('ChickenData', JSON.stringify(initialChickenData));
}
if (!localStorage.getItem('PastaData')) {
localStorage.setItem('PastaData', JSON.stringify(initialPastaData));
}
if (!localStorage.getItem('FriesData')) {
localStorage.setItem('FriesData', JSON.stringify(initialFriesData));
}
if (!localStorage.getItem('SubmarineData')) {
localStorage.setItem('SubmarineData', JSON.stringify(initialSubmarineData));
}
// Store initial data in localStorage if not already present
if (!localStorage.getItem('burgerData')) {
localStorage.setItem('burgerData', JSON.stringify(initialBurgerData));
}
function displayBeveragesData(){
const beveragesData = JSON.parse(localStorage.getItem('Beverages')) || [];
const beveragesTableBody = document.getElementById("BeveragesTableBody");
beveragesTableBody.innerHTML = "";
beveragesData.forEach(( beverage, index) => {
const row = beveragesTableBody.insertRow();
row.insertCell(0).textContent = beverage.itemCode;
row.insertCell(1).textContent = beverage.itemName;
row.insertCell(2).textContent = beverage.price;
row.insertCell(3).textContent = beverage.Qty;
if( beverage.discount==0){
row.insertCell(4).textContent = '-';
}else{
row.insertCell(4).textContent = beverage.discount;
}
const editCell = row.insertCell(5);
editCell.innerHTML = `<button class="edit-button" onclick="editBeverage(${index})">Edit</button>`;
const buyCell = row.insertCell(6);
buyCell.innerHTML = `<button class="buy-button" onclick="buyItem('${beverage.itemCode}', '${beverage.price}', '${beverage.discount}')">Buy Now</button>`;
const deleteCell = row.insertCell(7);
deleteCell.innerHTML = `<button class="delete-button" onclick="deleteBeverage(${index})">Delete</button>`;
});
}
if(document.getElementById("BeveragesTableBody") !=null){displayBeveragesData();}
function displayChickenData(){
const chickenData = JSON.parse(localStorage.getItem('ChickenData')) || [];
const chickenTableBody = document.getElementById("ChickenTableBody");
chickenTableBody.innerHTML = "";
chickenData.forEach((chicken, index) => {
const row = chickenTableBody.insertRow();
row.insertCell(0).textContent =chicken.itemCode;
row.insertCell(1).textContent =chicken.itemName;
row.insertCell(2).textContent =chicken.price;
row.insertCell(3).textContent =chicken.Qty;
if(chicken.discount==0){
row.insertCell(4).textContent = '-';
}else{
row.insertCell(4).textContent = chicken.discount;
}
const editCell = row.insertCell(5);
editCell.innerHTML = `<button class="edit-button" onclick="editChicken(${index})">Edit</button>`;
const buyCell = row.insertCell(6);
buyCell.innerHTML = `<button class="buy-button" onclick="buyItem('${chicken.itemCode}', '${chicken.price}', '${chicken.discount}')">Buy Now</button>`;
const deleteCell = row.insertCell(7);
deleteCell.innerHTML = `<button class="delete-button" onclick=" deleteChicken(${index})">Delete</button>`;
});
}
if(document.getElementById("ChickenTableBody") !=null){displayChickenData();}
function displayPastaData(){
const pastaData = JSON.parse(localStorage.getItem('PastaData')) || [];
const pastaTableBody = document.getElementById("PastaTableBody");
pastaTableBody.innerHTML = "";
pastaData.forEach((pasta, index) => {
const row = pastaTableBody.insertRow();
row.insertCell(0).textContent =pasta.itemCode;
row.insertCell(1).textContent =pasta.itemName;
row.insertCell(2).textContent =pasta.price;
row.insertCell(3).textContent =pasta.Qty;
if(pasta.discount==0){
row.insertCell(4).textContent = '-';
}else{
row.insertCell(4).textContent = pasta.discount;
}
const editCell = row.insertCell(5);
editCell.innerHTML = `<button class="edit-button" onclick="editPasta(${index})">Edit</button>`;
const buyCell = row.insertCell(6);
buyCell.innerHTML = `<button class="buy-button" onclick="buyItem('${pasta.itemCode}', '${pasta.price}', '${pasta.discount}')">Buy Now</button>`;
const deleteCell = row.insertCell(7);
deleteCell.innerHTML = `<button class="delete-button" onclick=" deletePasta(${index})">Delete</button>`;
});
}
if(document.getElementById("PastaTableBody") !=null){displayPastaData();}
function displayFriesData(){
const friesData = JSON.parse(localStorage.getItem('FriesData')) || [];
const friesTableBody = document.getElementById("FriesTableBody");
friesTableBody.innerHTML = "";
friesData.forEach((fry, index) => {
const row = friesTableBody.insertRow();
row.insertCell(0).textContent = fry.itemCode;
row.insertCell(1).textContent = fry.itemName;
row.insertCell(2).textContent = fry.price;
row.insertCell(3).textContent = fry.Qty;
if(fry.discount==0){
row.insertCell(4).textContent = '-';
}else{
row.insertCell(4).textContent = fry.discount;
}
const editCell = row.insertCell(5);
editCell.innerHTML = `<button class="edit-button" onclick="editFry(${index})">Edit</button>`;
const buyCell = row.insertCell(6);
buyCell.innerHTML = `<button class="buy-button" onclick="buyItem('${fry.itemCode}', '${fry.price}', '${fry.discount}')">Buy Now</button>`;
const deleteCell = row.insertCell(7);
deleteCell.innerHTML = `<button class="delete-button" onclick=" deleteFry(${index})">Delete</button>`;
});
}
if(document.getElementById("FriesTableBody") !=null){displayFriesData();}
function displaySubmarineData(){
const submarineData = JSON.parse(localStorage.getItem('SubmarineData')) || [];
const submarineTableBody = document.getElementById("SubmarineTableBody");
submarineTableBody.innerHTML = "";
submarineData.forEach((submarine, index) => {
const row = submarineTableBody.insertRow();
row.insertCell(0).textContent = submarine.itemCode;
row.insertCell(1).textContent = submarine.itemName;
row.insertCell(2).textContent = submarine.price;
row.insertCell(3).textContent = submarine.Qty;
if(submarine.discount==0){
row.insertCell(4).textContent = '-';
}else{
row.insertCell(4).textContent = submarine.discount;
}
const editCell = row.insertCell(5);
editCell.innerHTML = `<button class="edit-button" onclick="editSubmarine(${index})">Edit</button>`;
const buyCell = row.insertCell(6);
buyCell.innerHTML = `<button class="buy-button" onclick="buyItem('${submarine.itemCode}', '${submarine.price}', '${submarine.discount}')">BuyNow</button>`;
const deleteCell = row.insertCell(7);
deleteCell.innerHTML = `<button class="delete-button" onclick=" deleteSubmarine(${index})">Delete</button>`;
});
}
if(document.getElementById("SubmarineTableBody") !=null){displaySubmarineData();}
function editBeverage(index) {
const beverageData = JSON.parse(localStorage.getItem('Beverages')) || [];
const item = beverageData [index];
// Redirect to the update page with the item data
window.location.href = `Update.html?itemCode=${encodeURIComponent(item.itemCode)}&price=${encodeURIComponent(item.price)}&discount=${encodeURIComponent(item.discount)}`;
}
function editChicken(index) {
const chickenData = JSON.parse(localStorage.getItem('ChickenData')) || [];
const item = chickenData [index];
// Redirect to the update page with the item data
window.location.href = `Update.html?itemCode=${encodeURIComponent(item.itemCode)}&price=${encodeURIComponent(item.price)}&discount=${encodeURIComponent(item.discount)}`;
}
function editPasta(index) {
const pastaData = JSON.parse(localStorage.getItem('PastaData')) || [];
const item = pastaData [index];
// Redirect to the update page with the item data
window.location.href = `Update.html?itemCode=${encodeURIComponent(item.itemCode)}&price=${encodeURIComponent(item.price)}&discount=${encodeURIComponent(item.discount)}`;
}
function editFry(index) {
const friesData = JSON.parse(localStorage.getItem('FriesData')) || [];
const item = friesData[index];
// Redirect to the update page with the item data
window.location.href = `Update.html?itemCode=${encodeURIComponent(item.itemCode)}&price=${encodeURIComponent(item.price)}&discount=${encodeURIComponent(item.discount)}`;
}
function editSubmarine(index) {
const submarineData = JSON.parse(localStorage.getItem('SubmarineData')) || [];
const item = submarineData[index];
// Redirect to the update page with the item data
window.location.href = `Update.html?itemCode=${encodeURIComponent(item.itemCode)}&price=${encodeURIComponent(item.price)}&discount=${encodeURIComponent(item.discount)}`;
}
function deleteBeverage(index) {
const BeverageData= JSON.parse(localStorage.getItem('Beverages')) || [];
if (index > -1 && index < BeverageData.length) {
BeverageData.splice(index, 1); // Remove the item at the specified index
localStorage.setItem('Beverages', JSON.stringify(BeverageData));
displayBeveragesData();// Refresh the table to reflect the changes
alert("Item deleted successfully.");
} else {
alert("Invalid item index.");
}
}
function deleteChicken(index) {
const chickenData= JSON.parse(localStorage.getItem('ChickenData')) || [];
if (index > -1 && index < chickenData.length) {
chickenData.splice(index, 1); // Remove the item at the specified index
localStorage.setItem('ChickenData', JSON.stringify(pastaData));
displayChickenData(); // Refresh the table to reflect the changes
alert("Item deleted successfully.");
} else {
alert("Invalid item index.");
}
}
function deleteSubmarine(index) {
const submarineData = JSON.parse(localStorage.getItem('SubmarineData')) || [];
if (index > -1 && index < submarineData.length) {
submarineData.splice(index, 1); // Remove the item at the specified index
localStorage.setItem('SubmarineData', JSON.stringify(submarineData));
displaySubmarineData(); // Refresh the table to reflect the changes
alert("Item deleted successfully.");
} else {
alert("Invalid item index.");
}
}
function deleteChicken(index) {
const chickenData= JSON.parse(localStorage.getItem('ChickenData')) || [];
if (index > -1 && index < chickenData.length) {
chickenData.splice(index, 1); // Remove the item at the specified index
localStorage.setItem('ChickenData', JSON.stringify(chickenData));
displayChickenData(); // Refresh the table to reflect the changes
alert("Item deleted successfully.");
} else {
alert("Invalid item index.");
}
}
function deleteFry(index) {
const friesData= JSON.parse(localStorage.getItem('FriesData')) || [];
if (index > -1 && index < friesData.length) {
friesData.splice(index, 1); // Remove the item at the specified index
localStorage.setItem('FriesData', JSON.stringify(friesData));
displayFriesData(); // Refresh the table to reflect the changes
alert("Item deleted successfully.");
} else {
alert("Invalid item index.");
}
}
function deletePasta(index) {
const pastaData= JSON.parse(localStorage.getItem('PastaData')) || [];
if (index > -1 && index < pastaData.length) {
pastaData.splice(index, 1); // Remove the item at the specified index
localStorage.setItem('PastaData', JSON.stringify(pastaData));
displayPastaData(); // Refresh the table to reflect the changes
alert("Item deleted successfully.");
} else {
alert("Invalid item index.");
}
}
// Function to display data in a table
function displayBurgerData() {
const burgerData = JSON.parse(localStorage.getItem('burgerData')) || [];
const tableBody = document.getElementById("burgerTableBody");
tableBody.innerHTML = "";
burgerData.forEach((burger, index) => {
const row = tableBody.insertRow();
row.insertCell(0).textContent = burger.itemCode;
row.insertCell(1).textContent = burger.itemName;
row.insertCell(2).textContent = burger.price;
row.insertCell(3).textContent = burger.Qty;
if(burger.discount==0){
row.insertCell(4).textContent = '-';
}else{
row.insertCell(4).textContent = burger.discount;
}
const editCell = row.insertCell(5);
editCell.innerHTML = `<button class="edit-button" onclick="editItem(${index})">Edit</button>`;
const buyCell = row.insertCell(6);
buyCell.innerHTML = `<button class="buy-button" onclick="buyItem('${burger.itemCode}', '${burger.price}', '${burger.discount}')">Buy Now</button>`;
const deleteCell = row.insertCell(7);
deleteCell.innerHTML = `<button class="delete-button" onclick="deleteItem(${index})">Delete</button>`;
});
}
// document.addEventListener('DOMContentLoaded', function() {
// displayBurgerData();
// });
if(document.getElementById("burgerTableBody") !=null){displayBurgerData();}
// Function to update an item
function updateItem() {
const itemCode = document.getElementById("updateItemCode").value;
const newPrice = document.getElementById("updatePrice").value;
const newDiscount = document.getElementById("updateDiscount").value;
const burgerData = JSON.parse(localStorage.getItem('burgerData')) || [];
const itemIndex = burgerData.findIndex(burger => burger.itemCode === itemCode);
const submarineData=JSON.parse(localStorage.getItem('SubmarineData')) || [];
const SubIndex = submarineData.findIndex(submarine => submarine.itemCode === itemCode);
const friesDta =JSON.parse(localStorage.getItem('FriesData')) || [];
const FryIndex= friesDta.findIndex(fry => fry.itemCode === itemCode);
const pastaData =JSON.parse(localStorage.getItem('PastaData')) || [];
const PastaIndex= pastaData.findIndex(pasta => pasta.itemCode === itemCode);
const chickenData =JSON.parse(localStorage.getItem('ChickenData')) || [];
const ChickenIndex= chickenData.findIndex(chicken => chicken.itemCode === itemCode);
const BeverageData =JSON.parse(localStorage.getItem('Beverages')) || [];
const BeverageIndex= BeverageData.findIndex(Beverage => Beverage.itemCode === itemCode);
if (itemIndex !== -1) {
burgerData[itemIndex].price = newPrice;
burgerData[itemIndex].discount = newDiscount || "-";
localStorage.setItem('burgerData', JSON.stringify(burgerData));
//displayBurgerData();
alert("Wade goda");
// document.getElementById("message").innerHTML=(" Contagulations You Won π")
console.log("Hii");
} else if (SubIndex !== -1) {
submarineData[SubIndex].price = newPrice;
submarineData[SubIndex].discount = newDiscount || "-";
localStorage.setItem('SubmarineData', JSON.stringify(submarineData));
//displayBurgerData();
alert("Wade hri");
// document.getElementById("message").innerHTML=(" Contagulations You Won π")
console.log("Hii");
}else if (FryIndex !== -1) {
friesDta[FryIndex].price = newPrice;
friesDta[FryIndex].discount = newDiscount || "-";
localStorage.setItem('FriesData', JSON.stringify(friesDta));
//displayBurgerData();
alert("Wade hri");
// document.getElementById("message").innerHTML=(" Contagulations You Won π")
console.log("Hii");
} else if (PastaIndex !== -1) {
pastaData[PastaIndex].price = newPrice;
pastaData[PastaIndex].discount = newDiscount || "-";
localStorage.setItem('PastaData', JSON.stringify(pastaData));
//displayBurgerData();
alert("Wade hri");
// document.getElementById("message").innerHTML=(" Contagulations You Won π")
console.log("Hii");
} else if (ChickenIndex !== -1) {
chickenData[ChickenIndex].price = newPrice;
chickenData[ChickenIndex].discount = newDiscount || "-";
localStorage.setItem('ChickenData', JSON.stringify(chickenData));
//displayBurgerData();
alert("Wade hri");
// document.getElementById("message").innerHTML=(" Contagulations You Won π")
console.log("Hii");
} else if (BeverageIndex !== -1) {
BeverageData[BeverageIndex].price = newPrice;
BeverageData[BeverageIndex].discount = newDiscount || "-";
localStorage.setItem('Beverages', JSON.stringify(BeverageData));
//displayBurgerData();
alert("Wade hri");
// document.getElementById("message").innerHTML=(" Contagulations You Won π")
console.log("Hii");
}else {
alert("Item not found");
}
}
// Function to add a new item
function addBeverage(){
const itemCode = document.getElementById("addItemCodeBeverage").value;
const itemName = document.getElementById("addItemNameBeverage").value;
const price = document.getElementById("addPriceBeverage").value;
const discount = document.getElementById("addDiscountBeverage").value;
const BeverageData= JSON.parse(localStorage.getItem('Beverages')) || [];
const newItem = { itemCode, itemName, price, discount: discount || "-" };
BeverageData.push(newItem);
localStorage.setItem('Beverages', JSON.stringify(BeverageData));
displayBeveragesData();
}
function addChicken(){
const itemCode = document.getElementById("addItemCodeChicken").value;
const itemName = document.getElementById("addItemNameChicken").value;
const price = document.getElementById("addPriceChicken").value;
const discount = document.getElementById("addDiscountChicken").value;
const chickenData= JSON.parse(localStorage.getItem('ChickenData')) || [];
const newItem = { itemCode, itemName, price, discount: discount || "-" };
chickenData.push(newItem);
localStorage.setItem('ChickenData', JSON.stringify(chickenData));
displayChickenData();
}
function addItem() {
const itemCode = document.getElementById("addItemCode").value;
const itemName = document.getElementById("addItemName").value;
const price = document.getElementById("addPrice").value;
const discount = document.getElementById("addDiscount").value;
const burgerData = JSON.parse(localStorage.getItem('burgerData')) || [];
const newItem = { itemCode, itemName, price, discount: discount || "-" };
burgerData.push(newItem);
localStorage.setItem('burgerData', JSON.stringify(burgerData));
displayBurgerData();
}
function addSubmarine(){
const itemCode = document.getElementById("addItemCodeSub").value;
const itemName = document.getElementById("addItemNameSub").value;
const price = document.getElementById("addPriceSub").value;
const discount = document.getElementById("addDiscountSub").value;
const submarineData = JSON.parse(localStorage.getItem('SubmarineData')) || [];
const newItem = { itemCode, itemName, price, discount: discount || "-" };
submarineData.push(newItem);
localStorage.setItem('SubmarineData', JSON.stringify(submarineData));
displaySubmarineData();
}
function addFries(){
const itemCode = document.getElementById("addItemCodeFry").value;
const itemName = document.getElementById("addItemNameFry").value;
const price = document.getElementById("addPriceFry").value;
const discount = document.getElementById("addDiscountFry").value;
const friesData= JSON.parse(localStorage.getItem('FriesData')) || [];
const newItem = { itemCode, itemName, price, discount: discount || "-" };
friesData.push(newItem);
localStorage.setItem('FriesData', JSON.stringify(friesData));
displayFriesData();
}
function addPasta(){
const itemCode = document.getElementById("addItemCodePasta").value;
const itemName = document.getElementById("addItemNamePasta").value;
const price = document.getElementById("addPricePasta").value;
const discount = document.getElementById("addDiscountPasta").value;
const pastaData= JSON.parse(localStorage.getItem('PastaData')) || [];
const newItem = { itemCode, itemName, price, discount: discount || "-" };
pastaData.push(newItem);
localStorage.setItem('PastaData', JSON.stringify(pastaData));
displayPastaData();
}
// Function to populate update form with existing item data for editing
function editItem(index) {
const burgerData = JSON.parse(localStorage.getItem('burgerData')) || [];
const item = burgerData[index];
// Redirect to the update page with the item data
window.location.href = `Update.html?itemCode=${encodeURIComponent(item.itemCode)}&price=${encodeURIComponent(item.price)}&discount=${encodeURIComponent(item.discount)}`;
}
// Display burger data on page load
// window.onload = function() {
// displayBurgerData();
// };
function buyItem(itemCode, price, discount) {
window.location.href = `PlaceOrderUI.html?itemCode=${encodeURIComponent(itemCode)}&price=${encodeURIComponent(price)}&discount=${encodeURIComponent(discount)}`;
}
// function removeOrder(orderID) {
// let orders = JSON.parse(localStorage.getItem('orders')) || [];
// // Check if there are any orders
// if (orders.length === 0) {
// console.log('No orders found');
// return;
// }
// // Filter out the order with the specified orderID
// const newOrders = orders.filter(order => order.orderID !== orderID);
// // Save the updated orders back to localStorage
// localStorage.setItem('orders', JSON.stringify(newOrders));
// console.log('Order removed successfully');
// }
// removeOrder(1000);
function deleteItem(index) {
const burgerData = JSON.parse(localStorage.getItem('burgerData')) || [];
if (index > -1 && index < burgerData.length) {
burgerData.splice(index, 1); // Remove the item at the specified index
localStorage.setItem('burgerData', JSON.stringify(burgerData));
displayBurgerData(); // Refresh the table to reflect the changes
alert("Item deleted successfully.");
} else {
alert("Invalid item index.");
}
}
// Function to open the modal
function openModal() {
document.getElementById("myModal").style.display = "block";
}
function closeModal() {
document.getElementById("myModal").style.display = "none";
}
function openSubmaine() {
document.getElementById("mySub").style.display = "block";
}
function closeSubmarine() {
document.getElementById("mySub").style.display = "none";
}
function openFry() {
document.getElementById("myFry").style.display = "block";
}
function closeFry() {
document.getElementById("myFry").style.display = "none";
}
function openPasta() {
document.getElementById("myPasta").style.display = "block";
}
function closePasta() {
document.getElementById("myPasta").style.display = "none";
}
function openChicken() {
document.getElementById("myChicken").style.display = "block";
}
function closeChicken() {
document.getElementById("myChicken").style.display = "none";
}
function openBeverages() {
document.getElementById("myBeverages").style.display = "block";
}
function closeBeverages() {
document.getElementById("myBeverages").style.display = "none";
}
// Close the modal when clicking outside of it
window.onclick = function(event) {