Business rules in time off can be tricky based on the customers' requirements, and rounding of accruals may be one of them. There are couple of notes and blogs regarding this topic. (The most generic one can be found here.) In this article, I wanted to share a bit more complicated example with detailed explanations. You will see that the business rule is straight-forward easy; and compared to that, the scenario requires more attention.
Scenario
In our example, employee earns total of 20 days of accrual within a year. We want to have a hire and/or a termination rule, and want to recalculate accruals based on couple of conditions.
If the employee worked for a full year, the accrual will be 20 days, and will be prorated based on applicable months. As an example, for 10 months of work, the prorated amount will be: 20 / 12 x 10 = 16,67.
Note: The calculation of the total number of months within a year where employee was applicable for accrual is not the subject of this article. This value will be stored in a standard variable, which will be used within a business rule.
By looking at the example above, we can then create a table as follows:
Months | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
Accrual | 1,67 | 3,33 | 5 | 6,67 | 8,33 | 10 | 11,67 | 13,33 | 15 | 16,67 | 18,33 | 20 |
Now comes the tricky part: The customer wants to change its approach and adjust these amounts, so that:
So the desired accrual amounts will be as follows:
Months | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
Accrual | 1,5 | 3,5 | 5 | 6,5 | 8,5 | 10 | 11,5 | 13,5 | 15 | 16,5 | 18,5 | 20 |
The following section will be about how to achieve this.
The business rule that we are going to use can be found below.
Now let us breakdown the rule in details.
The result of these operations can be found below:
Months | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
Accrual | 1,67 | 3,33 | 5 | 6,67 | 8,33 | 10 | 11,67 | 13,33 | 15 | 16,67 | 18,33 | 20 |
x 2 | 3,33 | 6,66 | 10 | 13,33 | 16,66 | 20 | 23,33 | 26,66 | 30 | 33,33 | 36,66 | 40 |
Round | 3 | 7 | 10 | 13 | 17 | 20 | 23 | 27 | 30 | 33 | 37 | 40 |
/ 2 | 1,5 | 3,5 | 5 | 6,5 | 8,5 | 10 | 11,5 | 13,5 | 15 | 16,5 | 18,5 | 20 |
As seen, we now have the desired results, and job's done!
If you have different rounding criterions, you can easily adjust the number 2 we used above, and change this value according to your requirements. As an example, if you want to round the accruals to the closest 0,2 fractions, then you can use number 5 while multiplying and dividing.
Months | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
Accrual | 1,67 | 3,33 | 5 | 6,67 | 8,33 | 10 | 11,67 | 13,33 | 15 | 16,67 | 18,33 | 20 |
x 5 | 8,33 | 16,66 | 25 | 33,33 | 41,66 | 50 | 58,33 | 66,66 | 75 | 83,33 | 91,66 | 100 |
Round | 8 | 17 | 25 | 33 | 42 | 50 | 58 | 67 | 75 | 83 | 92 | 100 |
/ 5 | 1,6 | 3,4 | 5 | 6,6 | 8,4 | 10 | 11,6 | 13,4 | 15 | 16,6 | 18,4 | 20 |
I always have fun during adjusting the business rules and brainstorm about such calculations. I hope that this article will be helpful for you during your projects! Please also check the other blogs related to this topic.
Also please feel free to give feedback or comment.
Best,
Altug
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
11 | |
8 | |
5 | |
4 | |
4 | |
4 | |
3 | |
2 | |
2 | |
1 |