File size: 8,560 Bytes
cd2c91d
7547860
 
a64ad00
 
087584b
 
a64ad00
087584b
a64ad00
 
087584b
a64ad00
 
 
087584b
 
 
 
 
 
 
 
 
 
 
 
 
 
a64ad00
087584b
 
a64ad00
087584b
a64ad00
087584b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a64ad00
 
 
 
 
087584b
 
 
a64ad00
087584b
 
 
 
a64ad00
 
 
087584b
 
a64ad00
087584b
a64ad00
087584b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0ab6add
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
087584b
 
 
 
 
 
 
 
 
 
 
 
 
a64ad00
0ab6add
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a64ad00
316469c
 
b0082be
087584b
 
 
 
 
 
 
0ab6add
 
 
 
 
 
 
 
087584b
0ab6add
 
 
 
 
 
 
 
 
 
 
a64ad00
0ab6add
 
 
 
 
 
a64ad00
 
087584b
 
 
 
 
 
 
 
 
 
a64ad00
 
087584b
 
 
 
a64ad00
087584b
 
a64ad00
 
087584b
0ab6add
 
087584b
 
 
 
 
a64ad00
087584b
 
a64ad00
087584b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a64ad00
 
087584b
a64ad00
087584b
 
 
 
 
 
 
 
a64ad00
087584b
a64ad00
0ab6add
 
 
 
 
 
 
a64ad00
 
087584b
 
 
 
 
 
 
 
 
a64ad00
0ab6add
 
 
 
 
 
 
 
 
 
 
 
