Thank you very much Sir,
Indeed, your advice made me improve myself.
The Breaks report is now ok...
I also tried changing the codes of row 8 in my other reports like in our lates and undertime report. IF you have time, can you browse through my codes? I would really want to know if you can give me some of your pointers for me to improve my codes.
Also, the generation of this report is very slow... I think our customers really wants to have the 1 month timeline for their report.
I will wait for your reply Sir. Thank you very much
<?
set_time_limit(0);
include('globals/functions.php');
include('include/dbConnect.php');
//page title
$pageTitle = "Employee Lates and Undertime Report";
//get GET variables :
//if (isset($_GET['dept']) || isset($_GET['emp']) ||
// isset($_GET['frmDate']) || isset($_GET['toDate'])){
if (isset($_GET['dept']) && isset($_GET['emp']) &&
isset($_GET['frmDate']) && isset($_GET['toDate'])){
$FromDate = $_GET['frmDate'] . " 00:00:00 ";
$ToDate = $_GET['toDate'] . " 23:59:59 ";
$Department = $_GET['dept'];
$Employee = $_GET['emp'];
}
else{
$Deparment = $_SESSION['DeptID'];
$Employee = $_SESSION['UserID'];
}
//get substring of date range then print
$FromMonthNumber = substr($FromDate,5,2);
$FromDayNumber = substr($FromDate,8,2);
$ToMonthNumber = substr($ToDate,5,2);
$ToDayNumber = substr($ToDate,8,2);
$ToYearNumber = substr($ToDate,0,4);
$DateRange = date("F",mktime(0,0,0,$FromMonthNumber+1,0,0)) . " " .
$FromDayNumber . " to " . date("F", mktime(0,0,0,$ToMonthNumber+1,0,0)) ." " .
$ToDayNumber ." ". $ToYearNumber;
$Start = $_GET['frmDate'];
$End = $_GET['toDate'];
//GET DIFFERENCE OF Start and End Date
$days = (strtotime($End) - strtotime($Start)) / (60 * 60 * 24) ;
$conn = connect();
//get All employees of all department
if (($Department == "--") && ($Employee == "--")){
$rsAllDeptEE = array();
$rsAllDeptEE = getDeptEmployees();
}elseif (($Department <> "--") && ($Employee == "--")){
$rsAllDeptEE = array();
$rsAllDeptEE = getEmployeesPerDept($Department);
}elseif (($Department <> "--") && ($Employee <> "--")) {
$rsAllDeptEE = array();
$rsAllDeptEE = getSpecificEE($Department, $Employee);
}
?>
<html>
<head>
<title><?=$pageTitle;?></title>
<link href="css/actatek.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#FFFFFF" leftmargin="5" topmargin="15" marginwidth="0" marginheight="0">
<table align="center" border="1" cellpadding="0" cellspacing="0" width="890" >
<tr><td align="center" class="Reporttitle"><?=$pageTitle;?></td></tr>
<tr><td align="center" class="Reporttitle"><?=$DateRange;?></td></tr>
</table><br>
<table align="center" width="890" cellpadding="0" cellspacing="0" border="1" bordercolor="#C9C8C9" style="border-collapse: collapse;">
<tr>
<td>
<table align="center" width="890" cellpadding="0" cellspacing="0" border="1" bordercolor="#C9C8C9" style="border-collapse: collapse;">
<tr>
<td width="100" class="sideTitle" align="center">Last Name</td>
<td width="100" class="sideTitle" align="center">First Name</td>
<td width="111" class="sideTitle" align="center">Shift</td>
<td width="111" class="sideTitle" align="center">Date</td>
<td width="100" class="sideTitle" align="center">Time-In</td>
<td width="100" class="sideTitle" align="center">Time-Out</td>
<td width="111" class="sideTitle" align="center">Late</td>
<td width="100" class="sideTitle" align="center">Undertime</td>
</tr>
<?
foreach ($rsAllDeptEE as $id=>$deptEE){
//initialize variables
$cntrLate = 0; $cntrUndertime = 0;
//for late
$hours = 0; $mins = 0; $secs = 0;
//for undertime
$hour = 0; $min = 0; $sec = 0;
for($i=0;$i<=$days;$i++){
$rowspan = $days + 1;
$today = $i * (60*60*24) + strtotime($Start);
$todayPlusOneDay = $i * (60*60*24) + strtotime($Start) + (60*60*24);
$strTodayPlusOneDay = strftime("%Y-%m-%d",$todayPlusOneDay);
$todayTime = strftime("%Y-%m-%d",$today);
$todayTimeFrom = date("Y-m-d H:i:s D",mktime(0,0,0,substr($todayTime,5,2),substr($todayTime,8,2),substr($todayTime,0,4)));
$todayTimeTo = date("Y-m-d H:i:s D",mktime(23,59,59,substr($todayTime,5,2),substr($todayTime,8,2),substr($todayTime,0,4)));
echo "<tr>";
//print lastName
echo "<td class=\"report\">".$deptEE['fldlastName']."</td>";
//print firstName
echo "<td class=\"report\">".$deptEE['fldfirstName']."</td>";
//print shift
$getshift = getShift($deptEE['fldUserID'], $todayTime);
if ($getshift != ""){
$shift_desc = $getshift['shift_description'];
}else {
$shift_desc = "--";
}
echo "<td class=\"report\">" .$shift_desc. "</td>";
//get Shift Start
$shift_start = $getshift['shift_start'];
$GLOBALS['shift_start'] = $shift_start;
//shift start with date
$GLOBALS['shift_start_date'] = $todayTime . " " . $shift_start;
//get Shift End
$shift_end = $getshift['shift_end'];
$GLOBALS['shift_end'] = $shift_end;
//shift end with date
//get mktime of 3 pm for shifts more than 3 pm
$mkShiftEnd3pm = mktime(15,0,0,0,0,$ToYearNumber);
$strShiftEnd3pm = strftime("%H:%M:%S",$mkShiftEnd3pm);
if ($GLOBALS['shift_start'] < $strShiftEnd3pm){
$GLOBALS['shift_end_date'] = $todayTime . " " . $shift_end;
}
elseif ($GLOBALS['shift_start'] >= $strShiftEnd3pm){
$mkTimeToPlusOne = mktime(substr($shift_end,0,2),substr($shift_end,6,2),substr($shift_end,4,2),substr($todayTime,5,2),substr($todayTime,8,2),substr($todayTime,0,4)) + (60*60*24);
$strTimeToPlusOne = strftime("%Y-%m-%d %H:%M:%S", $mkTimeToPlusOne);
$GLOBALS['shift_end_date'] = $strTimeToPlusOne;
}
//print date
echo "<td class=\"report\">" .date("Y-m-d D", $today). "</td>";
//get weekend
$weekend = mktime(0,0,0,substr($todayTime,5,2),substr($todayTime,8,2),substr($todayTime,0,4));
$SatSun = getdate($weekend);
//get EE Time-In
$timeIN = gettimein($todayTimeFrom,$todayTimeTo,$deptEE['fldUserID']);
if(($SatSun["wday"]==0 || $SatSun["wday"]==6) && ($timeIN['timeIN'] == null)){
$shift_in = " ";
echo "<td>$shift_in</td>";
}
elseif (($SatSun["wday"]<>0 || $SatSun["wday"]<>6) && (substr($timeIN['timeIN'],11,18) == null)){
$shift_in = "--";
echo "<td>$shift_in</td>";
}elseif (($SatSun["wday"]<>0 || $SatSun["wday"]<>6) && (substr($timeIN['timeIN'],11,18) <> null)){
$shift_in = substr($timeIN['timeIN'], 11,18);
echo "<td>$shift_in</td>";
}
$GLOBALS['shift_in'] = $shift_in;
//PRINT TIME-OUT
//get EE Time-Out
$timeOUT = gettimeout($todayTimeFrom,$todayTimeTo,$deptEE['fldUserID'],$shift_start);
$timeOUTplus = gettimeoutPLUS($todayTimeFrom,$todayTimeTo,$deptEE['fldUserID'],$shift_start);
//print BLANK if SAT or SUN and timeIN is NULL
if((($SatSun["wday"]==0 || $SatSun["wday"]==6)) && ($timeIN['timeIN'] == null)){
$shift_out = " ";
$shift_out_full = $shift_out;
echo "<td>$shift_out</td>";
}
//if not SAT or SUN
elseif ($SatSun["wday"] <> 0 || $SatSun["wday"] <> 6){
//normal time-out
if ($timeOUT['timeOut'] <> null){
if ($timeOUT['timeOut'] > $GLOBALS['shift_end_date']){
$shift_out = substr($timeOUT['timeOut'], 11, 18);
$shift_out_full = $timeOUT['timeOut'];
echo "<td>$shift_out</td>";
}elseif ($timeOUT['timeOut'] < $GLOBALS['shift_end_date']){
if ($timeOUTplus['timeOutPlus'] <> null){
$shift_out = substr($timeOUTplus['timeOutPlus'], 11, 18);
$shift_out_full = $timeOUTplus['timeOutPlus'];
echo "<td>$shift_out</td>";
}else{
$shift_out = "--";
$shift_out_full = " ";
echo "<td>$shift_out</td>";
}
}
}elseif ($timeOUT['timeOut'] == null){
More codes to follow...