import csv
from datetime import datetime
def login():
print("Please enter your credentials to login.")
username = input("Username: ")
password = input("Password: ")
if username == "admin" and password == "password":
print("Login successful!")
return true
else:
print("Incorrect username or password. Please try again.")
return false
def stock_item(item_name, item_quantity, item_location):
with open("inventory.csv", mode="a", newline="") as file:
writer = csv.writer(file)
now = datetime.now()
date_time = now.strftime("%m/%d/%Y %H:%M:%S")
writer.writerow([date_time, item_name, item_quantity, item_location, "IN"])
print(f"{item_quantity} units of {item_name} added to inventory.")
def withdraw_item(item_name, item_quantity):
with open("inventory.csv", mode="r") as file:
reader = csv.reader(file)
rows = list(reader)
for row in rows:
if row[1] == item_name:
if int(row[2]) >= item_quantity:
row[2] = str(int(row[2]) - item_quantity)
with open("inventory.csv", mode="w", newline="") as file:
writer = csv.writer(file)
writer.writerows(rows)
now = datetime.now()
date_time = now.strftime("%m/%d/%Y %H:%M:%S")
writer.writerow([date_time, item_name, item_quantity, row[3], "OUT"])
print(f"{item_quantity} units of {item_name} withdrawn from inventory.")
return
else:
print("Insufficient quantity in inventory.")
return
print("Item not found in inventory.")
def view_inventory():
with open("inventory.csv", mode="r") as file:
reader = csv.reader(file)
rows = list(reader)
if len(rows) > 0:
for row in rows:
print(row)
else:
print("Inventory is empty.")