43 lines
1.6 KiB
Python
43 lines
1.6 KiB
Python
import tkinter as tk
|
|
from database import connect
|
|
|
|
class PemilikPage(tk.Frame):
|
|
def __init__(self, parent, controller):
|
|
super().__init__(parent)
|
|
self.controller = controller
|
|
|
|
# --- PERBAIKAN: Baris self.pack() sudah DIHAPUS ---
|
|
# Kita tidak boleh packing diri sendiri karena main.py sudah mengatur posisi kita pakai Grid.
|
|
|
|
# Judul Halaman
|
|
tk.Label(self, text="LAPORAN PENJUALAN", font=("Arial", 18, "bold")).pack(pady=20)
|
|
|
|
# Label Total
|
|
self.total_lbl = tk.Label(self, text="Total Pendapatan: Rp 0", font=("Arial", 20, "bold"), fg="green")
|
|
self.total_lbl.pack(pady=20)
|
|
|
|
tk.Label(self, text="(Menghitung semua transaksi berstatus 'Paid')", fg="gray").pack()
|
|
|
|
# Tombol-tombol
|
|
tk.Button(self, text="Refresh Laporan", bg="#cfe2ff", command=self.load).pack(pady=10)
|
|
tk.Button(self, text="Logout", bg="#f9e79f", command=lambda: controller.show_frame("LoginPage")).pack(pady=10)
|
|
|
|
def update_data(self):
|
|
"""Dipanggil otomatis saat halaman dibuka"""
|
|
self.load()
|
|
|
|
def load(self):
|
|
"""Ambil data total penjualan dari database"""
|
|
db = connect()
|
|
cur = db.cursor()
|
|
|
|
# Hitung sum total dari transaksi yang sudah Paid (Lunas)
|
|
cur.execute("SELECT SUM(total) FROM transaksi WHERE status='Paid'")
|
|
result = cur.fetchone()[0]
|
|
|
|
# Kalau belum ada penjualan, set 0
|
|
total = result if result else 0
|
|
db.close()
|
|
|
|
# Update tampilan
|
|
self.total_lbl.config(text=f"Total Pendapatan: Rp {int(total):,}") |