Start a Conversation

Unsolved

D

1 Rookie

 • 

1 Message

2

October 4th, 2025 21:08

Automating gratuity calculation — handling edge cases with code

Hi everyone,

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 vary based 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 logic for resignation cases is correct:

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 cross-check my formula, I ran a few examples through an end-of-service calculator to see if the results align.

Has anyone here implemented similar automation for payroll or HR systems?
I’d love to hear how you handle resignation deductions and partial month calculations.

Thanks in advance!

No Responses!
No Events found!

Top