コード例 #1
0
    def notepage3(self, note):
        app2 = Frame(note)
        app2.grid(row=0, column=0)
        for i in range(3):
            app2.rowconfigure(i, weight=1)
        for i in range(3):
            app2.columnconfigure(i, weight=1)
        note.add(app2, text=' Sales ')
        Label(app2, text="Sales Records", foreground="#3496ff", font=('Berlin Sans FB Demi', 25)).grid(row=0, column=0,
                                                                                                       columnspan=1,
                                                                                                       sticky=sty,
                                                                                                       pady=9)
        self.btn31 = Button(app2, text="Edit Selling Records", command=lambda: self.sellsedit(None))
        self.btn31.grid(row=0, column=1, sticky=sty, pady=20)
        self.btn32 = Button(app2, text="Delete Selling Records", command=lambda: self.deletesells())
        self.btn32.grid(row=0, column=2, sticky=sty, pady=20, padx=10)

        self.mlb22 = MultiListbox(app2, (
            ("Selling ID", 25), ("Sold Date", 35), ("Cost Price", 25), ("Sold Price", 25), ("Quantity", 15),
            ("Profit", 25)))
        self.mlb22.grid(row=1, column=0, columnspan=3, sticky=sty)
        self.mlb22.tree.bind('<Double-Button-1>', self.sellsedit)
        lf = Frame(app2)
        lf.grid(row=2, column=0, sticky=sty)
        Label(lf, text="Total Gain From Product  - ").grid(row=0, column=0, sticky=sty, pady=8, padx=7)
        self.gp = Label(lf, text="0")
        self.gp.grid(row=0, column=1, sticky=sty, padx=2)
        Label(lf, text="Total Profit  - ").grid(row=1, column=0, sticky=sty, pady=8, padx=7)
        self.pg = Label(lf, text="0")
        self.pg.grid(row=1, column=1, sticky=sty, padx=2)
        Label(lf, text="Total Item Sold  - ").grid(row=2, column=0, sticky=sty, pady=8, padx=7)
        self.tis = Label(lf, text="0")
        self.tis.grid(row=2, column=1, sticky=sty, padx=2)
        self.Add2Mlb22()
コード例 #2
0
 def __init__(self, master, db):
     self.value = []
     self.db = db
     self.master = master
     self.f = Frame(master)
     self.f.grid(row=0, column=0, sticky=N + W + S + E)
     self.f.columnconfigure(0, weight=1)
     self.f.rowconfigure(1, weight=1)
     Label(self.f,
           text="Category List",
           foreground="#3496ff",
           font=('Berlin Sans FB Demi', 20)).grid(row=0,
                                                  column=0,
                                                  sticky=N + S + E + W)
     self.mlb1 = MultiListbox(self.f,
                              (('Category Name', 35), ('No of Product', 45),
                               ('Category ID', 30)),
                              height=20)
     self.mlb1.grid(row=1, column=0, columnspan=4, sticky=N + W + S + E)
     self.Del = Button(self.f, text="Delete", command=lambda: self.Delete())
     self.Del.grid(row=2, column=3)
     self.Add = Button(self.f,
                       text="ADD",
                       command=lambda: self.Add_category())
     self.Add.grid(row=2, column=1)
     self.Edit = Button(self.f,
                        text="Edit",
                        command=lambda: self.Add_category(edit=True))
     self.Edit.grid(row=2, column=2)
     self.Insert()
コード例 #3
0
 def __init__(self, master, db):
     self.value = []
     self.db = db
     self.master = master
     self.f = Frame(master)
     self.f.grid(row=0, column=0, sticky=N + W + S + E)
     self.f.columnconfigure(0, weight=1)
     self.f.rowconfigure(1, weight=1)
     Label(self.f,
           text="Invoice List",
           font=('Berlin Sans FB Demi', 21),
           foreground="#3496ff").grid(row=0,
                                      column=0,
                                      sticky=N + S + E + W,
                                      columnspan=2,
                                      padx=10,
                                      pady=5)
     self.mlb1 = MultiListbox(self.f,
                              (("Invoice ID", 40), ('Invoice No', 17),
                               ('Invoice Date', 40),
                               ('Customer Attached', 40)),
                              height=15)
     self.mlb1.grid(row=1, column=0, columnspan=4, sticky=N + W + S + E)
     self.Del = Button(self.f, text="Delete", command=lambda: self.Delete())
     self.Del.grid(row=2, column=3)
     self.Add = Button(self.f,
                       text="ADD",
                       command=lambda: self.Add_Invoice())
     self.Add.grid(row=2, column=1)
     self.Edit = Button(self.f,
                        text="Edit",
                        command=lambda: self.Add_Invoice(edit=True))
     self.Edit.grid(row=2, column=2)
     self.Insert()
コード例 #4
0
 def __init__(self,master,db):
     Frame.__init__(self,master)
     self.master = master
     self.db = db
     self.date ={}
     self.mlb = MultiListbox(master,(("Purchase Date",40),("Product Name",40),("Quantity Brought",20),("Cost Price",30)))
     self.mlb.grid(row = 0,column = 0,sticky = sty)
     self.assign()
コード例 #5
0
class Purchase_Log(Frame):
    def __init__(self,master,db):
        Frame.__init__(self,master)
        self.master = master
        self.db = db
        self.date ={}
        self.mlb = MultiListbox(master,(("Purchase Date",40),("Product Name",40),("Quantity Brought",20),("Cost Price",30)))
        self.mlb.grid(row = 0,column = 0,sticky = sty)
        self.assign()

    def assign(self):
        row = self.db.sqldb.execute("""SELECT purchase_date,product_name,QTY,cost FROM purchase
                                JOIN costs USING (cost_id) JOIN products USING (product_id) """)
        a = row.fetchall()
        for i in a :
            self.mlb.insert(END,i)
コード例 #6
0
 def notepage2(self, note):
     self.invid = None
     app1 = Frame(note)
     app1.grid(row=0, column=0, sticky=sty)
     note.add(app1, text=' Invoices ')
     for i in range(5):
         app1.rowconfigure(i, weight=1)
     for i in range(3):
         app1.columnconfigure(i, weight=1)
     Label(app1,
           text="Invoice Attached",
           font=('Berlin Sans FB Demi', 21),
           foreground="#3496ff").grid(row=0,
                                      column=0,
                                      sticky=sty,
                                      padx=10,
                                      pady=10)
     self.mlb21 = MultiListbox(app1,
                               (("Invoice ID", 30), ("Invoice Number", 25),
                                ("Invoice Date", 35), ("Paid", 20)))
     self.mlb21.grid(row=1, column=0, columnspan=3, sticky=sty)
     Button(app1, text="Edit Invoice",
            command=lambda: self.editinvoice()).grid(row=0,
                                                     column=1,
                                                     sticky=sty,
                                                     pady=20)
     Button(app1,
            text="Delete Invoice",
            command=lambda: self.deleteinvoice()).grid(row=0,
                                                       column=2,
                                                       sticky=sty,
                                                       pady=20,
                                                       padx=5)
     self.lbl1 = Label(app1, text="Total Amount Earned - 0 ")
     self.lbl1.grid(row=2, column=0, sticky=sty, padx=5, pady=5)
     self.lbl2 = Label(app1, text="Total No of Product - 0 ")
     self.lbl2.grid(row=3, column=0, sticky=sty, padx=5, pady=5)
     self.lbl3 = Label(app1, text="Total Amount Due - 0 ")
     self.lbl3.grid(row=4, column=0, sticky=sty, padx=5, pady=5)
     if self.modify == True:
         self.mlb21load()
     return 1
コード例 #7
0
 def notepage15(self, note):
     self.pcostid = None
     app15 = Frame(note)
     app15.grid(row=0, column=0)
     for i in range(3):
         app15.rowconfigure(i, weight=1)
     for i in range(3):
         app15.columnconfigure(i, weight=1)
     app15.rowconfigure(0, weight=1)
     note.add(app15, text=' Costs ')
     Label(app15, text="Product Costs", foreground="#3496ff", font=('Berlin Sans FB Demi', 25)).grid(row=0, column=0,
                                                                                                     columnspan=1,
                                                                                                     sticky=sty,
                                                                                                     pady=9)
     self.btn12 = Button(app15, text="Delete costs", command=lambda: self.deletecost())
     self.btn12.grid(row=0, column=2, sticky=sty, pady=20, padx=10)
     self.mlb11 = MultiListbox(app15, (("Cost ID", 25), ("Cost Price", 30), ("Selling Price", 30), ("Qty", 15)))
     self.mlb11.grid(row=1, column=0, columnspan=3, sticky=sty)
     self.mlb11.tree.bind('<Double-Button-1>', self.setcostid)
     lf = LabelFrame(app15, text="ADD New Costs", labelanchor=N + W)
     lf.grid(row=2, column=0, sticky=sty, pady=5, padx=5)
     self.costhead = lf
     for i in range(3):
         lf.rowconfigure(i, weight=1)
     for i in range(2):
         lf.columnconfigure(i, weight=1)
     Label(lf, text="New Cost").grid(row=0, column=0, sticky=sty, pady=5, padx=5)
     self.ncost = Entry(lf)
     self.ncost.grid(row=0, column=1, sticky=sty, pady=5, padx=5)
     Label(lf, text="New Price").grid(row=1, column=0, sticky=sty, pady=5, padx=5)
     self.nprice = Entry(lf)
     self.nprice.grid(row=1, column=1, sticky=sty, pady=5, padx=5)
     self.btn13 = Button(lf, text="Add Cost", command=lambda: self.addcost())
     self.btn13.grid(row=2, column=1, sticky=sty, pady=5, padx=5)
     self.btn14 = Button(lf, text="Edit Cost", command=lambda: self.addcost(True))
     self.btn14.grid(row=2, column=0, sticky=sty, pady=5, padx=5)
     self.Add2Mlb15()
コード例 #8
0
 def notepage2(self, note):
     self.purid = None
     app1 = Frame(note)
     app1.grid(row=0, column=0)
     for i in range(3):
         app1.rowconfigure(i, weight=1)
     for i in range(3):
         app1.columnconfigure(i, weight=1)
     app1.rowconfigure(0, weight=1)
     note.add(app1, text=' Purchase ')
     Label(app1, text="Purchase Records", foreground="#3496ff", font=('Berlin Sans FB Demi', 25)).grid(row=0,
                                                                                                       column=0,
                                                                                                       columnspan=1,
                                                                                                       sticky=sty,
                                                                                                       pady=9)
     self.btn21 = Button(app1, text="Edit Purchase Records", command=lambda: self.purchaseedit(None))
     self.btn21.grid(row=0, column=1, sticky=sty, pady=20)
     self.btn22 = Button(app1, text="Delete Purchase Records", command=lambda: self.deletepurchase())
     self.btn22.grid(row=0, column=2, sticky=sty, pady=20, padx=10)
     self.mlb21 = MultiListbox(app1, (
         ("Purchase ID", 25), ("Purchase Date", 35), ("Cost Price", 25), ("Selling Price", 25), ("Qty", 10),
         ("Expected profit", 25)))
     self.mlb21.grid(row=1, column=0, columnspan=3, sticky=sty)
     self.mlb21.tree.bind('<Double-Button-1>', self.purchaseedit)
     lf = Frame(app1)
     lf.grid(row=2, column=0, sticky=sty)
     Label(lf, text="Total Profit Estimated  - ").grid(row=1, column=0, sticky=sty, pady=8, padx=7)
     Label(lf, text="Total Capital Invested  - ").grid(row=0, column=0, sticky=sty, pady=8, padx=7)
     Label(lf, text="Total Item Brought  - ").grid(row=2, column=0, sticky=sty, pady=8, padx=7)
     self.ib = Label(lf, text="0")
     self.ib.grid(row=2, column=1, sticky=sty, padx=2)
     self.ci = Label(lf, text="0")
     self.ci.grid(row=0, column=1, sticky=sty, padx=2)
     self.te = Label(lf, text="0")
     self.te.grid(row=1, column=1, sticky=sty, padx=2)
     self.Add2Mlb21()
コード例 #9
0
class NewProduct(Frame):
    def __init__(self, master, tup, modify, db):
        Frame.__init__(self, master)
        self.db = db
        self.tup = tup
        self.modify = modify
        bg = 'White'
        fg = "#3496ff"
        self.master = master
        self.f = Frame(self, style='me.TFrame')
        self.f.grid(row=0, column=0, sticky=sty)
        self.f.rowconfigure(1, weight=3)
        self.f.columnconfigure(0, weight=1)
        if modify == True:
            value = tup[1]
        else:
            value = "Product Name"
        self.name = Label(self.f, text=value, font=('Berlin Sans FB Demi', 40), foreground=fg)
        self.name.grid(row=0, column=0, sticky=sty)
        note = Notebook(self.f)
        note.grid(row=1, column=0, sticky=sty)
        note.rowconfigure(0, weight=1)
        note.columnconfigure(0, weight=1)
        self.notepage1(note, modify, tup)
        if modify == True:
            self.notepage15(note)
            self.notepage2(note)
            self.notepage3(note)

    def update_name(self, event):
        name = Filter(self.entry5.get()).title()
        if len(name) == 0:
            name = "Product Name"
        self.name.configure(text=name)

    def Load_Percent(self, cost, price):
        if float(cost) == 0.0:
            return 0
        profit = float(price) - float(cost)
        percent = (100 * profit) / float(cost)
        return round(percent, 2)

    def notepage1(self, note, modify, tup):
        app = Frame(note)
        app.grid(row=0, column=0)
        self.f.rowconfigure(0, weight=1)
        self.f.columnconfigure(0, weight=1)
        note.add(app, text='Detail')
        for i in range(17):
            app.rowconfigure(i, weight=1)
        for i in range(8):
            app.columnconfigure(i, weight=1)
        Label(app, text='Product Detail', font=('Berlin Sans FB Demi', 23), foreground="#3496ff").grid(row=0, column=0,
                                                                                                       columnspan=2,
                                                                                                       sticky=sty)
        Label(app, text='Product Name').grid(row=1, column=0, sticky=E, padx=10, pady=4)
        self.entry5 = Entry(app, width=65)
        self.entry5.grid(row=1, column=1, columnspan=2, sticky=sty, padx=10, pady=10)
        self.entry5.bind('<Any-KeyRelease>', self.update_name)
        Label(app, text="Product Category").grid(row=2, column=0, sticky=E, padx=10, pady=10)
        self.entry = Combobox(app, width=35)
        self.entry.grid(row=2, column=1, columnspan=2, sticky=sty, padx=10, pady=10)
        Label(app, text="Product Description").grid(row=3, column=0, sticky=N + E, padx=10, pady=10)
        self.text = Text(app, width=26, height=5, wrap=WORD, relief=FLAT)
        self.text.grid(row=3, column=1, columnspan=2, sticky=sty, padx=10, pady=10)
        self.text.configure(highlightthickness=1, highlightbackground="Grey")
        self.df = self.text.configure()
        Label(app, text="Product QTY").grid(row=4, column=0, sticky=E, padx=10, pady=10)
        self.qty = StringVar()
        self.entry3 = Entry(app, width=35, textvariable=self.qty)
        self.entry3.grid(row=4, column=1, columnspan=2, sticky=E + W, padx=10, pady=10)

        Label(app, text=" Product ID ").grid(row=5, column=0, sticky=E)
        self.entry6 = Entry(app, width=35)
        self.entry6.grid(row=5, column=1, columnspan=2, sticky=sty, padx=10, pady=10)
        btn = Button(app, text='Save', width=12, command=lambda: self.Save(modify, self.tup), style='new.TButton')
        btn.grid(row=6, column=1, sticky=sty, padx=10, pady=10)
        copy = Button(app, text='Save As Copy', command=lambda: self.Save(False, self.tup), style='new.TButton')
        copy.grid(row=6, column=2, sticky=sty, padx=10, pady=10)
        keys = self.db.sqldb.execute("SELECT category_name FROM category").fetchall()
        keys = map(selectfirst, keys)
        keys.sort()
        self.entry['value'] = keys
        del keys
        if modify == False:
            copy['state'] = DISABLED
        if modify == True:
            d = self.db.sqldb.execute(""" SELECT product_name,category_name,product_description FROM  products 
                        JOIN category USING (category_id) WHERE product_id = "%s" """ % (tup[0])).fetchone()
            name = d[0]
            category = d[1]
            Des = d[2]
            no = tup[0]
            qty = self.db.sqldb.getquantity(tup[0])
            self.entry5.delete(0, END)
            self.entry5.insert(0, name)
            self.entry.delete(0, END)
            self.entry.insert(0, category)
            self.text.delete(0.0, END)
            self.text.insert(0.0, Des)
            self.entry3.delete(0, END)
            self.qty.set(qty)
            self.entry6.delete(0, END)
            self.entry6.insert(0, no)
        self.entry6['state'] = "readonly"
        self.entry3['state'] = "readonly"

    def Percent(self, event):
        cost = Filter(self.entry4.get())
        if len(cost) == 0:
            return showinfo(title="Error", message='Product Cost Must Be Specified Before Product % ',
                            parent=self.master)
        else:
            try:
                cost = float(cost)
            except(AttributeError, ValueError):
                return showinfo(title="Error", message='Numbers Must be Written in Cost Entry', parent=self.master)
        percent = Filter(self.entry7.get())
        if len(percent) == 0:
            percent = 0
        else:
            try:
                percent = float(percent)
            except(AttributeError, ValueError):
                return showinfo(title="Error", message='Numbers Must be Written in Profit % Entry', parent=self.master)
        s = cost / 100.0
        s = s * percent
        price = float(cost) + s
        price = round(price, 2)
        self.entry2.delete(0, END)
        self.entry2.insert(0, price)
        return 1

    def Save(self, modify, tup):
        """Objects of Tup
           tup[0] ->  ID No
           tup[1] ->  Product name
           tup[2] ->  category
           tup[3] ->  description
           tup[4] ->  quantity
        """

        name = Filter(self.entry5.get()).title()
        category = Filter(self.entry.get()).title()
        description = Filter(self.text.get(0.0, END)).title()
        if len(name.split()) == 0:
            return showinfo(title="Error", message='Product Name Must Be Specified', parent=self.master)
        if len(category.split()) == 0:
            return showinfo(title="Error", message='Product Category Must Be Specified', parent=self.master)
        vre = self.db.sqldb.getproductID(name)
        if modify == False:
            if vre != None:
                return showinfo(title="Error", message='Product Name is Already Listed Change Name To Save As Copy',
                                parent=self.master)
            PID = self.db.addproduct(name, category, description)
        elif modify == True:
            PID = tup[0]
            previousname = tup[1]
            previouscategory = tup[2]
            pdescription = tup[3]
            if previousname != name:
                if vre != None:
                    return showinfo(title="Error", message='Product Name is Already Listed', parent=self.master)
                s = askokcancel("Name Mismatch",
                                "Are You Sure You Want to Change\n\n%s to %s\n\n%s to %s\n\n%s to %s" % (
                                    previousname, name, previouscategory,
                                    category, pdescription, description), parent=self.master)
                if s == False:
                    return False
            self.db.editproduct(PID, name, category, description)
        self.master.destroy()
        return showinfo("ADDED", 'Saved Successfully')

    def Add2Mlb15(self):
        self.mlb11.delete(0, END)
        ins = self.mlb11.insert
        if self.modify == True:
            row = self.db.sqldb.execute(""" SELECT cost_id,cost,price FROM costs
                                          JOIN products USING (product_id)  WHERE product_id = "%s"  """ % (
                self.tup[0])).fetchall()
            for i in row:
                i = list(i)
                price = i[2]
                cost = i[1]
                costid = i[0]
                qty = self.db.sqldb.getcostquantity(costid)
                i.append(qty)
                ins(END, i)

    def dummy(self):
        pass

    def addcost(self, edit=False):
        try:
            PID = self.tup[0]
        except(IndexError):
            return showinfo(title="ERROR", message='Product Not Yet Saved', parent=self.master)
        try:
            newcost = float(Filter(self.ncost.get()))
            newprice = float(Filter(self.nprice.get()))
        except:
            return showinfo(title="ERROR", message='costs and price must be numbers', parent=self.master)
        costid = self.db.sqldb.getcostID(PID, newcost, newprice)
        if costid != None:
            return showinfo("Message", "Cost and Price Already Listed", parent=self.master)
        if edit == False:
            self.db.sqldb.addnewcost(PID, newcost, newprice)
        else:
            i = self.mlb11.Select_index
            if i == None:
                return showinfo("Message", "Select a Cost Or Price To Edit", parent=self.master)
            r = self.mlb11.get(i)
            pcostid = r[0]
            self.db.editcosts(pcostid, PID, newcost, newprice)
        self.Add2Mlb15()
        self.ncost.delete(0, END)
        self.nprice.delete(0, END)

    def deletecost(self):
        PID = self.tup[0]
        costid = self.pcostid
        if costid == None:
            return showinfo("Message", "Select a Cost Or Price To Delete", parent=self.master)
        ans = self.db.sqldb.deletecost(costid)
        if ans == True:
            return showinfo("Message", "%s Has Been Successfully Deleted" % (costid),
                            parent=self.master), self.Add2Mlb15()
        else:
            return showinfo("Message", "Cannot Delete %s It Is Associated With Purchase And Sells" % (costid),
                            parent=self.master)

    def setcostid(self, event):
        i = self.mlb11.Select_index
        r = self.mlb11.get(i)
        pcostid = r[0]
        self.costhead['text'] = pcostid
        self.pcostid = pcostid

    def notepage15(self, note):
        self.pcostid = None
        app15 = Frame(note)
        app15.grid(row=0, column=0)
        for i in range(3):
            app15.rowconfigure(i, weight=1)
        for i in range(3):
            app15.columnconfigure(i, weight=1)
        app15.rowconfigure(0, weight=1)
        note.add(app15, text=' Costs ')
        Label(app15, text="Product Costs", foreground="#3496ff", font=('Berlin Sans FB Demi', 25)).grid(row=0, column=0,
                                                                                                        columnspan=1,
                                                                                                        sticky=sty,
                                                                                                        pady=9)
        self.btn12 = Button(app15, text="Delete costs", command=lambda: self.deletecost())
        self.btn12.grid(row=0, column=2, sticky=sty, pady=20, padx=10)
        self.mlb11 = MultiListbox(app15, (("Cost ID", 25), ("Cost Price", 30), ("Selling Price", 30), ("Qty", 15)))
        self.mlb11.grid(row=1, column=0, columnspan=3, sticky=sty)
        self.mlb11.tree.bind('<Double-Button-1>', self.setcostid)
        lf = LabelFrame(app15, text="ADD New Costs", labelanchor=N + W)
        lf.grid(row=2, column=0, sticky=sty, pady=5, padx=5)
        self.costhead = lf
        for i in range(3):
            lf.rowconfigure(i, weight=1)
        for i in range(2):
            lf.columnconfigure(i, weight=1)
        Label(lf, text="New Cost").grid(row=0, column=0, sticky=sty, pady=5, padx=5)
        self.ncost = Entry(lf)
        self.ncost.grid(row=0, column=1, sticky=sty, pady=5, padx=5)
        Label(lf, text="New Price").grid(row=1, column=0, sticky=sty, pady=5, padx=5)
        self.nprice = Entry(lf)
        self.nprice.grid(row=1, column=1, sticky=sty, pady=5, padx=5)
        self.btn13 = Button(lf, text="Add Cost", command=lambda: self.addcost())
        self.btn13.grid(row=2, column=1, sticky=sty, pady=5, padx=5)
        self.btn14 = Button(lf, text="Edit Cost", command=lambda: self.addcost(True))
        self.btn14.grid(row=2, column=0, sticky=sty, pady=5, padx=5)
        self.Add2Mlb15()

    def Add2Mlb21(self):
        self.mlb21.delete(0, END)
        estmpro = 0
        cap = 0
        brou = 0
        ins = self.mlb21.insert
        if self.modify == True:
            row = self.db.sqldb.execute(""" SELECT purchase_id,purchase_date,cost,price,QTY FROM purchase
                                            JOIN costs USING (cost_id) JOIN products USING (product_id)  WHERE product_id = "%s"  """ % (
                self.tup[0])).fetchall()
            for i in row:
                i = list(i)
                purid = i[0]
                price = i[3]
                cost = i[2]
                date = i[1]
                qty = i[4]
                profit = round(price - cost, 2)
                estmpro += (profit * qty)
                cap += cost * qty
                brou += qty
                i.append(profit)
                ins(END, i)
        self.te.configure(text=str(estmpro))
        self.ci.configure(text=str(cap))
        self.ib.configure(text=str(brou))

    def purchaseedit(self, event):
        i = self.mlb21.Select_index
        if i == None:
            return showinfo("Message", "No Item Selected", parent=self.master)
        r = self.mlb21.get(i)
        self.purid = r[0]
        root13 = Toplevel()
        root13.title("Purchase Edit")
        root13.grid()
        for i in range(5):
            root13.rowconfigure(i, weight=1)
        for i in range(2):
            root13.columnconfigure(i, weight=1)
        lf = root13
        self.purgui = root13
        color = 'gray98'
        root13['background'] = color
        Label(lf, text="Purchase ID : %s" % (self.purid), foreground="#3496ff", font=('Berlin Sans FB Demi', 18)).grid(
            row=0, column=0, columnspan=2, sticky=sty, pady=8, padx=7)

        r = self.db.sqldb.execute(
            """ SELECT purchase_date,QTY,cost,price FROM purchase JOIN costs USING (cost_id) WHERE purchase_id = "%s" """ % (
                self.purid)).fetchone()
        Label(lf, text="Purchase Date").grid(row=1, column=0, sticky=sty, pady=8, padx=2)
        Label(lf, text="Quantity").grid(row=2, column=0, sticky=sty, pady=8, padx=7)
        Label(lf, text="Cost").grid(row=3, column=0, sticky=sty, pady=8, padx=7)
        Label(lf, text="Price").grid(row=4, column=0, sticky=sty, pady=8, padx=7)
        self.purdate = CalendarButton(lf)
        self.purdate.grid(row=1, column=1, sticky=sty, pady=8, padx=7)
        try:
            self.purdate.insert(r[0])
        except:
            self.purdate.insert(self.purdate.getTimeStamp())
        self.purqty = Entry(lf)
        self.purqty.grid(row=2, column=1, sticky=sty, pady=8, padx=7)
        self.purqty.delete(0, END)
        self.purqty.insert(0, r[1])
        self.purcost = Entry(lf)
        self.purcost.grid(row=3, column=1, sticky=sty, pady=8, padx=7)
        self.purcost.delete(0, END)
        self.purcost.insert(0, r[2])
        self.purprice = Entry(lf)
        self.purprice.grid(row=4, column=1, sticky=sty, pady=8, padx=7)
        self.purprice.delete(0, END)
        self.purprice.insert(0, r[3])
        Button(lf, text="Save", command=lambda: self.purchasesave()).grid(row=5, column=1, sticky=sty, pady=8, padx=7)
        root13.wait_window()
        return 1

    def purchasesave(self):
        PID = self.tup[0]
        try:
            cost = float(Filter(self.purcost.get()))
            price = float(Filter(self.purprice.get()))
            qty = float(Filter(self.purqty.get()))
            date = Filter(self.purdate.get())
            date = " ".join(date.split())
        except:
            return showinfo(title="ERROR", message='costs and price must be numbers', parent=self.master)
        costid = self.db.sqldb.getcostID(PID, cost, price)
        if costid == None:
            costid = self.db.sqldb.addnewcost(PID, cost, price)
        self.db.editpurchase(self.purid, costid, qty, date)
        self.purgui.destroy()
        self.Add2Mlb21()
        return showinfo(title="Successful", message='Changes Saved', parent=self.master)

    def deletepurchase(self):
        i = self.mlb21.Select_index
        if i == None:
            return showinfo("Message", "No Item Selected", parent=self.master)
        r = self.mlb21.get(i)
        self.purid = r[0]
        ans = askokcancel("Message", "Sure You Want To Delete %s ?" % (self.purid), parent=self.master)
        if ans == True:
            self.db.deletepurchase(self.purid)
            return showinfo("Message", "%s Has Been Successfully Deleted" % (self.purid),
                            parent=self.master), self.Add2Mlb21()
        return False

    def notepage2(self, note):
        self.purid = None
        app1 = Frame(note)
        app1.grid(row=0, column=0)
        for i in range(3):
            app1.rowconfigure(i, weight=1)
        for i in range(3):
            app1.columnconfigure(i, weight=1)
        app1.rowconfigure(0, weight=1)
        note.add(app1, text=' Purchase ')
        Label(app1, text="Purchase Records", foreground="#3496ff", font=('Berlin Sans FB Demi', 25)).grid(row=0,
                                                                                                          column=0,
                                                                                                          columnspan=1,
                                                                                                          sticky=sty,
                                                                                                          pady=9)
        self.btn21 = Button(app1, text="Edit Purchase Records", command=lambda: self.purchaseedit(None))
        self.btn21.grid(row=0, column=1, sticky=sty, pady=20)
        self.btn22 = Button(app1, text="Delete Purchase Records", command=lambda: self.deletepurchase())
        self.btn22.grid(row=0, column=2, sticky=sty, pady=20, padx=10)
        self.mlb21 = MultiListbox(app1, (
            ("Purchase ID", 25), ("Purchase Date", 35), ("Cost Price", 25), ("Selling Price", 25), ("Qty", 10),
            ("Expected profit", 25)))
        self.mlb21.grid(row=1, column=0, columnspan=3, sticky=sty)
        self.mlb21.tree.bind('<Double-Button-1>', self.purchaseedit)
        lf = Frame(app1)
        lf.grid(row=2, column=0, sticky=sty)
        Label(lf, text="Total Profit Estimated  - ").grid(row=1, column=0, sticky=sty, pady=8, padx=7)
        Label(lf, text="Total Capital Invested  - ").grid(row=0, column=0, sticky=sty, pady=8, padx=7)
        Label(lf, text="Total Item Brought  - ").grid(row=2, column=0, sticky=sty, pady=8, padx=7)
        self.ib = Label(lf, text="0")
        self.ib.grid(row=2, column=1, sticky=sty, padx=2)
        self.ci = Label(lf, text="0")
        self.ci.grid(row=0, column=1, sticky=sty, padx=2)
        self.te = Label(lf, text="0")
        self.te.grid(row=1, column=1, sticky=sty, padx=2)
        self.Add2Mlb21()

    def Add2Mlb22(self):
        self.mlb22.delete(0, END)
        gp = 0
        pg = 0
        tis = 0
        ins = self.mlb22.insert
        if self.modify == True:
            row = self.db.sqldb.execute(""" SELECT selling_id,invoice_date,cost,sold_price,QTY FROM (SELECT * FROM sells JOIN invoices USING (invoice_id) )
                                            JOIN costs USING (cost_id) JOIN products USING (product_id) WHERE product_id = "%s" """ % (
                self.tup[0])).fetchall()
            for i in row:
                i = list(i)
                date = i[1]
                cost = i[2]
                price = i[3]
                qty = i[4]
                profit = round(price - cost, 2)
                pg += (profit * qty)
                gp += price * qty
                tis += qty
                i.append(profit)
                ins(END, i)
        self.gp.configure(text=str(gp))
        self.pg.configure(text=str(pg))
        self.tis.configure(text=str(tis))

    def sellsedit(self, event):
        i = self.mlb22.Select_index
        if i == None:
            return showinfo("Message", "No Item Selected", parent=self.master)
        r = self.mlb22.get(i)
        self.selid = r[0]
        root13 = Toplevel()
        root13.title("Sales Edit")
        root13.grid()
        for i in range(8):
            root13.rowconfigure(i, weight=1)
        for i in range(2):
            root13.columnconfigure(i, weight=1)
        lf = root13
        self.salegui = root13
        color = 'gray98'
        root13['background'] = color
        Label(lf, text="Selling ID : %s" % (self.selid), foreground="#3496ff", font=('Berlin Sans FB Demi', 18)).grid(
            row=0, column=0, columnspan=2, sticky=sty, pady=8, padx=7)

        r = self.db.sqldb.execute(""" SELECT invoice_date,invoice_no,QTY,cost,price,sold_price FROM (SELECT * FROM sells JOIN invoices USING (invoice_id) )
                                            JOIN costs USING (cost_id) JOIN products USING (product_id) WHERE selling_id = "%s" """ % (
            self.selid)).fetchone()
        Label(lf, text="Selling Date", width=15).grid(row=1, column=0, sticky=sty, pady=8, padx=2)
        Label(lf, text="Invoice No").grid(row=2, column=0, sticky=sty, pady=8, padx=7)
        Label(lf, text="Quantity").grid(row=3, column=0, sticky=sty, pady=8, padx=7)
        Label(lf, text="Cost").grid(row=4, column=0, sticky=sty, pady=8, padx=7)
        Label(lf, text="Selling Price").grid(row=5, column=0, sticky=sty, pady=8, padx=7)
        Label(lf, text="Sold Price").grid(row=6, column=0, sticky=sty, pady=8, padx=7)
        self.seldate = CalendarButton(lf)
        self.seldate.grid(row=1, column=1, sticky=sty, pady=8, padx=7)
        try:
            self.seldate.insert(r[0])
        except:
            self.seldate.insert(self.seldate.getTimeStamp())
        self.selinvno = Entry(lf, width=40)
        self.selinvno.grid(row=2, column=1, sticky=sty, pady=8, padx=7)
        self.selinvno.delete(0, END)
        self.selinvno.insert(0, r[1])
        self.selinvno['state'] = "readonly"

        self.selqty = Entry(lf)
        self.selqty.grid(row=3, column=1, sticky=sty, pady=8, padx=7)
        self.selqty.delete(0, END)
        self.selqty.insert(0, r[2])

        self.selcost = Entry(lf)
        self.selcost.grid(row=4, column=1, sticky=sty, pady=8, padx=7)
        self.selcost.delete(0, END)
        self.selcost.insert(0, r[3])

        self.selprice = Entry(lf)
        self.selprice.grid(row=5, column=1, sticky=sty, pady=8, padx=7)
        self.selprice.delete(0, END)
        self.selprice.insert(0, r[4])

        self.selsold = Entry(lf)
        self.selsold.grid(row=6, column=1, sticky=sty, pady=8, padx=7)
        self.selsold.delete(0, END)
        self.selsold.insert(0, r[5])

        Button(lf, text="Save", command=lambda: self.salesave()).grid(row=7, column=1, sticky=sty, pady=8, padx=7)
        root13.wait_window()
        return 1

    def salesave(self):
        PID = self.tup[0]
        try:
            cost = float(Filter(self.selcost.get()))
            price = float(Filter(self.selprice.get()))
            sold = float(Filter(self.selsold.get()))
            qty = float(Filter(self.selqty.get()))
            invno = float(Filter(self.selinvno.get()))
            date = Filter(self.seldate.get())
        except:
            return showinfo(title="ERROR", message='Costs,Price,Selling,Price,Invoice No And Qty must be numbers',
                            parent=self.master)
        costid = self.db.sqldb.getcostID(PID, cost, price)
        if costid == None:
            costid = self.db.sqldb.addnewcost(PID, cost, price)
        invid = self.db.sqldb.getinvoiceID(invno)
        if invid == None:
            return showinfo(title="ERROR", message='Invoice In That Number Dsn\'t Exsist', parent=self.master)
        print (self.selid, sold, qty, costid)
        self.db.editsells(self.selid, sold, qty, costid)
        self.salegui.destroy()
        self.Add2Mlb22()
        return showinfo(title="Successful", message='Changes Saved', parent=self.master)

    def deletesells(self):
        i = self.mlb22.Select_index
        if i == None:
            return showinfo("Message", "No Item Selected", parent=self.master)
        r = self.mlb22.get(i)
        self.selid = r[0]
        ans = askokcancel("Message", "Sure You Want To Delete %s ?" % (self.selid), parent=self.master)
        if ans == True:
            self.db.deletesells(self.selid)
            return showinfo("Message", "%s Has Been Successfully Deleted" % (self.selid),
                            parent=self.master), self.Add2Mlb22()
        return False

    def notepage3(self, note):
        app2 = Frame(note)
        app2.grid(row=0, column=0)
        for i in range(3):
            app2.rowconfigure(i, weight=1)
        for i in range(3):
            app2.columnconfigure(i, weight=1)
        note.add(app2, text=' Sales ')
        Label(app2, text="Sales Records", foreground="#3496ff", font=('Berlin Sans FB Demi', 25)).grid(row=0, column=0,
                                                                                                       columnspan=1,
                                                                                                       sticky=sty,
                                                                                                       pady=9)
        self.btn31 = Button(app2, text="Edit Selling Records", command=lambda: self.sellsedit(None))
        self.btn31.grid(row=0, column=1, sticky=sty, pady=20)
        self.btn32 = Button(app2, text="Delete Selling Records", command=lambda: self.deletesells())
        self.btn32.grid(row=0, column=2, sticky=sty, pady=20, padx=10)

        self.mlb22 = MultiListbox(app2, (
            ("Selling ID", 25), ("Sold Date", 35), ("Cost Price", 25), ("Sold Price", 25), ("Quantity", 15),
            ("Profit", 25)))
        self.mlb22.grid(row=1, column=0, columnspan=3, sticky=sty)
        self.mlb22.tree.bind('<Double-Button-1>', self.sellsedit)
        lf = Frame(app2)
        lf.grid(row=2, column=0, sticky=sty)
        Label(lf, text="Total Gain From Product  - ").grid(row=0, column=0, sticky=sty, pady=8, padx=7)
        self.gp = Label(lf, text="0")
        self.gp.grid(row=0, column=1, sticky=sty, padx=2)
        Label(lf, text="Total Profit  - ").grid(row=1, column=0, sticky=sty, pady=8, padx=7)
        self.pg = Label(lf, text="0")
        self.pg.grid(row=1, column=1, sticky=sty, padx=2)
        Label(lf, text="Total Item Sold  - ").grid(row=2, column=0, sticky=sty, pady=8, padx=7)
        self.tis = Label(lf, text="0")
        self.tis.grid(row=2, column=1, sticky=sty, padx=2)
        self.Add2Mlb22()
