Page 1 of 1

carry forward

Posted: Sat Aug 02, 2003 10:49 am
by superman
is this code correct? can someone give suggestion how to use this in mysql database to carry forward from the previous year & add to next year? thanx.

define('MAX_CARRY',10);
define('BASE_LEAVE', 20);

calc_carry($year_start, $year_used, $bonus_days)
{
return BASE_LEAVE + $bonus_days + min(MAX_CARRY, max($year_start-$year_used,0));
}

Posted: Sun Aug 03, 2003 12:18 am
by superman
i don't know how to carry forward the result?

for example, for the first 2 years, he does not has bonus leave, on the third year onwards, he has 1 day increase.

by default, he has 18 days leave, on the third year, he can carry forward the 10 days from the previous year, now, he has 28 days leave plus 1 day bonus leave = 29 days.

same with the fourth year, he can carry forward 10 days, so, he has 39 days leave plus 1 day bonus leave = 40 days.

if he apply 2 days leave in the first 2 years, the balance is 16 days. on the third year, he only can carry forward 10 days only, not 16 days.

if he apply 12 days leave in the first 2 years, the balance is 6 days. on the third year, he only can carry forward 6 days only, not 10 days.

this is the problem that i don't know how to fix, can you teach me?