import mysql.
connector as m
flag = True
with open ("[Link]","r")as p:
passwd = [Link]().strip()
while flag:
pawd = input("Enter your password: ")
if pawd == passwd:
flag = False
def get_connection():
return [Link](
user ='root',
host ='localhost',
passwd = 'class12',
database = 'prjct_k')
def add_item():
product_id = int(input("Enter HSN Code: "))
name = input("Enter its name: ")
qty = float(input("Enter its qty in: "))
price = float(input("Enter its price: "))
category = input("Enter its category: ")
con = get_connection()
cursor = [Link]()
[Link]("INSERT INTO product_details VALUES (%s, %s, %s,
%s, %s)",
(product_id, name, qty, price, category))
[Link]()
[Link]()
print("✅Successfully Added.....")
def view_items():
con = get_connection()
cursor = [Link]()
[Link]("SELECT * FROM product_details order by
HSN_code")
data = [Link]()
if data:
print("| HSN Code | Product_Name | Quantity | Price | Category
|")
print("-" * 60)
for i in data:
HSN_code,product_name,Qty,price,category =i
print(HSN_code,product_name,Qty,price,category,sep=" | ")
[Link]()
else:
print("No data in table!")
return
def search_item():
HSN_code = input("Enter the HSN_code:")
con = get_connection()
cursor = [Link]()
try:
[Link]("SELECT * FROM product_details WHERE
HSN_code = %s", (HSN_code,))
rows = [Link]()
[Link]()
if rows:
for i in rows:
print(f"HSN_code: {i[0]}\nProduct_Name: {i[1]}\nQuantity:
{i[2]}\nPrice: {i[3]}\nCategory: {i[4]}\n")
else:
print("No item found!")
except:
print("Some Error occured")
def update_item():
HSN_code = int(input("Enter the HSN_code:"))
quantity = float(input("Enter the quantity:"))
price = float(input("Enter the Unit_Price:"))
con = get_connection()
cursor = [Link]()
[Link]("UPDATE product_details SET qty=%s, price=%s
WHERE HSN_code=%s", (quantity, price, HSN_code))
[Link]()
[Link]()
print("✅Successfully Updated!")
def delete_it_us():
ask = input("1. Products\n2. Customers\n")
con = get_connection()
cursor = [Link]()
if ask == "1":
HSN_code = int(input("Enter HSN_code: "))
[Link]("DELETE FROM product_details WHERE
HSN_code = %s", (HSN_code,))
[Link]()
print("Deleted successfully")
elif ask == "2":
user_id = int(input("Enter user_id: "))
HSN_code = int(input("Enter HSN_code: "))
try:
[Link]("SELECT * FROM user_details WHERE user_id
= %s AND HSN_code = %s", (user_id, HSN_code))
data = [Link]()
if data:
print("Data found:", data)
[Link]("INSERT INTO backup (user_id, name,
HSN_code,contact_no,Payment_Status,dt_of_issue,GSTIN) VALUES (%s,
%s, %s, %s, %s, %s, %s)", data)
[Link]()
[Link]("DELETE FROM user_details WHERE user_id
= %s AND HSN_code = %s", (user_id, HSN_code))
[Link]()
print("Succcessfully Deleted")
else:
print("Record not found Please recheck!!!....")
except:
print("Error occured")
[Link]()
def user_details():
con = get_connection()
cursor = [Link]()
try:
if input("New user (Y/N)?").lower() == "y":
user_id=int(input("Create your User_ID:"))
Name=input("Enter your Name: ")
GSTIN=input("Enter your GSTIN number(if you have else type
B2C): ")
contact_no=int(input("Enter contact_no: "))
HSN_code=int(input("Enter the HSN_code of product you
Bought:"))
payment=input("Payment (Done/Pending):")
query=f"insert into user_details values({user_id},'{Name}',
{HSN_code},{contact_no},'{payment}',date(now()),'{GSTIN}')"
[Link](query)
[Link]()
[Link]()
print("Successfully Added.....")
pass
else:
user_id = int(input("Enter your User_ID: "))
query = f"SELECT user_id, name, HSN_code, contact_no,
Payment_Status, dt_of_issue, GSTIN FROM user_details WHERE user_id =
%s ORDER BY user_id"
[Link](query, (user_id,))
data = [Link]()
if data:
print("\nUser Details Table:")
print("-" * 200)
print(" ID Name HSN Contact Payment
Date GSTIN")
print("-" * 200)
count = 1
for row in data:
user_id, name, hsn, contact, payment, date_val, gstin =
row
print(user_id, name, hsn, contact, payment, date_val,
gstin,sep=" | ")
count += 1
print("-" * 200)
else:
print("User not Found!")
except:
print(f"Error occured")
finally:
[Link]()
[Link]()
def user_products():
con = get_connection()
cursor = [Link]()
user_id = int(input("Enter user_id:"))
[Link](f"select
product_details.HSN_code,product_name,price,category from
product_details,user_details where
product_details.HSN_code=user_details.HSN_code and
user_id={user_id}")
data = [Link]()
[Link]()
[Link]()
if data:
print("HSN_code | Product_name | Price | Category | ")
for i in data:
HSN_code,product_name,price,category=i
print(HSN_code,product_name,price,category,sep=" | ")
else:
print("No Data found")
def Recycle_Bin():
con = get_connection()
cur = [Link]()
query = "SELECT * FROM Backup ORDER BY dt_of_issue DESC"
[Link](query)
data = [Link]()
[Link]()
if not data:
print("Recycle Bin is empty!")
return
print("User_ID Name HSN Contact_No Payment Date
GSTIN")
print("-" * 70)
for row in data:
if row[-1] == None:
user_id, name, hsn, contact, payment, date_val,gstin = row
print(user_id, name, hsn, contact, payment, date_val,
"B2C",sep=" | ")
# Menu
print(" Welcome to
INVENTORY MANAGEMENT Project")
while True:
print('\n\n\n ✅ 1. product_details\n\
✅ 2. User_details \n\
✅ 3. Recycle Bin\n\
✅ 4. Change Password\n\
✅ 5. Exit')
inp = input("\nEnter your choice(1/2/3/4/5):\n\
_-------->")
if inp == "1":
print(" ✅ 1. Add_ Item\n\
✅ 2. View_Item\n\
✅ 3. Search_Item\n\
✅ 4. Update_Item\n\
✅ 5. Delete_Item")
choice=input("Enter the choice:")
if choice == "1":
add_item()
elif choice == "2":
view_items()
elif choice == "3":
search_item()
elif choice == "4":
update_item()
elif choice == "5":
delete_it_us()
elif inp == "2":
print(" ✅ 1. User_Details\n\
✅ 2.User_products")
choice=input("Enter the choice:")
if choice == "1":
user_details()
elif choice=="2":
user_products()
elif inp == "3":
Recycle_Bin()
break
elif inp == "4":
while True:
old_pass = input("Enter your Old Password:")
if old_pass == passwd:
while True:
new_pass = input("Enter your New Password: ")
new_pass1 = input("Re-Enter your New Password: ")
if new_pass == new_pass1:
passwd = new_pass
with open("[Link]","w") as f:
[Link](new_pass)
print("succcessfully Updated your new Password")
print("🔐 Program will now exit - restart to use new
password")
exit()
else:
print("❌Password doesn't match Try again !.. ")
break
else:
print("❌Old Password doesn't Match! Try again........")
break
elif inp=="5":
print("Thank You for Choosing us!........ Exiting...........")
break
else:
print("Please choose from (1/2/3)\n\n")
else:
print("Incorrect Password!\tTry Again......")