コード例 #10
0
    def Add_Invoice(self, edit=False):
        tup = []
        cor = 'white'
        fg = 'black'
        title = 'Add Invoice'
        heading = "New Invoice"
        if edit == True:
            title = "Modify Invoice"
            index = self.mlb1.Select_index
            if index == None or index > self.mlb1.size():
                return showinfo('Select Error',
                                'Noting Is Selected',
                                parent=self.master)
            tup = self.mlb1.get(index)
            heading = "Invoice ID : %s " % (tup[0])

        def productsearch():
            inp = Filter(entry7.get())
            l = self.db.searchproduct(inp.title())
            entry7["value"] = l
            return 1

        def pAssdd():
            name = Filter(entry7.get()).title()
            amount = Filter(entry4.get())
            qty = Filter(entry8.get())
            PID = self.db.sqldb.getproductID(name)
            if PID == None:
                return showinfo("Error",
                                "No Product Name %s is in Product List" %
                                (name),
                                parent=self.app)
            try:
                amount = float(amount)
                qty = float(qty)
            except (ValueError):
                return showinfo("Error",
                                "Amount,Qty Should be in Numbers",
                                parent=self.app)
            price = self.db.sqldb.getcell("costs", "product_id", "price", PID)
            if price == None:
                return showinfo("Error",
                                "No Purchse has been made on %s " % (name),
                                parent=self.app)
            costid = self.db.getanycostid(PID, price)
            boo = False
            for i in xrange(lb.size()):
                r = lb.get(i)
                if costid == r[3]:
                    newqty = float(r[1]) + float(qty)
                    lb.setvalue(i, "Qty", newqty)
                    boo = True
            amount += float(price) * qty
            if boo == False:
                lb.insert(END, (name, qty, price, costid))
            entry7.delete(0, END)
            entry4.delete(0, END)
            entry4.insert(END, str(round(amount, 2)))
            return 1

        def pDssdd():
            index = lb.Select_index
            if index == None or index > lb.size():
                return 0
            tmtup = lb.get(index)
            amount = float(Filter(entry4.get()))
            amount -= float(tmtup[2]) * float(tmtup[1])
            entry4.delete(0, END)
            entry4.insert(END, str(round(amount, 2)))
            lb.delete(index)
            return 1

        self.app = Toplevel(self.master)
        self.app.title(title)
        self.app['bg'] = cor
        Label(self.app,
              text=heading,
              font=('Berlin Sans FB Demi', 21),
              foreground="#3496ff").grid(row=0,
                                         column=0,
                                         sticky=N + S + E + W,
                                         padx=10,
                                         pady=5)
        self.t = Frame(self.app)
        self.t.grid(row=1, column=0, sticky=N + S + E + W)
        Label(self.t, text="Invoice No", background=cor,
              foreground=fg).grid(row=0,
                                  column=0,
                                  sticky=N + W + S + E,
                                  padx=10,
                                  pady=10)
        entry0 = Spinbox(self.t, from_=0, to=9999)
        entry0.grid(row=0, column=1, sticky=N + W + S + E, padx=10, pady=10)

        Label(self.t, text="Invoice Date", background=cor,
              foreground=fg).grid(row=1,
                                  column=0,
                                  sticky=N + W + S + E,
                                  padx=10,
                                  pady=10)
        cb0 = CalendarButton(self.t)
        cb0.grid(row=1, column=1, sticky=N + W + S + E, padx=10, pady=10)
        Label(self.t, text="Customer Name", background=cor,
              foreground=fg).grid(row=2,
                                  column=0,
                                  sticky=N + W + S + E,
                                  padx=10,
                                  pady=10)
        drop = map(
            lambda x: x[0],
            self.db.sqldb.execute(
                """ SELECT customer_name FROM customers """).fetchall())

        entry1 = Combobox(self.t, width=30, value=drop)
        entry1.grid(row=2, column=1, sticky=N + W + S + E, padx=10, pady=10)
        Label(self.t,
              text=" Customer Address  ",
              background=cor,
              foreground=fg).grid(row=3,
                                  column=0,
                                  sticky=N + W + E,
                                  padx=10,
                                  pady=10)
        entry2 = Text(self.t,
                      width=5,
                      height=5,
                      wrap=WORD,
                      borderwidth=2,
                      relief=GROOVE)
        entry2.grid(row=3, column=1, sticky=N + W + S + E, padx=10, pady=10)
        Label(self.t, text=" Customer Phone", background=cor,
              foreground=fg).grid(row=4,
                                  column=0,
                                  sticky=N + W + S + E,
                                  padx=10,
                                  pady=10)
        entry3 = Entry(self.t, width=30)
        entry3.grid(row=4, column=1, sticky=N + W + S + E, padx=10, pady=10)
        btn = Button(self.t,
                     text="Save Invoice",
                     command=lambda: self.Ainv(edit, tup))
        btn.grid(row=5, column=1, sticky=N + W + S + E, padx=10, pady=10)
        Label(self.t, text="Amount", background=cor,
              foreground=fg).grid(row=0,
                                  column=2,
                                  sticky=N + W + S + E,
                                  padx=10,
                                  pady=10)
        entry4 = Entry(self.t, width=30)
        entry4.grid(row=0, column=3, sticky=N + W + S + E, padx=10, pady=10)
        Label(self.t, text="Paid", background=cor,
              foreground=fg).grid(row=1,
                                  column=2,
                                  sticky=N + W + S + E,
                                  padx=10,
                                  pady=10)
        entry5 = Entry(self.t, width=30)
        entry5.grid(row=1, column=3, sticky=N + W + S + E, padx=10, pady=10)
        Label(self.t, text="Discount", background=cor,
              foreground=fg).grid(row=2,
                                  column=2,
                                  sticky=N + W + S + E,
                                  padx=10,
                                  pady=10)
        drop = map(
            lambda x: x[0],
            self.db.sqldb.execute(
                """ SELECT product_name FROM products ORDER BY product_name """
            ).fetchall())

        entry6 = Entry(self.t, width=30)
        entry6.grid(row=2, column=3, sticky=N + W + S + E, padx=10, pady=10)
        frm = Frame(self.t)
        frm.grid(row=3, column=2, sticky=N + W + E + S, padx=10, pady=10)
        btnA1 = Button(frm, text=">>", command=lambda: pAssdd())
        btnA1.grid(row=0, column=0)
        btnA2 = Button(frm, text="<<", command=lambda: pDssdd())
        btnA2.grid(row=1, column=0)
        lb = MultiListbox(self.t, [("Product Name", 35), ("Qty", 15),
                                   ("Unit Price", 23), ("Cost ID", 30)], 5)
        lb.firstcolumn("", width=0)
        lb.grid(row=3, column=3, sticky=N + W + S + E, padx=10, pady=10)

        Label(self.t, text="Products", background=cor,
              foreground=fg).grid(row=4,
                                  column=2,
                                  sticky=N + W + S + E,
                                  padx=10,
                                  pady=10)

        tmpff = Frame(self.t)
        tmpff.grid(row=4, column=3, sticky=N + W + S + E, padx=0, pady=0)
        tmpff.rowconfigure(0, weight=1)
        tmpff.columnconfigure(0, weight=5)
        tmpff.columnconfigure(2, weight=1)

        entry7 = Combobox(tmpff,
                          width=30,
                          value=drop,
                          postcommand=lambda: productsearch())
        entry7.grid(row=0, column=0, sticky=N + W + S + E, padx=10, pady=10)
        Label(tmpff, text="QTY", background=cor,
              foreground=fg).grid(row=0,
                                  column=1,
                                  sticky=N + W + S + E,
                                  padx=10,
                                  pady=10)
        entry8 = Entry(tmpff, width=10)
        entry8.grid(row=0, column=2, sticky=N + W + S + E, padx=10, pady=10)

        def autofill(event):
            st = Filter(entry1.get())
            l = self.db.sqldb.execute(
                """SELECT customer_address,phone_no FROM customers JOIN contacts USING (customer_id)
                 WHERE customer_name =  "%s" """ % (st)).fetchone()
            if l == None:
                return None
            add = l[0]
            phn = l[1]
            entry2.delete(0.0, END)
            entry2.insert(0.0, add)
            entry3.delete(0, END)
            entry3.insert(0, phn)

        def adddis(event):
            amt = Filter(entry4.get())
            paid = Filter(entry5.get())
            try:
                amt = float(amt)
                paid = float(paid)
            except (ValueError):
                return None
            dis = amt - paid
            entry6.delete(0, END)
            entry6.insert(0, str(dis))
            return None

        entry1.bind('<<ComboboxSelected>>', autofill)
        entry4.delete(0, END)
        entry4.insert(0, str(0))
        entry5.delete(0, END)
        entry5.insert(0, str(0))
        entry6.delete(0, END)
        entry6.insert(0, str(0))
        entry7.bind(
            '<<ComboboxSelected>>', lambda event:
            (entry8.delete(0, END), entry8.insert(0, 1.0)))
        entry5.bind('<Any-KeyRelease>', adddis)
        if edit == True:
            entry0.delete(0, END)
            entry0.insert(0, tup[1])
            entry0['state'] = "readonly"
            try:
                cb0.insert(tup[2])
            except:
                cb0.insert(cb0.getTimeStamp())
            entry1.delete(0, END)
            entry1.insert(0, tup[3])
            autofill(1)
            amount = 0.0
            paid = self.db.sqldb.getcell("invoices", "invoice_id", "paid",
                                         tup[0])
            row = self.db.sqldb.execute(
                """SELECT product_name,QTY,price,cost_id FROM sells JOIN costs USING (cost_id) JOIN products USING(product_id)
                 WHERE invoice_id =  "%s" """ % (tup[0])).fetchall()
            for i in row:
                amount += i[2]
                lb.insert(END, i)
            discount = float(amount) - float(paid)
            entry4.delete(0, END)
            entry4.insert(0, str(amount))
            entry5.delete(0, END)
            entry5.insert(0, str(paid))
            entry6.delete(0, END)
            entry6.insert(0, str(discount))
        self.entry0 = entry0
        self.entry1 = entry1
        self.entry2 = entry2
        self.entry3 = entry3
        self.entry4 = entry4
        self.entry5 = entry5
        self.entry6 = entry6
        self.entry7 = entry7
        self.entry8 = entry8
        self.cb0 = cb0
        self.lb = lb
        self.t.mainloop()
        return 1
コード例 #11
0
class ADDInvoice():
    def __init__(self, master, db):
        self.value = []
        self.db = db
        self.master = master
        self.f = Frame(master)
        self.f.grid(row=0, column=0, sticky=N + W + S + E)
        self.f.columnconfigure(0, weight=1)
        self.f.rowconfigure(1, weight=1)
        Label(self.f,
              text="Invoice List",
              font=('Berlin Sans FB Demi', 21),
              foreground="#3496ff").grid(row=0,
                                         column=0,
                                         sticky=N + S + E + W,
                                         columnspan=2,
                                         padx=10,
                                         pady=5)
        self.mlb1 = MultiListbox(self.f,
                                 (("Invoice ID", 40), ('Invoice No', 17),
                                  ('Invoice Date', 40),
                                  ('Customer Attached', 40)),
                                 height=15)
        self.mlb1.grid(row=1, column=0, columnspan=4, sticky=N + W + S + E)
        self.Del = Button(self.f, text="Delete", command=lambda: self.Delete())
        self.Del.grid(row=2, column=3)
        self.Add = Button(self.f,
                          text="ADD",
                          command=lambda: self.Add_Invoice())
        self.Add.grid(row=2, column=1)
        self.Edit = Button(self.f,
                           text="Edit",
                           command=lambda: self.Add_Invoice(edit=True))
        self.Edit.grid(row=2, column=2)
        self.Insert()

    def Delete(self):
        index = self.mlb1.Select_index
        if index == None or index > self.mlb1.size():
            return showinfo('Select Error',
                            'Noting Is Selected',
                            parent=self.master)
        tup = self.mlb1.get(index)
        s = askokcancel('Confirm',
                        'Are You Sure You Want To Delete Invoice Number %s ?' %
                        tup[0],
                        parent=self.master)
        if s == True:
            self.db.deleteinvoice(tup[0])
        self.Refresh()
        return showinfo("Info",
                        "Invoice delete successfully",
                        parent=self.master)

    def Insert(self):
        lists = self.db.sqldb.execute(
            """ SELECT invoice_id,invoice_no,invoice_date,customer_name FROM invoices JOIN customers USING (customer_id)
                                            ORDER BY invoice_date """
        ).fetchall()
        self.mlb1.delete(0, END)
        for i in lists:
            self.mlb1.insert(END, i)
        return 1

    def Add_Invoice(self, edit=False):
        tup = []
        cor = 'white'
        fg = 'black'
        title = 'Add Invoice'
        heading = "New Invoice"
        if edit == True:
            title = "Modify Invoice"
            index = self.mlb1.Select_index
            if index == None or index > self.mlb1.size():
                return showinfo('Select Error',
                                'Noting Is Selected',
                                parent=self.master)
            tup = self.mlb1.get(index)
            heading = "Invoice ID : %s " % (tup[0])

        def productsearch():
            inp = Filter(entry7.get())
            l = self.db.searchproduct(inp.title())
            entry7["value"] = l
            return 1

        def pAssdd():
            name = Filter(entry7.get()).title()
            amount = Filter(entry4.get())
            qty = Filter(entry8.get())
            PID = self.db.sqldb.getproductID(name)
            if PID == None:
                return showinfo("Error",
                                "No Product Name %s is in Product List" %
                                (name),
                                parent=self.app)
            try:
                amount = float(amount)
                qty = float(qty)
            except (ValueError):
                return showinfo("Error",
                                "Amount,Qty Should be in Numbers",
                                parent=self.app)
            price = self.db.sqldb.getcell("costs", "product_id", "price", PID)
            if price == None:
                return showinfo("Error",
                                "No Purchse has been made on %s " % (name),
                                parent=self.app)
            costid = self.db.getanycostid(PID, price)
            boo = False
            for i in xrange(lb.size()):
                r = lb.get(i)
                if costid == r[3]:
                    newqty = float(r[1]) + float(qty)
                    lb.setvalue(i, "Qty", newqty)
                    boo = True
            amount += float(price) * qty
            if boo == False:
                lb.insert(END, (name, qty, price, costid))
            entry7.delete(0, END)
            entry4.delete(0, END)
            entry4.insert(END, str(round(amount, 2)))
            return 1

        def pDssdd():
            index = lb.Select_index
            if index == None or index > lb.size():
                return 0
            tmtup = lb.get(index)
            amount = float(Filter(entry4.get()))
            amount -= float(tmtup[2]) * float(tmtup[1])
            entry4.delete(0, END)
            entry4.insert(END, str(round(amount, 2)))
            lb.delete(index)
            return 1

        self.app = Toplevel(self.master)
        self.app.title(title)
        self.app['bg'] = cor
        Label(self.app,
              text=heading,
              font=('Berlin Sans FB Demi', 21),
              foreground="#3496ff").grid(row=0,
                                         column=0,
                                         sticky=N + S + E + W,
                                         padx=10,
                                         pady=5)
        self.t = Frame(self.app)
        self.t.grid(row=1, column=0, sticky=N + S + E + W)
        Label(self.t, text="Invoice No", background=cor,
              foreground=fg).grid(row=0,
                                  column=0,
                                  sticky=N + W + S + E,
                                  padx=10,
                                  pady=10)
        entry0 = Spinbox(self.t, from_=0, to=9999)
        entry0.grid(row=0, column=1, sticky=N + W + S + E, padx=10, pady=10)

        Label(self.t, text="Invoice Date", background=cor,
              foreground=fg).grid(row=1,
                                  column=0,
                                  sticky=N + W + S + E,
                                  padx=10,
                                  pady=10)
        cb0 = CalendarButton(self.t)
        cb0.grid(row=1, column=1, sticky=N + W + S + E, padx=10, pady=10)
        Label(self.t, text="Customer Name", background=cor,
              foreground=fg).grid(row=2,
                                  column=0,
                                  sticky=N + W + S + E,
                                  padx=10,
                                  pady=10)
        drop = map(
            lambda x: x[0],
            self.db.sqldb.execute(
                """ SELECT customer_name FROM customers """).fetchall())

        entry1 = Combobox(self.t, width=30, value=drop)
        entry1.grid(row=2, column=1, sticky=N + W + S + E, padx=10, pady=10)
        Label(self.t,
              text=" Customer Address  ",
              background=cor,
              foreground=fg).grid(row=3,
                                  column=0,
                                  sticky=N + W + E,
                                  padx=10,
                                  pady=10)
        entry2 = Text(self.t,
                      width=5,
                      height=5,
                      wrap=WORD,
                      borderwidth=2,
                      relief=GROOVE)
        entry2.grid(row=3, column=1, sticky=N + W + S + E, padx=10, pady=10)
        Label(self.t, text=" Customer Phone", background=cor,
              foreground=fg).grid(row=4,
                                  column=0,
                                  sticky=N + W + S + E,
                                  padx=10,
                                  pady=10)
        entry3 = Entry(self.t, width=30)
        entry3.grid(row=4, column=1, sticky=N + W + S + E, padx=10, pady=10)
        btn = Button(self.t,
                     text="Save Invoice",
                     command=lambda: self.Ainv(edit, tup))
        btn.grid(row=5, column=1, sticky=N + W + S + E, padx=10, pady=10)
        Label(self.t, text="Amount", background=cor,
              foreground=fg).grid(row=0,
                                  column=2,
                                  sticky=N + W + S + E,
                                  padx=10,
                                  pady=10)
        entry4 = Entry(self.t, width=30)
        entry4.grid(row=0, column=3, sticky=N + W + S + E, padx=10, pady=10)
        Label(self.t, text="Paid", background=cor,
              foreground=fg).grid(row=1,
                                  column=2,
                                  sticky=N + W + S + E,
                                  padx=10,
                                  pady=10)
        entry5 = Entry(self.t, width=30)
        entry5.grid(row=1, column=3, sticky=N + W + S + E, padx=10, pady=10)
        Label(self.t, text="Discount", background=cor,
              foreground=fg).grid(row=2,
                                  column=2,
                                  sticky=N + W + S + E,
                                  padx=10,
                                  pady=10)
        drop = map(
            lambda x: x[0],
            self.db.sqldb.execute(
                """ SELECT product_name FROM products ORDER BY product_name """
            ).fetchall())

        entry6 = Entry(self.t, width=30)
        entry6.grid(row=2, column=3, sticky=N + W + S + E, padx=10, pady=10)
        frm = Frame(self.t)
        frm.grid(row=3, column=2, sticky=N + W + E + S, padx=10, pady=10)
        btnA1 = Button(frm, text=">>", command=lambda: pAssdd())
        btnA1.grid(row=0, column=0)
        btnA2 = Button(frm, text="<<", command=lambda: pDssdd())
        btnA2.grid(row=1, column=0)
        lb = MultiListbox(self.t, [("Product Name", 35), ("Qty", 15),
                                   ("Unit Price", 23), ("Cost ID", 30)], 5)
        lb.firstcolumn("", width=0)
        lb.grid(row=3, column=3, sticky=N + W + S + E, padx=10, pady=10)

        Label(self.t, text="Products", background=cor,
              foreground=fg).grid(row=4,
                                  column=2,
                                  sticky=N + W + S + E,
                                  padx=10,
                                  pady=10)

        tmpff = Frame(self.t)
        tmpff.grid(row=4, column=3, sticky=N + W + S + E, padx=0, pady=0)
        tmpff.rowconfigure(0, weight=1)
        tmpff.columnconfigure(0, weight=5)
        tmpff.columnconfigure(2, weight=1)

        entry7 = Combobox(tmpff,
                          width=30,
                          value=drop,
                          postcommand=lambda: productsearch())
        entry7.grid(row=0, column=0, sticky=N + W + S + E, padx=10, pady=10)
        Label(tmpff, text="QTY", background=cor,
              foreground=fg).grid(row=0,
                                  column=1,
                                  sticky=N + W + S + E,
                                  padx=10,
                                  pady=10)
        entry8 = Entry(tmpff, width=10)
        entry8.grid(row=0, column=2, sticky=N + W + S + E, padx=10, pady=10)

        def autofill(event):
            st = Filter(entry1.get())
            l = self.db.sqldb.execute(
                """SELECT customer_address,phone_no FROM customers JOIN contacts USING (customer_id)
                 WHERE customer_name =  "%s" """ % (st)).fetchone()
            if l == None:
                return None
            add = l[0]
            phn = l[1]
            entry2.delete(0.0, END)
            entry2.insert(0.0, add)
            entry3.delete(0, END)
            entry3.insert(0, phn)

        def adddis(event):
            amt = Filter(entry4.get())
            paid = Filter(entry5.get())
            try:
                amt = float(amt)
                paid = float(paid)
            except (ValueError):
                return None
            dis = amt - paid
            entry6.delete(0, END)
            entry6.insert(0, str(dis))
            return None

        entry1.bind('<<ComboboxSelected>>', autofill)
        entry4.delete(0, END)
        entry4.insert(0, str(0))
        entry5.delete(0, END)
        entry5.insert(0, str(0))
        entry6.delete(0, END)
        entry6.insert(0, str(0))
        entry7.bind(
            '<<ComboboxSelected>>', lambda event:
            (entry8.delete(0, END), entry8.insert(0, 1.0)))
        entry5.bind('<Any-KeyRelease>', adddis)
        if edit == True:
            entry0.delete(0, END)
            entry0.insert(0, tup[1])
            entry0['state'] = "readonly"
            try:
                cb0.insert(tup[2])
            except:
                cb0.insert(cb0.getTimeStamp())
            entry1.delete(0, END)
            entry1.insert(0, tup[3])
            autofill(1)
            amount = 0.0
            paid = self.db.sqldb.getcell("invoices", "invoice_id", "paid",
                                         tup[0])
            row = self.db.sqldb.execute(
                """SELECT product_name,QTY,price,cost_id FROM sells JOIN costs USING (cost_id) JOIN products USING(product_id)
                 WHERE invoice_id =  "%s" """ % (tup[0])).fetchall()
            for i in row:
                amount += i[2]
                lb.insert(END, i)
            discount = float(amount) - float(paid)
            entry4.delete(0, END)
            entry4.insert(0, str(amount))
            entry5.delete(0, END)
            entry5.insert(0, str(paid))
            entry6.delete(0, END)
            entry6.insert(0, str(discount))
        self.entry0 = entry0
        self.entry1 = entry1
        self.entry2 = entry2
        self.entry3 = entry3
        self.entry4 = entry4
        self.entry5 = entry5
        self.entry6 = entry6
        self.entry7 = entry7
        self.entry8 = entry8
        self.cb0 = cb0
        self.lb = lb
        self.t.mainloop()
        return 1

    def Ainv(self, edit, tup):
        """tup = [invoice number,invoice date,customer name]
        """
        inv_no = Filter(self.entry0.get())
        if edit == True:
            invid = tup[0]
        else:
            invid = self.db.sqldb.getinvoiceID(inv_no)
        if invid != None and edit == False:
            return showinfo('Input Error',
                            'Invoice Number Already Exists',
                            parent=self.t)
        inv_date = self.cb0.get()
        if self.lb.size() == 0:
            return showinfo('Input Error',
                            'At Least One Product must be Added',
                            parent=self.t)
        Cname = Filter(self.entry1.get()).title()
        if len(Cname) == 0:
            return showinfo('Input Error',
                            'Customer Name Should Be specified',
                            parent=self.t)
        Cadd = Filter(self.entry2.get(0.0, END)).title()
        Cphn = Filter(self.entry3.get()).title()
        try:
            amount = float(Filter(self.entry4.get()))
            paid = float(Filter(self.entry5.get()))
            discount = float(Filter(self.entry6.get()))
        except (ValueError):
            return showinfo('Input Error',
                            'Amount, Paid and Discount Have To Be numbers',
                            parent=self.t)
        ctmid = self.db.sqldb.getcustomerID(Cphn)
        if ctmid == None:
            ans = askokcancel(
                "New Customer",
                "The Customer %s is not in customer list!\nAdd It?",
                parent=self.t)
            if ans == False:
                return 0
            ctmid = self.db.addcustomer(Cname, Cadd, Cphn, "")
        else:
            dbcmname = self.db.sqldb.getcell("customers", "customer_id",
                                             "customer_name", ctmid)
            if dbcmname != Cname:
                showinfo('Input Error',
                         'Phone Number Already Registered in Another Name',
                         parent=self.t)
        if edit == True:
            self.db.editinvoice_withpaid(invid, ctmid, paid, inv_no, inv_date)
        else:
            invid = self.db.addinvoice(ctmid, inv_no, paid, inv_date)
        selids = self.db.getallsellID(invid)
        for i in selids:
            self.db.deletesells(i)
        tnoofproduct = 0
        for i in xrange(self.lb.size()):
            r = self.lb.get(i)
            tnoofproduct += float(tup[1])
        discountperproduct = discount / tnoofproduct
        for i in xrange(self.lb.size()):
            tup = self.lb.get(i)
            product_price = float(tup[2])
            product_qty = float(tup[1])
            costid = tup[3]
            selID = self.db.sqldb.getsellID(invid, costid)
            sold_price = product_price - discountperproduct
            self.db.addsells(costid, sold_price, invid, product_qty)
        self.lb.delete(0, END)
        self.app.destroy()
        return self.Refresh()

    def Refresh(self):
        self.Insert()
        return showinfo('Saved',
                        'All Changes Successfully Saved',
                        parent=self.f)
