Guest User

Untitled

a guest
Jan 24th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.73 KB | None | 0 0
  1. def mainMenu():
  2. print("""
  3. ###############################################################################
  4. # #
  5. # Clive's Carpets #
  6. # Please Login Below! #
  7. # #
  8. ###############################################################################
  9. """)
  10. validateUser()
  11.  
  12. def adminMenu():
  13. while True:
  14. print("""
  15. ###############################################################################
  16. # #
  17. # Clive's Carpets #
  18. # Admin Menu #
  19. # #
  20. # 1 - Add a New User #
  21. # 2 - Quotes #
  22. # 3 - Exit #
  23. # #
  24. ###############################################################################
  25. """)
  26.  
  27. adminMenu = input("Which option would you like to choose? '1' , '2' or '3': ")
  28. if adminMenu == "1":
  29. userInput()
  30. break
  31. elif adminMenu == "2":
  32. quoteMenu()
  33. break
  34. elif adminMenu == "3":
  35. exit()
  36. break
  37.  
  38.  
  39. def userMenu():
  40. print("\nUser Menu")
  41. userMenu = input("\nDo you wish to create a new quote? 'Yes' 'No': ")
  42. if userMenu.lower() == "yes":
  43. newQuote()
  44. elif userMenu.lower() == "no":
  45. exit()
  46. else:
  47. userMenu()
  48.  
  49. def newQuote():
  50.  
  51. CARPET = 22.50
  52. carpetCost = 0
  53. GRIPPER = 1.10
  54. gripperCost = 0
  55. RATE = 65
  56. labour = 0
  57. underlayPicker = 0
  58. underlay = 0
  59. underlayCost = 0
  60. width = 0
  61. length = 0
  62. perimeter = 0
  63. squareMeter = 0
  64. rawMaterialsCost = 0
  65. totalCost = 0
  66.  
  67. quotationCount=len(open("quotes.txt","r").readlines( ))
  68. quotationID = "CC"+str(quotationCount+1)
  69.  
  70. while True:
  71. customerID=input("\nInput the Customer ID: ")
  72. if len(customerID)>12:
  73. print("\nCustomerID has to be less than 12 characters (5 characters House Number + 7 character Postcode")
  74. else:
  75. break
  76. while True:
  77. length=float(input("\nInput the total length of the room (m): "))
  78. if length>30:
  79. print("\nRoom Is too long!")
  80. else:
  81. break
  82. while True:
  83. width=float(input("\nInput the total width of the room (m): "))
  84. if width>5:
  85. print("\nRoom is too wide!")
  86. else:
  87. break
  88. while True:
  89. perimeter=float(input("\nInput the total perimeter of the room (m): "))
  90. if perimeter>300:
  91. print("\nYou had better double check!")
  92. else:
  93. break
  94. while True:
  95. print("""
  96. ###############################################################################
  97. # #
  98. # Clive's Carpets #
  99. # Underlay Picker #
  100. # #
  101. # Which underlay would the customer like: #
  102. # 1 - First Step: £5.99 per square meter #
  103. # 2 - Monarch: £7.99 per square meter #
  104. # 3 - Royal: £60.00 per square meter #
  105. # #
  106. # 4 - Exit #
  107. # #
  108. ###############################################################################
  109. """)
  110. underlayPicker=input("Which underlay would the customer like? Option '1', '2', '3' or '4': ")
  111. if underlayPicker =="1":
  112. underlay = 5.99
  113. break
  114. elif underlayPicker =="2":
  115. underlay = 7.99
  116. break
  117. elif underlayPicker =="3":
  118. underlay = 60
  119. break
  120. elif underlayPicker =="4":
  121. quit()
  122. else:
  123. print("\nThat is not a valid entry you must select '1', '2', '3' or '4'")
  124.  
  125. squareMeter = length * width
  126. squareMeter = float(str(round(squareMeter, 2,)))
  127. perimeter = round(perimeter + 0.49)
  128. carpetCost = squateMeter * CARPET
  129. carpetCost = float(str(round(carpetCost, 2)))
  130. gripperCost = perimeter * GRIPPER
  131. gripperCost = float(str(round(gripperCost, 2)))
  132. underlayCost = squareMeter * underlay
  133. underlayCost = float(str(round(underlayCost, 2)))
  134. if squareMeter < 17:
  135. labour = RATE
  136. elif squareMeter > 16:
  137. labour = (squareMeter / 16) * RATE
  138. labour = float(str(round(labour, 2)))
  139. rawMaterialsCost = carpetCost + gripperCost + underlayCost
  140. rawMaterialsCost = float(str(round(rawMaterialsCost, 2)))
  141. totalCost = rawMaterialsCost + labour
  142. totalCost = float(str(round(totalCost, 2)))
  143. print("\nQuotation "+str(quotationID)+" for Customer "+str(customerID))
  144. print("\nRoom Size in Sq.M: "+str(squareMeter))
  145. print("\nRoom Perimiter in M: "+str(perimeter))
  146. print("\nCarpet Cost: £"+"(:.2f)".format(carpetCost))
  147. print("\nGripper Cost: £"+"(:.2f)".format(gripperCost))
  148. print("\nUnderlay Cost: £"+"(:.2f)".format(underlayCost))
  149. print("\nRaw Materials Cost: £"+"(:.2f)".format(rawMaterialsCost))
  150. print("\nLabour Cost: £"+"(:.2f)".format(labour))
  151. print("\nTotal Cost: £"+"(:.2f)".format(totalCost))
  152. quotationIDStore=quoationID.ljust(10)
  153. customerID=customerID.lower()
  154. customerID=customerID.replace(" ", "")
  155. customerIDStore=customerID.ljust(12)
  156. squareMeter=str(squareMeter)
  157. squareMeterStore=squareMeter.ljust(10)
  158. perimeter=str(perimeter)
  159. perimeterStore=perimeter.ljust(10)
  160. carpetCost=str(carpetCost)
  161. carpetCostStore=carpetCost.ljust(10)
  162. gripperCost=str(gripperCost)
  163. gripperCostStore=grippercost.ljust(10)
  164. underlayCost=str(underlayCost)
  165. underlayCostStore=underlayCost.ljust(10)
  166. rawMaterialsCost=str(rawMaterialsCost)
  167. rawMaterialsCostStore=rawMaterialsCost.ljust(10)
  168. labour=str(labour)
  169. labourStore=labour.ljust(10)
  170. totalCost=str(totalCost)
  171. totalCostStore=totalCost.ljust(10)
  172. store=open("quotations.txt","a")
  173. iStore=quotationIDStore+CustomerIDStore+squareMeterStore+perimeterStore+carpetCostStore+gripperCostStore+underlayCostStore+rawMaterialsCostStore+labourStore+totalCostStore+"\n"
  174. store.write(iStore)
  175. store.close()
  176. print("\nQuotation saved to Customer Records")
  177.  
  178. def showQuotation():
  179. file = open('quotation.txt','r+')
  180. for line in file:
  181. quotationID = line[0:10]
  182. quotationID = quotationID.strip()
  183. customerID = line [10:22]
  184. customerID = customerID.strip()
  185. squareMeter = line [22:32]
  186. squareMeter = squareMeter.strip()
  187. squareMeter = float(squareMeter)
  188. perimeter = line[32:42]
  189. perimeter = perimeter.strip()
  190. perimeter = float(perimeter)
  191. carpetCost = line[42:52]
  192. carpetCost = carpetCost.strip()
  193. carpetCost = float(carpetCost)()
  194. gripperCost = line[52:62]
  195. gripperCost = gripperCost.strip()
  196. gripperCost = float(grippperCost)
  197. underlayCost = line[62:72]
  198. underlayCost = underlayCost.strip()
  199. underlayCost = float(gripperCost)
  200. rawMaterialsCost = line[72:82]
  201. rawMaterialsCost = float(rawMaterialsCost)
  202. rawMaterialsCost = rawMaterialsCost.strip()
  203. labour = line [82:92]
  204. labour = labour.strip()
  205. labour = float(labour)
  206. totalCost = line[92:102]
  207. totalCost = totalCost.strip()
  208. totalCost = float(totalCost)
  209. print("\nQuotation "+str(quotationID)+" for Customer "+str(customerID))
  210. print("\nRoom Size in Sq.M: "+str(squareMeter))
  211. print("\nRoom Perimiter in M: "+str(perimeter))
  212. print("\nCarpet Cost: £"+"(:.2f)".format(carpetCost))
  213. print("\nGripper Cost: £"+"(:.2f)".format(gripperCost))
  214. print("\nUnderlay Cost: £"+"(:.2f)".format(underlayCost))
  215. print("\nRaw Materials Cost: £"+"(:.2f)".format(rawMaterialsCost))
  216. print("\nLabour Cost: £"+"(:.2f)".format(labour))
  217. print("\nTotal Cost: £"+"(:.2f)".format(totalCost))
  218.  
  219.  
  220.  
  221. def quoteMenu():
  222.  
  223. quoteMenu()
  224. def userInput():
  225. userType, username, password1, password2 = "", "", "", ""
  226. while True:
  227.  
  228. userType = input("What type of user are you creating?\n(1) Admin \n(2) Defnyddiwr \n")
  229. if userType == "-1":
  230. mainMenu()
  231. if len(userType) > 1:
  232. print("\nInvalid Input.\n")
  233. elif userType.isdigit() != True:
  234. print("Please enter a number!")
  235. elif int(userType) <1:
  236. print("\nInvalid Input.\n")
  237. elif int(userType) >2:
  238. print("\nInvalid Input.\n")
  239. else:
  240. break
  241. while True:
  242. username = input("\nPlease enter the username of the new user: ")
  243. if username == "-1":
  244. mainMenu()
  245. if len(username) >10:
  246. print("\nThe username must be less than 11 characters.\n")
  247. elif username.isalpha() == False:
  248. print("\nThe username must only contain alpha.\n")
  249. else:
  250. break
  251. while True:
  252. password1 = input("\nPlease enter the password for the user: ")
  253. if password1 == "-1":
  254. mainMenu()
  255. if len(password1) > 10:
  256. print("\nThe password must be less than 11 characters.\n")
  257. password2 = input("\nPlease enter the password again: ")
  258. if password2 == "-1":
  259. mainMenu()
  260. if len(password2) > 10:
  261. print("\nThe password must be less than 11 characters.\n")
  262. if password1 != password2:
  263. print("\nThe password does not match,retry.\n")
  264. else:
  265. break
  266. while True:
  267. FirstName = input("\nPlease enter your first name: ")
  268. if FirstName == "-1":
  269. mainMenu()
  270. if len(FirstName) >25:
  271. print("\nYour first name must be less than 25 characters.\n")
  272. else:
  273. break
  274. while True:
  275. Surname = input("\nPlease enter your surname: ")
  276. if Surname == "-1":
  277. mainMenu()
  278. if len(Surname) >25:
  279. print("\nYour surname must be less than 25 characters.\n")
  280. else:
  281. break
  282. while True:
  283. Telephone = input("\nPlease enter your telephone: ")
  284. try:
  285. int(Telephone)
  286. except:
  287. print("The telephone number must be a number")
  288. if Telephone == "-1":
  289. mainMenu()
  290. if len(Telephone) >16:
  291. print("\nThe telephone number must be less than 16 characters.\n")
  292. else:
  293. break
  294. while True:
  295. Town = input("\nPlease enter your town: ")
  296. if Town == "-1":
  297. mainMenu()
  298. if len(Town) >15:
  299. print("\nYour town must be less than 15 characters.\n")
  300. else:
  301. break
  302.  
  303.  
  304.  
  305. username = username.lower()
  306. password1 = password1.lower()
  307. password2 = password2.lower()
  308. FirstName = FirstName.lower()
  309. Surname = Surname.lower()
  310. Telephone = Telephone.lower()
  311. Town = Town.lower()
  312.  
  313. userTypeStore = str(userType).ljust(2)
  314. usernameStore = username.ljust(10)
  315. passwordStore = password1.ljust(10)
  316. FirstNameStore = FirstName.ljust(25)
  317. SurnameStore = Surname.ljust(25)
  318. TelephoneStore = Telephone.ljust(16)
  319. TownStore = Town.ljust(15)
  320.  
  321. store = open("users.txt","a")
  322. iStore = usernameStore + passwordStore + userTypeStore + FirstNameStore + SurnameStore + TelephoneStore + TownStore + "\n"
  323. store.write(iStore)
  324. store.close()
  325.  
  326. print("\nNew User Created: ")
  327. print("Usertype: ",userType)
  328. print("Username: ",username)
  329. print("Password: ",("*"*len(password1)))
  330. print("First Name: ",FirstName)
  331. print("Surname: ",Surname)
  332. print("Telephone: ",Telephone)
  333. print("Town: ",Town)
  334.  
  335. mainMenu()
  336.  
  337.  
  338. def validateUser():
  339. validateUserType = ""
  340. validateUsername = ""
  341. validatePassword = ""
  342.  
  343. username = str(input("\nPlease enter your username: \n"))
  344. password = str(input("\nPlease enter your password: \n"))
  345.  
  346. while True:
  347. try:
  348. readUsers = open("users.txt","r")
  349. validateCounter = 0
  350.  
  351. while True:
  352. location = readUsers.readline()
  353. validateUserType = location[20:22]
  354. validateUserType = validateUserType.strip()
  355.  
  356. validateUsername = location [0:10]
  357. validateUsername = validateUsername.strip()
  358. validateUsername = validateUsername.lower()
  359. username = username.lower()
  360.  
  361. validatePassword = location[10:20]
  362. validatePassword = validatePassword.strip()
  363. validatePassword = validatePassword.lower()
  364. password = password.lower()
  365.  
  366.  
  367.  
  368. if location == "":
  369. readUsers.close()
  370. break
  371. if validateUserType == str(1) and validateUsername == username and validatePassword == password:
  372. validateCounter = validateCounter + 1
  373. adminMenu()
  374. break
  375. if validateUserType == str(2) and validateUsername == username and validatePassword == password:
  376. validateCounter = validateCounter + 1
  377. userMenu()
  378. break
  379.  
  380. if validateCounter ==0:
  381. print("\nThere is no user in the file with those login details. \n")
  382. validateUser()
  383. except FileNotFoundError:
  384. print("There is no Users file for you to search! How about making your first account?\nTop Tip, make it a System Administrator Account!\n")
  385. userInput()
  386.  
  387. def main():
  388. mainMenu()
  389.  
  390.  
  391. main()
Add Comment
Please, Sign In to add comment