Advertisement
Guest User

work

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