Compare commits
2 Commits
29f0700324
...
984b1ecba5
| Author | SHA1 | Date | |
|---|---|---|---|
| 984b1ecba5 | |||
| eaf12c10a4 |
187
project/kasir.py
187
project/kasir.py
@ -2,41 +2,107 @@ import tkinter as tk
|
||||
from tkinter import messagebox
|
||||
from database import connect
|
||||
|
||||
import qrcode
|
||||
from PIL import ImageTk
|
||||
|
||||
|
||||
class KasirPage:
|
||||
def __init__(self, parent, controller):
|
||||
def __init__(self, parent, controller=None):
|
||||
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()
|
||||
# =====================
|
||||
# JUDUL
|
||||
# =====================
|
||||
tk.Label(
|
||||
self.frame,
|
||||
text="KASIR - PEMBAYARAN",
|
||||
font=("Arial", 18, "bold")
|
||||
).pack(pady=10)
|
||||
|
||||
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)
|
||||
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(pady=3)
|
||||
|
||||
# =====================
|
||||
# LIST TAGIHAN
|
||||
# =====================
|
||||
tk.Label(
|
||||
self.frame,
|
||||
text="Daftar Tagihan (Status: Disajikan)",
|
||||
font=("Arial", 12)
|
||||
).pack(pady=5)
|
||||
|
||||
self.listbox = tk.Listbox(self.frame, width=65, height=10)
|
||||
self.listbox.pack(pady=5)
|
||||
|
||||
tk.Button(self.frame, text="Proses Pembayaran", bg="#d1e7dd", command=self.bayar).pack(pady=5)
|
||||
# =====================
|
||||
# METODE PEMBAYARAN
|
||||
# =====================
|
||||
metode_frame = tk.Frame(self.frame)
|
||||
metode_frame.pack(pady=5)
|
||||
|
||||
self.transaksi_data = []
|
||||
tk.Label(metode_frame, text="Metode Pembayaran:").pack(side=tk.LEFT)
|
||||
|
||||
self.metode = tk.StringVar(value="Cash")
|
||||
tk.OptionMenu(
|
||||
metode_frame,
|
||||
self.metode,
|
||||
"Cash", "QRIS", "E-Wallet"
|
||||
).pack(side=tk.LEFT, padx=5)
|
||||
|
||||
# =====================
|
||||
# BUTTON BAYAR
|
||||
# =====================
|
||||
tk.Button(
|
||||
self.frame,
|
||||
text="Proses Pembayaran",
|
||||
bg="#d1e7dd",
|
||||
width=25,
|
||||
command=self.bayar
|
||||
).pack(pady=10)
|
||||
|
||||
self.transaksi_data = []
|
||||
self.load_tagihan()
|
||||
|
||||
# =====================
|
||||
# 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'")
|
||||
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.listbox.insert(
|
||||
tk.END,
|
||||
f"Meja {meja} | ID {t_id} | Total Rp {total:,.0f}"
|
||||
)
|
||||
self.transaksi_data.append(row)
|
||||
|
||||
# =====================
|
||||
# BAYAR
|
||||
# =====================
|
||||
def bayar(self):
|
||||
idx = self.listbox.curselection()
|
||||
if not idx:
|
||||
@ -44,21 +110,92 @@ class KasirPage:
|
||||
return
|
||||
|
||||
t_id, meja, total = self.transaksi_data[idx[0]]
|
||||
metode = self.metode.get()
|
||||
|
||||
# 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()
|
||||
if metode == "QRIS":
|
||||
self.tampilkan_qr(t_id, meja, total)
|
||||
else:
|
||||
self.selesaikan_pembayaran(t_id, meja, total, metode)
|
||||
|
||||
# =====================
|
||||
# QRIS
|
||||
# =====================
|
||||
def tampilkan_qr(self, t_id, meja, total):
|
||||
win = tk.Toplevel(self.frame)
|
||||
win.title("QRIS Payment")
|
||||
win.geometry("320x420")
|
||||
|
||||
tk.Label(
|
||||
win,
|
||||
text="SCAN QR UNTUK BAYAR",
|
||||
font=("Arial", 12, "bold")
|
||||
).pack(pady=10)
|
||||
|
||||
qr_data = f"""
|
||||
QRIS-DUMMY
|
||||
Cafe Python
|
||||
Transaksi: {t_id}
|
||||
Meja: {meja}
|
||||
Total: {total}
|
||||
"""
|
||||
|
||||
qr = qrcode.make(qr_data)
|
||||
qr_img = ImageTk.PhotoImage(qr)
|
||||
|
||||
lbl = tk.Label(win, image=qr_img)
|
||||
lbl.image = qr_img
|
||||
lbl.pack(pady=10)
|
||||
|
||||
tk.Label(
|
||||
win,
|
||||
text=f"Total: Rp {total:,.0f}",
|
||||
font=("Arial", 11)
|
||||
).pack(pady=5)
|
||||
|
||||
tk.Button(
|
||||
win,
|
||||
text="Konfirmasi Pembayaran",
|
||||
bg="#d1e7dd",
|
||||
width=25,
|
||||
command=lambda: [
|
||||
self.selesaikan_pembayaran(t_id, meja, total, "QRIS"),
|
||||
win.destroy()
|
||||
]
|
||||
).pack(pady=15)
|
||||
|
||||
# =====================
|
||||
# FINAL PEMBAYARAN
|
||||
# =====================
|
||||
def selesaikan_pembayaran(self, t_id, meja, total, metode):
|
||||
db = connect()
|
||||
cur = db.cursor()
|
||||
cur.execute(
|
||||
"UPDATE transaksi SET status='Lunas' WHERE id=?",
|
||||
(t_id,)
|
||||
)
|
||||
db.commit()
|
||||
db.close()
|
||||
|
||||
messagebox.showinfo(
|
||||
"Struk Pembayaran",
|
||||
f"""
|
||||
======= STRUK =======
|
||||
ID Transaksi : {t_id}
|
||||
Meja : {meja}
|
||||
Total : Rp {total:,.0f}
|
||||
Metode : {metode}
|
||||
Status : Lunas
|
||||
====================
|
||||
Terima kasih 🙏
|
||||
"""
|
||||
)
|
||||
|
||||
self.load_tagihan()
|
||||
|
||||
# =====================
|
||||
# LOGOUT
|
||||
# =====================
|
||||
def logout(self):
|
||||
self.frame.destroy()
|
||||
from main import LoginScreen
|
||||
LoginScreen(self.parent)
|
||||
LoginScreen(self.parent)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user