-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGUI.py
2336 lines (1945 loc) · 76.8 KB
/
GUI.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
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# GUI Source Code
""" Import Section """
import modules.Install as Ins
Ins.install()
try:
from modules.SQL_IDGenrate import supp_gen, prod_gen, cust_gen
except:
raise SystemExit
from modules.SQL_Update import Update_row, Update_column
from modules.SQL_Entry import Create
from modules.SQL_Check import Check_Database
from time import strftime as stime
import mysql.connector as mysql
from tkinter import messagebox
import modules.SQL_Pass as Pas
from datetime import datetime
from modules.PDF import Pdf
from tkinter import ttk
from tkinter import *
""" Constants """
pas, us = Pas.Pass()
bgcol:str = "#add8e6"
Company:str = "A. Somasundara Nadar & Co."
text_format:tuple = ("arial", 14)
unitlst:tuple = ('Select Unit', 'Kgs', 'Nos')
button_format:dict = {"bg":"brown", "fg":"white", "font":text_format}
DB:dict[str,str] = {"user": us, "passwd": pas, "database": "project", "host": "localhost"}
gstlst:tuple = ('Select GST Rate', '00.00 %', '05.00 %', '12.00 %', '18.00 %', '28.00 %')
""" Working Lists/Dicts """
supplst: list[str] = [] # To select supplier in product Add
prodlst: list[str] = [] # To show product in Bill
custlst: list[str] = [] # To show customer in Bill
prodname:dict = {} # {PID:Name} To Display in modify screen
suppname:dict = {} # {SID:Name} To Display in modify screen
prodqty:dict = {} # {PID:Qty} To Check Avaible Stock
""" Other Functions """
def Helpwind(): # Help Window
import modules.Help
modules.Help.Help()
def sql_data_create(): # Create database
from modules.SQL_Datacreate import SQL
SQL(us, pas)
sql_csv()
Update_lst(4)
def exit_prog(): # Exit Program
ask_exit = messagebox.askquestion("Exit", "Do You Want To Exit Application ?")
if ask_exit == 'yes':
window.destroy()
else:
pass
def printf(filename): # Print Bills
import os
os.startfile(filename, 'print')
def PDF(Bill): # Genrate Bill
Pdf(Bill, us, pas)
def sql_csv(): # Genrate CSV File
cc = messagebox.askquestion("Bulk Data Entry", "Do you want to add Data from file?")
if cc == 'yes':
window1 = Tk()
window1.title('Bulk Data Entry')
window1.config(bg=bgcol)
window1.focus_force()
window1.iconbitmap(r'modules/1.ico')
import modules.SQL_CSV as SQL0
def imp():
SQL0.Read_csv(us, pas)
Update_lst(4)
window1.destroy()
def cancel():
SQL0.Delfile()
window1.destroy()
SQL0.New_csv()
from os import startfile as strfile
strfile("Details.csv")
f = f"\nFile Created. Now Enter Data and click on Import Data when done."
lab = Label(window1, text=f, bg=bgcol, font=text_format)
lab.pack(padx=20)
f = f"Only Supplier name is required for multiple products of same supplier."
lab1 = Label(window1, text=f, bg=bgcol, font=text_format)
lab1.pack(pady=10, padx=20)
button0 = Button(window1, text="Import Data", **button_format, command=imp)
button0.pack(padx=10)
button1 = Button(window1, text="Cancel Import", **button_format, command=cancel)
button1.pack(pady=10, padx=10)
def Update_lst(what): # Genrate Alpha List
"""
Genrate Alpha List What value:
1 - genrate list of supplier
2 - genrate list of product
3 - genrate list of bill
4 - genrate list of all
5 - genrate list of product qty
6 - genrate list of customer name
"""
demodb = mysql.connect(**DB)
cursor = demodb.cursor()
global supplst, prodlst, prodname, suppname, prodqty, custlst
prodname = {}
prodqty = {}
prodlst = ['Select Product']
supplst = ['Select Supplier']
custlst = ['Select/Type Name']
if what==1: # supplier
cursor.execute(f"SELECT SuppID,SuppName FROM supplier where Hide='N'")
supplier = list(cursor.fetchall())
for i in supplier:
ABC = f'{i[0]} - {i[1]}'
suppname[i[0]] = i[1]
supplst.append(ABC)
elif what==2: # product
cursor.execute(f"SELECT ProdID,Name FROM product where Hide='N'")
product = list(cursor.fetchall())
for i in product:
prodname[i[0]] = i[1]
elif what==3: # bill
cursor.execute(f"select Name from product where Stock>0")
bill = list(cursor.fetchall())
for i in bill:
prodlst.append(i[0])
elif what==5: # Product Qty
cursor.execute(f"select ProdID, Stock from product where Stock>0")
Qty = list(cursor.fetchall())
for i in Qty:
prodqty[i[0]] = i[1]
elif what==6: # Customer Name
cursor.execute(f"select Name from cust")
cust = list(cursor.fetchall())
for i in cust:
custlst.append(i[0])
elif what==4: # All
cursor.execute(f"SELECT SuppID,SuppName FROM supplier where Hide='N'")
supplier = list(cursor.fetchall())
for i in supplier:
ABC = f'{i[0]} - {i[1]}'
suppname[i[0]] = i[1]
supplst.append(ABC)
cursor.execute(f"SELECT ProdID,Name FROM product where Hide='N'")
product = list(cursor.fetchall())
for i in product:
prodname[i[0]] = i[1]
cursor.execute(f"select Name from product where Stock>0")
bill = list(cursor.fetchall())
for i in bill:
prodlst.append(i[0])
cursor.execute(f"select ProdID, Stock from product where Stock>0")
Qty = list(cursor.fetchall())
for i in Qty:
prodqty[i[0]] = i[1]
cursor.execute(f"select Name from cust")
cust = list(cursor.fetchall())
for i in cust:
custlst.append(i[0])
demodb.close()
def Main(): # Home Screen
option = {1: Main_Add, 2: Main_Mod, 3: Bill, 4: Main_View}
right.grid(column=0,row=1,padx=0,pady=0)
right0 = Frame(right, bd=2, relief=SOLID, padx=50, pady=50)
right0.pack(pady=20)
lab = Label(window, text= Company, bg=bgcol, font=("arial-bold", 25))
lab.grid(column=0,row=0,ipadx=275,ipady=20)
def Comon(v):
right0.destroy()
dictt = option.get(v)
dictt()
lab.destroy()
b0 = Button(right0, text="Add", width=12, **button_format, command=lambda *args: Comon(1))
b0.grid(row=0, column=0, padx=10, pady=10)
b1 = Button(right0, text="Update", width=12, **button_format, command=lambda *args: Comon(2))
b1.grid(row=1, column=0, padx=10, pady=10)
b3 = Button(right0, text="View", width=12, **button_format, command=lambda *args: Comon(4))
b3.grid(row=2, column=0, padx=10, pady=5)
b2 = Button(right0, text="Bill", width=12, **button_format, command=lambda *args: Comon(3))
b2.grid(row=3, column=0, padx=10, pady=10)
b4 = Button(right0, text="Exit", **button_format, width=12, command=exit_prog)
b4.grid(row=4, column=0, padx=10, pady=5)
def Bill(): # Billing mode
right.place(x=75, y=35)
right1 = Frame(right, bd=2, relief=SOLID, padx=20, pady=20)
right1.pack()
down = Frame(right1, bd=1, relief=SOLID)
down.grid(row=1, column=1, sticky=W, pady=5)
side = Frame(right1)
side.grid(row=0, column=0, rowspan=2)
up = Frame(right1)
up.grid(row=0, column=1, sticky=W)
sel = None
sel_tup = None
bill_total = 0.0
Bal = DoubleVar() # Bill Ballance
Qty = StringVar() # Product Qty
Typ = StringVar() # Bill Payment Type
Adv = StringVar() # Bill Pay in Advance
Total = DoubleVar() # Bill After Dicount
Dis_ru = StringVar() # Discount ₹
data = list(prodlst) # Product Name Working
b_items = [] # Bill items in dict form -> {ProdID:(ProdName,Qty,Gst,Unit,Rate,Price)}
Dis_per = StringVar() # Discount %
Pname = list(prodlst) # Product Name main
Typ.set('Full')
""" Other Interface """
def Clear(): # Clear Interface
right1.destroy()
Update_lst(4)
Bill()
def Close(): # Close Interface
right1.destroy()
Main()
def clock(): # Clock Function
stri = f"Time:\t{stime('%I:%M:%S %p')}"
label.config(text=stri)
label.after(1000, clock)
def Custdrop(): # Custname DropBox
eCName.event_generate ('<Down>', when='head')
def Proddrop(): # Prodname DropBox
ePName.event_generate ('<Down>', when='head')
""" CallBack Function """
def Next_Prod(event):
ePName.focus()
def Next_Qty(event):
eQty.focus()
def Next_Prod1(event):
ePName.focus()
Add()
def Next_dis(event):
eBdis_r.focus()
def Adv_pay(event):
val = float(Adv.get())
btotal = Total.get()
if not val:
val='0.0'
if Total.get()<float(val):
messagebox.showerror("Negetive Ruprees", "Please Enter advance less than total !!!!")
Adv.set('')
return
if Total.get()!=0.0:
btotal = round(btotal-float(val),2)
Bal.set(btotal)
eBtot.configure(text=f"₹{Bal.get()}")
def Next_Modify(event):
Modify()
def Or_Dis_p(event):
Dis_ru.set('')
eBdis_p.focus()
def Or_Dis_r(event):
Dis_per.set('')
eBdis_r.focus()
def Dis_perc(event):
val = Dis_per.get()
if not val:
val='0.0'
if float(val)>100.0:
messagebox.showerror("Negetive Ruprees", "Please Enter discount(%) between 0 to 100 !!!!")
Dis_per.set('')
return
if Total.get()!=0.0:
Discount(1,val)
Credit()
eType1.focus()
def Dis_rup(event):
val = Dis_ru.get()
if not val:
val='0.0'
if Total.get()<float(val):
messagebox.showerror("Negetive Ruprees", "Please Enter discount(₹) less than total !!!!")
Dis_ru.set('')
return
if Total.get()!=0.0:
Discount(2,val)
Credit()
eType1.focus()
def checkout(event):
Check()
""" Calculate """
def ProdN(event): # Prodname search
value = ePName.get()
nonlocal Pname
if value == '' or value == 'Select Product':
data = Pname
else:
data = []
for item in Pname:
if value.lower() in item.lower():
data.append(item)
ePName.config(values=data)
ePName.after(750,Proddrop)
def CustN(event): # Custname search
value:str = eCName.get()
if value == '':
eCName.config(values=custlst)
else:
CName = []
for item in custlst:
if value.lower() in item.lower():
CName.append(item)
CName.insert(0,value)
eCName.config(values=CName)
def Discount(typ:int,val:str|float): # Calculate discount
val = float(val)
btotal = float(bill_total)
if typ==1: #calc %
dis_ru = str(round((val/100)*btotal,2))
btotal=round(btotal-float(dis_ru),2)
Dis_ru.set(dis_ru)
else: #calc ₹
dis_per = str(round((val*100)/btotal,2))
btotal=round(btotal-val,2)
Dis_per.set(dis_per)
Total.set(btotal)
eBnet.configure(text=f"₹{Total.get()}")
def Credit(): # Credit
if Typ.get() == "Full" :
eType1.config(bg='light gray')
eType2.config(bg='SystemButtonFace')
Adv.set("")
ePay.config(state="disabled")
else:
eType1.config(bg='SystemButtonFace')
eType2.config(bg='light gray')
ePay.config(state="normal")
ePay.focus()
""" Side Panel """
def Add(): # Add Element
# Preprocessing Part
if ePName.get() == 'Select Product':
messagebox.showerror("Select Product", "Please Select Product")
return
try:
int(eQty.get())
except ValueError:
messagebox.showerror("No Qty", "Please Enter Product Qty")
eQty.focus()
return
pid:str = ""
name:str = ePName.get()
for ppid, pname in prodname.items():
if pname == name:
pid = ppid # Product ID
qty:int = int(eQty.get())
stk = Check_Database(1,(pid,qty),us,pas)
if not stk[0]:
messagebox.showerror("Insuffient Stock", f"You dont have enough stock of {name}.\n Stock Availble = {stk[1]}")
eQty.focus()
Qty.set('')
return
stk = stk[1]
# Processing Part
demodb = mysql.connect(**DB)
cursor = demodb.cursor()
cursor.execute(f"SELECT GST, Unit, SP FROM product where ProdID='{pid}'")
det = cursor.fetchone()
demodb.close()
price = round((det[2]*qty)+((det[2]*qty)*(float(det[0]))/100),2)
tup = (name,qty,det[0],det[1],det[2],price)
# Postprocessing Part
b_items.append({pid:tup})
tv.insert('', 'end', values=tup) # For Display Table
tv.yview_moveto(1)
nonlocal bill_total
bill_total = bill_total + price
Total.set(Total.get()+price)
eBnet.configure(text=f"₹{Total.get()}")
Qty.set("")
Pname.remove(name)
ePName.config(values=Pname)
ePName.current(0)
def Delete(): # Remove Element
if tv.focus() == '':
return
x = tv.focus()
aa = tv.item(x)['values'] # (Name,qty,gst,unit,rate,price)
name, qty, gst, unit, sp, price = aa
sp = float(sp)
price = float(price)
pid = ''
for ppid, pname in prodname.items():
if pname == name:
pid = ppid
break
b_items.remove({pid: (name, qty, gst, unit, sp, price)})
Total.set(Total.get() - float(price))
eBnet.configure(text=f"₹{Total.get()}")
Pname.append(name)
ePName.config(values=Pname)
ePName.current(0)
tv.delete(x)
def Modify(): # Edit Qty
if tv.focus() == '':
return
nonlocal sel,sel_tup
select = tv.focus()
if sel!=select: # Modified
sel = select
sel_tup = tv.item(select)['values'] # (Name,qty,gst,unit,rate,price)
Qty.set(sel_tup[1])
button1.config(text='Save Edit')
eQty.focus()
eQty.bind('<Return>', Next_Modify)
return
sp = float(sel_tup[4])
gst = float(sel_tup[2])
new = int(Qty.get())
old_price = float(sel_tup[5])
pid = ""
for ppid, pname in prodname.items():
if pname == sel_tup[0]:
pid = ppid
break
stk = Check_Database(1, (pid, new), us, pas)
if not stk[0]:
messagebox.showerror("Insufficient Stock", f"Not enough stock of {new}.\nAvailable stock = {stk[1]}")
return
sel_tup[5] = float(sel_tup[5])
sel_tup[4] = float(sel_tup[4])
index = b_items.index({pid:tuple(sel_tup)})
sel_tup[1] = new
new_price = round((sp * new) + ((sp * new) * (gst) / 100), 2)
sel_tup[5] = new_price
b_items[index] = {pid:tuple(sel_tup)}
tv.item(sel, text="", values=sel_tup)
Total.set((Total.get()-old_price)+new_price)
eBnet.configure(text=f"₹{Total.get()}")
button1.config(text='Edit Qty')
eQty.bind('<Return>', Next_Prod1)
ePName.focus()
return
def Check(): # Check Before Billing
cc = messagebox.askquestion("Procced to Bill","Procced to Bill?")
if cc == 'no':
return
# Preprocessing part
CustName = eCName.get()
if CustName == '' or CustName == 'Select/Type Name':
messagebox.showerror("Unknown Customer", "Please Enter Customer Name")
eCName.focus()
return
if CustName not in custlst:
cid = cust_gen(CustName, us, pas)
Update_lst(6)
count = 0
else:
cid,count = Check_Database(2,(CustName,stime('%Y-%m-%d')),us,pas)
count += 1
BillDate = f'{stime("%Y-%m-%d %H:%M:%S")}'
balance = Bal.get()
total = Total.get()
b_paid = total-balance
Type = 'Cash' if Typ.get()=="Full" else 'Credit'
# Processing part
if count == 0:
Create(5,(cid,CustName,1,balance,total),us,pas)
count=1
BillNos = f'{stime('%y%m%d')}{cid}-{count}'
else:
Update_column(4,(cid,balance,total),us,pas)
BillNos = f'{stime('%y%m%d')}{cid}-{count}'
dis_per = Dis_per.get() if Dis_per.get() else '0.0'
dis_ru = Dis_ru.get() if Dis_ru.get() else '0.0'
Create(3,(BillNos,cid,Type,BillDate,len(b_items),b_paid,dis_per,dis_ru,total,balance),us,pas)
count=1
for i in b_items: # i = {ProdID:(ProdName,Qty,Gst,Unit,Rate,Price)}
pid,tup = list(i.items())[0]
Update_column(1,(pid,tup[1]),us,pas)
Create(4,(BillNos,pid,tup[1],tup[5],count),us,pas)
count+=1
PDF(BillNos)
# Postprocessing part
QA = messagebox.askquestion("Print Pdf", f"Bill has been genrated.\nDo you want to print bill?")
if QA == 'yes':
filename = str(f'Bills\\Invoice {BillNos}.pdf')
printf(filename)
Clear()
lCName = Label(up, text="Customer Name:", font=text_format)
lCName.grid(row=0, column=0, sticky=W)
eCName = ttk.Combobox(up, values=custlst)
eCName.grid(row=0, column=1, pady=5, padx=10)
eCName.configure(width=16, font=text_format)
eCName.current(0)
eCName.bind('<KeyRelease>', CustN)
eCName.bind('<Return>', Next_Prod)
eCName.after(750,Custdrop)
eCName.focus()
label = Label(up, font=text_format) # For Clock
label.grid(row=0, column=2, sticky=W, columnspan=2)
clock()
lPName = Label(up, text="Product Name:", font=text_format)
lPName.grid(row=1, column=0, sticky=W)
ePName = ttk.Combobox(up, values=data)
ePName.current(0)
ePName.configure(width=16, font=text_format)
ePName.grid(row=1, column=1, pady=5, padx=10)
ePName.bind('<KeyRelease>', ProdN)
ePName.bind('<Return>', Next_Qty)
ePName.bind('<Shift_L>', Next_dis)
ePName.bind('<Shift_R>', Next_dis)
lQty = Label(up, text="Quantity:", font=text_format)
lQty.grid(row=1, column=2, sticky=W)
eQty = Entry(up, textvariable=Qty, width=7, font=text_format)
eQty.grid(row=1, column=3, sticky=W, padx=10, pady=5)
eQty.bind('<Return>', Next_Prod1)
eQty.bind('<Shift_L>', Next_dis)
eQty.bind('<Shift_R>', Next_dis)
lBdis_r = Label(up, text="Discount(₹):", font=text_format)
lBdis_r.grid(row=2, column=0, sticky=W)
eBdis_r = Entry(up, textvariable=Dis_ru, width=7, font=text_format)
eBdis_r.grid(row=2, column=1, sticky=W, padx=10, pady=5)
eBdis_r.bind('<Return>', Dis_rup)
eBdis_r.bind('<Shift_L>', Or_Dis_p)
eBdis_r.bind('<Shift_R>', Or_Dis_p)
lBdis_p = Label(up, text="Discount(%):", font=text_format)
lBdis_p.grid(row=2, column=2, sticky=W)
eBdis_p = Entry(up, textvariable=Dis_per, width=7, font=text_format)
eBdis_p.grid(row=2, column=3, sticky=W, padx=10, pady=5)
eBdis_p.bind('<Return>', Dis_perc)
eBdis_p.bind('<Shift_L>', Or_Dis_r)
eBdis_p.bind('<Shift_R>', Or_Dis_r)
lType = Label(up, text="Payment Type:", font=text_format)
lType.grid(row=3, column=0, sticky=W)
eType1 = Radiobutton(up, text="Full", variable=Typ, value="Full", font=text_format, command=Credit)
eType1.grid(row=3, column=1, sticky=W, pady=5)
eType2 = Radiobutton(up, text="Part", variable=Typ, value="Part", font=text_format, command=Credit)
eType2.grid(row=3, column=1, sticky=E, padx=10)
lPay = Label(up, text="Advance:", font=text_format)
lPay.grid(row=3, column=2, sticky=W)
ePay = Entry(up, textvariable=Adv, width=7, font=text_format)
ePay.grid(row=3, column=3, sticky=W, padx=10, pady=5)
ePay.config(state="disabled")
ePay.bind('<Return>', Adv_pay)
ePay.bind('<Shift_L>', checkout)
ePay.bind('<Shift_R>', checkout)
lBnet = Label(up, text="Bill Total:", font=text_format)
lBnet.grid(row=4, column=0, sticky=W)
eBnet = Label(up, text=f"₹{Total.get()}", font=text_format)
eBnet.grid(row=4, column=1, sticky=W, padx=10, pady=5)
lBtot = Label(up, text="Balance:", font=text_format)
lBtot.grid(row=4, column=2, sticky=W)
eBtot = Label(up, text=f"₹{Bal.get()}", font=text_format)
eBtot.grid(row=4, column=3, sticky=W, padx=10, pady=5)
scroll = Scrollbar(down)
scroll.pack(side=RIGHT, fill=Y)
tv = ttk.Treeview(down, columns=('col0', 'col1', 'col2', 'col3', 'col4', 'col5'),
show='headings', height=10, yscrollcommand=scroll.set, style="mystyle.Treeview")
tv.pack()
scroll.config(command=tv.yview)
tv.heading('col0', text='Product Name')
tv.heading('col1', text='Qty')
tv.heading('col2', text='GST')
tv.heading('col3', text='Unit')
tv.heading('col4', text='Rate')
tv.heading('col5', text='Price')
tv.column('col0', anchor=CENTER, width=175)
tv.column('col1', anchor=CENTER, width=60)
tv.column('col2', anchor=CENTER, width=60)
tv.column('col3', anchor=CENTER, width=60)
tv.column('col4', anchor=CENTER, width=100)
tv.column('col5', anchor=CENTER, width=100)
button0 = Button(side, text="Add", **button_format, width=12, command=Add)
button0.grid(row=0, column=0, sticky=W, pady=10, padx=10)
button1 = Button(side, text="Edit Qty", **button_format, width=12 ,command=Modify)
button1.grid(row=1, column=0, sticky=W, pady=10, padx=10)
button2 = Button(side, text="Delete", **button_format, width=12, command=Delete)
button2.grid(row=2, column=0, sticky=W, pady=10, padx=10)
button3 = Button(side, text="Check Out", **button_format, width=12, command=Check)
button3.grid(row=3, column=0, sticky=W, pady=10, padx=10)
button3 = Button(side, text="Clear", **button_format, width=12, command=Clear)
button3.grid(row=4, column=0, sticky=W, pady=10, padx=10)
button5 = Button(side, text="Home", **button_format, width=12, command=Close)
button5.grid(row=5, column=0, sticky=E, pady=10, padx=10)
""" Add Function """
def Main_Add(): # Select what to Add
option = {1: Suppliers_Add, 2: Products_Add, 3: Main}
right.grid(row=0,column=0,padx=350,pady=80)
right2 = Frame(right, bd=2, relief=SOLID, padx=50, pady=50)
right2.pack()
l0 = Label(right2, text="New", font=("arial-bold", 25))
l0.grid(row=0, column=0, padx=10, pady=10)
def Comon(v):
right2.destroy()
dictt = option.get(v)
dictt()
b1 = Button(right2, text="Supplier", width=12, **button_format, command=lambda *args: Comon(1))
b1.grid(row=1, column=0, padx=10, pady=10)
b2 = Button(right2, text="Product", width=12, **button_format, command=lambda *args: Comon(2))
b2.grid(row=2, column=0, padx=10, pady=10)
b4 = Button(right2, text="Home", width=12, **button_format, command=lambda *args: Comon(3))
b4.grid(row=4, column=0, padx=10, pady=10)
l3 = Label(right2, text=" ", font=text_format)
l3.grid(row=3, column=0, padx=10, pady=11)
def Suppliers_Add(): # Add supplier
right.grid(row=0,column=0,padx=220,pady=55)
SuppID = supp_gen(us, pas)
right1 = Frame(right, bd=2, relief=SOLID, padx=50, pady=50)
right1.pack()
def Close():
right1.destroy()
Main()
def Back():
right1.destroy()
Main_Add()
def Save(tup):
Create(1, tup, us, pas)
supplst.append(f"{tup[0]} - {tup[1]}")
right1.destroy()
Suppliers_Add()
def Show(tup0):
SuppName, SuppAdd, SuppPhone, SuppEmail = tup0
SuppName = SuppName.title()
SuppAdd = SuppAdd.title()
Name.set(SuppName)
Adr.set(SuppAdd)
eName.config(state='disabled')
eAdd.config(state='disabled')
ePhone.config(state='disabled')
eEmail.config(state='disabled')
tup = (SuppID, SuppName, SuppAdd, SuppPhone, SuppEmail)
def OK():
Save(tup)
def callback(event):
OK()
right1.focus_set()
right1.bind('<Return>', callback)
button1.configure(text="All Ok! Lets save it", command=OK, width=15)
def Check():
phone, email = Phone.get(), Email.get()
adr = eAdd.get(1.0, END).strip()
Adr.set(adr)
a = 0
if email == '':
pass
elif '@' not in email or '.' not in email:
Email.set("")
eEmail.focus()
a = 1
if not phone.isdigit():
Phone.set("")
ePhone.focus()
a = 1
if a == 1:
messagebox.showerror("Wrong Format", "Wrong Format\nCheck Again")
elif a == 0:
Show(tuple([Name.get(), Adr.get(), Phone.get(), Email.get()]))
ID = StringVar()
Name = StringVar()
Adr = StringVar()
Phone = StringVar()
Email = StringVar()
ID.set(SuppID)
lID = Label(right1, text="Supplier ID", font=text_format)
lID.grid(row=0, column=0, sticky=W)
eID = Entry(right1, textvariable=ID, state='disabled', font=text_format)
eID.grid(row=0, column=1, sticky=W, padx=10, pady=10)
lName = Label(right1, text="Supplier Name", font=text_format)
lName.grid(row=1, column=0, sticky=W)
eName = Entry(right1, textvariable=Name, font=text_format)
eName.grid(row=1, column=1, sticky=W, padx=10, pady=10)
eName.focus()
lAdd = Label(right1, text="Supplier Address", font=text_format)
lAdd.grid(row=2, column=0, sticky=W)
eAdd = Text(right1, width=20, height=3, font=text_format)
eAdd.grid(row=2, column=1, sticky=W, padx=10, pady=10)
lPhone = Label(right1, text="Supplier Phone No.", font=text_format)
lPhone.grid(row=3, column=0, sticky=W)
ePhone = Entry(right1, textvariable=Phone, font=text_format)
ePhone.grid(row=3, column=1, sticky=W, padx=10, pady=10)
lEmail = Label(right1, text="Supplier Email", font=text_format)
lEmail.grid(row=4, column=0, sticky=W)
eEmail = Entry(right1, textvariable=Email, font=text_format)
eEmail.grid(row=4, column=1, sticky=W, padx=10, pady=10)
def callback0(event):
eAdd.focus()
eName.bind('<Return>', callback0)
def callback1(event):
ePhone.focus()
eAdd.bind('<Return>', callback1)
def callback2(event):
eEmail.focus()
ePhone.bind('<Return>', callback2)
def callback3(event):
Check()
eEmail.bind('<Return>', callback3)
button1 = Button(right1, text="Check", width=7, **button_format, command=Check)
button1.grid(row=5, column=0, pady=10, columnspan=2, padx=10)
button3 = Button(right1, text="Back", width=5, **button_format, command=Back)
button3.grid(row=5, column=0, pady=10, padx=10, sticky=W)
button2 = Button(right1, text="Home", width=5, **button_format, command=Close)
button2.grid(row=5, column=1, pady=10, padx=10, sticky=E)
def Products_Add(): # Add product
right.grid(row=0,column=0,padx=220,pady=25)
right1 = Frame(right, bd=2, relief=SOLID, padx=50, pady=20)
right1.pack()
global prodlst, prodname
def Close():
right1.destroy()
Main()
def Back():
right1.destroy()
Main_Add()
def Save(tup1):
Create(2, tup1, us, pas)
prodname.update({tup1[1]:tup1[2]})
prodlst.append(tup1[2])
Close()
def Show(tup0):
SuppID, ProdID, ProdName, ProdCost, ProdRate, ProdGST, ProdStock, ProdUnit = tup0
ProdName = ProdName.title()
ProdUnit = ProdUnit.title()
Name.set(ProdName)
Cost.set(ProdCost)
Rate.set(ProdRate)
GST.set(ProdGST)
Unit.set(ProdUnit)
Stock.set(ProdStock)
eName.config(state='disabled')
eCost.config(state='disabled')
eRate.config(state='disabled')
eGST.config(state='disabled')
eUnit.config(state='disabled')
eStock.config(state='disabled')
eSID.config(state='disabled')
tup1 = (SuppID, ProdID, ProdName, ProdCost, ProdRate, ProdGST, ProdUnit, ProdStock)
def OK():
Save(tup1)
def callback(event):
OK()
right1.focus_set()
right1.bind('<Return>', callback)
button1.configure(text="All Ok! Lets save it", command=OK, width=15)
button2.configure(text="Cancel", command=Back)
def Check():
stock, rate, cost = Stock.get(), Rate.get(), Cost.get()
a = 0
SID.set(eSID.get())
GST.set(eGST.get())
Unit.set(eUnit.get())
SuppID = SID.get()[0:3]
if SuppID == 'Sel':
a = 1
eSID.focus()
gst = GST.get()[0:5]
if gst == 'Selec':
a = 1
eGST.focus()
if Unit.get() == 'Select Unit':
a = 1
eUnit.focus()
ProdID:str = prod_gen(SuppID, us, pas)
ID.set(ProdID)
if not stock.isdigit():
Stock.set("")
eStock.focus()
a = 1
try:
if float(rate):
pass
except ValueError:
Rate.set("")
eRate.focus()
a = 1
try:
if float(cost):
pass
except ValueError:
Cost.set("")
eCost.focus()
a = 1
if a == 1:
messagebox.showerror("Wrong Format", "Wrong Format\nCheck Again")
if a == 0:
Show(tuple([SuppID, ProdID, Name.get(), Cost.get(), Rate.get(), gst, Stock.get(), Unit.get()]))
ID = StringVar()
Name = StringVar()
Cost = StringVar()
Rate = StringVar()
GST = StringVar()
Unit = StringVar()
Stock = StringVar()
SID = StringVar()
lSID = Label(right1, text="Supplier", font=text_format)
lSID.grid(row=0, column=0, sticky=W)
eSID = ttk.Combobox(right1, values=supplst)
eSID.config(width=18)
eSID.config(font=text_format)
eSID.current(0)
eSID.grid(row=0, column=1, padx=10, pady=10)
eSID.config(state='readonly')
eSID.focus()
lID = Label(right1, text="Product ID", font=text_format)
lID.grid(row=1, column=0, sticky=W)
eID = Entry(right1, textvariable=ID, state='disabled', font=text_format)
eID.grid(row=1, column=1, sticky=W, padx=10, pady=10)
lName = Label(right1, text="Product Name", font=text_format)
lName.grid(row=2, column=0, sticky=W)
eName = Entry(right1, textvariable=Name, font=text_format)
eName.grid(row=2, column=1, sticky=W, padx=10, pady=10)
lCost = Label(right1, text="Product Cost (CP)", font=text_format)
lCost.grid(row=3, column=0, sticky=W)
eCost = Entry(right1, textvariable=Cost, font=text_format)
eCost.grid(row=3, column=1, sticky=W, padx=10, pady=10)
lRate = Label(right1, text="Product Rate (SP)", font=text_format)
lRate.grid(row=4, column=0, sticky=W)
eRate = Entry(right1, textvariable=Rate, font=text_format)
eRate.grid(row=4, column=1, sticky=W, padx=10, pady=10)
lStock = Label(right1, text="Product Stock", font=text_format)
lStock.grid(row=5, column=0, sticky=W)
eStock = Entry(right1, textvariable=Stock, font=text_format)
eStock.grid(row=5, column=1, sticky=W, padx=10, pady=10)
lGST = Label(right1, text="Product GST(%)", font=text_format)
lGST.grid(row=6, column=0, sticky=W)
eGST = ttk.Combobox(right1, values=gstlst)
eGST.current(0)
eGST.config(width=18)
eGST.config(font=text_format)
eGST.grid(row=6, column=1, padx=10, pady=10)
eGST.config(state='readonly')
lUnit = Label(right1, text="Product Unit", font=text_format)
lUnit.grid(row=7, column=0, sticky=W)
eUnit = ttk.Combobox(right1, values=unitlst)
eUnit.config(width=18)
eUnit.current(0)
eUnit.config(font=text_format)
eUnit.grid(row=7, column=1, padx=10, pady=10)
eUnit.config(state='readonly')
def callback0(event):
eName.focus()
eSID.bind('<Return>', callback0)
def callback1(event):
eCost.focus()
eName.bind('<Return>', callback1)
def callback2(event):
eRate.focus()
eCost.bind('<Return>', callback2)
def callback3(event):
eStock.focus()
eRate.bind('<Return>', callback3)
def callback4(event):
eGST.focus()
eStock.bind('<Return>', callback4)
def callback5(event):