Repository navigation
Expand file tree
/
Copy pathPyRestaurant.py
More file actions
485 lines (457 loc) · 20.6 KB
/
Copy pathPyRestaurant.py
File metadata and controls
485 lines (457 loc) · 20.6 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
import sys
from PyQt6.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QWidget, QLabel, QPushButton, QListWidget, QLineEdit, QComboBox, QMessageBox, QSpinBox, QStyle, QTabWidget, QHBoxLayout
from PyQt6.QtCore import Qt
from PyQt6.QtGui import QIcon
import database
class RestaurantApp(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("PyRestaurant Management System")
self.setGeometry(100, 100, 800, 600)
self.setWindowIcon(QIcon("images/restaurant.png"))
self.conn = database.create_connection("restaurant.db")
if self.conn:
database.create_tables(self.conn)
self.selected_menu_id = None
self.central_widget = QWidget()
self.setCentralWidget(self.central_widget)
self.layout = QVBoxLayout(self.central_widget)
title_layout = QHBoxLayout()
icon_label = QLabel()
from PyQt6.QtGui import QPixmap
pixmap = QPixmap("images/order.png")
icon_label.setPixmap(pixmap.scaled(32, 32, Qt.AspectRatioMode.KeepAspectRatio, Qt.TransformationMode.SmoothTransformation))
title_layout.addWidget(icon_label)
self.title_label = QLabel("Welcome to PyRestaurant!")
self.title_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.title_label.setStyleSheet("font-size: 24px; font-weight: bold;")
title_layout.addWidget(self.title_label)
title_layout.addStretch()
self.layout.addLayout(title_layout)
self.description_label = QLabel("Welcome to PyRestaurant Management System.\nPlease select your interface to continue.")
self.description_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.description_label.setStyleSheet("font-size: 18px; color: #1b5e20; margin: 20px;")
self.layout.addWidget(self.description_label)
self.interface_label = QLabel("Select Interface:")
self.layout.addWidget(self.interface_label)
self.interface_combo = QComboBox()
self.interface_combo.addItems(["Customer", "Staff/Manager"])
self.interface_combo.setCurrentIndex(-1)
self.interface_combo.currentTextChanged.connect(self.switch_interface)
self.interface_combo.setStyleSheet("font-size: 25px; font-weight: bold;")
self.layout.addWidget(self.interface_combo)
self.customer_widget = QWidget()
self.customer_layout = QVBoxLayout(self.customer_widget)
self.menu_list = QListWidget()
self.customer_layout.addWidget(QLabel("Menu:"))
self.customer_layout.addWidget(self.menu_list)
self.quantity_spin = QSpinBox()
self.quantity_spin.setMinimum(1)
self.quantity_spin.setStyleSheet("font-size: 25px; font-weight: bold;")
self.customer_layout.addWidget(QLabel("Quantity:"))
self.customer_layout.addWidget(self.quantity_spin)
self.order_button = QPushButton("Place Order")
self.order_button.clicked.connect(self.place_order)
self.customer_layout.addWidget(self.order_button)
self.customer_widget.setVisible(False)
self.layout.addWidget(self.customer_widget)
self.staff_widget = QWidget()
self.staff_layout = QVBoxLayout(self.staff_widget)
self.tab_widget = QTabWidget()
self.tab_widget.addTab(self.create_orders_tab(), "Orders")
self.tab_widget.addTab(self.create_menu_tab(), "Menu Management")
self.tab_widget.addTab(self.create_reports_tab(), "Reports")
self.staff_layout.addWidget(self.tab_widget)
self.staff_widget.setVisible(False)
self.layout.addWidget(self.staff_widget)
self.menu_bar = self.menuBar()
help_menu = self.menu_bar.addMenu("Help")
about_action = help_menu.addAction("About")
about_action.triggered.connect(self.show_about)
self.load_menu()
self.setStyleSheet("""
QMainWindow {
background-color: #f1f8e9;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
QLabel {
font-size: 20px;
color: #1b5e20;
font-weight: 600;
}
QPushButton {
background-color: #4caf50;
color: white;
border: none;
padding: 12px 24px;
border-radius: 10px;
font-size: 14px;
font-weight: bold;
min-width: 100px;
}
QPushButton:hover {
background-color: #388e3c;
transform: scale(1.05);
}
QPushButton:pressed {
background-color: #2e7d32;
}
QListWidget {
background-color: white;
border: 2px solid #4caf50;
border-radius: 10px;
padding: 10px;
font-size: 25px;
}
QListWidget::item {
padding: 8px;
border-bottom: 1px solid #e8f5e8;
color: black;
font-size: 25px;
}
QListWidget::item:selected {
background-color: #c8e6c9;
color: #1b5e20;
font-weight: bold;
}
QLineEdit, QComboBox, QSpinBox {
padding: 10px;
border: 2px solid #4caf50;
border-radius: 8px;
background-color: white;
color: black;
font-size: 14px;
}
QLineEdit:focus, QComboBox:focus, QSpinBox:focus {
border-color: #1b5e20;
box-shadow: 0 0 5px rgba(76, 175, 80, 0.5);
}
QComboBox::drop-down {
border: none;
background-color: #4caf50;
width: 20px;
}
QComboBox::down-arrow {
color: white;
width: 10px;
height: 10px;
}
QSpinBox::up-button, QSpinBox::down-button {
background-color: #4caf50;
border: none;
width: 20px;
}
QSpinBox::up-arrow, QSpinBox::down-arrow {
color: white;
width: 8px;
height: 8px;
}
QTabWidget::pane {
border: 2px solid #4caf50;
border-radius: 10px;
background-color: white;
}
QTabBar::tab {
background-color: #e8f5e8;
color: #1b5e20;
padding: 12px 24px;
border: 1px solid #4caf50;
border-bottom: none;
border-radius: 10px 10px 0 0;
font-weight: bold;
font-size: 14px;
}
QTabBar::tab:selected {
background-color: white;
color: #1b5e20;
}
QTabBar::tab:hover {
background-color: #c8e6c9;
}
QMenuBar {
background-color: #4caf50;
color: white;
font-size: 14px;
}
QMenuBar::item {
background-color: transparent;
padding: 8px 16px;
}
QMenuBar::item:selected {
background-color: #388e3c;
}
""")
def show_about(self):
about_text = """
<h2>PyRestaurant Management System</h2>
<p><b>Version:</b> 1.0.0</p>
<p><b>Developed by:</b> ahmetcakir-dev</p>
<p>This application is designed to manage restaurant orders, menu items, and sales reports efficiently.</p>
"""
QMessageBox.about(self, "About PyRestaurant", about_text)
def create_orders_tab(self):
widget = QWidget()
layout = QVBoxLayout(widget)
self.orders_list = QListWidget()
self.orders_list.setStyleSheet("""
QListWidget::item {
color: black;
}
""")
layout.addWidget(QLabel("Orders:"))
layout.addWidget(self.orders_list)
self.update_status_button = QPushButton("Update Status")
self.update_status_button.setIcon(self.style().standardIcon(QStyle.StandardPixmap.SP_ArrowRight))
self.update_status_button.setToolTip("Update the selected order status")
self.update_status_button.clicked.connect(self.update_order_status)
layout.addWidget(self.update_status_button)
self.status_combo = QComboBox()
self.status_combo.addItems(["Preparing", "Ready", "Completed"])
self.status_combo.setStyleSheet("font-size: 20px;")
layout.addWidget(QLabel("New Status:"))
layout.addWidget(self.status_combo)
self.status_combo.setStyleSheet("font-size: 25px; font-weight: bold;")
self.delete_order_button = QPushButton("Delete Order")
self.delete_order_button.setIcon(self.style().standardIcon(QStyle.StandardPixmap.SP_TrashIcon))
self.delete_order_button.setToolTip("Delete the selected order")
self.delete_order_button.clicked.connect(self.delete_order)
layout.addWidget(self.delete_order_button)
return widget
def create_menu_tab(self):
widget = QWidget()
layout = QVBoxLayout(widget)
self.staff_menu_list = QListWidget()
self.staff_menu_list.setStyleSheet("""
QListWidget::item {
color: black;
}
""")
layout.addWidget(QLabel("Current Menu:"))
layout.addWidget(self.staff_menu_list)
self.staff_menu_list.itemClicked.connect(self.select_menu_item)
layout.addWidget(QLabel("Menu Management:"))
self.name_input = QLineEdit()
self.name_input.setStyleSheet("font-size: 25px;")
layout.addWidget(QLabel("Item Name:"))
layout.addWidget(self.name_input)
self.price_input = QLineEdit()
self.price_input.setStyleSheet("font-size: 25px;")
layout.addWidget(QLabel("Price:"))
layout.addWidget(self.price_input)
button_layout = QHBoxLayout()
self.add_button = QPushButton("Add Item")
self.add_button.setIcon(self.style().standardIcon(QStyle.StandardPixmap.SP_FileIcon))
self.add_button.setToolTip("Add a new menu item")
self.add_button.clicked.connect(self.add_menu_item)
button_layout.addWidget(self.add_button)
self.edit_button = QPushButton("Edit Item")
self.edit_button.setIcon(self.style().standardIcon(QStyle.StandardPixmap.SP_FileDialogContentsView))
self.edit_button.setToolTip("Edit the selected menu item")
self.edit_button.clicked.connect(self.edit_menu_item)
button_layout.addWidget(self.edit_button)
self.delete_button = QPushButton("Delete Item")
self.delete_button.setIcon(self.style().standardIcon(QStyle.StandardPixmap.SP_TrashIcon))
self.delete_button.setToolTip("Delete the selected menu item")
self.delete_button.clicked.connect(self.delete_menu_item)
button_layout.addWidget(self.delete_button)
layout.addLayout(button_layout)
return widget
def create_reports_tab(self):
widget = QWidget()
layout = QVBoxLayout(widget)
self.view_reports_button = QPushButton("View Reports")
self.view_reports_button.setIcon(self.style().standardIcon(QStyle.StandardPixmap.SP_ComputerIcon))
self.view_reports_button.setToolTip("View sales reports")
self.view_reports_button.clicked.connect(self.view_reports)
layout.addWidget(self.view_reports_button)
layout.addStretch()
return widget
def switch_interface(self, interface):
if interface == "Customer":
self.customer_widget.setVisible(True)
self.staff_widget.setVisible(False)
self.description_label.setVisible(False)
elif interface == "Staff/Manager":
self.customer_widget.setVisible(False)
self.staff_widget.setVisible(True)
self.description_label.setVisible(False)
self.load_orders()
else:
self.customer_widget.setVisible(False)
self.staff_widget.setVisible(False)
self.description_label.setVisible(True)
def load_menu(self):
try:
if self.conn:
cursor = self.conn.cursor()
cursor.execute("SELECT name, price FROM menu ORDER BY name")
items = cursor.fetchall()
self.menu_list.clear()
for i in range(0, len(items), 100):
batch = items[i:i+100]
for item in batch:
self.menu_list.addItem(f"{item[0]} - {item[1]} €")
if hasattr(self, 'staff_menu_list'):
self.staff_menu_list.clear()
for i in range(0, len(items), 100):
batch = items[i:i+100]
for item in batch:
self.staff_menu_list.addItem(f"{item[0]} - {item[1]} €")
except Exception as e:
QMessageBox.critical(self, "Database Error", f"Failed to load menu: {str(e)}")
def place_order(self):
selected_item = self.menu_list.currentItem()
if selected_item:
quantity = self.quantity_spin.value()
name = selected_item.text().split(" - ")[0]
cursor = self.conn.cursor()
cursor.execute("SELECT id, price FROM menu WHERE name = ?", (name,))
item = cursor.fetchone()
if item:
menu_id, price = item
total = quantity * price
cursor.execute("INSERT INTO orders (menu_id, quantity) VALUES (?, ?)", (menu_id, quantity))
self.conn.commit()
order_id = cursor.lastrowid
QMessageBox.information(self, "Order", f"Order placed for {quantity} x {name}. Total: {total} €")
self.load_orders()
try:
from reportlab.pdfgen import canvas
from datetime import datetime
filename = f"receipt_{order_id}.pdf"
c = canvas.Canvas(filename)
c.drawString(100, 750, "PyRestaurant Receipt")
c.drawString(100, 730, f"Order ID: {order_id}")
c.drawString(100, 710, f"Date: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
c.drawString(100, 690, f"Item: {name}")
c.drawString(100, 670, f"Quantity: {quantity}")
c.drawString(100, 650, f"Price per item: {price} €")
c.drawString(100, 630, f"Total: {total} €")
c.drawString(100, 600, "Thank you for your order!")
c.save()
QMessageBox.information(self, "Receipt", f"PDF generated as {filename}")
except ImportError:
QMessageBox.warning(self, "Receipt", "ReportLab not installed, PDF not generated.")
else:
QMessageBox.warning(self, "Error", "Item not found!")
else:
QMessageBox.warning(self, "Warning", "Please select a dish!")
def load_orders(self):
try:
if self.conn:
cursor = self.conn.cursor()
cursor.execute("SELECT orders.id, menu.name, orders.quantity, orders.status FROM orders JOIN menu ON orders.menu_id = menu.id ORDER BY orders.id DESC")
orders = cursor.fetchall()
self.orders_list.clear()
for i in range(0, len(orders), 100):
batch = orders[i:i+100]
for order in batch:
self.orders_list.addItem(f"Order ID: {order[0]}, Item: {order[1]}, Qty: {order[2]}, Status: {order[3]}")
except Exception as e:
QMessageBox.critical(self, "Database Error", f"Failed to load orders: {str(e)}")
def update_order_status(self):
selected_order = self.orders_list.currentItem()
if selected_order:
order_id = int(selected_order.text().split(", ")[0].split(": ")[1])
new_status = self.status_combo.currentText()
cursor = self.conn.cursor()
cursor.execute("UPDATE orders SET status = ? WHERE id = ?", (new_status, order_id))
self.conn.commit()
self.load_orders()
QMessageBox.information(self, "Update", f"Status updated to {new_status}")
else:
QMessageBox.warning(self, "Warning", "Please select an order!")
def delete_order(self):
selected_order = self.orders_list.currentItem()
if selected_order:
order_id = int(selected_order.text().split(", ")[0].split(": ")[1])
reply = QMessageBox.question(self, "Delete Order", f"Are you sure you want to delete order {order_id}?", QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No)
if reply == QMessageBox.StandardButton.Yes:
cursor = self.conn.cursor()
cursor.execute("DELETE FROM orders WHERE id = ?", (order_id,))
self.conn.commit()
self.load_orders()
QMessageBox.information(self, "Success", "Order deleted!")
else:
QMessageBox.warning(self, "Warning", "Please select an order!")
def select_menu_item(self, item):
name = item.text().split(" - ")[0]
cursor = self.conn.cursor()
cursor.execute("SELECT id FROM menu WHERE name = ?", (name,))
result = cursor.fetchone()
if result:
self.selected_menu_id = result[0]
self.name_input.setText(name)
price = item.text().split(" - ")[1].replace(" €", "")
self.price_input.setText(price)
def add_menu_item(self):
name = self.name_input.text()
price = self.price_input.text()
if name and price:
try:
cursor = self.conn.cursor()
cursor.execute("INSERT INTO menu (name, price) VALUES (?, ?)", (name, float(price)))
self.conn.commit()
self.load_menu()
self.name_input.clear()
self.price_input.clear()
QMessageBox.information(self, "Success", "Item added to menu!")
except ValueError:
QMessageBox.warning(self, "Error", "Invalid price!")
else:
QMessageBox.warning(self, "Warning", "Enter name and price!")
def edit_menu_item(self):
if self.selected_menu_id is None:
QMessageBox.warning(self, "Warning", "Select an item to edit!")
return
name = self.name_input.text()
price = self.price_input.text()
if name and price:
try:
cursor = self.conn.cursor()
cursor.execute("UPDATE menu SET name = ?, price = ? WHERE id = ?", (name, float(price), self.selected_menu_id))
self.conn.commit()
self.load_menu()
self.name_input.clear()
self.price_input.clear()
self.selected_menu_id = None
QMessageBox.information(self, "Success", "Item updated!")
except ValueError:
QMessageBox.warning(self, "Error", "Invalid price!")
else:
QMessageBox.warning(self, "Warning", "Enter name and price!")
def delete_menu_item(self):
if self.selected_menu_id is None:
QMessageBox.warning(self, "Warning", "Select an item to delete!")
return
cursor = self.conn.cursor()
cursor.execute("DELETE FROM menu WHERE id = ?", (self.selected_menu_id,))
self.conn.commit()
self.load_menu()
self.name_input.clear()
self.price_input.clear()
self.selected_menu_id = None
QMessageBox.information(self, "Success", "Item deleted!")
def view_reports(self):
try:
import matplotlib.pyplot as plt
cursor = self.conn.cursor()
cursor.execute("SELECT menu.name, SUM(orders.quantity) FROM orders JOIN menu ON orders.menu_id = menu.id GROUP BY menu.id")
data = cursor.fetchall()
if data:
names = [row[0] for row in data]
quantities = [row[1] for row in data]
plt.bar(names, quantities)
plt.title("Sales Report")
plt.xlabel("Items")
plt.ylabel("Quantity Sold")
plt.show()
else:
QMessageBox.information(self, "Reports", "No orders yet!")
except ImportError:
QMessageBox.warning(self, "Error", "Matplotlib not installed!")
if __name__ == "__main__":
app = QApplication(sys.argv)
window = RestaurantApp()
window.showMaximized()
sys.exit(app.exec())