<?
session_start();
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../ind.php'; </script>";
 return;
}
include("../opendb.php");
include("../test.php");

 $tbl2='esipfbr'.$brcode;
$tbl3="ded_payrolltmp".$brcode;
$esires=mysqli_query($db,"select empesip from celmast where brcode='$brcode'");
$esipr=mysqli_fetch_row($esires);
$esip=$esipr[0];
?>
<head>
<style>
body,td{font-family:'arial narrow';letter-spacing:1;}
tr{background-color:e3ecd2}
th{background-color:c1d799}
.mnu{margin-left:5}
body{BACKGROUND-COLOR:fcfff1}
</style>
<center>
<?
if($show)
{
$re1=mysqli_query($db,"select distinct grp from empmaster where brcode='$brcode' and grp is not null")or die(mysqli_error($db));
while($grow=mysqli_fetch_array($re1))
{
 print "<fieldset><legend>$grow[0]</legend>";
 print "<table border=1><th>No<th>Employee Name <th>ESI <th>ESI <th>ESI<br>(Incentive)<th>Total ESI<th>Gross<br>Pay";
 $sq="select empcode,esi  from $tbl3 where month(wdatefrm)='$month' and year(wdatefrm)=$year and empcode in(select empcode from empmaster where grp='$grow[0]') order by empcode";
 $re3=mysqli_query($db,$sq)or die('Err'.mysqli_error($db));
 $i=1;
 $t1=0;
 $t2=0;
 $t3=0;
 $t4=0;
 $tgpay=0;
 while($row=mysqli_fetch_array($re3))
 {
	$mename = getEmp($row[0]);
	$sq1="select esi,newesi  from esiinc where month(fordate)='$month' and year(fordate)=$year and ename = '$mename'";
	$re31=mysqli_query($db,$sq1)or die('Err'.mysqli_error($db));
	$row1=mysqli_fetch_array($re31);
   print "<tr><td>".$i++."</td><td>".$mename."</td><td align=right>$row[esi]</td><td align=right>".ceil($row1[esi])."</td><td align=right>".ceil($row1[newesi])."</td>";
   $ees=($row[esi]*$esip)/100;
   $tot=ceil($row1[esi])+ceil($row1[newesi]);
   print "<td align=right>".round($tot,2)."</td><td align=right>".ceil($tot/1.75*100)."</td>";
   print "</tr>";
  $t1+=$row[esi];
  $t2+=$tot;
  $t3+=ceil($row1[esi]);
  $t4+=ceil($row1[newesi]);
  $tgpay+=ceil($tot/1.75*100);
 }
 print "<tr><td colspan=2><center><b>Total</td><td align=right>".putComa($t1)."</td><td align=right>". round($t3,2)."</td><td align=right>". round($t4,2)."</td><td align=right>". round($t2,2)."</td><td align=right>". round($tgpay,2)."</td></tr>";
print "</table></fieldset>";
}
return;
} // end if show
//************
function getEmp($x)
{
 $s="select empname from empmaster where empcode='$x'";
 //print $s;
 $rr=mysqli_query($db,$s)or die(mysqli_error($db));
 $r=mysqli_fetch_array($rr);
 return $r[0];
}
?>
<center>
<form action='<?print $PHP_SELF?>' method='post'> 
<table>
<tr><td>Select Month</td><td><select name='month'>
<?
 for($i=1;$i<=12;$i++)
  print "<option>$i</option>";
?>
</select>
</td><td>Year <td><select name='year'>
<option>2008</option>
<option>2009</option>
<option>2010</option>
<option>2011</option>
</select>
</td><td><input type=submit value='Show' name='show'></td></tr>
</table>
</form>

