Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.35 KB | None | 0 0
  1. import os
  2. import datetime
  3.  
  4.  
  5.  
  6. def main():
  7. loginMenu()
  8.  
  9.  
  10. def loginMenu():
  11. #Loads The Main Menu
  12. print("""
  13. #################################################################
  14. # #
  15. # Guild of the Ceramic Arts #
  16. # Please Enter Your Login Details Below! #
  17. # #
  18. #################################################################
  19. """)
  20.  
  21. #UserLogInAndCreatingUser
  22. authenticateUser()
  23.  
  24. #Authenticates and checks the users
  25. def authenticateUser():
  26. authenticateUsername = ""
  27. authenticatePassword = ""
  28. while True:
  29. #Allows a User to Sign In
  30. username = str(input("\nPlease enter your username for your current Account! \n"))
  31. password = str(input("\nPlease enter your password for your current Account! \n"))
  32. #Checks User File For Any Users
  33. while True:
  34. readUsers = open("Users.txt","r")
  35. lines = readUsers.readlines()
  36. if len(lines) == 0:
  37. print("There is no Users file for you to search! Would you like to create a new file? \n") #Searches for a file
  38. createUser()
  39. continue
  40. authenticateCounter = 0
  41. #Checks For The Username and Password in The Specific Locations
  42. i = 0
  43. while i < len(lines):
  44. location = lines[i]
  45. authenticateUsername = location [0:10]
  46. authenticateUsername = authenticateUsername.strip()
  47. authenticateUsername = authenticateUsername.lower()
  48. username = username.lower()
  49. authenticatePassword = location[10:20]
  50. authenticatePassword = authenticatePassword.strip()
  51. authenticatePassword = authenticatePassword.lower()
  52. password = password.lower()
  53.  
  54. if location == "":
  55. readUsers.close()
  56. break
  57. if authenticateUsername == username and authenticatePassword == password:
  58. authenticateCounter = authenticateCounter + 1
  59. mainMenu()
  60. break
  61. i += 1
  62. if authenticateCounter ==0:
  63. print("\nThere is no user in the file with those login details, please re-try!. \n")
  64. loginMenu()
  65. else:
  66. break
  67. main()
  68.  
  69.  
  70. #Prints the Main Menu to the screen and Lists all options
  71.  
  72. def mainMenu():
  73. print("""
  74.  
  75. #################################################################################
  76. # #
  77. # #
  78. # Welcome to the #
  79. # #
  80. # Guild of the Ceramic Arts #
  81. # #
  82. # Main Menu #
  83. # #
  84. # #
  85. # Please choose what you would like to do? #
  86. # #
  87. # #
  88. # 1 - Add a new User #
  89. # #
  90. # 2 - Create a new customer #
  91. # #
  92. # 3 - Add new product #
  93. # #
  94. # 4 - Delete product #
  95. # #
  96. # 5 - Create new order #
  97. # #
  98. # 6 - Logout of your account #
  99. # #
  100. # 7 - Print an Invoice #
  101. # #
  102. # 8 - Delete a Customer #
  103. # #
  104. # 9 - Unpaid orders #
  105. # #
  106. # 10 - Leave the menu #
  107. # #
  108. #################################################################################
  109.  
  110. """)
  111. 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' : ")
  112. #GoesToAddUserMenu
  113. if mainMenu =="1":
  114. createUser()
  115. return
  116. elif mainMenu =="2":
  117. createUser()
  118. return
  119. #GoesToCreateCustomerMenu
  120. elif mainMenu =="3":
  121. newProduct()
  122. return
  123. #GoesToAddNewProductMenu
  124. elif mainMenu =="4":
  125. removeProduct()
  126. return
  127. #GoesToRemoveProductMenu
  128. elif mainMenu =="5":
  129. createOrder()
  130. return
  131. #GoesToCreateAnOrderMenu
  132. elif mainMenu =="6":
  133. quit()
  134. return
  135. #MakesYourUserQuitAndLogOut
  136. elif mainMenu =="7":
  137. createInvoice()
  138. return
  139. #GoesToYourInvoiceMenu
  140. elif mainMenu =="8":
  141. deleteUser()
  142. return
  143. #GoesToDeleteUserMenu
  144. elif mainMenu =="9":
  145. unpaidOrders()
  146. return
  147. elif mainmenu =="10":
  148. paidOrders()
  149. #GoesToAllUnpaidOrders
  150. elif mainMenu =="11":
  151. quit()
  152. #QuitsTheProgram
  153. else:
  154.  
  155. print("\nThat is not a valid number, you must select '1', '2', '3', '4', '5' , '6' or '7', '8', '9', '10': please try again. ")
  156.  
  157.  
  158.  
  159. #Takes You To Create a User
  160. def createUser():
  161. userName, password1, password2 = "", "", ""
  162. #Creating a New Account For The User
  163. while True:
  164. userName=input("\n Please insert a new Username for the new user (input '0' to cancel and exit the create user menu): ")
  165. if userName =="-1":
  166. mainMenu()
  167. #Creating a Username for the new user
  168. if len(userName)>10:
  169. print("\n This username has to be between 1 and 10 characters!")
  170. #Allowing User To Create a Password
  171. elif userName.isalpha()==False:
  172. print("\nYou need to use letters only!")
  173. #Allowing Letters Only To Be Used in The Username
  174. else:
  175. break
  176. while True:
  177. password1=input("\nInput a password for the user (input '-1' to cancel and exit): ")
  178. if password1 =="-1":
  179. mainMenu()
  180. #Allowing a password to be made
  181. if len(password1)>10:
  182. print("\nPassword has to be between 1 and 10 charcters!")
  183. password2=input("\nInput the password again (input '-1' to cancel and exit): ")
  184. if password2 =="-1":
  185. mainMenu()
  186. if len(password2)>10:
  187. print("\nPassword has to be between 1 and 10 charcters!")
  188. if password1 != password2:
  189. #Making the password requires less than 10 characters
  190. print("\nThe passwords did not match, please try again!")
  191. else:
  192. break
  193.  
  194. userName=userName.lower()
  195. password1=password1.lower()
  196. #Location of the username and password to be stored at
  197. userNameStore=userName.ljust(10)
  198. password1Store=password1.ljust(10)
  199. #Where all user info is stored
  200. store=open("users.txt","a")
  201. iStore=userNameStore+password1Store+"\n"
  202. store.write(iStore)
  203.  
  204. store.close()
  205.  
  206.  
  207.  
  208.  
  209.  
  210. def userName():
  211. #ChecksFilesForCustomers
  212. def check_files():
  213. for i in ["stock","users","orders","customers"]:
  214. if not os.path.isfile(i+".txt"):
  215. print ("Creating the " + i + " file....")
  216. stockID = open(i+".txt", 'w')
  217. print(i + " file created")
  218. #Creates files if no file is present
  219. print("\n" + userName + " has been successfully created!")
  220. print("Username :",userName)
  221. print("Password : ********** ")
  222. check_files()
  223. #Allows The User To Delete an Account
  224. def deleteUser():
  225.  
  226. while True:
  227. username = input("\nPlease enter the username of the user you would wish to delete from the software: ")
  228. if username == "-1":
  229. #Finds the user to delete off the software
  230. mainMenu()
  231. if len(username) >10:
  232. print("\nYour username you have created must be less than 11 characters.\n")
  233. elif username.isalpha() == False:
  234. #The username is not in the boundaries of the characters used
  235. print("\nThe username must only contain alpha.\n")
  236. else:
  237. break
  238. store = open("users.txt","r")
  239. lines = store.readlines()
  240. store.close()
  241. store = open("users.txt","w")
  242. for line in lines:
  243. if line[0:10].lower().strip() != username.lower().strip():
  244. store.write(line)
  245. store.close()
  246. print("User is now successfully deleted")
  247. #User is removed from the system
  248.  
  249. #Allows The User to Create an Account
  250.  
  251.  
  252.  
  253. def createUser():
  254. userName, password1, password2 = "", "", ""
  255. while True:
  256. userName=input("\n Please insert a new Username for the new user (input '-1' to cancel and exit the create user menu): ")
  257. if userName =="-1":
  258. mainMenu()
  259. if len(userName)>10:
  260. print("\n This username has to be between 1 and 10 characters!")
  261. elif userName.isalpha()==False:
  262. print("\nYou need to use letters only!")
  263. else:
  264. break
  265. while True:
  266. password1=input("\nInput a password for the user (input '-1' to cancel and exit): ")
  267. if password1 =="-1":
  268. mainMenu()
  269. if len(password1)>10:
  270. print("\nPassword has to be between 1 and 10 charcters!")
  271. password2=input("\nInput the password again (input '-1' to cancel and exit): ")
  272. if password2 =="-1":
  273. mainMenu()
  274. if len(password2)>10:
  275. print("\nPassword has to be between 1 and 10 charcters!")
  276. if password1 != password2:
  277. print("\nThe passwords did not match, please try again!")
  278. else:
  279. break
  280. userName=userName.lower()
  281. password1=password1.lower()
  282.  
  283. userNameStore=userName.ljust(10)
  284. password1Store=password1.ljust(10)
  285.  
  286. store=open("users.txt","a")
  287. iStore=userNameStore+password1Store+"\n"
  288. store.write(iStore)
  289.  
  290. store.close()
  291.  
  292.  
  293. #Create an Order For The Users Product(s)
  294.  
  295.  
  296.  
  297. def createOrder():
  298.  
  299.  
  300. while True:
  301. customerID = input("Please enter your customer ID: ")
  302. with open('customers.txt') as f:
  303. if customerID in f.read():
  304. print("\nThe customer ID is valid")
  305. break
  306. #Customer ID of an order is invalid
  307. else:
  308. print("\nThat Customer ID does not exist. Please try again")
  309. while True:
  310. orderID = input("Please enter a unique ID for your order to show your item (5 numbers): ")
  311. if orderID.isdigit()==False:
  312. print("\nYou can only use numbers for your unique ID in order to see your order")
  313. elif len(orderID) != 5:
  314.  
  315. print("\nYou must use exactly 5 digits")
  316. #Digits of the order is not recognized and is over the limit of 5
  317. else:
  318. print("Your unique ID is OR" + orderID)
  319. orderID = ("OR")+ orderID
  320. orderID=orderID.strip()
  321. orderID=orderID.lower()
  322. orderIDStore=orderID.ljust(60)
  323. break
  324. #Prints your unique order on to your screen
  325.  
  326. while True:
  327. item_name = input("\nPlease type the name of the item you would like to purchase: ")
  328. with open('stock.txt') as f:
  329. if item_name in f.read():
  330. print("\nItem Successfully added")
  331. #Items are added to basket ready to purchase for the customer
  332. break
  333. elif item_name not in f.read():
  334. print("\nThis item currently does not exist. Please try again")
  335. #Invalid item ID have been searched for
  336. while True:
  337. readStock = open('stock.txt','r')
  338. location = readStock.readline()
  339. price = location[33:50]
  340. price = float(price)
  341. quantity = int(input("\nHow much of the product would you like to purchase? (Above 1 and Up to 100): "))
  342. if quantity >100:
  343. print("\nYou can only buy up to 100 items")
  344. #You have exceeded the maximum number of orders placed in your basket
  345. elif quantity <1:
  346. ("\nYou must buy a minimum of 1 item!")
  347. #No items are placed and quantity of less than zero is invalid
  348. finalPrice = (price*quantity)
  349. if finalPrice >= 50:
  350. finalPrice *= 0.95
  351. readStock.close()
  352. finalPrice=str(finalPrice)
  353. finalPrice=finalPrice.ljust(7)
  354. break
  355. #Location of all orders and order ID plus all customer ID
  356.  
  357. customerID=customerID.strip()
  358. customerID=customerID.lower()
  359. customerIDStore=customerID.ljust(13)
  360. today = datetime.today()
  361.  
  362. today = str(today)
  363. today = today.ljust(15)
  364. quantity = str(quantity)
  365. quantityStore = quantity.ljust(55)
  366. #Final price of the basket is displayed in the folder/file
  367.  
  368. order_file = open('orders.txt', 'a')
  369. stock_file = open('stock.txt', 'r')
  370. for line in stock_file:
  371. if item_name in line:
  372. line = line.ljust(12)
  373. order_store = finalPrice + today + customerIDStore + line + quantityStore + orderIDStore + "\n"
  374. order_file.write(order_store)
  375. print("\nThank you! Your chosen items have been successfully added to your order! ")
  376. #Order has been placed and items are added to that also
  377. order_file.close()
  378. stock_file.close()
  379. mainMenu()
  380.  
  381. def unpaidOrders(): #Opens unpaid orders function
  382.  
  383. today = datetime.datetime.now() #Current Date is being retrieved
  384.  
  385. with open('orders.txt') as orders:
  386. expired = []
  387. dates = [[datetime.datetime.strptime(i[130:196].strip(), '%Y-%m-%d %H:%M:%S.%f'),i[95:102]] for i in orders.readlines()]
  388. for i in dates: #Checking invoices and dates
  389. if datetime.datetime.now() > i[0] + datetime.timedelta(28):
  390. expired.append(i)
  391. if len (expired) >0:
  392. 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
  393. else:
  394. print("\nThere are currently no late orders")
  395.  
  396. mainMenu()
  397.  
  398.  
  399.  
  400. #Create an Invoice for The Customers Order
  401.  
  402.  
  403.  
  404. def createInvoice():
  405.  
  406. while True:
  407. orderID = input("Please enter your order ID\n ")
  408. with open('orders.txt') as f:
  409. if orderID in f.read():
  410. print("Invoice Printed")
  411. break
  412. #Invoice is now echoed to the screen and can be printed
  413. else:
  414. #Locating OrderID
  415. print("Order ID was not found. Please try again")
  416. with open ("orders.txt","r") as f:
  417. f.seek(0)
  418. for line in f.read():
  419. if orderID in line:
  420. finalPrice = line[0:8]
  421. today = line[8:18]
  422. customerIDStore = line[23:32]
  423. productQuantity = line[36:40]
  424. date = line[48:60]
  425. orderID = line[91:98]
  426. productName = line[151:160]
  427. productID = line[176:183]
  428. productPrice = line[184:190]
  429. finalPrice = finalPrice + 5.99
  430. print("Final Price (Including £5.99: "+finalPrice)
  431. print("Date: "+today)
  432. print("Customer ID: "+customerIDStore)
  433. print("Product Quantity: "+productQuantity)
  434. print("Order ID: "+orderID)
  435. print("Product Name: "+productName)
  436. print("Product ID: "+productID)
  437. print("Individual Product Price: "+productPrice)
  438.  
  439. break
  440. #Location of the required ID and information of the Invoice
  441.  
  442.  
  443. #Allows an Admin to Create a Product or to add a product(s)
  444.  
  445.  
  446. def newProduct():
  447. productID = ""
  448. productName = ""
  449. productPrice = ""
  450. #Creating a product and adding the username
  451. while True:
  452. productName = input("\nInput the product name you would like to create: ")
  453. productName.strip()
  454. productName.lower()
  455. if len(productName)>25:
  456. print("\nProduct name must be between 1 and 25 characters! Try Again! ")#Product Name is too long and not in boundaries
  457. break
  458. while True:
  459. productID = input("\nInput the product ID of the product you want to add (5 Numbers): ") #Product ID for a unique product
  460. productID.strip()
  461. if len(productID)>5:
  462. print("\nThe product number, '"+str(productID)+"' that exceeds that amount required!")
  463. if len (productID)<5:
  464. print("\nThe prodcut number, '"+str(productID)+"' that is below the amount required!")
  465. elif productID.isdigit()!= True:
  466. print("\nYou can only use numbers for the product ID!") #Lists the required things to create the product
  467. elif productID.isdigit()!= False:
  468. print("\nYour product has been successfully added to the files!")
  469. productID=input("\nTo exit please type: '-1': ")
  470. if productID ==" -1":
  471. exit()
  472. break
  473. while True:
  474. productPrice=float(input("\nInput the price of the product: ")) #Adds a price to the given product
  475. productPrice=str(productPrice)
  476. productID = "PT"+productID
  477. productID.strip()
  478. productID.lower()
  479. productIDStore = productID.ljust(8)
  480. productName.strip()
  481. productName.lower()
  482. productNameStore = productName.ljust(25)
  483. store= open("stock.txt","a")
  484. istore= productNameStore + productIDStore + productPrice+ "\n"
  485. store.write(istore)
  486. store.close()
  487. print("\nFinished adding the new product")
  488. print("Product ID: ",productIDStore)
  489. print("Product Name: ",productNameStore)
  490. print("Product Price: ",productPrice)
  491. break
  492. mainmenu()
  493. main()
  494.  
  495. def deleteInvoiceID(): #Deleting an invoice function
  496. while True:
  497. deleteInvoiceID = input("\nPlease enter the invoiceID of the invoice you wish to delete: ")
  498. if deleteInvoiceID == "-1":
  499. Menu()
  500. elif invoiceID.isalpha() == False:
  501. print("\nInvoiceID must only contain alpha.\n") #Checks if invoice is only alpha
  502. else:
  503. break
  504. f = open("invoiceID.txt","r")
  505. lines = f.readlines()
  506. f.close()
  507. f = open("invoiceID.txt","w")
  508. for line in lines:
  509. if line[0:10].lower().strip() != invoiceID.lower().strip():
  510. f.write(line)
  511. f.close()
  512. print("InvoiceID successfully deleted") #Invoice is now removed from the files
  513.  
  514.  
  515. def removeProduct():
  516. product = input("What product would you like to delete (Insert Name)? ") #Checks the product name is its correct
  517. f = open("stock.txt","r+")
  518. r = open("newStocks.txt","w")
  519. deleted = 0
  520. for line in f:
  521. stock = line [0:25]
  522. stock = stock.lower()
  523. stock = stock.strip()
  524. if product == stock:
  525. deleted = deleted + 1
  526. line = ""
  527. r.write(line+'\n')
  528. f.close()
  529. r.close()
  530. if deleted == 1:
  531. print("\nProduct name '"+str(product)+"' has been deleted!") #Product is now removed from the file
  532. cleanupProduct()
  533.  
  534.  
  535.  
  536. def cleanupProduct():
  537. with open("newStocks.txt","r+") as f, open("stock.txt","w") as r:
  538. for i in f.readlines():
  539. if not i.strip():
  540. continue
  541. if i:
  542. r.write(i)
  543.  
  544. f.close()
  545. r.close()
  546. mainMenu()
  547.  
  548.  
  549. def PaidOrders(): #This prints the paid menu - used to check if paid
  550.  
  551. while True: #Checks the ID given by user if valid or not
  552. orderID = input("Please enter the order ID you want to pay for: ")
  553. with open('orders.txt') as f:
  554. if orderID in f.read():
  555. print("OrderID verified")
  556.  
  557. with open('paid.txt') as h: #Checks to see if this has been paid or not
  558. if orderID in h.read():
  559. print("OrderID already paid for") #Prints to sreen and shows order
  560. mainMenu()
  561. else:
  562. print(orderID+" does not exist/has not been paid") #The ID given is payed or not existent in the current file
  563. mainMenu()
  564. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement