0% found this document useful (0 votes)
9 views7 pages

Source Codee

Uploaded by

harishkumar66876
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views7 pages

Source Codee

Uploaded by

harishkumar66876
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

from tkinter import *

from tkinter import messagebox


import [Link]
from datetime import datetime

# ---------- DATABASE CONNECTION ----------


con = [Link](
host="localhost",
user="h1rish",
password="harish2008@#",
database="cafe_db"
)
cursor = [Link]()

# ---------- MAIN WINDOW ----------


root = Tk()
[Link]("Cafe Management System")
[Link]("450x350")
[Link](bg="#f4e1d2")

Label(root, text="☕ Cafe Management System ☕", font=("Arial", 16, "bold"),


bg="#f4e1d2").pack(pady=25)
Label(root, text="Select Your Role", font=("Arial", 12, "bold"),
bg="#f4e1d2").pack(pady=10)

# ---------- ADMIN LOGIN ----------


def admin_login():
login_win = Toplevel(root)
login_win.title("Admin Login")
login_win.geometry("350x250")

Label(login_win, text="Admin Login", font=("Arial", 14, "bold")).pack(pady=10)

Label(login_win, text="Username:").pack()
user_entry = Entry(login_win)
user_entry.pack(pady=5)

Label(login_win, text="Password:").pack()
pass_entry = Entry(login_win, show="*")
pass_entry.pack(pady=5)

def check_admin():
if user_entry.get() == "admin" and pass_entry.get() == "1234":
[Link]("Login Success", "Welcome Admin!")
login_win.destroy()
admin_panel()
else:
[Link]("Error", "Invalid username or password")

Button(login_win, text="Login", command=check_admin, bg="#4CAF50",


fg="white").pack(pady=10)

# ---------- ADMIN PANEL ----------


def admin_panel():
admin_win = Toplevel(root)
admin_win.title("Admin Panel")
admin_win.geometry("400x400")
Label(admin_win, text="Admin Panel", font=("Arial", 14, "bold")).pack(pady=10)

# --- View Menu ---


def view_menu():
[Link]("SELECT * FROM menu")
data = [Link]()
menu_win = Toplevel(admin_win)
menu_win.title("Menu List")
Label(menu_win, text="Menu Items", font=("Arial", 12, "bold")).pack(pady=5)
for row in data:
Label(menu_win, text=f"{row[0]}. {row[1]} - ₹{row[2]}").pack()

# --- Add Item ---


def add_item():
win = Toplevel(admin_win)
[Link]("Add Item")
Label(win, text="Item Name:").pack()
name_entry = Entry(win)
name_entry.pack(pady=5)
Label(win, text="Price:").pack()
price_entry = Entry(win)
price_entry.pack(pady=5)

def add():
name = name_entry.get()
price = price_entry.get()
if not name or not price:
[Link]("Warning", "Enter all fields")
return
[Link]("INSERT INTO menu (item_name, price) VALUES (%s, %s)",
(name, price))
[Link]()
[Link]("Success", f"{name} added to menu")
[Link]()

Button(win, text="Add", command=add, bg="#4CAF50",


fg="white").pack(pady=10)

# --- Delete Item ---


def delete_item():
win = Toplevel(admin_win)
[Link]("Delete Item")
Label(win, text="Item Name:").pack()
name_entry = Entry(win)
name_entry.pack(pady=5)

def delete():
name = name_entry.get()
[Link]("DELETE FROM menu WHERE item_name=%s", (name,))
[Link]()
[Link]("Deleted", f"{name} removed from menu")
[Link]()

Button(win, text="Delete", command=delete, bg="red",


fg="white").pack(pady=10)

# --- Update Item Price ---


def update_price():
win = Toplevel(admin_win)
[Link]("Update Item Price")
[Link]("300x250")

Label(win, text="Update Item Price", font=("Arial", 12,


"bold")).pack(pady=10)

Label(win, text="Item Name:").pack()


name_entry = Entry(win)
name_entry.pack(pady=5)

Label(win, text="New Price:").pack()


price_entry = Entry(win)
price_entry.pack(pady=5)

def update():
name = name_entry.get().strip()
price = price_entry.get().strip()

if not name or not price:


