Skip to content

Commit

Permalink
Uploaded py files: 3
Browse files Browse the repository at this point in the history
  • Loading branch information
jdhruv1503 authored Aug 19, 2021
1 parent ab11368 commit ff22b03
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 58 deletions.
155 changes: 97 additions & 58 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import csv
import pickle


def isAdmin(username, password):
Expand All @@ -20,109 +21,147 @@ def addAdmin(username, password):
adminWrite.writerow({'Username': username, 'Password': password})


def isWorker(username, password):
with open("workers.csv", "r") as workerFile:
workerRead = csv.DictReader(workerFile)
isValid = False
def checkStock():
with open("stock.dat", "rb") as stockFile:
stockDict = pickle.load(stockFile)
return stockDict

for line in workerRead:
if (line['Username'] == username) and (line['Password'] == password):
isValid = True
break
def outOfStockCheck():
outOfStock = False
stockDict = checkStock()
itemsOutOfStock = []

return isValid
for key in stockDict.keys():
if stockDict[key]==0:
outOfStock = True
itemsOutOfStock.append(key)

if outOfStock:
print("ALERT! Following items are currently out of stock: ",itemsOutOfStock)

def tooMuchStockCheck():
maxCapacity = 1000
stockDict = checkStock()
totalStock = 0

for value in stockDict.values():
totalStock += value

if totalStock >= 0.9*maxCapacity:
print("ALERT! Warehouse nearing capacity. Ship some stock soon. Max capacity: ",maxCapacity," and current stock: ",totalStock)

def addStock():
maxCapacity = 1000
stockDict = checkStock()
print("The products are: ", stockDict)

product = str(input("Which product to update stock from? "))
add = int(input("How much stock to add? "))
stockDict[product] += add

with open("stock.dat", "wb") as stockFile:
pickle.dump(stockDict, stockFile)

def addWorker(username, password):
with open("workers.csv", "a", newline='') as workerFile:
workerWrite = csv.DictWriter(workerFile, ['Username', 'Password'])
workerWrite.writerow({'Username': username, 'Password': password})
print("Stock successfully updated!")


def workerstatus():
def removeStock():
stockDict = checkStock()
print("The products are: ", stockDict)

l=[]
product = str(input("Which product to update stock from? "))
remove = int(input("How much cargo to ship? "))

if remove <= stockDict[product]:
stockDict[product] -= remove
print("Stock successfully updated!")
with open("stock.dat", "wb") as stockFile:
pickle.dump(stockDict, stockFile)

else:
print("Cannot ship this cargo: Not enough stock")


def workerStatus():
l = []
minHours = 24
maxHours = 0

with open('workerlog.csv','r') as workerFile:
with open('workerlog.csv', 'r') as workerFile:
workerRead = csv.DictReader(workerFile)

for line in workerRead:
if line['workerHours'] == '0':
a=line['workerName']
a = line['workerName']
l.append(a)

elif ( int(line['workerHours']) < minHours ):
elif int(line['workerHours']) < minHours:
minHours = int(line['workerHours'])
minWorker = line['workerName']

elif ( int(line['workerHours']) > maxHours ):
elif int(line['workerHours']) > maxHours:
maxHours = int(line['workerHours'])
maxWorker = line['workerName']

print('List of absent workers today is: ',l)
print('List of absent workers today is: ', l)
print('The worker who has worked the most today is: ', maxWorker)
print('The worker who has worked the least today is: ', minWorker)

#-------------------------------------------------------------------------------------------------------

# -------------------------------------------------------------------------------------------------------

continueLoop = True

print('----- LOGIN SCREEN -----')
print('---Enter your choice:---')
print()
print('1. Administrator Login')
print('2. Worker Login')
username = str(input("Enter username: "))
password = str(input("Enter password: "))
print()
choice = int(input('Enter your choice (1/2): '))

if choice == 1:
if isAdmin(username, password):
print('Access granted.')
outOfStockCheck()
tooMuchStockCheck()

print()
print('----- ADMIN LOGIN -----')
username = str(input("Enter username: "))
password = str(input("Enter password: "))
print()

if isAdmin(username, password):
# ADMINISTRATOR FUNCTIONS
print('Access granted.')
while continueLoop:
print()
print('1. Add an Administrator account')
print('2. Add a Worker account')
print('3. View worker status and today\'s statistics')
print('1. Add a new login account')
print('2. View worker status and today\'s statistics')
print('3. Check current warehouse stock')
print('4. Received shipment (add stock)')
print('5. Ship cargo (remove stock)')
print('9. Log out')
print()
choiceA = int(input('Enter your choice (1/2/3): '))
choiceA = int(input('Enter your choice (1-9): '))

if choiceA == 1:
print()
uname = str(input("Enter the new user's username: "))
passwd = str(input("Enter the new user's password: "))
addAdmin(uname, passwd)
print("Adding new user \'", uname, "\' successful.")

elif choiceA == 2:
uname = str(input("Enter the new user's username: "))
passwd = str(input("Enter the new user's password: "))
addWorker(uname, passwd)
print()
workerStatus()

elif choiceA == 3:
workerstatus()
print()
print("Current stock is: ", checkStock())

else:
print('Wrong username and/or password. The program will now exit.')

elif choice == 2:
elif choiceA == 4:
print()
addStock()

print()
print('----- WORKER LOGIN ----')
username = str(input("Enter username: "))
password = str(input("Enter password: "))
print()
elif choiceA == 5:
print()
removeStock()

if isWorker(username, password):
print('Access granted.')
# HERE is where the fun begins. This is where we will add all worker functions, warehouse and vehicle management
elif choiceA == 9:
continueLoop = False

else:
print('Wrong username and/or password. The program will now exit.')
else:
print('Invalid input. The program will now exit.')

else:
print("Invalid input. Program will now exit.")
print('Wrong username and/or password. The program will now exit.')
Binary file added stock.dat
Binary file not shown.

0 comments on commit ff22b03

Please sign in to comment.