Leaver Holiday Calculator
Calculate a leaving employee's holiday balance.
Leaving employees are entitled to payment for accrued but unused holidays. Employers can deduct from an employee's final pay if they have overused their holiday when calculated pro-rata at the leaving date.
1. Write the script
This step is as simple as pasting the code below into a new python file.
Make a new file called leaver_calc.py. In the terminal you can simply enter:
$ touch leaver_calc.py
Now open it in your favourite text editor and enter the following:
import datetime as dt
start = input(str("Start Date (dd mm yy): "))
end = input("Leaving (dd mm yy): ")
entitlement = float(input("Entitlement: "))
holidays = float(input("Holidays taken: "))
carry = float(input("Carry over: "))
s = start.split("-")
start_date = dt.datetime(int(s[2]), int(s[1]), int(s[0]))
d = end.split("-")
end_date = dt.datetime(int(d[2]), int(d[1]), int(d[0]))
difference = end_date - start_date
fraction = float(difference.days)/365
print(difference)
print(fraction)
pro_rata = entitlement * fraction
total = pro_rata + (carry - holidays)
print(total)
2. Use the script from the terminal
Open your terminal, and go to the directory you saved leaver_calc.py in. Use the cd
command to change directories.
Check the script is indeed in your current director by ensuring the filename is lister there when you run the list command:
$ ls -l
Now run the script by entering the following:
$ python3 leaver_calc.py
If you entered the script correctly, you should see it prompt you for the relevant information such as start date (i.e. the start of the holiday year), leaving date et cetera. Once the information has been given, the pro-ated balance of days will be calculated.
You could easily extend the functionality of the script - why not try adding a "salary" input to work out the size of the payment based on the resulting number of days?