Hi,
You have not mentioned about what database server you use.
If you are using SQL server, you can create a job and schedule it to run everyday. It can be as follows
Create a procedure that
1) Checks if TODAY - 6 months = Date_Of_Joining(DOJ) of any staff.
2) If so populate those rows in a cursor and do the calculations for those staffs and update their remaining leave details.
3) Schedule it to run daily as an SQL job. As staff might have joined on any day.
Within the procedure you may code like this.
If (Select count(Staff) from YOURTABLE where DOJ = '''' + cast(year(getdate()) as char(4)) + '-' + cast(month(getdate())-6 as varchar(2)) + '-' + cast(day(getdate()) as varchar(2)) + '''' > 0)
BEGIN
-- Have a CURSOR Populating rows that satisfy the above condition,
-- because there may be more than one staff memeber joined that day.
-- within the cursor pick row by row and
-- if (6 - staff_availed_Leave) < 0 then calculate (6 - staff_availed_Leave) * Day_Salary and
-- store that in deductions column to be deducted from current salary.
-- if (6 - staff_availed_Leave) > 0 then update add up (6 - staff_availed_Leave) to REMAINING leave for next half year.
-- close the cursor.
END
Follow the same logic for cases of 12 months, 18 months and 24 months within the same procedure using different IF constructs. This can be donw without CURSOR too, provided you derive at a formula that can do all that(calculate deduction, and remaining leaves) in one step for one IF.
Hope that helps.
Cheers!
_________________________
-Vijay G

Strive for Perfection
