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

Python CIA 3 Ims

Uploaded by

Debanik Hazra
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Python CIA 3 Ims

Uploaded by

Debanik Hazra
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

MIS PROJECT ON INVENTORY MANAGEMENT SYSTEM

SUBMITTED TO

Dr.HELEN JOSEPHINE

BY

ACHARI BHAVANA(2227401)

PYTHON CIA 3

INVENTORY MANAGEMENT SYSTEM :

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"

print("Welcome to Inventory Management System")


print()
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("Q-Quit")
print("help-See all commands again")
print()

total_cost=0
flag=0

while(c!= "q" or c!= "Q"):


c= input("What would you like to do? ")

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()

elif(c=="remove" or c=="Remove"):#To remove an item from the cart


print()
are_you_sure = input("Are you sure you want to remove an item from the cart(y/n)?
if(are_you_sure=="y"):
p_no = int(input("Enter item number to remove from cart: "))
if(p_no in cart):
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
j=0
for i in range(0,len(cart)):
if(i==p_no):
j=i

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()

if(total_cost>0 and flag==0):


print()
print("You bought: ",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)

print("Thank you for using Inventory Management System")

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

# Set the safety stock level for the item


safety_stock = 10

# Get the current stock level from your inventory system


current_stock = 5 # replace this with the actual stock level obtained from the inventory sy

# Check if the current stock is below the safety stock level


if current_stock < safety_stock:

print("Low stock notification sent!")


else:
print("Current stock level is sufficient.")

Low stock notification sent!

ORDER TEXTFILE :

# Define the file path where order data will be stored


file_path = "orders.txt"

# Define a function to add a new order to the file


def add_order(item, quantity, date):
with open(file_path, "a") as file:
file.write(f"{item},{quantity},{date}\n")
print("New order added to the file.")

# 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: add a new order to the file


add_order("soaps", 10, "2023-04-24")
add_order("detergents", 13, "2022-12-15")
add_order("Widget", 30, "2021-06-4")

# 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.")

New order added to the file.


New order added to the file.
New order added to the file.
{'item': 'soaps', 'quantity': 10, 'date': '2023-04-24'}
{'item': 'detergents', 'quantity': 13, 'date': '2022-12-15'}
{'item': 'Widget', 'quantity': 30, 'date': '2021-06-4'}
No matching orders found.

CUSTOMER TEXTFILE :

# Define the file path where customer data will be stored


file_path = "customers.txt"

# Define a function to add a new customer to the file


def add_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 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: add a new customer to the file


add_customer("John Doe", "123 Main St", "[email protected]", "555-1234")
add_customer("sid", "43 church street", "[email protected]", "288-1222")
add_customer("krish", "5 ramkom", "[email protected]", "647-2465")
add_customer("tan", "35 casiko", "[email protected]", "324-3242")
# Example usage: get all customers from the file and print their data
customers = get_customers()
for customer in customers:
print(customer)

# 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.")

New customer John Doe added to the file.


New customer sid added to the file.
New customer krish added to the file.
New customer tan added to the file.
{'name': 'John Doe', 'address': '123 Main St', 'email': '[email protected]', 'ph
{'name': 'sid', 'address': '43 church street', 'email': '[email protected]', 'phone
{'name': 'krish', 'address': '5 ramkom', 'email': '[email protected]', 'phone': '6
{'name': 'tan', 'address': '35 casiko', 'email': '[email protected]', 'phone': '324
Customer not found.

INVENTORY TEXT.FILE :

import os

# function to check if file exists and create it if it doesn't


def check_file():
if not os.path.exists('inventory.txt'):
with open('inventory.txt', 'w') as file:
file.write('')

# function to add stock to the inventory


def add_stock(item_name, quantity):
check_file()
with open('inventory.txt', 'r') as file:
inventory = file.readlines()

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)

# function to remove stock from the inventory


def remove_stock(item_name, quantity):
check_file()
with open('inventory.txt', 'r') as file:
inventory = file.readlines()

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

with open('inventory.txt', 'w') as file:


file.writelines(inventory)

# function to display the current stock of an item


def check_stock(item_name):
check_file()
with open('inventory.txt', 'r') as file:
inventory = file.readlines()

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

widget not found in inventory.


soaps: 30
detergent not found in inventory.

PURCHASE TEXT FILE :

# Define the file path where purchase data will be stored


file_path = "purchases.txt"

# Define a function to record a new purchase and add it to the file


def record_purchase(product_name, quantity, price):
with open(file_path, "a") as file:
file.write(f"{product_name},{quantity},{price}\n")
print("Purchase recorded.")

# 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

# Define a function to calculate the total cost of all purchases


def calculate_total_cost():
total_cost = 0
with open(file_path, "r") as file:
for line in file:
fields = line.strip().split(",")
quantity = int(fields[1])
price = float(fields[2])
total_cost += quantity * price
return total_cost

# Define a function to calculate the total quantity of a specific product purchased


def calculate_total_quantity(product_name):
total_quantity = 0
with open(file_path, "r") as file:
for line in file:
fields = line.strip().split(",")
if fields[0] == product_name:
total_quantity += int(fields[1])
return total_quantity

# Example usage: record a new purchase


record_purchase("Widget A", 10, 2.99)
record_purchase("soaps", 5, 41.2)

# Example usage: read all purchases from the file and print their data
purchases = read_purchases()
for purchase in purchases:
print(purchase)

# Example usage: calculate the total cost of all purchases


total_cost = calculate_total_cost()
print(f"Total cost of all purchases: {total_cost}")

# Example usage: calculate the total quantity of a specific product purchased


total_quantity = calculate_total_quantity("Widget A")
total_quantity = calculate_total_quantity("soaps")
print(f"Total quantity of Widget A purchased: {total_quantity}")

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 :

we are using create,read,update,delete operations to manage customer details in inventory


management system .

# Define the file path where customer data will be stored


file_path = "customers.txt"

# 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

# Define a function to update a customer's data in the file by name


def update_customer(name, address=None, email=None, phone=None):
customers = read_customers()
for i in range(len(customers)):
if customers[i]["name"] == name:
if address is not None:
customers[i]["address"] = address
if email is not None:
customers[i]["email"] = email
if phone is not None:
customers[i]["phone"] = phone
with open(file_path, "w") as file:
for customer in customers:
file.write(f"{customer['name']},{customer['address']},{customer['email
print(f"Customer {name} updated in the file.")
return
print(f"Customer {name} not found in the file.")

# Define a function to delete a customer from the file by name


def delete_customer(name):
customers = read_customers()
for i in range(len(customers)):
if customers[i]["name"] == name:
del customers[i]
with open(file_path, "w") as file:
for customer in customers:
file.write(f"{customer['name']},{customer['address']},{customer['email
print(f"Customer {name} deleted from the file.")
return
print(f"Customer {name} not found in the file.")

# Example usage: create a new customer


create_customer("John Doe", "123 Main St", "[email protected]", "555-1234")
create_customer("sid", "35 church street", "[email protected]", "353-1344")

# 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.")

# Example usage: update a customer's data in the file by name


update_customer("hashi", phone="515-22418")

New customer John Doe added to the file.


New customer sid added to the file.
{'name': 'John Doe', 'address': '123 Main St', 'email': '[email protected]', 'ph
{'name': 'sid', 'address': '43 church street', 'email': '[email protected]', 'phone
{'name': 'krish', 'address': '5 ramkom', 'email': '[email protected]', 'phone': '6
{'name': 'tan', 'address': '35 casiko', 'email': '[email protected]', 'phone': '324
{'name': 'John Doe', 'address': '123 Main St', 'email': '[email protected]', 'ph
{'name': 'sid', 'address': '35 church street', 'email': '[email protected]', 'phone
{'name': 'John Doe', 'address': '123 Main St', 'email': '[email protected]', 'ph
{'name': 'sid', 'address': '35 church street', 'email': '[email protected]', 'phone
Customer not found.
Customer hashi not found in the file.

PROCESS FLOW DIAGRAM :

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.

3. The user can look up a customer by name or ID number.

4. The Customer function looks up the supplied customer in the customer database.

5. The Customer function displays information about the customer.

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.

You might also like