129 lines
3.6 KiB
Python
129 lines
3.6 KiB
Python
import tkinter as tk
|
|
from tkinter import messagebox
|
|
from database import connect
|
|
|
|
class WaiterDashboard:
|
|
def __init__(self, parent):
|
|
self.parent = parent
|
|
self.frame = tk.Frame(parent)
|
|
self.frame.pack(fill="both", expand=True, padx=20, pady=10)
|
|
|
|
# =====================
|
|
# HEADER
|
|
# =====================
|
|
tk.Label(
|
|
self.frame,
|
|
text="DASHBOARD WAITER (DAPUR)",
|
|
font=("Arial", 18, "bold")
|
|
).pack(pady=10)
|
|
|
|
top_btn = tk.Frame(self.frame)
|
|
top_btn.pack(pady=5)
|
|
|
|
tk.Button(top_btn, text="Refresh Data", bg="#cfe2ff",
|
|
width=15, command=self.load_orders).grid(row=0, column=0, padx=5)
|
|
|
|
tk.Button(top_btn, text="Logout", bg="#f8d7da",
|
|
width=10, command=self.logout).grid(row=0, column=1, padx=5)
|
|
|
|
# =====================
|
|
# LIST PESANAN + SCROLL
|
|
# =====================
|
|
list_frame = tk.Frame(self.frame)
|
|
list_frame.pack(pady=10)
|
|
|
|
scrollbar = tk.Scrollbar(list_frame)
|
|
scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
|
|
|
|
self.listbox = tk.Listbox(
|
|
list_frame,
|
|
width=90,
|
|
height=15,
|
|
yscrollcommand=scrollbar.set
|
|
)
|
|
self.listbox.pack(side=tk.LEFT)
|
|
|
|
scrollbar.config(command=self.listbox.yview)
|
|
|
|
# =====================
|
|
# BUTTON VALIDASI
|
|
# =====================
|
|
tk.Button(
|
|
self.frame,
|
|
text="✔ Pesanan Selesai Disajikan",
|
|
bg="#d1e7dd",
|
|
font=("Arial", 11, "bold"),
|
|
width=30,
|
|
command=self.validasi_layanan
|
|
).pack(pady=10)
|
|
|
|
self.order_ids = []
|
|
self.load_orders()
|
|
|
|
# =====================
|
|
# LOAD DATA
|
|
# =====================
|
|
def load_orders(self):
|
|
self.listbox.delete(0, tk.END)
|
|
self.order_ids = []
|
|
|
|
db = connect()
|
|
cur = db.cursor()
|
|
|
|
cur.execute(
|
|
"SELECT id, meja_id, total FROM transaksi WHERE status='Pending'"
|
|
)
|
|
rows = cur.fetchall()
|
|
|
|
for t_id, meja, total in rows:
|
|
cur.execute(
|
|
"SELECT menu_nama, jumlah FROM detail_transaksi WHERE transaksi_id=?",
|
|
(t_id,)
|
|
)
|
|
details = cur.fetchall()
|
|
|
|
self.listbox.insert(tk.END, f"Meja {meja} | ID Transaksi: {t_id}")
|
|
for menu, qty in details:
|
|
self.listbox.insert(tk.END, f" - {menu} x{qty}")
|
|
|
|
self.listbox.insert(tk.END, f"Total : Rp {total:,.0f}")
|
|
self.listbox.insert(tk.END, "-" * 70)
|
|
|
|
self.order_ids.append(t_id)
|
|
|
|
db.close()
|
|
|
|
# =====================
|
|
# VALIDASI
|
|
# =====================
|
|
def validasi_layanan(self):
|
|
idx = self.listbox.curselection()
|
|
if not idx:
|
|
messagebox.showwarning("Pilih", "Pilih pesanan yang sudah disajikan")
|
|
return
|
|
|
|
# Cari ID terdekat ke atas
|
|
selected_index = idx[0]
|
|
transaksi_index = selected_index // 5
|
|
transaksi_id = self.order_ids[transaksi_index]
|
|
|
|
db = connect()
|
|
cur = db.cursor()
|
|
cur.execute(
|
|
"UPDATE transaksi SET status='Disajikan' WHERE id=?",
|
|
(transaksi_id,)
|
|
)
|
|
db.commit()
|
|
db.close()
|
|
|
|
messagebox.showinfo(
|
|
"Sukses",
|
|
"Pesanan ditandai selesai.\nKasir bisa memproses pembayaran."
|
|
)
|
|
self.load_orders()
|
|
|
|
def logout(self):
|
|
self.frame.destroy()
|
|
from main import LoginScreen
|
|
LoginScreen(self.parent)
|