36 lines
1.5 KiB
Python
36 lines
1.5 KiB
Python
import tkinter as tk
|
|
from database import connect
|
|
|
|
class PemilikPage(tk.Frame): # HARUS inherit tk.Frame
|
|
def __init__(self, parent, controller):
|
|
super().__init__(parent) # Init parent class
|
|
self.controller = controller
|
|
|
|
tk.Label(self, text="LAPORAN PENJUALAN (OWNER)", font=("Arial", 18, "bold")).pack(pady=20)
|
|
|
|
self.box = tk.Frame(self, bd=2, relief="groove", padx=40, pady=40)
|
|
self.box.pack()
|
|
|
|
# Label Total
|
|
self.total_lbl = tk.Label(self.box, text="Total Pendapatan: Rp 0", font=("Arial", 20, "bold"), fg="green")
|
|
self.total_lbl.pack(pady=10)
|
|
|
|
self.count_lbl = tk.Label(self.box, text="Jumlah Transaksi: 0", font=("Arial", 12))
|
|
self.count_lbl.pack(pady=5)
|
|
|
|
tk.Button(self, text="Refresh Laporan", bg="#cfe2ff", command=self.update_data).pack(pady=10)
|
|
tk.Button(self, text="Logout", bg="#f9e79f", command=lambda: controller.show_frame("LoginPage")).pack(pady=5)
|
|
|
|
def update_data(self):
|
|
db = connect()
|
|
cur = db.cursor()
|
|
# Hitung total dari transaksi yang statusnya 'Paid'
|
|
cur.execute("SELECT SUM(total), COUNT(id) FROM transaksi WHERE status='Paid'")
|
|
res = cur.fetchone()
|
|
db.close()
|
|
|
|
total_duit = res[0] if res[0] else 0
|
|
total_transaksi = res[1] if res[1] else 0
|
|
|
|
self.total_lbl.config(text=f"Total Pendapatan: Rp {int(total_duit):,}")
|
|
self.count_lbl.config(text=f"Jumlah Transaksi Sukses: {total_transaksi}") |