-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
541 lines (457 loc) · 19.4 KB
/
main.py
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
from tkinter import *
import time
from PIL import ImageTk, Image
from tkinter import ttk
from tkinter import messagebox
import random
import os
import sys
# ========================== Window Format Start Here ========================== #
root = Tk()
root.title("HK Billing Software") # This is the title
width = root.winfo_screenwidth()
height = root.winfo_screenheight()
root.geometry("%dx%d" % (width, height))
root.title("Billing Software")
# This is the measurement of window
root.resizable(0, 0) # To prevent resizing of window
root.state("zoomed") # This is for Full Screen
bg_color = '#3c3f41' # This is variable storing hex color code
root.configure(bg=bg_color) # This is color of background Screen
photo = PhotoImage(file="icon.png") # Icon of the main window
root.iconphoto(False, photo)
bg_color1 = '#1B2631' # This is variable storing hex color code
bg_color2 = '#626567' # This is variable storing hex color code
bg_color3 = '#2b2b2b' # This is variable storing hex color code
title_color = '#D0D3D4' # This is variable storing hex color code
# ========================== Window Format End Here ========================== #
# ========== Variables ========== #
clicked = StringVar() # select category dropdown list variable
clicked1 = StringVar() # select product dropdown list variable
qty = IntVar() # Quantity variable
a = int(qty.get()) # Conversion of IntStr() into int()
expression = "" # Calculator starting variable
input_text = StringVar() # It is used to get the instance of input field
# Total and Tax variables
grocery_price = StringVar()
cosmetic_price = StringVar()
other_price = StringVar()
tax_grocery = StringVar()
tax_cosmetic = StringVar()
tax_other = StringVar()
# Customer Details Variable
cname = StringVar()
cmobile = StringVar()
billno = StringVar()
randbillno = random.randint(1000, 9000)
billno.set(str(randbillno))
search_bill = StringVar()
# Other Required Variables
items = []
quantity = []
final_price_grocery = []
final_price_cosmetic = []
final_price_other = []
final_price = []
net_amt_var = StringVar()
all_tax = StringVar()
all_total = StringVar()
# ========================== Functions Starts Here ========================== #
# Function = clock() : This will show current time
def clock():
hour = time.strftime("%H")
minute = time.strftime("%M")
second = time.strftime("%S")
show_time.config(text=hour + ':' + minute + ':' + second)
show_time.after(1000, clock)
# Function = Display_date() : This will show current date
def display_date():
date = time.strftime("%d")
month = time.strftime("%m")
year = time.strftime("%y")
show_date.config(text=date + '-' + month + '-' + year)
show_date.after(1000, clock)
# Function = select_categories : This will update the product list
def select_categories(e):
if clicked.get() == 'Groceries':
product_drop.config(value=grocery_product)
elif clicked.get() == 'Cosmetics':
product_drop.config(value=cosmetic_product)
elif clicked.get() == 'Others':
product_drop.config(value=other_product)
# 'extra' function : This Function continuously updates the input field whenever you enters a number
def extra(item):
global expression
expression = expression + str(item)
input_text.set(expression)
# 'clear' function : This is used to clear the input field
def clear():
global expression
expression = ""
input_text.set("")
# 'evaluation':This method calculates the expression present in input field
def evaluation():
global expression
result = str(eval(expression))
input_text.set(result)
# clear the selected item
def clear_crt():
categories_drop.set(" ")
product_drop.set(" ")
qty.set(0)
# Append the item in cart
def add_cart():
if clicked.get() == '':
messagebox.showinfo("Warning", "Please Select Category")
elif clicked1.get() == '':
messagebox.showinfo("Warning", "Please Select Product")
# elif a == 0:
# messagebox.showinfo("Warning", "Please Enter the Quantity")
elif qty.get() == 0:
messagebox.showinfo("Warning", "Please Enter the Quantity")
elif clicked1.get() == 'Rice':
items.append(clicked1.get())
quantity.append(qty.get())
price = qty.get() * 50
final_price_grocery.append(price)
final_price.append(price)
elif clicked1.get() == 'Wheat':
items.append(clicked1.get())
quantity.append(qty.get())
price = qty.get() * 70
final_price_grocery.append(price)
final_price.append(price)
elif clicked1.get() == 'Sugar':
items.append(clicked1.get())
quantity.append(qty.get())
price = qty.get() * 150
final_price_grocery.append(price)
final_price.append(price)
elif clicked1.get() == 'Oil':
items.append(clicked1.get())
quantity.append(qty.get())
price = qty.get() * 120
final_price_grocery.append(price)
final_price.append(price)
elif clicked1.get() == 'Soap':
items.append(clicked1.get())
quantity.append(qty.get())
price = qty.get() * 100
final_price_cosmetic.append(price)
final_price.append(price)
elif clicked1.get() == 'Cream':
items.append(clicked1.get())
quantity.append(qty.get())
price = qty.get() * 180
final_price_cosmetic.append(price)
final_price.append(price)
elif clicked1.get() == 'Face Wash':
items.append(clicked1.get())
quantity.append(qty.get())
price = qty.get() * 300
final_price_cosmetic.append(price)
final_price.append(price)
elif clicked1.get() == 'Body Wash':
items.append(clicked1.get())
quantity.append(qty.get())
price = qty.get() * 250
final_price_cosmetic.append(price)
final_price.append(price)
elif clicked1.get() == 'Waffers':
items.append(clicked1.get())
quantity.append(qty.get())
price = qty.get() * 30
final_price_other.append(price)
final_price.append(price)
elif clicked1.get() == 'Biscuits':
items.append(clicked1.get())
quantity.append(qty.get())
price = qty.get() * 50
final_price_other.append(price)
final_price.append(price)
elif clicked1.get() == 'Cold Drink':
items.append(clicked1.get())
quantity.append(qty.get())
price = qty.get() * 30
final_price_other.append(price)
final_price.append(price)
elif clicked1.get() == 'Namkeen':
items.append(clicked1.get())
quantity.append(qty.get())
price = qty.get() * 80
final_price_other.append(price)
final_price.append(price)
clear_crt()
# Clear All Function
def clear_all():
items.clear()
quantity.clear()
final_price_grocery.clear()
final_price_cosmetic.clear()
final_price_other.clear()
cosmetic_price.set("")
grocery_price.set("")
other_price.set("")
tax_other.set("")
tax_cosmetic.set("")
tax_grocery.set("")
net_amt_var.set("")
cname.set("")
cmobile.set("")
search_bill.set("")
billno.set("")
randbillno = random.randint(1000, 9000)
billno.set(str(randbillno))
bill_txt()
# Display the Total category wise price and Tax
def display_total():
total = 0
total1 = 0
total2 = 0
final_total = 0
for i in range(0, len(final_price_grocery)):
total = total + final_price_grocery[i]
grocery_price.set(str(total))
for j in range(0, len(final_price_cosmetic)):
total1 = total1 + final_price_cosmetic[j]
cosmetic_price.set(str(total1))
for k in range(0, len(final_price_other)):
total2 = total2 + final_price_other[k]
other_price.set(str(total2))
grocery_after_tax = (total * 18)/100
tax_grocery.set(grocery_after_tax)
cosmetic_after_tax = (total1 * 22)/100
tax_cosmetic.set(cosmetic_after_tax)
other_after_tax = (total2 * 18)/100
tax_other.set(other_after_tax)
total_price = total + total1 + total2
all_total.set(total_price)
total_tax = grocery_after_tax + cosmetic_after_tax + other_after_tax
all_tax.set(total_tax)
final_total = total + grocery_after_tax + total1 + cosmetic_after_tax + total2 + other_after_tax
final_total1 = "Rs. " + str(final_total)
net_amt_var.set(final_total1)
# Function for Bill Area Default Text
def bill_txt():
da = time.strftime("%d-%m-%y")
ti = time.strftime("%H:%M")
txtarea.delete(1.0, END)
txtarea.insert(END, "################ Welcome to HK Retails ###############\n")
txtarea.insert(END, " Phone No: 9825323396 , Vadodara GJ-390018")
txtarea.insert(END, f"\n\n Bill No: {billno.get()}\t\t\t\tDate : {da}")
txtarea.insert(END, f"\n Customer Name: {cname.get()}\t\t\t\tTime : {ti}")
txtarea.insert(END, f"\n Customer Phone: {cmobile.get()}")
txtarea.insert(END, "\n######################################################")
txtarea.insert(END, "\n Products Quantity Price")
txtarea.insert(END, "\n######################################################")
# Function bill_area : This will generate the bill
def bill_area():
if cname.get() == '':
messagebox.showinfo("warning", "Please enter Customer Details")
elif cmobile.get() == '':
messagebox.showinfo("warning", "Please enter Customer Details")
elif not items:
messagebox.showinfo("warning", "Please enter Products in cart")
elif grocery_price.get() == '0' and cosmetic_price.get() == '0' and other_price.get() == '0':
messagebox.showinfo("warning", "Please enter Products in cart")
else:
bill_txt()
x = len(items)
v = 0
while v < x:
txtarea.insert(END, f"\n {items[v]}\t\t\t {quantity[v]}\t\t\t{final_price[v]}")
v = v + 1
txtarea.insert(END, "\n******************************************************")
txtarea.insert(END, f"\n Total Price : {all_total.get()}")
txtarea.insert(END, f"\n Total Tax : {all_tax.get()}")
txtarea.insert(END, "\n******************************************************")
txtarea.insert(END, f"\n Net Price : {net_amt_var.get()}")
save_bill()
# Function to Save bill Txt file in Folder
def save_bill():
msg = messagebox.askyesno("Save Bill", "Do you want to save bill ?")
if msg > 0:
data_bill = txtarea.get('1.0', END)
f1 = open("Bill_records/" + str(billno.get()) + ".txt", "w")
f1.write(data_bill)
f1.close()
messagebox.showinfo("Saved", f"Bill with bill no {billno.get()} has saved successfully")
else:
return
# Function to Search Bill
def bill_search():
current = "False"
for i in os.listdir("Bill_records/"):
if i.split('.')[0] == search_bill.get():
f1 = open(f"Bill_records/{i}", "r")
txtarea.delete('1.0', END)
for j in f1:
txtarea.insert(END, j)
f1.close()
current = "True"
if current == "False":
messagebox.showinfo("Error", "No Record Found !")
# Function to exit
def exit_window():
msg1 = messagebox.askyesno("System", "Do you want to exit ?")
if msg1 > 0:
sys.exit()
else:
return
# ========================== Functions End Here ========================== #
# ========================== Software Design Starts Here ========================== #
# =============== Title Frame =============== #
# Top Frame 1
frame1 = Frame(root, bg=bg_color, height=50, relief=RIDGE)
frame1.pack(side=TOP, fill='x')
# Image of Clock
clock_img = Image.open("clock.png")
clock_img = clock_img.resize((30, 30))
my_clock = ImageTk.PhotoImage(clock_img)
# Clock Image Label
clock_frame = Frame(frame1, bg=bg_color)
clock_frame.pack(side=LEFT)
clockLabel = Label(clock_frame, image=my_clock, bg=bg_color, fg='white')
clockLabel.pack(side=LEFT, padx=20)
# Time display
show_time = Label(clock_frame, text='', bg=bg_color, fg='white', font='Helvetica 15 bold')
show_time.pack(side=LEFT)
# Image of Calander
calander_img = Image.open("calander.png")
calander_img = calander_img.resize((23, 23))
my_calander = ImageTk.PhotoImage(calander_img)
# Calander Image Label
date_frame = Frame(frame1, bg=bg_color)
date_frame.pack(side=RIGHT)
calanderLabel = Label(date_frame, image=my_calander, bg=bg_color, fg='white')
calanderLabel.pack(side=LEFT)
# Date Display
show_date = Label(date_frame, text='', bg=bg_color, fg='white', font='Helvetica 15 bold')
show_date.pack(side=RIGHT, padx=25)
# Image of LOGO
logo = Image.open("icon.png")
logo = logo.resize((48, 48))
my_logo = ImageTk.PhotoImage(logo)
# Logo Image Label
title_frame = Frame(frame1, bg=bg_color)
title_frame.pack(side=TOP)
logoLabel = Label(title_frame, image=my_logo, bg=bg_color, fg='white')
logoLabel.pack(side=LEFT)
# Title in Frame 1
title = Label(title_frame, text="HK Billing Software", font="Fira_Mono 30 bold", bg=bg_color, fg='white')
title.pack(side=RIGHT)
# =============== Customer Details Frame =============== #
# Frame 2 :
frame2 = LabelFrame(root, text="Customer Details", font='Helvetica 13 bold', fg=title_color, bg=bg_color)
frame2.pack(side=TOP, fill='x')
# Customer Name Label
cname_label = Label(frame2, text="Customer Name: ", font="Fira_Mono 16 bold", bg=bg_color, fg='white')
cname_label.grid(row=0, column=0, padx=5, pady=20)
# Customer Name Input Field
cname_inp = Entry(frame2, width=22, font='Arial 15', textvariable=cname)
cname_inp.grid(row=0, column=1, pady=5, padx=2)
# Customer Phone Number Label
cmobile_label = Label(frame2, text="Phone No: ", font="Fira_Mono 16 bold", bg=bg_color, fg='white')
cmobile_label.grid(row=0, column=2, padx=5, pady=10)
# Customer Phone Number Input Field
cmobile_inp = Entry(frame2, width=22, font='Arial 15', textvariable=cmobile)
cmobile_inp.grid(row=0, column=3, pady=5, padx=2)
# Bill Number Label
billno_label = Label(frame2, text="Bill No: ", font="Fira_Mono 16 bold", bg=bg_color, fg='white')
billno_label.grid(row=0, column=4, padx=5, pady=10)
# Bill Number Input Field
billno_inp = Entry(frame2, width=22, font='Arial 15', textvariable=search_bill)
billno_inp.grid(row=0, column=5, pady=5, padx=2)
# Button of Bill Search
bill_button = Button(frame2, text='Search', width=10, font="Helvetica 10 bold", command=bill_search)
bill_button.grid(row=0, column=6, pady=7, padx=15)
# =============== Item Details Frame =============== #
# Frame Main
main_frame = Frame(root, bg=bg_color)
main_frame.pack(side=TOP)
# Frame 3
frame3 = LabelFrame(main_frame, text='Item Details', font='Helvetica 13 bold', fg=title_color, bg=bg_color)
frame3.pack(side=LEFT, padx=50)
# Select Categories Label
categories_label = Label(frame3, text="Select Category: ", font="Fira_Mono 16 bold", bg=bg_color, fg='white')
categories_label.grid(row=0, column=0, padx=25, pady=15)
# Categories Option List and Drop Down list
categories_drop = ttk.Combobox(frame3, width=37, textvariable=clicked)
categories_drop['values'] = ("Groceries", "Cosmetics", "Others")
categories_drop.grid(row=0, column=1, padx=2, pady=5)
categories_drop.bind("<<ComboboxSelected>>", select_categories)
# Select Product Label
product_label = Label(frame3, text="Select Product: ", font="Fira_Mono 16 bold", bg=bg_color, fg='white')
product_label.grid(row=1, column=0, padx=25, pady=25)
# Product Option List and Drop Down list
grocery_product = ["Rice", "Wheat", "Sugar", "Oil"]
cosmetic_product = ["Soap", "Cream", "Face Wash", "Body Wash"]
other_product = ["Waffers", "Biscuits", "Cold Drink", "Namkeen"]
product_drop = ttk.Combobox(frame3, width=37, textvariable=clicked1, value=[" "])
product_drop.grid(row=1, column=1, padx=2, pady=25)
# Quantity Label
quantity_label = Label(frame3, text='Quantity: ', font="Fira_Mono 16 bold", bg=bg_color, fg='white')
quantity_label.grid(row=2, column=0, padx=25, pady=25)
# Quantity Input Field
quantity_inp = Entry(frame3, width=22, font='Arial 15', textvariable=qty)
quantity_inp.grid(row=2, column=1, padx=25, pady=25)
# Add to Cart Button
atc_button = Button(frame3, text='Add To Card', width=18, font="Helvetica 13 bold", command=add_cart)
atc_button.grid(row=3, column=0, padx=25, pady=25)
# Clear Cart Button
clearct_button = Button(frame3, text='Clear', width=18, font="Helvetica 13 bold", command=clear_crt)
clearct_button.grid(row=3, column=1, padx=25, pady=30)
# =============== Bill Frame =============== #
# frame 5
frame5 = Frame(main_frame, bd=5, relief=GROOVE)
frame5.pack(side=RIGHT, padx=50)
# Bill Title Label
bill_title = Label(frame5, text='Bill Area', font='arial 15 bold', bd=5, relief=GROOVE)
bill_title.pack(fill='x')
# Text Area And Scrollbar
scroll_y = Scrollbar(frame5, orient=VERTICAL)
txtarea = Text(frame5, yscrollcommand=scroll_y.set, width=54, height=19)
scroll_y.pack(side=RIGHT, fill='y')
scroll_y.config(command=txtarea.yview)
txtarea.pack()
# =============== Total and Tax Frame =============== #
# Frame 6
full_frame = LabelFrame(root, text='Bill Options', font='Helvetica 13 bold', fg=title_color, bg=bg_color)
full_frame.pack(side=BOTTOM, pady=15)
frame6 = Frame(full_frame, bg=bg_color)
frame6.pack(side=LEFT)
price_total = Label(frame6, text='Total Amount: ', font="Fira_Mono 15 bold", bg=bg_color, fg='white')
price_total.grid(row=0, column=0, padx=20, pady=10, sticky='w')
price_total_txt = Entry(frame6, width=15, font="Fira_Mono 16 bold", textvariable=all_total)
price_total_txt.grid(row=0, column=1, padx=5, pady=10)
tax_total = Label(frame6, text='Total Tax: ', font="Fira_Mono 15 bold", bg=bg_color, fg='white')
tax_total.grid(row=0, column=2, padx=20, pady=10, sticky='w')
tax_total_txt = Entry(frame6, width=15, font="Fira_Mono 16 bold", textvariable=all_tax)
tax_total_txt.grid(row=0, column=3, padx=5, pady=10)
# Net Amount Label
net_amt = Label(frame6, text='Net Amount', font="Fira_Mono 15 bold", bg=bg_color, fg='white')
net_amt.grid(row=1, column=1, padx=50, pady=15)
# Net amount Text field
net_amt_txt = Entry(frame6, width=20, font="Fira_Mono 16 bold", textvariable=net_amt_var)
net_amt_txt.grid(row=1, column=2, padx=5, pady=10)
# =============== Button Frame =============== #
# Frame 7
frame7 = Frame(full_frame, relief=GROOVE, bg=bg_color)
frame7.pack(side=RIGHT, padx=25, pady=5)
# Total Button
total_button = Button(frame7, text='Total', width=16, height=3, font="Helvetica 10 bold", bg=bg_color3, fg='white', command=display_total)
total_button.grid(row=0, column=0, padx=5)
# Generate Bill Button
generatebill_button = Button(frame7, text='Generate Bill', width=16, height=3, font="Helvetica 10 bold", bg=bg_color3, fg='white', command=bill_area)
generatebill_button.grid(row=0, column=1, padx=15, pady=5)
# Clear Button
clear_button = Button(frame7, text='Clear', width=16, height=3, font="Helvetica 10 bold", bg=bg_color3, fg='white', command=clear_all)
clear_button.grid(row=1, column=0, padx=25)
# Exit Button
exit_button = Button(frame7, text='Exit', width=16, height=3, font="Helvetica 10 bold", bg=bg_color3, fg='white', command=exit_window)
exit_button.grid(row=1, column=1, padx=5)
# Calling Funtions Starts Here #
bill_txt() # Calling bill_txt to print default Bill Data
display_date() # Calling display_date to show date at top right
clock() # Calling clock to show current time at top left
root.mainloop()