Here is a logic that I have to implement in an in-house application that manages attendance, leaves, etc. The following is one of the workflows in leave application processing.<p><pre><code> if (attendance has been marked for any session of the leave duration) {
perform exception processing // excluded for simplicity
return
}
if (applied leave duration overlaps (partly or fully) with any other currently-valid leave application) {
reject and return
}
switch (leave type) {
case annual:
if (not enough annual leave balance) {
reject and return
}
// more annual condition checks
case carry-forward:
if (not enough carry forward leave balance) {
reject and return
}
// more carry-forward condition checks
case paternity, maternity:
branch out to eligibility and extent of availability processing // excluded for simplicity
case compensatory-off:
if (date against which compensation is availed was working) {
reject and return
}
if (employee did not work on that day) {
reject and return
}
if (that date is already used for compensatory off) {
reject and return
}
// more compensatory checks
case loss-of-pay:
// several loss-of-pay checks
// several more varieties
}
load the holiday calendar based on employee's location
load the shift details for the employee
calculate effective duration of leave
insert / update all applicable records
write audit entries and logs
send response back
</code></pre>
Significantly simplified logic above excludes things like leave duration crossing year boundary (some counters get reset; new leave quotas may become available).<p>I look forward to guidance on how to approach this from a functional programming perspective. Thanks.