import tkinter as tk from tkinter import messagebox from database import connect class KasirPage: def __init__(self, parent, controller): self.parent = parent self.frame = tk.Frame(parent) self.frame.pack(fill="both", expand=True) tk.Label(self.frame, text="KASIR - PEMBAYARAN", font=("Arial", 18, "bold")).pack(pady=10) tk.Button(self.frame, text="Logout", bg="#f9e79f", command=self.logout).pack(pady=5) tk.Button(self.frame, text="Refresh", command=self.load_tagihan).pack() tk.Label(self.frame, text="Daftar Tagihan (Status: Disajikan):", font=("Arial", 12)).pack(pady=5) self.listbox = tk.Listbox(self.frame, width=60, height=10) self.listbox.pack(pady=5) tk.Button(self.frame, text="Proses Pembayaran", bg="#d1e7dd", command=self.bayar).pack(pady=5) self.transaksi_data = [] self.load_tagihan() def load_tagihan(self): self.listbox.delete(0, tk.END) self.transaksi_data = [] db = connect() cur = db.cursor() # Kasir hanya melihat yang sudah disajikan waiter cur.execute("SELECT id, meja_id, total FROM transaksi WHERE status='Disajikan'") rows = cur.fetchall() db.close() for row in rows: t_id, meja, total = row self.listbox.insert(tk.END, f"Meja {meja} - ID Transaksi: {t_id} - Total: Rp {total:,.0f}") self.transaksi_data.append(row) def bayar(self): idx = self.listbox.curselection() if not idx: messagebox.showwarning("Pilih", "Pilih tagihan yang akan dibayar!") return t_id, meja, total = self.transaksi_data[idx[0]] # Konfirmasi pembayaran confirm = messagebox.askyesno("Konfirmasi", f"Bayar tagihan Meja {meja} sebesar Rp {total:,.0f}?") if confirm: db = connect() cur = db.cursor() # Ubah status menjadi Lunas cur.execute("UPDATE transaksi SET status='Lunas' WHERE id=?", (t_id,)) db.commit() db.close() messagebox.showinfo("Sukses", "Pembayaran Berhasil! Struk dicetak.") self.load_tagihan() def logout(self): self.frame.destroy() from main import LoginScreen LoginScreen(self.parent)