-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpayment_interface.py
More file actions
104 lines (85 loc) · 4.07 KB
/
payment_interface.py
File metadata and controls
104 lines (85 loc) · 4.07 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
from tkinter import ttk, messagebox
import tkinter as tk
from common import get_db_connection
def payment_interface(clear_main_frame, main_frame, show_home, table_id):
"""Interfaccia di pagamento per gestire il riepilogo degli ordini e applicare sconti."""
clear_main_frame()
conn = get_db_connection()
cursor = conn.cursor()
# Recupera gli ordini per il tavolo specifico
cursor.execute("""
SELECT p.nome, d.quantita, d.prezzo_totale
FROM DettagliOrdine d
JOIN Ordini o ON d.ordine_id = o.id
JOIN Pietanze p ON d.pietanza_id = p.id
WHERE o.tavolo_id = ? AND o.stato = 'consegnato'
""", (table_id,))
orders = cursor.fetchall()
conn.close()
# Variabile per gestire il totale aggiornato
total_var = tk.DoubleVar(value=sum(order[2] for order in orders))
# Aggiorna il totale al cambio degli sconti
def update_total():
"""Aggiorna il totale detraendo il costo degli articoli selezionati."""
selected_items = payment_list.selection()
if not selected_items:
messagebox.showwarning("Warning", "No items selected for discount.")
return
# Calcola il nuovo totale sottraendo gli articoli selezionati
updated_total = total_var.get()
for item in selected_items:
values = payment_list.item(item, "values")
updated_total -= float(values[2]) # Sottrae il prezzo totale dell'articolo
total_var.set(updated_total)
# Rimuove gli articoli scontati dalla lista
for item in selected_items:
payment_list.delete(item)
messagebox.showinfo("Success", "Discount applied successfully!")
# Conferma il pagamento e libera il tavolo
def confirm_payment():
with get_db_connection() as conn:
cursor = conn.cursor()
try:
# Elimina tutti gli ordini associati al tavolo
cursor.execute("""
DELETE FROM DettagliOrdine
WHERE ordine_id IN (
SELECT id FROM Ordini WHERE tavolo_id = ?
)
""", (table_id,))
cursor.execute("""
DELETE FROM Ordini
WHERE tavolo_id = ?
""", (table_id,))
# Imposta lo stato del tavolo su "libero"
cursor.execute("""
UPDATE Tavoli
SET stato = 'libero', customer_name = 'N/A', cameriere_id = 'N/A'
WHERE id = ?
""", (table_id,))
conn.commit()
messagebox.showinfo("Success", f"Payment processed for Table {table_id}. The table is now free.")
show_home()
except Exception as e:
conn.rollback()
messagebox.showerror("Error", f"Failed to process payment: {e}")
tk.Label(main_frame, text=f"Payment Interface - Table {table_id}", font=("Arial", 16, "bold")).pack(pady=10)
# Lista degli ordini
payment_list = ttk.Treeview(main_frame, columns=("Dish", "Quantity", "Total Price"), show="headings", height=10)
payment_list.heading("Dish", text="Dish")
payment_list.heading("Quantity", text="Quantity")
payment_list.heading("Total Price", text="Total Price")
payment_list.pack(padx=10, pady=10, fill="both", expand=True)
for order in orders:
payment_list.insert("", "end", values=order)
# Mostra il totale
total_frame = tk.Frame(main_frame)
total_frame.pack(pady=5, fill="x")
tk.Label(total_frame, text="Total:", font=("Arial", 14)).pack(side="left", padx=10)
tk.Label(total_frame, textvariable=total_var, font=("Arial", 14, "bold")).pack(side="left")
# Bottoni di controllo
button_frame = tk.Frame(main_frame)
button_frame.pack(pady=10)
tk.Button(button_frame, text="Apply Discount", command=update_total).pack(side="left", padx=5)
tk.Button(button_frame, text="Confirm Payment", command=confirm_payment).pack(side="left", padx=5)
tk.Button(button_frame, text="Back to Home", command=show_home).pack(side="left", padx=5)