Advertisement
Guest User

Untitled

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