-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathusers.py
More file actions
696 lines (560 loc) · 36 KB
/
Copy pathusers.py
File metadata and controls
696 lines (560 loc) · 36 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
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
import customtkinter,json,os
from PIL import ImageTk,Image
from utils import *
import matplotlib, numpy
matplotlib.use('TkAgg')
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
from tkinter import filedialog
import regex as re
os.chdir("assets/")
with open("users.json","r+") as file:
data = json.load(file)
customtkinter.set_default_color_theme("green")
class Users:
def check_login(self, frame):
username = frame.uentry.get().strip()
password = frame.pentry.get().strip()
if username not in data["users"].keys():
self.error_label.configure(text=f"No user named {username} found")
else:
real_password = data["users"][username]["password"]
if password == real_password:
if data["users"][username]["isadmin"] == True:
frame.destroy()
user = Admin(self.window, username)
user.manage_user()
else:
frame.destroy()
self.username = username
self.home_page(i=0)
else:
self.error_label.configure(text="Incorrect password")
def login_page(self):
self.window = customtkinter.CTk()
frame = customtkinter.CTkToplevel(self.window)
frame.geometry("600x440")
frame.title("Login")
bg_image = ImageTk.PhotoImage(Image.open("pattern.png"))
bg = customtkinter.CTkLabel(master=frame, image=bg_image, text="")
bg.pack()
frame.l_frame = customtkinter.CTkFrame(master=bg, height=360, width=360, corner_radius=15)
frame.l_frame.place(relx=0.5, rely=0.5, anchor=customtkinter.CENTER)
frame.label_1 = customtkinter.CTkLabel(master=frame.l_frame, text="Login into your account", font=("Century Gothic", 20))
frame.label_1.place(x=70, y=10)
frame.uentry = customtkinter.CTkEntry(master=frame.l_frame, placeholder_text="Username", width=220)
frame.uentry.place(relx=0.2, y=125)
self.password_visible = False
frame.pentry = customtkinter.CTkEntry(master=frame.l_frame, placeholder_text="Password", width=220, show="*")
frame.pentry.place(relx=0.2, y=180)
self.eye_image_open = ImageTk.PhotoImage(Image.open("eye_open.png").resize((20, 20), Image.Resampling.LANCZOS))
self.eye_image_closed = ImageTk.PhotoImage(Image.open("eye_closed.png").resize((20, 20), Image.Resampling.LANCZOS))
self.eye_button = customtkinter.CTkButton(master=frame.l_frame, image=self.eye_image_closed, width=20, height=20, text="", command=lambda: self.toggle_password(frame))
self.eye_button.place(relx=0.715, rely=0.505)
frame.l_button = customtkinter.CTkButton(master=frame.l_frame, width=220, text="Login", corner_radius=6, command=lambda: self.check_login(frame))
frame.l_button.place(relx=0.2, y=250)
# Error message label
self.error_label = customtkinter.CTkLabel(master=frame.l_frame, text="", font=("Century Gothic", 12), text_color="red")
self.error_label.place(relx=0.2, y=210)
frame.mainloop()
def toggle_password(self, frame):
if self.password_visible:
self.eye_button.configure(image=self.eye_image_closed)
frame.pentry.configure(show="*")
self.password_visible = False
else:
self.eye_button.configure(image=self.eye_image_open)
frame.pentry.configure(show="")
self.password_visible = True
def print(self):
name = data["users"][self.username]["name"]
basic = data["users"][self.username]["basic"]
ID = self.username
acc = data["users"][self.username]["acc"]
com_allowance = basic*0.16
da=basic*0.38
perks = basic*0.252
cpf = basic*0.06
taxable = basic+basic*0.792
total_tax = taxable*0.3
folder_selected = filedialog.askdirectory()
samosa(folder_selected,x=name,da=da,basic=basic,perks=perks,empID=ID,tax=total_tax,epf=cpf,acc_number = acc,com_allow = com_allowance)
def home_page(self,i=0):
#Define window of the page
self.window.title("Employee Payroll")
self.window.iconbitmap("deshpremikiryu-modified.ico")
self.text_font = customtkinter.CTkFont("Proxima Nova Rg",18)
self.text_font_bold = customtkinter.CTkFont("Proxima Nova Rg",20,"bold")
self.font = customtkinter.CTkFont("Proxima Nova Rg",12,'bold')
self.window.geometry("900x600")
#Define grid inside the window
self.window.grid_columnconfigure(1,weight=1)
self.window.grid_rowconfigure(0,weight=1)
#Add left frame inside the row 0 col 0 cell
self.l_frame = customtkinter.CTkFrame(master=self.window)
self.l_frame.grid(row=0,column=0,rowspan=4,padx=20,pady=20,sticky="nsew")
#Added MANAGE label
self.window.manage_ = customtkinter.CTkLabel(master=self.l_frame,text="MANAGE",font=self.font)
self.window.manage_.place(y=60,relx=0.1)
#Added ATTENDANCE button
self.window.but_attend = customtkinter.CTkButton(master=self.l_frame,width=220,height=40,text="Attendance",corner_radius=0,fg_color="#333333",hover_color="#2e2e2e",image=customtkinter.CTkImage(Image.open("calendar-solid.png")),command=self.attendace)
self.window.but_attend.place(y=100)
#Added EMPLOYEE button
self.window.but_emp = customtkinter.CTkButton(master=self.l_frame,width=220,height=40,text="Change Password",corner_radius=0,image=customtkinter.CTkImage(Image.open("a.png"),size=(20,20)),fg_color="#333333",hover_color="#2e2e2e",
command= self.change_password
)
self.window.but_emp.place(y=145)
#Added DEDUCTION button
self.window.but_deduction = customtkinter.CTkButton(master=self.l_frame,width=220,height=40,text="Pay History",corner_radius=0,fg_color="#333333",hover_color="#2e2e2e",image=customtkinter.CTkImage(Image.open("documents-solid.png")),command=self.pay_history)
self.window.but_deduction.place(y=190)
#Added Printables label
self.window.printables = customtkinter.CTkLabel(master=self.l_frame,text="ADMIN",font=self.font)
self.window.printables.place(y=285,relx=0.1)
#Added PAYROLL button
self.window.but_payroll = customtkinter.CTkButton(master=self.l_frame,width=220,height=40,text="Payroll ",corner_radius=0,fg_color="#333333",hover_color="#2e2e2e",image=customtkinter.CTkImage(Image.open("coins-solid.png")),command=self.print)
self.window.but_payroll.place(y=235)
#Added SCHEDULE button
# self.window.but_schedule = customtkinter.CTkButton(master=self.l_frame,width=220,height=40,text="Schedule",corner_radius=0,fg_color="#333333",hover_color="#2e2e2e",image=customtkinter.CTkImage(Image.open("clock-solid.png")))
# self.window.but_schedule.place(y=255)
#Added Home page button
if i==0:
self.window.home_page = customtkinter.CTkButton(master=self.l_frame,width=220,height=40,text="Home Page",corner_radius=0,fg_color="#333333",hover_color="#2e2e2e",image=customtkinter.CTkImage(Image.open("icons8-home-500.png")),command=self.home_page)
self.window.home_page.place(y=10)
else:
self.window.home_page = customtkinter.CTkButton(master=self.l_frame,width=220,height=40,text="Home Page",corner_radius=0,fg_color="#333333",hover_color="#2e2e2e",image=customtkinter.CTkImage(Image.open("icons8-home-500.png")), command=lambda : self.home_page(1))
self.window.home_page.place(y=10)
#Added right frame
self.r_frame = customtkinter.CTkFrame(master=self.window)
self.r_frame.grid(row=0,column=1,rowspan=4,padx=20,pady=20,sticky="nsew")
if i==1:
manage = customtkinter.CTkButton(master=self.l_frame,width=220,height=40,text="Manage Users",corner_radius=0,fg_color="#333333",hover_color="#2e2e2e",command=self.manage_user)
manage.place(y=320)
#Added dashboard label inside right frame
self.dashboard = customtkinter.CTkLabel(master=self.r_frame,text="Dashboard")
self.dashboard.configure(padx=20,font=self.text_font_bold)
#Grid inside right frame with 3 coloumns and 3 rows
self.r_frame.grid_columnconfigure((0,1,2,3),weight=1)
self.r_frame.grid_rowconfigure((1,2,3),weight=1)
#Place dashboard label to the (0,0) of right frame
self.dashboard.grid(row=0,column=0,padx=7.5,pady=20,sticky="nw")
#Add total_working_employee frame
total_employee = customtkinter.CTkFrame(master=self.r_frame,fg_color="#6c7f91",corner_radius=0)
total_employee.grid(row=1,column=0,sticky="new",padx=20)
#Details
total_employee_ = customtkinter.CTkLabel(master=total_employee,text="Total Employees",font=self.text_font)
total_employee_.place(relx=0.1,rely=0.25)
users = len(data["users"])
total_employee_label = customtkinter.CTkLabel(master=total_employee,text=f"{users}",font=self.text_font_bold)
total_employee_label.place(relx=0.1,rely=0.1)
#Add attendance percentage frame
percentage = customtkinter.CTkFrame(master=self.r_frame,fg_color="#019258",corner_radius=0)
percentage.grid(row=1,column=1,sticky="new")
#Details
percentage_label = customtkinter.CTkLabel(master=percentage,text=f"{total_attendace(data,self.username)}",font=self.text_font_bold)
percentage_label.place(relx=0.1,rely=0.1)
percentage_label_ = customtkinter.CTkLabel(master=percentage,text="Attendance %",font=self.text_font)
percentage_label_.place(relx=0.1,rely=0.25)
#Add current time frame
time = customtkinter.CTkFrame(master=self.r_frame,fg_color="#fd9c0a",corner_radius=0)
time.grid(row=1,column=2,sticky="new",padx=20)
#Details
time_label = customtkinter.CTkLabel(master=time,text="",font=self.text_font_bold)
time_label.place(relx=0.1,rely=0.1)
update_time(time_label)
current_time_label = customtkinter.CTkLabel(master=time,text="Current Time",font=self.text_font)
current_time_label.place(relx=0.1,rely=0.25)
basic = int(data["users"][self.username]["basic"])
taxable = basic+basic*0.792
net_pay = (basic+basic*0.792)-(taxable*0.3+basic*0.06)
#Late Frame Right most
total_pay_f = customtkinter.CTkFrame(master=self.r_frame,fg_color="#e85832",corner_radius=0)
total_pay_f.grid(row=1,column=3,sticky="new")
total_pay = customtkinter.CTkLabel(master=total_pay_f,text=f"₹{net_pay}",font=self.text_font_bold)
total_pay.place(relx=0.1,rely=0.1)
total_pay_ = customtkinter.CTkLabel(master=total_pay_f,text="Monthly Total Pay",font=self.text_font)
total_pay_.place(relx=0.1,rely=0.25)
details = customtkinter.CTkFrame(master=self.r_frame)
details.grid(row=2,column=0,sticky="nsew",rowspan=4,columnspan=4)
name_account = customtkinter.CTkLabel(details,width=2000,bg_color="#474545",text="Name: {} Account Number:{}".format(data["users"][self.username]["name"],data["users"][self.username]["acc"]),anchor="w",font=self.text_font)
name_account.place(x=0,y=40)
name_account.configure(padx=40)
total_deduction = customtkinter.CTkLabel(details,font=self.text_font,text="Total Monthly Deduction: {} Basic Pay: {}".format(taxable*0.3+basic*0.06,basic),anchor="w")
total_deduction.place(x=0,y=100)
total_deduction.configure(padx=40)
total_allowance = customtkinter.CTkLabel(details,font=self.text_font,text="Total Monthly Allowance(Including DA): {} Perks: {}".format(basic*0.38,basic*0.412),anchor="w")
total_allowance.place(x=0,y=140)
total_allowance.configure(padx=40)
if i==0:
self.window.mainloop()
def pay_history(self):
self.r_frame.destroy()
self.r_frame = customtkinter.CTkFrame(master=self.window)
self.r_frame.grid_columnconfigure((0,1,2,3),weight=1)
self.r_frame.grid_rowconfigure(1,weight=1)
self.r_frame.grid(row=0,column=1,rowspan=4,padx=20,pady=20,sticky="nsew")
attendance = customtkinter.CTkLabel(master=self.r_frame,text="Pay History")
attendance.configure(padx=20,font=self.text_font_bold)
attendance.grid(row=0,column=0,padx=7.5,pady=20,sticky="nw")
attendance_graph = customtkinter.CTkFrame(master=self.r_frame)
attendance_graph.grid(row=1,column=0,padx=7.5,pady=20,sticky="nsew",columnspan=4)
y_coord = 60
customtkinter.CTkLabel(master=attendance_graph,text=f"Month of Payment : Net Pay",font=customtkinter.CTkFont("Proxima Nova Rg",18,'bold')).place(x=50,y=20)
months = ["January", "February", 'March', "April", "May", 'June', "July", "August", "September", "October", 'November' , "December"]
for i in range(len(data["users"][self.username]["pay_record"])):
monthly_pay = data["users"][self.username]["pay_record"][i]
month = months[i]
if monthly_pay!=None:
a = customtkinter.CTkLabel(master=attendance_graph,text=f"{month} : {monthly_pay}",font=self.text_font)
a.place(x=50,y=y_coord)
y_coord+=40
cummulative = customtkinter.CTkLabel(master=attendance_graph,text=f"Month of Payment : Net Pay",font=customtkinter.CTkFont("Proxima Nova Rg",18,'bold')).place(x=50,y=20)
def attendace(self):
self.r_frame.destroy()
#Create a new window with the same name
self.r_frame = customtkinter.CTkFrame(master=self.window)
self.r_frame.grid(row=0,column=1,rowspan=4,padx=20,pady=20,sticky="nsew")
self.r_frame.grid_columnconfigure((0,1,2,3),weight=1)
self.r_frame.grid_rowconfigure(1,weight=1)
attendance = customtkinter.CTkLabel(master=self.r_frame,text="Attendance")
attendance.configure(padx=20,font=self.text_font_bold)
attendance.grid(row=0,column=0,padx=7.5,pady=20,sticky="nw")
attendance_graph = customtkinter.CTkFrame(master=self.r_frame)
attendance_graph.grid(row=1,column=0,padx=7.5,pady=20,sticky="nsew",columnspan=4)
f = Figure(figsize=(10,20), dpi=100,facecolor="#2a2b2a")
ax = f.add_subplot(111)
ax.set_facecolor("orange")
ax.set_xlabel('X-axis')
ax.set_ylabel('Y-axis')
ax.xaxis.label.set_color('white')
ax.tick_params(axis='x', colors='white')
ax.yaxis.label.set_color('white')
ax.tick_params(axis='y', colors='white')
data_ = tuple(data["users"][self.username]["attendance"])
ind = numpy.arange(len(data_)) # the x locations for the groups
width = .75
ax.set_xticks([0,1,2,3,4,5,6,7,8,9,10,11],["January", "February", 'March', "April", "May", 'June', "July", "August", "September", "October", 'November' , "December"])
ax.set_xticklabels(["January", "February", 'March', "April", "May", 'June', "July", "August", "September", "October", 'November' , "December"],rotation=30)
rects1 = ax.bar(ind, data_, width)
canvas = FigureCanvasTkAgg(f, master=attendance_graph)
canvas.draw()
canvas.get_tk_widget().pack(side=customtkinter.TOP, fill=customtkinter.BOTH, expand=1)
def change_password(self):
# UI Element
self.top_level = customtkinter.CTkToplevel()
self.top_level.title("Change Password")
image = ImageTk.PhotoImage(Image.open("alo.png"))
bg = customtkinter.CTkLabel(master=self.top_level, image=image, text="")
bg.pack()
self.top_level.geometry("600x440")
self.top_l_frame = customtkinter.CTkFrame(master=self.top_level, height=360, width=360, corner_radius=15)
self.top_l_frame.place(relx=0.5, rely=0.5, anchor=customtkinter.CENTER)
label_1 = customtkinter.CTkLabel(master=self.top_l_frame, text="Change Password", font=("Century Gothic", 20))
label_1.place(x=100, y=10)
current_password_label = customtkinter.CTkLabel(master=self.top_l_frame, text="Current Password")
current_password_label.place(relx=0.2, y=70)
uentry = customtkinter.CTkEntry(master=self.top_l_frame, placeholder_text="", width=220)
uentry.place(relx=0.2, y=105)
new_password_label = customtkinter.CTkLabel(master=self.top_l_frame, text="New Password")
new_password_label.place(relx=0.2, y=145)
new_password = customtkinter.CTkEntry(master=self.top_l_frame, placeholder_text="", width=220)
new_password.place(relx=0.2, y=180)
confirm_password_label = customtkinter.CTkLabel(master=self.top_l_frame, text="Confirm Password")
confirm_password_label.place(relx=0.2, y=220)
confirm_password = customtkinter.CTkEntry(master=self.top_l_frame, placeholder_text="", width=220)
confirm_password.place(relx=0.2, y=255)
l_button = customtkinter.CTkButton(master=self.top_l_frame, width=220, text="Change Password", corner_radius=6, command=lambda: self.check_entered_pass(self.top_level, self.top_l_frame, uentry, new_password, confirm_password))
l_button.place(relx=0.2, y=300)
#Check if current password is right
def check_entered_pass(self, window, frame, uentry, uentry2, uentry3):
pass1 = uentry2.get()
pass2 = uentry3.get()
# Clear previous error messages
for widget in frame.winfo_children():
if isinstance(widget, customtkinter.CTkLabel) and widget.cget("text_color") == "Red":
widget.destroy()
if not re.search(r'[A-Z]', pass1) or not re.search(r'[a-z]', pass1) or not re.search(r'[0-9]', pass1) or not re.search(r'[\W_]', pass1):
invalid_pass_format = customtkinter.CTkLabel(master=frame, text="Invalid Password Format", text_color="Red", font=("Century Gothic", 15))
invalid_pass_format.place(relx=0.25, rely=0.1)
return
if (data["users"][self.username]["password"] == uentry.get().strip()) and (pass1 == pass2):
self.top_l_frame.destroy()
self.top_l_frame2 = customtkinter.CTkFrame(master=self.top_level, height=360, width=360, corner_radius=15)
self.top_l_frame2.place(relx=0.5, rely=0.5, anchor=customtkinter.CENTER)
valid_pass = customtkinter.CTkLabel(master=self.top_l_frame2, text="Password changed", text_color="Green", font=("Century Gothic", 20))
password_changed_image = customtkinter.CTkImage(Image.open("checkmark.png"), size=(60, 60))
image_frame = customtkinter.CTkLabel(master=self.top_l_frame2, image=password_changed_image, text="")
image_frame.place(relx=0.4, rely=0.5)
valid_pass.place(relx=0.25, rely=0.3)
data["users"][self.username]["password"] = pass1
d_button = customtkinter.CTkButton(master=self.top_l_frame2, width=220, text="close", corner_radius=6, command=lambda: self.top_level.destroy())
d_button.place(relx=0.2, y=300)
with open("users.json", "w") as file:
json.dump(data, file, indent=4)
# Destroy the window after password change
window.after(2000, window.destroy) # Close the window after 2 seconds
else:
invalid_pass = customtkinter.CTkLabel(master=frame, text="Invalid Password Try again", text_color="Red", font=("Century Gothic", 15))
invalid_pass.place(relx=0.15, rely=0.1)
class Admin(Users):
def __init__(self,window,username):
self.window = window
self.username = username
super().__init__()
def manage_user(self):
font = customtkinter.CTkFont("Proxima Nova Rg",18,'bold')
text_font = customtkinter.CTkFont("Proxima Nova Rg",18)
text_font_bold = customtkinter.CTkFont("Proxima Nova Rg",20,"bold")
self.home_page(1)
manage = customtkinter.CTkButton(master=self.l_frame,width=220,height=40,text="Manage Users",corner_radius=0,fg_color="#333333",hover_color="#2e2e2e",command=self.manage_user)
manage.place(y=320)
self.window.home_page.configure(text="Home Page", command = lambda: self.home_page(1))
self.r_frame.destroy()
self.r_frame = customtkinter.CTkFrame(master=self.window)
self.r_frame.grid(row=0,column=1,rowspan=4,padx=20,pady=20,sticky="nsew")
self.r_frame.grid_columnconfigure((0,1,2,3),weight=1)
self.r_frame.grid_rowconfigure(1,weight=1)
manage_users_frame = customtkinter.CTkFrame(master=self.r_frame)
manage_users_frame.grid(row=1,column=0,padx=7.5,pady=10,sticky="nsew",columnspan=4)
manage_user_label = customtkinter.CTkLabel(master=self.r_frame,text="Manage Users")
manage_user_label.configure(padx=20,font=self.text_font_bold)
manage_user_label.grid(row=0,column=0,padx=7.5,pady=10,sticky="nw")
def option_callback2(choice):
if choice=="1" and int(current_basic.cget("text"))<10000:
change_basic.configure(textvariable=10000)
def option_callback(choice):
username = data["users"][choice]["name"]
account_number = data["users"][choice]["acc"]
basic = data["users"][choice]["basic"]
employee_id.configure(text=f"Employee Name: {username} Account Number: {account_number}")
current_basic.configure(text=basic)
calculated_da.configure(text=basic*0.38)
company_allowance.configure(text=basic*0.16)
perks.configure(text=basic*0.252)
taxable = basic+basic*0.792
total_tax = taxable*0.3
itax.configure(text=total_tax)
cpf.configure(text=basic*0.06)
deductions.configure(text=taxable*0.3+basic*0.06)
gross_pay_total = basic+basic*0.792
gross_pay.configure(text=gross_pay_total)
net_salary.configure(text=(basic+basic*0.792)-(taxable*0.3+basic*0.06))
#SELECT USER
select_user = customtkinter.CTkLabel(master=manage_users_frame,text="Select Employee:",font=text_font)
select_user.place(x=30,y=20)
list_users = customtkinter.CTkOptionMenu(master=manage_users_frame,font=text_font_bold,
values=[username for username in data["users"].keys()],command=option_callback)
list_users.place(x=30,y=50)
def save_changes(new_window, action, employee_id=None):
if action == "delete":
if new_window:
new_window.destroy()
if employee_id:
data["users"].pop(employee_id)
elif action == "save":
if new_window:
new_window.destroy()
if employee_id:
new_basic = int(change_basic.get())
data["users"][employee_id]["basic"] = new_basic
with open("users.json", "w") as file:
json.dump(data, file, indent=4)
list_users.configure(values=[username for username in data["users"].keys()])
if employee_id:
option_callback(employee_id)
def confirmation_window(action, employee_id=None):
new_window = customtkinter.CTkToplevel()
new_window.title("Confirm Changes")
new_window.geometry("400x240")
new_window.protocol("WM_DELETE_WINDOW", lambda: new_window.destroy())
new_window.resizable(width=False, height=False)
warning_label = customtkinter.CTkLabel(master=new_window, text="Changes are being finalized \n please confirm the changes to continue", height=40)
warning_label.place(relx=0.22, rely=0.25)
cancel_changes = customtkinter.CTkButton(master=new_window, text="Cancel Changes", command=lambda: new_window.destroy())
accept_changes = customtkinter.CTkButton(master=new_window, text="Accept Changes", command=lambda: save_changes(new_window, action, employee_id))
cancel_changes.place(relx=0.15, rely=0.5)
accept_changes.place(relx=0.55, rely=0.5)
#ACC NUMBER
employee_id = customtkinter.CTkLabel(master=manage_users_frame,text=f"Employee Name: {0} Account Number: {0}"
,font=text_font,bg_color="#474545",anchor="w",width=2000,height=40)
employee_id.place(x=0,y=90)
employee_id.configure(padx=40)
#CHANGE GRADE SCALE
change_grade = customtkinter.CTkLabel(master=manage_users_frame,text="Change Grade Scale:",font=text_font)
grade_list = customtkinter.CTkOptionMenu(master=manage_users_frame,font=text_font_bold,values=["3","2","1"],width=80,command=option_callback2)
grade_list.place(x=30,y=170)
change_grade.place(x=30,y=140)
#CHANGE BASIC PAY
change_basic_label = customtkinter.CTkLabel(master=manage_users_frame,text="Basic:",font=text_font)
change_basic = customtkinter.CTkEntry(master=manage_users_frame,font=text_font,placeholder_text="Change Basic Pay",width=120)
change_basic_label.place(x=225,y=140)
change_basic.place(x=225,y=170)
current_basic_label = customtkinter.CTkLabel(master=manage_users_frame,text="Current Basic:",font=text_font)
current_basic_label.place(x=350,y=140)
current_basic = customtkinter.CTkLabel(master=manage_users_frame,text="0000",font=text_font,bg_color="#202120",corner_radius=20)
current_basic.place(x=460,y=140)
#CALCULATED DA
da_label = customtkinter.CTkLabel(master=manage_users_frame,text="DA:",font=text_font)
da_label.place(x=30,y=215)
calculated_da = customtkinter.CTkButton(master=manage_users_frame,text="0000",font=text_font,state="disabled",width=100)
calculated_da.place(x=65,y=215)
#COMPANY ALLOWANCE
company_allowance_label = customtkinter.CTkLabel(master=manage_users_frame,text="CAllowance:",font=text_font)
company_allowance_label.place(x=180,y=215)
company_allowance = customtkinter.CTkLabel(master=manage_users_frame,text="0",font=font)
company_allowance.place(x=280,y=215)
#PERKS
perks_label = customtkinter.CTkLabel(master=manage_users_frame,text="Perks:",font=text_font)
perks_label.place(x=400,y=215)
perks= customtkinter.CTkLabel(master=manage_users_frame,text="0",font=font)
perks.place(x=450,y=215)
#DEDUCTIONS
deductions = customtkinter.CTkLabel(master=manage_users_frame,text=f"Calculated Deductions"
,font=text_font,bg_color="#474545",anchor="w",width=2000,height=40)
deductions.place(x=0,y=260)
deductions.configure(padx=40)
#CPF
cpf_label = customtkinter.CTkLabel(master=manage_users_frame,text="CPF:",font=text_font)
cpf_label.place(x=30,y=310)
cpf= customtkinter.CTkLabel(master=manage_users_frame,text="0",font=font,text_color="#e3685e")
cpf.place(x=70,y=310)
#ITAX
itax_label = customtkinter.CTkLabel(master=manage_users_frame,text="ITAX:",font=text_font)
itax_label.place(x=170,y=310)
itax= customtkinter.CTkLabel(master=manage_users_frame,text="0",font=font,text_color="#e3685e")
itax.place(x=215,y=310)
#LIC
lic_label = customtkinter.CTkLabel(master=manage_users_frame,text="LIC:",font=text_font)
lic_label.place(x=290,y=310)
lic= customtkinter.CTkLabel(master=manage_users_frame,text="N.A",font=font,text_color="#6ec555")
lic.place(x=325,y=310)
#TOTAL DEDUCTIONS
deductions_label = customtkinter.CTkLabel(master=manage_users_frame,text="Total Deduction:",font=text_font)
deductions_label.place(x=30,y=350)
deductions= customtkinter.CTkLabel(master=manage_users_frame,text="0",font=font,text_color="#e3685e")
deductions.place(x=160,y=350)
#GROSS PAY
gross_pay_label = customtkinter.CTkLabel(master=manage_users_frame,text="Gross Pay:",font=text_font)
gross_pay_label.place(x=290,y=350)
gross_pay= customtkinter.CTkLabel(master=manage_users_frame,text="0",font=font,text_color="#6ec555")
gross_pay.place(x=380,y=350)
#IN HAND SALARY
net_salary_calc = customtkinter.CTkLabel(master=manage_users_frame,text=f"Net Salary"
,font=text_font,bg_color="#474545",anchor="w",width=2000,height=40)
net_salary_calc.place(x=0,y=390)
net_salary_calc.configure(padx=40)
#Total Working Days
working_days_label = customtkinter.CTkLabel(master=manage_users_frame,text="Working Days:",font=text_font)
working_days_label.place(x=30,y=440)
working_days= customtkinter.CTkLabel(master=manage_users_frame,text="0",font=font)
working_days.place(x=145,y=440)
#NET SALARY
net_salary_label = customtkinter.CTkLabel(master=manage_users_frame,text="Net Salary:",font=text_font)
net_salary_label.place(x=190,y=440)
net_salary= customtkinter.CTkLabel(master=manage_users_frame,text="0",font=font)
net_salary.place(x=280,y=440)
save_button = customtkinter.CTkButton(master=manage_users_frame, text="Save Changes", font=font, fg_color="#4b873a", command=lambda: confirmation_window("save", list_users.get()))
save_button.place(x=440, y=440)
current_month = customtkinter.CTkButton(master=self.r_frame,text="{}".format(datetime.datetime.now().strftime("%B")),font=text_font,state="disabled")
current_month.place(x=170,y=12)
new_user = customtkinter.CTkButton(master=self.r_frame,text="Create User",font=text_font,command=self.create_new_user)
new_user.place(x=470,y=12)
delete_user = customtkinter.CTkButton(master=self.r_frame, text="Delete User", font=text_font, command=lambda: confirmation_window("delete", list_users.get()))
delete_user.place(x=320, y=12)
self.window.mainloop()
def create_new_user(self):
new_window = customtkinter.CTkToplevel()
new_window.title("New User")
new_window.geometry("600x400")
new_window.resizable(width=False, height=False)
frame = customtkinter.CTkFrame(master=new_window, width=580, height=380)
frame.place(relx=0.5, rely=0.5, anchor=customtkinter.CENTER)
uentry_label = customtkinter.CTkLabel(master=frame, text="New Username:", font=self.text_font)
uentry_label.place(x=10, y=20)
uentry = customtkinter.CTkEntry(master=frame, placeholder_text="New Username", width=180, font=self.text_font)
uentry.place(x=10, y=50)
pentry_label = customtkinter.CTkLabel(master=frame, text="New Password:", font=self.text_font)
pentry_label.place(x=10, y=100)
password = customtkinter.CTkEntry(master=frame, placeholder_text="New Password", width=180, font=self.text_font, show="*")
password.place(x=10, y=130)
self.password_visible = False
self.eye_image_open = ImageTk.PhotoImage(Image.open("eye_open.png").resize((20, 20), Image.Resampling.LANCZOS))
self.eye_image_closed = ImageTk.PhotoImage(Image.open("eye_closed.png").resize((20, 20), Image.Resampling.LANCZOS))
self.eye_button = customtkinter.CTkButton(master=frame, image=self.eye_image_closed, width=20, height=20, text="", command=lambda: self.toggle_password_check(password))
self.eye_button.place(x=200, y=130)
month_of_joining = customtkinter.CTkOptionMenu(master=frame, values=["January", "February", 'March', "April", "May", 'June', "July", "August", "September", "October", 'November', "December"], font=self.text_font)
month_of_joining.place(x=360, y=130)
month_of_joining_label = customtkinter.CTkLabel(master=frame, text="Month of Joining:", font=self.text_font)
month_of_joining_label.place(x=360, y=100)
salary_basic_label = customtkinter.CTkLabel(master=frame, text="Set Basic Pay:", font=self.text_font)
set_basic = customtkinter.CTkEntry(master=frame, placeholder_text="Set Basic Pay", font=self.text_font)
salary_basic_label.place(x=10, y=180)
set_basic.place(x=10, y=210)
max_acc_number = max([int(user["acc"]) for user in data["users"].values()], default=0)
new_acc_number = str(max_acc_number + 1).zfill(10)
set_acc_label = customtkinter.CTkLabel(master=frame, text="Account Number:", font=self.text_font)
set_acc_value = customtkinter.CTkLabel(master=frame, text=new_acc_number, font=self.text_font)
set_acc_label.place(x=360, y=180)
set_acc_value.place(x=360, y=210)
set_name_label = customtkinter.CTkLabel(master=frame, text="User's Name:", font=self.text_font)
set_name = customtkinter.CTkEntry(master=frame, placeholder_text="Set User's name", width=200, font=self.text_font)
set_name_label.place(x=360, y=20)
set_name.place(x=360, y=50)
l_button = customtkinter.CTkButton(master=frame, width=220, text="Create User", corner_radius=6, command=lambda: self.check_entry(new_window, frame, password=password, username=uentry, basic=set_basic, month=month_of_joining, name=set_name), font=self.text_font)
l_button.place(x=170, y=270)
def toggle_password_check(self, password_entry):
if self.password_visible:
self.eye_button.configure(image=self.eye_image_closed)
password_entry.configure(show="*")
self.password_visible = False
else:
self.eye_button.configure(image=self.eye_image_open)
password_entry.configure(show="")
self.password_visible = True
def check_entry(self, window, frame, **kwargs: customtkinter.CTkEntry):
password = kwargs["password"].get()
username = kwargs["username"].get()
basic = kwargs["basic"].get()
name = kwargs["name"].get()
create_attendance = lambda: [0 for _ in range(12)] # Initialize with 12 zeroes
# Clear previous error messages
for widget in frame.winfo_children():
if isinstance(widget, customtkinter.CTkLabel) and widget.cget("text_color") == "Red":
widget.destroy()
if password == "" or username == "" or basic == "" or name == "":
error_message = "All fields are required."
if password == "":
error_message = "Password is required."
elif username == "":
error_message = "Username is required."
elif basic == "":
error_message = "Basic pay is required."
elif name == "":
error_message = "Name is required."
invalid_pass_format = customtkinter.CTkLabel(master=frame, text=error_message, text_color="Red", font=("Century Gothic", 15))
invalid_pass_format.place(x=200, y=299)
elif not re.search(r'[A-Z]', password) or not re.search(r'[a-z]', password) or not re.search(r'[0-9]', password) or not re.search(r'[\W_]', password):
invalid_pass_format = customtkinter.CTkLabel(master=frame, text="Invalid Password Format.", text_color="Red", font=("Century Gothic", 15))
invalid_pass_format.place(x=200, y=299)
elif username in data["users"].keys():
alread_exist_user = customtkinter.CTkLabel(master=frame, text="Username already exists.", text_color="Red", font=("Century Gothic", 15))
alread_exist_user.place(x=200, y=299)
print("Username already exists.")
else:
max_acc_number = max([user["acc"] for user in data["users"].values()], default=0)
new_acc_number = str(max_acc_number + 1).zfill(10)
data["users"][username] = {
"name": name,
"password": password,
"attendance": create_attendance(),
"acc": int(new_acc_number),
"isadmin": "false",
"basic": int(basic),
"pay_record": [0] * 12
}
with open("users.json", "w") as file:
json.dump(data, file, indent=4)
success_message = customtkinter.CTkLabel(master=frame, text="User created successfully.", text_color="Green", font=("Century Gothic", 15))
success_message.place(x=200, y=299)
window.after(2000, window.destroy)
user = Users()
user.login_page()