File size: 41,668 Bytes
ebd9a1b
 
 
 
 
8c04391
ebd9a1b
 
 
 
 
 
 
8c04391
 
 
 
ebd9a1b
 
8c04391
ebd9a1b
8c04391
 
 
 
 
 
 
 
 
 
 
 
353392a
 
 
8c04391
ebd9a1b
 
8c04391
 
 
ebd9a1b
 
 
8c04391
 
 
 
 
 
 
 
 
 
 
 
 
ebd9a1b
 
8c04391
 
 
 
 
 
 
 
 
ebd9a1b
8c04391
 
 
 
 
 
 
 
 
 
ebd9a1b
8c04391
 
 
 
 
 
 
 
 
 
ebd9a1b
 
 
 
8c04391
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ebd9a1b
 
8c04391
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ebd9a1b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c04391
 
 
ebd9a1b
8c04391
 
ebd9a1b
 
 
8c04391
 
 
 
 
 
 
ebd9a1b
8c04391
ebd9a1b
8c04391
 
 
ebd9a1b
8c04391
ebd9a1b
 
 
8c04391
 
ebd9a1b
 
8c04391
 
ebd9a1b
 
 
8c04391
 
 
 
 
 
 
 
 
 
 
 
 
 
353392a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ebd9a1b
 
 
8c04391
 
 
 
 
 
 
 
 
 
 
 
ebd9a1b
8c04391
ebd9a1b
8c04391
 
 
ebd9a1b
 
 
 
 
 
8c04391
 
353392a
ebd9a1b
8c04391
353392a
8c04391
 
ebd9a1b
8c04391
 
353392a
ebd9a1b
8c04391
 
353392a
 
ebd9a1b
8c04391
 
 
ebd9a1b
 
8c04391
 
 
 
 
 
 
 
ebd9a1b
 
 
8c04391
 
ebd9a1b
 
8c04391
 
 
 
 
 
ebd9a1b
 
8c04391
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
353392a
 
 
 
8c04391
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
353392a
 
 
 
8c04391
 
 
 
 
 
 
 
 
 
 
 
353392a
 
 
 
 
 
8c04391
 
 
 
 
 
ebd9a1b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c04391
ebd9a1b
 
 
 
 
 
 
 
 
 
 
8c04391
ebd9a1b
 
8c04391
ebd9a1b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c04391
ebd9a1b
8c04391
 
ebd9a1b
 
 
 
8c04391
ebd9a1b
 
 
 
 
 
 
 
 
8c04391
ebd9a1b
 
 
 
 
 
 
 
 
 
 
 
 
 
8c04391
ebd9a1b
8c04391
ebd9a1b
8c04391
 
 
 
ebd9a1b
8c04391
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ebd9a1b
 
 
8c04391
 
ebd9a1b
8c04391
ebd9a1b
 
 
8c04391
 
ebd9a1b
8c04391
 
ebd9a1b
8c04391
 
ebd9a1b
 
8c04391
ebd9a1b
8c04391
ebd9a1b
8c04391
 
 
ebd9a1b
8c04391
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ebd9a1b
 
 
8c04391
ebd9a1b
 
8c04391
 
 
 
 
 
 
 
 
 
 
 
 
 
ebd9a1b
8c04391
 
 
 
ebd9a1b
8c04391
 
 
ebd9a1b
8c04391
 
 
 
 
353392a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c04391
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ebd9a1b
8c04391
 
 
 
 
 
 
 
 
ebd9a1b
8c04391
 
 
 
 
 
ebd9a1b
8c04391
 
ebd9a1b
8c04391
 
 
 
 
 
 
ebd9a1b
8c04391
 
ebd9a1b
8c04391
 
 
 
 
 
ebd9a1b
8c04391
 