コード例 #12
0
    def notepage1(self, note, modify, tup):
        app = Frame(note)
        app.grid(row=0, column=0, sticky=sty)
        note.add(app, text='Customer')
        for i in range(20):
            app.rowconfigure(i, weight=1)
        for i in range(3):
            app.columnconfigure(i, weight=1)
        Label(app,
              text="Customer Detail",
              font=('Berlin Sans FB Demi', 21),
              foreground="#3496ff").grid(row=0,
                                         column=0,
                                         sticky=sty,
                                         columnspan=2,
                                         padx=10,
                                         pady=10)
        lbl = Label(app, text='Customer Name  ')
        lbl.grid(row=1, column=0, sticky=sty, padx=5, pady=5)

        self.entry5 = Entry(app, width=55)
        self.entry5.grid(row=1, column=1, sticky=sty, padx=5, pady=5)
        self.entry5.bind('<Any-KeyRelease>', self.update_name)

        lbl3 = Label(app, text="Email ")
        lbl3.grid(row=2, column=0, sticky=sty, padx=5, pady=5)
        self.entry3 = Entry(app, width=35)
        self.entry3.grid(row=2, column=1, sticky=sty, padx=5, pady=5)

        lbl1 = Label(app, text="Customer Address ", anchor=N)
        lbl1.grid(row=3, column=0, sticky=sty, padx=5, pady=5)
        self.text = Text(app, width=26, height=5, wrap=WORD, relief=FLAT)
        self.text.grid(row=3, column=1, sticky=sty, padx=5, pady=5)
        self.text.configure(highlightthickness=1, highlightbackground="Grey")

        tmpapp = Frame(app)
        tmpapp.grid(row=1, column=2, rowspan=4, sticky=sty, padx=0, pady=0)
        tmpapp.columnconfigure(0, weight=1)
        tmpapp.rowconfigure(0, weight=5)
        tmpapp.rowconfigure(1, weight=1)

        self.mlb2221 = MultiListbox(tmpapp, [("Phone Number", 30)], height=5)
        self.mlb2221.grid(row=0, column=0, sticky=sty, padx=5, pady=5)

        tmpapp = Frame(tmpapp)
        tmpapp.grid(row=1, column=0, sticky=sty, padx=0, pady=0)
        tmpapp.rowconfigure(0, weight=1)

        Button(tmpapp, text='Add',
               command=lambda: self.phoneedit(False)).grid(row=0,
                                                           column=0,
                                                           sticky=sty,
                                                           padx=5,
                                                           pady=5)
        Button(tmpapp, text='Edit',
               command=lambda: self.phoneedit(True)).grid(row=0,
                                                          column=1,
                                                          sticky=sty,
                                                          padx=5,
                                                          pady=5)
        Button(tmpapp, text='Delete',
               command=lambda: self.phonedelete()).grid(row=0,
                                                        column=2,
                                                        sticky=sty,
                                                        padx=5,
                                                        pady=5)

        tmpapp = Frame(app)
        tmpapp.grid(row=4, column=1, sticky=sty, padx=0, pady=0)
        tmpapp.columnconfigure(0, weight=1)
        tmpapp.columnconfigure(1, weight=1)
        tmpapp.rowconfigure(0, weight=1)

        btn = Button(tmpapp,
                     text='Save',
                     width=12,
                     command=lambda: self.Save(modify, tup))
        btn.grid(row=0, column=0, sticky=sty, padx=5, pady=5)
        copy = Button(tmpapp,
                      text='Save As Copy',
                      width=12,
                      command=lambda: self.Save(False, tup))
        copy.grid(row=0, column=1, sticky=sty, padx=5, pady=5)
        if modify == False:
            copy['state'] = DISABLED

        if modify == True:
            ctmid = self.tup[0]
            d = self.db.sqldb.execute(
                """ SELECT customer_name,customer_address,customer_email FROM customers WHERE customer_id = "%s" """
                % (ctmid)).fetchone()
            name = d[0]
            add = d[1]
            email = d[2]
            self.phnrefresh(ctmid)
            self.entry5.delete(0, END)
            self.entry5.insert(0, name)
            self.text.delete(0.0, END)
            self.text.insert(0.0, add)
            self.entry3.delete(0, END)
            self.entry3.insert(0, email)
