|
| 1 | +from tkinter import * |
| 2 | +from tkinter import ttk |
| 3 | +from tkcalendar import DateEntry |
| 4 | +from tkinter import messagebox |
| 5 | +import sqlite3 as db |
| 6 | + |
| 7 | + |
| 8 | +def connection(): |
| 9 | + connectObj = db.connect("shopManagement.db") |
| 10 | + cur = connectObj.cursor() |
| 11 | + sql = ''' |
| 12 | + create table if not exists sellings ( |
| 13 | + date string, |
| 14 | + product string, |
| 15 | + price number, |
| 16 | + quantity number, |
| 17 | + total number |
| 18 | + ) |
| 19 | + ''' |
| 20 | + cur.execute(sql) |
| 21 | + connectObj.commit() |
| 22 | + |
| 23 | + |
| 24 | +connection() |
| 25 | +window = Tk() |
| 26 | +window.title("Shop Sales and Stock Managing") |
| 27 | +tabs = ttk.Notebook(window) |
| 28 | +root = ttk.Frame(tabs) |
| 29 | +root2 = ttk.Frame(tabs) |
| 30 | + |
| 31 | +tabs.add(root, text='Sell') |
| 32 | +tabs.add(root2, text='Stock') |
| 33 | +tabs.pack(expand=1, fill="both") |
| 34 | + |
| 35 | + |
| 36 | +# -----------------------------------tab1 ---------------------------------- |
| 37 | + |
| 38 | +def GenerateBill(): |
| 39 | + connectObj = db.connect("shopManagement.db") |
| 40 | + cur = connectObj.cursor() |
| 41 | + |
| 42 | + global billarea |
| 43 | + if p1quantity.get() == 0 and p2quantity.get() == 0 and p3quantity.get() == 0 and p4quantity.get() == 0: |
| 44 | + messagebox.showerror("Error", "No product purchased") |
| 45 | + else: |
| 46 | + billarea.delete('1.0', END) |
| 47 | + billarea.insert(END, "\t|| Shop Sales and Stock Managing ||") |
| 48 | + billarea.insert(END, "\n_______________\n") |
| 49 | + billarea.insert(END, "\nDate\t Products\tPrice\t QTY\t Total") |
| 50 | + billarea.insert(END, "\n==========================================") |
| 51 | + |
| 52 | + price = IntVar() |
| 53 | + price2 = IntVar() |
| 54 | + price3 = IntVar() |
| 55 | + price4 = IntVar() |
| 56 | + |
| 57 | + print(dateE.get()) |
| 58 | + price = price2 = price3 = price4 = 0 |
| 59 | + |
| 60 | + if p1quantity.get() != 0: |
| 61 | + price = p1quantity.get() * p1price.get() |
| 62 | + print(price) |
| 63 | + billarea.insert(END, f"\n{dateE.get()}\t {p1name.get()} \t{p1price.get()}\t {p1quantity.get()}\t {price}") |
| 64 | + |
| 65 | + sql = ''' |
| 66 | + INSERT INTO Sellings VALUES |
| 67 | + (?, ?, ?, ?,?) |
| 68 | + ''' |
| 69 | + cur.execute(sql, (dateE.get(), p1name.get(), p1price.get(), p1quantity.get(), price)) |
| 70 | + connectObj.commit() |
| 71 | + |
| 72 | + if p2quantity.get() != 0: |
| 73 | + price2 = (p2quantity.get() * p2price.get()) |
| 74 | + print(price2) |
| 75 | + billarea.insert(END, f"\n{dateE.get()}\t {p2name.get()} \t{p2price.get()}\t {p2quantity.get()}\t {price2}") |
| 76 | + |
| 77 | + sql = ''' |
| 78 | + INSERT INTO Sellings VALUES |
| 79 | + (?, ?, ?, ?,?) |
| 80 | + ''' |
| 81 | + print(dateE.get(), 'Product-2', p2price.get(), p2quantity.get(), price2) |
| 82 | + cur.execute(sql, (dateE.get(), p2name.get(), p2price.get(), p2quantity.get(), price2)) |
| 83 | + connectObj.commit() |
| 84 | + |
| 85 | + if p3quantity.get() != 0: |
| 86 | + price3 = p3quantity.get() * p1price.get() |
| 87 | + print(price3) |
| 88 | + billarea.insert(END, f"\n{dateE.get()}\t{p3name.get()}\t{p3price.get()}\t {p3quantity.get()}\t {price3}") |
| 89 | + |
| 90 | + sql = ''' |
| 91 | + INSERT INTO Sellings VALUES |
| 92 | + (?, ?, ?, ?,?) |
| 93 | + ''' |
| 94 | + cur.execute(sql, (dateE.get(), p1name.get(), p3price.get(), p3quantity.get(), price3)) |
| 95 | + connectObj.commit() |
| 96 | + |
| 97 | + if p4quantity.get() != 0: |
| 98 | + price4 = p4quantity.get() * p1price.get() |
| 99 | + billarea.insert(END, f"\n{dateE.get()}\t{p4name.get()}\t{p4price.get()}\t {p4quantity.get()}\t {price4}") |
| 100 | + |
| 101 | + sql = ''' |
| 102 | + INSERT INTO Sellings VALUES |
| 103 | + (?, ?, ?, ?,?) |
| 104 | + ''' |
| 105 | + cur.execute(sql, (dateE.get(), p4name.get(), p4price.get(), p4quantity.get(), price4)) |
| 106 | + connectObj.commit() |
| 107 | + |
| 108 | + Totalprice = IntVar() |
| 109 | + Totalprice = price + price2 + price3 + price4 |
| 110 | + |
| 111 | + Totalquantity = IntVar() |
| 112 | + Totalquantity = p1quantity.get() + p2quantity.get() + p3quantity.get() + p4quantity.get() |
| 113 | + billarea.insert(END, f"\nTotal \t \t \t{Totalquantity}\t {Totalprice}") |
| 114 | + |
| 115 | + |
| 116 | +def view(): |
| 117 | + connectObj = db.connect("shopManagement.db") |
| 118 | + cur = connectObj.cursor() |
| 119 | + |
| 120 | + sql = 'Select * from Sellings' |
| 121 | + cur.execute(sql) |
| 122 | + |
| 123 | + rows = cur.fetchall() |
| 124 | + viewarea.insert(END, f"Date\t Product\t Price of 1\t Quantity\t Price\n") |
| 125 | + |
| 126 | + for i in rows: |
| 127 | + allrows = "" |
| 128 | + for j in i: |
| 129 | + allrows += str(j) + '\t' |
| 130 | + allrows += '\n' |
| 131 | + viewarea.insert(END, allrows) |
| 132 | + |
| 133 | + |
| 134 | +dateL = Label(root, text="Date", bg="DodgerBlue2", width=12, font=('arial', 15, 'bold')) |
| 135 | +dateL.grid(row=0, column=0, padx=7, pady=7) |
| 136 | + |
| 137 | +dateE = DateEntry(root, width=12, font=('arial', 15, 'bold')) |
| 138 | +dateE.grid(row=0, column=1, padx=7, pady=7) |
| 139 | + |
| 140 | +l = Label(root, text="Product", font=('arial', 15, 'bold'), bg="DodgerBlue2", width=12) |
| 141 | +l.grid(row=1, column=0, padx=7, pady=7) |
| 142 | + |
| 143 | +l = Label(root, text="Price", font=('arial', 15, 'bold'), bg="DodgerBlue2", width=12) |
| 144 | +l.grid(row=1, column=1, padx=7, pady=7) |
| 145 | + |
| 146 | +l = Label(root, text="Quantity", font=('arial', 15, 'bold'), bg="DodgerBlue2", width=12) |
| 147 | +l.grid(row=1, column=2, padx=7, pady=7) |
| 148 | + |
| 149 | +# ----product 1---------------------------------------------------- |
| 150 | +p1name = StringVar() |
| 151 | +p1name.set('Product1') |
| 152 | + |
| 153 | +p1price = IntVar() |
| 154 | +p1price.set(100) |
| 155 | + |
| 156 | +p1quantity = IntVar() |
| 157 | +p1quantity.set(0) |
| 158 | + |
| 159 | +l = Entry(root, text=p1name, font=('arial', 15, 'bold'), width=12) |
| 160 | +l.grid(row=2, column=0, padx=7, pady=7) |
| 161 | + |
| 162 | +l = Entry(root, text=p1price, font=('arial', 15, 'bold'), width=12) |
| 163 | +l.grid(row=2, column=1, padx=7, pady=7) |
| 164 | + |
| 165 | +t = Entry(root, textvariable=p1quantity, font=('arial', 15, 'bold'), width=12) |
| 166 | +t.grid(row=2, column=2, padx=7, pady=7) |
| 167 | + |
| 168 | +# ----product 2------------------------------------------------------------- |
| 169 | +p2name = StringVar() |
| 170 | +p2name.set('Product2') |
| 171 | + |
| 172 | +p2price = IntVar() |
| 173 | +p2price.set(200) |
| 174 | + |
| 175 | +p2quantity = IntVar() |
| 176 | +p2quantity.set(0) |
| 177 | + |
| 178 | +l = Entry(root, text=p2name, font=('arial', 15, 'bold'), width=12) |
| 179 | +l.grid(row=3, column=0, padx=7, pady=7) |
| 180 | + |
| 181 | +l = Entry(root, text=p2price, font=('arial', 15, 'bold'), width=12) |
| 182 | +l.grid(row=3, column=1, padx=7, pady=7) |
| 183 | + |
| 184 | +t = Entry(root, textvariable=p2quantity, font=('arial', 15, 'bold'), width=12) |
| 185 | +t.grid(row=3, column=2, padx=7, pady=7) |
| 186 | + |
| 187 | +# ----product 3---- |
| 188 | +p3name = StringVar() |
| 189 | +p3name.set('Product3') |
| 190 | + |
| 191 | +p3price = IntVar() |
| 192 | +p3price.set(300) |
| 193 | + |
| 194 | +p3quantity = IntVar() |
| 195 | +p3quantity.set(0) |
| 196 | + |
| 197 | +l = Entry(root, text=p3name, font=('arial', 15, 'bold'), width=12) |
| 198 | +l.grid(row=4, column=0, padx=7, pady=7) |
| 199 | + |
| 200 | +l = Entry(root, text=p3price, font=('arial', 15, 'bold'), width=12) |
| 201 | +l.grid(row=4, column=1, padx=7, pady=7) |
| 202 | + |
| 203 | +t = Entry(root, textvariable=p3quantity, font=('arial', 15, 'bold'), width=12) |
| 204 | +t.grid(row=4, column=2, padx=7, pady=7) |
| 205 | + |
| 206 | +# ----product 4---- |
| 207 | +p4name = StringVar() |
| 208 | +p4name.set('Product4') |
| 209 | + |
| 210 | +p4price = IntVar() |
| 211 | +p4price.set(400) |
| 212 | + |
| 213 | +p4quantity = IntVar() |
| 214 | +p4quantity.set(0) |
| 215 | + |
| 216 | +l = Entry(root, text=p4name, font=('arial', 15, 'bold'), width=12) |
| 217 | +l.grid(row=5, column=0, padx=7, pady=7) |
| 218 | + |
| 219 | +l = Entry(root, text=p4price, font=('arial', 15, 'bold'), width=12) |
| 220 | +l.grid(row=5, column=1, padx=7, pady=7) |
| 221 | + |
| 222 | +t = Entry(root, textvariable=p4quantity, font=('arial', 15, 'bold'), width=12) |
| 223 | +t.grid(row=5, column=2, padx=7, pady=7) |
| 224 | + |
| 225 | +# ------------------------bill------------------------- |
| 226 | +billarea = Text(root) |
| 227 | + |
| 228 | +submitbtn = Button(root, command=GenerateBill, text="Bill", |
| 229 | + font=('arial', 15, 'bold'), bg="DodgerBlue2", width=20) |
| 230 | + |
| 231 | +submitbtn.grid(row=6, column=0, padx=7, pady=7) |
| 232 | + |
| 233 | +viewbtn = Button(root, command=view, text="View All Sellings", |
| 234 | + font=('arial', 15, 'bold'), bg="DodgerBlue2", width=20) |
| 235 | + |
| 236 | +viewbtn.grid(row=6, column=2, padx=7, pady=7) |
| 237 | + |
| 238 | +billarea.grid(row=9, column=0) |
| 239 | +viewarea = Text(root) |
| 240 | +viewarea.grid(row=9, column=2) |
| 241 | + |
| 242 | + |
| 243 | +# ----------------------------------------------tab2 ---------------------------------- |
| 244 | +def connection2(): |
| 245 | + connectObj2 = db.connect("shopManagement.db") |
| 246 | + cur = connectObj2.cursor() |
| 247 | + sql = ''' |
| 248 | + create table if not exists stocks ( |
| 249 | + date string, |
| 250 | + product string, |
| 251 | + price number, |
| 252 | + quantity number |
| 253 | + ) |
| 254 | + ''' |
| 255 | + cur.execute(sql) |
| 256 | + connectObj2.commit() |
| 257 | + |
| 258 | + |
| 259 | +connection2() |
| 260 | + |
| 261 | + |
| 262 | +def addStock(): |
| 263 | + global dateE2, qty, name, price |
| 264 | + |
| 265 | + connectObj = db.connect("shopManagement.db") |
| 266 | + cur = connectObj.cursor() |
| 267 | + sql = ''' |
| 268 | + INSERT INTO stocks VALUES |
| 269 | + (?, ?, ?, ?) |
| 270 | + ''' |
| 271 | + cur.execute(sql, (dateE2.get(), name.get(), price.get(), qty.get())) |
| 272 | + connectObj.commit() |
| 273 | + |
| 274 | + |
| 275 | +def viewStock(): |
| 276 | + connectObj = db.connect("shopManagement.db") |
| 277 | + cur = connectObj.cursor() |
| 278 | + |
| 279 | + sql = 'Select * from stocks' |
| 280 | + cur.execute(sql) |
| 281 | + |
| 282 | + rows = cur.fetchall() |
| 283 | + viewarea2.insert(END, f"Date \tProduct\t Price\t Quantity\t \n") |
| 284 | + |
| 285 | + for i in rows: |
| 286 | + allrows = "" |
| 287 | + for j in i: |
| 288 | + allrows += str(j) + '\t' |
| 289 | + allrows += '\n' |
| 290 | + viewarea2.insert(END, allrows) |
| 291 | + |
| 292 | + |
| 293 | +dateL = Label(root2, text="Date", bg="DodgerBlue2", width=12, font=('arial', 15, 'bold')) |
| 294 | +dateL.grid(row=0, column=0, padx=7, pady=7) |
| 295 | + |
| 296 | +dateE2 = DateEntry(root2, width=12, font=('arial', 15, 'bold')) |
| 297 | +dateE2.grid(row=0, column=1, padx=7, pady=7) |
| 298 | + |
| 299 | +l = Label(root2, text="Product", font=('arial', 15, 'bold'), bg="DodgerBlue2", width=12) |
| 300 | +l.grid(row=1, column=0, padx=7, pady=7) |
| 301 | + |
| 302 | +l = Label(root2, text="Price", font=('arial', 15, 'bold'), bg="DodgerBlue2", width=12) |
| 303 | +l.grid(row=2, column=0, padx=7, pady=7) |
| 304 | + |
| 305 | +l = Label(root2, text="Quantity", font=('arial', 15, 'bold'), bg="DodgerBlue2", width=12) |
| 306 | +l.grid(row=3, column=0, padx=7, pady=7) |
| 307 | + |
| 308 | +name = StringVar() |
| 309 | +price = IntVar() |
| 310 | +qty = IntVar() |
| 311 | + |
| 312 | +Name = Entry(root2, textvariable=name, font=('arial', 15, 'bold'), width=12) |
| 313 | +Name.grid(row=1, column=1, padx=7, pady=7) |
| 314 | + |
| 315 | +Price = Entry(root2, textvariable=price, font=('arial', 15, 'bold'), width=12) |
| 316 | +Price.grid(row=2, column=1, padx=7, pady=7) |
| 317 | + |
| 318 | +Qty = Entry(root2, textvariable=qty, font=('arial', 15, 'bold'), width=12) |
| 319 | +Qty.grid(row=3, column=1, padx=7, pady=7) |
| 320 | + |
| 321 | +addbtn = Button(root2, command=addStock, text="Add", |
| 322 | + font=('arial', 15, 'bold'), bg="DodgerBlue2", width=20) |
| 323 | + |
| 324 | +addbtn.grid(row=4, column=1, padx=7, pady=7) |
| 325 | + |
| 326 | +viewarea2 = Text(root2) |
| 327 | +viewarea2.grid(row=5, column=0, columnspan=2) |
| 328 | + |
| 329 | +viewbtn2 = Button(root2, command=viewStock, text="View Stock", |
| 330 | + font=('arial', 15, 'bold'), bg="DodgerBlue2", width=20) |
| 331 | + |
| 332 | +viewbtn2.grid(row=4, column=0, padx=7, pady=7) |
| 333 | + |
| 334 | +mainloop() |
0 commit comments