0% found this document useful (0 votes)
38 views6 pages

Sweet Shop Management Without Ui Codes

source code

Uploaded by

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

Sweet Shop Management Without Ui Codes

source code

Uploaded by

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

import mysql.

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
)
""")

# Insert initial data if tables are empty


cur.execute("SELECT COUNT(*) FROM menu")
if cur.fetchone()[0] == 0:
cur.executemany("""
INSERT INTO menu (sno, products, cost) VALUES (%s, %s, %s)
""", [
(1, 'Cake', 50),
(2, 'Pastry', 20),
(3, 'Milk', 60),
(4, 'Butter', 20),
(5, 'Cheese', 30)
])
cur.execute("SELECT COUNT(*) FROM vip")
if cur.fetchone()[0] == 0:
cur.executemany("""
INSERT INTO vip (sno, varieties) VALUES (%s, %s)
""", [
(1, 'Vanilla'),
(2, 'Chocolate'),
(3, 'Strawberry'),
(4, 'Butter_scotch')
])

cur.execute("SELECT COUNT(*) FROM worker")


if cur.fetchone()[0] == 0:
cur.executemany("""
INSERT INTO worker (sno, name, salary) VALUES (%s, %s, %s)
""", [
(1, 'Prashanna', 12364),
(2, 'Hem', 1234),
(3, 'SIG', 23459),
(4, 'Srini', 8987)
])

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 handle_admin_choice(choice, cur, con):


if choice == 1:
add_item(cur, con)
elif choice == 2:
view_items(cur)
elif choice == 3:
update_cost(cur, con)
elif choice == 4:
add_worker(cur, con)
elif choice == 5:
view_workers(cur)
elif choice == 6:
update_worker_salary(cur, con)
elif choice == 7:
delete_item(cur, con)
elif choice == 8:
fire_worker(cur, con)
elif choice == 9:
view_total_sales(cur)
else:
print("Invalid choice")

def add_item(cur, con):


try:
sno = int(input("Enter sno: "))
product = input("Enter product name: ")
cost = int(input("Enter the cost: "))
cur.execute("INSERT INTO menu (sno, products, cost) VALUES (%s, %s, %s)",
(sno, product, cost))
con.commit()
print('Item added successfully')
except ValueError:
print("Invalid input. Please enter numbers for sno and cost.")

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]}")

def update_cost(cur, con):


try:
sno = int(input("Enter sno of the product: "))
adjustment_amount = int(input("Enter the amount to be adjusted: "))
print("1: Increase cost")
print("2: Decrease cost")
choice = int(input("Enter your choice: "))

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 add_worker(cur, con):


try:
sno = int(input("Enter sno: "))
name = input("Enter name: ")
salary = int(input("Enter salary: "))
cur.execute("INSERT INTO worker (sno, name, salary) VALUES (%s, %s, %s)",
(sno, name, salary))
con.commit()
print("Worker added successfully")
except ValueError:
print("Invalid input. Please enter numbers for sno and salary.")

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 update_worker_salary(cur, con):


name = input("Enter the name of the employee: ")
try:
amount = int(input("Enter the amount to be adjusted: "))
choice = int(input("Choose 1 to increase, 2 to decrease: "))
if choice == 1:
cur.execute("UPDATE worker SET salary = salary + %s WHERE name = %s",
(amount, name))
elif choice == 2:
cur.execute("UPDATE worker SET salary = salary - %s WHERE name = %s",
(amount, name))
else:
print("Invalid choice")
return
con.commit()
print("Worker salary updated successfully")
view_workers(cur)
except ValueError:
print("Invalid input. Please enter numbers for amount and choice.")

def delete_item(cur, con):


try:
sno = int(input("Enter the serial number of the item to delete: "))
cur.execute("DELETE FROM menu WHERE sno = %s", (sno,))
con.commit()
print("Item deleted successfully")
view_items(cur)
except ValueError:
print("Invalid input. Please enter a number for sno.")

def fire_worker(cur, con):


try:
sno = int(input("Enter the serial number of the worker to fire: "))
cur.execute("DELETE FROM worker WHERE sno = %s", (sno,))
con.commit()
print("Worker fired successfully")
view_workers(cur)
except ValueError:
print("Invalid input. Please enter a number for sno.")

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}")

def customer_order(cur, con):


name = input("Enter your name: ")
phone = input("Enter your phone number: ")
print('1: View Menu')
print('2: Order an item')
try:
choice = int(input('Enter your choice: '))

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.")

def process_order(cur, con, name, phone):


cur.execute("SELECT * FROM menu")
items = cur.fetchall()
print("Available items:")
for item in items:
print(f"{item[0]}: {item[1]} - cost {item[2]}")

try:
sno = int(input("Enter serial number of the item to buy: "))
qty = int(input("Enter quantity: "))

cur.execute("SELECT cost FROM menu WHERE sno = %s", (sno,))


result = cur.fetchone()
if result:
cost = result[0]
total_amount = qty * cost
print(f"Total amount: {total_amount}")
print("YOUR BILL")
print(f"Customer's name: {name}")
print(f"Contact no.: {phone}")
print(f"Item serial no: {sno}")
print(f"Quantity: {qty}")
print(f"Total amount: {total_amount}")
print("THANK YOU FOR ORDERING!")
print(f"Date: {datetime.now()}")

# Record the sale


cur.execute("INSERT INTO sales (sno, quantity, total_amount, sale_date)
VALUES (%s, %s, %s, %s)", (sno, qty, total_amount, datetime.now()))
con.commit()
else:
print("Invalid item serial number")
except ValueError:
print("Invalid input. Please enter numbers for serial number and
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()

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy