<?
session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($brcode)<=0)
{
  	print "<script> alert('Invalid User'); parent.document.location='../index.php' </script>";
  	return;
}
include("../opendb.php");
include("../test.php");
?>
<link rel="stylesheet" href="style.css" type="text/css" />
<style>
body,td{font-family:'arial narrow';letter-spacing:1;font-size:.88em}
th{background-color:c1d799;font-size:.88em}
.mnu{margin-left:5}
</style>
<center>
<?
$sql="select brcode_org from TimeTrack.branch_link where br = '$br'";
$result=mysqli_query($db,$sql) or die ('Error'.mysqli_error($db));
$row5=mysqli_fetch_row($result);
$num = cal_days_in_month(CAL_GREGORIAN, $monthfrm, $yearfrm); 
$monthNum = $monthfrm;
$monthName = date("F", mktime(0, 0, 0, $monthNum, 10));

$sql="select distinct employeecode from TimeTrack.AttendanceLogs where month(logdate) = '$monthfrm' and year(logdate)='$yearfrm' and deviceid ='$row5[0]' order by logdate ";
$result=mysqli_query($db,$sql) or die ('Error'.mysqli_error($db));
while($row=mysqli_fetch_row($result))
{
	$res=mysqli_query($db,"select * from TimeTrack.emp_link where br='$br' and esign_id=$row[0] order by empname");
	if(mysqli_num_rows($res)<=0)
	{
		print "<td><font color = 'red'><font size='20'>$row[0] - not found in Emplyee Code</td><br>";
		
	}
}
$res=mysqli_query($db,"select * from TimeTrack.emp_link where br='$br' order by empname");
if(mysqli_num_rows($res)>0)
{
	$row=mysqli_fetch_row($res);
	?>
	<table width=100% bgcolor='white' border = '1'>
	<tr><td colspan=35 align=center font = calibri><h3>PSN AUTOMOBILES PVT LTD<br>Branch : <? print $br ?><br>ATTENDANCE<br> for the Month of <?print $monthName?> - <?print $yearfrm?></td></tr>
	<tr><td>No</td><td>Employee Name</td><td align=center>Esign ID</td>
	<?
	for ($i = 1; $i <= $num; $i++) {
		print "<td align=center>".$i."</td>";
	}
	print "</tr>";
 	$i=1;
 	do
	{
		print "<tr><td align=center width='1%'>".$i++."</td><td>$row[1]</td><td align=center>$row[0]</td>";
		$mesign_id = $row[0];
		for ($day = 1; $day <= $num; $day++) 
		{
			$mdate = $yearfrm."-".$monthfrm."-".$day;
			$sql="select * from TimeTrack.AttendanceLogs where employeecode= $mesign_id and date(logdate) = '$mdate' and deviceid ='$row5[0]' order by logdate ";
			$result=mysqli_query($db,$sql) or die ('Error'.mysqli_error($db));
			if(mysqli_num_rows($result)>0)
				print "<td align=center>P</td>";
			else
				print "<td align=center><font color = 'red'>A</td>";
		}
		print "</tr>";
	}
	while($row=mysqli_fetch_row($res));
}
print "</table>";
?>