[Link]("Warning", "Enter both item name and new
price")
return

[Link]("SELECT * FROM menu WHERE item_name=%s", (name,))


data = [Link]()
if not data:
[Link]("Error", "Item not found!")
return

[Link]("UPDATE menu SET price=%s WHERE item_name=%s", (price,


name))
[Link]()
[Link]("Success", f"Price for '{name}' updated to ₹
{price}")
[Link]()

Button(win, text="Update", command=update, bg="#4CAF50",


fg="white").pack(pady=15)

Button(admin_win, text="View Menu", command=view_menu, width=20).pack(pady=10)


Button(admin_win, text="Add Item", command=add_item, width=20).pack(pady=10)
Button(admin_win, text="Delete Item", command=delete_item,
width=20).pack(pady=10)
Button(admin_win, text="Update Item Price", command=update_price,
width=20).pack(pady=10)

# ---------- CUSTOMER PANEL ----------

def customer_panel():
cust_win = Toplevel(root)
cust_win.title("Customer Panel")
cust_win.geometry("400x400")
cust_win.config(bg="#f4e1d2")

Label(cust_win, text="Customer Panel", font=("Arial", 16, "bold"),


bg="#f4e1d2").pack(pady=15)
# --------- VIEW MENU ----------
def view_menu():
[Link]("SELECT item_name, price FROM menu")
items = [Link]()
menu_win = Toplevel(cust_win)
menu_win.title("Menu")
menu_win.geometry("350x300")
menu_win.config(bg="#fffaf0")

Label(menu_win, text="☕ Cafe Menu ☕", font=("Arial", 14, "bold"),


bg="#fffaf0").pack(pady=10)
if not items:
Label(menu_win, text="No items available", bg="#fffaf0").pack()
else:
for i, item in enumerate(items, 1):
Label(menu_win, text=f"{i}. {item[0]} - ₹{item[1]}", bg="#fffaf0",
font=("Arial", 11)).pack(anchor="w", padx=30)

# --------- PLACE ORDER ----------

def place_order():
order_win = Toplevel(cust_win)
order_win.title("Place Order")
order_win.geometry("500x500")
order_win.config(bg="#fffaf0")

Label(order_win, text="Place Your Order", font=("Arial", 16, "bold"),


bg="#fffaf0").pack(pady=10)

Label(order_win, text="Your Name:", bg="#fffaf0").pack()


name_entry = Entry(order_win)
name_entry.pack(pady=5)

# Fetch menu items


[Link]("SELECT item_name, price FROM menu")
items = [Link]()

if not items:
Label(order_win, text="No items in menu!", fg="red",
bg="#fffaf0").pack(pady=10)
return

Label(order_win, text="Select items and enter quantity:",


bg="#fffaf0").pack(pady=10)

qty_entries = {}
for item_name, price in items:
frame = Frame(order_win, bg="#fffaf0")
[Link](anchor="w", padx=20, pady=2)
Label(frame, text=f"{item_name} (₹{price})", bg="#fffaf0", width=20,
anchor="w").pack(side=LEFT)
qty_box = Entry(frame, width=5)
qty_box.pack(side=LEFT, padx=10)
qty_entries[item_name] = (qty_box, price)

# -------- CONFIRM ORDER BUTTON --------


def confirm():
cust_name = name_entry.get().strip()
if not cust_name:
[Link]("Warning", "Please enter your name")
return

total_amount = 0
ordered_items = []

for item_name, (qty_box, price) in qty_entries.items():


qty = qty_box.get().strip()
if qty:
try:
qty = int(qty)
if qty > 0:
total = price * qty
total_amount += total
ordered_items.append((cust_name, item_name, qty,
total))
except ValueError:
[Link]("Error", f"Invalid quantity for
{item_name}")
return

if not ordered_items:
[Link]("Warning", "No items selected")
return

# Get current date and time


current_datetime = [Link]()
order_date = current_datetime.strftime("%Y-%m-%d")
order_time = current_datetime.strftime("%I:%M:%S %p")

# Save all items to DB


for order in ordered_items:
[Link]("""
INSERT INTO orders (customer_name, item_name, quantity,
total_price, order_date, order_time)
VALUES (%s, %s, %s, %s, %s, %s)
""", (order[0], order[1], order[2], order[3], order_date,
order_time))
[Link]()

# --- BILL WINDOW ---


bill_win = Toplevel(order_win)
bill_win.title("Order Bill")
bill_win.geometry("400x450")
bill_win.config(bg="#fffaf0")

Label(bill_win, text="☕ Cafe Receipt ☕", font=("Arial", 16, "bold"),


bg="#fffaf0").pack(pady=10)
Label(bill_win, text=f"Customer: {cust_name}", font=("Arial", 12),
bg="#fffaf0").pack(pady=5)
Label(bill_win, text=f"Date: {order_date}", font=("Arial", 11),
bg="#fffaf0").pack()
Label(bill_win, text=f"Time: {order_time}", font=("Arial", 11),
bg="#fffaf0").pack()
Label(bill_win, text="-------------------------------------",
bg="#fffaf0").pack()
for _, item_name, qty, total in ordered_items:
Label(bill_win, text=f"{item_name} x{qty} = ₹{total}",
bg="#fffaf0").pack(anchor="w", padx=50)

Label(bill_win, text="-------------------------------------",
bg="#fffaf0").pack()
Label(bill_win, text=f"Total Bill: ₹{total_amount}", font=("Arial", 13,
"bold"), bg="#fffaf0").pack(pady=10)
Label(bill_win, text="Thank you! Visit again ❤️", font=("Arial", 11,
"italic"), bg="#fffaf0").pack(pady=10)

def save_bill():
filename = f"{cust_name}_bill_{order_date}_{order_time.replace(':',
'-')}.txt"
with open(filename, "w", encoding="utf-8") as f:
[Link]("☕ Cafe Receipt ☕\n\n")
[Link](f"Customer: {cust_name}\n")
[Link](f"Date: {order_date}\n")
[Link](f"Time: {order_time}\n\n")
for _, item_name, qty, total in ordered_items:
[Link](f"{item_name} x{qty} = ₹{total}\n")
[Link](f"\nTotal: ₹{total_amount}\n")
[Link]("\nThank you! Visit again ❤️\n")
[Link]("Saved", f"Bill saved as {filename}")

Button(bill_win, text="Save Bill", command=save_bill, bg="#4CAF50",


fg="white").pack(pady=10)

[Link]("Order Placed", f"Order placed successfully!\nTotal


= ₹{total_amount}")
order_win.destroy()

Button(order_win, text="Confirm Order", command=confirm, bg="#4CAF50",


fg="white").pack(pady=20)

# --------- SEE MY ORDERS ----------


def see_orders():
see_win = Toplevel(cust_win)
see_win.title("My Orders")
see_win.geometry("600x400")
see_win.config(bg="#fffaf0")

Label(see_win, text="View Your Orders", font=("Arial", 16, "bold"),


bg="#fffaf0").pack(pady=10)

Label(see_win, text="Enter Your Name:", bg="#fffaf0").pack()


name_entry = Entry(see_win)
name_entry.pack(pady=5)

def fetch_orders():
name = name_entry.get().strip()
if not name:
[Link]("Warning", "Please enter your name")
return
# Fetch orders for this customer
[Link]("""
SELECT item_name, quantity, total_price, order_date, order_time
FROM orders
WHERE customer_name = %s
ORDER BY order_date DESC, order_time DESC
""", (name,))
orders = [Link]()

for widget in see_win.winfo_children()[5:]:


[Link]()

if not orders:
Label(see_win, text="No orders found!", fg="red",
bg="#fffaf0").pack(pady=10)
return

# Display each order with date and time


Label(see_win, text="----------------------------------------------",
bg="#fffaf0").pack()
for item_name, qty, price, o_date, o_time in orders:
Label(
see_win,
text=f"{o_date} {o_time} | {item_name} x{qty} = ₹{price}",
bg="#fffaf0",
anchor="w"
).pack(anchor="w", padx=30)
Label(see_win, text="----------------------------------------------",
bg="#fffaf0").pack()

Button(see_win, text="Show Orders", command=fetch_orders, bg="#4CAF50",


fg="white").pack(pady=10)

# --------- BUTTONS ----------


Button(cust_win, text="View Menu", command=view_menu, width=20, bg="#4CAF50",
fg="white").pack(pady=10)
Button(cust_win, text="Place Order", command=place_order, width=20,
bg="#FF9800", fg="white").pack(pady=10)
Button(cust_win, text="See My Orders", command=see_orders, width=20,
bg="#2196F3", fg="white").pack(pady=10)

# ---------- MAIN ROLE SELECTION ----------


Button(root, text="Admin (Staff)", command=admin_login, width=20, bg="#4CAF50",
fg="white").pack(pady=10)
Button(root, text="Customer", command=customer_panel, width=20, bg="#2196F3",
fg="white").pack(pady=10)

[Link]()

You might also like