62 lines
2.3 KiB
Python
62 lines
2.3 KiB
Python
import tkinter as tk
|
|
from tkinter import messagebox
|
|
from database import connect
|
|
|
|
class KasirPage(tk.Frame):
|
|
def __init__(self, parent, controller):
|
|
super().__init__(parent)
|
|
self.controller = controller
|
|
|
|
# Header
|
|
top = tk.Frame(self, bg="#ddd")
|
|
top.pack(fill="x")
|
|
tk.Button(top, text="Logout", command=lambda: controller.show_frame("LoginPage")).pack(side="right", padx=10, pady=5)
|
|
tk.Label(top, text="KASIR - PEMBAYARAN", font=("Arial", 16, "bold"), bg="#ddd").pack(side="left", padx=10)
|
|
|
|
# List
|
|
tk.Label(self, text="Tagihan Belum Bayar (Status: Served):", font=("Arial", 11)).pack(pady=10)
|
|
self.order_list = tk.Listbox(self, width=80, height=15)
|
|
self.order_list.pack(pady=5)
|
|
|
|
tk.Button(self, text="Refresh Data", command=self.update_data).pack(pady=5)
|
|
tk.Button(self, text="💰 PROSES BAYAR & LUNAS", bg="#81C784", height=2, command=self.bayar).pack(fill="x", padx=20, pady=20)
|
|
|
|
def update_data(self):
|
|
self.order_list.delete(0, tk.END)
|
|
self.data_orders = []
|
|
|
|
db = connect()
|
|
cur = db.cursor()
|
|
# Kasir melihat yang sudah diantar (Served) tapi belum bayar
|
|
cur.execute("SELECT id, nama_pelanggan, meja_id, total FROM transaksi WHERE status='Served'")
|
|
self.data_orders = cur.fetchall()
|
|
db.close()
|
|
|
|
for item in self.data_orders:
|
|
self.order_list.insert(tk.END, f"ID Transaksi: {item[0]} | Meja {item[2]} | {item[1]} | Tagihan: Rp {int(item[3]):,}")
|
|
|
|
def bayar(self):
|
|
idx = self.order_list.curselection()
|
|
if not idx:
|
|
messagebox.showwarning("Pilih", "Pilih tagihan dulu!")
|
|
return
|
|
|
|
selected = self.data_orders[idx[0]]
|
|
trans_id = selected[0]
|
|
total = selected[3]
|
|
|
|
# Konfirmasi
|
|
if not messagebox.askyesno("Konfirmasi", f"Terima pembayaran sebesar Rp {int(total):,}?"):
|
|
return
|
|
|
|
db = connect()
|
|
cur = db.cursor()
|
|
|
|
# Update status jadi 'Paid'
|
|
cur.execute("UPDATE transaksi SET status='Paid', metode_pembayaran='CASH' WHERE id=?", (trans_id,))
|
|
|
|
db.commit()
|
|
db.close()
|
|
|
|
messagebox.showinfo("Lunas", "Transaksi Selesai & Lunas!")
|
|
self.update_data() |