ebd9a1b
 
 
8c04391
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ebd9a1b
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vending Machine Manager Pro</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(10px); }
            to { opacity: 1; transform: translateY(0); }
        }
        .fade-in { animation: fadeIn 0.3s ease-in-out; }
        .chart-container {
            height: 300px;
            width: 100%;
        }
    </style>
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
</head>
<body class="bg-gray-50 min-h-screen">
    <div class="flex h-screen overflow-hidden">
        <!-- Main Content -->
        <div class="flex flex-col flex-1 overflow-hidden">
            <!-- Top Navigation -->
            <div class="flex items-center justify-between h-16 flex-shrink-0 px-4 border-b border-gray-200 bg-white">
                <div class="flex-1 px-4">
                    <h1 class="text-xl font-bold text-gray-800 flex items-center">
                        <i class="fas fa-cubes text-indigo-500 mr-2"></i> Vending Machine Manager Pro
                    </h1>
                </div>
                <div class="flex space-x-3">
                    <button id="resetBtn" class="bg-red-600 hover:bg-red-700 text-white px-4 py-2 rounded-lg transition flex items-center text-sm">
                        <i class="fas fa-trash-alt mr-2"></i> Reset All
                    </button>
                    <button id="exportBtn" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg transition flex items-center text-sm">
                        <i class="fas fa-file-export mr-2"></i> Export
                    </button>
                    <button id="importBtn" class="bg-purple-600 hover:bg-purple-700 text-white px-4 py-2 rounded-lg transition flex items-center text-sm">
                        <i class="fas fa-file-import mr-2"></i> Import
                    </button>
                </div>
            </div>

            <!-- Main Content Area -->
            <div class="flex-1 overflow-auto p-6 bg-gray-50">
                <!-- Quick Stats -->
                <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6 mb-6">
                    <div class="bg-white rounded-xl shadow-sm p-6">
                        <div class="flex items-center">
                            <div class="p-3 rounded-lg bg-indigo-50 text-indigo-600">
                                <i class="fas fa-box-open text-xl"></i>
                            </div>
                            <div class="ml-4">
                                <h3 class="text-sm font-medium text-gray-500">Total Items</h3>
                                <p class="text-2xl font-semibold text-gray-900" id="totalItems">0</p>
                            </div>
                        </div>
                    </div>
                    <div class="bg-white rounded-xl shadow-sm p-6">
                        <div class="flex items-center">
                            <div class="p-3 rounded-lg bg-green-50 text-green-600">
                                <i class="fas fa-chart-line text-xl"></i>
                            </div>
                            <div class="ml-4">
                                <h3 class="text-sm font-medium text-gray-500">This Week's Profit</h3>
                                <p class="text-2xl font-semibold text-gray-900" id="weeklyProfit">$0.00</p>
                            </div>
                        </div>
                    </div>
                    <div class="bg-white rounded-xl shadow-sm p-6">
                        <div class="flex items-center">
                            <div class="p-3 rounded-lg bg-yellow-50 text-yellow-600">
                                <i class="fas fa-calendar-week text-xl"></i>
                            </div>
                            <div class="ml-4">
                                <h3 class="text-sm font-medium text-gray-500">Current Week</h3>
                                <p class="text-2xl font-semibold text-gray-900" id="currentWeek">Week 1</p>
                            </div>
                        </div>
                    </div>
                    <div class="bg-white rounded-xl shadow-sm p-6">
                        <div class="flex items-center">
                            <div class="p-3 rounded-lg bg-red-50 text-red-600">
                                <i class="fas fa-coins text-xl"></i>
                            </div>
                            <div class="ml-4">
                                <h3 class="text-sm font-medium text-gray-500">Total Profit</h3>
                                <p class="text-2xl font-semibold text-gray-900" id="totalProfit">$0.00</p>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Main Grid -->
                <div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
                    <!-- Inventory Section -->
                    <div class="lg:col-span-2 space-y-6">
                        <!-- Inventory Card -->
                        <div class="bg-white rounded-xl shadow-sm overflow-hidden">
                            <div class="p-6">
                                <div class="flex justify-between items-center mb-6">
                                    <h2 class="text-lg font-semibold text-gray-800">
                                        <i class="fas fa-boxes text-indigo-500 mr-2"></i> Inventory
                                    </h2>
                                    <div class="flex space-x-3">
                                        <button id="addItemBtn" class="bg-green-600 hover:bg-green-700 text-white px-4 py-2 rounded-lg transition flex items-center">
                                            <i class="fas fa-plus mr-2"></i> Add Item
                                        </button>
                                        <button id="restockBtn" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg transition flex items-center">
                                            <i class="fas fa-truck-loading mr-2"></i> Restock
                                        </button>
                                    </div>
                                </div>

                                <div class="overflow-x-auto">
                                    <table class="min-w-full divide-y divide-gray-200">
                                        <thead class="bg-gray-50">
                                            <tr>
                                                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Item</th>
                                                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Stock</th>
                                                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Cost</th>
                                                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Price</th>
                                                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Profit</th>
                                                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th>
                                            </tr>
                                        </thead>
                                        <tbody id="inventoryTable" class="bg-white divide-y divide-gray-200">
                                            <tr>
                                                <td colspan="6" class="px-6 py-4 text-center text-gray-500">No items in inventory. Add your first item!</td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- Analytics Section -->
                    <div class="space-y-6">
                        <!-- Profit Chart -->
                        <div class="bg-white rounded-xl shadow-sm p-6">
                            <h2 class="text-lg font-semibold text-gray-800 mb-4">
                                <i class="fas fa-chart-bar text-indigo-500 mr-2"></i> Weekly Profit
                            </h2>
                            <div class="chart-container">
                                <canvas id="profitChart"></canvas>
                            </div>
                        </div>

                        <!-- Restock History -->
                        <div class="bg-white rounded-xl shadow-sm p-6">
                            <h2 class="text-lg font-semibold text-gray-800 mb-4">
                                <i class="fas fa-history text-indigo-500 mr-2"></i> Restock History
                            </h2>
                            <div class="overflow-y-auto max-h-64">
                                <table class="min-w-full divide-y divide-gray-200">
                                    <thead class="bg-gray-50">
                                        <tr>
                                            <th scope="col" class="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Week</th>
                                            <th scope="col" class="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Profit</th>
                                            <th scope="col" class="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Items</th>
                                        </tr>
                                    </thead>
                                    <tbody id="restockHistory" class="bg-white divide-y divide-gray-200">
                                        <tr>
                                            <td colspan="3" class="px-3 py-2 text-center text-gray-500">No restock history yet</td>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Add/Edit Item Modal -->
    <div id="itemModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center hidden z-50">
        <div class="bg-white rounded-xl p-6 w-full max-w-md fade-in">
            <div class="flex justify-between items-center mb-4">
                <h3 class="text-xl font-semibold" id="modalTitle">Add New Item</h3>
                <button id="closeModal" class="text-gray-500 hover:text-gray-700">
                    <i class="fas fa-times"></i>
                </button>
            </div>
            <form id="itemForm" class="space-y-4">
                <input type="hidden" id="itemId">
                <div>
                    <label for="itemName" class="block text-sm font-medium text-gray-700">Item Name</label>
                    <input type="text" id="itemName" class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500">
                </div>
                <div>
                    <label for="itemStock" class="block text-sm font-medium text-gray-700">Stock Quantity</label>
                    <input type="number" id="itemStock" min="0" class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500">
                </div>
                <div>
                    <label for="itemCost" class="block text-sm font-medium text-gray-700">Cost Price ($)</label>
                    <input type="number" id="itemCost" min="0" step="0.01" class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500">
                </div>
                <div>
                    <label for="itemPrice" class="block text-sm font-medium text-gray-700">Retail Price ($)</label>
                    <input type="number" id="itemPrice" min="0" step="0.01" class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500">
                </div>
                <div class="flex justify-end space-x-3 pt-4">
                    <button type="button" id="cancelBtn" class="bg-gray-200 hover:bg-gray-300 px-4 py-2 rounded-lg transition">Cancel</button>
                    <button type="submit" class="bg-indigo-600 hover:bg-indigo-700 text-white px-4 py-2 rounded-lg transition">Save</button>
                </div>
            </form>
        </div>
    </div>

    <!-- Restock Modal -->
    <div id="restockModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center hidden z-50">
        <div class="bg-white rounded-xl p-6 w-full max-w-md fade-in">
            <div class="flex justify-between items-center mb-4">
                <h3 class="text-xl font-semibold">Restock Inventory</h3>
                <button id="closeRestockModal" class="text-gray-500 hover:text-gray-700">
                    <i class="fas fa-times"></i>
                </button>
            </div>
            <form id="restockForm" class="space-y-4">
                <div>
                    <label class="block text-sm font-medium text-gray-700">Current Week: <span id="restockWeekDisplay">Week 1</span></label>
                </div>
                <div>
                    <label class="block text-sm font-medium text-gray-700">Items to Restock</label>
                    <div class="mt-2 space-y-2 max-h-60 overflow-y-auto" id="restockItemsList">
                        <!-- Items will be added here dynamically -->
                    </div>
                </div>
                <div class="flex justify-end space-x-3 pt-4">
                    <button type="button" id="cancelRestockBtn" class="bg-gray-200 hover:bg-gray-300 px-4 py-2 rounded-lg transition">Cancel</button>
                    <button type="submit" class="bg-indigo-600 hover:bg-indigo-700 text-white px-4 py-2 rounded-lg transition">Complete Restock</button>
                </div>
            </form>
        </div>
    </div>

    <!-- Import Modal -->
    <div id="importModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center hidden z-50">
        <div class="bg-white rounded-xl p-6 w-full max-w-md fade-in">
            <div class="flex justify-between items-center mb-4">
                <h3 class="text-xl font-semibold">Import Data</h3>
                <button id="closeImportModal" class="text-gray-500 hover:text-gray-700">
                    <i class="fas fa-times"></i>
                </button>
            </div>
            <form id="importForm" class="space-y-4">
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-2">Select JSON File</label>
                    <input type="file" id="importFile" accept=".json" class="block w-full text-sm text-gray-500
                        file:mr-4 file:py-2 file:px-4
                        file:rounded-lg file:border-0
                        file:text-sm file:font-semibold
                        file:bg-indigo-50 file:text-indigo-700
                        hover:file:bg-indigo-100">
                </div>
                <div class="flex justify-end space-x-3 pt-4">
                    <button type="button" id="cancelImportBtn" class="bg-gray-200 hover:bg-gray-300 px-4 py-2 rounded-lg transition">Cancel</button>
                    <button type="submit" class="bg-indigo-600 hover:bg-indigo-700 text-white px-4 py-2 rounded-lg transition">Import</button>
                </div>
    </form>
        </div>
    </div>

    <!-- Confirmation Modal -->
    <div id="confirmModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center hidden z-50">
        <div class="bg-white rounded-xl p-6 w-full max-w-md fade-in">
            <div class="flex justify-between items-center mb-4">
                <h3 class="text-xl font-semibold">Confirm Reset</h3>
                <button id="closeConfirmModal" class="text-gray-500 hover:text-gray-700">
                    <i class="fas fa-times"></i>
                </button>
            </div>
            <div class="mb-6">
                <p class="text-gray-700">Are you sure you want to reset all data? This will delete all inventory items and reset all profit tracking. This action cannot be undone.</p>
            </div>
            <div class="flex justify-end space-x-3">
                <button type="button" id="cancelResetBtn" class="bg-gray-200 hover:bg-gray-300 px-4 py-2 rounded-lg transition">Cancel</button>
                <button type="button" id="confirmResetBtn" class="bg-red-600 hover:bg-red-700 text-white px-4 py-2 rounded-lg transition">Reset All Data</button>
            </div>
        </div>
    </div>

    <!-- Success Notification -->
    <div id="successNotification" class="fixed top-4 right-4 bg-green-500 text-white px-4 py-2 rounded-lg shadow-lg flex items-center hidden z-50">
        <i class="fas fa-check-circle mr-2"></i>
        <span id="successMessage">Operation completed successfully!</span>
    </div>

    <!-- Error Notification -->
    <div id="errorNotification" class="fixed top-4 right-4 bg-red-500 text-white px-4 py-2 rounded-lg shadow-lg flex items-center hidden z-50">
        <i class="fas fa-exclamation-circle mr-2"></i>
        <span id="errorMessage">An error occurred!</span>
    </div>

    <script>
        // Data structure
        let inventory = [];
        let restockHistory = [];
        let currentWeek = 1;
        let profitChart = null;
        let editMode = false;
        let currentEditId = null;

        // DOM Elements
        const inventoryTable = document.getElementById('inventoryTable');
        const itemModal = document.getElementById('itemModal');
        const restockModal = document.getElementById('restockModal');
        const importModal = document.getElementById('importModal');
        const confirmModal = document.getElementById('confirmModal');
        const addItemBtn = document.getElementById('addItemBtn');
        const restockBtn = document.getElementById('restockBtn');
        const resetBtn = document.getElementById('resetBtn');
        const exportBtn = document.getElementById('exportBtn');
        const importBtn = document.getElementById('importBtn');
        const closeModal = document.getElementById('closeModal');
        const closeRestockModal = document.getElementById('closeRestockModal');
        const closeImportModal = document.getElementById('closeImportModal');
        const closeConfirmModal = document.getElementById('closeConfirmModal');
        const cancelBtn = document.getElementById('cancelBtn');
        const cancelRestockBtn = document.getElementById('cancelRestockBtn');
        const cancelImportBtn = document.getElementById('cancelImportBtn');
        const cancelResetBtn = document.getElementById('cancelResetBtn');
        const confirmResetBtn = document.getElementById('confirmResetBtn');
        const itemForm = document.getElementById('itemForm');
        const restockForm = document.getElementById('restockForm');
        const importForm = document.getElementById('importForm');
        const totalItems = document.getElementById('totalItems');
        const weeklyProfit = document.getElementById('weeklyProfit');
        const totalProfit = document.getElementById('totalProfit');
        const currentWeekDisplay = document.getElementById('currentWeek');
        const restockWeekDisplay = document.getElementById('restockWeekDisplay');
        const restockItemsList = document.getElementById('restockItemsList');
        const restockHistoryTable = document.getElementById('restockHistory');
        const successNotification = document.getElementById('successNotification');
        const successMessage = document.getElementById('successMessage');
        const errorNotification = document.getElementById('errorNotification');
        const errorMessage = document.getElementById('errorMessage');

        // Initialize the app
        document.addEventListener('DOMContentLoaded', () => {
            // Load data from localStorage if available
            loadFromLocalStorage();
            
            renderInventory();
            updateDashboard();
            renderRestockHistory();
            initializeProfitChart();
            
            // Add event listeners
            addEventListeners();
        });

        // Add all event listeners
        function addEventListeners() {
            // Modal controls
            addItemBtn.addEventListener('click', () => {
                editMode = false;
                currentEditId = null;
                document.getElementById('modalTitle').textContent = 'Add New Item';
                document.getElementById('itemForm').reset();
                document.getElementById('itemId').value = '';
                itemModal.classList.remove('hidden');
            });

            restockBtn.addEventListener('click', () => {
                if (inventory.length === 0) {
                    showNotification('No items to restock. Add items first!', 'error');
                    return;
                }
                prepareRestockModal();
                restockModal.classList.remove('hidden');
            });

            resetBtn.addEventListener('click', () => {
                confirmModal.classList.remove('hidden');
            });

            exportBtn.addEventListener('click', exportData);
            importBtn.addEventListener('click', () => {
                importModal.classList.remove('hidden');
            });

            closeModal.addEventListener('click', () => {
                itemModal.classList.add('hidden');
            });

            closeRestockModal.addEventListener('click', () => {
                restockModal.classList.add('hidden');
            });

            closeImportModal.addEventListener('click', () => {
                importModal.classList.add('hidden');
            });

            closeConfirmModal.addEventListener('click', () => {
                confirmModal.classList.add('hidden');
            });

            cancelBtn.addEventListener('click', () => {
                itemModal.classList.add('hidden');
            });

            cancelRestockBtn.addEventListener('click', () => {
                restockModal.classList.add('hidden');
            });

            cancelImportBtn.addEventListener('click', () => {
                importModal.classList.add('hidden');
            });

            cancelResetBtn.addEventListener('click', () => {
                confirmModal.classList.add('hidden');
            });

            confirmResetBtn.addEventListener('click', resetAllData);

            // Form submissions
            itemForm.addEventListener('submit', saveItem);
            restockForm.addEventListener('submit', completeRestock);
            importForm.addEventListener('submit', importData);
        }

        // Render inventory table
        function renderInventory() {
            inventoryTable.innerHTML = '';
            
            if (inventory.length === 0) {
                inventoryTable.innerHTML = `
                    <tr>
                        <td colspan="6" class="px-6 py-4 text-center text-gray-500">No items in inventory. Add your first item!</td>
                    </tr>
                `;
                return;
            }

            inventory.forEach(item => {
                const profit = (item.price - item.cost) * item.stock;
                const profitClass = profit >= 0 ? 'text-green-600' : 'text-red-600';
                const profitDisplay = formatCurrency(profit);

                const row = document.createElement('tr');
                row.className = 'hover:bg-gray-50';
                row.innerHTML = `
                    <td class="px-6 py-4 whitespace-nowrap">
                        <div class="font-medium text-gray-900">${item.name}</div>
                    </td>
                    <td class="px-6 py-4 whitespace-nowrap">
                        <div class="text-gray-900">${item.stock}</div>
                    </td>
                    <td class="px-6 py-4 whitespace-nowrap">
                        <div class="text-gray-900">${formatCurrency(item.cost)}</div>
                    </td>
                    <td class="px-6 py-4 whitespace-nowrap">
                        <div class="text-gray-900">${formatCurrency(item.price)}</div>
                    </td>
                    <td class="px-6 py-4 whitespace-nowrap">
                        <div class="${profitClass}">${profitDisplay}</div>
                    </td>
                    <td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
                        <button class="text-indigo-600 hover:text-indigo-900 mr-3 edit-btn" data-id="${item.id}">
                            <i class="fas fa-edit"></i>
                        </button>
                        <button class="text-red-600 hover:text-red-900 delete-btn" data-id="${item.id}">
                            <i class="fas fa-trash"></i>
                        </button>
                    </td>
                `;
                inventoryTable.appendChild(row);
            });

            // Add event listeners to edit and delete buttons
            document.querySelectorAll('.edit-btn').forEach(btn => {
                btn.addEventListener('click', (e) => {
                    const id = parseInt(e.currentTarget.getAttribute('data-id'));
                    editItem(id);
                });
            });

            document.querySelectorAll('.delete-btn').forEach(btn => {
                btn.addEventListener('click', (e) => {
                    const id = parseInt(e.currentTarget.getAttribute('data-id'));
                    deleteItem(id);
                });
            });
        }

        // Edit item
        function editItem(id) {
            const item = inventory.find(item => item.id === id);
            if (!item) return;

            editMode = true;
            currentEditId = id;
            document.getElementById('modalTitle').textContent = 'Edit Item';
            document.getElementById('itemId').value = item.id;
            document.getElementById('itemName').value = item.name;
            document.getElementById('itemStock').value = item.stock;
            document.getElementById('itemCost').value = item.cost;
            document.getElementById('itemPrice').value = item.price;
            itemModal.classList.remove('hidden');
        }

        // Delete item
        function deleteItem(id) {
            if (confirm('Are you sure you want to delete this item?')) {
                inventory = inventory.filter(item => item.id !== id);
                saveToLocalStorage();
                renderInventory();
                updateDashboard();
                showNotification('Item deleted successfully!', 'success');
            }
        }

        // Save item (add or edit)
        function saveItem(e) {
            e.preventDefault();

            const id = editMode ? currentEditId : Date.now();
            const name = document.getElementById('itemName').value;
            const stock = parseInt(document.getElementById('itemStock').value);
            const cost = parseFloat(document.getElementById('itemCost').value);
            const price = parseFloat(document.getElementById('itemPrice').value);

            if (!name || isNaN(stock) || isNaN(cost) || isNaN(price)) {
                showNotification('Please fill in all fields with valid values', 'error');
                return;
            }

            if (editMode) {
                // Update existing item
                const index = inventory.findIndex(item => item.id === id);
                if (index !== -1) {
                    inventory[index] = { id, name, stock, cost, price };
                }
            } else {
                // Add new item
                inventory.push({ id, name, stock, cost, price });
            }

            saveToLocalStorage();
            renderInventory();
            updateDashboard();
            itemModal.classList.add('hidden');
            
            const message = editMode ? 'Item updated successfully!' : 'Item added successfully!';
            showNotification(message, 'success');
        }

        // Prepare restock modal
        function prepareRestockModal() {
            restockWeekDisplay.textContent = `Week ${currentWeek}`;
            restockItemsList.innerHTML = '';
            
            inventory.forEach(item => {
                const itemDiv = document.createElement('div');
                itemDiv.className = 'flex items-center justify-between p-2 bg-gray-50 rounded-lg';
                itemDiv.innerHTML = `
                    <div class="flex-1">
                        <span class="font-medium">${item.name}</span>
                        <span class="text-sm text-gray-500 ml-2">(Current: ${item.stock})</span>
                    </div>
                    <input type="number" min="0" value="${item.stock}" 
                        class="w-20 border border-gray-300 rounded-md shadow-sm py-1 px-2 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 restock-qty" 
                        data-id="${item.id}">
                `;
                restockItemsList.appendChild(itemDiv);
            });
        }

        // Complete restock
        function completeRestock(e) {
            e.preventDefault();
            
            // Calculate profit for this week
            let weeklyProfitValue = 0;
            const updatedItems = [];
            
            document.querySelectorAll('.restock-qty').forEach(input => {
                const id = parseInt(input.getAttribute('data-id'));
                const newStock = parseInt(input.value);
                
                const item = inventory.find(item => item.id === id);
                if (item) {
                    const soldItems = item.stock - newStock;
                    if (soldItems > 0) {
                        weeklyProfitValue += (item.price - item.cost) * soldItems;
                    }
                    item.stock = newStock;
                    updatedItems.push(item.name);
                }
            });
            
            // Add to restock history
            restockHistory.push({
                week: currentWeek,
                profit: weeklyProfitValue,
                items: updatedItems
            });
            
            // Increment week counter
            currentWeek++;
            
            saveToLocalStorage();
            renderInventory();
            updateDashboard();
            renderRestockHistory();
            updateProfitChart();
            restockModal.classList.add('hidden');
            
            showNotification(`Restock completed for Week ${currentWeek - 1}! Profit: ${formatCurrency(weeklyProfitValue)}`, 'success');
        }

        // Render restock history
        function renderRestockHistory() {
            restockHistoryTable.innerHTML = '';
            
            if (restockHistory.length === 0) {
                restockHistoryTable.innerHTML = `
                    <tr>
                        <td colspan="3" class="px-3 py-2 text-center text-gray-500">No restock history yet</td>
                    </tr>
                `;
                return;
            }
            
            // Sort by week descending (newest first)
            const sortedHistory = [...restockHistory].sort((a, b) => b.week - a.week);
            
            sortedHistory.forEach(record => {
                const row = document.createElement('tr');
                row.className = 'hover:bg-gray-50';
                row.innerHTML = `
                    <td class="px-3 py-2 whitespace-nowrap">
                        <div class="text-gray-900">Week ${record.week}</div>
                    </td>
                    <td class="px-3 py-2 whitespace-nowrap">
                        <div class="${record.profit >= 0 ? 'text-green-600' : 'text-red-600'}">${formatCurrency(record.profit)}</div>
                    </td>
                    <td class="px-3 py-2">
                        <div class="text-gray-900 text-sm">${record.items.join(', ')}</div>
                    </td>
                `;
                restockHistoryTable.appendChild(row);
            });
        }

        // Initialize profit chart
        function initializeProfitChart() {
            const ctx = document.getElementById('profitChart').getContext('2d');
            
            profitChart = new Chart(ctx, {
                type: 'bar',
                data: {
                    labels: [],
                    datasets: [{
                        label: 'Weekly Profit',
                        data: [],
                        backgroundColor: '#4f46e5',
                        borderColor: '#4f46e5',
                        borderWidth: 1
                    }]
                },
                options: {
                    responsive: true,
                    maintainAspectRatio: false,
                    scales: {
                        y: {
                            beginAtZero: true,
                            ticks: {
                                callback: function(value) {
                                    return '$' + value;
                                }
                            }
                        }
                    },
                    plugins: {
                        tooltip: {
                            callbacks: {
                                label: function(context) {
                                    return 'Profit: $' + context.raw.toFixed(2);
                                }
                            }
                        }
                    }
                }
            });
            
            updateProfitChart();
        }

        // Update profit chart
        function updateProfitChart() {
            if (!profitChart) return;
            
            // Sort by week ascending
            const sortedHistory = [...restockHistory].sort((a, b) => a.week - b.week);
            
            const weeks = sortedHistory.map(record => `Week ${record.week}`);
            const profits = sortedHistory.map(record => record.profit);
            
            profitChart.data.labels = weeks;
            profitChart.data.datasets[0].data = profits;
            profitChart.update();
        }

        // Update dashboard stats
        function updateDashboard() {
            totalItems.textContent = inventory.length;
            currentWeekDisplay.textContent = `Week ${currentWeek}`;
            
            // Calculate total profit
            const totalProfitValue = restockHistory.reduce((sum, record) => sum + record.profit, 0);
            totalProfit.textContent = formatCurrency(totalProfitValue);
            
            // Calculate this week's profit (if we have data for current week - 1)
            const currentWeekRecord = restockHistory.find(record => record.week === currentWeek - 1);
            weeklyProfit.textContent = currentWeekRecord ? formatCurrency(currentWeekRecord.profit) : '$0.00';
        }

        // Reset all data
        function resetAllData() {
            inventory = [];
            restockHistory = [];
            currentWeek = 1;
            
            saveToLocalStorage();
            renderInventory();
            updateDashboard();
            renderRestockHistory();
            updateProfitChart();
            confirmModal.classList.add('hidden');
            
            showNotification('All data has been reset successfully!', 'success');
        }

        // Format currency
        function formatCurrency(value) {
            return '$' + value.toFixed(2);
        }

        // Show notification
        function showNotification(message, type) {
            if (type === 'success') {
                successMessage.textContent = message;
                successNotification.classList.remove('hidden');
                setTimeout(() => {
                    successNotification.classList.add('hidden');
                }, 3000);
            } else {
                errorMessage.textContent = message;
                errorNotification.classList.remove('hidden');
                setTimeout(() => {
                    errorNotification.classList.add('hidden');
                }, 3000);
            }
        }

        // Save data to localStorage
        function saveToLocalStorage() {
            const data = {
                inventory,
                restockHistory,
                currentWeek
            };
            localStorage.setItem('vendingMachineData', JSON.stringify(data));
        }

        // Load data from localStorage
        function loadFromLocalStorage() {
            const savedData = localStorage.getItem('vendingMachineData');
            if (savedData) {
                try {
                    const data = JSON.parse(savedData);
                    inventory = data.inventory || [];
                    restockHistory = data.restockHistory || [];
                    currentWeek = data.currentWeek || 1;
                } catch (e) {
                    console.error('Failed to parse saved data', e);
                }
            }
        }

        // Export data as JSON file
        function exportData() {
            if (inventory.length === 0 && restockHistory.length === 0) {
                showNotification('No data to export', 'error');
                return;
            }
            
            const data = {
                inventory,
                restockHistory,
                currentWeek,
                exportedAt: new Date().toISOString()
            };
            
            const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' });
            const url = URL.createObjectURL(blob);
            
            const a = document.createElement('a');
            a.href = url;
            a.download = `vending-machine-data-${new Date().toISOString().split('T')[0]}.json`;
            document.body.appendChild(a);
            a.click();
            document.body.removeChild(a);
            URL.revokeObjectURL(url);
            
            showNotification('Data exported successfully!', 'success');
        }

        // Import data from JSON file
        function importData(e) {
            e.preventDefault();
            
            const fileInput = document.getElementById('importFile');
            const file = fileInput.files[0];
            
            if (!file) {
                showNotification('Please select a file to import', 'error');
                return;
            }
            
            const reader = new FileReader();
            reader.onload = function(e) {
                try {
                    const data = JSON.parse(e.target.result);
                    
                    if (confirm('This will replace all current data. Are you sure?')) {
                        inventory = data.inventory || [];
                        restockHistory = data.restockHistory || [];
                        currentWeek = data.currentWeek || 1;
                        
                        saveToLocalStorage();
                        renderInventory();
                        updateDashboard();
                        renderRestockHistory();
                        updateProfitChart();
                        
                        importModal.classList.add('hidden');
                        fileInput.value = '';
                        showNotification('Data imported successfully!', 'success');
                    }
                } catch (e) {
                    showNotification('Failed to parse the file. Please check the format.', 'error');
                    console.error('Import error', e);
                }
            };
            reader.readAsText(file);
        }
    </script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=101keyoperator/vms" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>