0% found this document useful (0 votes)
9 views

Source Code

Uploaded by

sohamsurana
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)
9 views

Source Code

Uploaded by

sohamsurana
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/ 5

Source Code

import mysql.connector
try:
conn = mysql.connector.connect(
host="localhost",
user="root",
password="Sohamsurana@1234",
database="tax_inventory"
)
cursor = conn.cursor()

def insert_into_inventory():
print("Enter details for inventory item:")
item_barcode = input("Item Barcode: ")
item_name = input("Item Name: ")
brand = input("Brand: ")
number_of_units = int(input("Number of Units: "))
price_per_unit = float(input("Price per Unit: "))
total_price = number_of_units * price_per_unit
cursor.execute("""
INSERT INTO inventory (item_barcode, item_name, brand,
number_of_units, price_per_unit, total_price)
VALUES (%s, %s, %s, %s, %s, %s)
""", (item_barcode, item_name, brand, number_of_units, price_per_unit,
total_price))
conn.commit()
print("Data inserted successfully into inventory table.")

def insert_into_tax_records():
print("\nEnter details for tax record:")
item_taxid = input("Item Tax ID: ")
item_barcode = input("Item Barcode: ")
item_name = input("Item Name: ")
tax_percentage = float(input("Tax Percentage: "))
tax_cost = float(input("Tax Cost: "))
cursor.execute("""
INSERT INTO tax_records (item_taxid, item_barcode, item_name,
tax_percentage, tax_cost)
VALUES (%s, %s, %s, %s, %s)
""", (item_taxid, item_barcode, item_name, tax_percentage, tax_cost))
conn.commit()
print("Data inserted successfully into tax_records table.")

def create_bill():
cursor.execute("use bills;")
print("\nCreating new bill:")
bill_id = input("Enter Bill ID: ")
customer_name = input("Customer Name: ")
bill_date = input("Bill Date (YYYY-MM-DD): ")
total_amount = 0.0

bill_table_name = f"bill_{bill_id}"
cursor.execute(f"""
CREATE TABLE IF NOT EXISTS {bill_table_name} (
id INT AUTO_INCREMENT PRIMARY KEY,
item_name VARCHAR(100) NOT NULL,
quantity INT NOT NULL,
unit_price FLOAT NOT NULL,
total_price FLOAT NOT NULL
)
""")
conn.commit()

while True:
print("\nEnter item details for the bill (enter 'done' to finish):")
item_name = input("Item Name: ")
if item_name.lower() == 'done':
break
quantity = int(input("Quantity: "))
unit_price = float(input("Unit Price: "))
total_price = quantity * unit_price
total_amount += total_price

cursor.execute("use bills;")
cursor.execute(f"""
INSERT INTO {bill_table_name} (item_name, quantity,
unit_price, total_price)
VALUES (%s, %s, %s, %s)
""", (item_name, quantity, unit_price, total_price))
conn.commit()

cursor.execute("""
INSERT INTO bills (bill_id, customer_name, bill_date, total_amount)
VALUES (%s, %s, %s, %s)
""", (bill_id, customer_name, bill_date, total_amount))
conn.commit()
print(f"Bill {bill_id} created successfully with total amount:
{total_amount}")
def inventory():
cursor.execute("use tax_inventory;")
cursor.execute("Select * from inventory;")
rows = cursor.fetchall()
for i in rows:
print("Item Barcode: ",i[0])
print("Item Name: ",i[1])
print("Brand: ", i[2])
print("Number of units: ",i[3])
print("Price per unit: ",i[4])
print("Total Price: ",i[5])
print("\n\n")
def tax():
cursor.execute("use tax_inventory;")
cursor.execute("Select * from tax_records;")
rows = cursor.fetchall()
for i in rows:
print("Item taxid: ",i[0])
print("Item barcode: ",i[1])
print("Item Name: ", i[2])
print("Tax Percentage: ",i[3])
print("Tax Cost: ",i[4])
print("\n\n")
def Bills():
cursor.execute("use bills;")
Bill_No = (input("Enter the Bill ID: "))
cursor.execute(f"Select * from bill_{Bill_No};")
rows = cursor.fetchall()
for i in rows:
print("Item id: ",i[0])
print("Item name: ",i[1])
print("Quantity: ", i[2])
print("Unit Price: ",i[3])
print("Total Price:",i[4])
print("\n\n")

while True:
print("\n1. Insert into Inventory")
print("2. Insert into Tax Records")
print("3. Create Bill")
print("4. View the Inventory")
print("5. View the tax Records")
print("6. View the bill records")
print("7. Exit")
choice = input("Enter your choice (1/2/3/4/5/6): ")

if choice == '1':
insert_into_inventory()
elif choice == '2':
insert_into_tax_records()
elif choice == '3':
create_bill()
elif choice == '4':
inventory()
elif choice == '5':
tax()
elif choice == '6':
Bills()
elif choice == '7':
break
else:
print("Invalid choice. Please enter 1, 2, 3, 4, 5, 6 or 7")

except mysql.connector.Error as err:


print("Error connecting to MySQL:", err)

You might also like