Python CIA 3 Ims
Python CIA 3 Ims
SUBMITTED TO
Dr.HELEN JOSEPHINE
BY
ACHARI BHAVANA(2227401)
PYTHON CIA 3
Mart want to create a inventory management system to keep track on the product availability by
updating the stock availability in the godown . Inventory management is important to keep the
update on stock availability of product by keeping a track on the purchase and sales of the product
PROBLEM STATEMENT:
To discover stockouts and excess inventory in order to improve customer happiness and revenue
unit_price={}
description={}
stock={}
#STOCK TEXTFILE
try:
details = open("stock.txt","r")
no_items = int((details.readline()).rstrip("\n"))
for i in range(0,no_items):
line = (details.readline()).rstrip("\n")
x1,x2 = line.split("#")
x1=int(x1)
x2=float(x2)
unit_price.update({x1: x2})
for i in range(0,no_items):
line = (details.readline()).rstrip("\n")
x1,x2 = line.split("#")
x1=int(x1)
description.update({x1: x2})
for i in range(0,no_items):
line = (details.readline()).rstrip("\n")
x1,x2 = line.split("#")
x1=int(x1)
x2=int(x2)
stock.update({x1: x2})
except:
print("Stock empty")
cart=[]
c="y"
total_cost=0
flag=0
if(c=="q" or c=="Q"):
break
elif(c=="A" or c=="a"):
p_no = int(input("Enter item number: "))
p_pr = float(input("Enter item price: "))
p_desc = input("Enter item description: ")
p_stock = int(input("Enter item stock: "))
m=0
for i in range(0,len(unit_price)):
if(p_no in unit_price):
p_no+=1
m=1
if(m==1):
print()
print("That item number already exists :(, changing value to ",p_no)
unit_price.update({p_no: p_pr})
description.update({p_no: p_desc})
if(p_stock > -1):
stock.update({p_no: p_stock})
else:
p_stock = 0
stock.update({p_no: p_stock})
print("The stock of an item cannot be negative, the stock has been set to 0.")
print()
print("Item number: ",p_no," Description: ",description.get(p_no)," Price: ",unit_
print("Item was added successfully!")
print()
elif(c=="E" or c=="e"):
print()
p_no = int(input("Enter item number: "))
if(p_no in unit_price):
p_pr = float(input("Enter item price: "))
p_desc = input("Enter item description: ")
p_stock = int(input("Enter item stock: "))
unit_price.update({p_no: p_pr})
description.update({p_no: p_desc})
stock.update({p_no: p_stock})
else:
print("That item does not exist, to add an item use a")
print()
elif(c=="R" or c=="r"):
print()
p_no = int(input("Enter item number: "))
if(p_no in unit_price):
are_you_sure = input("Are you sure you want to remove that item(y/n)? ")
if(are_you_sure=="y" or are_you_sure=="Y"):
unit_price.pop(p_no)
description.pop(p_no)
stock.pop(p_no)
print("Item successfully removed!")
print()
else:
print("Sorry, we don't have such an item!")
print()
elif(c=="L" or c=="l"):
print()
print("Item and their prices: ",unit_price)
print("Descriptions: ",description)
print("Stock left of Item: ",stock)
print()
elif(c=="I" or c=="i"):
print()
p_no=int(input("Enter Item Number: "))
if(p_no in unit_price):
print()
print("Item number: ",p_no," Description: ",description.get(p_no)," Price: ",u
if(stock.get(p_no)<3 and stock.get(p_no)!=0):
print("Only ",stock.get(p_no)," remaining! Hurry!")
print()
else:
print("Sorry we don't have such an item!")
print()
elif(c=="P" or c=="p"):
print()
p_no = int(input("Enter Item number: "))
if(p_no in unit_price):
if(flag==1):
flag=0
stock_current = stock.get(p_no)
if(stock_current>0):
stock_current = stock.get(p_no)
stock[p_no] = stock_current-1
item_price = unit_price.get(p_no)
total_cost = total_cost+item_price
print(description.get(p_no),"added to cart: ","$",item_price)
cart.append(p_no)
else:
print("Sorry! We don't have that item in stock!")
else:
print("Sorry! We don't have such an item!")
print()
elif(c=="C" or c=="c"):
print()
print("You bought the following items: ",cart)
print("Total: ","$",round(total_cost,2))
tax= round(0.12*total_cost,2)
print("Tax is 12%: ","$",tax)
total = round(total_cost+tax,2)
print("After Tax: ","$",total)
total_cost=0
flag=1
print()
print("You can still purchase items after check out, your cart has been reset. To
print()
elif(c=="help"):
print()
print("Help Centre")
print("A-Add an item")
print("R-Remove an item")
print("E-Edit specifics of an item")
print("L-List all items")
print("I-Inquire about a item")
print("P-Purchase")
print("C-Checkout")
print("S-Show all items purchased")
print("remove-Remove an item from the cart")
print("help-See all commands again")
print("If you have any other questions or concerns please contact the manager.")
print()
cart.pop(j)
print(description.get(p_no),"removed from cart: ")
print()
else:
print()
print("That item is not in your cart!")
print()
elif(c=="s" or c=="S"):
print()
print(cart)
print()
else:
print()
print("ERROR! Contact manager for help!")
print()
try:
details = open("stock.txt","w")
no_items=len(unit_price)
details.write(str(no_items)+"\n")
for i in range(0,no_items):
details.write(str(i+1)+"#"+str(unit_price[i+1])+"\n")
for i in range(0,no_items):
details.write(str(i+1)+"#"+description[i+1]+"\n")
for i in range(0,no_items):
details.write(str(i+1)+"#"+str(stock[i+1])+"\n")
except:
print("Stock saved")
finally:
details.close()
Stock empty
Welcome to Inventory Management System
A-Add an item
R-Remove an item
E-Edit specifics of an item
L-List all items
I-Inquire about a item
P-Purchase
C-Checkout
S-Show all items purchased
Q-Quit
help-See all commands again
ORDER TEXTFILE :
# Define a function to read the order data from the file and return it as a list of dictio
def get_orders():
orders = []
with open(file_path, "r") as file:
for line in file:
item, quantity, date = line.strip().split(",")
order = {"item": item, "quantity": int(quantity), "date": date}
orders.append(order)
return orders
# Define a function to search for orders by item name and return them as a list of dictiona
def search_orders_by_item(item):
orders = get_orders()
matching_orders = []
for order in orders:
if order["item"] == item:
matching_orders.append(order)
return matching_orders
# Example usage: get all orders from the file and print their data
orders = get_orders()
for order in orders:
print(order)
# Example usage: search for orders by item name and print their data
matching_orders = search_orders_by_item("Widget")
matching_orders = search_orders_by_item("detergents")
matching_orders = search_orders_by_item("soaps")
matching_orders = search_orders_by_item("washing powder")
if matching_orders:
for order in matching_orders:
print(order)
else:
print("No matching orders found.")
CUSTOMER TEXTFILE :
# Define a function to read the customer data from the file and return it as a list of dic
def get_customers():
customers = []
with open(file_path, "r") as file:
for line in file:
name, address, email, phone = line.strip().split(",")
customer = {"name": name, "address": address, "email": email, "phone": phone}
customers.append(customer)
return customers
# Define a function to search for a customer by name and return the customer's data as a d
def search_customer(name):
customers = get_customers()
for customer in customers:
if customer["name"] == name:
return customer
return None
# Example usage: search for a customer by name and print their data
customer = search_customer("John Doe")
customer = search_customer("hana")
if customer:
print(customer)
else:
print("Customer not found.")
INVENTORY TEXT.FILE :
import os
for i in range(len(inventory)):
item = inventory[i].split()
if item[0] == item_name:
item[1] = str(int(item[1]) + quantity)
inventory[i] = ' '.join(item) + '\n'
break
else:
inventory.append(item_name + ' ' + str(quantity) + '\n')
with open('inventory.txt', 'w') as file:
file.writelines(inventory)
for i in range(len(inventory)):
item = inventory[i].split()
if item[0] == item_name:
item[1] = str(max(0, int(item[1]) - quantity))
inventory[i] = ' '.join(item) + '\n'
break
else:
print(f"{item_name} not found in inventory.")
return
for i in range(len(inventory)):
item = inventory[i].split()
if item[0] == item_name:
print(f"{item_name}: {item[1]}")
break
else:
print(f"{item_name} not found in inventory.")
# example usage
add_stock('soaps', 10) # add 10 soaps to inventory
remove_stock('widget', 5) # remove 5 widget from inventory
check_stock('soaps') # display current stock of soaps
check_stock('detergent') # display current stock of detergent
# Define a function to read all purchases from the file and return them as a list of dictio
def read_purchases():
purchases = []
with open(file_path, "r") as file:
for line in file:
product_name, quantity, price = line.strip().split(",")
purchase = {"product_name": product_name, "quantity": int(quantity), "price":
purchases.append(purchase)
return purchases
# Example usage: read all purchases from the file and print their data
purchases = read_purchases()
for purchase in purchases:
print(purchase)
Purchase recorded.
Purchase recorded.
{'product_name': 'Widget A', 'quantity': 10, 'price': 2.99}
{'product_name': 'soaps', 'quantity': 5, 'price': 41.2}
Total cost of all purchases: 235.9
Total quantity of Widget A purchased: 5
CRUD OPERATIONS ON CUSTOMER TEXT FILE :
# Define a function to create a new customer and add them to the file
def create_customer(name, address, email, phone):
with open(file_path, "a") as file:
file.write(f"{name},{address},{email},{phone}\n")
print(f"New customer {name} added to the file.")
# Define a function to read all customers from the file and return them as a list of dictio
def read_customers():
customers = []
with open(file_path, "r") as file:
for line in file:
name, address, email, phone = line.strip().split(",")
customer = {"name": name, "address": address, "email": email, "phone": phone}
customers.append(customer)
return customers
# Define a function to read a single customer from the file by name and return their data a
def read_customer(name):
with open(file_path, "r") as file:
for line in file:
fields = line.strip().split(",")
if fields[0] == name:
customer = {"name": fields[0], "address": fields[1], "email": fields[2], "
return customer
return None
# Example usage: read all customers from the file and print their data
customers = read_customers()
for customer in customers:
print(customer)
# Example usage: read a single customer from the file by name and print their data
customer = read_customer("John Doe")
customer = read_customer("Hana")
if customer:
print(customer)
else:
print("Customer not found.")
The process flow diagram depicts a simple stock management system that allows the user to
record purchases, check stock levels, search for customers, and place orders. It gives a clear
visualisation of the flow of data and operations inside the system, making it easier to comprehend
and manage.
The user enters the product name, quantity, and price to create a new purchase.
1. The user enters the product name, quantity, and price to create a new purchase.
2. The transaction function records the transaction and verifies the stock levels. Based on the
new purchase, the Stock function changes the stock levels.
4. The Customer function looks up the supplied customer in the customer database.
6. By inputting the product name and amount, the user can make an order for a customer.
7. The Order function processes the order and adjusts the stock levels as needed.
ER DIAGRAM :
CONCLUSION :
An inventory management system that integrates buy, order, customer, and stock functions can
assist firms in streamlining processes and optimising inventory levels. Businesses can make
informed decisions regarding when to order more products, how much to order, and how to
allocate inventory to different sales channels if they have real-time visibility into stock levels. The
technology can also provide warnings and notifications when stock levels are low or shipments
are delayed, assisting firms in staying on top of their inventory and improving customer service.