Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import datetime
- def main():
- loginMenu()
- def loginMenu():
- #Loads The Main Menu
- print("""
- #################################################################
- # #
- # Guild of the Ceramic Arts #
- # Please Enter Your Login Details Below! #
- # #
- #################################################################
- """)
- #UserLogInAndCreatingUser
- authenticateUser()
- #Authenticates and checks the users
- def authenticateUser():
- authenticateUsername = ""
- authenticatePassword = ""
- while True:
- #Allows a User to Sign In
- username = str(input("\nPlease enter your username for your current Account! \n"))
- password = str(input("\nPlease enter your password for your current Account! \n"))
- #Checks User File For Any Users
- while True:
- readUsers = open("Users.txt","r")
- lines = readUsers.readlines()
- if len(lines) == 0:
- print("There is no Users file for you to search! Would you like to create a new file? \n") #Searches for a file
- createUser()
- continue
- authenticateCounter = 0
- #Checks For The Username and Password in The Specific Locations
- i = 0
- while i < len(lines):
- location = lines[i]
- authenticateUsername = location [0:10]
- authenticateUsername = authenticateUsername.strip()
- authenticateUsername = authenticateUsername.lower()
- username = username.lower()
- authenticatePassword = location[10:20]
- authenticatePassword = authenticatePassword.strip()
- authenticatePassword = authenticatePassword.lower()
- password = password.lower()
- if location == "":
- readUsers.close()
- break
- if authenticateUsername == username and authenticatePassword == password:
- authenticateCounter = authenticateCounter + 1
- mainMenu()
- break
- i += 1
- if authenticateCounter ==0:
- print("\nThere is no user in the file with those login details, please re-try!. \n")
- loginMenu()
- else:
- break
- main()
- #Prints the Main Menu to the screen and Lists all options
- def mainMenu():
- print("""
- #################################################################################
- # #
- # #
- # Welcome to the #
- # #
- # Guild of the Ceramic Arts #
- # #
- # Main Menu #
- # #
- # #
- # Please choose what you would like to do? #
- # #
- # #
- # 1 - Add a new User #
- # #
- # 2 - Create a new customer #
- # #
- # 3 - Add new product #
- # #
- # 4 - Delete product #
- # #
- # 5 - Create new order #
- # #
- # 6 - Logout of your account #
- # #
- # 7 - Print an Invoice #
- # #
- # 8 - Delete a Customer #
- # #
- # 9 - Unpaid orders #
- # #
- # 10 - Leave the menu #
- # #
- #################################################################################
- """)
- mainMenu=input("What would like to do? Please pick an Option between the following... '1', '2', '3', '4', '5' , '6', '7' or '8', '9', '10' : ")
- #GoesToAddUserMenu
- if mainMenu =="1":
- createUser()
- return
- elif mainMenu =="2":
- createUser()
- return
- #GoesToCreateCustomerMenu
- elif mainMenu =="3":
- newProduct()
- return
- #GoesToAddNewProductMenu
- elif mainMenu =="4":
- removeProduct()
- return
- #GoesToRemoveProductMenu
- elif mainMenu =="5":
- createOrder()
- return
- #GoesToCreateAnOrderMenu
- elif mainMenu =="6":
- quit()
- return
- #MakesYourUserQuitAndLogOut
- elif mainMenu =="7":
- createInvoice()
- return
- #GoesToYourInvoiceMenu
- elif mainMenu =="8":
- deleteUser()
- return
- #GoesToDeleteUserMenu
- elif mainMenu =="9":
- unpaidOrders()
- return
- elif mainmenu =="10":
- paidOrders()
- #GoesToAllUnpaidOrders
- elif mainMenu =="11":
- quit()
- #QuitsTheProgram
- else:
- print("\nThat is not a valid number, you must select '1', '2', '3', '4', '5' , '6' or '7', '8', '9', '10': please try again. ")
- #Takes You To Create a User
- def createUser():
- userName, password1, password2 = "", "", ""
- #Creating a New Account For The User
- while True:
- userName=input("\n Please insert a new Username for the new user (input '0' to cancel and exit the create user menu): ")
- if userName =="-1":
- mainMenu()
- #Creating a Username for the new user
- if len(userName)>10:
- print("\n This username has to be between 1 and 10 characters!")
- #Allowing User To Create a Password
- elif userName.isalpha()==False:
- print("\nYou need to use letters only!")
- #Allowing Letters Only To Be Used in The Username
- else:
- break
- while True:
- password1=input("\nInput a password for the user (input '-1' to cancel and exit): ")
- if password1 =="-1":
- mainMenu()
- #Allowing a password to be made
- if len(password1)>10:
- print("\nPassword has to be between 1 and 10 charcters!")
- password2=input("\nInput the password again (input '-1' to cancel and exit): ")
- if password2 =="-1":
- mainMenu()
- if len(password2)>10:
- print("\nPassword has to be between 1 and 10 charcters!")
- if password1 != password2:
- #Making the password requires less than 10 characters
- print("\nThe passwords did not match, please try again!")
- else:
- break
- userName=userName.lower()
- password1=password1.lower()
- #Location of the username and password to be stored at
- userNameStore=userName.ljust(10)
- password1Store=password1.ljust(10)
- #Where all user info is stored
- store=open("users.txt","a")
- iStore=userNameStore+password1Store+"\n"
- store.write(iStore)
- store.close()
- def userName():
- #ChecksFilesForCustomers
- def check_files():
- for i in ["stock","users","orders","customers"]:
- if not os.path.isfile(i+".txt"):
- print ("Creating the " + i + " file....")
- stockID = open(i+".txt", 'w')
- print(i + " file created")
- #Creates files if no file is present
- print("\n" + userName + " has been successfully created!")
- print("Username :",userName)
- print("Password : ********** ")
- check_files()
- #Allows The User To Delete an Account
- def deleteUser():
- while True:
- username = input("\nPlease enter the username of the user you would wish to delete from the software: ")
- if username == "-1":
- #Finds the user to delete off the software
- mainMenu()
- if len(username) >10:
- print("\nYour username you have created must be less than 11 characters.\n")
- elif username.isalpha() == False:
- #The username is not in the boundaries of the characters used
- print("\nThe username must only contain alpha.\n")
- else:
- break
- store = open("users.txt","r")
- lines = store.readlines()
- store.close()
- store = open("users.txt","w")
- for line in lines:
- if line[0:10].lower().strip() != username.lower().strip():
- store.write(line)
- store.close()
- print("User is now successfully deleted")
- #User is removed from the system
- #Allows The User to Create an Account
- def createUser():
- userName, password1, password2 = "", "", ""
- while True:
- userName=input("\n Please insert a new Username for the new user (input '-1' to cancel and exit the create user menu): ")
- if userName =="-1":
- mainMenu()
- if len(userName)>10:
- print("\n This username has to be between 1 and 10 characters!")
- elif userName.isalpha()==False:
- print("\nYou need to use letters only!")
- else:
- break
- while True:
- password1=input("\nInput a password for the user (input '-1' to cancel and exit): ")
- if password1 =="-1":
- mainMenu()
- if len(password1)>10:
- print("\nPassword has to be between 1 and 10 charcters!")
- password2=input("\nInput the password again (input '-1' to cancel and exit): ")
- if password2 =="-1":
- mainMenu()
- if len(password2)>10:
- print("\nPassword has to be between 1 and 10 charcters!")
- if password1 != password2:
- print("\nThe passwords did not match, please try again!")
- else:
- break
- userName=userName.lower()
- password1=password1.lower()
- userNameStore=userName.ljust(10)
- password1Store=password1.ljust(10)
- store=open("users.txt","a")
- iStore=userNameStore+password1Store+"\n"
- store.write(iStore)
- store.close()
- #Create an Order For The Users Product(s)
- def createOrder():
- while True:
- customerID = input("Please enter your customer ID: ")
- with open('customers.txt') as f:
- if customerID in f.read():
- print("\nThe customer ID is valid")
- break
- #Customer ID of an order is invalid
- else:
- print("\nThat Customer ID does not exist. Please try again")
- while True:
- orderID = input("Please enter a unique ID for your order to show your item (5 numbers): ")
- if orderID.isdigit()==False:
- print("\nYou can only use numbers for your unique ID in order to see your order")
- elif len(orderID) != 5:
- print("\nYou must use exactly 5 digits")
- #Digits of the order is not recognized and is over the limit of 5
- else:
- print("Your unique ID is OR" + orderID)
- break
- #Prints your unique order on to your screen
- while True:
- item_name = input("\nPlease type the name of the item you would like to purchase: ")
- with open('stock.txt') as f:
- if item_name in f.read():
- print("\nItem Successfully added")
- #Items are added to basket ready to purchase for the customer
- break
- elif item_name not in f.read():
- print("\nThis item currently does not exist. Please try again")
- #Invalid item ID have been searched for
- while True:
- readStock = open('stock.txt','r')
- location = readStock.readline()
- price = location[33:50]
- price = float(price)
- quantity = int(input("\nHow much of the product would you like to purchase? (Above 1 and Up to 100): "))
- if quantity >100:
- print("\nYou can only buy up to 100 items")
- #You have exceeded the maximum number of orders placed in your basket
- elif quantity <1:
- ("\nYou must buy a minimum of 1 item!")
- #No items are placed and quantity of less than zero is invalid
- finalPrice = (price*quantity)
- if finalPrice >= 50:
- finalPrice *= 0.95
- readStock.close()
- break
- #Location of all orders and order ID plus all customer ID
- orderID = ("OR")+ orderID
- orderID=orderID.strip()
- orderID=orderID.lower()
- orderIDStore=orderID.ljust(60)
- customerID=customerID.strip()
- customerID=customerID.lower()
- customerIDStore=customerID.ljust(13)
- finalPrice=str(finalPrice)
- finalPrice=finalPrice.ljust(7)
- today = date.today()
- today = str(today)
- today = today.ljust(15)
- quantity = str(quantity)
- quantityStore = quantity.ljust(55)
- #Final price of the basket is displayed in the folder/file
- order_file = open('orders.txt', 'a')
- stock_file = open('stock.txt', 'r')
- for line in stock_file:
- if item_name in line:
- line = line.ljust(12)
- order_store = finalPrice + today + customerIDStore + line + quantityStore + orderIDStore + "\n"
- order_file.write(order_store)
- print("\nThank you! Your chosen items have been successfully added to your order! ")
- #Order has been placed and items are added to that also
- order_file.close()
- stock_file.close()
- mainMenu()
- def unpaidOrders(): #Opens unpaid orders function
- today = datetime.datetime.now() #Current Date is being retrieved
- with open('orders.txt') as orders:
- expired = []
- dates = [[datetime.datetime.strptime(i[130:196].strip(), '%Y-%m-%d %H:%M:%S.%f'),i[95:102]] for i in orders.readlines()]
- for i in dates: #Checking invoices and dates
- if datetime.datetime.now() > i[0] + datetime.timedelta(28):
- expired.append(i)
- if len (expired) >0:
- print("Unpaid orders:\n" + "\n".join([("Order ID: " + i[1] + " Date: " + i[0]) for i in[[str(i[0]),i[1]] for i in expired]])) #Prints The date of the late orders
- else:
- print("\nThere are currently no late orders")
- mainMenu()
- #Create an Invoice for The Customers Order
- def createInvoice():
- while True:
- orderID = input("Please enter your order ID\n ")
- with open('orders.txt') as f:
- if orderID in f.read():
- print("Invoice Printed")
- break
- #Invoice is now echoed to the screen and can be printed
- else:
- #Locating OrderID
- print("Order ID was not found. Please try again")
- with open ("orders.txt","r") as f:
- f.seek(0)
- for line in f.read():
- if orderID in line:
- finalPrice = line[0:8]
- today = line[8:18]
- customerIDStore = line[23:32]
- productQuantity = line[36:40]
- date = line[48:60]
- orderID = line[91:98]
- productName = line[151:160]
- productID = line[176:183]
- productPrice = line[184:190]
- finalPrice = finalPrice + 5.99
- print("Final Price (Including £5.99: "+finalPrice)
- print("Date: "+today)
- print("Customer ID: "+customerIDStore)
- print("Product Quantity: "+productQuantity)
- print("Order ID: "+orderID)
- print("Product Name: "+productName)
- print("Product ID: "+productID)
- print("Individual Product Price: "+productPrice)
- break
- #Location of the required ID and information of the Invoice
- #Allows an Admin to Create a Product or to add a product(s)
- def newProduct():
- productID = ""
- productName = ""
- productPrice = ""
- #Creating a product and adding the username
- while True:
- productName = input("\nInput the product name you would like to create: ")
- productName.strip()
- productName.lower()
- if len(productName)>25:
- print("\nProduct name must be between 1 and 25 characters! Try Again! ")#Product Name is too long and not in boundaries
- break
- while True:
- productID = input("\nInput the product ID of the product you want to add (5 Numbers): ") #Product ID for a unique product
- productID.strip()
- if len(productID)>5:
- print("\nThe product number, '"+str(productID)+"' that exceeds that amount required!")
- if len (productID)<5:
- print("\nThe prodcut number, '"+str(productID)+"' that is below the amount required!")
- elif productID.isdigit()!= True:
- print("\nYou can only use numbers for the product ID!") #Lists the required things to create the product
- elif productID.isdigit()!= False:
- print("\nYour product has been successfully added to the files!")
- productID=input("\nTo exit please type: '-1': ")
- if productID ==" -1":
- exit()
- break
- while True:
- productPrice=float(input("\nInput the price of the product: ")) #Adds a price to the given product
- productPrice=str(productPrice)
- productID = "PT"+productID
- productID.strip()
- productID.lower()
- productIDStore = productID.ljust(8)
- productName.strip()
- productName.lower()
- productNameStore = productName.ljust(25)
- store= open("stock.txt","a")
- istore= productNameStore + productIDStore + productPrice+ "\n"
- store.write(istore)
- store.close()
- print("\nFinished adding the new product")
- print("Product ID: ",productIDStore)
- print("Product Name: ",productNameStore)
- print("Product Price: ",productPrice)
- break
- mainmenu()
- main()
- def deleteInvoiceID(): #Deleting an invoice function
- while True:
- deleteInvoiceID = input("\nPlease enter the invoiceID of the invoice you wish to delete: ")
- if deleteInvoiceID == "-1":
- Menu()
- elif invoiceID.isalpha() == False:
- print("\nInvoiceID must only contain alpha.\n") #Checks if invoice is only alpha
- else:
- break
- f = open("invoiceID.txt","r")
- lines = f.readlines()
- f.close()
- f = open("invoiceID.txt","w")
- for line in lines:
- if line[0:10].lower().strip() != invoiceID.lower().strip():
- f.write(line)
- f.close()
- print("InvoiceID successfully deleted") #Invoice is now removed from the files
- def removeProduct():
- product = input("What product would you like to delete (Insert Name)? ") #Checks the product name is its correct
- f = open("stock.txt","r+")
- r = open("newStocks.txt","w")
- deleted = 0
- for line in f:
- stock = line [0:25]
- stock = stock.lower()
- stock = stock.strip()
- if product == stock:
- deleted = deleted + 1
- line = ""
- r.write(line+'\n')
- f.close()
- r.close()
- if deleted == 1:
- print("\nProduct name '"+str(product)+"' has been deleted!") #Product is now removed from the file
- cleanupProduct()
- def cleanupProduct():
- with open("newStocks.txt","r+") as f, open("stock.txt","w") as r:
- for i in f.readlines():
- if not i.strip():
- continue
- if i:
- r.write(i)
- f.close()
- r.close()
- mainMenu()
- def PaidOrders(): #This prints the paid menu - used to check if paid
- while True: #Checks the ID given by user if valid or not
- orderID = input("Please enter the order ID you want to pay for: ")
- with open('orders.txt') as f:
- if orderID in f.read():
- print("OrderID verified")
- with open('paid.txt') as h: #Checks to see if this has been paid or not
- if orderID in h.read():
- print("OrderID already paid for") #Prints to sreen and shows order
- mainMenu()
- else:
- print(orderID+" does not exist/has not been paid") #The ID given is payed or not existent in the current file
- mainMenu()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement