
<?
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");

if($level<5)
{
$psres=mysqli_query($db,"select brpass from br_master where brname='$br'");
$psrow=mysqli_fetch_array($psres);
 if($psrow[0]!=$pswd)
 {
   print "<center><blink><font color=red> Invalid Password</font>";
   return;
 }
}
?>
<style>
 td{color:#455342;font-family:helvetica;font-size:12}
 th{color:white;font-family:helvetica;font-size:12}
</style>
<?

$tbl1="payrolltmp".$brcode;
$tbl2="allow_payrolltmp".$brcode;
$tbl3="ded_payrolltmp".$brcode;

$sql="select * from branch where brcode='$brcode'";
$brres=mysqli_query($db,$sql);
$brow=mysqli_fetch_array($brres);
?>
<center><span style={letter-spacing:5;color:455342}>
<U><b>Bonus-<?print $br?></b></U>
</SPAN>
<table width=100% BORDER=0>
<?
$brname=explode(',',$branch);
?>
<tr><td align=center COLSPAN=2><span style={letter-spacing:3}><b><?print STRTOUPPER($brname[0])
?></b> </span> <br>
<?
Print $brow[braddr].''.$brow[brcity]
?>
<br>
Bonus 2008-2009
</td></tr>
</table>
<table border=0  bgcolor='455342' cellspacing=1 cellpadding=3>
<?

$sql="select distinct empcode from $tbl1 where wgfrom>='2009-04-01' and wgfrom<='2010-03-01' and brcode='$brcode' and divi='$divi' and br='$br' order by ename";
$res=mysqli_query($db,$sql) or die('Err:'.mysqli_error($db));

while($row=mysqli_fetch_array($res))

{

$rbasic=0;
$rebasic=0;
$rta=0;
$reta=0;
$rhra=0;
$rehra=0;
$rrent=0;
$gtottillhra=0;
$gtotbon=0;
$gtotex=0;
$gtbon=0;
$leav=0;
$crleav=0;

$sqle="select empname,doj from empmaster where empcode='$row[empcode]'";
$rese=mysqli_query($db,$sqle) or die('Err:'.mysqli_error($db));
$wee=mysqli_fetch_array($rese);
$do=$wee[1];


 print "<tr><td colspan=10 bgcolor='#455342'><font color='white'><b>".strtoupper($wee[empname])."</td>";
 

 //print "<tr><td colspan=10 bgcolor='#455342'><font color='white'><b>".strtoupper($row[ename])."</td>";
 print "<tr bgcolor='#6B852C'><th>Month<th>Total Att.<th>No.of Days Paid<th>Leave Taken<th>Credit Leave<th>Total Salary <br>(Basic+DA)<th>Earned <br>(Basic+DA)<th>T.A <th>Earned <br>TA<th>CCA <th>E.CCA<th>";


if($monthfrm>=4&&$monthfrm<=5)
print "HRA";

print " <th>Total";

$al2=mysqli_query($db,"select distinct alloname from $tbl2 where month(wdatefrm)='$i' and year(wdatefrm)>='$yearfrm' and wdatefrm>='2009-04-01' and wdatefrm<='2010-03-01' and divi='$divi' and br='$br' and brcode='$brcode'");

while($allorow2=mysqli_fetch_array($al2))
 {
 print "<td></td>";
 }

?>
<th>Bonus<th>Ex-gratia<th>Total Bonus<th>PF<th>ESI<th>Adv/<br>other
<th>Total <br>Deduction<th>Net Salary <br>Paid</tr>
<?


 for($i=$monthfrm;$i<=15;$i++)
 {
$totebasicda=0;
$totbasicda=0;
$totta=0;
$toteta=0;
$tothra=0;
$totehra=0;
$totnet=0;


/*$totpf=0;
$totesi=0;
$ttotded=0;
$gtotded=0;
*/
$tottilhra=0;
$totded=0;
  print "<tr bgcolor='white'><td>".getMonth($i)."</td>";
$k=$i;
if ($i==13)
{
$k=1;
}
if ($i==14)
{
$k=2;
}
if ($i==15)
{
$k=3;
}

$sql="select * from $tbl1 where month(wgfrom)='$k' and year(wgfrom)>='$yearfrm' and wgfrom>='2009-04-01' and wgfrom<='2010-03-01' and brcode='$brcode' and empcode='$row[empcode]' and divi='$divi' and br='$br'";
 $empres=mysqli_query($db,$sql) or die('Err:'.mysqli_error($db));
 $empayrow=mysqli_fetch_array($empres);
$d=$empayrow[wgfrom];

if($do<=$d && $do!='0000-00-00' && $do<='2009-04-01')
{
$x=2-$empayrow[8];
if ($x<0) 
$x=0;
else
$x=$x;

print "<td align=center>$empayrow[wdays]</td><td  align=center>$empayrow[dayspaid]</td><td  align=center>$empayrow[8]</td><td  align=center>$x</td><td align=right>$empayrow[basicda]</td><td align=right>$empayrow[ebasicda]</td><td align=right>$empayrow[ta]</td><td align=right>$empayrow[eta]</td><td align=right>$empayrow[hra]</td><td align=right>$empayrow[ehra]</td>";



if($i>=4&&$i<=5)
{
	print "<td align=right>$empayrow[rent]</td>"; //
$rrent+=$empayrow[rent];
}
else
{
print "<td align=right>&nbsp;</td>"; //$empayrow[rent]
}


$rbasic+=$empayrow[basicda];
$rebasic+=$empayrow[ebasicda];
$rta+=$empayrow[ta];
$reta+=$empayrow[eta];
$rhra+=$empayrow[hra];
$rehra+=$empayrow[ehra];
$leav+=$empayrow[8];
$crleav+=$x;

$totebasicda+=$empayrow[ebasicda];
$totbasicda+=$empayrow[basicda];
$totta+=$empayrow[ta];
$toteta+=$empayrow[eta];
$tothra+=$empayrow[hra];
$totehra+=$empayrow[ehra];
if($monthfrm>=4&&$monthfrm<=5)
 $totrent+=$empayrow[rent];
//$empayrow[basicda]+
$tottilhra=($empayrow[ebasicda]+$empayrow[eta]+$empayrow[ehra]+$empayrow[rent1]);
if($i>=4&&$i<=5)
	$tottilhra+=$empayrow[rent];

$gtottilhra+=$tottilhra;

$totfornet=($empayrow[ebasicda]+$empayrow[eta]+$empayrow[ehra]+$empayrow[rent1]);
$totforbon=($empayrow[ebasicda]+$empayrow[eta]+$empayrow[ehra]+$empayrow[rent1]);
if ($brcode=='Aut141' || $brcode=='PSN236')
{
$bonus=($totforbon*9/100);
$ex=($totforbon*9/100);

if($bonus>450)
{
$bonus=450;
}
if($ex>450)
{
$ex=450;
}
$tbon=$ex+$bonus;
}
if($i>=4&&$i<=5)
	$totfornet+=$empayrow[rent];
print "<td align=right>".putComa($tottilhra)."</td>";

if(mysqli_num_rows($allow_res2)<=0&& $hasallow=='y')
 print "<td align=right>0.00</td>";
else
while($allorow=mysqli_fetch_array($allow_res2))
 {
 print "<td align=right>".putComa($allorow[ealloamt])."</td>";
 $tallo+=$allorow[ealloamt];
 
 }

$sq="select * from $tbl3 where month(wdatefrm)='$k' and year(wdatefrm)>='$yearfrm' and wdatefrm>='2009-04-01' and wdatefrm<='2010-03-01' and divi='$divi' and br='$br' and brcode='$brcode' and empcode='$row[empcode]'";

$ded_res=mysqli_query($db,$sq) or die("er2:".mysqli_error($db));
$dedow1=mysqli_fetch_array($ded_res);
print "<td align='right'><b>".putComa($bonus)."</td>";
print "<td align='right'><b>".putComa($ex)."</td>";
print "<td align='right'><b>".putComa($tbon)."</td>";
print "<td align=right>".putcoma($dedow1[pf])."</td>";
print "<td align=right>".putComa($dedow1[esi])."</td>";
print "<td align=right>".putComa($dedow1[otherded])."</td>";
$totded+=$dedow1[pf]+$dedow1[esi]+$dedow1[otherded];
$totfornet-=$totded;
$totnet+=$totfornet;
$totpf+=$dedow1[pf];
$totesi+=$dedow1[esi];
$ttotded+=$dedow1[otherded];
$gtotded+=$totded;
$gtotbon+=$bonus;
$gtotex+=$ex;
$gtbon+=$tbon;
print "<td align=right>".putComa($totded)."</td><td align=right>".putComa($totnet)."</td>";
  print "</tr>";
$rtotded+=$totded;
$rtotnet+=$totnet;
}
 }// end for
print "<tr bgcolor='#E6E6E6'><td colspan=3><b>$wee[empname]</td>";
print "<td align='right'><b>".putComa($leav)."</td>";
print "<td align='right'><b>".putComa($crleav)."</td>";
print "<td align='right'><b>".putComa($rbasic)."</td>";
print "<td align='right'><b>".putComa($rebasic)."</td>";
print "<td align='right'><b>".putComa($rta)."</td>";
print "<td align='right'><b>".putComa($reta)."</td>";
print "<td align='right'><b>".putComa($rhra)."</td>";
print "<td align='right'><b>".putComa($rehra)."</td>";
print "<td align='right'><b>".putComa($rrent)."</td>";
print "<td align='right'><b>".putComa($gtottilhra)."</td>";
print "<td align='right'><b>".putComa($gtotbon)."</td>";
print "<td align='right'><b>".putComa($gtotex)."</td>";
print "<td align='right'><b>".putComa($gtbon)."</td>";

print "<td align='right'><b>".putComa($totpf)."</td>";
print "<td align='right'><b>".putComa($totesi)."</td>";
print "<td align='right'></td>";
print "<td align='right'><b>".putComa($rtotded)."</td>";
print "<td align='right'><b>".putComa($rtotnet)."</td>";

$trbasic+=$rbasic;
$trebasic+=$rebasic;
$trta+=$rta;
$treta+=$reta;
$trhra+=$rhra;
$trehra+=$rehra;
$trrent+=$rrent;
$tgtottilhra+=$gtottilhra;
$ttotpf+=$totpf;
$ttotesi+=$totesi;
$trtotded+=$rtotded;
$trtotnet+=$rtotnet;
$ggtotbon+=$gtotbon;
$ggtotex+=$gtotex;
$ggtbon+=$gtbon;
$gtottilhra=0;
$totpf=0;
$totesi=0;
$rtotded=0;
$rtotnet=0;
} // end while

print "<tr bgcolor='#E6E6E6'><td colspan=3><b>Grant Total</td>";
print "<td align='right'><b>".putComa($trbasic)."</td>";
print "<td align='right'><b>".putComa($trebasic)."</td>";
print "<td align='right'><b>".putComa($trta)."</td>";
print "<td align='right'><b>".putComa($treta)."</td>";
print "<td align='right'><b>".putComa($trhra)."</td>";
print "<td align='right'><b>".putComa($trehra)."</td>";
print "<td align='right'><b>".putComa($trrent)."</td>";
print "<td align='right'><b>".putComa($tgtottilhra)."</td>";
print "<td align='right'><b>".putComa($ggtotbon)."</td>";
print "<td align='right'><b>".putComa($ggtotex)."</td>";
print "<td align='right'><b>".putComa($ggtbon)."</td>";

print "<td align='right'><b>".putComa($ttotpf)."</td>";
print "<td align='right'><b>".putComa($ttotesi)."</td>";
print "<td align='right'></td>";
print "<td align='right'><b>".putComa($trtotded)."</td>";
print "<td align='right'><b>".putComa($trtotnet)."</td>";

function getMonth($m)
{
 switch($m)
 {
   case '13': return "January";break;   
   case '14': return "February";break;   
   case '15': return "March";break;
   case '4': return "April";break;
   case '5': return "May";break;
   case '6': return "Jun";break;
   case '7': return "July";break;
   case '8': return "August";break;
   case '9': return "Sepember";break;
   case '10': return "October";break;
   case '11': return "November";break;
   case '12': return "December";break;
 }
}



?>
