lokeshloki143 commited on
Commit
66e8343
·
verified ·
1 Parent(s): 1b42973

Create bill.html

Browse files
Files changed (1) hide show
  1. templates/bill.html +699 -0
templates/bill.html ADDED
@@ -0,0 +1,699 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Your Bill</title>
7
+ <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
8
+ <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons/font/bootstrap-icons.css" rel="stylesheet">
9
+ <style>
10
+ body {
11
+ font-family: Arial, sans-serif;
12
+ background-color: #fdf4e3;
13
+ color: #333;
14
+ }
15
+ .top-bar {
16
+ background-color: #FF6F3C;
17
+ width: 100%;
18
+ padding: 10px 15px;
19
+ display: flex;
20
+ align-items: center;
21
+ }
22
+ .back-link {
23
+ display: flex;
24
+ align-items: center;
25
+ text-decoration: none;
26
+ }
27
+ .back-arrow {
28
+ font-size: 1.8rem;
29
+ color: #000;
30
+ font-weight: bold;
31
+ }
32
+ .back-label {
33
+ margin-left: 10px;
34
+ color: white;
35
+ font-weight: bold;
36
+ font-size: 1rem;
37
+ }
38
+ .order-heading {
39
+ color: #000;
40
+ font-size: 2.5rem;
41
+ font-weight: bold;
42
+ text-align: center;
43
+ margin-top: 30px;
44
+ }
45
+ .bill-container {
46
+ max-width: 768px;
47
+ margin: 20px auto;
48
+ padding: 15px;
49
+ background-color: #FFFFFF;
50
+ border-radius: 10px;
51
+ box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
52
+ }
53
+ .bill-item {
54
+ display: flex;
55
+ align-items: flex-start;
56
+ justify-content: space-between;
57
+ border: 1px solid #fdf4e3;
58
+ padding: 15px;
59
+ background-color: #fff;
60
+ border-radius: 8px;
61
+ margin-bottom: 10px;
62
+ }
63
+ .image-wrapper {
64
+ width: 80px;
65
+ height: 80px;
66
+ display: flex;
67
+ align-items: center;
68
+ justify-content: center;
69
+ }
70
+ .bill-item img {
71
+ width: 70px;
72
+ height: 70px;
73
+ object-fit: cover;
74
+ border-radius: 5px;
75
+ border: 1px solid #ffcc80;
76
+ }
77
+ .bill-item img:hover {
78
+ transform: scale(1.05);
79
+ }
80
+ .bill-item-details {
81
+ flex: 1;
82
+ margin-left: 15px;
83
+ }
84
+ .bill-item-title {
85
+ font-size: 1.1rem;
86
+ font-weight: bold;
87
+ }
88
+ .text-primary {
89
+ color: #2e7d32;
90
+ text-align: right;
91
+ font-weight: bold;
92
+ }
93
+ .bill-summary {
94
+ text-align: left;
95
+ margin-top: 15px;
96
+ padding: 20px;
97
+ background-color: #fff;
98
+ border-radius: 12px;
99
+ border: 2px solid #fdf4e3;
100
+ }
101
+ .bill-details {
102
+ display: grid;
103
+ grid-template-columns: 1fr 1fr;
104
+ grid-gap: 10px;
105
+ margin-bottom: 10px;
106
+ }
107
+ .bill-details .label {
108
+ font-weight: 600;
109
+ font-size: 1rem;
110
+ }
111
+ .bill-details .amount {
112
+ text-align: right;
113
+ font-weight: 600;
114
+ font-size: 1rem;
115
+ }
116
+ .dotted-line {
117
+ border-bottom: 2px dotted #ccc;
118
+ margin: 15px 0;
119
+ }
120
+ .total-bill {
121
+ display: grid;
122
+ grid-template-columns: 1fr 1fr;
123
+ font-weight: 600;
124
+ font-size: 1.2rem;
125
+ }
126
+ .total-bill .amount {
127
+ text-align: right;
128
+ color: #2e7d32;
129
+ }
130
+ .generate-bill-button {
131
+ background-color: #A52A2A;
132
+ color: #ffffff;
133
+ padding: 12px;
134
+ border-radius: 8px;
135
+ border: none;
136
+ width: 100%;
137
+ font-size: 1rem;
138
+ cursor: pointer;
139
+ margin-top: 15px;
140
+ }
141
+ .confirm-order-button {
142
+ background-color: #2e7d32;
143
+ color: #ffffff;
144
+ padding: 12px;
145
+ border-radius: 8px;
146
+ border: none;
147
+ width: 100%;
148
+ font-size: 1rem;
149
+ cursor: pointer;
150
+ margin-top: 10px;
151
+ }
152
+ .modal {
153
+ display: none;
154
+ position: fixed;
155
+ top: 0;
156
+ left: 0;
157
+ width: 100%;
158
+ height: 100%;
159
+ background-color: rgba(0, 0, 0, 0.5);
160
+ z-index: 1000;
161
+ justify-content: center;
162
+ align-items: center;
163
+ }
164
+ .modal-content {
165
+ background-color: #fff;
166
+ padding: 20px;
167
+ border-radius: 10px;
168
+ width: 90%;
169
+ max-width: 600px;
170
+ max-height: 80vh;
171
+ overflow-y: auto;
172
+ box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
173
+ }
174
+ .modal-content h3 {
175
+ text-align: center;
176
+ margin-bottom: 20px;
177
+ color: #333;
178
+ }
179
+ .close-modal {
180
+ position: absolute;
181
+ top: 10px;
182
+ right: 15px;
183
+ font-size: 1.5rem;
184
+ cursor: pointer;
185
+ color: #333;
186
+ }
187
+ .menu-items-container {
188
+ display: flex;
189
+ flex-wrap: wrap;
190
+ gap: 10px;
191
+ padding: 10px;
192
+ }
193
+ .menu-item {
194
+ display: flex;
195
+ align-items: center;
196
+ justify-content: space-between;
197
+ width: calc(50% - 10px);
198
+ padding: 10px;
199
+ border-radius: 8px;
200
+ background-color: #fff;
201
+ box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
202
+ border: 2px solid #fdf4e3;
203
+ min-height: 70px;
204
+ }
205
+ .menu-item img {
206
+ width: 50px;
207
+ height: 50px;
208
+ object-fit: cover;
209
+ border-radius: 5px;
210
+ margin-right: 10px;
211
+ border: 1px solid #ffcc80;
212
+ }
213
+ .menu-item:hover img {
214
+ transform: scale(1.05);
215
+ }
216
+ .menu-item-details {
217
+ flex-grow: 1;
218
+ font-size: 0.9rem;
219
+ }
220
+ .menu-item-details strong {
221
+ font-size: 1rem;
222
+ }
223
+ .menu-item-details small {
224
+ display: block;
225
+ color: #666;
226
+ font-size: 0.8rem;
227
+ }
228
+ .quantity-selector {
229
+ display: none;
230
+ align-items: center;
231
+ }
232
+ .quantity-selector button {
233
+ width: 28px;
234
+ height: 28px;
235
+ border: none;
236
+ background-color: #f0f0f0;
237
+ font-size: 1rem;
238
+ font-weight: bold;
239
+ cursor: pointer;
240
+ border-radius: 4px;
241
+ }
242
+ .quantity-selector input {
243
+ width: 40px;
244
+ text-align: center;
245
+ border: none;
246
+ background-color: #f8f9fa;
247
+ font-size: 1rem;
248
+ margin: 0 5px;
249
+ border-radius: 4px;
250
+ }
251
+ .customization-section {
252
+ display: none;
253
+ position: absolute;
254
+ top: 100%;
255
+ left: 0;
256
+ right: 0;
257
+ background-color: #fff;
258
+ padding: 15px;
259
+ border-radius: 8px;
260
+ box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
261
+ z-index: 10;
262
+ border: 2px solid #fdf4e3;
263
+ max-height: 300px;
264
+ overflow-y: auto;
265
+ }
266
+ .customization-section.show {
267
+ display: block;
268
+ }
269
+ .customization-section h4 {
270
+ font-size: 1.2rem;
271
+ margin-bottom: 10px;
272
+ }
273
+ .customization-section label {
274
+ display: block;
275
+ margin-bottom: 5px;
276
+ font-size: 0.9rem;
277
+ }
278
+ .customization-section textarea {
279
+ width: 100%;
280
+ height: 60px;
281
+ margin-top: 10px;
282
+ padding: 5px;
283
+ border: 1px solid #ccc;
284
+ border-radius: 5px;
285
+ font-size: 0.9rem;
286
+ }
287
+ .customization-actions {
288
+ display: flex;
289
+ justify-content: space-between;
290
+ margin-top: 15px;
291
+ }
292
+ .customization-actions button {
293
+ padding: 8px;
294
+ border: none;
295
+ border-radius: 5px;
296
+ cursor: pointer;
297
+ width: 48%;
298
+ text-align: center;
299
+ font-size: 0.9rem;
300
+ color: #fff;
301
+ }
302
+ .add-to-cart-btn {
303
+ background-color: #A52A2A;
304
+ }
305
+ .cancel-customization-btn {
306
+ background-color: #6c757d;
307
+ }
308
+ .modal-actions {
309
+ display: flex;
310
+ justify-content: space-between;
311
+ margin-top: 20px;
312
+ }
313
+ .action-btn {
314
+ padding: 10px;
315
+ border: none;
316
+ border-radius: 8px;
317
+ cursor: pointer;
318
+ width: 48%;
319
+ text-align: center;
320
+ color: #fff;
321
+ }
322
+ .view-bill-btn {
323
+ background-color: #A52A2A;
324
+ }
325
+ .cancel-btn {
326
+ background-color: #6c757d;
327
+ }
328
+ </style>
329
+ </head>
330
+ <body>
331
+ <div class="top-bar">
332
+ <a href="/cart" class="back-link">
333
+ <span class="back-arrow">⟨</span>
334
+ <span class="back-label">Back to Cart</span>
335
+ </a>
336
+ </div>
337
+
338
+ <div class="order-heading">Your Bill</div>
339
+
340
+ <div class="container">
341
+ <div class="bill-container">
342
+ {% for item in cart_items %}
343
+ <div class="bill-item">
344
+ <div class="image-wrapper">
345
+ <img src="{{ item.Image1__c }}" alt="{{ item.Name }}" onerror="this.src='/static/placeholder.jpg';">
346
+ </div>
347
+ <div class="bill-item-details">
348
+ <div class="bill-item-title">{{ item.Name }} x{{ item.Quantity__c }}</div>
349
+ <div class="bill-item-addons">
350
+ <small class="text-muted">Add-ons: {{ item.Add_Ons__c }}</small>
351
+ </div>
352
+ <div class="bill-item-instructions">
353
+ <small class="text-muted">Instructions: {{ item.Instructions__c or "None" }}</small>
354
+ </div>
355
+ </div>
356
+ <div class="text-primary">${{ item.Price__c }}</div>
357
+ </div>
358
+ {% else %}
359
+ <p>No items in your bill.</p>
360
+ {% endfor %}
361
+
362
+ <div class="bill-summary">
363
+ <div class="bill-details">
364
+ <div class="label">Subtotal</div>
365
+ <div class="amount">${{ subtotal }}</div>
366
+ </div>
367
+ <div class="dotted-line"></div>
368
+ <div class="total-bill">
369
+ <div class="label">Total</div>
370
+ <div class="amount">${{ subtotal }}</div>
371
+ </div>
372
+ <button class="generate-bill-button" onclick="generateBill()">Generate Bill</button>
373
+ <button class="confirm-order-button" onclick="confirmOrder()">Confirm Order</button>
374
+ </div>
375
+ </div>
376
+ </div>
377
+
378
+ <div class="modal" id="anythingElseModal">
379
+ <div class="modal-content">
380
+ <span class="close-modal" onclick="closeAnythingElseModal()">×</span>
381
+ <h3>Anything Else You Want?</h3>
382
+ <div class="menu-items-container" id="menuItems"></div>
383
+ <div class="modal-actions">
384
+ <button class="action-btn view-bill-btn" onclick="refreshBill()">View Updated Bill</button>
385
+ <button class="action-btn cancel-btn" onclick="closeAnythingElseModal()">Cancel</button>
386
+ </div>
387
+ </div>
388
+ </div>
389
+
390
+ <script>
391
+ let currentCart = null;
392
+ let menuItems = [];
393
+ let selectedItem = null;
394
+ let availableAddOns = [];
395
+
396
+ function fetchAddOns() {
397
+ return fetch('/cart/fetch_add_ons', {
398
+ method: 'GET',
399
+ headers: { 'Content-Type': 'application/json' }
400
+ })
401
+ .then(response => response.json())
402
+ .then(data => {
403
+ if (data.success) {
404
+ availableAddOns = data.add_ons;
405
+ } else {
406
+ console.error('Error fetching add-ons:', data.error);
407
+ availableAddOns = [];
408
+ }
409
+ })
410
+ .catch(err => {
411
+ console.error('Error fetching add-ons:', err);
412
+ availableAddOns = []);
413
+ });
414
+ }
415
+
416
+ function generateBill() {
417
+ fetchAddOns().then(() => {
418
+ fetch('/cart/checkout', {
419
+ method: 'POST',
420
+ headers: { 'Content-Type': 'application/json' },
421
+ body: JSON.stringify({})
422
+ })
423
+ .then(response => response.json())
424
+ .then(data => {
425
+ if (data.success) {
426
+ currentCart = data.cart;
427
+ menuItems = data.menu_items;
428
+ displayAnythingElse();
429
+ } else {
430
+ alert(data.error || data.message);
431
+ }
432
+ })
433
+ .catch(err => {
434
+ console.error('Error during checkout:', err);
435
+ alert('An error occurred. Please try again.');
436
+ });
437
+ });
438
+ }
439
+
440
+ function displayAnythingElse() {
441
+ const menuItemsContainer = document.getElementById('menuItems');
442
+ menuItemsContainer.innerHTML = '';
443
+ menuItems.forEach(item => {
444
+ const itemElement = document.createElement('div');
445
+ itemElement.className = 'menu-item';
446
+ itemElement.innerHTML = `
447
+ <img src="${item.Image1__c}" alt="${item.Name}" onerror="this.src='/static/placeholder.jpg';">
448
+ <div class="menu-item-details">
449
+ <strong>${item.Name}</strong>
450
+ <small>${item.Veg_NonVeg__c} | ${item.Section__c}</small>
451
+ <small>$${item.Price__c.toFixed(2)}</small>
452
+ </div>
453
+ <button class="add-back-button" onclick="showQuantitySelector('${item.Name}', ${item.Price__c}, '${item.Image1__c}', this)">+</button>
454
+ <div class="quantity-selector" data-item-name="${item.Name}">
455
+ <button onclick="updateMenuItemQuantity('${item.Name}', 'decrease')">-</button>
456
+ <input type="text" value="1" readonly data-item-name="${item.Name}">
457
+ <button onclick="updateMenuItemQuantity('${item.Name}', 'increase')">+</button>
458
+ </div>
459
+ <div class="customization-section" data-item-name="${item.Name}">
460
+ <h4>Customize ${item.Name}</h4>
461
+ <div id="addOns-${item.Name}">
462
+ ${availableAddOns.length > 0 ? availableAddOns.map(addon => `
463
+ <label>
464
+ <input type="checkbox" value="${addon.name}" data-price="${addon.price}">
465
+ ${addon.name}
466
+ </label>
467
+ `).join('') : '<p>No add-ons available</p>'}
468
+ </div>
469
+ <div>
470
+ <strong>Special Instructions</strong>
471
+ <textarea placeholder="e.g., Less spicy"></textarea>
472
+ </div>
473
+ <div class="customization-actions">
474
+ <button class="add-to-cart-btn" onclick="addToCartWithCustomizations('${item.Name}', ${item.Price__c}, '${item.Image1__c}')">Add to Cart</button>
475
+ <button class="cancel-customization-btn" onclick="cancelCustomization('${item.Name}')">Cancel</button>
476
+ </div>
477
+ </div>
478
+ `;
479
+ menuItemsContainer.appendChild(itemElement);
480
+ });
481
+ document.getElementById('anythingElseModal').style.display = 'flex';
482
+ }
483
+
484
+ function showQuantitySelector(itemName, itemPrice, itemImage, buttonElement) {
485
+ document.querySelectorAll('.quantity-selector').forEach(selector => {
486
+ selector.style.display = 'none';
487
+ selector.querySelector('input').value = 1;
488
+ });
489
+ document.querySelectorAll('.customization-section').forEach(section => {
490
+ section.classList.remove('show');
491
+ section.querySelectorAll('input[type="checkbox"]').forEach(checkbox => {
492
+ checkbox.checked = false;
493
+ });
494
+ section.querySelector('textarea').value = '';
495
+ });
496
+ document.querySelectorAll('.add-back-button').forEach(btn => {
497
+ btn.style.display = 'inline-block';
498
+ });
499
+
500
+ const quantitySelector = buttonElement.nextElementSibling;
501
+ quantitySelector.style.display = 'flex';
502
+ buttonElement.style.display = 'none';
503
+
504
+ const customizationSection = quantitySelector.nextElementSibling;
505
+ customizationSection.classList.add('show');
506
+
507
+ selectedItem = { name: itemName, price: itemPrice, image: itemImage };
508
+ }
509
+
510
+ function updateMenuItemQuantity(itemName, action) {
511
+ const quantityInput = document.querySelector(`.quantity-selector[data-item-name="${itemName}"] input`);
512
+ let quantity = parseInt(quantityInput.value);
513
+ if (action === 'increase') {
514
+ quantity++;
515
+ } else if (action === 'decrease' && quantity > 1) {
516
+ quantity--;
517
+ }
518
+ if (isNaN(quantity) || quantity < 1) {
519
+ quantity = 1;
520
+ }
521
+ quantityInput.value = quantity;
522
+ }
523
+
524
+ function cancelCustomization(itemName) {
525
+ const quantitySelector = document.querySelector(`.quantity-selector[data-item-name="${itemName}"]`);
526
+ const customizationSection = quantitySelector.nextElementSibling;
527
+ const addButton = quantitySelector.previousElementSibling;
528
+
529
+ quantitySelector.querySelector('input').value = 1;
530
+ quantitySelector.style.display = 'none';
531
+ customizationSection.classList.remove('show');
532
+ addButton.style.display = 'inline-block';
533
+ customizationSection.querySelectorAll('input[type="checkbox"]').forEach(checkbox => {
534
+ checkbox.checked = false;
535
+ });
536
+ customizationSection.querySelector('textarea').value = '';
537
+ }
538
+
539
+ function addToCartWithCustomizations(itemName, itemPrice, itemImage) {
540
+ const quantitySelector = document.querySelector(`.quantity-selector[data-item-name="${itemName}"]`);
541
+ const quantity = parseInt(quantitySelector.querySelector('input').value);
542
+ if (isNaN(quantity) || quantity < 1) {
543
+ alert('Invalid quantity!');
544
+ return;
545
+ }
546
+ const customizationSection = document.querySelector(`.customization-section[data-item-name="${itemName}"]`);
547
+ const addOns = Array.from(customizationSection.querySelectorAll('input[type="checkbox"]:checked')).map(checkbox => checkbox.value);
548
+ const instructions = customizationSection.querySelector('textarea').value.trim();
549
+ const customerEmail = "{{ customer_email }}";
550
+
551
+ const data = {
552
+ item_name: itemName,
553
+ item_price: itemPrice,
554
+ item_image: itemImage,
555
+ addons: addOns,
556
+ instructions: instructions,
557
+ customer_email: customerEmail,
558
+ quantity: quantity
559
+ };
560
+
561
+ fetch('/cart/add_suggestion_to_cart', {
562
+ method: 'POST',
563
+ headers: { 'Content-Type': 'application/json' },
564
+ body: JSON.stringify(data)
565
+ })
566
+ .then(response => response.json())
567
+ .then(data => {
568
+ if (data.success) {
569
+ alert('Item added to cart!');
570
+ closeAnythingElseModal();
571
+ refreshBill();
572
+ } else {
573
+ alert('Error adding item to cart: ' + data.error);
574
+ }
575
+ })
576
+ .catch(err => {
577
+ console.error('Error adding item:', err);
578
+ alert('An error occurred while adding the item to the cart.');
579
+ });
580
+ }
581
+
582
+ function refreshBill() {
583
+ fetch('/bill/fetch_cart', {
584
+ method: 'GET',
585
+ headers: { 'Content-Type': 'application/json' }
586
+ })
587
+ .then(response => response.json())
588
+ .then(data => {
589
+ if (data.success) {
590
+ const billContainer = document.querySelector('.bill-container');
591
+ billContainer.innerHTML = '';
592
+ data.cart_items.forEach(item => {
593
+ const itemElement = document.createElement('div');
594
+ itemElement.className = 'bill-item';
595
+ itemElement.innerHTML = `
596
+ <div class="image-wrapper">
597
+ <img src="${item.Image1__c}" alt="${item.Name}" onerror="this.src='/static/placeholder.jpg';">
598
+ </div>
599
+ <div class="bill-item-details">
600
+ <div class="bill-item-title">${item.Name} x${item.Quantity__c}</div>
601
+ <div class="bill-item-addons">
602
+ <small class="text-muted">Add-ons: ${item.Add_Ons__c}</small>
603
+ </div>
604
+ <div class="bill-item-instructions">
605
+ <small class="text-muted">Instructions: ${item.Instructions__c || "None"}</small>
606
+ </div>
607
+ </div>
608
+ <div class="text-primary">$${item.Price__c.toFixed(2)}</div>
609
+ `;
610
+ billContainer.appendChild(itemElement);
611
+ });
612
+ if (data.cart_items.length === 0) {
613
+ billContainer.innerHTML = '<p>No items in your bill.</p>';
614
+ }
615
+ const summaryElement = document.createElement('div');
616
+ summaryElement.className = 'bill-summary';
617
+ summaryElement.innerHTML = `
618
+ <div class="bill-details">
619
+ <div class="label">Subtotal</div>
620
+ <div class="amount">$${data.subtotal.toFixed(2)}</div>
621
+ </div>
622
+ <div class="dotted-line"></div>
623
+ <div class="total-bill">
624
+ <div class="label">Total</div>
625
+ <div class="amount">$${data.subtotal.toFixed(2)}</div>
626
+ </div>
627
+ <button class="generate-bill-button" onclick="generateBill()">Generate Bill</button>
628
+ <button class="confirm-order-button" onclick="confirmOrder()">Confirm Order</button>
629
+ `;
630
+ billContainer.appendChild(summaryElement);
631
+ closeAnythingElseModal();
632
+ } else {
633
+ alert('Error refreshing bill: ' + data.error);
634
+ }
635
+ })
636
+ .catch(err => {
637
+ console.error('Error refreshing bill:', err);
638
+ alert('An error occurred while refreshing the bill.');
639
+ });
640
+ }
641
+
642
+ function closeAnythingElseModal() {
643
+ document.getElementById('anythingElseModal').style.display = 'none';
644
+ document.querySelectorAll('.quantity-selector').forEach(selector => {
645
+ selector.style.display = 'none';
646
+ selector.querySelector('input').value = 1;
647
+ });
648
+ document.querySelectorAll('.customization-section').forEach(section => {
649
+ section.classList.remove('show');
650
+ section.querySelectorAll('input[type="checkbox"]').forEach(checkbox => {
651
+ checkbox.checked = false;
652
+ });
653
+ section.querySelector('textarea').value = '';
654
+ });
655
+ document.querySelectorAll('.add-back-button').forEach(btn => {
656
+ btn.style.display = 'inline-block';
657
+ });
658
+ }
659
+
660
+ function confirmOrder() {
661
+ fetch('/cart/checkout', {
662
+ method: 'POST',
663
+ headers: { 'Content-Type': 'application/json' },
664
+ body: JSON.stringify({})
665
+ })
666
+ .then(response => response.json())
667
+ .then(data => {
668
+ if (data.success) {
669
+ currentCart = data.cart;
670
+ fetch('/cart/submit_order', {
671
+ method: 'POST',
672
+ headers: { 'Content-Type': 'application/json' },
673
+ body: JSON.stringify({ cart: currentCart })
674
+ })
675
+ .then(response => response.json())
676
+ .then(data => {
677
+ if (data.success) {
678
+ alert(data.message);
679
+ window.location.href = '/order';
680
+ } else {
681
+ alert(data.error || data.message);
682
+ }
683
+ })
684
+ .catch(err => {
685
+ console.error('Error during order submission:', err);
686
+ alert('An error occurred during order submission.');
687
+ });
688
+ } else {
689
+ alert(data.error || data.message);
690
+ }
691
+ })
692
+ .catch(err => {
693
+ console.error('Error during checkout:', err);
694
+ alert('An error occurred. Please try again.');
695
+ });
696
+ }
697
+ </script>
698
+ </body>
699
+ </html>