
08-01-03, 10:08 PM
|
 |
Newbie Coder
|
|
Join Date: Jun 2003
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
carry forward
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 u don't know how to fix, can you teach me?
|

08-03-03, 12:24 AM
|
 |
Newbie Coder
|
|
Join Date: Jun 2003
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
can someone give suggestion how to use this in mysql database to carry forward from the previous year & add to next year? thanx.
|

08-03-03, 11:23 PM
|
 |
Newbie Coder
|
|
Join Date: Jun 2003
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
i don't know how to carry forward the result?
for example, for the first 2 years, a new staff does not has bonus leave, on the third year onwards, he has 1 day increase.
by default, he has 18 days leave, the maximum days he can bring to next year are 10 days. If he already applied 12 days, than he can carry forward 6 days to the next year. (must below 10 days, not more than 10)
i explain more by giving this example.
2001
(default) 18
(apply leave) -13
______
5 days
(carried forward from 2000) 3 days
______
8 days
(bring forward to 2002) 8 days
------------------------------------------------------
2002
(default) 18
(apply leave) -11
______
7 days
(carried forward from 2001) 8 days
______
15 days
(bring forward to 2003) maximum 10 days
-------------------------------------------------------
2003
(default) 18
(bonus leave after 1 year) +1
(apply leave) -14
______
5 days
(carried forward from 2002) 10 days
______
15 days
(bring forward to 2004) maximum 10 days
Last edited by superman; 08-05-03 at 10:48 AM.
|

08-05-03, 10:50 AM
|
 |
Newbie Coder
|
|
Join Date: Jun 2003
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
can someone help me? thanq very much!!!
|

08-05-03, 10:01 PM
|
 |
Newbie Coder
|
|
Join Date: Jun 2003
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
i really need your help, please, please help me.
thanq very much...
|

08-05-03, 10:42 PM
|
 |
The Lonely Coder
|
|
Join Date: Aug 2003
Location: Ontario
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I really don't think anybody knows exactly what you want to know. It all depends on too many things. Are you asking how you would code such a thing in PHP?
__________________
where am i......
|

08-06-03, 02:12 AM
|
 |
Newbie Coder
|
|
Join Date: Jun 2003
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
yes. then it should store in the database.
|

08-06-03, 09:29 AM
|
 |
Newbie Coder
|
|
Join Date: Jun 2003
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I can calculate the leave days for current year only, I don't know how to carry forward to the next year. How to bring forward the balance to the next year?
If the balance is 14, only 10 days will be bring to the next year.
If the balance is 3, then the 3 days will bring to the next year. (maximum 10 days)
Hope you all can help me. Thank you.
<? $Connect = mysql_connect("localhost","root","");
mysql_select_db("help");
$result=mysql_query("select Entitlement from Staff where StaffID = '$username'") ;
$number_of_array = mysql_num_rows($result);
while ($number_of_array = mysql_fetch_array($result)){
"$number_of_array[Entitlement]";
}
mysql_close(); ?>
<? $Entitlement ?>
------------------------------------------------------
<? $Connect = mysql_connect("localhost","root","");
mysql_select_db("help");
$result=mysql_query("select YearStarted from Staff where StaffID = '$username'") ;
$number_of_array = mysql_num_rows($result);
while ($number_of_array = mysql_fetch_array($result)){
"$number_of_array[YearStarted]";
}
mysql_close(); ?>
<? $YearStarted ?>
-------------------------------------------------------
<?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)
{
$BonusLeave = 0;
}
if ($yearsworked >= 2)
{
$BonusLeave = 0;
}
if ($yearsworked >= 3)
{
$BonusLeave = 1;
}
if ($yearsworked >= 4)
{
$BonusLeave = 2;
}
if ($yearsworked >= 5)
{
$BonusLeave = 3;
}
if ($yearsworked >= 6)
{
$BonusLeave = 4;
}
.
.
.
if ($yearsworked >= 23)
{
$BonusLeave = 21;
}
if ($yearsworked >= 24)
{
$BonusLeave = 22;
}
if ($yearsworked >= 25)
{
$BonusLeave = 23;
}
echo $BonusLeave;
?>
-----------------------------------------------------
<? echo $FromDate ?>
-----------------------------------------------------
<? echo $ToDate ?>
-----------------------------------------------------
<?php
function NumHolidays($Start, $End)
{
$dbConn = MySQL_Connect("localhost", "root", "") or
Die("Error connecting to Server");
MySQL_Select_DB("help") or
Die("Error Connecting to Database");
$sSQL = "SELECT * FROM Holidays";
$recHolidays = MySQL_Query($sSQL) or
Die("Invalid Query");
$NumHolidays = 0;
while ($Holiday = MySQL_Fetch_Array($recHolidays))
{
$dtDate = StrToTime($Holiday["Date"]);
$dtStart = StrToTime($Start);
$dtEnd = StrToTime($End);
if (Date("m", $dtStart) < Date("m", $dtDate))
{
if (Date("m", $dtDate) <= Date("m", $dtEnd))
{
if (Date("d", $dtDate) <= Date("d", $dtEnd))
{
$NumHolidays++;
}
}
}
else if (Date("m", $dtStart) == Date("m", $dtDate))
{
if (Date("d", $dtStart) <= Date("d", $dtDate))
{
if (Date("m", $dtDate) <= Date("m", $dtEnd))
{
if (Date("d", $dtDate) <= Date("d", $dtEnd))
{
$NumHolidays++;
}
}
}
}
}
return $NumHolidays;
}
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;
}
return ($workdays);
} //end funtion count_workdays()
$date1 = "$FromDate";
$date2 = "$ToDate";
$leave_to_date = 0;
$Duration = count_workdays($date1, $date2) - NumHolidays($date1, $date2);
$Balance = $Entitlement - $leave_to_date - $Duration + $BonusLeave;
echo $Duration ; ?>
-----------------------------------------------------
<?php echo $Balance; ?>
-----------------------------------------------------
<? $Connect = mysql_connect("localhost","root","");
mysql_select_db("help");
$TodayDate = strftime("%Y-%m-%d");
$TodayTime = strftime("%H:%M:%S");
$Duration = count_workdays($FromDate,$ToDate);
$result=mysql_query("insert into LeaveApplication (ApplicationNumber, StaffID, LeaveType, JobTitle, FromDate, ToDate, Duration, Reason, TodayDate, TodayTime, YearStarted, BonusLeave, Balance, Subjects1, DateAffected1, DateReplaced1, Subjects2, DateAffected2, DateReplaced2, Subjects3, DateAffected3, DateReplaced3, Subjects4, DateAffected4, DateReplaced4, Subjects5, DateAffected5, DateReplaced5, Subjects6, DateAffected6, DateReplaced6) values ('$ApplicationNumber', '$username', '$LeaveType', '$JobTitle', '$FromDate', '$ToDate', '$Duration', '$Reason', '$TodayDate', '$TodayTime', '$YearStarted', '$BonusLeave', '$Balance', '$Subjects1', '$DateAffected1', '$DateReplaced1', '$Subjects2', '$DateAffected2', '$DateReplaced2', '$Subjects3', '$DateAffected3', '$DateReplaced3', '$Subjects4', '$DateAffected4', '$DateReplaced4', '$Subjects5', '$DateAffected5', '$DateReplaced5', '$Subjects6', '$DateAffected6', '$DateReplaced6')");
mysql_close();
?>
|

08-06-03, 09:33 AM
|
|
Newbie Coder
|
|
Join Date: Jul 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
wai loon ah!!! lain kali u online boleh itu icq online juga kah?
tak boleh contact u .........
|

08-07-03, 04:42 AM
|
 |
Newbie Coder
|
|
Join Date: Jun 2003
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
am i need to create a field in table?
to store the balance in 1990, 1991, 1992....2003, 2004..??
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|