-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompany.py
More file actions
160 lines (136 loc) · 5.94 KB
/
Copy pathcompany.py
File metadata and controls
160 lines (136 loc) · 5.94 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
from datetime import datetime
import os
COMPANY_NAME = "\t\t\t ABC PVT. LTD."
COMPANY_ADD = "\t\t\t B2/23 xyz Colony\n\t\t\t New Delhi - 110003"
class Employee(object):
def __init__(self, emp_id, name, position, grade_pay, basic_pay, ta_basic, ma):
self.emp_id = emp_id
self.name = name
self.position = position
self.grade_pay = grade_pay
self.basic_pay = basic_pay
self.ta_basic = ta_basic
self.ma = ma
def _calc_epf(self):
return 0.12 * self.basic_pay
def _calc_itax(self):
return 0.2 * self.basic_pay
def _calc_hra(self):
return 0.3 * (self.basic_pay + self.grade_pay)
def _calc_da(self):
return 1.32 * (self.basic_pay + self.grade_pay)
def _calc_total(self):
return (self.basic_pay + self.grade_pay +
self._calc_hra() + self._calc_da())
def _calc_ta(self):
return 1.32 * self.ta_basic
def _calc_total_pay(self):
return (self.basic_pay + self.grade_pay +
self._calc_hra() + self._calc_da() +
self.ta_basic + self._calc_ta() + self.ma)
def _calc_deduce(self):
return self._calc_epf() + self._calc_itax()
def print_employee(self, now):
print(COMPANY_NAME)
print(COMPANY_ADD)
print("\t\t\t\t\t\t\tDate: " + str(now.day) + '/' + str(now.month) + '/' + str(now.year))
print("\n\tEmployee Number: " + str(self.emp_id) + '\tName: ' + self.name + '\t\tPost: ' + self.position)
print("\n\t Payment\t\t\t\t\t Deduction")
print("\tBasic Pay: " + str(self.basic_pay) + '\t\t\t\tEPF: ' + str(self._calc_epf()))
print("\tGrade Pay: " + str(self.grade_pay) + " \t\t\t\tITAX: " + str(self._calc_itax()))
print("\tTotal: " + str(self._calc_total()))
print("\tHRA: " + str(self._calc_hra()))
print("\tDA: " + str(self._calc_da()))
print("\tTABASIC: " + str(self.ta_basic))
print("\tTA: " + str(self._calc_ta()))
print("\tMA: " + str(self.ma))
print("\n\tTotal Pay: " + str(self._calc_total_pay()) + "\t\t\t Total Deduction: " + str(self._calc_deduce()))
def generate_pay_slip(self, now):
with open(self.name + '.txt', 'w') as f:
f.write(COMPANY_NAME)
f.write('\n' + COMPANY_ADD)
f.write("\n\t\t\t\t\t\t\tDate: " + str(now.day) + '/' + str(now.month) + '/' + str(now.year))
f.write("\n\n\tEmployee Number: " + str(self.emp_id) + '\tName: ' + self.name + '\t\tPost: ' + self.position)
f.write("\n\n\t Payment\t\t\t\t\t Deduction")
f.write("\n\tBasic Pay: " + str(self.basic_pay) + '\t\t\t\tEPF: ' + str(self._calc_epf()))
f.write("\n\tGrade Pay: " + str(self.grade_pay) + " \t\t\t\tITAX: " + str(self._calc_itax()))
f.write("\n\tTotal: " + str(self._calc_total()))
f.write("\n\tHRA: " + str(self._calc_hra()))
f.write("\n\tDA: " + str(self._calc_da()))
f.write("\n\tTABASIC: " + str(self.ta_basic))
f.write("\n\tTA: " + str(self._calc_ta()))
f.write("\n\tMA: " + str(self.ma))
f.write("\n\n\tTotal Pay: " + str(self._calc_total_pay()) + "\t\t\t Total Deduction: " + str(self._calc_deduce()))
def generate_pay_slip_and_print(self):
now = datetime.now()
self.print_employee(now)
self.generate_pay_slip(now)
def get_new_id(li):
if len(li) == 0: return 1
max_id = li[0].emp_id
for i in range(1, len(li)):
if li[i].emp_id > max_id:
max_id = li[i].emp_id
return max_id
def enter_new_employee(emp_id):
name = input('Enter Name: ')
position = input('Enter Position: ')
grade_pay = float(input('Enter Grade Pay: '))
basic_pay = float(input('Enter Basic Pay: '))
ta_basic = float(input('Enter TABASIC: '))
ma = float(input('Enter ma: '))
return Employee(emp_id, name, position, grade_pay,
basic_pay, ta_basic, ma)
def find_employee(employees, emp_id):
for i in range(len(employees)):
if employees[i].emp_id == emp_id:
return True, i
return False, None
if __name__ == '__main__':
employees = []
while True:
print('\t\tMENU')
print('-' * 50)
print('\t1. Enter New Employee Details')
print('\t2. Make Employee Pay Slip')
print('\t3. Delete Employee')
print('\t4. Update Employee')
print('\t5. Display Employee')
print('\t6. Exit')
print('-' * 50)
choice = int(input('Enter Your Choice: '))
if choice == 1:
employees.append(enter_new_employee(get_new_id(employees)))
print('\nID Given: '+str(employees[-1].emp_id))
elif choice == 2:
emp_id = int(input('Enter Employee ID: '))
is_found, emp_pos = find_employee(employees, emp_id)
if is_found:
employees[emp_pos].generate_pay_slip(datetime.now())
print("Generate Pay Slip")
else:
print("Employee Doesn't exist.")
elif choice == 3:
emp_id = int(input('Enter Employee ID: '))
is_found, pos = find_employee(employees, emp_id)
if is_found:
del employees[pos]
else:
print("Employee Doesn't exist.")
elif choice == 4:
emp_id = int(input('Enter Employee ID: '))
is_found, emp_pos = find_employee(employees, emp_id)
if is_found:
employees[emp_pos] = enter_new_employee(employees[emp_pos].emp_id)
else:
print("Employee Doesn't exist.")
elif choice == 5:
emp_id = int(input('Enter Employee ID: '))
is_found, emp_pos = find_employee(employees, emp_id)
if is_found:
employees[emp_pos].print_employee()
else:
print("Employee Doesn't exist.")
else:
print('Program Terminating!!!')
break