0% found this document useful (0 votes)
7 views31 pages

Import Pandas As Pd2

Uploaded by

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

Import Pandas As Pd2

Uploaded by

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

import pandas as pd

import mysql.connector
from datetime import datetime
from tabulate import tabulate
import matplotlib.pyplot as plt

#Connecting to MySQL database


mydb=mysql.connector.connect(host='localhost',
user='root',
password='root',
database='restrnt102'
);
mycursor=mydb.cursor()

#Only for the menu table/ displaying it


def only_item_menu():
query="""select
item_ID,Category,Item_name,description,price,item_type
from menu_items where available='yes';"""
mycursor.execute(query)
data=mycursor.fetchall()

header=['Item_Id','Category','Item_Name','Description','Pri
ce(₹)','Item Type']
print(tabulate(data,header,tablefmt='pretty'))

def menu_items():
while True:
print("\n")
print(" ~~~~~~~~~~~~~~~~~~
")
print("┍<<-------------->>| ITEMS MENU |
<<-------------->>┒ ")
print("| ~~~~~~~~~~~~~~~~~~
| ")

print("""
1.Whole Menu
2. By Item type (VEG/NON VEG)
3. By category(Appetizers/Main Courses/
Breads/Desserts/Beverages)
4. Exit""")

userinput=input("\n-->>| Enter Your Choice: ")


if userinput=="1":
only_item_menu()
elif userinput=="2":
preference=input("Enter Your Preference (Veg/Non
veg): ").strip()

if preference.lower() in ['veg','non veg','nonveg']:


query="""select
item_ID,Category,Item_name,description,price,item_type
from menu_items where item_type=%s and
available='yes';"""
mycursor.execute(query,(preference,))
data=mycursor.fetchall()
header=['Item_Id','Category','Item_Name','Description','Pri
ce(₹)','Item Type']
print(tabulate(data,header,tablefmt='pretty'))

else:
print(" Invalid Item Type...")
elif userinput=="3":
print("\n Searching by category...")
category=input("--->>Enter Category: ").strip()

if category.lower() in
['appetizers','maincourses','main
courses','desserts','beverages','breads']:
q="""select
item_ID,Category,Item_name,description,price,item_type
from menu_items where category=%s and
available='yes';"""

mycursor.execute(q,(category,))
data=mycursor.fetchall()
cols=['Item_Id','Category','Item_Name','Description','Price(
₹)','Item_type']
print(tabulate(data,headers=cols,tablefmt='pretty'))
else:
print(" Invalid Category!!!")
elif userinput=="4":
print("-->>Exiting...")
break
else:
print(" Invalid Option!")

def place_order():
print(" Placing an Order...")
mobile_no = input(" >>Enter Your Mobile no. :")

if mobile_no.isdigit() and len(mobile_no) == 10:


print("Mobile Number Valid")
only_item_menu()
order_details = []
order_total = 0
mycursor.execute("""
SELECT order_id, total_amount
FROM orders
WHERE mobile = %s AND DATE(order_date) =
DATE(NOW())
""", (mobile_no,))
existing_order = mycursor.fetchone()
if existing_order:
last_id = existing_order[0]
order_total = existing_order[1]
else:
mycursor.execute("""
INSERT INTO orders (order_date, mobile,
total_amount)
VALUES (NOW(), %s, 0);
""", (mobile_no,))
mydb.commit()
last_id = mycursor.lastrowid

if last_id is None:
print("Error: Failed to retrieve a valid order ID.
Please try again.")
while True:
item_id = int(input(" >>Enter the Item ID to order
(or 0 to finish): "))
if item_id == 0:
break

else:
quantity = int(input(" >>Enter
Quantity to order :"))
mycursor.execute("SELECT item_name,
ROUND(price, 2) FROM menu_items WHERE item_id
= %s and available='yes';", (item_id,))
item = mycursor.fetchone()

if item:
item_name, price = item
total_price = float(price) * quantity

order_details.append([item_name,
price, quantity, total_price])
order_total += total_price

mycursor.execute("""
INSERT INTO order_items (order_id,
item_id, quantity, price, total_price)
VALUES (%s, %s, %s, %s, %s);
""", (last_id, item_id, quantity, price,
total_price))

else:
print(""" Item ID not found. Please
enter a valid ID OR Item Not Available """)
mycursor.execute("UPDATE orders SET
total_amount = %s WHERE order_id = %s;",
(order_total, last_id))

mycursor.execute("""
SELECT SUM(total_amount),
COUNT(order_id)
FROM orders
WHERE DATE(order_date) = DATE(NOW());
""")
daily_total_sales, daily_total_orders =
mycursor.fetchone()
mycursor.execute("SELECT 1 FROM
sales_reports WHERE DATE(report_date) =
DATE(NOW());")
if mycursor.fetchone():
mycursor.execute("""
UPDATE sales_reports
SET total_sales = %s, total_orders = %s
WHERE DATE(report_date) =
DATE(NOW());
""", (daily_total_sales, daily_total_orders))
else:
mycursor.execute("""
INSERT INTO sales_reports (report_date,
total_sales, total_orders)
VALUES (NOW(), %s, %s);
""", (daily_total_sales, daily_total_orders))

mydb.commit()

# Displaying the order summary


if order_details:
print("\n >>Order Summary:")
headers = ['Item Name', 'Price (₹)',
'Quantity', 'Total Price (₹)']
print(tabulate(order_details, headers,
tablefmt='pretty'))
else:
print(" >>No item ordered!")

else:
print("Invalid Mobile Number")

def generate_bill():
print("\n")
print("
~~~~~~~~~~~~~~~~~~~~~~~~ ")
print("┍<<-------------->>| BILL GENERATION |
<<-------------->>┒ ")
print("|
~~~~~~~~~~~~~~~~~~~~~~~~ | ")

mobileno = int(input("--->>| Enter Mobile no.: "))


if len(str(mobileno)) != 10 :
print("!!| Invalid phone number! It must be a 10-digit
number.|!!")
return

mycursor.execute("SELECT mobile FROM orders WHERE


mobile = %s;", (mobileno,))
data = mycursor.fetchall()

while True:
if data:
print(" -------------------------------------- ")
print(" 1. Today's Bill 2. Previous Bill ")
print(" 3. Exit")

userinput = input("--->>| Enter Your choice : ")

# Define the common query to fetch bill details for


today's or previous orders
if userinput == "1":
query = """
SELECT m.item_name, o.quantity, m.price,
o.total_price, DATE(r.order_date)
FROM order_items o
JOIN orders r ON r.order_id = o.order_id
JOIN menu_items m ON m.item_id = o.item_id
WHERE r.mobile = %s
AND DATE(r.order_date) = CURDATE();
"""

total_query = """
SELECT SUM(total_price)
FROM order_items o
JOIN orders r ON r.order_id = o.order_id
WHERE r.mobile = %s AND DATE(r.order_date)
= CURDATE();
"""

elif userinput == "2":


query = """
SELECT m.item_name, o.quantity, m.price,
o.total_price, DATE(r.order_date)
FROM order_items o
JOIN orders r ON r.order_id = o.order_id
JOIN menu_items m ON m.item_id = o.item_id
WHERE r.mobile = %s
AND DATE(r.order_date) < CURDATE();
"""

total_query = """
SELECT SUM(total_price)
FROM order_items o
JOIN orders r ON r.order_id = o.order_id
WHERE r.mobile = %s AND DATE(r.order_date)
< CURDATE();
"""
elif userinput=="3":
print(" >>Exiting Bill Generation...")
break

else:
print(" >>Invalid Choice. Try again later")
return

mycursor.execute(query, (mobileno,))
bill = mycursor.fetchall()

if bill:
mycursor.execute(total_query, (mobileno,))
subtotal = mycursor.fetchone()[0]

if subtotal is not None:


gst_amt = subtotal * 5 / 100 # Standard GST
imposed on billing: 5%
subtotal += gst_amt # Total amount after
GST

# Get the current date


mycursor.execute("SELECT DATE(NOW());")
current_date = mycursor.fetchone()[0]
formatted_date = current_date.strftime("%d-
%m-%Y")
print("-------- TAX INVOICE ---------")
print("\nDate:", formatted_date)

# Print the bill summary


print(tabulate(bill, headers=['Particulars',
'Qty', 'Rate', 'Amount', 'Order date'], tablefmt='plain'))
print(' ---------------------')
print(" Sub Total: ₹", subtotal -
gst_amt)
print(" GST @5%: ₹", gst_amt)
print("----------------------------------------------")
print(f" Total amount : ₹{subtotal}\n")

else:
print("No orders found for the selected date
range")

else:
print("No orders found for this mobile number.")

else:
print("No orders found for this mobile number.") #
This is the fallback if no data is returned
break

def add_item():
print("Adding new Menu item...")
category=input("Enter the category to be
entered :")
item_name=input("Enter Item Name :")
description=input("Enter Description :")
price=float(input("Enter Item Price :"))
if price<=0:
print("Price cannot be zero or negative.")
return

item_type=input("Is This Item Vegetarian?


(yes/no) :")
if item_type.lower()=='yes':
item_type='VEG'
elif item_type.lower()=='no':
item_type='NON VEG'
else:
print('Invalid Choice.try again later')
availability="Yes" #default to available

L = [{
'Category': category,
'Item_Name': item_name,
'Description': description,
'Price(₹)': price,
'Item_type': item_type,
'Available': availability
}]

df=pd.DataFrame(L,columns=['Category','Item_Nam
e','Description','Price(₹)','Item_type','Available'])
print(tabulate(df,headers='keys', tablefmt='grid',
showindex=False))
choice=input("Is this The Item to be Added
(Yes/No) :")
if choice.lower()=='yes':
query = "INSERT INTO menu_items (category,
item_name, description, price, item_type, available)
VALUES (%s, %s, %s, %s, %s, %s)"
val = (category, item_name, description, price,
item_type, availability)
mycursor.execute(query, val)
mydb.commit()
print("New item added successfully.")
elif choice.lower()=='no':
admin_menu()
else:
print("Invalid Option!!")
#defining updatation of item
def update_menu():
item_id=input("\nEnter Item Id to be updated :")

mycursor.execute("Select *from menu_items


where item_id= %s", (item_id,))
check1= mycursor.fetchone()
if check1:
print("\nWhat Do You want to Update")
print("\n1.Category")
print("2.Price")
print("3.Availability")

userinput=input("Select an Option :")

if userinput=="1":
category=input("Enter new category :")

if category.strip().lower() in
['appetizers','breads','beverages','desserts','main
courses']:
query="Select*from menu_items where
item_id=%s;"
val=(item_id,)
mycursor.execute(query,val)
data=mycursor.fetchone()
header=['Item_Id','Category','Item_Name','Descripti
on','Price(₹)','Item_type','Available']

df=pd.DataFrame([data],columns=header)
df['Category']=category
print(tabulate(df, headers='keys',
tablefmt='grid', showindex=False))
print("\nIs The data inserted correct.
(yes/no): ")

choice=input("Enter a Choice: ")


if choice.lower()=='yes':
query="update menu_items set
category=%s where item_id=%s;"
val=(category,item_id)
mycursor.execute(query,val)
mydb.commit()
print("Updatation Completed...")

elif choice.lower()=='no':
update_menu()
else:
print("Not a valid Option!")
admin_menu()
else:
print("Invalid Category")
elif userinput=="2":
price=int(input("Enter New Price :"))

query="Select*from menu_items where


item_id=%s;"
val=(item_id,)
mycursor.execute(query,val)
data=mycursor.fetchone()
header=['Item_Id','Category','Item_Name','Description','Pri
ce(₹)','Item_type','Available']
df=pd.DataFrame([data],columns=header)
df['Price(₹)']=price
print(tabulate(df, headers='keys', tablefmt='grid',
showindex=False))
print("\nIs The data inserted correct.(yes/no): ")

choice=input("Enter a Choice: ")

if choice.lower()=='yes' and price>0:


query="update menu_items set price=%s where
item_id=%s;"
val=(price,item_id)
mycursor.execute(query,val)
mydb.commit()
print("Updatation Completed...")

elif choice.lower()=='no':
update_menu()

else:
print("Price Cannot be Zero or Negative")

elif userinput=="3":
availability=input("Is it Available? (yes/no) :")
if availability.strip().lower() in ['yes','no']:
query="Select*from menu_items where
item_id=%s;"
val=(item_id,)
mycursor.execute(query,val)
data=mycursor.fetchone()
header=['Item_Id','Category','Item_Name','Description','Pri
ce(₹)','item_id','Available']
df=pd.DataFrame([data],columns=header)
df['Available']=availability
print(tabulate(df, headers='keys',
tablefmt='grid', showindex=False))
choice=input("Is The data inserted
correct.(yes/no): ")
if choice.lower()=='yes' and
availability.lower()=='yes':
query="update menu_items set
available='yes' where item_id=%s;"
val=(item_id,)
mycursor.execute(query,val)
mydb.commit()
print("\nUpdatation Completed...")

elif choice.lower()=='yes' and


availability.lower()=='no':
query="update menu_items set
available='no' where item_id=%s;"
val=(item_id,)
mycursor.execute(query,val)
mydb.commit()
print("\nUpdatation Completed...")

elif choice.lower()=='no':
update_menu()
else:
print("Invalid Item Type")
else:
print("Invalid Option!!")
else:
print("Invalid Item Id ...")

def remove_item():
item_id=int(input("Enter Item Id to be
deleted :"))
query="Select*from menu_items where item_id=
%s;"
val=(item_id,)
mycursor.execute(query,val)
data=mycursor.fetchone()

if data:
header=['Item_Id','Category','Item_Name','Descripti
on','Price(₹)','Available']
print(tabulate([data],header,tablefmt='pretty'))

choice=input("\nIs The data to be deleted is


correct.\nEnter a Choice (yes/no): ")

if choice.lower()=='yes':
query="update menu_items set
available='no' where item_id=%s;"
val=(item_id,)
mycursor.execute(query,val) #Executing
the delete query
mydb.commit()

elif choice.lower()=='no':
admin_menu()

else:
print("Invalid Input")
else:
print("Invalid Item Id.")

def weekly_sales():
year= int(input(" -->>Enter Year : "))
mycursor.execute("select year(now());")
today=mycursor.fetchone()[0]
if int(year)>=today:
query = """
SELECT YEAR(report_date) AS sale_year,
WEEK(report_date) AS sale_week,
SUM(total_sales) AS weekly_total_sales
FROM sales_reports
where year(report_date) = %s
GROUP BY sale_year, sale_week
ORDER BY sale_year, sale_week;
"""
mycursor.execute(query,(year,))
weekly_sales = mycursor.fetchall()

if weekly_sales:
col = ['Sale_Year', 'Sale_Week', 'Total_Sales']
d_sales = pd.DataFrame(weekly_sales,
columns=col)

sale_dates = []
for i in range(len(d_sales)):
year = d_sales.loc[i, 'Sale_Year']
week = d_sales.loc[i, 'Sale_Week']
sale_date = datetime.strptime(f"{year}-
W{week}-1", "%Y-W%W-%w")
sale_dates.append(sale_date)
d_sales['Sale_Date'] = sale_dates

d_sales['Sale_Date_Str'] =
d_sales['Sale_Date'].dt.strftime('Week %U-%b-%Y')

print(tabulate(d_sales[['Sale_Date_Str',
'Total_Sales']], headers=['Sale Date', 'Total Sales'],
tablefmt='pretty'))
print("\n")

d_sales.plot(x='Sale_Date_Str',
y='Total_Sales', kind='bar', color='skyblue',
linewidth=2, rot=30)
plt.title('Weekly Sales')
plt.xlabel('Sale Date')
plt.ylabel('Total Sales')
plt.show()
else:
print("No Weekly Sales Record")
else:
print("Invalid Year")
return
def weekly_orders():
year= int(input(" -->>Enter Year : "))
mycursor.execute("select year(now());")
today=mycursor.fetchone()[0]
if int(year)>=today:
query="""select year(report_date) as
sale_year,week(report_date) as sale_week,
sum(total_orders) as total_orders
from sales_reports
where year(report_date) = %s
GROUP BY sale_year, sale_week
order by sale_year,sale_week;"""
mycursor.execute(query,(year,))
weekly_orders = mycursor.fetchall()

if weekly_orders:
col = ['Sale_Year', 'Sale_Week',
'Total_Orders']
d_sales = pd.DataFrame(weekly_orders,
columns=col)

d_sales['Total_Orders'] =
pd.to_numeric(d_sales['Total_Orders'])

sale_dates = []
for i in range(len(d_sales)):
year = d_sales.loc[i, 'Sale_Year']
week = d_sales.loc[i, 'Sale_Week']
sale_date = datetime.strptime(f"{year}-
W{week}-1", "%Y-W%U-%w")
sale_dates.append(sale_date)

d_sales['Sale_Date'] = sale_dates

d_sales['Sale_Date_Str'] =
d_sales['Sale_Date'].dt.strftime('Week %U-%b-%Y')

print(tabulate(d_sales[['Sale_Date_Str',
'Total_Orders']], headers=['Sale Date', 'Total
Orders'], tablefmt='pretty'))
print("\n")

d_sales.plot(x='Sale_Date_Str',
y='Total_Orders', kind='bar', color='skyblue',
linewidth=2, rot=30)
plt.title('Weekly Orders')
plt.xlabel('Sale Date')
plt.ylabel('Total Orders')
plt.show()

else:
print("No Weekly order Record")
else:
print("Invalid Year")
return
def monthly_sales():
year= int(input(" -->>Enter Year : "))
mycursor.execute("select year(now());")
today=mycursor.fetchone()[0]
if int(year)>=today:
query="""select year(report_date) as
sale_year,MONTH(report_date) as sale_month,
sum(total_sales) as total_sales
from sales_reports
where year(report_date) = %s
GROUP BY sale_year, sale_month
order by sale_year,sale_month;"""
mycursor.execute(query,(year,))
monthly_sales=mycursor.fetchall()

if monthly_sales:
col = ['Sale_Year', 'Sale_Month',
'Total_Sales']
d_sales = pd.DataFrame(monthly_sales,
columns=col)
d_sales['Total_Sales'] =
pd.to_numeric(d_sales['Total_Sales'])

sale_dates = []
for i in range(len(d_sales)):
year = d_sales.loc[i, 'Sale_Year']
month = d_sales.loc[i, 'Sale_Month']
sale_date = datetime.strptime(f"{year}-
{month}-1","%Y-%m-%d")
sale_dates.append(sale_date)

d_sales['Sale_Date'] = sale_dates

d_sales['Sale_Date_Str'] =
d_sales['Sale_Date'].dt.strftime('%b-%Y' )

print(tabulate(d_sales[['Sale_Date_Str',
'Total_Sales']], headers=['Sale Date', 'Total Sales'],
tablefmt='pretty'))
print("\n")

d_sales.plot(x='Sale_Date_Str',
y='Total_Sales', kind='bar', color='skyblue',
linewidth=2, rot=45)
plt.title('Monthly Sales')
plt.xlabel('Sales Date')
plt.ylabel('Total Sales(₹)')
plt.show()

else:
print("No Monthly Sales Record ")
else:
print("Invalid Year")
return

def monthly_orders():
year= int(input(" -->>Enter Year : "))
mycursor.execute("select year(now());")
today=mycursor.fetchone()[0]
if int(year)>=today:
query="""select Year(report_date) as
sale_year,month(report_date) as sale_month,
sum(total_orders) as total_orders
from sales_reports
where year(report_date) = %s
GROUP BY sale_year, sale_month
order by sale_year,sale_month;"""
mycursor.execute(query,(year,))
monthly_orders = mycursor.fetchall()

if monthly_orders:
col = ['Sale_Year', 'Sale_Month',
'Total_Orders']
d_sales = pd.DataFrame(monthly_orders,
columns=col)
d_sales['Total_Orders'] =
pd.to_numeric(d_sales['Total_Orders'])

sale_dates = []
for i in range(len(d_sales)):
year = d_sales.loc[i, 'Sale_Year']
month = d_sales.loc[i, 'Sale_Month']
sale_date = datetime.strptime(f"{year}-
{month}-1","%Y-%m-%d")
sale_dates.append(sale_date)

d_sales['Sale_Date'] = sale_dates

d_sales['Sale_Date_Str'] =
d_sales['Sale_Date'].dt.strftime('%b-%Y' )

print(tabulate(d_sales[['Sale_Date_Str',
'Total_Orders']], headers=['Sale Date', 'Total
Sales'], tablefmt='pretty'))
print("\n")

d_sales.plot(x='Sale_Date_Str',
y='Total_Orders', kind='bar', color='skyblue',
linewidth=2, rot=45)
plt.title('Monthly Orders')
plt.xlabel('Sales Date')
plt.ylabel('Total Orders')
plt.show()

else:
print("No Monthly Order Record")
else:
print("Invalid year")
return
def most_ordered():
query="SELECT m.item_name as name,\
sum(quantity) as total_Quantity\
from menu_items m,order_items o\
where m.item_id=o.item_id\
group by m.item_id;"
mycursor.execute(query)
data=mycursor.fetchall()

if data:
col=['Item_Name','Quantity_ordered']
df=pd.DataFrame(data,columns=col)

#plt.figure(figsize=(10, 8))

plt.pie(df['Quantity_ordered'],labels=df['Item_Name
'],autopct='%1.1f%
%',shadow=True,startangle=160,
textprops={'fontsize': 7,'weight':'bold'},
wedgeprops={'linewidth': 1, 'edgecolor': 'white'})
plt.title("Total Quantity Ordered for Each
Item")
#plt.axis('equal') # Equal aspect ratio ensures
the pie chart is circular.
plt.show()

else:
print("No Data Found")

def Daily_sales():
report_date=input("--->>| Enter Report
Date(YYYY-MM-DD) :" )
q="select*from sales_reports where
date(report_date)=%s;"
mycursor.execute(q,(report_date,))
data=mycursor.fetchall()

if data:
print(tabulate(data,headers=[‘Report
ID’,'Report Date','Total Sales(₹)','Total
Order'],tablefmt='pretty'))

else:
print(f"No data Found for report date:
{report_date}")

def Avg_revenue():
query="select
count(order_item_id),sum(total_price),round(avg(to
tal_price)) Average from order_items;"

mycursor.execute(query)
AVG=mycursor.fetchone()

if AVG:
print(f"Average Revenue Per Customer is:₹
{AVG}")
print(">> Details:")
print(tabulate([AVG],headers=['Total_orders','Total_
Sales','Average Revenue'],tablefmt='pretty'))

else:
print("No Data Found")

def Prime_hours():
query="SELECT HOUR(order_date) AS Hour,\
COUNT(order_id) AS total_orders\
FROM orders\
group by HOUR(order_date)\
order by Hour;"

mycursor.execute(query)
Hours=mycursor.fetchall()

if Hours:
header=['Prime Hours','Total orders']
print(tabulate(Hours,headers=header,tablefmt='pr
etty'))

col=['Prime Hours','Total orders']


df=pd.DataFrame(Hours,columns=col)

for i in range(len(df)):
df.loc[i, 'Prime Hours'] = str(df.loc[i, 'Prime
Hours']) + " O' Clock"

df.plot(x='Prime Hours',y='Total
orders',kind='bar',linewidth=2,rot=0)
plt.title('Prime Hours and Total Orders')
plt.xlabel('Total Orders Orders')
plt.ylabel('Hours')
plt.show()

else:
print("NO DATA FOUND")
def Sales_report_menu():
while True:
print("\n1. Total Weekly Sales 2. Total
monthly Sales")
print("3. Daily sales 4. Exit")

userinput=input("\nEnter your Selection: ")


if userinput=="1":
weekly_sales()

elif userinput=="2":
monthly_sales()

elif userinput=="3":
Daily_sales()

elif userinput=="4":
print(" >>Exiting...")
break

else:
print(" >>Invalid Option")

def Orders_report_menu():
while True:
print("1.Total Weekly Orders 2.Total
Monthly Orders")
print("3.Most ordered Items 4.Exit")

userinput=input("\n >>Enter your Selection:


")

if userinput=="1":
weekly_orders()

elif userinput=="2":
monthly_orders()

elif userinput=="3":
most_ordered()

elif userinput=="4":
print("\n >>Exiting...")
break
else:
print("\n >>Invalid Option")

def sales_report_menu():
while True:
print("\n")
print("
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
")
print("┍<<--------->>| REPORT MANAGEMENT
MENU |<<-------->>┒ ")
print("|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| ")
print("| 1. Sales Report 2. Orders
Report | ")
print("| 3. Revenue per customer 4. Prime
Hours report | ")
print("| 5. Exit |\n
")
userinput=input("\n--->>| Enter your Selection:
")

if userinput=="1":
print("<<--->>| Sales Menu |<<--->>")
Sales_report_menu()

elif userinput=="2":
print("<<--->>| Orders Menu |<<--->>")
Orders_report_menu()
elif userinput=="3":
print("<<--->>| Average Revenue |<<---
>>")
Avg_revenue()

elif userinput=="4":
Prime_hours()

elif userinput=="5":
print("\nExiting Report Menu...")
break

else:
print("\nInvalid selection")

def Admin_login():
username=input(" >>Enter Username :")
password=input(" >>Enter Password :")

if username=='abc' and password=='abc123':


print("Login successfull")
admin_menu()

else:
print("\nInvalid credentials. Access denied.")

def admin_menu():
while True:
print("\n")
print(" ~~~~~~~~~~~~~~~~~~~~
")
print("┍<<----------->>| Admin Menu |
<<----------->>┒ ")
print("| ~~~~~~~~~~~~~~~~~~~~
| ")
print("| 1. View Menu 2.Add Menu
Item | ")
print("| 3. Update Menu Item 4. Delete
Menu Item | ")
print("| 5. View Sales Reports 6.Exit Admin
Menu | ")

userinput=input("--->>| Select an Option :")

if userinput=="1":
menu_items()

elif userinput=="2":
add_item()

elif userinput=="3":
update_menu()

elif userinput=="4":
remove_item()

elif userinput=="5":
sales_report_menu()
elif userinput=="6":
break

else:
print('Invalid Option')

#Function to display main menu!!


def main_menu():
while True:
print("\n")
print("
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
")
print("┍<<------------->>| Welcome to ROYAL RASOI
|<<------------->>┒ ")
print("|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| ")
print("| 1. View Item Menu 2. Place Order
| ")
print("| 3.Generate Bill 4.Admin Login
| ")
print("| 5.Exit | ")

userinput=input("|---->>| Please enter Your choice :")

if userinput=="1":
menu_items() #Function to display menu
items

elif userinput=="2":
place_order() #Function to Place order

elif userinput=="3":
generate_bill() #function for generating bill

elif userinput=="4":
Admin_login() #Function for Admin
menu(Restricted)

elif userinput=="5":
print("Exiting The System...")
break

else:
print("Invalid option. Please try again.")

main_menu()
MySQL Database and
Tables
Database Name: Restrnt102

Tables in Restrnt102:

Desc menu_items;

Desc Order_items;
Desc Orders ;

Desc Sales_reports;

Select*from orders;
Select*from menu_items;

Select*from order_items;
Select*from sales_reports;
MySQL CODEs
Code for creating ‘restrnt102’ Database --

create database restrnt102;


use restrnt102;

Code for creating ‘menu_items’ Table --

create table menu_items(


item_id int auto_increment primary key,
category varchar(50) not null,
item_name varchar(100) not null,
description varchar(120) not null,
price decimal(10,2) not null,
item_type varchar(10) not null,
available varchar(10) default 'YES');

Code for creating ‘orders’ Table --

create table orders(


order_id int auto_increment primary key,
order_date datetime not null,
mobile char(10) not null,
total_amount float(10,2) not null);

Code for creating ‘order_items’ Table --

create table order_items(


order_item_id int auto_increment primary key,
order_id int not null,
item_id int not null,
quantity int not null,
price decimal(10,2) not null,
total_price float(10,2) not null,
foreign key (order_id) references orders(order_id),
foreign key (item_id) references menu_items(item_id));

Code for creating ‘sales_reports’ Table --

create table sales_reports(


report_id int auto_increment primary key,
report_date datetime not null unique,
total_sales float(10,2) not null,
total_orders int not null);
Code for Inserting values in ‘menu_items’ table--
INSERT INTO menu_items (category, item_name, description, price,
item_type) VALUES
-- Indian Appetizers
('Appetizers', 'Samosa', 'A crispy pastry filled with spiced potatoes and
peas', 99.00, 'VEG'),
('Appetizers', 'Paneer Tikka', 'Grilled paneer cubes marinated with spices
and yogurt', 250.00, 'VEG'),
('Appetizers', 'Chicken Seekh Kebab', 'Ground chicken spiced and grilled on
skewers', 300.00, 'NON VEG'),
('Appetizers', 'Hara Bhara Kebab', 'Spinach and green pea patties', 150.00,
'VEG'),
('Appetizers', 'Fish Amritsari', 'Crispy batter-fried fish', 280.00, 'NON VEG'),

-- Indian Vegetarian Main Courses


('Main Courses', 'Paneer Butter Masala', 'Paneer in a rich, creamy tomato-
based sauce', 450.00, 'VEG'),
('Main Courses', 'Chana Masala', 'Chickpeas cooked in a spiced tomato and
onion gravy', 220.00, 'VEG'),
('Main Courses', 'Vegetable Biryani', 'Basmati rice with mixed vegetables
and spices', 300.00, 'VEG'),
('Main Courses', 'Aloo Gobi', 'Potato and cauliflower cooked with spices',
200.00, 'VEG'),
('Main Courses', 'Palak Paneer', 'Spinach and paneer cooked in a spiced
curry', 350.00, 'VEG'),

-- Indian Non-Vegetarian Main Courses


('Main Courses', 'Butter Chicken', 'Chicken cooked in a creamy tomato
sauce', 480.00, 'NON VEG'),
('Main Courses', 'Lamb Rogan Josh', 'Tender lamb cooked with spices and
yogurt', 550.00, 'NON VEG'),
('Main Courses', 'Fish Curry', 'Fish fillets simmered in a coconut-based
curry', 400.00, 'NON VEG'),
('Main Courses', 'Dal Makhani', 'Slow-cooked black lentils with cream',
250.00, 'VEG'),
('Main Courses', 'Malai Kofta', 'Vegetable dumplings in creamy gravy',
350.00, 'VEG'),
('Main Courses', 'Mutton Biryani', 'Basmati rice cooked with marinated
mutton', 550.00, 'NON VEG'),

('Breads', 'Naan', 'Soft and fluffy Indian flatbread', 40.00, 'VEG'),


('Breads', 'Butter Naan', 'Indian flatbread brushed with butter', 50.00,
'VEG'),
('Breads', 'Garlic Naan', 'Indian flatbread topped with garlic', 60.00, 'VEG'),
('Breads', 'Tandoori Roti', 'Whole wheat flatbread cooked in a tandoor',
30.00, 'VEG'),
('Breads', 'Chapati', 'Thin whole wheat Indian flatbread', 20.00, 'VEG'),
('Breads', 'Paratha', 'Layered, flaky Indian flatbread', 40.00, 'VEG'),
('Breads', 'Aloo Paratha', 'Paratha stuffed with spiced potatoes', 70.00,
'VEG'),
Code for Inserting values in ‘orders’ table-
INSERT INTO orders (order_id, order_date, mobile, total_amount)
VALUES
(1, '2024-12-29 00:52:09', '9876543092', 540.00),
(2, '2024-10-01 12:30:45', '9876543210', 980.00),
(3, '2024-10-01 14:15:22', '9876543211', 550.00),
(4, '2024-10-01 16:45:10', '9876543212', 750.00),
(5, '2024-10-02 11:30:00', '9876543213', 320.00),
(6, '2024-10-02 13:00:30', '9876543214', 900.00),
(7, '2024-10-03 10:20:05', '9876543215', 1200.00),
(8, '2024-10-03 18:50:13', '9876543216', 600.00),
(9, '2024-10-04 17:25:10', '9876543217', 1300.00),
(10, '2024-10-05 09:10:40', '9876543218', 450.00),
(11, '2024-10-06 20:35:22', '9876543219', 950.00),
(12, '2024-11-01 13:45:12', '9876543220', 850.00),
(13, '2024-11-02 12:35:50', '9876543221', 700.00),
(14, '2024-11-03 19:00:12', '9876543222', 600.00),
(15, '2024-11-05 14:25:30', '9876543223', 1000.00),
(16, '2024-11-06 16:00:35', '9876543224', 750.00),
(17, '2024-11-10 11:10:15', '9876543225', 1100.00),
(18, '2024-11-12 17:45:50', '9876543226', 400.00),
(19, '2024-11-15 12:30:20', '9876543227', 500.00),
(20, '2024-12-01 10:00:10', '9876543228', 1000.00),
(21, '2024-12-02 14:10:00', '9876543229', 1200.00);

Code for Inserting values in ‘sales_reports’ table-


INSERT INTO sales_reports (report_id, report_date, total_sales,
total_orders)
VALUES
(1, '2024-10-01 00:00:00', 2790.00, 3),
(2, '2024-10-02 00:00:00', 1350.00, 2),
(3, '2024-10-03 00:00:00', 540.00, 2),
(4, '2024-10-04 00:00:00', 300.00, 1),
(5, '2024-10-05 00:00:00', 550.00, 1),
(6, '2024-10-06 00:00:00', 220.00, 1),
(7, '2024-11-01 00:00:00', 40.00, 1),
(8, '2024-11-02 00:00:00', 140.00, 1),
(9, '2024-11-03 00:00:00', 120.00, 1),
(10, '2024-11-05 00:00:00', 200.00, 1),
(11, '2024-11-06 00:00:00', 100.00, 1),
(12, '2024-11-10 00:00:00', 200.00, 1),
(13, '2024-11-12 00:00:00', 80.00, 1),
(14, '2024-11-15 00:00:00', 700.00, 1),
(15, '2024-12-01 00:00:00', 50.00, 1),
(16, '2024-12-02 00:00:00', 150.00, 1),
(17, '2024-12-29 00:00:00', 540.00, 1);
Code for Inserting values in ‘order_items’ table-
INSERT INTO order_items (order_item_id, order_id, item_id, quantity,
price, total_price) VALUES
(1, 1, 25, 4, 100.00, 400.00),
(2, 1, 35, 2, 70.00, 140.00),
(3, 2, 2, 2, 250.00, 500.00),
(4, 2, 5, 1, 280.00, 280.00),
(5, 3, 8, 2, 300.00, 600.00),
(6, 3, 19, 1, 60.00, 60.00),
(7, 4, 6, 3, 450.00, 1350.00),
(8, 5, 14, 1, 250.00, 250.00),
(9, 6, 16, 2, 550.00, 1100.00),
(10, 7, 11, 1, 480.00, 480.00),
(11, 8, 20, 2, 30.00, 60.00),
(12, 9, 3, 1, 300.00, 300.00),
(13, 10, 12, 1, 550.00, 550.00),
(14, 11, 7, 1, 220.00, 220.00),
(15, 12, 21, 2, 20.00, 40.00),
(16, 13, 23, 2, 70.00, 140.00),
(17, 14, 17, 3, 40.00, 120.00),
(18, 15, 9, 1, 200.00, 200.00),
(19, 16, 25, 1, 100.00, 100.00),
(20, 17, 28, 2, 100.00, 200.00),
(21, 18, 32, 1, 80.00, 80.00),
(22, 19, 10, 2, 350.00, 700.00),
(23, 20, 18, 1, 50.00, 50.00),
(24, 21, 26, 1, 150.00, 150.00);

You might also like