-
Notifications
You must be signed in to change notification settings - Fork 0
/
LNCT_LeaveSystem.py
364 lines (282 loc) · 13.9 KB
/
LNCT_LeaveSystem.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
import sqlite3
import tkinter.messagebox as tk
from tkinter.font import Font
from easygui import *
from tkinter import *
import random
conn = sqlite3.connect('leaveDb.db')
cur = conn.cursor()
# conn.execute("CREATE TABLE balance (employee_id text,sickleave int,maternityleave int,emergencyleave int)")
# conn.execute("CREATE TABLE status (leave_id int,employee_id text,leave text,Date1 text,Date2 text,days int,status text)")
# conn.execute('''CREATE TABLE employee (employee_id text,Name text,ContactNumber text,Password text)''')
def AdminLogin():
text = "Enter Username and Password"
title = "Admin Login"
fieldnames = ["Username", "Password"]
field = []
field = multpasswordbox(text, title, fieldnames)
if field[0] == 'admin' and field[1] == 'admin':
tk.showinfo("Admin Login", "Login Successfully")
adminwindow()
else:
tk.showerror("Error info", "Incorrect username or password")
def EmployeeLogin():
message = "Enter Employee ID and Password"
title = "Employee Login"
fieldnames = ["Employee ID", "Password"]
field = []
field = multpasswordbox(message, title, fieldnames)
for row in conn.execute('SELECT * FROM employee'):
f=0
if field[0] == row[0] and field[1] == row[3]:
global login
login = field[0]
f = 1
print("Success")
tk.showinfo("Employee Login", "Login Successfully")
EmployeeLoginWindow()
break
if not f:
print("Invalid")
tk.showerror("Error info", "Incorrect employee id or password")
def Employeelogout():
global login
login = -1
LoginWindow.destroy()
def EmployeeLeaveStatus():
global leaveStatus
leaveStatus = []
for i in conn.execute('SELECT * FROM status where employee_id=?', (login,)):
leaveStatus = i
WindowStatus()
def EmployeeAllStatus():
allStatus = Toplevel()
txt = Text(allStatus)
for i in conn.execute('SELECT * FROM status where employee_id=?', (login,)):
txt.insert(INSERT, i)
txt.insert(INSERT, '\n')
txt.pack()
def EmployeeInformationWindow():
employeeInformation = Toplevel()
txt = Text(employeeInformation)
for i in conn.execute('SELECT employee_id,Name,ContactNumber FROM employee where employee_id=?', (login,)):
txt.insert(INSERT, i)
txt.insert(INSERT, '\n')
txt.pack()
def EmployeeAllInformationWindow():
allEmployeeInformation = Toplevel()
txt = Text(allEmployeeInformation)
for i in conn.execute('SELECT employee_id,Name,ContactNumber FROM employee'):
txt.insert(INSERT, i)
txt.insert(INSERT, '\n')
txt.pack()
def WindowStatus():
StatusWindow = Toplevel()
label_1 = Label(StatusWindow, text="Employee ID=", fg="blue", font=("Calibri", 16), justify=LEFT)
label_2 = Label(StatusWindow, text=leaveStatus[1], font=("Calibri", 16))
label_3 = Label(StatusWindow, text="Type=", fg="blue", font=("Calibri", 16), justify=LEFT)
label_4 = Label(StatusWindow, text=leaveStatus[2], font=("Calibri", 16))
label_5 = Label(StatusWindow, text="start=", fg="blue", font=("Calibri", 16), justify=LEFT)
label_6 = Label(StatusWindow, text=leaveStatus[3], font=("Calibri", 16))
label_7 = Label(StatusWindow, text="end=", fg="blue", font=("Calibri", 16), justify=LEFT)
label_8 = Label(StatusWindow, text=leaveStatus[4], font=("Calibri", 16))
label_9 = Label(StatusWindow, text="Status:", fg="blue", font=("Calibri", 16), justify=LEFT)
label_10 = Label(StatusWindow, text=leaveStatus[6], font=("Calibri", 16))
label_11 = Label(StatusWindow, text="leave_id:", fg="blue", font=("Calibri", 16), justify=LEFT)
label_12 = Label(StatusWindow, text=leaveStatus[0], font=("Calibri", 16))
label_11.grid(row=0, column=0)
label_12.grid(row=0, column=1)
label_1.grid(row=1, column=0)
label_2.grid(row=1, column=1)
label_3.grid(row=2, column=0)
label_4.grid(row=2, column=1)
label_5.grid(row=3, column=0)
label_6.grid(row=3, column=1)
label_7.grid(row=4, column=0)
label_8.grid(row=4, column=1)
label_9.grid(row=5, column=0)
label_10.grid(row=5, column=1)
def balance():
global login
global balanced
check = (login,)
balanced = []
for i in conn.execute('SELECT * FROM balance WHERE employee_id = ?', check):
balanced = i
WindowBalance()
def WindowBalance():
balanceWindow = Toplevel()
label_1 = Label(balanceWindow, text="Employee ID=", fg="blue", font=("Calibri", 16), justify=LEFT)
label_2 = Label(balanceWindow, text=balanced[0], font=("Calibri", 16))
label_3 = Label(balanceWindow, text="Sick Leave=", fg="blue", font=("Calibri", 16), justify=LEFT)
label_4 = Label(balanceWindow, text=balanced[1], font=("Calibri", 16))
label_5 = Label(balanceWindow, text="Maternity Leave=", fg="blue", font=("Calibri", 16), justify=LEFT)
label_6 = Label(balanceWindow, text=balanced[2], font=("Calibri", 16))
label_7 = Label(balanceWindow, text="Emergency Leave=", fg="blue", font=("Calibri", 16), justify=LEFT)
label_8 = Label(balanceWindow, text=balanced[3], font=("Calibri", 16))
label_1.grid(row=0, column=0)
label_2.grid(row=0, column=1)
label_3.grid(row=1, column=0)
label_4.grid(row=1, column=1)
label_5.grid(row=2, column=0)
label_6.grid(row=2, column=1)
label_7.grid(row=3, column=0)
label_8.grid(row=3, column=1)
def apply():
message = "Enter the following details "
title = "Leave Apply"
fieldNames = ["Employee ID", "From", "To", "days"]
fieldValues = []
fieldValues = multenterbox(message, title, fieldNames)
if(fieldValues[0].isnumeric()):
message1 = "Select type of leave"
title1 = "Type of leave"
choices = ["Sick leave", "Maternity leave", "Emergency leave"]
choice = choicebox(message1, title1, choices)
leaveid = random.randint(100, 1000)
conn.execute("INSERT INTO status(leave_id,employee_id,leave,Date1,Date2,days,status) VALUES (?,?,?,?,?,?,?)", (leaveid, fieldValues[0], choice, fieldValues[1], fieldValues[2], fieldValues[3], "Pending"))
conn.commit()
def LeaveApproval():
message = "Enter Leave_Id"
title = "Leave Approval"
fieldNames = ["Leave_Id"]
fieldValues = []
fieldValues = multenterbox(message, title, fieldNames)
if(fieldValues[0].isnumeric()):
message1 = "Approve/Deny"
title1 = "Leave Approval"
choices = ["approve", "deny"]
choice = choicebox(message1, title1, choices)
conn.execute("UPDATE status SET status = ? WHERE leave_id= ?", (choice, fieldValues[0]))
conn.commit()
if choice == 'approve':
cur.execute("SELECT leave FROM status WHERE leave_id=?", (fieldValues[0],))
col = cur.fetchall()
for row in conn.execute("SELECT employee_id FROM status WHERE leave_id=?", (fieldValues[0],)):
exampleId = row[0]
for row in conn.execute("SELECT days FROM status WHERE leave_id=?", (fieldValues[0],)):
exampleDays = row[0]
for row in conn.execute("SELECT sickleave from balance where employee_id=?", (exampleId,)):
balance = row[0]
for row in conn.execute("SELECT maternityleave from balance where employee_id=?", (exampleId,)):
balance1 = row[0]
for row in conn.execute("SELECT emergencyleave from balance where employee_id=?", (exampleId,)):
balance2 = row[0]
if (col[0] == ('Sick leave',)):
conn.execute("UPDATE balance SET sickleave =? WHERE employee_id= ?", ((balance - exampleDays), (exampleId)))
if (col[0] == ('Maternity leave',)):
conn.execute("UPDATE balance SET maternityleave =? WHERE employee_id= ?", ((balance1 - exampleDays), (exampleId)))
if (col[0] == ('Emergency leave',)):
conn.execute("UPDATE balance SET emergencyleave =? WHERE employee_id= ?", ((balance2 - exampleDays), (exampleId)))
def leavelist():
leavelistwindow = Toplevel()
txt = Text(leavelistwindow)
for i in conn.execute('SELECT * FROM status'):
txt.insert(INSERT, i)
txt.insert(INSERT, '\n')
txt.pack()
def registration():
message = "Enter Details of Employee"
title = "Registration"
fieldNames = ["Employee ID", "Name", "Contact Number", "Password"]
fieldValues = []
fieldValues = multpasswordbox(message, title, fieldNames)
while 1:
if fieldValues == None:
break
errmsg = ""
for i in range(len(fieldNames)):
if fieldValues[i].strip() == "":
errmsg = errmsg + ('"%s" is a required field.\n\n' % fieldNames[i])
if errmsg == "":
break
fieldValues = multpasswordbox(errmsg, title, fieldNames, fieldValues)
if(fieldValues[0].isnumeric()):
conn.execute("INSERT INTO employee(employee_id,Name,ContactNumber,Password) VALUES (?,?,?,?)", (fieldValues[0], fieldValues[1], fieldValues[2], fieldValues[3]))
conn.execute("INSERT INTO balance(employee_id,sickleave,maternityleave,emergencyleave) VALUES (?,?,?,?)", (fieldValues[0], 12, 12, 50))
conn.commit()
def EmployeeLoginWindow():
global LoginWindow
LoginWindow = Toplevel()
LoginWindow.wm_attributes('-fullscreen', '1')
Background_Label = Label(LoginWindow, image=filename)
Background_Label.place(x=0, y=0, relwidth=1, relheight=1)
informationEmployee = Button(LoginWindow, text='Employee information', command=EmployeeInformationWindow, bd=12, relief=GROOVE, fg="white", bg="cornflower blue", font=("Calibri", 36, "bold"), pady=3)
informationEmployee['font'] = BtnFont
informationEmployee.pack(fill=X)
submit = Button(LoginWindow, text='Submit Leave', command=apply, bd=12, relief=GROOVE, fg="white", bg="cornflower blue", font=("Calibri", 36, "bold"), pady=3)
submit['font'] = BtnFont
submit.pack(fill=X)
LeaveBalance = Button(LoginWindow, text='Leave Balance', command=balance, bd=12, relief=GROOVE, fg="white", bg="cornflower blue", font=("Calibri", 36, "bold"), pady=3)
LeaveBalance['font'] = BtnFont
LeaveBalance.pack(fill=X)
LeaveApplicationStatus = Button(LoginWindow, text='Last leave status', command=EmployeeLeaveStatus, bd=12, relief=GROOVE, fg="white", bg="cornflower blue", font=("Calibri", 36, "bold"), pady=3)
LeaveApplicationStatus['font'] = BtnFont
LeaveApplicationStatus.pack(fill=X)
AllLeaveStatus = Button(LoginWindow, text='All leave status', command=EmployeeAllStatus, bd=12, relief=GROOVE, fg="white", bg="cornflower blue", font=("Calibri", 36, "bold"), pady=3)
AllLeaveStatus['font'] = BtnFont
AllLeaveStatus.pack(fill=X)
LogoutBtn = Button(LoginWindow, text='Logout', bd=12, relief=GROOVE, fg="red", bg="cornflower blue", font=("Calibri", 36, "bold"), pady=3, command=Employeelogout )
LogoutBtn['font'] = BtnFont
LogoutBtn.pack(fill=X)
informationEmployee.pack()
submit.pack()
LeaveBalance.pack()
LeaveApplicationStatus.pack()
AllLeaveStatus.pack()
LogoutBtn.pack()
ExitBtn.pack()
def adminwindow():
adminmainwindow = Toplevel()
adminmainwindow.wm_attributes('-fullscreen', '1')
Background_Label = Label(adminmainwindow, image=filename)
Background_Label.place(x=0, y=0, relwidth=1, relheight=1)
informationEmployee = Button(adminmainwindow, text='All Employee information', command=EmployeeAllInformationWindow, bd=12,relief=GROOVE, fg="white", bg="cornflower blue", font=("Calibri", 36, "bold"), pady=3)
informationEmployee['font'] = BtnFont
informationEmployee.pack(fill=X)
LeaveListButton = Button(adminmainwindow, text='Leave approval list', command=leavelist, bd=12, relief=GROOVE, fg="white", bg="cornflower blue",font=("Calibri", 36, "bold"), pady=3)
LeaveListButton['font'] = BtnFont
LeaveListButton.pack(fill=X)
ApprovalButton = Button(adminmainwindow, text='Approve leave', command=LeaveApproval, bd=12, relief=GROOVE, fg="white", bg="cornflower blue", font=("Calibri", 36, "bold"), pady=3)
ApprovalButton['font'] = BtnFont
ApprovalButton.pack(fill=X)
LogoutBtn = Button(adminmainwindow, text='Logout', command=adminmainwindow.destroy, bd=12, relief=GROOVE, fg="red",bg="cornflower blue", font=("Calibri", 36, "bold"), pady=3)
LogoutBtn['font'] = BtnFont
LogoutBtn.pack(fill=X)
informationEmployee.pack()
LeaveListButton.pack()
ApprovalButton.pack()
ExitBtn.pack()
root = Tk()
root.wm_attributes('-fullscreen', '1')
root.title("Leave Management System")
root.iconbitmap(default='LNCT_Bhopal_Logo.ico')
filename = PhotoImage(file="background.gif")
background_label = Label(root, image=filename)
background_label.place(x=0, y=0, relwidth=1, relheight=1)
BtnFont = Font(family='Calibri(Body)', size=20)
MainLabel = Label(root, text="Leave Management System", bd=12, relief=GROOVE, fg="black", bg="cornflower blue",
font=("Calibri", 36, "bold"), pady=3)
MainLabel.pack(fill=X)
AdminLgnBtn = Button(root, text='Admin login', bd=12, relief=GROOVE, fg="white", bg="cornflower blue",
font=("Calibri", 36, "bold"), pady=3,padx=330, command=AdminLogin)
AdminLgnBtn['font'] = BtnFont
AdminLgnBtn.pack()
LoginBtn = Button(root, text='Employee login', bd=12, relief=GROOVE, fg="white", bg="cornflower blue",
font=("Calibri", 36, "bold"), pady=3,padx=310, command=EmployeeLogin)
LoginBtn['font'] = BtnFont
LoginBtn.pack()
EmployeeRegistration = Button(root, text='Employee registration',bd=12, relief=GROOVE, fg="white",
bg="cornflower blue",font=("Calibri", 36, "bold"), pady=3,padx=270, command=registration)
EmployeeRegistration['font'] = BtnFont
EmployeeRegistration.pack()
ExitBtn = Button(root, text='Exit', command=root.destroy, bd=12, relief=GROOVE, fg="red", bg="cornflower blue",
font=("Calibri", 36, "bold"), pady=3,padx=380)
ExitBtn['font'] = BtnFont
ExitBtn.pack()
MainLabel.pack()
AdminLgnBtn.pack()
LoginBtn.pack()
EmployeeRegistration.pack()
ExitBtn.pack()
root.mainloop()