Unsolved

1 Rookie

 • 

1 Message

49

September 30th, 2025 10:44

Automating gratuity calculation — handling edge cases with code

Hi all,

I’m working on an HR automation module where we need to automatically calculate end-of-service gratuity for employees in the UAE. The main challenge is that the rules change depending on:

  • Contract type (limited vs unlimited)

  • Years of service (less than 1 year, 1–5 years, 5+ years)

  • Resignation vs termination

I’ve written a small script to handle this, but I’m not sure if my formula covers resignation cases correctly:

function calcGratuity(basicSalary, years, contractType, exitType) {let gratuity = 0;if (years < 1) return 0;if (years >= 1 && years < 5) gratuity = (basicSalary * 21 / 30) * years;if (years >= 5) gratuity = (basicSalary * 30 / 30) * years;// unsure about exitType adjustments (resignation vs termination)return gratuity;}

To double-check, I built a small online demo tool that automates these variations and shows worked examples:
https://gratuitycalculatorae.com

Has anyone here implemented something similar in payroll or HR systems?
How do you handle resignation deductions and partial months in automation logic?

Thanks in advance!

No Responses!

Top