Sweet Shop Management Without Ui Codes
Sweet Shop Management Without Ui Codes
connector
from datetime import datetime
def connect_to_database():
try:
con = mysql.connector.connect(host='localhost', user='VASU', passwd='VASU',
database='items')
if con.is_connected():
print("Connected to database")
return con
except mysql.connector.Error as err:
print(f"Error: {err}")
return None
def setup_database(con):
with con.cursor() as cur:
# Create tables if they don't exist
cur.execute("""
CREATE TABLE IF NOT EXISTS menu (
sno INT PRIMARY KEY,
products VARCHAR(20),
cost INT
)
""")
cur.execute("""
CREATE TABLE IF NOT EXISTS vip (
sno INT PRIMARY KEY,
varieties VARCHAR(20)
)
""")
cur.execute("""
CREATE TABLE IF NOT EXISTS worker (
sno INT PRIMARY KEY,
name VARCHAR(20),
salary INT
)
""")
cur.execute("""
CREATE TABLE IF NOT EXISTS sales (
id INT AUTO_INCREMENT PRIMARY KEY,
sno INT,
quantity INT,
total_amount INT,
sale_date DATETIME
)
""")
con.commit()
def display_menu():
print("
______________________________________________________________________________")
print("|....................
SWEET_SHOP_MANAGEMENT_SYSTEM ............................|")
print("|...............PROJECT FROM VASU BHARGAV AND
LAKSHAY .......................|")
print("
------------------------------------------------------------------------------")
def admin_login(cur):
username = input("USERNAME: ")
try:
password = int(input("ENTER PASSWORD: "))
except ValueError:
print("Password must be a number.")
return False
return username == "VASU" and password == 12460
def view_items(cur):
cur.execute("SELECT * FROM menu")
items = cur.fetchall()
print("Items in the shop:")
for item in items:
print(f"{item[0]}: {item[1]} - cost {item[2]}")
if choice == 1:
cur.execute("UPDATE menu SET cost = cost + %s WHERE sno = %s",
(adjustment_amount, sno))
elif choice == 2:
cur.execute("UPDATE menu SET cost = cost - %s WHERE sno = %s",
(adjustment_amount, sno))
else:
print("Invalid choice")
return
con.commit()
print("Item cost updated successfully")
view_items(cur)
except ValueError:
print("Invalid input. Please enter numbers for sno and adjustment amount.")
def view_workers(cur):
cur.execute("SELECT * FROM worker")
workers = cur.fetchall()
print("Workers in the shop:")
for worker in workers:
print(f"{worker[0]}: {worker[1]} - salary {worker[2]}")
def view_total_sales(cur):
cur.execute("SELECT SUM(total_amount) FROM sales")
total_sales = cur.fetchone()[0]
if total_sales is None:
total_sales = 0
print(f"Total Sales Amount: {total_sales}")
if choice == 1:
view_items(cur)
elif choice == 2:
process_order(cur, con, name, phone)
else:
print("Invalid choice")
except ValueError:
print("Invalid input. Please enter a number for choice.")
try:
sno = int(input("Enter serial number of the item to buy: "))
qty = int(input("Enter quantity: "))
def main():
con = connect_to_database()
if con is None:
return
setup_database(con)
display_menu()
try:
with con.cursor() as cur:
while True:
choice = int(input("\n\nPLEASE CHOOSE \n1 FOR ADMIN \n2 FOR
CUSTOMER \n3 FOR EXIT:\n"))
if choice == 3:
break
elif choice == 1:
if admin_login(cur):
print("Logged in as Admin")
print("1: Add item")
print("2: View items")
print("3: Update item cost")
print("4: Add worker")
print("5: View workers")
print("6: Update worker salary")
print("7: Delete item")
print("8: Fire worker")
print("9: View total sales")
try:
admin_choice = int(input("Enter your choice: "))
handle_admin_choice(admin_choice, cur, con)
except ValueError:
print("Invalid input. Please enter a number.")
else:
print("Invalid login credentials")
elif choice == 2:
customer_order(cur, con)
else:
print("Invalid choice")
except ValueError:
print("Invalid input. Please enter a number.")
finally:
con.close()
if __name__ == "__main__":
main()