Compare commits
No commits in common. "984b1ecba5796ce03eb531d92d1605c449849468" and "29f070032444c12e2194416cb2f40e4feadc900b" have entirely different histories.
984b1ecba5
...
29f0700324
169
project/kasir.py
169
project/kasir.py
@ -2,107 +2,41 @@ import tkinter as tk
|
|||||||
from tkinter import messagebox
|
from tkinter import messagebox
|
||||||
from database import connect
|
from database import connect
|
||||||
|
|
||||||
import qrcode
|
|
||||||
from PIL import ImageTk
|
|
||||||
|
|
||||||
|
|
||||||
class KasirPage:
|
class KasirPage:
|
||||||
def __init__(self, parent, controller=None):
|
def __init__(self, parent, controller):
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.frame = tk.Frame(parent)
|
self.frame = tk.Frame(parent)
|
||||||
self.frame.pack(fill="both", expand=True)
|
self.frame.pack(fill="both", expand=True)
|
||||||
|
|
||||||
# =====================
|
tk.Label(self.frame, text="KASIR - PEMBAYARAN", font=("Arial", 18, "bold")).pack(pady=10)
|
||||||
# JUDUL
|
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="KASIR - PEMBAYARAN",
|
|
||||||
font=("Arial", 18, "bold")
|
|
||||||
).pack(pady=10)
|
|
||||||
|
|
||||||
tk.Button(
|
tk.Label(self.frame, text="Daftar Tagihan (Status: Disajikan):", font=("Arial", 12)).pack(pady=5)
|
||||||
self.frame,
|
self.listbox = tk.Listbox(self.frame, width=60, height=10)
|
||||||
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)
|
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)
|
|
||||||
|
|
||||||
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.transaksi_data = []
|
||||||
self.load_tagihan()
|
self.load_tagihan()
|
||||||
|
|
||||||
# =====================
|
|
||||||
# LOAD TAGIHAN
|
|
||||||
# =====================
|
|
||||||
def load_tagihan(self):
|
def load_tagihan(self):
|
||||||
self.listbox.delete(0, tk.END)
|
self.listbox.delete(0, tk.END)
|
||||||
self.transaksi_data = []
|
self.transaksi_data = []
|
||||||
|
|
||||||
db = connect()
|
db = connect()
|
||||||
cur = db.cursor()
|
cur = db.cursor()
|
||||||
cur.execute("""
|
# Kasir hanya melihat yang sudah disajikan waiter
|
||||||
SELECT id, meja_id, total
|
cur.execute("SELECT id, meja_id, total FROM transaksi WHERE status='Disajikan'")
|
||||||
FROM transaksi
|
|
||||||
WHERE status='Disajikan'
|
|
||||||
""")
|
|
||||||
rows = cur.fetchall()
|
rows = cur.fetchall()
|
||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
for row in rows:
|
for row in rows:
|
||||||
t_id, meja, total = row
|
t_id, meja, total = row
|
||||||
self.listbox.insert(
|
self.listbox.insert(tk.END, f"Meja {meja} - ID Transaksi: {t_id} - Total: Rp {total:,.0f}")
|
||||||
tk.END,
|
|
||||||
f"Meja {meja} | ID {t_id} | Total Rp {total:,.0f}"
|
|
||||||
)
|
|
||||||
self.transaksi_data.append(row)
|
self.transaksi_data.append(row)
|
||||||
|
|
||||||
# =====================
|
|
||||||
# BAYAR
|
|
||||||
# =====================
|
|
||||||
def bayar(self):
|
def bayar(self):
|
||||||
idx = self.listbox.curselection()
|
idx = self.listbox.curselection()
|
||||||
if not idx:
|
if not idx:
|
||||||
@ -110,91 +44,20 @@ class KasirPage:
|
|||||||
return
|
return
|
||||||
|
|
||||||
t_id, meja, total = self.transaksi_data[idx[0]]
|
t_id, meja, total = self.transaksi_data[idx[0]]
|
||||||
metode = self.metode.get()
|
|
||||||
|
|
||||||
if metode == "QRIS":
|
# Konfirmasi pembayaran
|
||||||
self.tampilkan_qr(t_id, meja, total)
|
confirm = messagebox.askyesno("Konfirmasi", f"Bayar tagihan Meja {meja} sebesar Rp {total:,.0f}?")
|
||||||
else:
|
if confirm:
|
||||||
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()
|
db = connect()
|
||||||
cur = db.cursor()
|
cur = db.cursor()
|
||||||
cur.execute(
|
# Ubah status menjadi Lunas
|
||||||
"UPDATE transaksi SET status='Lunas' WHERE id=?",
|
cur.execute("UPDATE transaksi SET status='Lunas' WHERE id=?", (t_id,))
|
||||||
(t_id,)
|
|
||||||
)
|
|
||||||
db.commit()
|
db.commit()
|
||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
messagebox.showinfo(
|
messagebox.showinfo("Sukses", "Pembayaran Berhasil! Struk dicetak.")
|
||||||
"Struk Pembayaran",
|
|
||||||
f"""
|
|
||||||
======= STRUK =======
|
|
||||||
ID Transaksi : {t_id}
|
|
||||||
Meja : {meja}
|
|
||||||
Total : Rp {total:,.0f}
|
|
||||||
Metode : {metode}
|
|
||||||
Status : Lunas
|
|
||||||
====================
|
|
||||||
Terima kasih 🙏
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
|
|
||||||
self.load_tagihan()
|
self.load_tagihan()
|
||||||
|
|
||||||
# =====================
|
|
||||||
# LOGOUT
|
|
||||||
# =====================
|
|
||||||
def logout(self):
|
def logout(self):
|
||||||
self.frame.destroy()
|
self.frame.destroy()
|
||||||
from main import LoginScreen
|
from main import LoginScreen
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user