Leave Management in HRMS: Designing Accrual, Carry-Forward and Encashment Rules in Oracle
How to design leave management in an Oracle-based HRMS: leave types and policies in tables, a leave ledger instead of a balance column, monthly accrual, proration for joiners, carry-forward caps, encashment, sandwich rules and year-end processing.
HRMS · Oracle PL/SQL
Leave Management in HRMS: Designing Accrual, Carry-Forward and Encashment Rules
Leave looks like the simplest part of an HRMS: an employee has 20 days, takes 3, has 17 left. In practice, leave is where HR departments lose the most trust in their software. Balances do not match what employees expect, a new joiner gets a full year’s entitlement on day one, carry-forward is applied twice after a rerun, and nobody can explain how a balance of 11.5 was calculated.
Almost all of these problems come from one design decision: storing the leave balance as a single number that the system keeps updating. This guide shows a better structure – policies in tables and every movement in a ledger – with Oracle SQL and PL/SQL examples you can adapt to an APEX-based HR system.
1. Separate leave types, policies and employees
Different employee groups usually have different rules: staff and workers, permanent and contract, head office and factory. Keep the rules in a policy table instead of in code:
CREATE TABLE lv_type (
leave_code VARCHAR2(10) PRIMARY KEY, -- ANNUAL, CASUAL, SICK
leave_name VARCHAR2(60) NOT NULL,
paid_flag CHAR(1) DEFAULT 'Y'
);
CREATE TABLE lv_policy (
policy_code VARCHAR2(20) NOT NULL,
leave_code VARCHAR2(10) NOT NULL REFERENCES lv_type,
effective_from DATE NOT NULL,
annual_days NUMBER NOT NULL, -- e.g. 14
accrual_method VARCHAR2(10) NOT NULL
CHECK (accrual_method IN ('YEARLY','MONTHLY')),
prorate_joiners CHAR(1) DEFAULT 'Y',
max_carry_forward NUMBER DEFAULT 0, -- days allowed into next year
max_balance NUMBER, -- optional cap
encash_allowed CHAR(1) DEFAULT 'N',
min_service_days NUMBER DEFAULT 0, -- e.g. eligible after probation
count_holidays CHAR(1) DEFAULT 'N', -- sandwich rule
CONSTRAINT lv_policy_pk PRIMARY KEY (policy_code, leave_code, effective_from)
);
Each employee is linked to a policy code. When the company changes its rules from next January, you add new policy rows with a new effective_from date – the old rules remain available for recalculating past years.
The numbers themselves – how many days, what carries forward, what can be encashed – must come from your company’s HR policy and the labour laws that apply to your workers. The software’s job is to apply those rules consistently, not to decide them.
2. Use a leave ledger, not a balance column
Instead of a balance column that is updated in place, record every movement as a row. The balance is simply the sum.
CREATE TABLE lv_ledger (
ledger_id NUMBER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
emp_id NUMBER NOT NULL,
leave_code VARCHAR2(10) NOT NULL,
leave_year NUMBER(4) NOT NULL,
txn_date DATE NOT NULL,
txn_type VARCHAR2(12) NOT NULL
CHECK (txn_type IN ('OPENING','ACCRUAL','AVAILED','CARRY_FWD',
'LAPSE','ENCASH','ADJUST')),
days NUMBER(6,2) NOT NULL, -- + adds, - deducts
ref_id NUMBER, -- leave application / run id
remarks VARCHAR2(200),
created_by VARCHAR2(60) DEFAULT USER,
created_on DATE DEFAULT SYSDATE
);
-- Current balance
SELECT emp_id, leave_code, SUM(days) AS balance
FROM lv_ledger
WHERE leave_year = :p_year
GROUP BY emp_id, leave_code;
The ledger answers every question an employee or auditor will ask: when did I earn this, when did I use it, why was 2 days lapsed? It also makes reprocessing safe – you can delete the ledger rows of one type for one run (for example all ACCRUAL rows created by a monthly run) and post them again, without touching approved leave.
3. Accrual: yearly or monthly
With yearly accrual the full entitlement is credited at the start of the year. It is simple, but an employee who resigns in February may already have used leave they had not yet earned. With monthly accrual, one-twelfth is credited each month, so the balance always reflects service.
A monthly accrual run can be a single, re-runnable procedure:
CREATE OR REPLACE PROCEDURE lv_run_monthly_accrual (
p_month_start IN DATE -- first day of the month
) IS
l_year NUMBER := EXTRACT(YEAR FROM p_month_start);
BEGIN
-- make the run repeatable
DELETE FROM lv_ledger
WHERE txn_type = 'ACCRUAL'
AND txn_date = p_month_start;
INSERT INTO lv_ledger (emp_id, leave_code, leave_year, txn_date,
txn_type, days, remarks)
SELECT e.emp_id,
p.leave_code,
l_year,
p_month_start,
'ACCRUAL',
ROUND(p.annual_days / 12, 2),
'Monthly accrual ' || TO_CHAR(p_month_start, 'Mon YYYY')
FROM hr_employee e
JOIN lv_policy p ON p.policy_code = e.leave_policy
WHERE p.accrual_method = 'MONTHLY'
AND p.effective_from = (SELECT MAX(p2.effective_from)
FROM lv_policy p2
WHERE p2.policy_code = p.policy_code
AND p2.leave_code = p.leave_code
AND p2.effective_from <= p_month_start)
AND e.join_date <= LAST_DAY(p_month_start)
AND (e.leaving_date IS NULL OR e.leaving_date >= p_month_start)
AND p_month_start - e.join_date >= p.min_service_days;
END;
Rounding each month to two decimals can leave 13.92 instead of 14.00 at year end. A common fix is to credit the difference in December so the year totals exactly the annual entitlement – decide this rule with HR and apply it in the same procedure.
4. Joiners and leavers
For yearly accrual, prorate the opening credit for employees who join mid-year: entitlement × remaining days in the year ÷ days in the year, rounded according to policy (many companies round to the nearest half day). Store the result as an OPENING or ACCRUAL row with a clear remark such as “Prorated: joined 15 Aug, 139/365 days”.
For leavers, the final settlement must calculate the balance up to the leaving date. If leave was credited in advance (yearly method) and the employee used more than they earned, the final settlement may need a recovery. With a ledger, this calculation is one query; with a balance column it is guesswork.
5. Availing leave: working days, holidays and the sandwich rule
When an application is approved, post an AVAILED row with negative days. The number of days depends on two policy decisions:
- Weekly offs and public holidays. Usually a leave from Thursday to Monday counts only the working days. This requires a holiday calendar table and each employee’s weekly off day – which may differ between office staff and shift workers.
- Sandwich rule. Some companies count a holiday that falls between two leave days as leave. If your policy has this rule, make it a policy flag (
count_holidays) rather than special code.
Half-day leave is simply 0.5 days in the ledger. Do not allow an approval that takes the balance below zero unless the policy explicitly allows negative balances, and check it in the database procedure, not only in the APEX screen.
6. Year-end: carry forward, lapse and encashment
Year-end processing turns the closing balance of one year into the opening of the next. Process each employee and leave type in this order:
- Calculate the closing balance for the year from the ledger.
- Carry forward up to
max_carry_forwardinto the new year as aCARRY_FWDrow. - If encashment is allowed, encash the agreed portion of the remainder (an
ENCASHrow in the old year, and an earning element in payroll). - Lapse whatever is left with a
LAPSErow, so the old year closes at exactly zero.
SELECT emp_id, leave_code,
closing,
LEAST(closing, max_cf) AS carry_forward,
GREATEST(closing - max_cf, 0) AS excess -- encash or lapse
FROM (SELECT l.emp_id, l.leave_code,
SUM(l.days) AS closing,
MAX(p.max_carry_forward) AS max_cf
FROM lv_ledger l
JOIN hr_employee e ON e.emp_id = l.emp_id
JOIN lv_policy p ON p.policy_code = e.leave_policy
AND p.leave_code = l.leave_code
WHERE l.leave_year = :p_year
GROUP BY l.emp_id, l.leave_code)
WHERE closing > 0;
Run year-end as a single, logged job and record the run id on every ledger row it creates. If something is wrong, you can reverse the whole run by deleting its rows and run it again – something that is almost impossible when balances are overwritten.
7. Connect leave to attendance and payroll
Leave is not isolated. Attendance processing should mark approved leave days as leave, not absent, and unpaid leave must feed payroll deductions. Keep the dependency in one direction: attendance and payroll read approved leave; they never change the leave ledger. See our guides on night-shift attendance and designing a payroll engine in PL/SQL.
8. Make balances easy to explain
Give employees and HR a leave statement page that lists ledger rows with dates and remarks, not just the final number. Most leave complaints end the moment the employee sees “Accrual Jan–Oct: 11.67, Availed: 4.0, Carried forward from 2025: 3.0”. Transparency is the best feature an HR system can have.
Quick checklist
- Leave types and policy rules in tables, with effective dates
- A ledger of movements instead of a single balance column
- Accrual runs that can be repeated safely
- Proration for joiners and correct settlement for leavers
- Working-day counting using a holiday calendar and weekly offs
- Negative-balance checks enforced in the database
- Year-end carry forward, encashment and lapse posted as separate rows with a run id
- Leave statement visible to employees and HR
Related: HRMS implementation checklist for textile mills, payroll software features checklist and our HRMS & payroll software with a live demo.
Building or fixing an HR system?
AbairTech builds HRMS and payroll on Oracle APEX and PL/SQL – leave, attendance, ZKTeco integration and payroll.
Related implementation services
Need help applying these concepts in a business system? Explore Custom business software development or Oracle APEX development.