import tkinter as tk from tkinter import messagebox from database import connect class KasirPage: def __init__(self, parent, controller): self.parent = parent self.controller = controller self.frame = tk.Frame(parent) self.frame.pack(fill="both", expand=True) tk.Label(self.frame, text="KASIR PAGE", font=("Arial", 18, "bold")).pack(pady=10) # Tombol Logout tk.Button(self.frame, text="Logout", bg="#f9e79f", command=self.logout).pack(pady=5) # Listbox untuk menampilkan order tk.Label(self.frame, text="Daftar Order:", font=("Arial", 12, "bold")).pack(pady=5) self.listbox = tk.Listbox(self.frame, width=50, height=10) self.listbox.pack(pady=5) # Tombol bayar tk.Button(self.frame, text="Bayar", bg="#d1e7dd", command=self.bayar).pack(pady=5) self.load_orders() # Load order dari database saat awal def load_orders(self): self.listbox.delete(0, tk.END) db = connect() cur = db.cursor() cur.execute("SELECT id, nama, harga FROM orders") self.data = cur.fetchall() db.close() for order in self.data: self.listbox.insert(tk.END, f"ID {order[0]}: {order[1]} - Rp {order[2]:,}") def bayar(self): idx = self.listbox.curselection() if not idx: messagebox.showwarning("Pilih Order", "Pilih order yang ingin dibayar!") return order = self.data[idx[0]] order_id, nama, total = order # Simpan pembayaran di database (opsional, bisa buat tabel pembayaran) db = connect() cur = db.cursor() cur.execute("INSERT INTO pembayaran VALUES (NULL, ?, ?)", (order_id, total)) cur.execute("DELETE FROM orders WHERE id=?", (order_id,)) db.commit() db.close() # Tampilkan struk self.tampil_struk(order_id, nama, total) # Update listbox self.load_orders() def tampil_struk(self, order_id, nama, total): win = tk.Toplevel(self.frame) win.title("Struk Pembayaran") tk.Label(win, text="STRUK PEMBAYARAN", font=("Arial",14,"bold")).pack(pady=5) tk.Label(win, text=f"Order ID : {order_id}").pack() tk.Label(win, text=f"Nama Menu: {nama}").pack() tk.Label(win, text=f"Total : Rp {total:,}").pack() tk.Label(win, text="Terima kasih 🙏").pack(pady=10) tk.Button(win, text="Tutup", command=win.destroy).pack(pady=5) def logout(self): self.frame.destroy() self.controller.show_frame("Login")