-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchef_interface.py
More file actions
87 lines (73 loc) · 3.44 KB
/
chef_interface.py
File metadata and controls
87 lines (73 loc) · 3.44 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
from tkinter import ttk, messagebox
import tkinter as tk
from common import get_db_connection
# Funzione per l'interfaccia dello chef
def chef_interface(clear_main_frame, main_frame, show_home):
def update_kitchen_orders():
kitchen_orders_list.delete(*kitchen_orders_list.get_children())
conn = get_db_connection()
cursor = conn.cursor()
# Query per calcolare G come tempo residuo
cursor.execute("""
SELECT o.id, p.nome, d.quantita, t.id, p.tempo_preparazione,
ROUND((p.tempo_preparazione * 1.2) - ((strftime('%s', 'now') - strftime('%s', o.data_ora)) / 60)) AS G
FROM DettagliOrdine d
JOIN Ordini o ON d.ordine_id = o.id
JOIN Tavoli t ON o.tavolo_id = t.id
JOIN Pietanze p ON d.pietanza_id = p.id
WHERE o.stato = 'in preparazione'
ORDER BY G ASC
""")
orders = cursor.fetchall()
for order in orders:
g_value = order[5]
row_color = "red" if g_value < 2 else "yellow" if g_value < 5 else "green"
kitchen_orders_list.insert("", "end", values=order, tags=(row_color,))
# Colori per evidenziare le criticità
kitchen_orders_list.tag_configure("red", background="#FFCCCC")
kitchen_orders_list.tag_configure("yellow", background="#FFFFCC")
kitchen_orders_list.tag_configure("green", background="#CCFFCC")
conn.close()
def mark_as_ready():
selected_items = kitchen_orders_list.selection()
if not selected_items:
messagebox.showwarning("Warning", "No orders selected to mark as ready.")
return
conn = get_db_connection()
cursor = conn.cursor()
for item in selected_items:
order_id = kitchen_orders_list.item(item, "values")[0]
cursor.execute("""
UPDATE Ordini
SET stato = 'pronto'
WHERE id = ?
""", (order_id,))
conn.commit()
conn.close()
update_kitchen_orders()
messagebox.showinfo("Success", "Selected orders marked as ready.")
clear_main_frame()
tk.Label(main_frame, text="Chef's Kitchen Interface", font=("Arial", 16, "bold")).pack(pady=10)
# Creazione della tabella
kitchen_orders_list = ttk.Treeview(
main_frame,
columns=("Order ID", "Dish", "Quantity", "Table", "Prep Time", "G"),
show="headings",
height=15
)
kitchen_orders_list.heading("Order ID", text="Order ID")
kitchen_orders_list.heading("Dish", text="Dish")
kitchen_orders_list.heading("Quantity", text="Qty")
kitchen_orders_list.heading("Table", text="Table")
kitchen_orders_list.heading("Prep Time", text="Prep Time (min)")
kitchen_orders_list.heading("G", text="G (min)")
kitchen_orders_list.column("Order ID", width=40, anchor="center")
kitchen_orders_list.column("Dish", width=110, anchor="center")
kitchen_orders_list.column("Quantity", width=40, anchor="center")
kitchen_orders_list.column("Table", width=40, anchor="center")
kitchen_orders_list.column("Prep Time", width=70, anchor="center")
kitchen_orders_list.column("G", width=70, anchor="center")
kitchen_orders_list.pack(padx=10, pady=10, fill="both", expand=True)
tk.Button(main_frame, text="Mark as Ready", command=mark_as_ready).pack(pady=10)
tk.Button(main_frame, text="Back to Home", command=show_home).pack(pady=10)
update_kitchen_orders()