Advertisement
Guest User

Untitled

a guest
Jan 25th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 14.70 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("quotations.txt","r").readlines())
  68.     quotationID = "CC"+str(quotationCount+1)
  69.  
  70.    
  71.     while True:
  72.         customerID=input("\nInput the Customer ID: ")
  73.         if len(customerID)>12:
  74.             print("\nCustomerID 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("\nInput the total length of the room (m): "))
  79.         if length>30:
  80.             print("\nRoom Is too long!")
  81.         else:
  82.             break
  83.     while True:
  84.         width=float(input("\nInput the total width of the room (m): "))
  85.         if width>5:
  86.             print("\nRoom is too wide!")
  87.         else:
  88.             break
  89.     while True:
  90.         perimeter=float(input("\nInput 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 Perimiter 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.     rawMaterialsCost=str(rawMaterialsCost)
  168.     rawMaterialsCostStore=rawMaterialsCost.ljust(10)
  169.     labour=str(labour)
  170.     labourStore=labour.ljust(10)
  171.     totalCost=str(totalCost)
  172.     totalCostStore=totalCost.ljust(10)
  173.     store=open("quotations.txt","a")
  174.     iStore=quotationIDStore+customerIDStore+squareMeterStore+perimeterStore+carpetCostStore+gripperCostStore+underlayCostStore+rawMaterialsCostStore+labourStore+totalCostStore+"\n"
  175.     store.write(iStore)
  176.     store.close()
  177.     print("\nQuotation saved to Customer Records")
  178.  
  179. def showQuotation():
  180.     file = open('quotation.txt','r+')
  181.     for line in file:
  182.         quotationID = line[0:10]
  183.         quotationID = quotationID.strip()
  184.         customerID = line [10:22]
  185.         customerID = customerID.strip()
  186.         squareMeter = line [22:32]
  187.         squareMeter = squareMeter.strip()
  188.         squareMeter =  float(squareMeter)
  189.         perimeter = line[32:42]
  190.         perimeter = perimeter.strip()
  191.         perimeter = float(perimeter)
  192.         carpetCost = line[42:52]
  193.         carpetCost = carpetCost.strip()
  194.         carpetCost = float(carpetCost)()
  195.         gripperCost = line[52:62]
  196.         gripperCost = gripperCost.strip()
  197.         gripperCost = float(grippperCost)
  198.         underlayCost = line[62:72]
  199.         underlayCost = underlayCost.strip()
  200.         underlayCost = float(gripperCost)
  201.         rawMaterialsCost = line[72:82]
  202.         rawMaterialsCost = float(rawMaterialsCost)
  203.         rawMaterialsCost = rawMaterialsCost.strip()
  204.         labour = line [82:92]
  205.         labour = labour.strip()
  206.         labour = float(labour)
  207.         totalCost = line[92:102]
  208.         totalCost = totalCost.strip()
  209.         totalCost = float(totalCost)
  210.         print("\nQuotation "+str(quotationID)+" for Customer "+str(customerID))
  211.         print("\nRoom Size in Sq.M:     "+str(squareMeter))
  212.         print("\nRoom Perimiter in M: "+str(perimeter))
  213.         print("\nCarpet Cost:            £"+"(:.2f)".format(carpetCost))
  214.         print("\nGripper Cost:          £"+"(:.2f)".format(gripperCost))
  215.         print("\nUnderlay Cost:         £"+"(:.2f)".format(underlayCost))
  216.         print("\nRaw Materials Cost:     £"+"(:.2f)".format(rawMaterialsCost))
  217.         print("\nLabour Cost:        £"+"(:.2f)".format(labour))
  218.         print("\nTotal Cost:          £"+"(:.2f)".format(totalCost))
  219.        
  220. def quoteMenu():
  221.  
  222.     quoteMenu()
  223. def userInput():
  224.     userType, username, password1, password2 = "", "", "", ""
  225.     while True:
  226.        
  227.         userType = input("What type of user are you creating?\n(1) Admin \n(2) Defnyddiwr \n")
  228.         if userType == "-1":
  229.             mainMenu()
  230.         if len(userType) > 1:
  231.             print("\nInvalid Input.\n")
  232.         elif userType.isdigit() != True:
  233.             print("Please enter a number!")
  234.         elif int(userType) <1:
  235.             print("\nInvalid Input.\n")
  236.         elif int(userType) >2:
  237.             print("\nInvalid Input.\n")
  238.         else:
  239.             break
  240.     while True:
  241.         username = input("\nPlease enter the username of the new user: ")
  242.         if username == "-1":
  243.             mainMenu()
  244.         if len(username) >10:
  245.             print("\nThe username must be less than 11 characters.\n")
  246.         elif username.isalpha() == False:
  247.             print("\nThe username must only contain alpha.\n")
  248.         else:
  249.             break
  250.     while True:
  251.         password1 = input("\nPlease enter the password for the user: ")
  252.         if password1 == "-1":
  253.             mainMenu()
  254.         if len(password1) > 10:
  255.             print("\nThe password must be less than 11 characters.\n")
  256.         password2 = input("\nPlease enter the password again: ")
  257.         if password2 == "-1":
  258.             mainMenu()
  259.         if len(password2) > 10:
  260.             print("\nThe password must be less than 11 characters.\n")
  261.         if password1 != password2:
  262.             print("\nThe password does not match,retry.\n")
  263.         else:
  264.             break
  265.     while True:
  266.         FirstName = input("\nPlease enter your first name: ")
  267.         if FirstName == "-1":
  268.             mainMenu()
  269.         if len(FirstName) >25:
  270.             print("\nYour first name must be less than 25 characters.\n")
  271.         else:
  272.             break
  273.     while True:
  274.         Surname = input("\nPlease enter your surname: ")
  275.         if Surname == "-1":
  276.             mainMenu()
  277.         if len(Surname) >25:
  278.             print("\nYour surname must be less than 25 characters.\n")
  279.         else:
  280.             break
  281.     while True:
  282.         Telephone = input("\nPlease enter your telephone: ")
  283.         try:
  284.             int(Telephone)
  285.         except:
  286.             print("The telephone number must be a number")
  287.         if Telephone == "-1":
  288.             mainMenu()
  289.         if len(Telephone) >16:
  290.             print("\nThe telephone number must be less than 16 characters.\n")
  291.         else:
  292.             break
  293.     while True:
  294.         Town = input("\nPlease enter your town: ")
  295.         if Town == "-1":
  296.             mainMenu()
  297.         if len(Town) >15:
  298.             print("\nYour town must be less than 15 characters.\n")
  299.         else:
  300.             break
  301.        
  302.     username = username.lower()
  303.     password1 = password1.lower()
  304.     password2 = password2.lower()
  305.     FirstName = FirstName.lower()
  306.     Surname = Surname.lower()
  307.     Telephone = Telephone.lower()
  308.     Town = Town.lower()
  309.      
  310.     userTypeStore = str(userType).ljust(2)
  311.     usernameStore = username.ljust(10)
  312.     passwordStore = password1.ljust(10)
  313.     FirstNameStore = FirstName.ljust(25)
  314.     SurnameStore = Surname.ljust(25)
  315.     TelephoneStore = Telephone.ljust(16)
  316.     TownStore = Town.ljust(15)
  317.  
  318.  
  319.     store = open("users.txt","a")
  320.     iStore = usernameStore + passwordStore + userTypeStore + FirstNameStore + SurnameStore + TelephoneStore + TownStore + "\n"
  321.     store.write(iStore)
  322.     store.close()
  323.  
  324.     print("\nNew User Created: ")
  325.     print("Usertype: ",userType)
  326.     print("Username: ",username)
  327.     print("Password: ",("*"*len(password1)))
  328.     print("First Name: ",FirstName)
  329.     print("Surname: ",Surname)
  330.     print("Telephone: ",Telephone)
  331.     print("Town: ",Town)
  332.  
  333.     mainMenu()
  334.  
  335.  
  336. def validateUser():
  337.     validateUserType = ""
  338.     validateUsername = ""
  339.     validatePassword = ""
  340.  
  341.     username = str(input("\nPlease enter your username: \n"))
  342.     password = str(input("\nPlease enter your password: \n"))
  343.  
  344.     while True:
  345.         try:
  346.             readUsers = open("users.txt","r")
  347.             validateCounter = 0
  348.  
  349.             while True:
  350.                 location = readUsers.readline()
  351.  
  352.                 validateUserType = location[20:22]
  353.                 validateUserType = validateUserType.strip()
  354.  
  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.                 if location == "":
  367.                     readUsers.close()
  368.                     break
  369.                 if validateUserType == str(1) and validateUsername == username and validatePassword == password:
  370.                     validateCounter = validateCounter + 1
  371.                     adminMenu()
  372.                     break
  373.                 if validateUserType == str(2) and validateUsername == username and validatePassword == password:
  374.                     validateCounter = validateCounter + 1
  375.                     userMenu()
  376.                     break
  377.  
  378.             if validateCounter ==0:
  379.                 print("\nThere is no user in the file with those login details. \n")
  380.                 validateUser()
  381.         except FileNotFoundError:
  382.             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")
  383.             userInput()
  384.  
  385. def main():
  386.     mainMenu()
  387.  
  388.  
  389. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement