Page 1 of 1

annual leave calculation

Posted: Sat Jul 26, 2003 7:40 am
by irvine
hi,

is it possible to write a php code about the leave for a staff?
like the usaul ompany, after two years work a staff will get the bonus leave 1 day in third year........and fourth years have 2 days bonus leave........

thank you.......

Posted: Sat Jul 26, 2003 9:41 am
by redhair
Yes it is.
How? By using your imagination. (..and a database to store values)
I have never made such a thing..but i'm sure it is easy done.

Posted: Sat Jul 26, 2003 10:45 am
by irvine
can u show me the way how to write this kind of the code?

thanks a lot

Posted: Sat Jul 26, 2003 12:05 pm
by daniworldwide
Possibly make a new field in your database where those members are stored, where you can mark how many days they have been working. Make a simple script where it adds 1 day to that list whenever they've been working. I don't know if you want to add days to what they've been working, but if that new field where the days they've been working in is 365 * 2, or how every many years, then bonus is 2, or something, you just need to add another field called bonus and one called dayworking or something. I really don't know if that's what you want, but there's an idea.

-Dani

Posted: Sat Jul 26, 2003 12:12 pm
by irvine
Example
John is a staff of AA Company. He started to join the AA company in 1999 until now 2003. Then he wants to take a leave start from 25/7/2003 to 31/7/2003 for holiday.

Format
- a new staff with a two years worked have basic leave is 18 days.
- Start from 3 years worked a staff has additional leave 1 day. That is means after 2 years worked a staff will have an additional leave 1 day for 1 year.
- E.g. john had worked at AA company 4 years already (2003 – 1999 = 4 years). That’s mean john has 21 days leave (18+2). After john take the leaves and balance is 14 days (20-7=13)

Posted: Sat Jul 26, 2003 12:22 pm
by daniworldwide
John is a staff of AA Company. He started to join the AA company in 1999 until now 2003. Then he wants to take a leave start from 25/7/2003 to 31/7/2003 for holiday.

Format
- a new staff with a two years worked have basic leave is 18 days.
- Start from 3 years worked a staff has additional leave 1 day. That is means after 2 years worked a staff will have an additional leave 1 day for 1 year.
- E.g. john had worked at AA company 4 years already (2003 – 1999 = 4 years). That’s mean john has 21 days leave (18+2). After john take the leaves and balance is 14 days (20-7=13)

Make a new field in your database, yearstarted, and put the year John started in there.

Code: Select all

<?php

$currentyear = date("Y");

//current year would be 2003, Y in the date function is the Year in 4 digits

//select yearstarted from database where employee is john
//make yearstarted into an row, and make the variable name yearstarted

$yearsworked = $currentyear - $yearstarted;

if ($yearsworked >= 1)
{
$leave = 1;
}

if ($yearsworked >=2)
{
$leave = 3;
}

echo "John's leave is $leave";

?>
Something like that. In your database you can give each employee a number, and you can put that into a get function, and so the url would be leave.php?employee=384 . You would then select from the database: yearstarted where employee = $employee, from the get function.

Enjoy

-Dani

Posted: Sat Jul 26, 2003 12:34 pm
by irvine
thanks first here,

can u show the code in this way....

lets say a staff worked at xx company 10 already and he basic leave is 18, after 2 years work will started add the leave 1 day per year. and the total leave he has now is 26 days.(18+(10years-2years=8)=26)

how to count it continuously?

Posted: Sat Jul 26, 2003 12:34 pm
by patrikG
Just to bring together some crossposts: http://www.devnetwork.net/forums/viewto ... 1934#51934

Posted: Sun Jul 27, 2003 1:13 pm
by irvine
this is my code without counting the years.....
if i add a empty fields to give the staff fill in when they r join this company in a year format.e.g 1999.
then how can i add this function into this coding and also this is where im very clear about it.
can u do a correction to me pls?

<?php
function count_workdays($date1,$date2){
$firstdate = strtotime($date1);
$lastdate = strtotime($date2);
$firstday = date(w,$firstdate);
$lastday = date(w,$lastdate);
$totaldays = intval(($lastdate-$firstdate)/86400)+1;

//check for one week only
if ($totaldays<=7 && $firstday<=$lastday){
$workdays = $lastday-$firstday+1;
//check for weekend
if ($firstday==0){
$workdays = $workdays-1;
}
if ($lastday==6){
$workdays = $workdays-1;
}

}else { //more than one week

//workdays of first week
if ($firstday==0){
//so we don't count weekend
$firstweek = 5;
}else {
$firstweek = 6-$firstday;
}
$totalfw = 7-$firstday;

//workdays of last week
if ($lastday==6){
//so we don't count sat, sun=0 so it won't be counted anyway
$lastweek = 5;
}else {
$lastweek = $lastday;
}
$totallw = $lastday+1;

//check for any mid-weeks
if (($totalfw+$totallw)>=$totaldays){
$midweeks = 0;
} else { //count midweeks
$midweeks = (($totaldays-$totalfw-$totallw)/7)*5;
}

//total num of workdays
$workdays = $firstweek+$midweeks+$lastweek;

}

/*
check for and subtract and holidays etc. here
...
*/

return ($workdays);
} //end funtion count_workdays()

$date1 = "$FromDate";
$date2 = "$ToDate";
$entitlement = 18;
$leave_to_date = 0;

**** is it here am i going to start?***********

$balance = $entitlement - $leave_to_date - $Duration;

echo $Duration ;



?>