0
Need help with a code.
Hello, I have this code below, I used easy gui, Pickle and date.time. I've gotten this so far and I need help with a few things. Here's what I need help with: Produce replacement invoices for cancelled orders Also add a standard delivery charge of £5.99 for all orders. Order over £50 not inc delivery recieves a 5% discount. If an order is cancelled the user is charged 20% of the cost of the order. Also the program needs to have built using simple code that's understandable and needs to be annotated with comments using hashes.
5 odpowiedzi
+ 1
from easygui import *
import datetime
import pickle
try:
    fh = open( "orders.p", "rb" )
    pickle.load(orders,fh)
    fh.close()
except:
    orders = []
orders = []
def mainmenu():
    while True:
        msg = """»»————-— ★ ———————-««
                Ceramic Arts
                »»————-— ★ ———————-««
                """
        title = "Press The Button you'd like to go to."
        menuoptions = ["Create Order" , "Find Order" , "Edit Order" , "Exit"]
        choice = buttonbox(msg,choices=menuoptions)
        if choice == "Create Order":
            createorder()
        elif choice == "Find Order":
            findorder()
        elif choice =="Pay Order":
            payorder()
        elif choice =="Exit":
            break
def createorder():
    msgbox("-★Create Your Order★-")
    neworder = []
    while True:
        studentname = enterbox("Enter Student Name ")
        if studentname != "":
            break
    neworder.append(studentname)
    form = enterbox("Enter Form") 
    neworder.append(form) 
    email = enterbox("Enter Email Address ") 
    neworder.append(email) 
    colour = enterbox("Enter Hoody Colour ") 
    neworder.append(colour)
    hoodytext = enterbox("Enter Hoody Text ") 
    neworder.append(hoodytext) 
    while True:
        qty = enterbox("Enter Quantity ") 
        if qty.isnumeric():
            break
        else:
            msgbox("Error with number")
    neworder.append(qty) 
    price = enterbox("Enter Price ") 
    neworder.append(price) 
    paid = "NO"
    neworder.append(paid) 
    today = datetime.date.today()
    todaystring = str(today) 
    neworder.append(todaystring)
    orders.append(neworder) 
    msgbox("Hoody order for", studentname, "created.")
    recordnumber = len(orders) - 1
    receipt(recordnumber)
    fh = open( "orders.p", "wb" )
    pickle.dump( orders, fh)
    fh.close()
0
def findorder() :
    msgbox("-★Find Order★-")
    searchterm = enterbox("Enter A Name To Search.")
    for singleorder in orders: 
        if searchterm in singleorder:
         msgbox("Student Name :" + singleorder[0])
         msgbox("Form:" + singleorder[1])
         msgbox("Email :" + singleorder[2])
         msgbox("Colour:" + singleorder[3])
         msgbox("Hoody Text:" + singleorder[4])
         msgbox("QTY :" + singleorder[5])
         msgbox("Price (£):" + singleorder[6])
         msgbox("Paid:" + singleorder[7])
         msgbox("Date:" + singleorder[8])
def payorder():
     msgbox("-★Pay For Order★-")
     recordnumber = enterbox("Enter a record you want to mark as paid")
     if recordnum.isdigit() and recordnum in range(0,len(orders)-1):
        msgbox("Student Name       :" + orders[recordnum][0])
        msgbox("Form               :" + orders[recordnum][1])
        msgbox("Email              :" + singleorder[2])
        msgbox("Colour             :" + singleorder[3])
        msgbox("Hoody Text         :" + singleorder[4])
        msgbox("QTY                :" + singleorder[5])
        msgbox("Price (£)          :" + singleorder[6])
        msgbox("Paid               :" + singleorder[7])
        msgbox("Date               :" + singleorder[8])
        answer = enterbox("Do you want to mark your order as paid? Yes / No.")
        if answer == "Yes":
            orders[recordnum][7] = "Yes"
            receipt(recordnum)
0
def findoldunpaidorders():
    msgbox("-★Find Old Orders★-")
    d1 = datetime.date.today()
    for singleorder in orders:
        d2string = singleorder[8] #gets date in format of yyyy-mm-dd
        year = int(d2string[0:4]) #extracts day, month year
        month = int(d2string[5:7]) # converts to ints
        day = int(d2string[8:10])
        d2 = datetime.date(year,month,day) #creates date time object
        timedelta = d2-d1 #calculates time difference
        dayselapsed = timedelta.days # gets days diffence
        if dayselapsed > 10:
            msgbox("Student Name :" + singleorder[0])
            msgbox("Form:" + singleorder[1])
            msgbox("Email :" + singleorder[2])
            msgbox("Colour:" + singleorder[3])
            msgbox("Hoody Text:" + singleorder[4])
            msgbox("QTY :" + singleorder[5])
            msgbox("Price (£):" + singleorder[6])
            msgbox("Paid:" + singleorder[7])
            msgbox("Date:" + singleorder[8])
def receipt(recordnum):
    msgbox("***Creating Receipt***")
    receiptstring = "Recipet Number: " + str(recordnum)
    receiptstring += "\n" + "Student Name: " + orders[recordnum][0]
    receiptstring += "\n" + "Form: " + orders[recordnum][1]
    receiptstring += "\n" + "Email: " + orders[recordnum][2]
    receiptstring += "\n" + "Colour: " + orders[recordnum][3]
    receiptstring += "\n" + "Hoody Text: " + orders[recordnum][4]
    receiptstring += "\n" + "QTY: " + orders[recordnum][5]
    receiptstring += "\n" + "Price (£): " + orders[recordnum][6]
    receiptstring += "\n" + "Paid: " + orders[recordnum][7]
    receiptstring += "\n" + "Date: " + orders[recordnum][8]
0
qty = orders[recordnum][5]
    price = orders[recordnum][6]
    total = int(qty) * float(price)
    totalstring = str(total)
    receiptstring += "/n" + "total (£):" + totalstring
    msgbox(receiptstring)
    filename = "receipt"+str(recordnum)+".txt"
    fh = open(filename, "w")
    fh.write(receiptstring)
    fh.close()
    msgbox("Receipt has been saved to a file!")
0
Sort by date.



