Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.08 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. break
  320. #Prints your unique order on to your screen
  321.  
  322. while True:
  323. item_name = input("\nPlease type the name of the item you would like to purchase: ")
  324. with open('stock.txt') as f:
  325. if item_name in f.read():
  326. print("\nItem Successfully added")
  327. #Items are added to basket ready to purchase for the customer
  328. break
  329. elif item_name not in f.read():
  330. print("\nThis item currently does not exist. Please try again")
  331. #Invalid item ID have been searched for
  332. while True:
  333. readStock = open('stock.txt','r')
  334. location = readStock.readline()
  335. price = location[33:50]
  336. price = float(price)
  337. quantity = int(input("\nHow much of the product would you like to purchase? (Above 1 and Up to 100): "))
  338. if quantity >100:
  339. print("\nYou can only buy up to 100 items")
  340. #You have exceeded the maximum number of orders placed in your basket
  341. elif quantity <1:
  342. ("\nYou must buy a minimum of 1 item!")
  343. #No items are placed and quantity of less than zero is invalid
  344. finalPrice = (price*quantity)
  345. if finalPrice >= 50:
  346. finalPrice *= 0.95
  347. readStock.close()
  348. break
  349. #Location of all orders and order ID plus all customer ID
  350. orderID = ("OR")+ orderID
  351. orderID=orderID.strip()
  352. orderID=orderID.lower()
  353. orderIDStore=orderID.ljust(60)
  354. customerID=customerID.strip()
  355. customerID=customerID.lower()
  356. customerIDStore=customerID.ljust(13)
  357. finalPrice=str(finalPrice)
  358. finalPrice=finalPrice.ljust(7)
  359. today = date.today()
  360.  
  361. today = str(today)
  362. today = today.ljust(15)
  363. quantity = str(quantity)
  364. quantityStore = quantity.ljust(55)
  365. #Final price of the basket is displayed in the folder/file
  366.  
  367. order_file = open('orders.txt', 'a')
  368. stock_file = open('stock.txt', 'r')
  369. for line in stock_file:
  370. if item_name in line:
  371. line = line.ljust(12)
  372. order_store = finalPrice + today + customerIDStore + line + quantityStore + orderIDStore + "\n"
  373. order_file.write(order_store)
  374. print("\nThank you! Your chosen items have been successfully added to your order! ")
  375. #Order has been placed and items are added to that also
  376. order_file.close()
  377. stock_file.close()
  378. mainMenu()
  379.  
  380. def unpaidOrders(): #Opens unpaid orders function
  381.  
  382. today = datetime.datetime.now() #Current Date is being retrieved
  383.  
  384. with open('orders.txt') as orders:
  385. expired = []
  386. dates = [[datetime.datetime.strptime(i[130:196].strip(), '%Y-%m-%d %H:%M:%S.%f'),i[95:102]] for i in orders.readlines()]
  387. for i in dates: #Checking invoices and dates
  388. if datetime.datetime.now() > i[0] + datetime.timedelta(28):
  389. expired.append(i)
  390. if len (expired) >0:
  391. 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
  392. else:
  393. print("\nThere are currently no late orders")
  394.  
  395. mainMenu()
  396.  
  397.  
  398.  
  399. #Create an Invoice for The Customers Order
  400.  
  401.  
  402.  
  403. def createInvoice():
  404.  
  405. while True:
  406. orderID = input("Please enter your order ID\n ")
  407. with open('orders.txt') as f:
  408. if orderID in f.read():
  409. print("Invoice Printed")
  410. break
  411. #Invoice is now echoed to the screen and can be printed
  412. else:
  413. #Locating OrderID
  414. print("Order ID was not found. Please try again")
  415. with open ("orders.txt","r") as f:
  416. f.seek(0)
  417. for line in f.read():
  418. if orderID in line:
  419. finalPrice = line[0:8]
  420. today = line[8:18]
  421. customerIDStore = line[23:32]
  422. productQuantity = line[36:40]
  423. date = line[48:60]
  424. orderID = line[91:98]
  425. productName = line[151:160]
  426. productID = line[176:183]
  427. productPrice = line[184:190]
  428. finalPrice = finalPrice + 5.99
  429. print("Final Price (Including £5.99: "+finalPrice)
  430. print("Date: "+today)
  431. print("Customer ID: "+customerIDStore)
  432. print("Product Quantity: "+productQuantity)
  433. print("Order ID: "+orderID)
  434. print("Product Name: "+productName)
  435. print("Product ID: "+productID)
  436. print("Individual Product Price: "+productPrice)
  437.  
  438. break
  439. #Location of the required ID and information of the Invoice
  440.  
  441.  
  442. #Allows an Admin to Create a Product or to add a product(s)
  443.  
  444.  
  445. def newProduct():
  446. productID = ""
  447. productName = ""
  448. productPrice = ""
  449. #Creating a product and adding the username
  450. while True:
  451. productName = input("\nInput the product name you would like to create: ")
  452. productName.strip()
  453. productName.lower()
  454. if len(productName)>25:
  455. print("\nProduct name must be between 1 and 25 characters! Try Again! ")#Product Name is too long and not in boundaries
  456. break
  457. while True:
  458. productID = input("\nInput the product ID of the product you want to add (5 Numbers): ") #Product ID for a unique product
  459. productID.strip()
  460. if len(productID)>5:
  461. print("\nThe product number, '"+str(productID)+"' that exceeds that amount required!")
  462. if len (productID)<5:
  463. print("\nThe prodcut number, '"+str(productID)+"' that is below the amount required!")
  464. elif productID.isdigit()!= True:
  465. print("\nYou can only use numbers for the product ID!") #Lists the required things to create the product
  466. elif productID.isdigit()!= False:
  467. print("\nYour product has been successfully added to the files!")
  468. productID=input("\nTo exit please type: '-1': ")
  469. if productID ==" -1":
  470. exit()
  471. break
  472. while True:
  473. productPrice=float(input("\nInput the price of the product: ")) #Adds a price to the given product
  474. productPrice=str(productPrice)
  475. productID = "PT"+productID
  476. productID.strip()
  477. productID.lower()
  478. productIDStore = productID.ljust(8)
  479. productName.strip()
  480. productName.lower()
  481. productNameStore = productName.ljust(25)
  482. store= open("stock.txt","a")
  483. istore= productNameStore + productIDStore + productPrice+ "\n"
  484. store.write(istore)
  485. store.close()
  486. print("\nFinished adding the new product")
  487. print("Product ID: ",productIDStore)
  488. print("Product Name: ",productNameStore)
  489. print("Product Price: ",productPrice)
  490. break
  491. mainmenu()
  492. main()
  493.  
  494. def deleteInvoiceID(): #Deleting an invoice function
  495. while True:
  496. deleteInvoiceID = input("\nPlease enter the invoiceID of the invoice you wish to delete: ")
  497. if deleteInvoiceID == "-1":
  498. Menu()
  499. elif invoiceID.isalpha() == False:
  500. print("\nInvoiceID must only contain alpha.\n") #Checks if invoice is only alpha
  501. else:
  502. break
  503. f = open("invoiceID.txt","r")
  504. lines = f.readlines()
  505. f.close()
  506. f = open("invoiceID.txt","w")
  507. for line in lines:
  508. if line[0:10].lower().strip() != invoiceID.lower().strip():
  509. f.write(line)
  510. f.close()
  511. print("InvoiceID successfully deleted") #Invoice is now removed from the files
  512.  
  513.  
  514. def removeProduct():
  515. product = input("What product would you like to delete (Insert Name)? ") #Checks the product name is its correct
  516. f = open("stock.txt","r+")
  517. r = open("newStocks.txt","w")
  518. deleted = 0
  519. for line in f:
  520. stock = line [0:25]
  521. stock = stock.lower()
  522. stock = stock.strip()
  523. if product == stock:
  524. deleted = deleted + 1
  525. line = ""
  526. r.write(line+'\n')
  527. f.close()
  528. r.close()
  529. if deleted == 1:
  530. print("\nProduct name '"+str(product)+"' has been deleted!") #Product is now removed from the file
  531. cleanupProduct()
  532.  
  533.  
  534.  
  535. def cleanupProduct():
  536. with open("newStocks.txt","r+") as f, open("stock.txt","w") as r:
  537. for i in f.readlines():
  538. if not i.strip():
  539. continue
  540. if i:
  541. r.write(i)
  542.  
  543. f.close()
  544. r.close()
  545. mainMenu()
  546.  
  547.  
  548. def PaidOrders(): #This prints the paid menu - used to check if paid
  549.  
  550. while True: #Checks the ID given by user if valid or not
  551. orderID = input("Please enter the order ID you want to pay for: ")
  552. with open('orders.txt') as f:
  553. if orderID in f.read():
  554. print("OrderID verified")
  555.  
  556. with open('paid.txt') as h: #Checks to see if this has been paid or not
  557. if orderID in h.read():
  558. print("OrderID already paid for") #Prints to sreen and shows order
  559. mainMenu()
  560. else:
  561. print(orderID+" does not exist/has not been paid") #The ID given is payed or not existent in the current file
  562. mainMenu()
  563. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement