Beispiel #1
0
class FinishLease(Frame):
    leasedItem = ''
    leaseSum = 0
    fee = 0
    insurance = 5
    totalPrice = 0
    items = []
    oId = 0
    
    def __init__(self, parent, logic):
        Frame.__init__(self, parent)
        from Pages.main import MainPage
        from Pages.searchEngine import Result
        from Logic.mSettings import Settings
        from Logic.tLogic import ToolLogic
        from Logic.rLogic import LeaseLogic
        
        self.logic = logic
        self.tool = ToolLogic()
        self.lease = LeaseLogic()
        self.logic = logic
        
        Button(self, text='Logout', command=lambda: logic.show_frame(MainPage)).pack()
        Label(self, text='Return Tool', font=Settings.lFont).pack(padx=10, pady=10)
        
        Button(self, text='Go back!', command=lambda: self.logic.show_frame(Result)).pack(padx=10, pady=10)
        Label(self, text='Payment List:', font=Settings.lFont).pack(padx=10, pady=10)
        
        self.frame = Frame(self, relief=RAISED, borderwidth=1)
        self.frame.pack(fill=BOTH, expand=True)
        
        Label(self, text='Additional Info:', font=Settings.lFont).pack(padx=10, pady=10)
        self.addInfo = Label(self, text='Additional Info:', font=Settings.lFont)
        self.addInfo.pack(padx=10, pady=10)
        
        Label(self, text='Photos:', font=Settings.lFont).pack()
        Button(self, text='Browse', command=self.addToolPhoto).pack()
        
        Label(self, text='Price', font=Settings.lFont).pack(padx=10, pady=10)
        self.price = Label(self, text='Price', font=Settings.lFont)
        self.price.pack(padx=10, pady=10)

        Button(self, text='Confirm', command=self.makeLease).pack()

    def makeLease(self):
        self.lease.endLease(self.logic.lId, self.totalPrice, self.logic.session.uId)
        self.payments.addPayment(self.logic.session.uId, self.items, self.totalPrice)
        self.logic.show_frame(PaymentPage)

    def addToolPhoto(self):
        from Logic.fLogic import FileLogic
        file = FileLogic()
        self.photos = file.addPhoto()
        print(self.photos)

    def run(self):
        from Logic.pLogic import PaymentsLogic
        self.payments = PaymentsLogic()
        self.leaseItem = self.lease.getLeases(self.logic.selectrental)
        tool = self.tool.searchId(self.leasedItem['tId'])
        self.oId = tool['uId']
        fee = int(tool['price'])
        now = time.time()
        if (self.leasedItem['dEnd'] < now):
            self.addInfo.config(
                text='Your payment is multiplied 2 times, because you should finish renting before end date')
            fee = int(fee) * 2
        Label(self.frame, text=tool['name']).pack(padx=10, pady=10)
        days = datetime.datetime.utcfromtimestamp(now) - datetime.datetime.utcfromtimestamp(
            self.leasedItem['dStart'])
        itemPrice = fee * int(days.days)
        self.itemlist = [tool['name'] + ' Price:' + str(itemPrice), 'Insurance Price:' + str(self.insurance)]

        Label(self.frame, text='Price: ' + str(itemPrice),
              font=Settings.lFont).pack(padx=10, pady=10)
        Label(self.frame, text='Insurance: ').pack(padx=10, pady=10)
        Label(self.frame, text='Price: ' + str(self.insurance),
              font=Settings.lFont).pack(padx=10, pady=10)
        price = int(itemPrice) + self.insurance

        self.price.config(
            text='Total:' + str(price))
        self.totalPrice = price
Beispiel #2
0
class UserToolsPage(Frame):
    sTool = ''
    listTool = []
    listToolToLease = []
    
    def __init__(self, parent, logic):
        self.logic = logic
        self.tool = ToolLogic()
        self.lease = LeaseLogic()
        
        Frame.__init__(self, parent)

        Button(self, text="Logout", command=lambda: self.logic.show_frame(MainPage)).pack()
        Button(self, text="Back", command=lambda: self.logic.show_frame(Search)).pack(pady=10, padx=10)

        self.topic = Label(self, text="Your balance is: £" + str(Settings.mAvail),font=Settings.lFont)
        self.topic.pack(pady=10, padx=10)

        Label(self, text="Leased:", font=Settings.lFont).pack(pady=10, padx=10)

        scrollBar = Scrollbar(self)
        scrollBar.pack(side=RIGHT, fill=Y)
        self.record = Listbox(self, yscrollcommand=scrollBar.set)
        tools = self.tool.getListAll(1514206410.671336)
        for index, itemTool in enumerate(tools):
            self.record.insert(END, itemTool["name"] + str(index))
        self.record.pack(fill=BOTH)
        scrollBar.config(command=self.record.yview())

        Label(self, text="Rented:", font=Settings.lFont).pack(pady=10, padx=10)

        scrollBar = Scrollbar(self)
        scrollBar.pack(side=RIGHT, fill=Y)
        self.rRecord = Listbox(self, yscrollcommand=scrollBar.set)
        for line in range(100):
            self.rRecord.insert(END, "Tool number" + str(line))
        self.rRecord.pack(fill=BOTH)
        scrollBar.config(command=self.rRecord.yview())


    def run(self):
        self.sTool = ""
        if self.logic.session.session:
            tools = self.tool.getListAll(self.logic.session.uDetails["id"])
            self.record.delete(0, END)
            self.topic.config(text="Your balance is: £" + str(self.logic.session.uDetails["balance"]))
            for index, itemTool in enumerate(tools):
                self.record.insert(END, itemTool["name"])
                self.record.bind('<<ListboxSelect>>', self.select)
                self.listTool.append(itemTool)
            leases = self.lease.getLeasesUser(self.logic.session.uDetails["id"])
            self.rRecord.delete(0, END)
            for index, rental in enumerate(leases):
                itemTool = self.tool.searchId(rental["tId"])
                self.rRecord.insert(END, itemTool["name"])
                self.rRecord.bind('<<ListboxSelect>>', self.selectLease)
                self.rRecord.append(rental)

    def select(self, evt):
        q = evt.widget
        index = int(q.curselection()[0])
        value = q.get(index)
        self.logic.sTool = value
        self.logic.sTool = self.listTool[index]["id"]

        self.logic.show_frame(UserToolPage)

    def selectLease(self, evt):
        w = evt.widget
        index = int(w.curselection()[0])
        value = w.get(index)
        self.logic.selectLease = value
        self.logic.selectLease = self.listToolToLease[index]["id"]
        
        self.logic.show_frame(FinishLease)