Not sure if this the right sub-forum to ask (or if this belongs to base design), but I do have a problem.
Context is I am making a HR Leave Management System for my team and am trying to calculate Hospitalisation Leave. It is different from leaves like annual leaves where it is based on the years of service and that it resets every year.
The way this leave is calculated is if you are entitled 2 hospitalisation leave for every month you have worked in the first year, and 4 hospitalisation leave every month after the 12th month(from the 13th month onwards), with a cap of 120 days of hospitalisation leave. I can easily count how many days each employee currently are entitled with these 2 formulae in 2 different fields:
To calculate the amount of hospitalisation leave
IF({Number of months} <= 12, {Number of months}*2, IF({Number of months} > 12, (({Number of months}-12)*4)+24, 0))
120 days limit
IF({days of SL before limit} >= 120, 120, IF({days of SL before limit} < 120, {days of SL before limit}, 0))
Here comes the problem:
If someone were to actually take a hospitalisation leave of say 20 days, how do I ensure that after subtracting the 20 days off, the current leave I have will still be accumulated (+2/+4 every month) to the cap of 120?