Compare commits
28
Commits
6359376da0
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f349274710 | ||
|
|
4c8221971a | ||
|
|
5bd728b1bd | ||
|
|
9053434a83 | ||
|
|
e8edfe939f | ||
|
|
17bdf516b3 | ||
|
|
94e45a7aad | ||
|
|
54c14826c4 | ||
|
|
52233b09be | ||
|
|
3ab63e6327 | ||
|
|
e8bc7113d1 | ||
|
|
509715f629 | ||
|
|
c4b6e1fba9 | ||
|
|
e5c6da3417 | ||
|
|
92abbb95fa | ||
|
|
6e6218f2fa | ||
|
|
3dc145beae | ||
|
|
78c730f245 | ||
|
|
984b1ecba5 | ||
|
|
eaf12c10a4 | ||
|
|
29f0700324 | ||
|
|
2a9b7a4edc | ||
|
|
787bf561e4 | ||
|
|
b1a5224a67 | ||
|
|
a710f36393 | ||
|
|
67c6169a7e | ||
|
|
20386a867a | ||
|
|
f62c4904cd |
@@ -0,0 +1 @@
|
||||
*.pyc
|
||||
+200
-16
@@ -1,40 +1,224 @@
|
||||
import tkinter as tk
|
||||
from database import connect
|
||||
from tkinter import messagebox
|
||||
from database import connect
|
||||
|
||||
class AdminMenu:
|
||||
def __init__(self, root):
|
||||
self.root = root
|
||||
self.frame = tk.Frame(root)
|
||||
self.frame.pack()
|
||||
self.frame.pack(fill="both", expand=True)
|
||||
|
||||
# =====================
|
||||
# JUDUL
|
||||
# =====================
|
||||
tk.Label(
|
||||
self.frame,
|
||||
text="ADMIN - KELOLA MENU",
|
||||
font=("Arial", 18, "bold")
|
||||
).pack(pady=10)
|
||||
).pack(pady=15)
|
||||
|
||||
self.nama = tk.Entry(self.frame)
|
||||
self.harga = tk.Entry(self.frame)
|
||||
self.gambar = tk.Entry(self.frame)
|
||||
# =====================
|
||||
# FORM INPUT
|
||||
# =====================
|
||||
form = tk.Frame(self.frame)
|
||||
form.pack(pady=10)
|
||||
|
||||
for label, entry in [
|
||||
("Nama Menu", self.nama),
|
||||
("Harga", self.harga),
|
||||
("Path Gambar", self.gambar)
|
||||
]:
|
||||
tk.Label(self.frame, text=label).pack()
|
||||
entry.pack()
|
||||
tk.Label(form, text="Nama Menu", width=15, anchor="w")\
|
||||
.grid(row=0, column=0, pady=5)
|
||||
self.nama = tk.Entry(form, width=30)
|
||||
self.nama.grid(row=0, column=1)
|
||||
|
||||
tk.Button(self.frame, text="Tambah Menu", command=self.tambah).pack(pady=5)
|
||||
tk.Label(form, text="Kategori", width=15, anchor="w")\
|
||||
.grid(row=1, column=0, pady=5)
|
||||
self.kategori = tk.StringVar()
|
||||
tk.OptionMenu(
|
||||
form,
|
||||
self.kategori,
|
||||
"Makanan",
|
||||
"Minuman",
|
||||
"Dessert"
|
||||
).grid(row=1, column=1, sticky="w")
|
||||
self.kategori.set("Makanan")
|
||||
|
||||
tk.Label(form, text="Harga", width=15, anchor="w")\
|
||||
.grid(row=2, column=0, pady=5)
|
||||
self.harga = tk.Entry(form, width=30)
|
||||
self.harga.grid(row=2, column=1)
|
||||
|
||||
tk.Label(form, text="Path Gambar", width=15, anchor="w")\
|
||||
.grid(row=3, column=0, pady=5)
|
||||
self.gambar = tk.Entry(form, width=30)
|
||||
self.gambar.grid(row=3, column=1)
|
||||
|
||||
# =====================
|
||||
# BUTTON CRUD
|
||||
# =====================
|
||||
btn_frame = tk.Frame(self.frame)
|
||||
btn_frame.pack(pady=10)
|
||||
|
||||
tk.Button(btn_frame, text="Tambah", width=10,
|
||||
bg="#d1e7dd", command=self.tambah).grid(row=0, column=0, padx=5)
|
||||
|
||||
tk.Button(btn_frame, text="Update", width=10,
|
||||
bg="#cfe2ff", command=self.update).grid(row=0, column=1, padx=5)
|
||||
|
||||
tk.Button(btn_frame, text="Hapus", width=10,
|
||||
bg="#f8d7da", command=self.hapus).grid(row=0, column=2, padx=5)
|
||||
|
||||
tk.Button(btn_frame, text="Refresh", width=10,
|
||||
command=self.load_menu).grid(row=0, column=3, padx=5)
|
||||
|
||||
tk.Button(btn_frame, text="Logout", width=10,
|
||||
command=self.logout).grid(row=0, column=4, padx=5)
|
||||
|
||||
# =====================
|
||||
# FILTER
|
||||
# =====================
|
||||
filter_frame = tk.Frame(self.frame)
|
||||
filter_frame.pack(pady=5)
|
||||
|
||||
tk.Label(filter_frame, text="Filter Kategori:").pack(side=tk.LEFT)
|
||||
self.filter_kategori = tk.StringVar()
|
||||
tk.OptionMenu(
|
||||
filter_frame,
|
||||
self.filter_kategori,
|
||||
"Semua",
|
||||
"Makanan",
|
||||
"Minuman",
|
||||
"Dessert",
|
||||
command=self.load_menu
|
||||
).pack(side=tk.LEFT)
|
||||
self.filter_kategori.set("Semua")
|
||||
|
||||
# =====================
|
||||
# LIST MENU
|
||||
# =====================
|
||||
self.listbox = tk.Listbox(self.frame, width=80, height=10)
|
||||
self.listbox.pack(pady=10)
|
||||
self.listbox.bind("<<ListboxSelect>>", self.pilih_menu)
|
||||
|
||||
self.menu_data = []
|
||||
self.load_menu()
|
||||
|
||||
# =====================
|
||||
# LOAD MENU + FILTER
|
||||
# =====================
|
||||
def load_menu(self, *_):
|
||||
self.listbox.delete(0, tk.END)
|
||||
db = connect()
|
||||
cur = db.cursor()
|
||||
|
||||
if self.filter_kategori.get() == "Semua":
|
||||
cur.execute("SELECT * FROM menu")
|
||||
else:
|
||||
cur.execute(
|
||||
"SELECT * FROM menu WHERE kategori=?",
|
||||
(self.filter_kategori.get(),)
|
||||
)
|
||||
|
||||
self.menu_data = cur.fetchall()
|
||||
db.close()
|
||||
|
||||
for m in self.menu_data:
|
||||
self.listbox.insert(
|
||||
tk.END,
|
||||
f"{m[0]:<3} | {m[1]:<20} | {m[2]:<10} | Rp {m[3]:,.0f}"
|
||||
)
|
||||
|
||||
# =====================
|
||||
# PILIH MENU
|
||||
# =====================
|
||||
def pilih_menu(self, event):
|
||||
idx = self.listbox.curselection()
|
||||
if not idx:
|
||||
return
|
||||
|
||||
menu = self.menu_data[idx[0]]
|
||||
self.clear_form()
|
||||
|
||||
self.nama.insert(0, menu[1])
|
||||
self.kategori.set(menu[2])
|
||||
self.harga.insert(0, menu[3])
|
||||
self.gambar.insert(0, menu[4])
|
||||
|
||||
# =====================
|
||||
# CRUD
|
||||
# =====================
|
||||
def tambah(self):
|
||||
if not self.nama.get() or not self.harga.get():
|
||||
messagebox.showwarning("Error", "Data belum lengkap")
|
||||
return
|
||||
|
||||
db = connect()
|
||||
cur = db.cursor()
|
||||
cur.execute(
|
||||
"INSERT INTO menu(nama,harga,gambar) VALUES (?,?,?)",
|
||||
(self.nama.get(), self.harga.get(), self.gambar.get())
|
||||
"INSERT INTO menu(nama,kategori,harga,gambar) VALUES (?,?,?,?)",
|
||||
(
|
||||
self.nama.get(),
|
||||
self.kategori.get(),
|
||||
float(self.harga.get()),
|
||||
self.gambar.get()
|
||||
)
|
||||
)
|
||||
db.commit()
|
||||
db.close()
|
||||
|
||||
messagebox.showinfo("Sukses", "Menu berhasil ditambahkan")
|
||||
self.load_menu()
|
||||
self.clear_form()
|
||||
|
||||
def update(self):
|
||||
idx = self.listbox.curselection()
|
||||
if not idx:
|
||||
messagebox.showwarning("Pilih", "Pilih menu dulu")
|
||||
return
|
||||
|
||||
menu_id = self.menu_data[idx[0]][0]
|
||||
|
||||
db = connect()
|
||||
cur = db.cursor()
|
||||
cur.execute(
|
||||
"UPDATE menu SET nama=?, kategori=?, harga=?, gambar=? WHERE id=?",
|
||||
(
|
||||
self.nama.get(),
|
||||
self.kategori.get(),
|
||||
float(self.harga.get()),
|
||||
self.gambar.get(),
|
||||
menu_id
|
||||
)
|
||||
)
|
||||
db.commit()
|
||||
db.close()
|
||||
|
||||
messagebox.showinfo("Sukses", "Menu berhasil diupdate")
|
||||
self.load_menu()
|
||||
|
||||
def hapus(self):
|
||||
idx = self.listbox.curselection()
|
||||
if not idx:
|
||||
messagebox.showwarning("Pilih", "Pilih menu dulu")
|
||||
return
|
||||
|
||||
menu_id = self.menu_data[idx[0]][0]
|
||||
|
||||
if messagebox.askyesno("Konfirmasi", "Yakin hapus menu ini?"):
|
||||
db = connect()
|
||||
cur = db.cursor()
|
||||
cur.execute("DELETE FROM menu WHERE id=?", (menu_id,))
|
||||
db.commit()
|
||||
db.close()
|
||||
|
||||
messagebox.showinfo("Sukses", "Menu berhasil dihapus")
|
||||
self.load_menu()
|
||||
self.clear_form()
|
||||
|
||||
def clear_form(self):
|
||||
self.nama.delete(0, tk.END)
|
||||
self.harga.delete(0, tk.END)
|
||||
self.gambar.delete(0, tk.END)
|
||||
self.kategori.set("Makanan")
|
||||
|
||||
def logout(self):
|
||||
self.frame.destroy()
|
||||
from main import LoginScreen
|
||||
LoginScreen(self.root)
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 308 KiB |
+50
-21
@@ -1,5 +1,4 @@
|
||||
import sqlite3
|
||||
import datetime
|
||||
|
||||
def connect():
|
||||
return sqlite3.connect("cafe.db")
|
||||
@@ -8,7 +7,9 @@ def setup_database():
|
||||
db = connect()
|
||||
cur = db.cursor()
|
||||
|
||||
# Tabel Users
|
||||
# =====================
|
||||
# TABEL USERS
|
||||
# =====================
|
||||
cur.execute("""
|
||||
CREATE TABLE IF NOT EXISTS users(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
@@ -18,30 +19,42 @@ def setup_database():
|
||||
)
|
||||
""")
|
||||
|
||||
# Tabel Menu
|
||||
# =====================
|
||||
# TABEL MENU (ADA KATEGORI)
|
||||
# =====================
|
||||
cur.execute("""
|
||||
CREATE TABLE IF NOT EXISTS menu(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
nama TEXT,
|
||||
kategori TEXT,
|
||||
harga REAL,
|
||||
gambar TEXT,
|
||||
kategori TEXT
|
||||
gambar TEXT
|
||||
)
|
||||
""")
|
||||
|
||||
# Tabel Transaksi (Header nota)
|
||||
# Jaga-jaga DB lama (tidak error)
|
||||
try:
|
||||
cur.execute("ALTER TABLE menu ADD COLUMN kategori TEXT")
|
||||
except sqlite3.OperationalError:
|
||||
pass
|
||||
|
||||
# =====================
|
||||
# TABEL TRANSAKSI
|
||||
# =====================
|
||||
cur.execute("""
|
||||
CREATE TABLE IF NOT EXISTS transaksi(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
tanggal TEXT,
|
||||
total REAL,
|
||||
meja_id INTEGER,
|
||||
status TEXT
|
||||
status TEXT,
|
||||
metode TEXT
|
||||
)
|
||||
""")
|
||||
# Status: 'Pending' (Masuk Dapur), 'Disajikan' (Waiter selesai), 'Lunas' (Kasir)
|
||||
|
||||
# Tabel Detail Transaksi (Isi makanan per nota)
|
||||
# =====================
|
||||
# DETAIL TRANSAKSI
|
||||
# =====================
|
||||
cur.execute("""
|
||||
CREATE TABLE IF NOT EXISTS detail_transaksi(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
@@ -53,24 +66,40 @@ def setup_database():
|
||||
)
|
||||
""")
|
||||
|
||||
# Insert Akun Default jika kosong
|
||||
# =====================
|
||||
# INSERT USER DEFAULT
|
||||
# =====================
|
||||
cur.execute("SELECT COUNT(*) FROM users")
|
||||
if cur.fetchone()[0] == 0:
|
||||
users = [
|
||||
("admin","admin","admin"),
|
||||
("kasir","kasir","kasir"),
|
||||
("pembeli","pembeli","pembeli"),
|
||||
("waiter","waiter","waiter"),
|
||||
("pemilik","pemilik","pemilik")
|
||||
("admin", "admin", "admin"),
|
||||
("kasir", "kasir", "kasir"),
|
||||
("pembeli", "pembeli", "pembeli"),
|
||||
("waiter", "waiter", "waiter"),
|
||||
("pemilik", "pemilik", "pemilik")
|
||||
]
|
||||
cur.executemany("INSERT INTO users(username,password,role) VALUES (?,?,?)", users)
|
||||
db.commit()
|
||||
cur.executemany(
|
||||
"INSERT INTO users(username,password,role) VALUES (?,?,?)",
|
||||
users
|
||||
)
|
||||
|
||||
# Insert Menu Dummy jika kosong
|
||||
# =====================
|
||||
# INSERT MENU DEFAULT
|
||||
# =====================
|
||||
cur.execute("SELECT COUNT(*) FROM menu")
|
||||
if cur.fetchone()[0] == 0:
|
||||
cur.execute("INSERT INTO menu (nama, harga, gambar) VALUES ('Mie Ayam', 15000, 'mie_ayam.webp')")
|
||||
cur.execute("INSERT INTO menu (nama, harga, gambar) VALUES ('Es Teh', 5000, 'es_teh.webp')")
|
||||
db.commit()
|
||||
menus = [
|
||||
('Ayam Goreng', 'Makanan', 20000, 'aset/ayam_goreng.jpg'),
|
||||
('Bakso', 'Makanan', 15000, 'aset/bakso.jpg'),
|
||||
('Mie Ayam', 'Makanan', 12000, 'aset/mie_ayam.jpg'),
|
||||
('Es Teh', 'Minuman', 5000, 'aset/es_teh.jpg'),
|
||||
('Es Teler', 'Dessert', 15000, 'aset/es_teler.jpg'),
|
||||
('Jus Jeruk', 'Minuman', 8000, 'aset/jus_jeruk.jpg')
|
||||
]
|
||||
cur.executemany(
|
||||
"INSERT INTO menu (nama, kategori, harga, gambar) VALUES (?,?,?,?)",
|
||||
menus
|
||||
)
|
||||
|
||||
db.commit()
|
||||
db.close()
|
||||
+304
-19
@@ -1,62 +1,347 @@
|
||||
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):
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
# =====================
|
||||
# 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
|
||||
# =====================
|
||||
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}"
|
||||
)
|
||||
|
||||
# 🔽 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
|
||||
# =====================
|
||||
def bayar(self):
|
||||
idx = self.listbox.curselection()
|
||||
if not idx:
|
||||
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: # 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)
|
||||
# =====================
|
||||
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)
|
||||
|
||||
def selesai_qris():
|
||||
self.selesaikan_pembayaran(t_id, meja, total, "QRIS")
|
||||
win.destroy()
|
||||
|
||||
# ❌ WINDOW DITUTUP = TRANSAKSI BERHASIL
|
||||
win.protocol("WM_DELETE_WINDOW", selesai_qris)
|
||||
|
||||
tk.Button(
|
||||
win,
|
||||
text="Konfirmasi Pembayaran",
|
||||
bg="#d1e7dd",
|
||||
width=25,
|
||||
command=selesai_qris
|
||||
).pack(pady=15)
|
||||
|
||||
# =====================
|
||||
# E-WALLET
|
||||
# =====================
|
||||
def konfirmasi_ewallet(self, t_id, meja, total):
|
||||
confirm = messagebox.askyesno(
|
||||
"E-Wallet Payment",
|
||||
f"""
|
||||
Bayar menggunakan E-Wallet?
|
||||
|
||||
Meja : {meja}
|
||||
Total : Rp {total:,.0f}
|
||||
|
||||
Lanjutkan pembayaran?
|
||||
"""
|
||||
)
|
||||
|
||||
# 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,))
|
||||
self.selesaikan_pembayaran(t_id, meja, total, "E-Wallet")
|
||||
|
||||
def selesaikan_pembayaran(self, t_id, meja, total, metode, uang=None, kembalian=None):
|
||||
db = connect()
|
||||
cur = db.cursor()
|
||||
|
||||
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")
|
||||
|
||||
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()
|
||||
|
||||
messagebox.showinfo("Sukses", "Pembayaran Berhasil! Struk dicetak.")
|
||||
self.load_tagihan()
|
||||
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",
|
||||
f"""
|
||||
======= STRUK =======
|
||||
ID Transaksi : {t_id}
|
||||
Meja : {meja}
|
||||
Total : Rp {total:,.0f}
|
||||
Metode : {metode}{struk_tambahan}
|
||||
Status : Lunas
|
||||
====================
|
||||
Terima kasih 🙏
|
||||
"""
|
||||
)
|
||||
|
||||
self.load_tagihan()
|
||||
|
||||
def logout(self):
|
||||
self.frame.destroy()
|
||||
|
||||
+164
-76
@@ -1,22 +1,46 @@
|
||||
import tkinter as tk
|
||||
from tkinter import messagebox
|
||||
from tkinter import messagebox, ttk
|
||||
from PIL import Image, ImageTk
|
||||
from database import connect
|
||||
import sqlite3
|
||||
import datetime
|
||||
import os
|
||||
|
||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
# ================= DATABASE CONNECT =================
|
||||
def connect():
|
||||
return sqlite3.connect("cafe.db")
|
||||
|
||||
# ================= PEMBELI MENU =================
|
||||
class PembeliMenu:
|
||||
def __init__(self, parent):
|
||||
self.parent = parent
|
||||
self.frame = tk.Frame(parent)
|
||||
self.frame.pack(fill="both", expand=True)
|
||||
|
||||
self.cart = [] # List untuk menyimpan belanjaan sementara
|
||||
self.images = [] # List untuk reference gambar agar tidak hilang
|
||||
self.cart = []
|
||||
self.images = []
|
||||
|
||||
# --- Header ---
|
||||
tk.Label(self.frame, text="SELAMAT DATANG", font=("Arial", 18, "bold")).pack(pady=10)
|
||||
# ================= HEADER =================
|
||||
header = tk.Frame(self.frame)
|
||||
header.pack(fill="x", padx=20, pady=10)
|
||||
|
||||
# --- INPUT DATA PELANGGAN ---
|
||||
tk.Label(
|
||||
header,
|
||||
text="SELAMAT DATANG",
|
||||
font=("Arial", 18, "bold")
|
||||
).pack(side="left")
|
||||
|
||||
tk.Button(
|
||||
header,
|
||||
text="⬅ Kembali",
|
||||
bg="#f8d7da",
|
||||
font=("Arial", 10, "bold"),
|
||||
command=self.logout
|
||||
).pack(side="right")
|
||||
|
||||
|
||||
# ================= INPUT DATA =================
|
||||
info_frame = tk.Frame(self.frame, bd=2, relief="groove", padx=10, pady=10)
|
||||
info_frame.pack(pady=5)
|
||||
|
||||
@@ -24,31 +48,69 @@ class PembeliMenu:
|
||||
self.entry_nama = tk.Entry(info_frame)
|
||||
self.entry_nama.grid(row=0, column=1, padx=5)
|
||||
|
||||
tk.Label(info_frame, text="No. Meja:").grid(row=0, column=2, sticky="e")
|
||||
self.entry_meja = tk.Entry(info_frame, width=5)
|
||||
self.entry_meja.grid(row=0, column=3, padx=5)
|
||||
tk.Label(info_frame, text="Pilih Meja:").grid(row=0, column=2, sticky="e")
|
||||
self.meja_var = tk.StringVar()
|
||||
self.combo_meja = ttk.Combobox(
|
||||
info_frame,
|
||||
textvariable=self.meja_var,
|
||||
state="readonly",
|
||||
width=5
|
||||
)
|
||||
self.combo_meja.grid(row=0, column=3, padx=5)
|
||||
|
||||
# Tombol Kembali
|
||||
tk.Button(self.frame, text="Kembali ke Utama", bg="#f9e79f", command=self.logout).pack(pady=5)
|
||||
tk.Button(info_frame, text="🔄", command=self.refresh_available_tables).grid(row=0, column=4, padx=2)
|
||||
|
||||
# --- Area Menu ---
|
||||
self.menu_frame = tk.Frame(self.frame)
|
||||
self.menu_frame.pack(pady=10, fill="both", expand=True)
|
||||
self.refresh_available_tables()
|
||||
|
||||
# ================= CONTENT 2 KOLOM =================
|
||||
content = tk.Frame(self.frame)
|
||||
content.pack(fill="both", expand=True, padx=20, pady=10)
|
||||
|
||||
content.grid_columnconfigure(0, weight=3)
|
||||
content.grid_columnconfigure(1, weight=1)
|
||||
|
||||
# ================= MENU (KIRI) =================
|
||||
self.menu_frame = tk.Frame(content)
|
||||
self.menu_frame.grid(row=0, column=0, sticky="nw")
|
||||
self.load_menu()
|
||||
|
||||
# --- Keranjang Belanja ---
|
||||
tk.Label(self.frame, text="Keranjang Pesanan:", font=("Arial", 10, "bold")).pack()
|
||||
self.listbox = tk.Listbox(self.frame, width=50, height=6)
|
||||
self.listbox.pack()
|
||||
# ================= KERANJANG (KANAN) =================
|
||||
cart_frame = tk.LabelFrame(
|
||||
content,
|
||||
text="Keranjang Pesanan",
|
||||
font=("Arial", 11, "bold"),
|
||||
padx=10,
|
||||
pady=10
|
||||
)
|
||||
cart_frame.grid(row=0, column=1, sticky="ne")
|
||||
|
||||
# [BARU] Tombol Hapus Item
|
||||
tk.Button(self.frame, text="❌ Hapus Item Terpilih", fg="red", font=("Arial", 9), command=self.hapus_item_cart).pack(pady=2)
|
||||
self.listbox = tk.Listbox(cart_frame, width=35, height=10, font=("Courier", 10))
|
||||
self.listbox.pack(pady=5)
|
||||
|
||||
self.total_lbl = tk.Label(self.frame, text="Total: Rp 0", font=("Arial", 12, "bold"))
|
||||
tk.Button(cart_frame, text="➖ Kurangi / Hapus Item", fg="red",
|
||||
command=self.kurangi_item_cart).pack(pady=5)
|
||||
|
||||
self.total_lbl = tk.Label(cart_frame, text="Total: Rp 0",
|
||||
font=("Arial", 12, "bold"))
|
||||
self.total_lbl.pack(pady=5)
|
||||
|
||||
tk.Button(self.frame, text="✅ KIRIM PESANAN", bg="#d1e7dd", font=("Arial", 11, "bold"), command=self.checkout).pack(pady=10)
|
||||
tk.Button(cart_frame, text="✅ KIRIM PESANAN", bg="#d1e7dd",
|
||||
font=("Arial", 11, "bold"), command=self.checkout).pack(pady=10)
|
||||
|
||||
# ================= MEJA =================
|
||||
def refresh_available_tables(self):
|
||||
total_meja = [str(i) for i in range(1, 11)]
|
||||
db = connect()
|
||||
cur = db.cursor()
|
||||
cur.execute("SELECT DISTINCT meja_id FROM transaksi WHERE status != 'Selesai'")
|
||||
terisi = [str(row[0]) for row in cur.fetchall()]
|
||||
db.close()
|
||||
|
||||
tersedia = [m for m in total_meja if m not in terisi]
|
||||
self.combo_meja['values'] = tersedia if tersedia else ["Penuh"]
|
||||
self.combo_meja.set(tersedia[0] if tersedia else "Penuh")
|
||||
|
||||
# ================= MENU =================
|
||||
def load_menu(self):
|
||||
db = connect()
|
||||
cur = db.cursor()
|
||||
@@ -56,96 +118,122 @@ class PembeliMenu:
|
||||
data = cur.fetchall()
|
||||
db.close()
|
||||
|
||||
row_frame = None
|
||||
columns = 4
|
||||
for i, (nama, harga, gambar) in enumerate(data):
|
||||
if i % 3 == 0:
|
||||
row_frame = tk.Frame(self.menu_frame)
|
||||
row_frame.pack()
|
||||
|
||||
f = tk.Frame(row_frame, bd=2, relief="ridge", padx=5, pady=5)
|
||||
f.pack(side=tk.LEFT, padx=5)
|
||||
row, col = divmod(i, columns)
|
||||
card = tk.Frame(self.menu_frame, width=180, height=220, bd=2, relief="ridge")
|
||||
card.grid(row=row, column=col, padx=10, pady=10)
|
||||
card.grid_propagate(False)
|
||||
|
||||
try:
|
||||
img = Image.open(gambar).resize((100, 80))
|
||||
if not gambar:
|
||||
raise ValueError("gambar kosong")
|
||||
|
||||
# gambar dari DB sudah mengandung 'aset/...'
|
||||
img_path = os.path.join(BASE_DIR, gambar)
|
||||
|
||||
if not os.path.exists(img_path):
|
||||
raise FileNotFoundError(img_path)
|
||||
|
||||
img = Image.open(img_path)
|
||||
img = img.resize((140, 90), Image.Resampling.LANCZOS)
|
||||
photo = ImageTk.PhotoImage(img)
|
||||
|
||||
self.images.append(photo)
|
||||
tk.Label(f, image=photo).pack()
|
||||
except:
|
||||
tk.Label(f, text="[No Image]").pack()
|
||||
tk.Label(card, image=photo).pack(pady=5)
|
||||
|
||||
tk.Label(f, text=nama, font=("Arial",10,"bold")).pack()
|
||||
tk.Label(f, text=f"Rp {harga:,.0f}").pack()
|
||||
tk.Button(f, text="Tambah", bg="#cfe2ff", command=lambda n=nama, h=harga: self.add_to_cart(n, h)).pack(pady=2)
|
||||
except Exception as e:
|
||||
print("IMG ERROR:", e)
|
||||
tk.Label(card, text="No Image", height=6).pack()
|
||||
|
||||
|
||||
tk.Label(card, text=nama, font=("Arial", 10, "bold"), wraplength=160).pack()
|
||||
tk.Label(card, text=f"Rp {harga:,.0f}").pack(pady=2)
|
||||
|
||||
tk.Button(card, text="Tambah", bg="#cfe2ff",
|
||||
command=lambda n=nama, h=harga: self.add_to_cart(n, h)).pack(pady=5)
|
||||
|
||||
# ================= CART =================
|
||||
def add_to_cart(self, nama, harga):
|
||||
self.cart.append({'nama': nama, 'harga': harga})
|
||||
for item in self.cart:
|
||||
if item['nama'] == nama:
|
||||
item['qty'] += 1
|
||||
item['subtotal'] = item['qty'] * harga
|
||||
self.refresh_cart()
|
||||
return
|
||||
self.cart.append({'nama': nama, 'harga_satuan': harga, 'qty': 1, 'subtotal': harga})
|
||||
self.refresh_cart()
|
||||
|
||||
# [BARU] Fungsi Logic Hapus
|
||||
def hapus_item_cart(self):
|
||||
# Ambil index item yang dipilih di listbox
|
||||
idx = self.listbox.curselection()
|
||||
|
||||
if not idx:
|
||||
messagebox.showwarning("Peringatan", "Pilih menu di keranjang yang ingin dihapus!")
|
||||
return
|
||||
|
||||
index = idx[0]
|
||||
# Hapus data dari list cart
|
||||
item_removed = self.cart.pop(index)
|
||||
|
||||
# Update tampilan listbox dan total harga
|
||||
def kurangi_item_cart(self):
|
||||
if not self.listbox.curselection(): return
|
||||
idx = self.listbox.curselection()[0]
|
||||
item = self.cart[idx]
|
||||
item['qty'] -= 1
|
||||
if item['qty'] <= 0:
|
||||
self.cart.pop(idx)
|
||||
else:
|
||||
item['subtotal'] = item['qty'] * item['harga_satuan']
|
||||
self.refresh_cart()
|
||||
# Opsional: Tampilkan pesan kecil di console atau status bar (disini saya skip biar tidak ganggu user)
|
||||
|
||||
def refresh_cart(self):
|
||||
self.listbox.delete(0, tk.END)
|
||||
total = 0
|
||||
for item in self.cart:
|
||||
self.listbox.insert(tk.END, f"{item['nama']} - Rp {item['harga']:,.0f}")
|
||||
total += item['harga']
|
||||
self.listbox.insert(tk.END, f"{item['nama']} (x{item['qty']}) - Rp {item['subtotal']:,.0f}")
|
||||
total += item['subtotal']
|
||||
self.total_lbl.config(text=f"Total: Rp {total:,.0f}")
|
||||
|
||||
def checkout(self):
|
||||
nama_pemesan = self.entry_nama.get()
|
||||
meja = self.entry_meja.get()
|
||||
|
||||
if not nama_pemesan or not meja:
|
||||
messagebox.showwarning("Data Kurang", "Mohon isi Nama dan Nomor Meja!")
|
||||
return
|
||||
if not self.cart:
|
||||
messagebox.showwarning("Kosong", "Pilih menu dulu!")
|
||||
if not self.entry_nama.get() or not self.cart:
|
||||
messagebox.showwarning("Error", "Data belum lengkap")
|
||||
return
|
||||
|
||||
total_belanja = sum(item['harga'] for item in self.cart)
|
||||
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()
|
||||
|
||||
# Menyimpan nama pemesan di dalam string tanggal (Trik agar tidak ubah struktur DB)
|
||||
# Format: "2023-12-15 10:00:00 (Budi)"
|
||||
tanggal_custom = f"{tanggal} ({nama_pemesan})"
|
||||
# 1️⃣ Simpan transaksi
|
||||
cur.execute("""
|
||||
INSERT INTO transaksi (tanggal, total, meja_id, status)
|
||||
VALUES (?, ?, ?, ?)
|
||||
""", (tanggal, total, self.combo_meja.get(), "Pending"))
|
||||
|
||||
cur.execute("INSERT INTO transaksi (tanggal, total, meja_id, status) VALUES (?, ?, ?, ?)",
|
||||
(tanggal_custom, total_belanja, meja, "Pending"))
|
||||
|
||||
transaksi_id = cur.lastrowid
|
||||
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'], 1, item['harga']))
|
||||
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()
|
||||
|
||||
messagebox.showinfo("Berhasil", f"Pesanan a.n {nama_pemesan} berhasil dikirim ke Dapur!")
|
||||
messagebox.showinfo("Berhasil", "Pesanan berhasil dikirim")
|
||||
self.cart.clear()
|
||||
self.refresh_cart()
|
||||
self.entry_nama.delete(0, tk.END)
|
||||
self.entry_meja.delete(0, tk.END)
|
||||
|
||||
|
||||
def logout(self):
|
||||
self.frame.destroy()
|
||||
from main import LoginScreen
|
||||
LoginScreen(self.parent)
|
||||
|
||||
|
||||
# ================= RUN =================
|
||||
if __name__ == '__main__':
|
||||
root = tk.Tk()
|
||||
root.title("Sistem Cafe Python")
|
||||
root.geometry("1200x700")
|
||||
PembeliMenu(root)
|
||||
root.mainloop()
|
||||
+157
-15
@@ -1,40 +1,182 @@
|
||||
import tkinter as tk
|
||||
from tkinter import messagebox
|
||||
from database import connect
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
|
||||
class PemilikPage:
|
||||
def __init__(self, parent, controller):
|
||||
def __init__(self, parent, controller=None):
|
||||
self.parent = parent
|
||||
self.controller = controller
|
||||
|
||||
self.frame = tk.Frame(parent)
|
||||
self.frame.pack(fill="both", expand=True)
|
||||
|
||||
tk.Label(self.frame, text="LAPORAN PENJUALAN", font=("Arial", 18, "bold")).pack(pady=10)
|
||||
# =====================
|
||||
# JUDUL
|
||||
# =====================
|
||||
tk.Label(
|
||||
self.frame,
|
||||
text="LAPORAN PENJUALAN",
|
||||
font=("Arial", 18, "bold")
|
||||
).pack(pady=10)
|
||||
|
||||
# Label untuk total penjualan
|
||||
self.total_lbl = tk.Label(self.frame, text="Total Penjualan: Rp 0", font=("Arial", 14, "bold"))
|
||||
self.total_lbl.pack(pady=5)
|
||||
# =====================
|
||||
# FILTER PERIODE
|
||||
# =====================
|
||||
filter_frame = tk.Frame(self.frame)
|
||||
filter_frame.pack(pady=5)
|
||||
|
||||
# Tombol Refresh
|
||||
tk.Button(self.frame, text="Refresh", bg="#cfe2ff", command=self.load).pack(pady=5)
|
||||
tk.Label(filter_frame, text="Periode:").pack(side=tk.LEFT)
|
||||
|
||||
# Tombol Logout
|
||||
tk.Button(self.frame, text="Logout", bg="#f9e79f", command=self.logout).pack(pady=5)
|
||||
self.filter_var = tk.StringVar(value="Harian")
|
||||
tk.OptionMenu(
|
||||
filter_frame,
|
||||
self.filter_var,
|
||||
"Harian", "Mingguan", "Bulanan"
|
||||
).pack(side=tk.LEFT, padx=5)
|
||||
|
||||
tk.Button(
|
||||
filter_frame,
|
||||
text="Refresh",
|
||||
bg="#cfe2ff",
|
||||
command=self.load
|
||||
).pack(side=tk.LEFT, padx=10)
|
||||
|
||||
# =====================
|
||||
# TOTAL
|
||||
# =====================
|
||||
self.total_lbl = tk.Label(
|
||||
self.frame,
|
||||
text="Total (Harian): Rp 0",
|
||||
font=("Arial", 14, "bold")
|
||||
)
|
||||
self.total_lbl.pack(pady=10)
|
||||
|
||||
# =====================
|
||||
# GRAFIK
|
||||
# =====================
|
||||
tk.Button(
|
||||
self.frame,
|
||||
text="Tampilkan Grafik",
|
||||
bg="#d1e7dd",
|
||||
width=20,
|
||||
command=self.show_graph
|
||||
).pack(pady=5)
|
||||
|
||||
# =====================
|
||||
# LOGOUT
|
||||
# =====================
|
||||
tk.Button(
|
||||
self.frame,
|
||||
text="Logout",
|
||||
bg="#f9e79f",
|
||||
command=self.logout
|
||||
).pack(pady=5)
|
||||
|
||||
# Load data awal
|
||||
self.load()
|
||||
|
||||
# =====================
|
||||
# LOAD TOTAL (SUM ASLI)
|
||||
# =====================
|
||||
def load(self):
|
||||
db = connect()
|
||||
cur = db.cursor()
|
||||
# Jumlahkan semua total pembayaran dari tabel pembayaran
|
||||
cur.execute("SELECT SUM(total) FROM pembayaran")
|
||||
total = cur.fetchone()[0] or 0
|
||||
periode = self.filter_var.get()
|
||||
|
||||
if periode == "Harian":
|
||||
cur.execute("""
|
||||
SELECT COALESCE(SUM(total), 0)
|
||||
FROM transaksi
|
||||
WHERE status='Lunas'
|
||||
AND datetime(tanggal) >= datetime('now','-1 day')
|
||||
""")
|
||||
|
||||
elif periode == "Mingguan":
|
||||
cur.execute("""
|
||||
SELECT COALESCE(SUM(total), 0)
|
||||
FROM transaksi
|
||||
WHERE status='Lunas'
|
||||
AND datetime(tanggal) >= datetime('now','-7 day')
|
||||
""")
|
||||
|
||||
else: # Bulanan
|
||||
cur.execute("""
|
||||
SELECT COALESCE(SUM(total), 0)
|
||||
FROM transaksi
|
||||
WHERE status='Lunas'
|
||||
AND strftime('%Y-%m', tanggal) = strftime('%Y-%m','now')
|
||||
""")
|
||||
|
||||
total = cur.fetchone()[0]
|
||||
db.close()
|
||||
|
||||
self.total_lbl.config(text=f"Total Penjualan: Rp {total:,}")
|
||||
self.total_lbl.config(
|
||||
text=f"Total ({periode}): Rp {total:,.0f}"
|
||||
)
|
||||
|
||||
# =====================
|
||||
# GRAFIK (SUM SESUAI TOTAL)
|
||||
# =====================
|
||||
def show_graph(self):
|
||||
plt.close('all')
|
||||
|
||||
db = connect()
|
||||
cur = db.cursor()
|
||||
periode = self.filter_var.get()
|
||||
|
||||
if periode == "Harian":
|
||||
cur.execute("""
|
||||
SELECT strftime('%H:%M', tanggal), SUM(total)
|
||||
FROM transaksi
|
||||
WHERE status='Lunas'
|
||||
AND datetime(tanggal) >= datetime('now','-1 day')
|
||||
GROUP BY strftime('%H', tanggal)
|
||||
ORDER BY tanggal
|
||||
""")
|
||||
|
||||
elif periode == "Mingguan":
|
||||
cur.execute("""
|
||||
SELECT date(tanggal), SUM(total)
|
||||
FROM transaksi
|
||||
WHERE status='Lunas'
|
||||
AND datetime(tanggal) >= datetime('now','-7 day')
|
||||
GROUP BY date(tanggal)
|
||||
ORDER BY date(tanggal)
|
||||
""")
|
||||
|
||||
else:
|
||||
cur.execute("""
|
||||
SELECT strftime('%Y-%m', tanggal), SUM(total)
|
||||
FROM transaksi
|
||||
WHERE status='Lunas'
|
||||
GROUP BY strftime('%Y-%m', tanggal)
|
||||
ORDER BY strftime('%Y-%m', tanggal)
|
||||
""")
|
||||
|
||||
data = cur.fetchall()
|
||||
db.close()
|
||||
|
||||
if not data:
|
||||
messagebox.showinfo("Info", "Belum ada data penjualan")
|
||||
return
|
||||
|
||||
labels = [d[0] for d in data]
|
||||
totals = [d[1] for d in data]
|
||||
|
||||
plt.figure()
|
||||
plt.plot(labels, totals, marker='o')
|
||||
plt.title(f"Grafik Penjualan ({periode})")
|
||||
plt.xlabel("Periode")
|
||||
plt.ylabel("Total Penjualan")
|
||||
plt.xticks(rotation=45)
|
||||
plt.tight_layout()
|
||||
plt.show()
|
||||
|
||||
# =====================
|
||||
# LOGOUT
|
||||
# =====================
|
||||
def logout(self):
|
||||
self.frame.destroy()
|
||||
from main import LoginScreen
|
||||
LoginScreen(self.parent)
|
||||
|
||||
|
||||
+82
-23
@@ -6,61 +6,120 @@ class WaiterDashboard:
|
||||
def __init__(self, parent):
|
||||
self.parent = parent
|
||||
self.frame = tk.Frame(parent)
|
||||
self.frame.pack(fill="both", expand=True)
|
||||
self.frame.pack(fill="both", expand=True, padx=20, pady=10)
|
||||
|
||||
tk.Label(self.frame, text="DASHBOARD WAITER (Dapur)", font=("Arial", 18, "bold")).pack(pady=10)
|
||||
# =====================
|
||||
# HEADER
|
||||
# =====================
|
||||
tk.Label(
|
||||
self.frame,
|
||||
text="DASHBOARD WAITER (DAPUR)",
|
||||
font=("Arial", 18, "bold")
|
||||
).pack(pady=10)
|
||||
|
||||
tk.Button(self.frame, text="Logout", command=self.logout).pack(pady=5)
|
||||
tk.Button(self.frame, text="Refresh Data", bg="#cfe2ff", command=self.load_orders).pack(pady=5)
|
||||
top_btn = tk.Frame(self.frame)
|
||||
top_btn.pack(pady=5)
|
||||
|
||||
# List Pesanan Masuk
|
||||
self.listbox = tk.Listbox(self.frame, width=80, height=15)
|
||||
self.listbox.pack(pady=10)
|
||||
tk.Button(top_btn, text="Refresh Data", bg="#cfe2ff",
|
||||
width=15, command=self.load_orders).grid(row=0, column=0, padx=5)
|
||||
|
||||
tk.Button(self.frame, text="Selesai Disajikan / Validasi", bg="#d1e7dd", command=self.validasi_layanan).pack(pady=10)
|
||||
tk.Button(top_btn, text="Logout", bg="#f8d7da",
|
||||
width=10, command=self.logout).grid(row=0, column=1, padx=5)
|
||||
|
||||
self.order_ids = [] # Untuk menyimpan ID transaksi sesuai urutan listbox
|
||||
# =====================
|
||||
# LIST PESANAN + SCROLL
|
||||
# =====================
|
||||
list_frame = tk.Frame(self.frame)
|
||||
list_frame.pack(pady=10)
|
||||
|
||||
scrollbar = tk.Scrollbar(list_frame)
|
||||
scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
|
||||
|
||||
self.listbox = tk.Listbox(
|
||||
list_frame,
|
||||
width=90,
|
||||
height=15,
|
||||
yscrollcommand=scrollbar.set
|
||||
)
|
||||
self.listbox.pack(side=tk.LEFT)
|
||||
|
||||
scrollbar.config(command=self.listbox.yview)
|
||||
|
||||
# =====================
|
||||
# BUTTON VALIDASI
|
||||
# =====================
|
||||
tk.Button(
|
||||
self.frame,
|
||||
text="✔ Pesanan Selesai Disajikan",
|
||||
bg="#d1e7dd",
|
||||
font=("Arial", 11, "bold"),
|
||||
width=30,
|
||||
command=self.validasi_layanan
|
||||
).pack(pady=10)
|
||||
|
||||
self.order_ids = []
|
||||
self.load_orders()
|
||||
|
||||
# =====================
|
||||
# LOAD DATA
|
||||
# =====================
|
||||
def load_orders(self):
|
||||
self.listbox.delete(0, tk.END)
|
||||
self.order_ids = []
|
||||
|
||||
db = connect()
|
||||
cur = db.cursor()
|
||||
# Ambil pesanan yang statusnya 'Pending'
|
||||
cur.execute("SELECT id, meja_id, total, status FROM transaksi WHERE status='Pending'")
|
||||
|
||||
cur.execute(
|
||||
"SELECT id, meja_id, total FROM transaksi WHERE status='Pending'"
|
||||
)
|
||||
rows = cur.fetchall()
|
||||
|
||||
for row in rows:
|
||||
t_id, meja, total, status = row
|
||||
# Ambil detail menu untuk ditampilkan
|
||||
cur.execute("SELECT menu_nama FROM detail_transaksi WHERE transaksi_id=?", (t_id,))
|
||||
menus = [r[0] for r in cur.fetchall()]
|
||||
menu_str = ", ".join(menus)
|
||||
for t_id, meja, total in rows:
|
||||
cur.execute(
|
||||
"SELECT menu_nama, jumlah FROM detail_transaksi WHERE transaksi_id=?",
|
||||
(t_id,)
|
||||
)
|
||||
details = cur.fetchall()
|
||||
|
||||
self.listbox.insert(tk.END, f"Meja {meja} | ID Transaksi: {t_id}")
|
||||
for menu, qty in details:
|
||||
self.listbox.insert(tk.END, f" - {menu} x{qty}")
|
||||
|
||||
self.listbox.insert(tk.END, f"Total : Rp {total:,.0f}")
|
||||
self.listbox.insert(tk.END, "-" * 70)
|
||||
|
||||
display_text = f"[Meja {meja}] ID:{t_id} | Menu: {menu_str} | Status: {status}"
|
||||
self.listbox.insert(tk.END, display_text)
|
||||
self.order_ids.append(t_id)
|
||||
|
||||
db.close()
|
||||
|
||||
# =====================
|
||||
# VALIDASI
|
||||
# =====================
|
||||
def validasi_layanan(self):
|
||||
idx = self.listbox.curselection()
|
||||
if not idx:
|
||||
messagebox.showwarning("Pilih", "Pilih pesanan yang sudah disajikan")
|
||||
return
|
||||
|
||||
selected_id = self.order_ids[idx[0]]
|
||||
# Cari ID terdekat ke atas
|
||||
selected_index = idx[0]
|
||||
transaksi_index = selected_index // 5
|
||||
transaksi_id = self.order_ids[transaksi_index]
|
||||
|
||||
db = connect()
|
||||
cur = db.cursor()
|
||||
# Ubah status jadi 'Disajikan' agar muncul di kasir
|
||||
cur.execute("UPDATE transaksi SET status='Disajikan' WHERE id=?", (selected_id,))
|
||||
cur.execute(
|
||||
"UPDATE transaksi SET status='Disajikan' WHERE id=?",
|
||||
(transaksi_id,)
|
||||
)
|
||||
db.commit()
|
||||
db.close()
|
||||
|
||||
messagebox.showinfo("Sukses", "Pesanan selesai disajikan. Pelanggan bisa bayar di kasir.")
|
||||
messagebox.showinfo(
|
||||
"Sukses",
|
||||
"Pesanan ditandai selesai.\nKasir bisa memproses pembayaran."
|
||||
)
|
||||
self.load_orders()
|
||||
|
||||
def logout(self):
|
||||
|
||||
Reference in New Issue
Block a user