0% found this document useful (0 votes)
19 views4 pages

Aa

Uploaded by

Aditya Rawat
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)
19 views4 pages

Aa

Uploaded by

Aditya Rawat
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/ 4

import csv

import os

# Base file path


BASE_PATH = "D:\\"

# Function to load data from CSV files


def load_data(file_name):
data = []
try:
with open(os.path.join(BASE_PATH, file_name), mode='r', newline='',
encoding='utf-8') as file:
reader = csv.DictReader(file)
for row in reader:
data.append(row)
except FileNotFoundError:
print(f"{file_name} not found.")
return data

# Function to save data to CSV files


def save_data(file_name, data):
with open(os.path.join(BASE_PATH, file_name), mode='w', newline='',
encoding='utf-8') as file:
writer = csv.DictWriter(file, fieldnames=data[0].keys())
writer.writeheader()
writer.writerows(data)

# Function to add a new product


def add_new_product(products, new_product):
products.append(new_product)
save_data("Products.csv", products)

# Function to update product stock


def update_product_stock(products, product_id, quantity):
for product in products:
if product['Product_ID'] == product_id:
product['Stock_Quantity'] = str(int(product['Stock_Quantity']) +
quantity)
break
save_data("Products.csv", products)

# Function to record a sale


def record_sale(sales, new_sale):
sales.append(new_sale)
save_data("Sales.csv", sales)

# Function to generate sales report


def generate_sales_report(sales):
report = {}
for sale in sales:
product_id = sale['Product_ID']
total_price = float(sale['Total_Price'])
if product_id in report:
report[product_id] += total_price
else:
report[product_id] = total_price
return report

# Function to add a new supplier


def add_new_supplier(suppliers, new_supplier):
suppliers.append(new_supplier)
save_data("Suppliers.csv", suppliers)

# Function to find a supplier


def find_supplier(suppliers, supplier_id):
for supplier in suppliers:
if supplier['Supplier_ID'] == supplier_id:
return supplier
return None

# Function to check low stock products


def check_low_stock(products, threshold):
low_stock_products = []
for product in products:
if int(product['Stock_Quantity']) < threshold:
low_stock_products.append(product)
return low_stock_products

# Function to calculate total revenue


def calculate_total_revenue(sales):
total_revenue = sum(float(sale['Total_Price']) for sale in sales)
return total_revenue

# Function to list all products


def list_all_products(products):
for product in products:
print(product)

# Function to delete a product


def delete_product(products, product_id):
products[:] = [product for product in products if product['Product_ID'] !=
product_id]
save_data("Products.csv", products)

# Load data from CSV files


products = load_data("Products.csv")
sales = load_data("Sales.csv")
suppliers = load_data("Suppliers.csv")

while True:
print("\nWelcome to the Shop Management System")
print("1. Add New Product")
print("2. Update Product Stock")
print("3. Record Sale")
print("4. Generate Sales Report")
print("5. Add New Supplier")
print("6. Find Supplier")
print("7. Check Low Stock")
print("8. Calculate Total Revenue")
print("9. List All Products")
print("10. Delete a Product")
print("11. Exit")

choice = input("Please choose an option (1-11): ")

if choice == '1':
product_id = input("Enter Product ID: ")
product_name = input("Enter Product Name: ")
category = input("Enter Product Category: ")
price = input("Enter Product Price: ")
stock_quantity = input("Enter Product Stock Quantity: ")
supplier_id = input("Enter Supplier ID: ")

new_product = {
'Product_ID': product_id,
'Product_Name': product_name,
'Category': category,
'Price': price,
'Stock_Quantity': stock_quantity,
'Supplier_ID': supplier_id
}
add_new_product(products, new_product)
print("Product added successfully!")

elif choice == '2':


product_id = input("Enter Product ID to update stock: ")
quantity = int(input("Enter quantity to add: "))
update_product_stock(products, product_id, quantity)
print("Product stock updated successfully!")

elif choice == '3':


sale_id = input("Enter Sale ID: ")
product_id = input("Enter Product ID: ")
customer_id = input("Enter Customer ID: ")
quantity_sold = int(input("Enter Quantity Sold: "))
sale_date = input("Enter Sale Date (YYYY-MM-DD): ")
total_price = input("Enter Total Price: ")

new_sale = {
'Sale_ID': sale_id,
'Product_ID': product_id,
'Customer_ID': customer_id,
'Quantity_Sold': str(quantity_sold),
'Sale_Date': sale_date,
'Total_Price': total_price
}
record_sale(sales, new_sale)
print("Sale recorded successfully!")

elif choice == '4':


sales_report = generate_sales_report(sales)
print("Sales Report:", sales_report)
elif choice == '5':
supplier_id = input("Enter Supplier ID: ")
supplier_name = input("Enter Supplier Name: ")
contact_info = input("Enter Contact Info: ")
address = input("Enter Address: ")

new_supplier = {
'Supplier_ID': supplier_id,
'Supplier_Name': supplier_name,
'Contact_Info': contact_info,
'Address': address
}
add_new_supplier(suppliers, new_supplier)
print("Supplier added successfully!")

elif choice == '6':


supplier_id = input("Enter Supplier ID to find: ")
supplier = find_supplier(suppliers, supplier_id)
if supplier:
print("Supplier found:", supplier)
else:
print("Supplier not found.")

elif choice == '7':


threshold = int(input("Enter low stock threshold: "))
low_stock = check_low_stock(products, threshold)
print("Low Stock Products:", low_stock)

elif choice == '8':


total_revenue = calculate_total_revenue(sales)
print("Total Revenue:", total_revenue)

elif choice == '9':


print("All Products:")
list_all_products(products)

elif choice == '10':


product_id = input("Enter Product ID to delete: ")
delete_product(products, product_id)
print("Product deleted successfully!")

elif choice == '11':


print("Exiting the program. Goodbye!")
break

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

You might also like