-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpayroll.py
More file actions
427 lines (352 loc) · 13.6 KB
/
payroll.py
File metadata and controls
427 lines (352 loc) · 13.6 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
# Imports
# Globals
weeks_annually = 52
# PAYE:
# Tax credits
tax_credit_single = 1775
tax_credit_employee = 1775
# Tax rate cut off
tax_rate_cutoff_low = 40000
# Low rate
tax_rate_low = 0.2
# High rate
tax_rate_high = 0.4
# USC
# PRSI
# Max PRSI credit
prsi_credit = 12
# List of employees
# First name
# Last name
# PPSN
# Personal tax credit
# PRSI class
# Annual salary amount
employee1 = {"First name": "John", "Last name": "Appleseed", "PPSN": "1234567AB",
"Personal tax credit": tax_credit_single, "PRSI class": "A",
"Annual salary amount": 40000}
employee2 = {"First name": "Joe", "Last name": "Dow", "PPSN": "1267673AZ",
"Personal tax credit": tax_credit_single, "PRSI class": "A",
"Annual salary amount": 65000}
employee3 = {"First name": "Eve", "Last name": "Adamson", "PPSN": "1290273KZ",
"Personal tax credit": tax_credit_single, "PRSI class": "A",
"Annual salary amount": 78000}
employees = []
employees.append(employee1)
employees.append(employee2)
employees.append(employee3)
# Functions
def start_menu():
print("\n Welcome to the Payroll!!!\n---------------------------------\n")
print("Type -1- to View the list of employees")
print("Type -2- to Add an employee")
print("Type -3- to Print a payslip")
print("Type -4- to Print all payslips")
print("Type -5- to Show annual payroll total")
print("Type -6- to Show monthly payroll total")
print("Type -7- to Show weekly payroll total")
print("Type -8- to Complete a survey about the service")
print("Type -h- for Help")
print("Type -0- to Exit")
def view_employees():
num = 1
for e in employees:
print(f'Employee {num} - Name: {e["First name"]} {e["Last name"]} PPSN: {e["PPSN"]} Salary: ${e["Annual salary amount"]}')
num += 1
def add_employee(details):
f_name, l_name, pps, credit_t, prsi, sal = details
print(f"{f_name} {l_name} {pps} {credit_t} {prsi} {sal}")
new_employee = {"First name": f_name, "Last name": l_name, "PPSN": pps,
"Personal tax credit": credit_t, "PRSI class": prsi,
"Annual salary amount": sal}
employees.append(new_employee)
view_employees()
# new_employee = dict()
# new_employee["First name"] = input("Add first name: ").strip().capitalize()
# new_employee["Last name"] = input("Add last name: ").strip().capitalize()
# new_employee["PPSN"] = input("Add PPSN: ")
# new_employee["Personal taxt credit"] = tax_credit_single
# new_employee["PRSI class"] = input("Add the PRSI class: ")
# new_employee["Annual salary amount"] = int(input("Add employee salary: "))
# employee_details()
# employees.append(new_employee)
def employee_details():
first_name = ""
last_name = ""
ppsn = ""
tax_credit = 0
prsi_class = ""
salary = 0
# First name (the variable must be in the loop for it to work)
while True:
first_name = input("Add employee first name: ").strip().capitalize()
if len(first_name) >= 2:
print(first_name)
break
else:
print("Please, enter a valid first name: ")
# Last name (if the variable outside the loop, the else should assign a value to the variable)
last_name = input("Add employee last name: ").strip().capitalize()
while True:
if len(last_name) >= 2:
print(last_name)
break
else:
last_name = input("Please, enter a valid last name: ")
# PPSN - 8 or 9 characters long and first 7 are numbers
while True:
ppsn = input("Add employee PPSN: ").strip()
if len(ppsn) == 8 and ppsn[:7].isdigit() and ppsn[-1].isalpha():
print(ppsn)
break
elif len(ppsn) == 9 and ppsn[:7].isdigit() and ppsn[-2:].isalpha():
print(ppsn)
break
else:
ppsn = input("Invalid entry. PPSN should be 8 or 9 characters long. Please, try again ")
# Tax credit
while True:
tax_credit_string = input("Add employee tax credit: ").strip()
arr = tax_credit_string.split(".")
arr_count = len(arr)
if arr_count < 3:
if "." in tax_credit_string and len(tax_credit_string) > 1:
tax_credit = float(tax_credit_string)
print(tax_credit)
break
elif tax_credit_string.isnumeric():
tax_credit = int(tax_credit_string)
print(tax_credit)
break
else:
print("Invalid entry. Tax credit must be a number: ")
else:
print("Invalid entry. Tax credit must contain no more than 1 decimal point")
# Tax credit class
while True:
prsi_class = input("Add employee PRSI class: ")
if len(prsi_class) == 2 and prsi_class[:1].upper() == "A":
print(prsi_class)
break
else:
print("Invalid entry. PRSI class must begin with 'A' and be 2 characters in length")
# Salary
while True:
salary_string = input("Add employee salary: ").strip()
arr = salary_string.split(".")
arr_count = len(arr)
if arr_count < 3:
if "." in salary_string and len(salary_string) > 1:
salary = float(salary_string)
print(salary)
break
elif salary_string.isnumeric():
salary = int(salary_string)
print(salary)
break
else:
print("Invalid entry. Salary must be a number: ")
else:
print("Invalid entry. Salary must contain no more than 1 decimal point")
print(f'{first_name} {last_name} {ppsn} {tax_credit} {prsi_class} {salary}')
return first_name, last_name, ppsn, tax_credit, prsi_class, salary
def get_annual_paye(employee):
annual_salary = employee["Annual salary amount"]
high_rate_amount = 0.00
low_rate_amount = 0.00
tax_liability = 0.00
tax_credit = employee["Personal tax credit"] + tax_credit_employee
# if annual salary > 40.000, anything above that figure is calculated at 40%
# Anything aup to this sum is calculated at 20%. Minus tax credits
# (20%+40%) - credit = payee liability
if annual_salary > tax_rate_cutoff_low:
#calculate 40% amount
high_rate_amount = (annual_salary - tax_rate_cutoff_low)*tax_rate_high
else:
low_rate_amount = annual_salary*tax_rate_low
tax_liability = (high_rate_amount + low_rate_amount) - tax_credit
return tax_liability
def weekly_prsi_employee(employee):
prsi = 0.00
prsi_credit = 0.0
weekly_gross = employee["Annual salary amount"]/weeks_annually
# if the employee is PRSI class A and earns less than $352.01, the pay $0
# If they earn between $352.01 and $441 they pay 4% minus their PRSI credit
# The credit does not apply to anything over $424.01
if weekly_gross < 352.01:
prsi = 0.00
elif weekly_gross > 352 and weekly_gross < 424.01:
prsi_credit_personal = prsi_credit - ((weekly_gross - 352.01)/6)
prsi = (weekly_gross*0.04)-prsi_credit_personal
else:
prsi = (weekly_gross*0.04)
return prsi
def weekly_prsi_employer(employee):
prsi = 0.00
prsi_credit = 0.0
weekly_gross = employee["Annual salary amount"]/weeks_annually
# if the employee is PRSI class A and earns less than $352.01, the pay $0
# If they earn between $352.01 and $441 they pay 4% minus their PRSI credit
# The credit does not apply to anything over $424.01
if weekly_gross <= 441:
prsi = weekly_gross*0.088
else:
prsi = (weekly_gross*0.1105)
return prsi
def usc_annual(employee):
usc = 0.00
annual_salary = employee["Annual salary amount"]
# Exempt if you earn < $13000
# Otherwise:
#
#
if annual_salary < 13000:
usc = 0.00
else:
usc = 12012*0.005
annual_salary = annual_salary-12012
if annual_salary >= 10908:
usc += 10908*0.02
annual_salary = annual_salary-10908
else:
usc += annual_salary*0.02
if annual_salary >= 47124:
usc += 47124*0.045
annual_salary = annual_salary-47124
else:
usc += annual_salary*0.045
if annual_salary > 0:
usc += annual_salary*0.08
return usc
# Print a payslip for a particular employee
def print_payslip(employee):
name = f"{employee['First name']} {employee['Last name']}"
ppsn = employee['PPSN']
tax_credit = (employee["Personal tax credit"] + tax_credit_employee)/weeks_annually
prsi_class = employee["PRSI class"]
salary = employee["Annual salary amount"]
gross_pay = salary/weeks_annually
annual_paye = get_annual_paye(employee)
weekly_paye = annual_paye/weeks_annually
employee_weekly_prsi = weekly_prsi_employee(employee)
employer_weekly_prsi = weekly_prsi_employer(employee)
usc_per_year = usc_annual(employee)
if usc_per_year > 0:
weekly_usc = usc_per_year/weeks_annually
net_pay = ((gross_pay - weekly_paye)-employee_weekly_prsi)-weekly_usc
print("\n--------------------------------------")
print("Eir Telecom Inc.")
print(f"Employee PPS no.: {ppsn}")
print(f"Employee name: {name}")
print(f"PRSI class: {prsi_class}")
print("\n--------------------------------------")
print(f"Gross pay: {salary/weeks_annually}")
print(f"PAYE: {weekly_paye}")
print(f"PRSI (employee): {employee_weekly_prsi}")
print(f"PRSI (employer): {employer_weekly_prsi}")
print(f"USC: {weekly_usc}")
print("\n -----------")
print(f"Net pay: {net_pay}")
print("\n--------------------------------------")
#print(f"Employee: {name}\t PPSN: {ppsn}\t ")
def payroll_gross():
payroll_gross = 0
payroll_each = 0
for e in employees:
payroll_each = e["Annual salary amount"]
#print(payroll_each)
payroll_gross += payroll_each
return payroll_gross
def help():
print("The menue has seven option for you:\n\
if you press '1' you are be presented with the list of all employees in the company;\n\
------------\n\
if you press '2' you can add a new employee into the system. Keep all the data at hand,\n\
i.e. first and last name, PPSN, personal tax credit, PRSI class, and the annual salary;\n\
------------\n\
if you press '3' you can print a payslip for an employee you may select from the list;\n\
------------\n\
if you press '4' you will print the payslips for all the employees at once;\n\
------------\n\
if you press '5' you will be presented with the gross annual payroll expenditure;\n\
------------\n\
if you press '6' you will be presented with the gross monthly payroll;\n\
------------\n\
if you press '7' you will be presented with the gross weekly payroll;\n\
------------\n\
if you press '8' you will be asked to complete a survey about the service;\n\
to exit the menue, press '0'.\n")
def question():
q = input("Would you like to continue? Print 'y' for yes or 'n' for no: ")
if q == "n":
print("Have a nice rest of the day!")
exit()
def survey():
q1 = int(input("On the scale from 1 to 10, how useful do you find this service? "))
q2 = int(input("On the scale from 1 to 10, how easy is it for you to use the service? "))
q3 = int(input("On the scale from 1 to 10, how how satisfied are you with the service? "))
score = (q1+q2+q3)/3
if score == 10:
print("Thank you! We are happy to serve you!")
elif score < 10 and score > 6:
print("Great to know you are like our service")
elif score <= 6:
print("We are sorry to hear you are not satisfied!")
exit()
# Main function
def main():
cont = True
while cont:
start_menu()
option = input()
# start_menu()
# option = input()
if(option == "1"):
view_employees()
question()
elif(option == "2"):
add_employee(employee_details())
question()
elif(option == "3"):
view_employees()
# A loop to check the validity of the input of the employee number
valid = True
while valid:
employee_num = int(input("Please, provide the employee number: "))
if employee_num > len(employees):
print("Please, enter a valid number")
else:
print_payslip(employees[employee_num - 1])
valid = False
question()
elif(option == "4"):
for e in employees:
print_payslip(e)
question()
# payroll annual
elif(option == "5"):
#print("The annual payroll is:", payroll_gross())
print(f"The annual payroll is: {payroll_gross()}")
question()
# monthly
elif(option == "6"):
print(f"The monthly payroll is: {payroll_gross()/12}")
question()
# weekly
elif(option == "7"):
print(f"The weekly payroll is: {payroll_gross()/52}")
question()
# survey
elif(option == "8"):
survey()
elif(option == "h" or option == "H"):
help()
question()
elif(option == "0"):
print("Have a nice rest of the day!")
cont=False
#exit()
else:
print("****Error****\nPlease, provide correct input!")
# Call Main here
main()