60 lines
2.3 KiB
Python
60 lines
2.3 KiB
Python
import tkinter as tk
|
|
from tkinter import messagebox
|
|
from database import connect
|
|
|
|
class WaiterPage(tk.Frame):
|
|
def __init__(self, parent, controller):
|
|
super().__init__(parent)
|
|
self.controller = controller
|
|
|
|
# Header
|
|
top = tk.Frame(self, bg="#FF9800")
|
|
top.pack(fill="x")
|
|
tk.Label(top, text="WAITER DASHBOARD", font=("Arial", 16, "bold"), bg="#FF9800", fg="white").pack(side="left", padx=10, pady=10)
|
|
tk.Button(top, text="Logout", command=lambda: controller.show_frame("LoginPage")).pack(side="right", padx=10)
|
|
|
|
# List Pesanan
|
|
tk.Label(self, text="Pesanan Status: PENDING (Perlu Diantar)", font=("Arial", 12, "bold")).pack(pady=10)
|
|
|
|
self.list_orders = tk.Listbox(self, width=80, height=15, font=("Arial", 10))
|
|
self.list_orders.pack(pady=5)
|
|
|
|
btn_frame = tk.Frame(self)
|
|
btn_frame.pack(pady=10)
|
|
|
|
tk.Button(btn_frame, text="Refresh Data", command=self.update_data).pack(side="left", padx=5)
|
|
tk.Button(btn_frame, text="✅ Selesai Diantar (Served)", bg="#81C784", command=self.mark_served).pack(side="left", padx=5)
|
|
|
|
def update_data(self):
|
|
self.list_orders.delete(0, tk.END)
|
|
self.data_orders = []
|
|
|
|
db = connect()
|
|
cur = db.cursor()
|
|
# Ambil Transaksi yang statusnya Pending
|
|
cur.execute("SELECT id, nama_pelanggan, meja_id, total FROM transaksi WHERE status='Pending'")
|
|
self.data_orders = cur.fetchall()
|
|
db.close()
|
|
|
|
for item in self.data_orders:
|
|
# item: (id, nama, meja, total)
|
|
self.list_orders.insert(tk.END, f"ID Transaksi: {item[0]} | Meja: {item[2]} | A.N: {item[1]} | Total: Rp {int(item[3])}")
|
|
|
|
def mark_served(self):
|
|
idx = self.list_orders.curselection()
|
|
if not idx:
|
|
messagebox.showwarning("Pilih", "Pilih pesanan dulu!")
|
|
return
|
|
|
|
selected = self.data_orders[idx[0]]
|
|
transaksi_id = selected[0]
|
|
|
|
db = connect()
|
|
cur = db.cursor()
|
|
# Update Status Transaksi jadi Served
|
|
cur.execute("UPDATE transaksi SET status='Served' WHERE id=?", (transaksi_id,))
|
|
db.commit()
|
|
db.close()
|
|
|
|
messagebox.showinfo("Sukses", "Pesanan Meja selesai dilayani!")
|
|
self.update_data() |