Thanks to visit codestin.com
Credit goes to www.scribd.com

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

Bakery Management - Py

This document contains code for a bakery management system that allows admin and customer functions. The code defines database tables for stock, purchases, and user login. It includes procedures for customers to view items, add items to a cart, view their bill, and make a purchase. For admins, it allows editing stock quantities and prices, adding/deleting items, viewing reports, and changing passwords. Sales reports can be generated by date, week, month, or year from the purchase data.

Uploaded by

Faizaan Alam
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)
36 views6 pages

Bakery Management - Py

This document contains code for a bakery management system that allows admin and customer functions. The code defines database tables for stock, purchases, and user login. It includes procedures for customers to view items, add items to a cart, view their bill, and make a purchase. For admins, it allows editing stock quantities and prices, adding/deleting items, viewing reports, and changing passwords. Sales reports can be generated by date, week, month, or year from the purchase data.

Uploaded by

Faizaan Alam
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 tabulate import tabulate
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

print("****************************************************************************
")
print("*
*")
print("* Welcome to Bakery Management System
*")
print("*
*")
print("****************************************************************************
")
#creating database

mydb=mysql.connector.connect(host="localhost",user="root",passwd="root")
mycursor=mydb.cursor()
mycursor.execute("create database if not exists pysales_inventory")
mycursor.execute("use pysales_inventory")
#creating required tables
mycursor.execute("create table if not exists stock(pcode varchar(25) primary
key,pname varchar(25) not null,quantity int not null,price int not null)")
mycursor.execute("create table if not exists purchase(odate date not null,phone_no
varchar(25) not null,pcode varchar(25) not null,amount int not null)")
mycursor.execute("create table if not exists login(username varchar(25) not
null,password varchar(25) not null)")
mycursor.execute("select * from login")#==>Empty

j=0
for i in mycursor:
admin,paswrd=i
j=1

if(j==0):
mycursor.execute("insert into login values('admin','root')")#=>1st time
if(j==1):
pass

condition="y"
total=0
ptotal=0
qtotal=0
while(condition=="y" or condition=="Y"):
print("________________________________")
print("1.Admin")
print("2.Customer")
print("3.Exit")
print("________________________________")
ch=int(input("Enter the choice:"))
total=0
ptotal=0
qtotal=0
#PROCEDURE FOR Buying
if(ch==2):
conditioni='y'
while(conditioni=='y' or conditioni=='Y'):
print("________________________________")
print("1. Item Bucket")
print("2. Payment")
print("3. View Available Items")
print("4. Go Back")
print("________________________________")

ch9=input("Enter your choice: ")


if(ch9=='1'):
cn2='y'
while(cn2=='y' or cn2=='Y'):

print("All information prompted are mandatory to be filled")


pno=str(input("Enter the customer-phoneno: "))
while(len(pno)!=10):
print("Please Enter 10 digit number")
pno=str(input("Enter the customer-phoneno: "))
pcode=str(input("Enter purchased Item code: "))
pquantity=int(input("Enter the purchased item quantity: "))

mycursor.execute("select * from stock where


pcode='{}'".format(pcode))

for i in mycursor:
pcode,pname,quantity,price=i
print(f"Name of the product {pname}")
print(f"price of the product{price}")
amount=int(price)*int(pquantity)
total+=int(amount)
qtotal+=int(pquantity)
netquan=int(quantity)-int(pquantity)
mycursor.execute("insert into purchase values(now(),'{}','{}',
{})".format(pno,pcode,amount))
mycursor.execute("update stock set quantity={} where
pcode='{}'".format(netquan,pcode))
mydb.commit()

print("Record inserted successfully")


cn2=input("Do You want to continue Buying?(y/n)")
elif(ch9=='2'):
print("
________________________________________________________________________")
print(f"|
|")
print(f"| \t\t\tBILL To Be Paid\t\t\t
|")
print(f"|
______________________________________________________________________|")
print(f"|
|")
print(f"|
|")
print(f"|\t\t Bill to be paid {total}
|")
print(f"|\t\t No of items ordered is {qtotal}
|")
print(f"|
|")
print(f"|
|")
print(f"|Thank You For Using Bakery Management System...
|")

print("_________________________________________________________________________")
elif(ch9=='3'):
mycursor.execute("select * from stock")
print("\n")
table=[]
headers=["ICODE","INAME","QUANTITY","PRICE"]
print("_______________")
for i in mycursor:
table.append(i)
print(tabulate(table, headers, tablefmt="fancy_grid"))
print("\n")
else:
break

#PROCEDURE FOR Editing Stock


elif(ch==1):
print("Admin")
pswrd=str(input("Enter the password"))
mycursor.execute("select * from login")
for i in mycursor:
user,password=i
if (pswrd==password):
ech='y'
while(ech=='y' or ech=='Y'):

print("________________________________")
print("1.Add New Item")
print("2.updating price")
print("3.update quantity")
print("4.Deleting Item")
print("5.Display All Items")
print("6.To change the password")
print("7.Sales Report")
print("8.Logout")
print("________________________________")
ech2=int(input("Enter the choice: "))
if(ech2==1):
pcode=str(input("Enter the product code: "))
pname=str(input("Enter the product name: "))
pq=int(input("Enter the product quantity: "))
pp=int(input("Enter the product price: "))
mycursor.execute("insert into stock values('{}','{}',{},
{})".format(pcode,pname,pq,pp))
mydb.commit()
print("record inserted successfully")
ech=str(input("Do you want to continue editing stock!!! Press
y/n "))
elif(ech2==2):
pcode=str(input("Enter the product code: "))
pp=int(input("Enter the new product price: "))
mycursor.execute("update stock set price={} where
pcode='{}'".format(pp,pcode))
mydb.commit()
print("record updated successfully")
ech=str(input("Do you want to continue editing stock!!! Press
y/n "))
elif(ech2==3):
pcode=str(input("Enter the product code: "))
pq=int(input("Enter the updated quantity: "))
mycursor.execute("update stock set quantity={} where
pcode='{}'".format(pq,pcode))
mydb.commit()
print("record updated successfully")
ech=str(input("Do you want to continue editing stock!!! Press
y/n "))
elif(ech2==4):
pcode=str(input("Enter the product code: "))
mycursor.execute("delete from stock where
pcode='{}'".format(pcode))
mydb.commit()
print("record Deleted successfully")
ech=str(input("Do you want to continue editing stock!!! Press
y/n "))
elif(ech2==5):
mycursor.execute("select * from Stock")
j=1
#print("| Sno. | PCode | Pname | PQuantity | Pprice |")
headers=["SR_No","PCode","PName","Quantity","Price"]
table=[]
for i in mycursor:
a,b,c,d=i
temp=[j,a,b,c,d]
table.append(temp)
j+=1
#print(f"| {j} | {code} | {name} | {quantity} | {price} |")
print(tabulate(table, headers, tablefmt="fancy_grid"))

elif(ech2==6):
oldpassword=str(input("Enter old Password: "))
newpassword=str(input("Enter new Password"))
mycursor.execute("update login set password='{}' where
password='{}'".format(newpassword,oldpassword))
mydb.commit()
print("Password Changed successfully")
ech=str(input("Do you want to continue editing stock!!! Press
y/n "))
elif(ech2==7):
ech3='y'
while(ech3=='y' or ech3=='Y'):
print("________________________________")
print("1.Daily Sales Report")
print("2.Weekly Sales Report")
print("3.Monthly quantity")
print("4.Annual Report")
print("5.Back Menu")
print("________________________________")
ech4=int(input("Enter the choice: "))
if(ech4==1):
df= pd.read_sql("select sum(amount) as amount,odate
from purchase group by odate;",mydb)
headers=df.columns
tables=df.values
print(tabulate(tables,headers,tablefmt="fancy_grid"))
plt.plot(df['odate'],df['amount'],marker='d',
color='red')
plt.xlabel('Order_Date')
plt.ylabel('Amount')
plt.show()
ech3=str(input("Do you want to continue!!! Press y/n
"))
elif(ech4==2):
#df= pd.read_sql("select * from
purchase;",mydb,index_col='odate',parse_dates=['odate'])
df2=pd.read_sql("select sum(amount) as
amount,month(odate),left(monthname(odate),3) as monthName, day(odate) as date from
purchase group by week(odate);",mydb,index_col=None)
print(df2)
#df1=df.amount.resample('W').sum()

lab=['Jan','Feb','Mar','Apr','May','Jun','July','Aug','Sep','Oct','Nov','Dec']
L=[]
for i in df2['monthName']:
if i in lab:
if i not in L:
L.append(i)
print(L)
y=np.arange(len(L))
plt.barh(y-0.3,df2['amount']
[0],color='red',label='week1',height=0.2)
plt.barh(y-0.1,df2['amount']
[1],color='yellow',label='week2',height=0.2)
plt.barh(y,df2['amount']
[2],color='green',label='week3',height=0.2)
plt.barh(y+0.1,df2['amount']
[3],color='blue',label='week4',height=0.2)
plt.barh(y+0.3,df2['amount']
[4],color='purple',label='extra days',height=0.2)
plt.yticks(y,L)
plt.legend()
plt.show()
ech3=str(input("Do you want to continue!!! Press y/n
"))
elif(ech4==3):
df= pd.read_sql("select sum(amount) as
amount,month(odate),left(monthname(odate),3) as monthName from purchase group by
month(odate);",mydb)
print(df)
headers=df.columns
tables=df.values

print(tabulate(tables,headers,tablefmt="fancy_grid"))
lab=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
L=[]
for i in df['monthName']:
if i in lab:
L.append(i)
y=np.arange(len(L))
plt.barh(y,df['amount'],
color='Purple',align='center')
plt.title('Month-Wise Report')
plt.ylabel('Month')
plt.yticks(y,L)
plt.xlabel('Amount')
#plt.legend(['Week1','Week2','Week3','Week4'])
plt.show()
ech3=str(input("Do you want to continue!!! Press
y/n "))
elif(ech4==4):
df= pd.read_sql("select sum(amount) as
amount,year(odate) as year from purchase group by year(odate);",mydb)
print(df)
headers=df.columns
tables=df.values

print(tabulate(tables,headers,tablefmt="fancy_grid"))
plt.plot(df['year'],df['amount'])
plt.title('Annual Report')
plt.xlabel('Year')
plt.ylabel('Amount')
#plt.legend(['Week1','Week2','Week3','Week4'])
plt.show()
ech3=str(input("Do you want to continue!!! Press
y/n "))
elif(ech4==5):
break
else:
break
elif(ech2==8):
break
else:
break

You might also like