コード例 #13
0
class NewCustomer(Frame):
    def __init__(self, master, modify, tup, db):
        Frame.__init__(self, master)
        self.master = master
        self.db = db
        self.modify = modify
        self.tup = tup
        bg = 'White'
        fg = "#3496ff"
        self.app = Frame(master)
        self.app.grid(row=0, column=0, sticky=sty)
        self.app.rowconfigure(1, weight=1)
        self.app.columnconfigure(0, weight=1)
        if modify == True:
            value = tup[1]
            self.ctmid = tup[0]
        else:
            value = "Customer Name"
            self.ctmid = None
        self.name = Label(self.app,
                          text=value,
                          font=('Arial Black', 26),
                          foreground=fg)
        self.name.grid(row=0, column=0, sticky=sty, pady=10)

        note = Notebook(self.app)
        note.grid(row=1, column=0, sticky=sty)
        note.rowconfigure(0, weight=1)
        note.columnconfigure(0, weight=1)
        self.notepage1(note, modify, tup)
        if modify == True:
            self.notepage2(note)

    def update_name(self, event):
        name = Filter(self.entry5.get()).title()
        if len(name) == 0:
            name = "Customer Name"
        self.name.configure(text=name)

    def editinvoice(self):
        i = self.mlb21.Select_index
        if i == None:
            return showinfo("Message", "No Item Selected", parent=self.master)
        piid = self.mlb21.trueparent(self.mlb21.Select_iid)
        i = self.mlb21.index(piid)
        r = self.mlb21.get(i)
        self.invid = r[0]
        root13 = Toplevel()
        root13.title("Invoice Edit")
        root13.grid()
        for i in range(5):
            root13.rowconfigure(i, weight=1)
        for i in range(2):
            root13.columnconfigure(i, weight=1)
        lf = root13
        self.invgui = root13
        color = 'gray98'
        root13['background'] = color
        Label(lf,
              text="Invoice ID : %s" % (self.invid),
              foreground="#3496ff",
              font=('Berlin Sans FB Demi', 18)).grid(row=0,
                                                     column=0,
                                                     columnspan=2,
                                                     sticky=sty,
                                                     pady=8,
                                                     padx=7)

        r = self.db.sqldb.execute(
            """ SELECT invoice_date,invoice_no,customer_name,phone_no FROM invoices
                JOIN customers USING (customer_id) JOIN contacts USING (customer_id) WHERE invoice_id = "%s" """
            % (self.invid)).fetchone()
        Label(lf, text="Invoice Date", width=20).grid(row=1,
                                                      column=0,
                                                      sticky=sty,
                                                      pady=8,
                                                      padx=7)
        Label(lf, text="Invoice No").grid(row=2,
                                          column=0,
                                          sticky=sty,
                                          pady=8,
                                          padx=7)
        Label(lf, text="Customer Name").grid(row=3,
                                             column=0,
                                             sticky=sty,
                                             pady=8,
                                             padx=7)
        Label(lf, text="Customer Phone").grid(row=4,
                                              column=0,
                                              sticky=sty,
                                              pady=8,
                                              padx=7)
        self.invdate = CalendarButton(lf)
        self.invdate.grid(row=1, column=1, sticky=sty, pady=8, padx=7)
        try:
            self.invdate.insert(r[0])
        except:
            self.invdate.insert(self.invdate.getTimeStamp())
        self.invno = Spinbox(lf, from_=0, to=9999)
        self.invno.grid(row=2, column=1, sticky=sty, pady=8, padx=7)
        self.invno.delete(0, END)
        self.invno.insert(0, r[1])

        self.cusname = Entry(lf, width=40)
        self.cusname.grid(row=3, column=1, sticky=sty, pady=8, padx=7)
        self.cusname.delete(0, END)
        self.cusname.insert(0, r[2])

        self.cusphn = Entry(lf)
        self.cusphn.grid(row=4, column=1, sticky=sty, pady=8, padx=7)
        self.cusphn.delete(0, END)
        self.cusphn.insert(0, r[3])

        Button(lf, text="Save",
               command=lambda: self.invoicesave()).grid(row=5,
                                                        column=1,
                                                        sticky=sty,
                                                        pady=8,
                                                        padx=7)
        root13.wait_window()
        return 1

    def invoicesave(self):
        try:
            no = float(Filter(self.invno.get()))
            phn = Filter(self.cusphn.get())
            date = Filter(self.invdate.get())
        except:
            return showinfo(title="ERROR",
                            message='Invoice Number must be numbers',
                            parent=self.master)
        ctmid = self.db.sqldb.getcustomerID(phn)
        if ctmid == None:
            return showinfo(title="ERROR",
                            message='Customer Not Found',
                            parent=self.master)
        self.db.editinvoice(self.invid, ctmid, no, date)
        self.invgui.destroy()
        self.mlb21load()
        return showinfo(title="Successful",
                        message='Changes Saved',
                        parent=self.master)

    def deleteinvoice(self):
        i = self.mlb21.Select_index
        if i == None:
            return showinfo("Message", "No Item Selected", parent=self.master)
        r = self.mlb21.get(i)
        self.invid = r[0]
        ans = askokcancel("Message",
                          "Sure You Want To Delete %s ?" % (self.invid),
                          parent=self.master)
        if ans == True:
            b = self.db.deleteinvoice(self.invid)
            if b == True:
                return showinfo("Message",
                                "%s Has Been Successfully Deleted" %
                                (self.invid),
                                parent=self.master), self.mlb21load()
            else:
                return showinfo("Message",
                                "%s Is Attached To Selling Records" %
                                (self.invid),
                                parent=self.master), self.mlb21load()
        return False

    def notepage2(self, note):
        self.invid = None
        app1 = Frame(note)
        app1.grid(row=0, column=0, sticky=sty)
        note.add(app1, text=' Invoices ')
        for i in range(5):
            app1.rowconfigure(i, weight=1)
        for i in range(3):
            app1.columnconfigure(i, weight=1)
        Label(app1,
              text="Invoice Attached",
              font=('Berlin Sans FB Demi', 21),
              foreground="#3496ff").grid(row=0,
                                         column=0,
                                         sticky=sty,
                                         padx=10,
                                         pady=10)
        self.mlb21 = MultiListbox(app1,
                                  (("Invoice ID", 30), ("Invoice Number", 25),
                                   ("Invoice Date", 35), ("Paid", 20)))
        self.mlb21.grid(row=1, column=0, columnspan=3, sticky=sty)
        Button(app1, text="Edit Invoice",
               command=lambda: self.editinvoice()).grid(row=0,
                                                        column=1,
                                                        sticky=sty,
                                                        pady=20)
        Button(app1,
               text="Delete Invoice",
               command=lambda: self.deleteinvoice()).grid(row=0,
                                                          column=2,
                                                          sticky=sty,
                                                          pady=20,
                                                          padx=5)
        self.lbl1 = Label(app1, text="Total Amount Earned - 0 ")
        self.lbl1.grid(row=2, column=0, sticky=sty, padx=5, pady=5)
        self.lbl2 = Label(app1, text="Total No of Product - 0 ")
        self.lbl2.grid(row=3, column=0, sticky=sty, padx=5, pady=5)
        self.lbl3 = Label(app1, text="Total Amount Due - 0 ")
        self.lbl3.grid(row=4, column=0, sticky=sty, padx=5, pady=5)
        if self.modify == True:
            self.mlb21load()
        return 1

    def mlb21load(self):
        self.mlb21.delete(0, END)
        ctmid = self.tup[0]
        invoices = self.db.sqldb.execute(
            """SELECT invoice_id,invoice_no,invoice_date,paid
                           FROM invoices WHERE customer_id = "%s" ORDER BY invoice_no """
            % (ctmid)).fetchall()
        tp = 0.0
        tpro = 0
        td = 0.0
        for i in invoices:
            invid = i[0]
            paid = i[3]
            tp = tp + float(paid)
            iid = self.mlb21.insert(END, i)
            tup1 = self.db.sqldb.execute(
                """ SELECT  product_name,cost,sold_price,QTY  FROM  (SELECT * FROM sells JOIN costs USING (cost_id) JOIN products USING (product_id) )
                    JOIN invoices USING (invoice_id) WHERE invoice_id = "%s" ORDER BY product_name """
                % (invid)).fetchall()
            self.mlb21.insert(
                END, ["Product Name", "Cost Price", "Selling Price", "Qty"],
                parent=iid,
                rowname="+",
                bg='grey90',
                fg='Blue',
                tag="l5")
            tpro += len(tup1)
            for g in xrange(len(tup1)):
                self.mlb21.insert(END,
                                  tup1[g],
                                  parent=iid,
                                  rowname=g,
                                  bg='white')
        self.lbl1["text"] = "Total Amount Earned - %d " % (tp)
        self.lbl2["text"] = "Total No of Product - %d " % (tpro)
        self.lbl3["text"] = "Total Amount Due - %d " % (td)
        return 0

    def phnrefresh(self, ctmid):
        self.mlb2221.delete(0, END)
        d = self.db.execute(
            """ SELECT phone_no FROM contacts WHERE customer_id = "%s" """ %
            (ctmid))
        for i in d:
            self.mlb2221.insert(END, i)
        return None

    def phoneedit(self, edit):
        tup = []
        if edit == True:
            index = self.mlb2221.Select_index
            if index == None or index > self.mlb2221.size():
                return showinfo('Select Error',
                                'Noting Is Selected',
                                parent=self.master)
            piid = self.mlb2221.trueparent(self.mlb2221.Select_iid)
            index = self.mlb2221.index(piid)
            tup = self.mlb2221.get(index)
        self.t = Toplevel(master=self.master)
        self.t.title('Add Contact Number')
        if edit == True:
            self.t.title('Edit Contact Number')
        self.t['bg'] = 'white'
        self.t.focus()
        Label(self.t, text="Contact Number", background='white').grid(row=1,
                                                                      column=0,
                                                                      padx=5,
                                                                      pady=5)
        self.e = Entry(self.t)
        self.e.grid(row=1, column=1, sticky=E + S + W + N, padx=5, pady=5)
        btn = Button(self.t,
                     text="Save Phone",
                     command=lambda: self.Savephone(edit, tup))
        btn.grid(row=2, column=1, sticky=E + S + W + N, padx=5, pady=5)
        if edit == True:
            Label(self.t, text="Phone ID : ",
                  background='white').grid(row=0, column=0, padx=5, pady=5)
            Label(self.t,
                  text=self.db.sqldb.getphoneID(tup[0]),
                  background='white').grid(row=0, column=1, padx=5, pady=5)
            self.e.delete(0, END)
            self.e.insert(0, tup[0])
        self.t.wait_window()
        return None

    def Savephone(self, edit, tup):
        phone = Filter(self.e.get())
        if self.db.sqldb.getphoneID(phone) is not None:
            return showinfo('Error',
                            'Phone Number Is Already Added.',
                            parent=self.t)
        # phnid = self.db.sqldb.getphoneID(phone)
        # ctmid = self.ctmid
        # if phnid is not None and edit == False:
        #     return showinfo('Type Error', 'Phone Number Is Already Listed', parent=self.t)
        # if not phone.isdigit():
        #     return showinfo('Type Error', 'Not a Valid Phone Number', parent=self.t)
        # if edit:
        #     pphn = self.db.sqldb.getphoneID(tup[0])
        #     if pphn is not None:
        #         self.db.editphone(pphn, phone, ctmid)
        #     else:
        #         return showinfo('Type Error', 'Phone Number Already Listed', parent=self.t)
        # else:
        #     if ctmid is None:
        #         return showinfo('Error', 'Add Phone Number After Adding Customer.', parent=self.t)
        #     self.db.addphone(phone, ctmid)
        if edit:
            index = self.mlb2221.Select_index
            if index is None or index > self.mlb2221.size():
                return showinfo('Select Error',
                                'Noting Is Selected',
                                parent=self.master)
            piid = self.mlb2221.trueparent(self.mlb2221.Select_iid)
            index = self.mlb2221.index(piid)
            self.mlb2221.setvalue(index, 0, phone)
        else:
            self.mlb2221.insert(END, phone)
        self.t.destroy()
        return None

    def phonedelete(self):
        index = self.mlb2221.Select_index
        if index is None or index > self.mlb2221.size():
            return showinfo('Select Error',
                            'Noting Is Selected',
                            parent=self.master)
        piid = self.mlb2221.trueparent(self.mlb2221.Select_iid)
        index = self.mlb2221.index(piid)
        tup = self.mlb2221.get(index)
        phnid = self.db.sqldb.getphoneID(tup[0])
        if phnid == None:
            self.mlb2221.delete(index)
            return None
        d = self.db.deletephone(phnid)
        if d:
            self.mlb2221.delete(index)
            return showinfo('Info',
                            'Phone Number Deleted Successfully',
                            parent=self.master)
        else:
            return showinfo(
                'Info',
                'Phone Number Cannot Be deleted attached with Customer',
                parent=self.master)
        return None

    def notepage1(self, note, modify, tup):
        app = Frame(note)
        app.grid(row=0, column=0, sticky=sty)
        note.add(app, text='Customer')
        for i in range(20):
            app.rowconfigure(i, weight=1)
        for i in range(3):
            app.columnconfigure(i, weight=1)
        Label(app,
              text="Customer Detail",
              font=('Berlin Sans FB Demi', 21),
              foreground="#3496ff").grid(row=0,
                                         column=0,
                                         sticky=sty,
                                         columnspan=2,
                                         padx=10,
                                         pady=10)
        lbl = Label(app, text='Customer Name  ')
        lbl.grid(row=1, column=0, sticky=sty, padx=5, pady=5)

        self.entry5 = Entry(app, width=55)
        self.entry5.grid(row=1, column=1, sticky=sty, padx=5, pady=5)
        self.entry5.bind('<Any-KeyRelease>', self.update_name)

        lbl3 = Label(app, text="Email ")
        lbl3.grid(row=2, column=0, sticky=sty, padx=5, pady=5)
        self.entry3 = Entry(app, width=35)
        self.entry3.grid(row=2, column=1, sticky=sty, padx=5, pady=5)

        lbl1 = Label(app, text="Customer Address ", anchor=N)
        lbl1.grid(row=3, column=0, sticky=sty, padx=5, pady=5)
        self.text = Text(app, width=26, height=5, wrap=WORD, relief=FLAT)
        self.text.grid(row=3, column=1, sticky=sty, padx=5, pady=5)
        self.text.configure(highlightthickness=1, highlightbackground="Grey")

        tmpapp = Frame(app)
        tmpapp.grid(row=1, column=2, rowspan=4, sticky=sty, padx=0, pady=0)
        tmpapp.columnconfigure(0, weight=1)
        tmpapp.rowconfigure(0, weight=5)
        tmpapp.rowconfigure(1, weight=1)

        self.mlb2221 = MultiListbox(tmpapp, [("Phone Number", 30)], height=5)
        self.mlb2221.grid(row=0, column=0, sticky=sty, padx=5, pady=5)

        tmpapp = Frame(tmpapp)
        tmpapp.grid(row=1, column=0, sticky=sty, padx=0, pady=0)
        tmpapp.rowconfigure(0, weight=1)

        Button(tmpapp, text='Add',
               command=lambda: self.phoneedit(False)).grid(row=0,
                                                           column=0,
                                                           sticky=sty,
                                                           padx=5,
                                                           pady=5)
        Button(tmpapp, text='Edit',
               command=lambda: self.phoneedit(True)).grid(row=0,
                                                          column=1,
                                                          sticky=sty,
                                                          padx=5,
                                                          pady=5)
        Button(tmpapp, text='Delete',
               command=lambda: self.phonedelete()).grid(row=0,
                                                        column=2,
                                                        sticky=sty,
                                                        padx=5,
                                                        pady=5)

        tmpapp = Frame(app)
        tmpapp.grid(row=4, column=1, sticky=sty, padx=0, pady=0)
        tmpapp.columnconfigure(0, weight=1)
        tmpapp.columnconfigure(1, weight=1)
        tmpapp.rowconfigure(0, weight=1)

        btn = Button(tmpapp,
                     text='Save',
                     width=12,
                     command=lambda: self.Save(modify, tup))
        btn.grid(row=0, column=0, sticky=sty, padx=5, pady=5)
        copy = Button(tmpapp,
                      text='Save As Copy',
                      width=12,
                      command=lambda: self.Save(False, tup))
        copy.grid(row=0, column=1, sticky=sty, padx=5, pady=5)
        if modify == False:
            copy['state'] = DISABLED

        if modify == True:
            ctmid = self.tup[0]
            d = self.db.sqldb.execute(
                """ SELECT customer_name,customer_address,customer_email FROM customers WHERE customer_id = "%s" """
                % (ctmid)).fetchone()
            name = d[0]
            add = d[1]
            email = d[2]
            self.phnrefresh(ctmid)
            self.entry5.delete(0, END)
            self.entry5.insert(0, name)
            self.text.delete(0.0, END)
            self.text.insert(0.0, add)
            self.entry3.delete(0, END)
            self.entry3.insert(0, email)

    def Save(self, modify, tup):
        """
           tup[0] = id no
           tup[1] = customer name
           tup[2] = phn no
           tup[3] = address
           tup[4] = email
        """

        name = Filter(self.entry5.get()).title()
        add = Filter(self.text.get(0.0, END)).title()
        email = Filter(self.entry3.get()).title()
        if len(name.split()) == 0:
            return showinfo(title="Error",
                            message='Customer Name Must Be Specified',
                            parent=self.master)
        ctmid = None
        if not modify:
            ctmid = self.db.addcustomer(name, address=add, email=email)
        else:
            ctmid = self.tup[0]
            ask = askokcancel(
                "Key Error",
                "Are You Sure You Want To Change The Customer Name From %s To %s ?"
                % (tup[1], name),
                parent=self.master)
            if not ask:
                return 1
            self.db.editcustomer(ctmid, name, add, email)
        if ctmid is not None:
            for i in xrange(self.mlb2221.size()):
                tup = self.mlb2221.get(i)
                phnid = self.db.sqldb.getphoneID(tup[0])
                if phnid is None:
                    self.db.addphone(tup[0], ctmid)
        self.master.destroy()
        return showinfo("ADDED", 'Saved Successfully')
