0% found this document useful (0 votes)
8 views11 pages

Adobe Scan 11 Nov 2024

The document contains a Python script for managing a fashion store database, allowing users to add, edit, delete, view products, purchase items, and track sales. It utilizes MySQL for database interactions and includes functions for each operation, along with a menu-driven interface for user interaction. The code has several syntax errors and inconsistencies that need to be corrected for proper functionality.

Uploaded by

cadoyoy556
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)
8 views11 pages

Adobe Scan 11 Nov 2024

The document contains a Python script for managing a fashion store database, allowing users to add, edit, delete, view products, purchase items, and track sales. It utilizes MySQL for database interactions and includes functions for each operation, along with a menu-driven interface for user interaction. The code has several syntax errors and inconsistencies that need to be corrected for proper functionality.

Uploaded by

cadoyoy556
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
You are on page 1/ 11

Python code:

import os
import platform
import mysql.connector
Import pandas as pd
Import datetime

mydb=mysql .con nectar.connect(host="localhost",\


user="root",\
passwd="root",\
database="fashion")
mycursor=myd b.cursor()

def AddProduct():
L=()
stk=[)
pld=lnput("Enter the Product ID:")
L.append(pld)
IName=lnput("Enter the Product Name : ")

L.append(IName)
brnd=input("Enter the Product Brand Name : ")
L.append(brnd)
fr=input("Enter Male/Female/Kids:")
L.append(fr)
sn=input("Enter Winter/Summer:")
L.append(sn)
rate=lnt(lnput("Enter the Rates for Product :"))
L.append(rate)
product=(L)
sql="lnsert Into product
(product_id,PName,brand,Product_for,Season,rate)values(%s,%s,%s,%s,%s,%s)"
mycursor.execute(sql,product)
mydb.commit()
stk.append(pid)
stk.append(0)
stk.append("No")
st=(stk)
sql="lnsert Into stock(ltem_ld, lnstock, status) values(%s,%s,%s)"
mycursor.execute(sql,st)
mydb.commit()
print("One Product inserted ")

def EditProduct():
pid=input("Enter product ID to be edited: ")
sql="select • from product where product_id=%s"
ed=(pid,)
mycursor.execute(sql,ed)
res=mycursor.fetchall()
for x in res:
print(x)
print("")
fld=input("Enter the field which you want to edit: ")
val=input("Enter the value you want to set: ")
sql="Update product set"+ fld +"="'+val+ "' where product_id="' + pid + "'"
sq=sql
mycursor.execute(sqi)
print("Editing Don : ")
print("After correction the record is: ")
sql="select • from product where product_id=%s"
ed=(pid,)
mycursor.execute(sql,ed)
res=mycursor.fetchall()
for x in res:
print(x)
mydb.commit()

def DelProduct():
pid=input("Enter the Product)id to be deleted : ")
sql="delete from sales where item_id=%s"
id=(pid,)
mycursor.execute(sql,id)
mydb.commit()
sql="delete from purchase where item_id=%s"
mycursor.execute(sql,id)
mydb.commit()
sql="delete from stock where item_id=%s"
mycursor.execute(sql,id)
mydb.commit()
sql="delete from product where product_id=%s"
mycursor.execute(sql,id)
mydb.commit()
print("One Item Deleted")

def ViewProduct():
print("Display Menu: Select the category to display the data")
print("l. All Details")
print("2. Product Name:")
print("3. Product Brand:")
print("4. Product For:")
print("S. Product Season:")
print("6. Product ID:")
x=O
ch=int(input("Enter your choice to display: "))
if ch==l:
sql="select • from product"
mycursor.execute(sqi)
res=mycursor.fetchall()
for x in res:
print(x)
x=l
elif ch==2:
var='PName'
val=input("Enter the name of Product:")
elif ch==3:
var='brand'
val=input("Enter the name of Brand : ")
elif ch==4:
var= 1Product_for1
val=input("Enter Male/Femal/Kids : ")
elif ch==S:
var='season'

val=input("Enter the Season : ")


elif ch==6:
var='product_id'
val=input("Enter the Product_id : ")
if x==O:
sql="select • from product where"+ var+"= %s"
sq=sql
tp=(val,)
mycursor.execute(sq,tp)
res=mycursor.fetchall()
for x in res:
print(x)