a64ad00
4caeded
316469c
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Menu Page</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
    <style>
        /* Basic Styles */
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            padding: 0;
        }

        header {
            background-color: #333;
            color: white;
            padding: 15px;
            text-align: center;
        }

        .menu-container {
            margin: 20px;
        }

        .menu-category {
            margin-bottom: 20px;
        }

        .menu-category h2 {
            text-align: center;
            font-size: 24px;
        }

        .menu-item {
            background-color: white;
            padding: 10px;
            margin-bottom: 10px;
            border-radius: 5px;
            box-shadow: 0px 2px 5px rgba(0, 0, 0, 0.1);
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .menu-item h3 {
            margin: 0;
            font-size: 20px;
        }

        .menu-item p {
            margin: 0;
            font-size: 16px;
            color: #888;
        }

        .menu-item button {
            padding: 8px 12px;
            background-color: #28a745;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
        }

        .menu-item button:hover {
            background-color: #218838;
        }

        .cart-button {
            padding: 12px 20px;
            background-color: #007bff;
            color: white;
            border: none;
            border-radius: 5px;
            text-align: center;
            font-size: 18px;
            cursor: pointer;
            width: 100%;
        }

        .cart-button:hover {
            background-color: #0056b3;
        }

        .cart-icon {
            margin-right: 8px;
        }

        footer {
            text-align: center;
            padding: 10px;
            background-color: #333;
            color: white;
            position: fixed;
            width: 100%;
            bottom: 0;
        }

        .order-summary {
            margin: 20px;
            padding: 20px;
            background-color: white;
            border-radius: 5px;
            box-shadow: 0px 2px 5px rgba(0, 0, 0, 0.1);
        }

        .order-summary h3 {
            font-size: 24px;
            text-align: center;
        }

        .order-summary ul {
            list-style-type: none;
            padding: 0;
        }

        .order-summary li {
            padding: 10px;
            border-bottom: 1px solid #ddd;
            display: flex;
            justify-content: space-between;
        }

        .order-summary button {
            padding: 10px 20px;
            background-color: #007bff;
            color: white;
            border: none;
            border-radius: 5px;
            font-size: 18px;
            cursor: pointer;
        }

        .order-summary button:hover {
            background-color: #0056b3;
        }

        .cart-summary {
            display: flex;
            justify-content: space-between;
            margin-top: 20px;
        }

        .cart-summary span {
            font-size: 18px;
            font-weight: bold;
        }

        .cart-summary button {
            background-color: #28a745;
        }

        .logout-button {
            padding: 12px 20px;
            background-color: #dc3545;
            color: white;
            border: none;
            border-radius: 5px;
            font-size: 18px;
            cursor: pointer;
            width: 100%;
            margin-top: 20px;
        }

        .logout-button:hover {
            background-color: #c82333;
        }
    </style>
</head>
<body>

    <!-- Header -->
    <header>
        <h1>Welcome to Our Restaurant</h1>
    </header>

    <!-- Menu Content -->
    <div class="menu-container">
        <!-- Main Course Category -->
        <div class="menu-category">
            <h2>Main Course</h2>
            {% for item in menu_items %}
                <div class="menu-item">
                    <div>
                        <h3>{{ item.name }}</h3>
                        <p>Price: ₹{{ item.price }}</p>
                    </div>
                    <button onclick="addToCart('{{ item.name }}', {{ item.price }}, '{{ item.category }}')">Add to Cart</button>
                </div>
            {% endfor %}
        </div>

        <!-- Cart Button -->
        <div class="menu-category">
            <button class="cart-button" onclick="showCart()">
                <i class="fas fa-shopping-cart cart-icon"></i> View Cart
            </button>
        </div>

        <!-- Logout Button -->
        <div class="menu-category">
            <button class="logout-button" onclick="logout()">
                <i class="fas fa-sign-out-alt cart-icon"></i> Logout
            </button>
        </div>
    </div>

    <!-- Cart Summary (hidden initially) -->
    <div id="cart-summary" class="order-summary" style="display:none;">
        <h3>Your Cart</h3>
        <ul id="cart-items-list">
            <!-- Cart items will be dynamically listed here -->
        </ul>
        <div class="cart-summary">
            <span>Total: ₹<span id="total-price">0</span></span>
            <button onclick="placeOrder()">Place Order</button>
        </div>
    </div>

    <!-- Footer -->
    <footer>
        <p>Restaurant &copy; 2025</p>
    </footer>

    <!-- JavaScript -->
    <script>
        let cart = [];

        // Add item to cart
        function addToCart(itemName, itemPrice, itemCategory) {
            cart.push({ name: itemName, price: itemPrice, category: itemCategory });
            alert(`${itemName} added to cart!`);
        }

        // Show cart and order summary
        function showCart() {
            if (cart.length === 0) {
                alert("Your cart is empty!");
                return;
            }

            // Update cart items list
            const cartItemsList = document.getElementById('cart-items-list');
            cartItemsList.innerHTML = '';

            let totalPrice = 0;

            cart.forEach(item => {
                const li = document.createElement('li');
                li.innerHTML = `${item.name} - ₹${item.price}`;
                cartItemsList.appendChild(li);
                totalPrice += item.price;
            });

            // Update total price
            document.getElementById('total-price').textContent = totalPrice;

            // Show cart summary
            document.getElementById('cart-summary').style.display = 'block';
        }

        // Place the order
        function placeOrder() {
            if (cart.length === 0) {
                alert("Your cart is empty, cannot place the order.");
                return;
            }

            // Send the order to the backend (POST request)
            fetch('/order', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify({
                    customer_id: "user-id-placeholder", // Replace with actual user ID if necessary
                    items: cart.map(item => ({
                        item_id: item.name,
                        quantity: 1, // Assuming quantity is 1 for now
                    }))
                })
            })
            .then(response => response.json())
            .then(data => {
                alert(data.message);
                cart = [];  // Clear cart after placing the order
                document.getElementById('cart-summary').style.display = 'none';  // Hide cart summary
            })
            .catch(error => {
                console.error('Error:', error);
                alert('Error placing order');
            });
        }

        // Logout
        function logout() {
            fetch('/logout')
                .then(response => {
                    window.location.href = "/";  // Redirect to home page after logout
                })
                .catch(error => {
                    console.error('Error:', error);
                    alert('Error logging out');
                });
        }
    </script>

</body>
</html>