From e2573c2197251ff754aff2712c69abfbd7b25b7f Mon Sep 17 00:00:00 2001 From: Bluwww Date: Wed, 26 Nov 2025 20:00:11 +0700 Subject: [PATCH] Update --- main.py | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 1685d9b..642e813 100644 --- a/main.py +++ b/main.py @@ -5,4 +5,80 @@ from tkinter import ttk, messagebox, filedialog from PIL import Image, ImageTk DB_PATH = "cafe_person1.db" -IMG_PREVIEW_SIZE = (120, 80) \ No newline at end of file +IMG_PREVIEW_SIZE = (120, 80) + + + +# Baguan Database (ati ati) + + +def init_db(): + conn = sqlite3.connect(DB_PATH) + c = conn.cursor() + c.execute(""" + CREATE TABLE IF NOT EXISTS users ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + username TEXT UNIQUE, + password TEXT, + role TEXT + ) + """) + c.execute(""" + CREATE TABLE IF NOT EXISTS menu ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + nama TEXT NOT NULL, + kategori TEXT, + harga REAL NOT NULL, + stok INTEGER DEFAULT 0, + foto TEXT, + tersedia INTEGER DEFAULT 1, + item_discount_pct REAL DEFAULT 0 -- per item discount percent (like 10 for 10%) + ) + """) + c.execute(""" + CREATE TABLE IF NOT EXISTS promo ( + code TEXT PRIMARY KEY, + type TEXT CHECK(type IN ('percent','fixed')), + value REAL, + min_total REAL DEFAULT 0 + ) + """) + conn.commit() + seed_defaults(conn) + return conn + +def seed_defaults(conn): + c = conn.cursor() + defaults = [ + ('admin','admin123','admin'), + ('kasir1','kasir123','kasir'), + ('waiter1','waiter123','waiter'), + ('user1','user123','pembeli'), + ('owner','owner123','pemilik'), + ] + for u,p,r in defaults: + try: + c.execute("INSERT INTO users (username,password,role) VALUES (?,?,?)", (u,p,r)) + except sqlite3.IntegrityError: + pass + sample = [ + ('Americano','Minuman',20000,10,None,1,0), + ('Latte','Minuman',25000,5,None,1,10), + ('Banana Cake','Dessert',30000,2,None,1,0), + ('Nasi Goreng','Makanan',35000,0,None,0,0), + ] + for name,kategori,harga,stok,foto,tersedia,disc in sample: + c.execute("SELECT id FROM menu WHERE nama=?", (name,)) + if c.fetchone() is None: + c.execute("""INSERT INTO menu (nama,kategori,harga,stok,foto,tersedia,item_discount_pct) + VALUES (?,?,?,?,?,?,?)""", (name,kategori,harga,stok,foto,tersedia,disc)) + promos = [ + ('CAFE10','percent',10,0), + ('HEMAT5000','fixed',5000,20000), + ] + for code,ptype,val,min_total in promos: + try: + c.execute("INSERT INTO promo (code,type,value,min_total) VALUES (?,?,?,?)", (code,ptype,val,min_total)) + except sqlite3.IntegrityError: + pass + conn.commit() \ No newline at end of file