add new
This commit is contained in:
parent
e8edfe939f
commit
9053434a83
BIN
project/project/__pycache__/admin_menu.cpython-313.pyc
Normal file
BIN
project/project/__pycache__/admin_menu.cpython-313.pyc
Normal file
Binary file not shown.
BIN
project/project/__pycache__/database.cpython-313.pyc
Normal file
BIN
project/project/__pycache__/database.cpython-313.pyc
Normal file
Binary file not shown.
BIN
project/project/__pycache__/kasir.cpython-313.pyc
Normal file
BIN
project/project/__pycache__/kasir.cpython-313.pyc
Normal file
Binary file not shown.
BIN
project/project/__pycache__/main.cpython-313.pyc
Normal file
BIN
project/project/__pycache__/main.cpython-313.pyc
Normal file
Binary file not shown.
BIN
project/project/__pycache__/pembeli_menu.cpython-313.pyc
Normal file
BIN
project/project/__pycache__/pembeli_menu.cpython-313.pyc
Normal file
Binary file not shown.
BIN
project/project/__pycache__/pemilik.cpython-313.pyc
Normal file
BIN
project/project/__pycache__/pemilik.cpython-313.pyc
Normal file
Binary file not shown.
BIN
project/project/__pycache__/waiter_dashboard.cpython-313.pyc
Normal file
BIN
project/project/__pycache__/waiter_dashboard.cpython-313.pyc
Normal file
Binary file not shown.
@ -47,7 +47,8 @@ def setup_database():
|
||||
tanggal TEXT,
|
||||
total REAL,
|
||||
meja_id INTEGER,
|
||||
status TEXT
|
||||
status TEXT,
|
||||
metode TEXT
|
||||
)
|
||||
""")
|
||||
|
||||
|
||||
@ -1,11 +1,10 @@
|
||||
import tkinter as tk
|
||||
from tkinter import messagebox
|
||||
from database import connect
|
||||
|
||||
from datetime import datetime
|
||||
import qrcode
|
||||
from PIL import ImageTk
|
||||
|
||||
|
||||
class KasirPage:
|
||||
def __init__(self, parent, controller=None):
|
||||
self.parent = parent
|
||||
@ -61,6 +60,56 @@ class KasirPage:
|
||||
"Cash", "QRIS", "E-Wallet"
|
||||
).pack(side=tk.LEFT, padx=5)
|
||||
|
||||
# =====================
|
||||
# INPUT CASH
|
||||
# =====================
|
||||
cash_frame = tk.Frame(self.frame)
|
||||
cash_frame.pack(pady=5)
|
||||
|
||||
tk.Label(cash_frame, text="Uang Diterima (Cash):").pack(side=tk.LEFT)
|
||||
|
||||
self.uang_entry = tk.Entry(cash_frame, width=15)
|
||||
self.uang_entry.pack(side=tk.LEFT, padx=5)
|
||||
|
||||
# =====================
|
||||
# HITUNG KEMBALIAN
|
||||
# =====================
|
||||
def hitung_kembalian(event=None):
|
||||
try:
|
||||
# 1. Ambil transaksi yang sedang dipilih (Total tagihan)
|
||||
idx = self.listbox.curselection()
|
||||
if idx:
|
||||
teks_item = self.listbox.get(idx).split(" ")
|
||||
total = int(teks_item[len(teks_item)-1].replace(",",""))
|
||||
|
||||
uang_diterima = int(self.uang_entry.get())
|
||||
|
||||
# 3. Hitung dan update label
|
||||
kembalian = uang_diterima - total
|
||||
self.kembalian_label.config(text=f"Rp {kembalian:,.0f}")
|
||||
|
||||
except ValueError:
|
||||
# Jika input bukan angka atau kosong, atur kembalian jadi 0
|
||||
self.kembalian_label.config(text="Rp 0")
|
||||
except IndexError:
|
||||
# Jika transaksi tidak dipilih
|
||||
self.kembalian_label.config(text="Rp 0")
|
||||
|
||||
self.uang_entry.bind("<KeyRelease>", hitung_kembalian)
|
||||
|
||||
# =====================
|
||||
# UANG KEMBALIAN (BARU)
|
||||
# =====================
|
||||
kembalian_frame = tk.Frame(self.frame)
|
||||
kembalian_frame.pack(pady=5)
|
||||
|
||||
tk.Label(kembalian_frame, text="Uang Kembalian:").pack(side=tk.LEFT)
|
||||
|
||||
# ⭐️ Label untuk menampilkan kembalian
|
||||
self.kembalian_label = tk.Label(kembalian_frame, text="Rp 0")
|
||||
self.kembalian_label.pack(side=tk.LEFT, padx=5)
|
||||
|
||||
|
||||
# =====================
|
||||
# BUTTON BAYAR
|
||||
# =====================
|
||||
@ -94,12 +143,33 @@ class KasirPage:
|
||||
|
||||
for row in rows:
|
||||
t_id, meja, total = row
|
||||
|
||||
self.listbox.insert(
|
||||
tk.END,
|
||||
f"Meja {meja} | ID {t_id} | Total Rp {total:,.0f}"
|
||||
)
|
||||
|
||||
# 🔽 AMBIL DETAIL MENU
|
||||
db = connect()
|
||||
cur = db.cursor()
|
||||
cur.execute("""
|
||||
SELECT menu_nama, jumlah
|
||||
FROM detail_transaksi
|
||||
WHERE transaksi_id=?
|
||||
""", (t_id,))
|
||||
items = cur.fetchall()
|
||||
db.close()
|
||||
|
||||
for nama, qty in items:
|
||||
self.listbox.insert(
|
||||
tk.END,
|
||||
f" • {nama} x{qty}"
|
||||
)
|
||||
|
||||
self.listbox.insert(tk.END, "-" * 50)
|
||||
self.transaksi_data.append(row)
|
||||
|
||||
|
||||
# =====================
|
||||
# BAYAR
|
||||
# =====================
|
||||
@ -109,15 +179,41 @@ class KasirPage:
|
||||
messagebox.showwarning("Pilih", "Pilih tagihan yang akan dibayar!")
|
||||
return
|
||||
|
||||
t_id, meja, total = self.transaksi_data[idx[0]]
|
||||
idx = self.listbox.curselection()
|
||||
if idx:
|
||||
teks_item = self.listbox.get(idx).split(" ")
|
||||
total = int(teks_item[len(teks_item)-1].replace(",",""))
|
||||
meja = int(teks_item[1])
|
||||
t_id = int(teks_item[4])
|
||||
metode = self.metode.get()
|
||||
|
||||
if metode == "QRIS":
|
||||
self.tampilkan_qr(t_id, meja, total)
|
||||
|
||||
elif metode == "E-Wallet":
|
||||
self.konfirmasi_ewallet(t_id, meja, total)
|
||||
else:
|
||||
self.selesaikan_pembayaran(t_id, meja, total, metode)
|
||||
|
||||
else: # CASH
|
||||
try:
|
||||
uang = int(self.uang_entry.get())
|
||||
except:
|
||||
messagebox.showwarning("Error", "Masukkan uang cash!")
|
||||
return
|
||||
|
||||
if uang < total:
|
||||
messagebox.showwarning(
|
||||
"Kurang",
|
||||
f"Uang kurang!\nTotal: Rp {total:,.0f}"
|
||||
)
|
||||
return
|
||||
|
||||
kembalian = uang - total
|
||||
|
||||
self.selesaikan_pembayaran(
|
||||
t_id, meja, total, metode,
|
||||
uang, kembalian
|
||||
)
|
||||
|
||||
|
||||
# =====================
|
||||
# QRIS (CLOSE WINDOW = LUNAS)
|
||||
@ -188,25 +284,48 @@ Lanjutkan pembayaran?
|
||||
if confirm:
|
||||
self.selesaikan_pembayaran(t_id, meja, total, "E-Wallet")
|
||||
|
||||
# =====================
|
||||
# FINAL PEMBAYARAN
|
||||
# =====================
|
||||
def selesaikan_pembayaran(self, t_id, meja, total, metode):
|
||||
def selesaikan_pembayaran(self, t_id, meja, total, metode, uang=None, kembalian=None):
|
||||
db = connect()
|
||||
cur = db.cursor()
|
||||
|
||||
cur.execute(
|
||||
"""
|
||||
UPDATE transaksi
|
||||
SET status='Lunas',
|
||||
tanggal = DATETIME('now')
|
||||
WHERE id=?
|
||||
""",
|
||||
(t_id,)
|
||||
)
|
||||
try:
|
||||
cur.execute(
|
||||
"""
|
||||
UPDATE transaksi
|
||||
SET status='Lunas',
|
||||
tanggal = DATETIME('now')
|
||||
WHERE id=?
|
||||
""",
|
||||
(t_id,)
|
||||
)
|
||||
db.commit() # ⭐️ PASTIKAN COMMIT DILAKUKAN
|
||||
tanggal_sekarang = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
db.commit()
|
||||
db.close()
|
||||
sql_query = """
|
||||
INSERT INTO transaksi (tanggal, total, meja_id, status, metode)
|
||||
VALUES (?, ?, ?, ?, ?)
|
||||
"""
|
||||
|
||||
data_transaksi = (tanggal_sekarang, total, meja, "Lunas", metode)
|
||||
cur.execute(sql_query, data_transaksi)
|
||||
db.commit()
|
||||
|
||||
# Tambahkan print debug untuk konfirmasi
|
||||
print(f"DEBUG: Transaksi ID {t_id} berhasil diupdate menjadi Lunas.")
|
||||
|
||||
except Exception as e:
|
||||
# Jika ada error database
|
||||
print(f"ERROR: Gagal update status transaksi: {e}")
|
||||
messagebox.showerror("DB Error", "Gagal memperbarui status transaksi.")
|
||||
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
struk_tambahan = ""
|
||||
if metode == "Cash" and uang is not None and kembalian is not None:
|
||||
struk_tambahan = f"""
|
||||
Uang Diterima: Rp {uang:,.0f}
|
||||
Kembalian : Rp {kembalian:,.0f}"""
|
||||
|
||||
messagebox.showinfo(
|
||||
"Struk Pembayaran",
|
||||
@ -215,7 +334,7 @@ Lanjutkan pembayaran?
|
||||
ID Transaksi : {t_id}
|
||||
Meja : {meja}
|
||||
Total : Rp {total:,.0f}
|
||||
Metode : {metode}
|
||||
Metode : {metode}{struk_tambahan}
|
||||
Status : Lunas
|
||||
====================
|
||||
Terima kasih 🙏
|
||||
@ -224,9 +343,6 @@ Terima kasih 🙏
|
||||
|
||||
self.load_tagihan()
|
||||
|
||||
# =====================
|
||||
# LOGOUT
|
||||
# =====================
|
||||
def logout(self):
|
||||
self.frame.destroy()
|
||||
from main import LoginScreen
|
||||
|
||||
@ -183,18 +183,39 @@ class PembeliMenu:
|
||||
total += item['subtotal']
|
||||
self.total_lbl.config(text=f"Total: Rp {total:,.0f}")
|
||||
|
||||
# ================= CHECKOUT =================
|
||||
def checkout(self):
|
||||
if not self.entry_nama.get() or not self.cart:
|
||||
messagebox.showwarning("Error", "Data belum lengkap")
|
||||
return
|
||||
|
||||
total = sum(item['subtotal'] for item in self.cart)
|
||||
tanggal = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
db = connect()
|
||||
cur = db.cursor()
|
||||
cur.execute("INSERT INTO transaksi (tanggal, total, meja_id, status) VALUES (?, ?, ?, ?)",
|
||||
(tanggal, total, self.combo_meja.get(), "Pending"))
|
||||
|
||||
# 1️⃣ Simpan transaksi
|
||||
cur.execute("""
|
||||
INSERT INTO transaksi (tanggal, total, meja_id, status)
|
||||
VALUES (?, ?, ?, ?)
|
||||
""", (tanggal, total, self.combo_meja.get(), "Pending"))
|
||||
|
||||
transaksi_id = cur.lastrowid # 🔥 AMBIL ID TRANSAKSI
|
||||
|
||||
# 2️⃣ Simpan detail menu
|
||||
for item in self.cart:
|
||||
cur.execute("""
|
||||
INSERT INTO detail_transaksi
|
||||
(transaksi_id, menu_nama, harga, jumlah, subtotal)
|
||||
VALUES (?, ?, ?, ?, ?)
|
||||
""", (
|
||||
transaksi_id,
|
||||
item['nama'],
|
||||
item['harga_satuan'],
|
||||
item['qty'],
|
||||
item['subtotal']
|
||||
))
|
||||
|
||||
db.commit()
|
||||
db.close()
|
||||
|
||||
@ -202,6 +223,7 @@ class PembeliMenu:
|
||||
self.cart.clear()
|
||||
self.refresh_cart()
|
||||
|
||||
|
||||
def logout(self):
|
||||
self.frame.destroy()
|
||||
from main import LoginScreen
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user