-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbilling.py
More file actions
548 lines (453 loc) · 24.2 KB
/
Copy pathbilling.py
File metadata and controls
548 lines (453 loc) · 24.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
from tkinter import *
from tkinter import ttk,messagebox
import sqlite3
import time
import os
import tempfile
import bcrypt
# ------------------ BASE PATH SETUP ------------------
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
IMAGE_DIR = os.path.join(BASE_DIR, "images")
BILL_DIR = os.path.join(BASE_DIR, "bill")
os.makedirs(BILL_DIR, exist_ok=True)
class billClass:
def __init__(self,root):
self.root=root
self.root.geometry("1350x700+110+80")
self.root.resizable(False,False)
self.root.config(bg="white")
self.cart_list=[]
self.chk_print=0
self._is_logged_in = False
self._dash_container = Frame(self.root)
self._login_container = Frame(self.root)
self.icon_title = PhotoImage(file=os.path.join("images", "logo1.png"))
# ------------ login screen ------------
self._init_login()
# ------------- dasboard ---------------
self._init_dashboard()
self.to_login()
#---------------------- init functions -----------------------------
def _init_title(self, root):
title = Label(
root,
text="Inventory Management System",
image=self.icon_title,
compound=LEFT,
font=("times new roman", 40, "bold"),
bg="#010c48",
fg="white",
anchor="w",
padx=20
).place(x=0, y=0, relwidth=1, height=70)
def _init_product_frame(self):
ProductFrame1=Frame(self._dash_container,bd=4,relief=RIDGE,bg="white")
ProductFrame1.place(x=6,y=110,width=410,height=550)
pTitle=Label(ProductFrame1,text="All Products",font=("goudy old style",20,"bold"),bg="#262626",fg="white").pack(side=TOP,fill=X)
self.var_search=StringVar()
ProductFrame2=Frame(ProductFrame1,bd=2,relief=RIDGE,bg="white")
ProductFrame2.place(x=2,y=42,width=398,height=90)
lbl_search=Label(ProductFrame2,text="Search Product | By Name",font=("times new roman",15,"bold"),bg="white",fg="green").place(x=2,y=5)
lbl_search=Label(ProductFrame2,text="Product Name",font=("times new roman",15,"bold"),bg="white").place(x=2,y=45)
txt_search=Entry(ProductFrame2,textvariable=self.var_search,font=("times new roman",15),bg="lightyellow").place(x=128,y=47,width=150,height=22)
btn_search=Button(ProductFrame2,text="Search",command=self.search,font=("goudy old style",15),bg="#2196f3",fg="white",cursor="hand2").place(x=285,y=45,width=100,height=25)
btn_show_all=Button(ProductFrame2,text="Show All",command=self.show,font=("goudy old style",15),bg="#083531",fg="white",cursor="hand2").place(x=285,y=10,width=100,height=25)
ProductFrame3=Frame(ProductFrame1,bd=3,relief=RIDGE)
ProductFrame3.place(x=2,y=140,width=398,height=375)
scrolly=Scrollbar(ProductFrame3,orient=VERTICAL)
scrollx=Scrollbar(ProductFrame3,orient=HORIZONTAL)\
self.product_Table=ttk.Treeview(ProductFrame3,columns=("pid","name","price","qty","status"),yscrollcommand=scrolly.set,xscrollcommand=scrollx.set)
scrollx.pack(side=BOTTOM,fill=X)
scrolly.pack(side=RIGHT,fill=Y)
scrollx.config(command=self.product_Table.xview)
scrolly.config(command=self.product_Table.yview)
self.product_Table.heading("pid",text="P ID")
self.product_Table.heading("name",text="Name")
self.product_Table.heading("price",text="Price")
self.product_Table.heading("qty",text="Quantity")
self.product_Table.heading("status",text="Status")
self.product_Table["show"]="headings"
self.product_Table.column("pid",width=40)
self.product_Table.column("name",width=100)
self.product_Table.column("price",width=100)
self.product_Table.column("qty",width=40)
self.product_Table.column("status",width=90)
self.product_Table.pack(fill=BOTH,expand=1)
self.product_Table.bind("<ButtonRelease-1>",self.get_data)
self.show()
lbl_note=Label(ProductFrame1,text="Note: 'Enter 0 Quantity to remove product from the Cart'",font=("goudy old style",12),anchor="w",bg="white",fg="red").pack(side=BOTTOM,fill=X)
def _init_customer_frame(self):
self.var_cname=StringVar()
self.var_contact=StringVar()
CustomerFrame=Frame(self._dash_container,bd=4,relief=RIDGE,bg="white")
CustomerFrame.place(x=420,y=110,width=530,height=70)
cTitle=Label(CustomerFrame,text="Customer Details",font=("goudy old style",15),bg="lightgray").pack(side=TOP,fill=X)
lbl_name=Label(CustomerFrame,text="Name",font=("times new roman",15),bg="white").place(x=5,y=35)
txt_name=Entry(CustomerFrame,textvariable=self.var_cname,font=("times new roman",13),bg="lightyellow").place(x=80,y=35,width=180)
lbl_contact=Label(CustomerFrame,text="Contact No.",font=("times new roman",15),bg="white").place(x=270,y=35)
txt_contact=Entry(CustomerFrame,textvariable=self.var_contact,font=("times new roman",15),bg="lightyellow").place(x=380,y=35,width=140)
self.Cal_Cart_Frame=Frame(self._dash_container,bd=2,relief=RIDGE,bg="white")
self.Cal_Cart_Frame.place(x=420,y=190,width=530,height=360)
def _init_calculator_frame(self):
font = ('arial',15,'bold')
self.var_cal_input=StringVar()
Cal_Frame=Frame(self.Cal_Cart_Frame,bd=9,relief=RIDGE,bg="white")
Cal_Frame.place(x=5,y=10,width=268,height=340)
self.txt_cal_input=Entry(Cal_Frame,textvariable=self.var_cal_input,font=font,width=21,bd=10,relief=GROOVE,state='readonly',justify=RIGHT)
self.txt_cal_input.grid(row=0,columnspan=4)
btn_7=Button(Cal_Frame,text=7,font=font,command=lambda:self.get_input(7),bd=5,width=4,pady=10,cursor="hand2").grid(row=1,column=0)
btn_8=Button(Cal_Frame,text=8,font=font,command=lambda:self.get_input(8),bd=5,width=4,pady=10,cursor="hand2").grid(row=1,column=1)
btn_9=Button(Cal_Frame,text=9,font=font,command=lambda:self.get_input(9),bd=5,width=4,pady=10,cursor="hand2").grid(row=1,column=2)
btn_sum=Button(Cal_Frame,text="+",font=font,command=lambda:self.get_input('+'),bd=5,width=4,pady=10,cursor="hand2").grid(row=1,column=3)
btn_4=Button(Cal_Frame,text=4,font=font,command=lambda:self.get_input(4),bd=5,width=4,pady=10,cursor="hand2").grid(row=2,column=0)
btn_5=Button(Cal_Frame,text=5,font=font,command=lambda:self.get_input(5),bd=5,width=4,pady=10,cursor="hand2").grid(row=2,column=1)
btn_6=Button(Cal_Frame,text=6,font=font,command=lambda:self.get_input(6),bd=5,width=4,pady=10,cursor="hand2").grid(row=2,column=2)
btn_sub=Button(Cal_Frame,text="-",font=font,command=lambda:self.get_input('-'),bd=5,width=4,pady=10,cursor="hand2").grid(row=2,column=3)
btn_1=Button(Cal_Frame,text=1,font=font,command=lambda:self.get_input(1),bd=5,width=4,pady=10,cursor="hand2").grid(row=3,column=0)
btn_2=Button(Cal_Frame,text=2,font=font,command=lambda:self.get_input(2),bd=5,width=4,pady=10,cursor="hand2").grid(row=3,column=1)
btn_3=Button(Cal_Frame,text=3,font=font,command=lambda:self.get_input(3),bd=5,width=4,pady=10,cursor="hand2").grid(row=3,column=2)
btn_mul=Button(Cal_Frame,text="*",font=font,command=lambda:self.get_input('*'),bd=5,width=4,pady=10,cursor="hand2").grid(row=3,column=3)
btn_0=Button(Cal_Frame,text=0,font=font,command=lambda:self.get_input(0),bd=5,width=4,pady=15,cursor="hand2").grid(row=4,column=0)
btn_c=Button(Cal_Frame,text="C",font=font,command=self.clear_cal,bd=5,width=4,pady=15,cursor="hand2").grid(row=4,column=1)
btn_eq=Button(Cal_Frame,text="=",font=font,command=self.perform_cal,bd=5,width=4,pady=15,cursor="hand2").grid(row=4,column=2)
btn_div=Button(Cal_Frame,text="/",font=font,command=lambda:self.get_input('/'),bd=5,width=4,pady=15,cursor="hand2").grid(row=4,column=3)
def _init_cart_frame(self):
Cart_Frame=Frame(self.Cal_Cart_Frame,bd=3,relief=RIDGE)
Cart_Frame.place(x=280,y=8,width=245,height=342)
self.cartTitle=Label(Cart_Frame,text="Cart \t Total Products: [0]",font=("goudy old style",15),bg="lightgray")
self.cartTitle.pack(side=TOP,fill=X)
scrolly=Scrollbar(Cart_Frame,orient=VERTICAL)
scrollx=Scrollbar(Cart_Frame,orient=HORIZONTAL)\
self.CartTable=ttk.Treeview(Cart_Frame,columns=("pid","name","price","qty"),yscrollcommand=scrolly.set,xscrollcommand=scrollx.set)
scrollx.pack(side=BOTTOM,fill=X)
scrolly.pack(side=RIGHT,fill=Y)
scrollx.config(command=self.CartTable.xview)
scrolly.config(command=self.CartTable.yview)
self.CartTable.heading("pid",text="P ID")
self.CartTable.heading("name",text="Name")
self.CartTable.heading("price",text="Price")
self.CartTable.heading("qty",text="Quantity")
self.CartTable["show"]="headings"
self.CartTable.column("pid",width=40)
self.CartTable.column("name",width=100)
self.CartTable.column("price",width=90)
self.CartTable.column("qty",width=30)
self.CartTable.pack(fill=BOTH,expand=1)
self.CartTable.bind("<ButtonRelease-1>",self.get_data_cart)
def _add_cart_widgets_frame(self):
font = ("times new roman",15)
font_bold = ("times new roman",15,"bold")
self.var_pid=StringVar()
self.var_pname=StringVar()
self.var_price=StringVar()
self.var_qty=StringVar()
self.var_stock=StringVar()
Add_CartWidgets_Frame=Frame(self._dash_container,bd=2,relief=RIDGE,bg="white")
Add_CartWidgets_Frame.place(x=420,y=550,width=530,height=110)
def _get_lable(text, x, y):
return Label(Add_CartWidgets_Frame,text=text,font=font,bg="white").place(x=x,y=y)
lbl_p_name=_get_lable(text="Product Name",x=5,y=5)
txt_p_name=Entry(Add_CartWidgets_Frame,textvariable=self.var_pname,font=font,bg="lightyellow",state='readonly').place(x=5,y=35,width=190,height=22)
lbl_p_price=_get_lable(text="Price Per Qty",x=230,y=5)
txt_p_price=Entry(Add_CartWidgets_Frame,textvariable=self.var_price,font=font,bg="lightyellow",state='readonly').place(x=230,y=35,width=150,height=22)
lbl_p_qty=_get_lable(text="Quantity",x=390,y=5)
txt_p_qty=Entry(Add_CartWidgets_Frame,textvariable=self.var_qty,font=font,bg="lightyellow").place(x=390,y=35,width=120,height=22)
self.lbl_inStock=Label(Add_CartWidgets_Frame,text="In Stock",font=font,bg="white")
self.lbl_inStock.place(x=5,y=70)
btn_clear_cart=Button(Add_CartWidgets_Frame,command=self.clear_cart,text="Clear",font=font_bold,bg="lightgray",cursor="hand2").place(x=180,y=70,width=150,height=30)
btn_add_cart=Button(Add_CartWidgets_Frame,command=self.add_update_cart,text="Add | Update",font=font_bold,bg="orange",cursor="hand2").place(x=340,y=70,width=180,height=30)
def _init_billing_area(self):
billFrame=Frame(self._dash_container,bd=2,relief=RIDGE,bg="white")
billFrame.place(x=953,y=110,width=400,height=410)
BTitle=Label(billFrame,text="Customer Bill Area",font=("goudy old style",20,"bold"),bg="#262626",fg="white").pack(side=TOP,fill=X)
scrolly=Scrollbar(billFrame,orient=VERTICAL)
scrolly.pack(side=RIGHT,fill=Y)
self.txt_bill_area=Text(billFrame,yscrollcommand=scrolly.set)
self.txt_bill_area.pack(fill=BOTH,expand=1)
scrolly.config(command=self.txt_bill_area.yview)
def _init_billing_buttons(self):
font = ("goudy old style",15,"bold")
fg = "white"
def _get_lable(text, bg, x, y, width, height):
label = Label(billMenuFrame,text=text,font=font,bg=bg,fg=fg)
label.place(x=x,y=y,width=width,height=height)
return label
billMenuFrame=Frame(self._dash_container,bd=2,relief=RIDGE,bg="white")
billMenuFrame.place(x=953,y=520,width=400,height=140)
self.lbl_amnt=_get_lable(text="Bill Amount\n[0]",bg="#3f51b5",x=2,y=5,width=120,height=70)
self.lbl_discount=_get_lable(text="Discount\n[5%]",bg="#8bc34a",x=124,y=5,width=120,height=70)
self.lbl_net_pay=_get_lable(text="Net Pay\n[0]",bg="#607d8b",x=246,y=5,width=160,height=70)
btn_print=Button(billMenuFrame,text="Print",command=self.print_bill,cursor="hand2",font=font,bg="lightgreen",fg=fg)
btn_print.place(x=2,y=80,width=120,height=50)
btn_clear_all=Button(billMenuFrame,text="Clear All",command=self.clear_all,cursor="hand2",font=font,bg="gray",fg=fg)
btn_clear_all.place(x=124,y=80,width=120,height=50)
btn_generate=Button(billMenuFrame,text="Generate Bill",command=self.generate_bill,cursor="hand2",font=font,bg="#009688",fg="white")
btn_generate.place(x=246,y=80,width=160,height=50)
def _init_dashboard(self):
#------------- title --------------
self._init_title(self._dash_container)
#------------ logout button -----------
btn_logout=Button(self._dash_container,text="Logout",font=("times new roman",15,"bold"),bg="yellow",cursor="hand2",command=self.logout).place(x=1150,y=10,height=50,width=150)
#------------ clock -----------------
self.lbl_clock=Label(self._dash_container,text="Welcome to Inventory Management System\t\t Date: DD:MM:YYYY\t\t Time: HH:MM:SS",font=("times new roman",15),bg="#4d636d",fg="white")
self.lbl_clock.place(x=0,y=70,relwidth=1,height=30)
self._init_product_frame()
self._init_customer_frame()
self._init_calculator_frame()
self._init_cart_frame()
self._add_cart_widgets_frame()
self._init_billing_area()
self._init_billing_buttons()
self.show()
self.update_date_time()
def _init_login(self):
self.var_name = StringVar()
self.var_pass = StringVar()
font=("goudy old style", 20, "bold")
self._init_title(self._login_container)
form_frame = Frame(self._login_container)
form_frame.place(relx= 0.5, rely=0.5, anchor="center")
lbl_name = Label(form_frame, text="Username:", font=font)
lbl_name.grid(row=0, column=0, padx=40, pady=20, sticky="e")
txt_name = Entry(form_frame, textvariable=self.var_name, font=font, width=15)
txt_name.grid(row=0, column=1, padx=40, pady=20)
lbl_pass = Label(form_frame, text="Password:", font=font)
lbl_pass.grid(row=1, column=0, padx=40, pady=20, sticky="e")
txt_pass = Entry(form_frame, textvariable=self.var_pass, show="*", font=font, width=15)
txt_pass.grid(row=1, column=1, padx=40, pady=20)
login_button = Button(form_frame, text="Login", font=font, command=self.login)
login_button.grid(row=2, column=0, columnspan=2, pady=40)
#---------------------- all functions ------------------------------
def to_login(self):
self._dash_container.pack_forget()
self._login_container.pack(fill="both", expand=True)
def to_dashboard(self):
self._login_container.pack_forget()
self._dash_container.pack(fill="both", expand=True)
self.update_date_time()
def login(self):
con=sqlite3.connect(database=r'ims.db')
cur=con.cursor()
cur.execute("SELECT Password_hash FROM user WHERE Username=?", (self.var_name.get(),))
result = cur.fetchone()
con.close()
if result is None:
messagebox.showerror("Error","User does not exist",parent=self.root)
return
stored_hash = result[0]
password = self.var_pass.get()
if not bcrypt.checkpw(password.encode(), stored_hash.encode()):
messagebox.showerror("Error","Incorrect password",parent=self.root)
return
self.var_name.set("")
self.var_pass.set("")
self._is_logged_in = True
self.to_dashboard()
def logout(self):
self._is_logged_in = False
self.to_login()
def get_input(self,num):
xnum=self.var_cal_input.get()+str(num)
self.var_cal_input.set(xnum)
def clear_cal(self):
self.var_cal_input.set('')
def perform_cal(self):
result=self.var_cal_input.get()
self.var_cal_input.set(eval(result))
def show(self):
con=sqlite3.connect(database=r'ims.db')
cur=con.cursor()
try:
cur.execute("select pid,name,price,qty,status from product where status='Active'")
rows=cur.fetchall()
self.product_Table.delete(*self.product_Table.get_children())
for row in rows:
self.product_Table.insert('',END,values=row)
except Exception as ex:
messagebox.showerror("Error",f"Error due to : {str(ex)}")
def search(self):
con=sqlite3.connect(database=r'ims.db')
cur=con.cursor()
try:
if self.var_search.get()=="":
messagebox.showerror("Error","Search input should be required",parent=self.root)
else:
cur.execute("select pid,name,price,qty,status from product where name LIKE '%"+self.var_search.get()+"%'")
rows=cur.fetchall()
if len(rows)!=0:
self.product_Table.delete(*self.product_Table.get_children())
for row in rows:
self.product_Table.insert('',END,values=row)
else:
messagebox.showerror("Error","No record found!!!",parent=self.root)
except Exception as ex:
messagebox.showerror("Error",f"Error due to : {str(ex)}")
def get_data(self,ev):
f=self.product_Table.focus()
content=(self.product_Table.item(f))
row=content['values']
self.var_pid.set(row[0])
self.var_pname.set(row[1])
self.var_price.set(row[2])
self.lbl_inStock.config(text=f"In Stock [{str(row[3])}]")
self.var_stock.set(row[3])
self.var_qty.set('1')
def get_data_cart(self,ev):
f=self.CartTable.focus()
content=(self.CartTable.item(f))
row=content['values']
self.var_pid.set(row[0])
self.var_pname.set(row[1])
self.var_price.set(row[2])
self.var_qty.set(row[3])
self.lbl_inStock.config(text=f"In Stock [{str(row[4])}]")
self.var_stock.set(row[4])
def add_update_cart(self):
if self.var_pid.get()=="":
messagebox.showerror("Error","Please select product from the list",parent=self.root)
elif self.var_qty.get()=="":
messagebox.showerror("Error","Quantity is required",parent=self.root)
elif int(self.var_qty.get())>int(self.var_stock.get()):
messagebox.showerror("Error","Invalid Quantity",parent=self.root)
else:
price_cal=self.var_price.get()
cart_data=[self.var_pid.get(),self.var_pname.get(),price_cal,self.var_qty.get(),self.var_stock.get()]
#---------- update cart --------------
present="no"
index_=0
for row in self.cart_list:
if self.var_pid.get()==row[0]:
present="yes"
break
index_+=1
if present=="yes":
op=messagebox.askyesno("Confirm","Product already present\nDo you want to Update|Remove from the Cart List",parent=self.root)
if op==True:
if self.var_qty.get()=="0":
self.cart_list.pop(index_)
else:
self.cart_list[index_][3]=self.var_qty.get()
else:
self.cart_list.append(cart_data)
self.show_cart()
self.bill_update()
def bill_update(self):
self.bill_amnt=0
self.net_pay=0
self.siscount=0
for row in self.cart_list:
self.bill_amnt=self.bill_amnt+(float(row[2])*int(row[3]))
self.discount=(self.bill_amnt*5)/100
self.net_pay=self.bill_amnt-self.discount
self.lbl_amnt.config(text=f"Bill Amnt\n{str(self.bill_amnt)}")
self.lbl_net_pay.config(text=f"Net Pay\n{str(self.net_pay)}")
self.cartTitle.config(text=f"Cart \t Total Products: [{str(len(self.cart_list))}]")
def show_cart(self):
try:
self.CartTable.delete(*self.CartTable.get_children())
for row in self.cart_list:
self.CartTable.insert('',END,values=row)
except Exception as ex:
messagebox.showerror("Error",f"Error due to : {str(ex)}")
def generate_bill(self):
if self.var_cname.get()=="" or self.var_contact.get()=="":
messagebox.showerror("Error",f"Customer Details are required",parent=self.root)
elif len(self.cart_list)==0:
messagebox.showerror("Error",f"Please Add product to the Cart!!!",parent=self.root)
else:
#--------- bill top -----------------
self.bill_top()
#--------- bill middle --------------
self.bill_middle()
#--------- bill bottom --------------
self.bill_bottom()
fp=open(f'bill/{str(self.invoice)}.txt','w')
fp.write(self.txt_bill_area.get('1.0',END))
fp.close()
messagebox.showinfo("Saved","Bill has been generated",parent=self.root)
self.chk_print=1
def bill_top(self):
self.invoice=int(time.strftime("%H%M%S"))+int(time.strftime("%d%m%Y"))
bill_top_temp=f'''
\t\tXYZ-Inventory
\t Phone No. 9899459288 , Delhi-110053
{str("="*46)}
Customer Name: {self.var_cname.get()}
Ph. no. : {self.var_contact.get()}
Bill No. {str(self.invoice)}\t\t\tDate: {str(time.strftime("%d/%m/%Y"))}
{str("="*46)}
Product Name\t\t\tQTY\tPrice
{str("="*46)}
'''
self.txt_bill_area.delete('1.0',END)
self.txt_bill_area.insert('1.0',bill_top_temp)
def bill_bottom(self):
bill_bottom_temp=f'''
{str("="*46)}
Bill Amount\t\t\t\tRs.{self.bill_amnt}
Discount\t\t\t\tRs.{self.discount}
Net Pay\t\t\t\tRs.{self.net_pay}
{str("="*46)}\n
'''
self.txt_bill_area.insert(END,bill_bottom_temp)
def bill_middle(self):
con=sqlite3.connect(database=r'ims.db')
cur=con.cursor()
try:
for row in self.cart_list:
pid=row[0]
name=row[1]
qty=int(row[4])-int(row[3])
if int(row[3])==int(row[4]):
status="Inactive"
if int(row[3])!=int(row[4]):
status="Active"
price=float(row[2])*int(row[3])
price=str(price)
self.txt_bill_area.insert(END,"\n "+name+"\t\t\t"+row[3]+"\tRs."+price)
#------------- update qty in product table --------------
cur.execute("update product set qty=?,status=? where pid=?",(
qty,
status,
pid
))
con.commit()
con.close()
self.show()
except Exception as ex:
messagebox.showerror("Error",f"Error due to : {str(ex)}",parent=self.root)
def clear_cart(self):
self.var_pid.set("")
self.var_pname.set("")
self.var_price.set("")
self.var_qty.set("")
self.lbl_inStock.config(text=f"In Stock")
self.var_stock.set("")
def clear_all(self):
del self.cart_list[:]
self.clear_cart()
self.show()
self.show_cart()
self.var_cname.set("")
self.var_contact.set("")
self.chk_print=0
self.txt_bill_area.delete('1.0',END)
self.cartTitle.config(text=f"Cart \t Total Products: [0]")
self.var_search.set("")
def update_date_time(self):
time_=time.strftime("%I:%M:%S")
date_=time.strftime("%d-%m-%Y")
self.lbl_clock.config(text=f"Welcome to Inventory Management System\t\t Date: {str(date_)}\t\t Time: {str(time_)}")
self.lbl_clock.after(200,self.update_date_time)
def print_bill(self):
if self.chk_print==1:
messagebox.showinfo("Print","Please wait while printing",parent=self.root)
new_file=tempfile.mktemp('.txt')
open(new_file,'w').write(self.txt_bill_area.get('1.0',END))
os.startfile(new_file,'print')
else:
messagebox.showinfo("Print","Please generate bill to print the receipt",parent=self.root)
if __name__=="__main__":
root=Tk()
obj=billClass(root)
root.mainloop()