def PurchaseProduct():
11
mn= "

dy=""
now=datetlme.datetime.now()
purchaselD="P"+str(now.year)+str(now.month)+str(now.day)+str(now.hour)+str(now.minute)+str(n
ow.second)
L=(]
Lst=(]
L.append(purchaselD)
itemld=input("Enter Product ID : ")
L.append(itemld)
itemNo=int(input("Enter the number of Items:"))
L.append(itemNo)
sql="select rate from product where product_ld=%s"
pid=(itemld,)
mycursor.execute(sql,pid)
res=mycursor.fetchone()
for x in res:
print("rate is:", x)
amount=x•itemNo
print("Amount is:", amount}
L.append(amount)
mnth=now.month
if mnth<=9:
mn="O"+str(mnth)
else:
mn=str(mnth)
day=now.day
if day<=9:
dy="O"+str(day)
else:
dy=str(day)

dt=str( now.year)+"-"+mn+"-"+dy
L.append(dt)
tp=(L)
sql="lnsert Into
purchase( purchase_id,ltem_id,no_ of_ltems,a mount,Purchase_date)values(%s,%s,%s,%s,
%s)"
mycu rsor .execute(sql,tp)
mydb.commit()
sql="Select lnstock from stock where item_id=%s"
mycursor.execute(sql,pid)
res=mycursor.fetchall()
status="No"
for x in res:
print(x)
instock=x(OJ+itemNo
if instock>O:
status="Yes"
Lst.append(instock)
Lst.append(status)
Lst.append(itemld)
tp=(Lst)
sql="update stock set lnstock=%s,status=%s where item_id=%s"
mycursor.execute(sql,tp)
mydb.commit()
print("l Item purchased and saved in Database")

def ViewPurchase():
item=input("Enter Product Name: ")
sql="select product.product_ld,
product.PName,product.brand,purchase.no_of_items,purchase.purchase_date,purchase.am
ount from product INNER JOIN purchase ON product.product_ld=purchase.ltem_id and
product.PName=%s"
itm=(item,)
mycursor.execute(sql,itm)
res=mycursor.fetchall()
for x in res:
prlnt(x)

def ViewStock():
item=input("Enter Product Name: ")
sql="select product.product_id,product.PName,stock.lnstock,\
stock.status from stock, product where\
product.product_id=stock.item_id and product.PName=%s"
itm=(item,)
mycursor.execute(sql,itm)
res=mycursor.fetchall()
for x in res:
print(x)

def SaleProduct():
now•datetime.datetime.now()
salelD•"S''+str(now.year)+str(now.month)+str(now.day)+str(now.hour)+str(now.minute)+str(now.se
cond)
l•[)
L.append(salelD)
ltemld•lnput("Enter Product ID:")
L.append(ltemld)
itemNo•int(input("Enter the number of Items : "))
L.append(itemNo)
sql•"select rate from product where product_id•%s"
pid•(itemld,)
mycursor.execute(sql,pid)
res•mycursor.fetchall()
for x In res:
prlnt("The rate of item is :",x)
dis•int(lnput("Enter the discount : "))
saleRate=x[O)•(x[O]•dis/100)
L.append(saleRate)
amount•itemNo•saleRate
L.append(amount)
mnth•now.month
If mnth<•9:
mn="O"+str(mnth)
else:
mn•str(mnth)
day=now.day
if day<•9:
dy•"O"+str(day)
else:
dy=str(day)
dt=str( now.year)+"•"+mn+"•"+dy
L.append(dt)
tp=(L)
sql="lnsert into sales (sale_ld, ltem_ld,no_of_item_sold,\
sale_rate,amount,date_of_sale) values(%s,%s,%s,%s,%s,%s)"
mycursor.execute(sql,tp)
mydb.commit()
sql="Select lnstock from stock where ltem_id=%s"
mycursor.execute(sql,pld)
res=mycursor.fetchall()
for x In res:
print("Total Items in Stock are : ",x)
instock=x[O]•itemNo

