Advertisement
Guest User

Untitled

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