SHARE
TWEET

ladfsodvgnjsdgf

a guest Nov 22nd, 2019 159 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import string, datetime
  2.  
  3. def check_files(): #checks whether the files are there, if they're not, it creates one
  4.     try:
  5.         stockID = open('stock.txt', 'r') #searches for / opens the file
  6.     except FileNotFoundError: #if the file is not found:
  7.         print("Creating stock file...")
  8.         stockID = open('stock.txt', 'w') #make the file
  9.         print ("Stock file created")
  10.     try:
  11.         ordersID = open('orders.txt', 'r')
  12.     except FileNotFoundError:
  13.         print("Creating orders file...")
  14.  
  15.         ordersID = open('orders.txt', 'w')
  16.         print ("Orders file created")
  17.     try:
  18.         customerID = open('customers.txt', 'r')
  19.     except FileNotFoundError:
  20.         customerID = open('customers.txt', 'w')
  21.         print ("Customers file created")
  22.     try:
  23.         pay = open('paid.txt', 'r')
  24.     except FileNotFoundError:
  25.         pay = open('paid.txt', 'w')
  26.         print ("Unpaid orders file created")
  27. def mainMenu():
  28.     print("""
  29. ###############################################################################
  30. #                                                                             #                                                                                
  31. #                   Urdd y Clefyddydau Cerameg                                #                                                                        
  32. #                       Please Login Below!                                   #                                                        
  33. #                                                                             #        
  34. ###############################################################################
  35.        """)
  36.     validateUser()
  37.  
  38.  
  39.  
  40. def adminMenu():
  41.     while True:
  42.         print("""
  43. ###############################################################################
  44. #                                                                             #
  45. #                               Urdd y Clefyddydau Cerameg                    #
  46. #                                   Admin Menu                                #
  47. #                                                                             #
  48. # 1 - New Customer                                                            #
  49. # 2 - Add to the stock                                                        #
  50. # 3 - Remove item from stock                                                  #
  51. # 4 - Make an order                                                           #
  52. # 5 - Print an invoice                                                        #
  53. # 6 - Cancel an order                                                         #
  54. # 7 - Delete cutsomer                                                         #
  55. # 8 - Unpaid orders                                                           #
  56. # 9 - Pay for an order                                                        #
  57. #                                                                             #
  58. #                                                                             #                                                                        
  59. # 10 - Exit                                                                   #                                                                        
  60. #                                                                             #                                                                    
  61. #                                                                             #                                                                    
  62. ###############################################################################
  63. """)
  64.  
  65.         adminMenu = input("Which option would you like to choose?:\n ")
  66.         if adminMenu == "1":
  67.             newCustomer() #create a customer function
  68.             break
  69.         elif adminMenu == "2":
  70.             addStock() #adding stock function
  71.             break
  72.         elif adminMenu == "3":
  73.             delStock()#removing stock function
  74.             break
  75.         elif adminMenu == "4":
  76.             orderMenu()#making an order function
  77.             break
  78.         elif adminMenu == "5":
  79.             createInvoice()#producing an invoice function
  80.             break
  81.         elif adminMenu == "6":
  82.             delOrder()#canceling an order function
  83.             break
  84.         elif adminMenu == "7":
  85.             delCustomer()#deleting a customer function
  86.             break
  87.         elif adminMenu == "8":
  88.             check_unpaid_orders()#check for unpaid orders function
  89.             break
  90.         elif adminMenu =="9":
  91.             payOrder()#pay for order function
  92.             break
  93.         elif adminMenu == "10":
  94.             exit() #exit the program
  95.  
  96.  
  97.  
  98.  
  99. def validateUser():
  100.     validateUserName = ""
  101.     validatePassword = ""
  102.  
  103.     UserName = str(input("\nPlease enter your UserName: \n"))
  104.     password = str(input("\nPlease enter your password: \n"))
  105.     while True:
  106.         try:
  107.             readUsers = open("users.txt","r")#opens the file
  108.             validateCounter = 0 #to match both username and password
  109.        
  110.             while True:
  111.                 location = readUsers.readline() #reads the file
  112.  
  113.                 validateUserName = location [0:10] #where the string is located in the file
  114.                 validateUserName = validateUserName.strip()#removes any spaces
  115.                 validateUserName = validateUserName.lower()
  116.                 UserName = UserName.lower() #lowercase
  117.  
  118.                 validatePassword = location[10:20]
  119.                 validatePassword = validatePassword.strip()
  120.                 validatePassword = validatePassword.lower()
  121.                 password = password.lower()
  122.  
  123.          
  124.                 if location == "":
  125.                     readUsers.close()#closes the file
  126.                     break
  127.                 if validateUserName == UserName and validatePassword == password: #if everything matches up:
  128.                     validateCounter = validateCounter + 1
  129.                     adminMenu() #sends user through to the admin menu
  130.                     break
  131.                 if validateUserName == UserName and validatePassword == password:
  132.                     validateCounter = validateCounter + 1
  133.                     userMenu()
  134.                     break
  135.  
  136.             if validateCounter ==0: #if one of the things didn't match up:
  137.                     print("\nNo user in the file with those login details. \n")
  138.                     create_user_q = input ("Would you like to create a new user? (Y/N)\n ")
  139.                     if create_user_q == ("Y"):
  140.                         newUser() #sends you to the create a user function
  141.                     if create_user_q == ("N"):
  142.                         mainMenu()#sends the user back to the main menu
  143.                
  144.  
  145.         except FileNotFoundError: #if there is no file to be found:
  146.                     print("There is no Users file for you to search! How about making your first account?")
  147.                     newUser()#sends user to the create a user function
  148.  
  149.  
  150.  
  151.  
  152. def newUser():
  153.     UserName, password1, password2 = "", "", ""
  154.    
  155.     while True:
  156.         UserName = input("\nPlease enter the UserName of the new user:\n ")
  157.         if len(UserName) >10: #if the length of the username is more than 10:
  158.             print("\nUserName must be less than 11 characters.\n")
  159.         elif UserName.isalpha() == False: #if the username contains any numbers:
  160.             print("\nThe UserName must only contain alpha.\n")
  161.         else:
  162.             break
  163.     while True:
  164.         password1 = input("\nPlease enter the password for the user:\n ")
  165.         if len(password1) > 10:#if the length of the password is more than 10:
  166.             print("\nPassword must be less than 11 characters.\n")
  167.         password2 = input("\nPlease enter the password again:n\n ")
  168.         if len(password2) > 10:#if the length of the second password is more than 10:
  169.             print("\nPassword must be less than 11 characters.\n")
  170.         if password1 != password2: #if the first password doesn't match the second:
  171.             print("\nPasswords do not match.\n")
  172.         else:
  173.             break #breaks the loop
  174.  
  175.     UserName=UserName.lower() #lowercase
  176.     password1=password1.lower()#lowercase
  177.     UserNameStore=UserName.ljust(10)#makes the username 10 digits long in the text file
  178.     password1Store=password1.ljust(10)#makes the password 10 digits long in the text file
  179.     store=open("users.txt","a") #opens the file
  180.     iStore=UserNameStore+password1Store+"\n" #what's being stored in the text file
  181.     store.write(iStore) #writes it into the text file
  182.     store.close()#closes the file
  183.     print("\nCreated a New User")
  184.     print("UserName  :",UserName)
  185.     print("Password  : ********** ")
  186.     mainMenu() #goes back to the login menu
  187.  
  188.  
  189.  
  190.  
  191. def orderMenu():
  192.     while True:
  193.         print("""
  194. ################################################################################
  195. #                                                                              #
  196. #                               Urdd y Clefyddydau Cerameg                     #
  197. #                                                                              #
  198. # Create a new order:                                                          #
  199. # 1 - New Customer                                                             #
  200. # 2 - Existing Customer                                                        #
  201. #                                                                              #
  202. # 3 - Exit                                                                     #
  203. #                                                                              #
  204. ################################################################################
  205. """)
  206.         orderMenu=input("What would like to do? Option '1', '2' or '3':\n ")
  207.         if orderMenu =="1":
  208.             newCustomer() #create a customer function
  209.             break
  210.         if orderMenu =="2":
  211.             createOrder()#the create an order function
  212.             break
  213.         elif orderMenu =="3":
  214.             exit()#exits the program
  215.         else:
  216.             print("\nThat is not a valid entry, you must select '1', '2' or '3'")
  217.  
  218.  
  219.  
  220. def newCustomer():
  221.     customerID=""
  222.     customerForename=""
  223.     customerSurname=""
  224.     customerTown=""
  225.     customerHouseNumber=""
  226.     customerPostcode=""
  227.     customerPhone=""
  228.    
  229.  
  230.  
  231.  
  232.     while True:
  233.         customerForename=input("\nInput the Customer Forename:\n ")
  234.         if len(customerForename)>20: #if the length of the customer forename is more than 20:
  235.             print("\nCustomer Forename has to be between 1 and 20 characters")
  236.         elif customerForename.isalpha()==False:#if the customer forename contains any numbers:
  237.             print("\nYou can only use letters for a Customer Forename")
  238.         else:
  239.             break
  240.  
  241.  
  242.  
  243.  
  244.     while True:
  245.         customerSurname=input("\nInput the Customer Surname:\n ")
  246.         if len(customerSurname)>20:
  247.             print("\nCustomer Surname has to be between 1 and 20 characters")
  248.         elif customerSurname.isalpha()==False:
  249.             print("\nYou can only use letters for a Customer Surname")
  250.         else:
  251.             break
  252.  
  253.  
  254.  
  255.     while True:
  256.         customerTown=input("\nInput the Customer Town:\n ")
  257.         if len(customerTown)>20:
  258.             print("\nCustomer Town has to be between 1 and 20 characters")
  259.         elif customerTown.isalpha()==False:
  260.             print("\nYou can only use letters for a Customer Town")
  261.         else:
  262.             break
  263.  
  264.  
  265.  
  266.     while True:
  267.         customerHouseNumber=input("\nInput the Customer House Number:\n ")
  268.         if len(customerHouseNumber)>5:
  269.             print("\nCustomer House Number cannot be >5 characters")
  270.         else:
  271.             break
  272.  
  273.  
  274.  
  275.     while True:
  276.         customerPostcode=input("\nInput the Customer Postcode:\n ")
  277.         if len(customerPostcode)>8:
  278.             print("\nCustomer Postcode cannot be >8 characters i.e. XX99 9XX")
  279.         else:
  280.             break
  281.  
  282.  
  283.  
  284.     while True:
  285.         customerPhone=input("\nInput the Customer Phone Number:\n ")
  286.         if len(customerPhone)>11:
  287.             print("\nCustomer Phone Number can not be more than 11 numbers")
  288.         elif customerPhone.isdigit()!=True:
  289.             print("\nYou can only use numbers for a Customer Phone Number")
  290.         else:
  291.             break
  292.  
  293.  
  294.  
  295.  
  296.     customerHouseNumber=customerHouseNumber.strip() #gets rid of spaces
  297.     customerPostcode=customerPostcode.replace(" ", "")#removes the spaces in between
  298.     customerID=(customerHouseNumber)+(customerPostcode) #creates the customer ID
  299.     customerID=customerID.strip()#gets rid of spaces
  300.     customerID=customerID.lower()#makes it lowercase
  301.     customerIDStore=customerID.ljust(12)#makes it 12 digits long in the text file when storing it
  302.     customerForenameStore=customerForename.ljust(12)
  303.     customerSurnameStore=customerSurname.ljust(12)
  304.     customerTownStore=customerTown.ljust(20)
  305.     customerHouseNumberStore=customerHouseNumber.ljust(12)
  306.     customerPostcodeStore=customerPostcode.ljust(12)
  307.     customerPhoneStore=customerPhone.ljust(12)
  308.     store=open("customers.txt","a") #opens the file
  309.     iStore=customerIDStore+customerForenameStore+customerSurnameStore+customerTownStore+customerHouseNumberStore+customerPostcodeStore+customerPhoneStore+"\n" #everything that's being stored
  310.     store.write(iStore) #writes it into the file
  311.     store.close()#closes the file
  312.  
  313.  
  314.  
  315.     print("\nFinished creating a new customer")
  316.     print("Customer ID:             ",customerIDStore)
  317.     print("Customer Forename:       ",customerForenameStore)
  318.     print("Customer Surname:        ",customerSurnameStore)
  319.     print("Customer Town:           ",customerTownStore)
  320.     print("Customer House Number:   ",customerHouseNumberStore)
  321.     print("Customer Posecode:       ",customerPostcodeStore)
  322.     print("Customer Phone:          ",customerPhoneStore)
  323.  
  324. def addStock():
  325.     StockID = ""
  326.     StockName = ""
  327.     StockPrice = ""
  328.  
  329.  
  330.     while True:
  331.         StockName=input("\nInput the name of the item you are adding to the stock:\n ")
  332.         if len(StockName)>20: #if the length is more than 20:
  333.             print("\nStockName has to be between 1 and 20 characters")
  334.         elif StockName.isalpha()==False: #if it contains any numbers:
  335.             print("\nYou can only use letters for a product  name")
  336.         else:
  337.             break
  338.  
  339.  
  340.  
  341.     while True:
  342.         StockPrice=float(input("\nInput the price of your product:\n "))
  343.         if StockPrice>150: #if the price is more than £150:
  344.             print("\nPrice must be under £150!")
  345.         elif str(StockPrice).isdigit()!=False: #if it contains any letters:
  346.             print("\nYou can only use numbers for a price")
  347.         else:
  348.             break
  349.  
  350.  
  351.  
  352.     StockID=input("Please enter 5 random letters so we can give you a unique ID:\n ")
  353.     if StockID.isalpha()==False: #if it contains numbers
  354.         print("\nYou can only use letters for your unique ID")
  355.     elif len(StockID) != 5: #if it is more or less than 5 digits
  356.               print("\nYou must use exaclty 5 digits ")
  357.     StockID = ("QF")+ StockID
  358.     StockID=StockID.strip()#removes spaces
  359.     StockID=StockID.lower()#lowercase
  360.     StockPrice = str(StockPrice) #makes it writable
  361.     StockIDStore=StockID.ljust(12) #makes it 12 digits long in the text file
  362.     StockNameStore=StockName.ljust(12)
  363.     StockPriceStore=StockPrice.ljust(12)
  364.  
  365.  
  366.    
  367.     store=open("stock.txt","a") #opens the file
  368.     iStore=StockIDStore+StockNameStore+StockPriceStore+"\n" #everything that's being stored in the file
  369.     store.write(iStore) #writes it into the file
  370.     store.close() #closes the file  
  371.  
  372.  
  373.  
  374.     print("\nFinished adding to stock")
  375.     print("Stock ID:             ",StockIDStore)
  376.     print("Stock Name:       ",StockNameStore)
  377.     print("Stock Item Price:          ",StockPriceStore)
  378.  
  379.     while True:
  380.         print("""
  381. ################################################################################
  382. #                                                                              #
  383. #                               Urdd yr Clefyddydau Cerameg                    #
  384. #                                                                              #
  385. # Would you like to add another item to stock?:                                #
  386. # 1 - Add another item                                                         #
  387. #                                                                              #
  388. # 2 - Exit to Menu                                                             #
  389. #                                                                              #
  390. ################################################################################
  391.    """)
  392.         StockMenu=input("What would like to do? Option '1' or '2':\n ")
  393.         if StockMenu =="1":
  394.             addStock() #repeates th entire process
  395.             break
  396.         elif StockMenu =="2":
  397.             adminMenu() #returns to admin menu
  398.             break
  399.         else:
  400.             print("\nThat is not a valid entry, you must select '1' or '2'")
  401.  
  402.  
  403.  
  404.  
  405.  
  406.  
  407.  
  408. def delStock():
  409.  
  410.  
  411.    
  412.     while True:        
  413.         del_item = input("Please enter the name of the item you would like to remove from the stock\n ")            
  414.  
  415.         with open("stock.txt","r+") as f:
  416.             new_f = f.readlines() #reads the file
  417.             f.seek(0)
  418.             for line in new_f: #for every line in the file:
  419.                 if del_item not in line: #if the item isn't in the line:
  420.                     f.write(line)#writes the entire file bcak without the deleted line
  421.             f.truncate()
  422.  
  423.         a = input("Would you like to remove another item? (Y/N)\n ")
  424.         if a == ("n"):
  425.             break
  426.  
  427.         elif a == ("y"):
  428.             print("Thank you")
  429.    
  430.        
  431. def createOrder():
  432.  
  433.  
  434.     while True:
  435.         customerID = input("Please enter your customer ID (House number + Postcode - Example - 6ab123cd)\n ")
  436.         with open('customers.txt') as f: #opens the file
  437.             if customerID in f.read(): #if the customer ID is in the file:
  438.                 print("Thank you")
  439.                 break
  440.             else:
  441.                 print("Customer ID was not found. Please try again")
  442.     while True:
  443.         orderID = input("Please enter a unique ID for your order (5 random numbers)\n ") #to make the order ID
  444.         if orderID.isdigit()==False: #if it contains letters:
  445.             print("\nYou can only use numbers for your unique ID")
  446.         elif len(orderID) != 5: #if it's more or less than 5 digits long:
  447.               print("\nYou must use exaclty 5 digits ")
  448.         else:
  449.             print("Your unique ID is PQ" + orderID)
  450.             break
  451.     orderID = ("PQ")+ orderID
  452.     orderID=orderID.strip()#removes any spaces
  453.     orderID=orderID.lower()#lowercase
  454.     orderIDStore=orderID.ljust(12) #makes it 12 digits long in the text file
  455.  
  456.  
  457.  
  458.  
  459.     while True:
  460.         item_name = input("Please enter the name of the item you wish to purchase\n ")
  461.         with open('stock.txt') as f: #opens the file
  462.             if item_name in f.read(): #if it's in the file:
  463.                 print("Thank you")
  464.                 break
  465.             elif item_name not in f.read(): #if it isn't:
  466.                 print("Item was not found. Please try again")
  467.    
  468.     while True:
  469.         readStock = open('stock.txt','r') #opens the file
  470.         location = readStock.readline()#reads the file
  471.         price = location[24:36]#location of where the string is in the line   #makes the price a float (can have decimals)
  472.         price = float(price)
  473.         quantity = int(input("What quantity of this product would you like to purchase?\n "))
  474.         if quantity >100: #if the quantity is more than 100:
  475.             print("You can only have up to 100 items")
  476.         elif quantity <1: #if it's less than 1:
  477.             ("You must give a quantity of 1 or more")
  478.         overallPrice = (price*quantity) #gives the price of each item combined
  479.  
  480.         readStock.close() #closes the file
  481.  
  482.         break
  483.  
  484.  
  485.     quantityID=str(quantity) #makes the quantity a string
  486.  
  487.     quantityID=quantityID.ljust(12) #makes it 12 digits long in the text file
  488.     customerID=customerID.strip()#strips any spaces
  489.     customerID=customerID.lower()#lowercase
  490.     customerIDStore=customerID.ljust(12)
  491.     overallPrice=str(overallPrice)#makes the price a string
  492.     overallPrice=overallPrice.ljust(12)
  493.     today = datetime.datetime.now() #the date
  494.     today = str(today)#makes the date a string (so it can be stored in the file)
  495.     today = today.ljust(30) #makes it 12 digits long
  496.  
  497.  
  498.     order_file = open('orders.txt', 'a') #opens the order file in append mode
  499.     stock_file = open('stock.txt', 'r') #opens the stock file in read mode
  500.     for line in stock_file: #for each line in the stock file
  501.         if item_name in line: #for each line:
  502.             line = line.ljust(12) #makes sure that there's a gap at the end of the line
  503.             order_store = quantityID + orderIDStore + overallPrice + today + customerIDStore + line #everything that's being stored
  504.             order_file.write(order_store) #writes it into the file
  505.             print("Thank you, your item has been added to your order")
  506.        
  507.  
  508.     while True:
  509.         a = input("Would you like to add another item to the order? (y/n)\n ")
  510.         if a == ("n"):
  511.             break
  512.         elif a == ("y"):
  513.             print("Thank you ")
  514.             createOrder() #makes another order
  515.         else:
  516.             print("Invalid input, returning to menu ")
  517.             break
  518.  
  519.     while True:
  520.         a = input("Would you like to pay for your order now? (y/n)\n ")
  521.         if a == ("y"):
  522.             pay_file = open("paid.txt","a") #opens the paid file
  523.             stock_file = open('stock.txt', 'r')#opens the stock file
  524.             for line in stock_file: #for every line in the stock file:
  525.                 if item_name in line: #if the item name is in the line:
  526.                     line = line.ljust(12)
  527.                     order_store = quantityID + orderIDStore + overallPrice + today + customerIDStore + line + "\n"
  528.                     pay_file.write(order_store) #writes the line into the pay file
  529.                     print("Paid")
  530.        
  531.             break
  532.         elif a == ("n"):
  533.             print("Thank you ")
  534.             break
  535.         else:
  536.             print("Invalid input, returning to menu ")
  537.             break
  538.  
  539.        
  540.        
  541. def delOrder():
  542.     while True:
  543.         z = input("Are you sure you want to cancel an order? (You must pay 20% of the order)")
  544.         if z == "y":
  545.             break
  546.         if z == "n":
  547.             adminMenu()
  548.             break
  549.         else:
  550.             print("Invalid input, returning to menu")
  551.             adminMenu()        
  552.                
  553.     while True:
  554.         order_ID = input("Please enter your order ID\n ")
  555.         with open('orders.txt') as f: #opens the file
  556.             if order_ID in f.read(): #if the order ID is in the file:
  557.                 print("Thank you")
  558.                 break
  559.             else:
  560.                 print("Order ID was not found. Please try again")
  561.     while True:
  562.  
  563.         with open("orders.txt","r") as f: #opens the file
  564.             f.seek(0) #reads the file
  565.             total = 0
  566.             for line in f: #for every line in the file:
  567.                 if order_ID in line: #if the order ID is in the line:
  568.                     total_price = line[24:36] #location of the total
  569.                     total += float(total_price) #produces the total
  570.         if total>50: #if it's more than 50:
  571.             total = float(total - (total*0.05)) #discount
  572.             total = int(total) #changes it into an integer
  573.  
  574.         print("You will be charged £",total*0.2) #20% of the total
  575.  
  576.  
  577.         with open("orders.txt","r+") as f:
  578.             new_f = f.readlines() #reads the file
  579.             f.seek(0)
  580.             for line in new_f: #for every line in the file:
  581.                 if order_ID not in line: #if the order ID isn't in the line:
  582.                     f.write(line) #writes the line back in
  583.             print("Order deleted ")
  584.             f.truncate()
  585.  
  586.        
  587.         if total>50: #if the total is more than 50
  588.             total = float(total - (total*0.05))
  589.             total = str(total) #turns it into a string (so it can be stored)
  590.        
  591.         a = input("Would you like to cancel another order? (Y/N)\n ")
  592.         if a == ("n"):
  593.             break
  594.  
  595.         elif a == ("y"):
  596.             delOrder()
  597.    
  598.  
  599. def delCustomer():
  600.     while True:        
  601.         del_item = input("Please enter customer ID\n ")            
  602.  
  603.         with open("customers.txt","r+") as f:
  604.             new_f = f.readlines() #reads the file
  605.             f.seek(0)
  606.             for line in new_f: #for every line in the file:
  607.                 if del_item not in line: #if it's not in the line
  608.                     f.write(line)#write the line back in
  609.             print("Customer deleted")
  610.             f.truncate()
  611.  
  612.         a = input("Would you like to remove another customer? (Y/N)\n ")
  613.         if a == ("n"):
  614.             break
  615.  
  616.         elif a == ("y"):
  617.             print("Thank you")
  618.    
  619.    
  620.    
  621. def createInvoice():
  622.    
  623.     while True:
  624.         order_ID = input("Please enter your order ID\n ")
  625.         with open('orders.txt') as f:
  626.             if order_ID in f.read():
  627.                 print("Thank you")
  628.                 break
  629.             else:
  630.                 print("Order ID was not found. Please try again")
  631.  
  632.     with open("orders.txt","r+") as f:
  633.         f.seek(0)        
  634.         for line in f:
  635.             if order_ID in line:
  636.                 quantity = line[0:12]
  637.                 orderID = line[12:24]
  638.                 ovr_price = line[24:36]
  639.                 date = line[36:48]
  640.                 customerID = line[48:60]
  641.                 stockID = line[60:72]
  642.                 stockName = line[72:84]
  643.                 itemPrice = line[84:96]
  644.                
  645.                 print("\nInvoice for Order ID: " +orderID)
  646.                 print("Date of order:      " + date)
  647.                 print("Customer ID:        " + customerID)
  648.                 print("Stock ID:           " + stockID)
  649.                 print("Item name:          " + stockName)
  650.                 print("Item price:         " + itemPrice)
  651.                 print("Stock Quantity:     " + quantity)
  652.                 ovr_price = float(ovr_price)
  653.                 ovr_price = ovr_price + 5.99
  654.                 ovr_price = str(ovr_price)
  655.                 print("Shipping:           £5.99")
  656.                 print("Total:              " + ovr_price)
  657.                
  658.  
  659.     while True:      
  660.         with open("orders.txt","r") as f:
  661.             f.seek(0)
  662.             total = 0
  663.             for line in f:
  664.                 if order_ID in line:
  665.                     total_price = line[24:36]
  666.                     total += float(total_price)
  667.  
  668.         if total>50:
  669.             total = float(total-(total*0.05))
  670.             total = str(total)
  671.             print("\nYour order total is:     ",total + " (Including 5% discount)")
  672.             break
  673.         else:
  674.             print("\nYour order total is:     ",total)
  675.             break
  676.                
  677.                
  678. def check_unpaid_orders(): #begins the late orders function
  679.  
  680.     today = datetime.datetime.now() #detecting Current Date
  681.  
  682.     with open('orders.txt') as orders:
  683.         expired = []
  684.         dates = [[datetime.datetime.strptime(i[36:62].strip(), '%Y-%m-%d %H:%M:%S.%f'),i[12:24]] for i in orders.readlines()]
  685.         for i in dates: #check + print expired invoices
  686.             if today > i[0] + datetime.timedelta(28): #checks if the current date is larger than the date saved in the file
  687.                 expired.append(i)
  688.         if len (expired) >0:
  689.             print("Late 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 order which is late and the date of  the order
  690.         else:
  691.             print("There are currently no late orders")
  692.  
  693.     mainMenu()
  694.            
  695. def payOrder():
  696.     while True:
  697.         order_ID = input("Please enter your order ID\n ")
  698.         with open('orders.txt') as f: #opens the file
  699.             if order_ID in f.read(): #if the order ID is in the text file:
  700.                 print("Thank you")
  701.                 break
  702.     while True:
  703.         pay_file = open("paid.txt","a") #opens the paid file in append mode
  704.         orders_file = open('orders.txt', 'r') #opens the orders file in read mode
  705.         for line in orders_file: #for each line in the orders file:
  706.             if order_ID in line: #if the order ID is in the line:
  707.                 line = line.ljust(12) #gives room at the end of the line
  708.                 pay_file.write(line + "\n") #writes the line into the paid flie        
  709.         break
  710.  
  711.     while True:      
  712.         with open("orders.txt","r") as f:
  713.             f.seek(0)
  714.             total = 0
  715.             for line in f:
  716.                 if order_ID in line:
  717.                     total_price = line[24:36]
  718.                     total += float(total_price)
  719.  
  720.         if total>50:
  721.             total = float(total-(total*0.05))
  722.             total = str(total)
  723.             print("\nYour order total is:     ",total + " (Including 5% discount)")
  724.             break
  725.         else:
  726.             print("\nYour order total is:     ",total)
  727.             break
  728.  
  729.  
  730.  
  731.    
  732. def main():
  733.     check_files()
  734.     mainMenu()
  735.  
  736. main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top