if instock>O:
status•"Yes"
tp=(instock,status,itemld)
sql="update stock set instock=%s,status=%s where item_id=%s"
print("Remaining Items in Stock are: ",instock)
mycursor.execute(sql,tp)
mydb.commit()

def ViewSales():
item=input("Enter Product Name: ")
sql="select product.product_id, product.PName,product.brand,\
sales.no_of_item_sold,sales.date_of_sale,sales.amount \
from sales, product where product.product_id=sales.item_id \
and product.PName=%s"
itm=(item,)
mycursor.execute(sql,itm)
res=mycursor.fetchall()
for x in res:
print(x)

def MenuSet(): #Function For The SFashion Store System


print("Enter 1 : To Add Product")
print("Enter 2 : To Edit Product")
print("Enter 3 : To Delete Product")
print("Enter 4: To View Product")
print("Enter S : To Purchase Product")
print("Enter 6: To View Purchases")
print("Enter 7: To View Stock Detials")
prlnt("Enter 8: To Sale the item")
print("Enter 9: To View Sales Oetials")
try: #Using Exceptions For Validation
userlnput = int{lnput("Please Select An Above Option:")) #Will Take Input From User
except ValueError:
exlt{"\nHyl That's Not A Number") #Error Message
else:
print("\n") #Print New line
if(userlnput == 1):
AddProduct()
elif(userlnput == 2):
EditProduct()
elif (userlnput==3):
Del Product()
elif (userlnput==4):
ViewProduct()
elif (userlnput==S):
PurchaseProduct()
elif (userlnput==6):
ViewPurchase()
elif (userlnput==7):
ViewStock()
elif (userlnput==S):
SaleProduct()
elif (userlnput==9):
ViewSales()
else:
print("Enter correct choice... ")

MenuSet()

def runAgain():
runAgn = input("\nwant To Run Again Y/n: ")
whlle(runAgn.lower() == 'y'):
if(platform.system() == "Windows"):
prlnt(os.system('cls'))
else:
prlnt(os.system('clear'))
MenuSet()
runAgn = input("\nwant To Run Again Y/n: ")
runAgaln()
• • • • • • • Welcome lo th• Project of F'ashion Store • • • • • • •

.............. ................... ..................... .........................


• • • • Developed by: Neha Tyagi, PGT cs, KV no. 5 .Jaipur : • • • •
" ,. ,.

Enter l ; To Add Prnduct


E.nter 2 : To &dit Product
Enter J : To Delete Product
Enter 4 : To View Product
Enter 5 : To Purchase Product
Enter 6 ; To View Purcha:,;es
&nter 7 : To view stock oetial:i
Enter 8 : To sale the ite■
Enter 9 : To view sale:i oetial:i
Plea:,;e Select An Above Option: I

Add product:

Enter 1 To Add Product


Enter 2 TO Edit Product
Enter 3 To Del..ete Product
Enter 4 To View Product
Enter 5 To Purcha5e Product
Enter 6 TO view Purcha5es
Enter 7 To View Stock Detia15
Enter e To saie the item
Enter 9 To View Sa1e5 Detial..5
Pl..ea3e Se1ect An Above Option: 1

Enter the Product ID: P106


Enter the Product Name : TShirt
Enter the Product Brand Name : Lee
Enter Ma1e/remal..e/Kid5 : Mal..e
Enter Winter/Summer : summer
~nter the Rato3 ~or Product :640
one Product in~•rted
want To Run Again Y/n: I

Edit product:
Enter 1 TO Add Product
Enter 2 To Edit Product
Enter 3 To Delete Product
Enter 4 To View Product
Enter 5 To Purcha~e Product
Enter 6 To view Purchases
Enter 7 To View Stock Dotiuls
Enter 8 To sale the Jtem
Enter 9 : To View Sales Detials
Please Select An Above Option: 2

Enter product 1D to be edited: Pl05


('Pl05', 'Kurta', 'Manyawar', 'Male', 'Summer', 1500)

Enter the tield which you want to edit : 5ea5on


Enter the value you want to set : Winter
EdiLing Don :
After correction the record i 3
('Pl05', 'Kurta', 'Manyawar•, 'Male', 'Winter•, 1500)

want To Run Again Y/n: I

Delete product:
Enter 1 To Add Product
Enter 2 TO Edit Product
Enter 3 TO Delete Product
Enter 4 TO view Product
Enter 5 To Purcha3e Product
Enter 6 TO View Purcha.ses
Enter 7 TO View stock Detial,s
Enter 8 TO sale the item
Enter 9 To View Sales Detials
Please Select An Above Option: 3

Enter the Product)id to be deleted Pl06


One Item Deleted
I
want To Run Again Y/n:

View product:

Enter 1 To Add Product


Enter 2 TO Edit Product
Enter 3 To Delete Product
Enter 4 To View Product
Enter 5 To Purchase Product
Enter 6 To View Purchases
Enter 7 To View stock Detials
Enter 8 To Sale the item
Enter 9 To View Sales Detials
Please Select An Above Option: 4

Display Menu: select the category to display the data


l. All Details
2. Product Name:
3. Product Brand:
4. Product For:
5. Product season:
6. Product IO:
Enter your choice to display: 1
('PlOl', 'Lower', 'Lee', 'Male', 'Winter', 900)
(' P102', 'TShirt', 'Polo', 'Male', 'Summer', 350)
('Pl03', 'Lower', 'Adidas', 'Kids', 'Summer', 250)
('Pl04', 'Leging', 'Lyra', 'Female', •summer', 300)
('Pl05', 'Kurta', 'Manyawar', 'Male', 'Winter', 1500)
want To Run Again Y/n: I

Purchase product:
Enter 1 To Add Product
Enter 2 To Edit Product
Enter 3 To Delete Product
Enter 4 TO View Product
Enter 5 TO Purcha:,e Product
Enter 6 To View Purcha:se!S
Enter 7 TO View Stock Detial:,
Enter 8 To sal.e the item
Enter 9 To View Sale:, Detial:,
Pl.ea:,e sel.ect An Above Option: 5

Enter Product ID : P104


Enter the number or Item:, 20
rate is : 300
Amount is : 6000
(0,)
1 Item purchased and saved in Database

want To Run Again Y/n: I

View purchase:
Enter 1 To Add Product
Enter 2 TO Edit Product
Enter 3 TO Delete Product
Enter 4 TO view Product
Enter 5 TO Purchase Product
Enter 6 TO View Purchases
Enter 7 To view Stock Detials
Enter 8 To Sale the item
Enter 9 To View Sale!! Detial!!
Please Select An Above Option: 6

Enter Product Name : Leging


('Pl04', 'Leging', 'Lyra', 20, datetime.date(2018, 12, 14), 6000)

want To Run Again Y/n: I

View stock details:


Enter 1 To Add Product
Enter 2 To Edit Product
Enter 3 To Del.eta Product
Enter 4 To View Product
Enter 5 TO Purcha:,e Product
Enter 6 TO View Purchases
Enter 7 TO View stock Detial.s
Enter 8 TO Sal.e the item
Enter 9 To View Sales Detials
Pl.ease sel.ect An Above Option: 7

Enter Product Name : Lower


('P101', 'Lower•, 5, 'Yes')
('P103', 'Lower', O, 'No')

want To Run Again Y/n: I

Sale Item:
Enter 1 To Add Product
Enter 2 To Edit Product
Enter 3 To Delete Product
Enter 4 TO View Product
Enter 5 To Purchase Product
Enter 6 To View Purchases
Enter 7 TO View stock Detials
Enter 8 To Sale the item
Enter 9 TO View Sales Detials
Please Select An Above Option: 8

Enter Product ID : P104


Enter the number of Items : 6
The rate of item is : (300,)
Enter the discount : 10
Total Items in Stock are (20,)
Remaining Items in Stock are : 14
want To Run Again Y/n: I
View sales details:
Enter 1 To Add Product
Enter 2 To Edit Product
Enter 3 To Delete Product
Enter 4 To View Product
Enter 5 To Purchase Product
Enter 6 To View Purchases
Enter 7 To View stock Detials
Enter 8 To Sale the item
Enter 9 To View Sales Detials
Please Select An Above Option: 9

Enter Product Name : Leging


('P104', 'Leging', 'Lyra', 61 datetime.date(2018, 12, 14), 1620)

want To Run Again Y/n: I

You might also like