-
Notifications
You must be signed in to change notification settings - Fork 0
/
ph.py
1084 lines (844 loc) · 39.5 KB
/
ph.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
from tkinter import *
#python 39/scripts
#pip install Pillow
#pip install Prettytable
#pip install mysql-connector-python
from PIL import ImageTk,Image
from mysql.connector import *
from tkinter import messagebox
from tkinter import ttk
from prettytable import PrettyTable
from datetime import datetime
mydb = connect(host="localhost", user="root", password="tiger")
mycursor = mydb.cursor(buffered=1)
# Checking the databese
mycursor.execute("SHOW DATABASES")
databases = mycursor.fetchall()
if ("pharmacy",) in databases:
mycursor.execute("USE pharmacy")
mydb.commit()
else:
mycursor.execute("CREATE DATABASE pharmacy")
mycursor.execute("USE pharmacy")
mydb.commit()
# Checking the user table
mycursor.execute("SHOW TABLES")
tables = mycursor.fetchall()
if ('stocks',) in tables:
pass
else:
mycursor.execute("""
CREATE TABLE stocks(
med_id varchar(30) PRIMARY KEY,
med_name varchar(200),
amt int,
expiry date,
price float,
lot_no int
)""")
mydb.commit()
if ("users",) in tables:
pass
else:
mycursor.execute("""
CREATE TABLE users (
userID INTEGER PRIMARY KEY AUTO_INCREMENT,
name varchar(50),
username varchar(20),
password varchar(20)
)""")
mydb.commit()
mycursor.execute("insert into users values(1,'Admin','root','tiger')")
mycursor.execute("insert into users values(2,'Aditya Prabahkar','Adi','tiger')")
mydb.commit()
mycursor.close()
mydb.close()
allowentry=0
def LoginPage():
global allowentry
mydb = connect(host="localhost",database="pharmacy" ,user="root", password="tiger")
mycursor = mydb.cursor(buffered=1)
log=Tk()
log.title("pharma")
log.geometry("500x500+400+60")
log.resizable(False,False)
bgimg=ImageTk.PhotoImage(Image.open("pharma\\loginbg.png"))
log.configure(background="navajowhite")
log.iconbitmap("pharma\\sign-emergency-code-sos_24_icon-icons.com_57215.ico")
LoginFrame = Frame(log, bg="midnightblue")
limg=Label(LoginFrame,image=bgimg,borderwidth=0)
limg.place(x=0,y=0)
center=Frame(LoginFrame,borderwidth=0,bg="#0489A8")
LoginHeading = Label(LoginFrame, text="Log In", bg="#0B111D",height=1,fg='white',font=("Bahnschrift Light",30,""))
LoginHeading.pack(fill=X,side=TOP,pady=30)
userName = Label(center, text="Username:",font=("Bahnschrift Light",17,"bold underline"),fg="white",bg="#0489A8")
userName.grid(row=0,column=0,padx=22,pady=20,sticky="nsew")
usernameValue = Entry(center,width=16,font=("Calibri",15,"bold"),relief="flat")
usernameValue.grid(row=0,column=1,padx=0,pady=20,)
Password = Label(center, text="Password:",fg="white",bg="#0489A8",font=("Bahnschrift Light",17,"bold underline"))
Password.grid(row=2,column=0,padx=22,pady=20,sticky="nsew")
PasswordValue = Entry(center,width=16,font=("Calibri",15,"bold"),relief="flat",show="●")
PasswordValue.grid(row=2,column=1,padx=0,pady=20,)
def submit():
global allowentry
mycursor.execute("SELECT * FROM users WHERE username='{}' AND password='{}'".format(usernameValue.get(),PasswordValue.get()))
data = mycursor.fetchall()
if len(data)!=0:
allowentry=1
mycursor.close()
mydb.close()
log.destroy()
else:
messagebox.showinfo("Log-In Error","InValid Username or Password")
submitButton = Button(LoginFrame, text="Submit",command=submit,fg="white",height=0, bg="#0B111D",font=("Segoe UI",18,"bold"),borderwidth=0)
submitButton.pack(side=BOTTOM,expand=True,pady=20,fill=X)
center.pack(expand=1,fill=BOTH,padx=70,pady=50)
LoginFrame.pack(expand=1,fill=BOTH)
usernameValue.focus()
def efoc(e):
submit()
def pfoc(e):
PasswordValue.focus()
usernameValue.bind("<Return>",pfoc)
PasswordValue.bind("<Return>",efoc)
log.mainloop()
def check_float(s):
try:
float(s)
return True
except ValueError:
return False
def check_date(st):
s=1
if len(st)!=10:
s=0
elif st[4]!="-" or st[7]!="-":
s=0
elif st[:4].isdigit()==0 or st[8:].isdigit()==0 or st[5:7].isdigit()==0:
s=0
if s==1:
if int(st[5:7]) in (1,3,5,7,8,10,12):
maxdays=31
elif int(st[5:7]) in (4,6,9,11):
maxdays=30
elif int(st[:4])%4==0 and int(st[:4])%100!=0 or int(st[:4])%400==0:
maxdays=29
else:
maxdays=28
if int(st[5:7]) not in range(1,13):
s=0
elif int(st[8:]) not in range(1,maxdays+1):
s=0
if s==0:
return False
else:
return True
def launchapp():
#===================base window================
root=Tk()
root.title("pharma")
root.geometry("1230x600+60+50")
root.minsize(1230,600)
#root.resizable(False,False)
root.iconbitmap("pharma\\sign-emergency-code-sos_24_icon-icons.com_57215.ico")
root.configure()
#===============base window====================
mycon=connect(host="localhost",user="root",password="tiger",database="pharmacy")
cur=mycon.cursor(buffered=True)
global additemcount,bill_list
additemcount=1
bill_list=[]
def pay():
t=PrettyTable(["Product","Exp. Date","Qty.","Total Price"])
for i in bill_table.get_children():
vv=bill_table.item(i,"values")
med_id=vv[0]
qty=int(vv[5])
cur.execute("update stocks set amt=amt-%s where med_id=%s"%(qty,med_id) )
t.add_row([vv[2],vv[3],vv[5],vv[6]])
mycon.commit()
t.add_row(['','','',''])
t.add_row(['','','',''])
t.add_row(["",'','Grand Total:',str(grandtot())])
for j in bill_table.get_children():
bill_table.delete(j)
grandtot()
t_string=t.get_string()
bb1=0
for i in t_string:
if i=="\n":
break
bb1+=1
bb=(bb1-13)//2
p1=(bb)*"="+"|Pharma Bill|"+(bb1-bb-13)*"="+"\n\n"
p2="Time : "+datetime.now().strftime("%d %b, %Y %H:%M:%S")+"\n\n"
p3=("\n\n"+((bb1-24)//2)*" "+"Wishing You Good HEALTH."+" "*(bb1-((bb1-24)//2)))
f=open("kk.txt","w")
f.write(p1+p2+t_string+p3)
f.close()
showbill['state']='normal'
showbill.delete("1.0","end")
showbill.insert(INSERT,(p1+p2+t_string+p3))
showbill['state']='disabled'
show_frame(f_showbill)
cleardbill()
es_bill.delete(0,END)
global additemcount,bill_list
additemcount=1
bill_list=[]
def grandtot():
tot=0.00
for i in bill_table.get_children():
val=bill_table.item(i,"values")
tot+=float(val[6])
d_e8['state']='normal'
d_e8.delete(0,END)
d_e8.insert(0,tot)
d_e8['state']='readonly'
return tot
def del_item():
global bill_list
x=bill_table.selection()
for record in x:
v=bill_table.item(record,"values")
bill_list.remove(v[0])
bill_table.delete(record)
update_bill_table()
def search_bill(e):
typed=es_bill.get()
sbill_table.tag_configure("oddrow",background="white")
sbill_table.tag_configure("evenrow",background="plum")
l=["evenrow","oddrow"]
for record in sbill_table.get_children():
sbill_table.delete(record)
cur.execute("select* from stocks where med_name like "+'"'+typed+"%"+'"'+"and expiry>now() and amt>0 order by med_name")
tabledata=cur.fetchall()
i=0
for row in tabledata:
i=i+1
sbill_table.insert("",index=END,values=(row[0],row[1]),tags=(l[i%2],))
def cleardbill():
for i in [d_e0,d_e1,d_e2,d_e3,d_e4,d_e6]:
i['state']='normal'
d_e0.delete(0,END)
d_e1.delete(0,END)
d_e2.delete(0,END)
d_e3.delete(0,END)
d_e4.delete(0,END)
d_e5.delete(0,END)
d_e6.delete(0,END)
for i in [d_e0,d_e1,d_e2,d_e3,d_e4,d_e6]:
i['state']='readonly'
def select_sbill(e):
cleardbill()
selected=sbill_table.focus()
values=sbill_table.item(selected,"values")
if len(values)!=0:
cur.execute("select * from stocks where med_id="+"'"+values[0]+"'")
d=cur.fetchone()
for i in [d_e0,d_e1,d_e2,d_e3,d_e4,d_e6]:
i['state']='normal'
d_e0.insert(0,d[0])
d_e1.insert(0,d[1])
d_e2.insert(0,d[5])
d_e3.insert(0,d[3])
d_e4.insert(0,d[4])
for i in [d_e0,d_e1,d_e2,d_e3,d_e4,d_e6]:
i['state']='readonly'
d_e5.focus()
def d_e5check(e):
global bill_list
d_e6['state']='normal'
if d_e5.get().isdigit()==True and d_e0.get().isdigit()==True:
cur.execute("select amt,price from stocks where med_id="+"'"+d_e0.get()+"'")
d=cur.fetchone()
k=int(d[0])
if int(d_e5.get())>k and d_e0.get() not in bill_list:
messagebox.showerror("","only "+str(k)+" units available")
d_e5.delete(0,END)
d_e5.insert(0,k)
d_e6.delete(0,END)
d_e6.insert(0,int(d_e5.get())*d[1])
else:
d_e6.delete(0,END)
d_e6.insert(0,int(d_e5.get())*d[1])
if d_e0.get() in bill_list:
sum=0
for i in bill_table.get_children():
vv=bill_table.item(i,'values')
if d_e0.get()==vv[0]:
sum+=int(vv[5])
if int(d_e5.get())>(k-sum):
messagebox.showerror("","only "+str(k-sum)+" units available")
d_e5.delete(0,END)
d_e5.insert(0,k-sum)
d_e6.delete(0,END)
d_e6.insert(0,int(d_e5.get())*d[1])
else:
d_e6.delete(0,END)
d_e6.insert(0,int(d_e5.get())*d[1])
else:
if len(d_e5.get())!=0:
messagebox.showerror("","invalid Qty.")
d_e5.delete(0,END)
else:
d_e6.delete(0,END)
d_e6['state']='readonly'
def update_bill_table():
global additemcount
additemcount=1
l=["evenrow","oddrow"]
bill_table.tag_configure("oddrow",background="white")
bill_table.tag_configure("evenrow",background="thistle")
for i in bill_table.get_children():
bill_table.set(i,'#2',additemcount)
bill_table.item(i,tags=(l[additemcount%2],))
additemcount+=1
grandtot()
def additem():
l=["evenrow","oddrow"]
bill_table.tag_configure("oddrow",background="white")
bill_table.tag_configure("evenrow",background="thistle")
global additemcount,bill_list
if (d_e5.get()).isdigit()==True and (d_e0.get().isdigit()==True):
if int(d_e5.get())!=0:
bill_table.insert("",index=END,values=(d_e0.get(),additemcount,d_e1.get(),d_e3.get(),d_e4.get(),d_e5.get(),d_e6.get()),tags=(l[additemcount%2],))
additemcount+=1
bill_list.append(d_e0.get())
cleardbill()
es_bill.focus()
grandtot()
def de5foc(e):
additem()
def buttonstyle(nom):
nom['bg']='navyblue'
for b in [b1,b2,b3,b4]:
if b!=nom:
b['bg']="#2a57de"
def search_view(e):
search_view1()
def search_view1():
l=["evenrow","oddrow"]
typed=e_search.get()
ch_=choice_table.get()
clearview_table()
if typed=="":
if ch_=="All":
update_table()
elif ch_=="Expired Medicine":
cur.execute("select* from stocks where expiry < now() order by expiry desc")
tabledata=cur.fetchall()
i=0
for row in tabledata:
i=i+1
table.insert("",index=END,values=(i,row[0],row[1],row[3],row[5],row[2],row[4]),tags=(l[i%2],))
elif ch_=="Valid Medicine":
cur.execute("select* from stocks where expiry > now() order by med_name")
tabledata=cur.fetchall()
i=0
for row in tabledata:
i=i+1
table.insert("",index=END,values=(i,row[0],row[1],row[3],row[5],row[2],row[4]),tags=(l[i%2],))
else:
if ch_=="All":
cur.execute("select* from stocks where med_name like "+'"'+typed+"%"+'"'+"order by med_name")
tabledata=cur.fetchall()
i=0
for row in tabledata:
i=i+1
table.insert("",index=END,values=(str(i),row[0],row[1],row[3],row[5],row[2],row[4]),tags=(l[i%2],))
elif ch_=="Expired Medicine":
cur.execute("select* from stocks where expiry < now() and med_name like "+'"'+typed+"%"+'"'+"order by med_name")
tabledata=cur.fetchall()
i=0
for row in tabledata:
i=i+1
table.insert("",index=END,values=(i,row[0],row[1],row[3],row[5],row[2],row[4]),tags=(l[i%2],))
elif ch_=="Valid Medicine":
cur.execute("select* from stocks where expiry > now() and med_name like "+'"'+typed+"%"+'"'+"order by med_name")
tabledata=cur.fetchall()
i=0
for row in tabledata:
i=i+1
table.insert("",index=END,values=(i,row[0],row[1],row[3],row[5],row[2],row[4]),tags=(l[i%2],))
def choice_view(event):
ch=choice_table.get()
l=["evenrow","oddrow"]
clearview_table()
if ch=="All":
update_table()
elif ch=="Expired Medicine":
cur.execute("select* from stocks where expiry < now() order by expiry desc")
tabledata=cur.fetchall()
i=0
for row in tabledata:
i=i+1
table.insert("",index=END,values=(i,row[0],row[1],row[3],row[5],row[2],row[4]),tags=(l[i%2],))
elif ch=="Valid Medicine":
cur.execute("select* from stocks where expiry > now() order by med_name")
tabledata=cur.fetchall()
i=0
for row in tabledata:
i=i+1
table.insert("",index=END,values=(i,row[0],row[1],row[3],row[5],row[2],row[4]),tags=(l[i%2],))
search_view1()
def clearview_table():
for record in table.get_children():
table.delete(record)
def update_table():
clearview_table()
l=("evenrow","oddrow")
cur.execute("select* from stocks order by med_name")
tabledata=cur.fetchall()
i=0
for row in tabledata:
i=i+1
table.insert("",index=END,values=(i,row[0],row[1],row[3],row[5],row[2],row[4]),tags=(l[i%2],))
def table_insert_update(e):
reset_update()
selected=table.focus()
values=table.item(selected,"values")
if True and len(values)!=0:
e1u.insert(0,values[1])
e2u.insert(0,values[2])
e3u.insert(0,values[5])
e4u.insert(0,values[3])
e5u.insert(0,values[6])
e6u.insert(0,values[4])
def reset_update():
e1u.delete(0,END)
e2u.delete(0,END)
e3u.delete(0,END)
e4u.delete(0,END)
e5u.delete(0,END)
e6u.delete(0,END)
def search_update():
k=e1u.get()
if e1u.get()!=None:
if e1u.get().isdigit()==True:
cur.execute("select* from stocks where med_id='"+e1u.get()+"'")
data=cur.fetchone()
if data==None:
bad['image']=img_
bad.after(800,laugh)
messagebox.showerror("","Data does not exist\nPlease add it first")
else:
reset_update()
e1u.insert(0,k)
e2u.insert(0,data[1])
e3u.insert(0,data[2])
e4u.insert(0,data[3])
e5u.insert(0,data[4])
e6u.insert(0,data[5])
else:
messagebox.showerror("ID Error","please enter a valid numeric id")
bad['image']=img_
bad.after(100,laugh)
else:
messagebox.showerror("ID Error","please enter a valid numeric id")
def reset_add():
e1.delete(0,END)
e2.delete(0,END)
e3.delete(0,END)
e4.delete(0,END)
e5.delete(0,END)
e6.delete(0,END)
def laugh():
bad['image']=img
def update_med():
if e1u.get()!=None:
if e1u.get().isdigit()==True:
cur.execute("select med_id from stocks where med_id=%s",((e1u.get()),))
else:
messagebox.showerror("","please enter a numeric code")
if '' in (e1u.get(),e2u.get(),e3u.get(),e4u.get(),e5u.get(),e6u.get()):
messagebox.showerror("","one or more fields empty")
elif cur.fetchone()==None:
messagebox.showerror("ID Error","Data does not exist\nPlease add it first")
reset_update()
elif e1u.get().isdigit()==False:
messagebox.showerror("","please enter a numeric code")
elif e1u.get().isdigit()==False:
messagebox.showerror("","please enter a numeric value")
elif e3u.get().isdigit()==False:
messagebox.showerror("","please enter a numeric value")
elif e6u.get().isdigit()==False:
messagebox.showerror("","please enter a numeric value")
elif check_float(e5u.get())==False:
messagebox.showerror("","please enter a numeric value")
elif check_date(e4u.get())==False:
messagebox.showerror("","Invalid Date Format")
else :
cur.execute("delete from stocks where med_id=%s",(e1u.get().strip(),))
cur.execute("insert into stocks values(%s,%s,%s,%s,%s,%s)",(e1u.get().strip(),
e2u.get().lower().strip(),int(e3u.get().strip()),e4u.get().strip(),
float(e5u.get().strip()),int(e6u.get().strip())))
mycon.commit()
reset_update()
e1u.focus()
def delete_med():
if e1u.get()!=None:
if e1u.get().isdigit()==True:
cur.execute("select med_id from stocks where med_id=%s",((e1u.get()),))
else:
messagebox.showerror("","please enter a numeric code")
if '' in (e1u.get(),e2u.get(),e3u.get(),e4u.get(),e5u.get(),e6u.get()):
messagebox.showerror("","one or more fields empty")
elif cur.fetchone()==None:
messagebox.showerror("","Data does not exist\nPlease add it first")
reset_update()
elif e1u.get().isdigit()==False:
messagebox.showerror("","please enter a numeric code")
elif e1u.get().isdigit()==False:
messagebox.showerror("","please enter a numeric value")
elif e3u.get().isdigit()==False:
messagebox.showerror("","please enter a numeric value")
elif e6u.get().isdigit()==False:
messagebox.showerror("","please enter a numeric value")
elif check_float(e5u.get())==False:
messagebox.showerror("","please enter a numeric value")
elif check_date(e4u.get())==False:
messagebox.showerror("","Invalid Date Format")
else :
cur.execute("delete from stocks where med_id=%s",(e1u.get().strip(),))
mycon.commit()
reset_update()
def add_med():
if e1.get()!=None:
if e1.get().isdigit()==True:
cur.execute("select med_id from stocks where med_id=%s",((e1.get()),))
else:
messagebox.showerror("","please enter a numeric code")
if '' in (e1.get(),e2.get(),e3.get(),e4.get(),e5.get(),e6.get()):
messagebox.showerror("","one or more fields empty")
elif cur.fetchone()!=None:
messagebox.showerror("","Data already exists,Please add new data")
reset_add()
elif e1.get().isdigit()==False:
messagebox.showerror("ID Error","please enter a numeric code")
e1.focus()
elif e3.get().isdigit()==False:
messagebox.showerror("","please enter a numeric value")
elif e6.get().isdigit()==False:
messagebox.showerror("","please enter a numeric value")
elif check_float(e5.get())==False:
messagebox.showerror("","please enter a numeric value")
elif check_date(e4.get())==False:
messagebox.showerror("","Invalid Date Format\n YYYY-MM-DD")
e4.focus()
else :
cur.execute("insert into stocks values(%s,%s,%s,%s,%s,%s)",(e1.get().strip(),e2.get().lower().strip(),int(e3.get().strip()),e4.get().strip(),float(e5.get().strip()),int(e6.get().strip())))
mycon.commit()
reset_add()
e1.focus()
def show_frame(frame):
hide_all_fr()
frame.pack(fill=BOTH,expand=1)
def hide_all_fr():
f_x.pack_forget()
f_add.pack_forget()
f_view.pack_forget()
f_update.pack_forget()
f_bill.pack_forget()
f_showbill.pack_forget()
def DESTROY():
mycon.close()
root.destroy()
frame=LabelFrame(root,borderwidth=0)
frame.pack(fill=Y,side="left")
#image
img=ImageTk.PhotoImage(Image.open("pharma\\r11.png"))
img_=ImageTk.PhotoImage(Image.open("pharma\\troll-face.png"))
#admin button
bad=Button(frame,borderwidth=0,image=img,bg="#2a57de",font=("Calibri",15),fg="White")
bad.pack(fill="both",expand=True)
#buttons
b1=Button(frame,borderwidth=0,text="View Stock",bg="#2a57de",font=("Calibri",16,"bold"),fg="White",command=lambda:[show_frame(f_view),search_view1(),buttonstyle(b1),e_search.focus()])
b1.pack(fill="both",expand=True)
b2=Button(frame,borderwidth=0,text="ADD Medicine",bg="#2a57de",font=("Calibri",16,"bold"),fg='White',command=lambda:[show_frame(f_add),buttonstyle(b2),e1.focus()])
b2.pack(fill=BOTH,expand=True)
b3=Button(frame,borderwidth=0,text="Update Stock",bg="#2a57de",font=("Calibri",16,"bold"),fg='White',command=lambda:[show_frame(f_update),buttonstyle(b3),e1u.focus()])
b3.pack(fill=BOTH,expand=True)
b4=Button(frame,borderwidth=0,text="Generate BILL",bg="#2a57de",font=("Calibri",16,"bold"),fg='White',command=lambda:[show_frame(f_bill),es_bill.focus(),buttonstyle(b4)])
b4.pack(fill=BOTH,expand=True)
b5=Button(frame,borderwidth=0,text="Log OUT",bg="#171010",font=("Calibri",16,"bold"),fg='White',command=DESTROY)
b5.pack(fill=BOTH,expand=True)
f_x=LabelFrame(root,borderwidth=0)
Label(f_x,text="Made by -",font=("Segoe UI",30,"italic"),fg="lightgray",anchor="s").grid(row=0,column=0,sticky="s",pady=220,ipady=10)
Label(f_x,text=" Aditya Prabhakar",font=("Segoe UI",45,"italic"),fg="silver").grid(row=0,column=1,sticky="w",pady=170)
f_x.pack()
f_showbill=LabelFrame(root,borderwidth=0)
showbill=Text(f_showbill,font=("consolas",13),state="disabled")
showbill.pack(expand=1,fill=BOTH,pady=10,padx=10)
#===========f_add===========#
f_add=LabelFrame(root,borderwidth=0,bg="navajowhite")
#ID
f_add1=LabelFrame(f_add,borderwidth=0,bg="navajowhite")
l1=Label(f_add1,text="ID: ",font=("Calibri",15,"bold"),bg="navajowhite")
l1.grid(row=0,column=0,padx=22,pady=20,sticky="nsew")
e1=Entry(f_add1,width=20,font=("Calibri",15,"bold"))
e1.grid(row=0,column=1,pady=20,sticky="nsew")
f_add1.pack(expand=1,fill=BOTH,side=TOP)
#med name
f_add2=LabelFrame(f_add,borderwidth=0,bg="navajowhite")
l2=Label(f_add2,text="Medicine Name:",font=("Calibri",15,"bold"),bg="navajowhite")
l2.grid(row=0,column=0,padx=15,pady=20,sticky="nsew")
e2=Entry(f_add2,width=20,font=("Calibri",15,"bold"))
e2.grid(row=0,column=1,padx=20,pady=20,sticky="nsew")
f_add2.pack(expand=1,fill=BOTH,side=TOP)
#units
f_add3=LabelFrame(f_add,borderwidth=0,bg="navajowhite")
l3=Label(f_add3,text="No. of Units: ",font=("Calibri",15,"bold"),bg="navajowhite")
l3.grid(row=0,column=0,padx=20,pady=20,sticky="nsew")
e3=Entry(f_add3,width=20,font=("Calibri",15,"bold"))
e3.grid(row=0,column=1,padx=20,pady=20,sticky="nsew")
f_add3.pack(expand=1,fill=BOTH,side=TOP)
#exp date
f_add4=LabelFrame(f_add,borderwidth=0,bg="navajowhite")
l4=Label(f_add4,anchor=W,text="Expiry Date: \n(YYYY-MM-DD)",font=("Calibri",15,"bold"),bg="navajowhite")
l4.grid(row=0,sticky="w",column=0,padx=20,pady=20,)
e4=Entry(f_add4,width=20,font=("Calibri",15,"bold"))
e4.grid(row=0,column=1,padx=20,pady=20,sticky="nsew")
f_add4.pack(expand=1,fill=BOTH,side=TOP)
#price
f_add5=LabelFrame(f_add,borderwidth=0,bg="navajowhite")
l5=Label(f_add5,text="Price per unit: ",font=("Calibri",15,"bold"),bg="navajowhite")
l5.grid(row=0,column=0,padx=20,pady=20,sticky="nsew")
e5=Entry(f_add5,width=20,font=("Calibri",15,"bold"))
e5.grid(row=0,column=1,padx=20,pady=20,sticky="nsew")
f_add5.pack(expand=1,fill=BOTH,side=TOP)
#lot no.
f_add6=LabelFrame(f_add,borderwidth=0,bg="navajowhite")
l6=Label(f_add6,text="Lot No.: ",font=("Calibri",15,"bold"),bg="navajowhite")
l6.grid(row=0,column=0,padx=20,pady=20,sticky="nsew")
e6=Entry(f_add6,width=20,font=("Calibri",15,"bold"))
def e6foc(e):
add_med()
e6.bind("<Return>",e6foc)
e6.grid(row=0,column=1,padx=20,pady=20,sticky="nsew")
f_add6.pack(expand=1,fill=BOTH,side=TOP)
#confirm entry button
addbutton=Button(f_add,bg="#5bc236",text="Confirm Entry",font=("Calibri",15,"bold underline"),command=add_med)
addbutton.pack(expand=1,side=RIGHT,fill=X)
#reset button
reb=Button(f_add,bg="#5bc236",font=("Calibri",15,"bold underline"),text="RESET",command=reset_add)
reb.pack(expand=1,side=RIGHT,fill=X)
#--------------frame view ------------#
f_view=LabelFrame(root,borderwidth=0,bg="navajowhite")
#style
style=ttk.Style()
style.theme_use("winnative")
style.configure("Treeview.Heading",background="purple",font=('calibri', 12),foreground="white")
style.configure("Treeview",
background="whitesmoke",
foreground="black",
fieldbackground="whitesmoke",
font=('calibri', 11)
)
style.map("Treeview",
background=[('selected','green')])
f_view1=LabelFrame(f_view,borderwidth=0,bg="darksalmon")
option_table=("All",
'Expired Medicine',
'Valid Medicine')
choice_table=ttk.Combobox(f_view1,state="readonly",value=option_table,font=("Calibri",13))
choice_table.current(0)
choice_table.bind("<<ComboboxSelected>>",choice_view)
choice_table.pack(side=RIGHT,expand=1)
e_search=Entry(f_view1,width=40,font=("Calibri",15,"bold underline"))
e_search.bind("<KeyRelease>",search_view)
e_search.pack(side=RIGHT)
view_search_label=Label(f_view1,text="Search:",font=("Calibri",13,"italic"),bg="darksalmon")
view_search_label.pack(side=RIGHT,padx=20)
f_view1.pack(expand=1,fill=X,side=TOP)
table_view_frame=Frame(f_view,bg="moccasin")
table_scroll=Scrollbar(table_view_frame)
table_scroll.pack(side=RIGHT,fill=Y)
# table data
table=ttk.Treeview(table_view_frame,yscrollcommand=table_scroll.set,selectmode="browse")
table["columns"]=("S.no.","ID",'Medicine Name','Expiry Date',"Lot No.",'No. of Units',"Price")
table.column("#0",minwidth=0,width=0,stretch=NO)
table.column('S.no.',anchor=W,minwidth=40,width=40)
table.column('ID',anchor=W,minwidth=150,width=150)
table.column('Medicine Name',anchor=CENTER,minwidth=250,width=250,)
table.column('Expiry Date',anchor=CENTER,minwidth=160,width=160)
table.column('Lot No.',anchor=CENTER,minwidth=100,width=100)
table.column('No. of Units',minwidth=130,width=130,anchor=CENTER)
table.column('Price',minwidth=150,width=150,anchor=CENTER)
table_scroll.config(command=table.yview)
# headings
table.heading("#0",text="",anchor=W)
table.heading('S.no.',text='S.no.')
table.heading('ID',text='ID')
table.heading('Medicine Name',anchor=CENTER,text='Medicine Name')
table.heading('Expiry Date',anchor=CENTER,text='Expiry Date')
table.heading('Lot No.',anchor=CENTER,text='Lot No.')
table.heading('No. of Units',anchor=CENTER,text='No. of Units',)
table.heading('Price',text='₹ Price')
table.bind("<ButtonRelease-1>",table_insert_update)
table.tag_configure("oddrow",background="white")
table.tag_configure("evenrow",background="thistle")
table.pack(expand=1,fill=BOTH,side=BOTTOM,padx=10,pady=10)
table_view_frame.pack(expand=1,fill=BOTH,side=BOTTOM)
#=====================frame update=====================
f_update=LabelFrame(root,borderwidth=0,bg="navajowhite")
#ID
f_u1=LabelFrame(f_update,borderwidth=0,bg="navajowhite")
l1u=Label(f_u1,text="ID: ",font=("Calibri",15,"bold"),bg="navajowhite")
l1u.grid(row=0,column=0,padx=22,pady=20,sticky="nsew")
e1u=Entry(f_u1,width=20,font=("Calibri",15,"bold"))
e1u.grid(row=0,column=1,pady=20,sticky="nsew")
def e1ufoc(e):
search_update()
e1u.bind("<Return>",e1ufoc)
#search button
su_btn=Button(f_u1,font=("Calibri",12,"bold italic"),text="search",command=search_update,borderwidth=1,bg="#24a0ed",fg="white")
su_btn.grid(row=0,column=2,ipady=1,padx=5)
f_u1.pack(expand=1,fill=BOTH,side=TOP)
#med name
f_u2=LabelFrame(f_update,borderwidth=0,bg="navajowhite")
l2u=Label(f_u2,text="Medicine Name:",font=("Calibri",15,"bold"),bg="navajowhite")
l2u.grid(row=0,column=0,padx=15,pady=20,sticky="nsew")
e2u=Entry(f_u2,width=20,font=("Calibri",15,"bold"))
e2u.grid(row=0,column=1,padx=20,pady=20,sticky="nsew")
f_u2.pack(expand=1,fill=BOTH,side=TOP)
#units
f_u3=LabelFrame(f_update,borderwidth=0,bg="navajowhite")
l3u=Label(f_u3,text="No. of Units: ",font=("Calibri",15,"bold"),bg="navajowhite")
l3u.grid(row=0,column=0,padx=20,pady=20,sticky="nsew")
e3u=Entry(f_u3,width=20,font=("Calibri",15,"bold"),)
e3u.grid(row=0,column=1,padx=20,pady=20,sticky="nsew")
f_u3.pack(expand=1,fill=BOTH,side=TOP)
#exp date
f_u4=LabelFrame(f_update,borderwidth=0,bg="navajowhite")
l4u=Label(f_u4,anchor=W,text="Expiry Date: \n(YYYY-MM-DD)",font=("Calibri",15,"bold"),bg="navajowhite")
l4u.grid(row=0,sticky="w",column=0,padx=20,pady=20,)
e4u=Entry(f_u4,width=20,font=("Calibri",15,"bold"))
e4u.grid(row=0,column=1,padx=20,pady=20,sticky="nsew")
f_u4.pack(expand=1,fill=BOTH,side=TOP)
#price
f_u5=LabelFrame(f_update,borderwidth=0,bg="navajowhite")
l5u=Label(f_u5,text="Price per unit: ",font=("Calibri",15,"bold"),bg="navajowhite")
l5u.grid(row=0,column=0,padx=20,pady=20,sticky="nsew")
e5u=Entry(f_u5,width=20,font=("Calibri",15,"bold"))
e5u.grid(row=0,column=1,padx=20,pady=20,sticky="nsew")
f_u5.pack(expand=1,fill=BOTH,side=TOP)
#lot no.
f_u6=LabelFrame(f_update,borderwidth=0,bg="navajowhite")
l6u=Label(f_u6,text="Lot No.: ",font=("Calibri",15,"bold"),bg="navajowhite")
l6u.grid(row=0,column=0,padx=20,pady=20,sticky="nsew")
e6u=Entry(f_u6,width=20,font=("Calibri",15,"bold"))
e6u.grid(row=0,column=1,padx=20,pady=20,sticky="nsew")
f_u6.pack(expand=1,fill=BOTH,side=TOP)
#confirm entry button
update_button=Button(f_update,bg="#5bc236",text="Update",font=("Calibri",15,"bold underline"),command=update_med)
update_button.pack(expand=1,side=RIGHT,fill=X)
#delete button
del_btn=Button(f_update,bg="red",text="DELETE",font=("Calibri",15,"bold underline"),command=delete_med)
del_btn.pack(expand=1,side=RIGHT,fill=X)
#reset button
rebu=Button(f_update,bg="#5bc236",font=("Calibri",15,"bold underline"),text="RESET",command=reset_update)
rebu.pack(expand=1,side=RIGHT,fill=X)
#=============BILL Frame===========
f_bill=LabelFrame(root,borderwidth=0,bg="navajowhite")
#search bill frame=================>
f_bill_search=LabelFrame(f_bill,borderwidth=0,bg="darksalmon")
bill_search_label=Label(f_bill_search,text="Search:",font=("Calibri",13,"italic"),bg="darksalmon")
bill_search_label.pack(fill=X)
es_bill=Entry(f_bill_search,width=20,font=("Calibri",13))
es_bill.bind("<KeyRelease>",search_bill)
es_bill.pack(padx=7,side=TOP,anchor=W)
s_bill_frame=Frame(f_bill_search,bg="darksalmon")
sbill_scroll=Scrollbar(s_bill_frame)
sbill_scroll.pack(side=RIGHT,fill=Y)
# table data
sbill_table=ttk.Treeview(s_bill_frame,yscrollcommand=sbill_scroll.set,selectmode=BROWSE,show="tree")
sbill_table["columns"]=("med_id",'Medicine Name')
sbill_table.column("#0",minwidth=0,width=0,stretch=NO)
sbill_table.column('med_id',anchor=W,minwidth=0,width=0,stretch=NO)
sbill_table.column('Medicine Name',anchor=W,minwidth=180,width=180,)
sbill_scroll.config(command=sbill_table.yview)
# headings
sbill_table.heading("#0",text="",anchor=W)
sbill_table.heading('Medicine Name',anchor=CENTER,text='')
sbill_table.heading('med_id',anchor=CENTER,text='')
sbill_table.pack(expand=1,fill=BOTH,side=BOTTOM,padx=5,pady=5)
sbill_table.bind("<ButtonRelease-1>",select_sbill)
s_bill_frame.pack(expand=1,fill=Y,side=BOTTOM)
f_bill_search.pack(fill=Y,side="left")
#bill ,price , quantity frame=================
d_bill=LabelFrame(f_bill,bg="navajowhite",borderwidth=0)
d_e0=Entry(d_bill,font=("Calibri",13,"italic"),state='readonly')
d_l1=Label(d_bill,text="Medicine Name:",font=("Calibri",13,"italic"),anchor=W,bg="bisque")
d_e1=Entry(d_bill,state='readonly',font=("Calibri",13,"italic"))
d_l1.grid(row=0,column=0,sticky="w",padx=7,pady=7)
d_e1.grid(row=0,column=1,padx=7,pady=7)
d_l2=Label(d_bill,text="Lot No.:",font=("Calibri",13,"italic"),bg="bisque")
d_e2=Entry(d_bill,state='readonly',font=("Calibri",13,"italic"))
d_l2.grid(row=1,column=0,sticky="w",padx=7,pady=7)
d_e2.grid(row=1,column=1,padx=7,pady=7)
d_l3=Label(d_bill,text="Exp. Date:",font=("Calibri",13,"italic"),bg="bisque")
d_e3=Entry(d_bill,state='readonly',font=("Calibri",13,"italic"))
d_l3.grid(row=2,column=0,sticky="w",padx=7,pady=7)
d_e3.grid(row=2,column=1,padx=7,pady=7)
d_l4=Label(d_bill,text="₹ Price/unit:",font=("Calibri",13,"italic"),bg="bisque")
d_e4=Entry(d_bill,state='readonly',font=("Calibri",13,"italic"))
d_l4.grid(row=0,column=2,sticky=W,padx=10,pady=7)
d_e4.grid(row=0,column=3,padx=7,pady=7)
d_l5=Label(d_bill,text="Qty:",font=("Calibri",13,"italic"),bg="bisque")
d_e5=Entry(d_bill,font=("Calibri",13,"italic"))
d_e5.bind("<KeyRelease>",d_e5check)
d_e5.bind("<Return>",de5foc)
d_l5.grid(row=1,column=2,sticky="w",padx=10,pady=7)
d_e5.grid(row=1,column=3,padx=7,pady=7)