コード例 #14
0
class Category():
    def __init__(self, master, db):
        self.value = []
        self.db = db
        self.master = master
        self.f = Frame(master)
        self.f.grid(row=0, column=0, sticky=N + W + S + E)
        self.f.columnconfigure(0, weight=1)
        self.f.rowconfigure(1, weight=1)
        Label(self.f,
              text="Category List",
              foreground="#3496ff",
              font=('Berlin Sans FB Demi', 20)).grid(row=0,
                                                     column=0,
                                                     sticky=N + S + E + W)
        self.mlb1 = MultiListbox(self.f,
                                 (('Category Name', 35), ('No of Product', 45),
                                  ('Category ID', 30)),
                                 height=20)
        self.mlb1.grid(row=1, column=0, columnspan=4, sticky=N + W + S + E)
        self.Del = Button(self.f, text="Delete", command=lambda: self.Delete())
        self.Del.grid(row=2, column=3)
        self.Add = Button(self.f,
                          text="ADD",
                          command=lambda: self.Add_category())
        self.Add.grid(row=2, column=1)
        self.Edit = Button(self.f,
                           text="Edit",
                           command=lambda: self.Add_category(edit=True))
        self.Edit.grid(row=2, column=2)
        self.Insert()

    def Delete(self):
        index = self.mlb1.Select_index
        if index == None or index > self.mlb1.size():
            return showinfo('Select Error',
                            'Noting Is Selected',
                            parent=self.master)
        tup = self.mlb1.get(index)
        s = askokcancel('Confirm',
                        'Are You Sure You Want To Delete %s ?' % tup[0],
                        parent=self.master)
        if s == True:
            self.db.deletecategory(tup[0])
        return self.Refresh(), showinfo('Successful',
                                        'Successfully Deleted',
                                        parent=self.master)

    def Insert(self):
        self.mlb1.delete(0, END)
        row = self.db.sqldb.execute(
            """SELECT * FROM category ORDER BY category_name """).fetchall()
        for i in row:
            row2 = self.db.sqldb.execute(
                """SELECT product_id,product_name FROM products JOIN category USING (category_id)
                                            WHERE category_id = "%s"  ORDER BY product_name """
                % (i[0])).fetchall()
            iid = self.mlb1.insert(END, (i[1], len(row2), i[0]))
            self.mlb1.insert(END, ["Product ID", "Product Name", "Qty"],
                             parent=iid,
                             rowname="",
                             bg='grey93',
                             fg='Red',
                             tag="lo")
            for p in row2:
                qty = float(self.db.sqldb.getquantity(p[0]))
                self.mlb1.insert(END, [p[0], p[1], qty],
                                 parent=iid,
                                 rowname="",
                                 bg='grey95',
                                 fg='Blue',
                                 tag="lol")
        return 1

    def Add_category(self, edit=False):
        tup = []
        if edit == True:
            index = self.mlb1.Select_index
            if index == None or index > self.mlb1.size():
                return showinfo('Select Error',
                                'Noting Is Selected',
                                parent=self.master)
            piid = self.mlb1.trueparent(self.mlb1.Select_iid)
            index = self.mlb1.index(piid)
            tup = self.mlb1.get(index)
        self.t = Toplevel(master=self.master)
        self.t.title('Add Category')
        if edit == True:
            self.t.title('Edit Category')
        self.t['bg'] = 'white'
        Label(self.t, text="Category Name", background='white').grid(row=1,
                                                                     column=0,
                                                                     padx=5,
                                                                     pady=5)
        self.e = Entry(self.t)
        self.e.grid(row=1, column=1, sticky=E + S + W + N, padx=5, pady=5)
        btn = Button(self.t,
                     text="Save Category",
                     command=lambda: self.Acat(edit, tup))
        btn.grid(row=2, column=1, sticky=E + S + W + N, padx=5, pady=5)
        if edit == True:
            Label(self.t, text="Category ID : ",
                  background='white').grid(row=0, column=0, padx=5, pady=5)
            Label(self.t, text=tup[2], background='white').grid(row=0,
                                                                column=1,
                                                                padx=5,
                                                                pady=5)
            self.e.delete(0, END)
            self.e.insert(0, tup[0])
        self.t.mainloop()
        return 1

    def Acat(self, edit, tup):
        Cname = Filter(self.e.get()).title()
        catid = self.db.sqldb.getcategory_id(Cname)
        if catid != None:
            return showinfo('Type Error',
                            'Category Name Is Already Listed',
                            parent=self.t)
        if len(Cname.split()) == 0:
            return showinfo('Type Error',
                            'Category Name Must Be Specified',
                            parent=self.t)
        if edit == True:
            self.db.editcategoryname(tup[0], Cname)
        else:
            self.db.addcategory(Cname)
        self.t.destroy()
        self.Refresh()
        return showinfo('Successful', 'Changes Saved', parent=self.master)

    def Refresh(self):
        return self.Insert()