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

$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);

$sq="select * from $tbl1 where month(wgfrom)='$month' and year(wgfrom)='$year' and divi='$divi' and br='$br' and brcode='$brcode' order by empcode";
$emppayres=mysqli_query($db,$sq) or die("er2:".mysqli_error($db));


if(mysqli_num_rows($emppayres)<=0)
 {
   print "<script> alert('Record does not exist'); history.back(1); </script>";
 }

while($empayrow=mysqli_fetch_array($emppayres))
{
 ?>
<center><span style={letter-spacing:5}>
<U><b>PAY SLIP</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]
?>
</td></tr>
</table>

<?
PRINT "<CENTER><TABLE BORDER=0 width=100%><TR><TD width=50% align=right>";
 PRINT "<TABLE BORDER=0 width=70%><TR><TD width=200>Name</td><td>".strtoupper($empayrow[ename])."</td></tr>";
print "<TR><TD width=200>Designation</td><td>".strtoupper($empayrow[design])."</td></tr>";


 print "<tr><td>Wages Period </td><td>From ".datetohtml($empayrow[wgfrom])."<br>To &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".datetohtml($empayrow[wgto])."</td></tr>";


 print "<tr><td>No of Days paid </td><td>$empayrow[dayspaid]</td></tr>";
 print "<tr><td>No of working days </td><td>$empayrow[wdays]</td></tr>";
 print "<tr><td>No of Leave </td><td>$empayrow[leave]</td></tr>";
 print "<tr><td>Basic + DA</td><td>".putcoma($empayrow[basicda])."</td></tr>";

 print "<tr><td>Earned (Basic + DA) </td><td>".putComa($empayrow[ebasicda])."</td></tr>";

 print "<tr><td>HRA </td><td>".putcoma($empayrow[hra])."</td></tr>";
 print "<tr><td>Earned HRA </td><td>".putComa($empayrow[ehra])."</td></tr>";

 print "<tr><td>TA</td><td>".putcoma($empayrow[ta])."</td></tr>";
 print "<tr><td>Earned TA </td><td>".putComa($empayrow[eta])."</td></tr>";
 $tots=$ebasic+$eda+$ehra+$eta+$teall;

 //print "<tr><td><b>&nbsp;&nbsp;Total (A)</td><td><b></td></tr>";



$sq="select * from $tbl2 where month(wdatefrm)='$month' and year(wdatefrm)='$year' and divi='$divi' and br='$br' and brcode='$brcode'";
$allow_res=mysqli_query($db,$sq) or die("er2:".mysqli_error($db));

while($allorow1=mysqli_fetch_array($allow_res))
 {
 print "<tr><td>$allorow1[alloname]</td><td>".putComa($allorow1[alloamt])."</td></tr>";
 print "<tr><td>$allorow1[ealloname]</td><td>".putComa($allorow1[ealloamt])."</td></tr>";
 $total+=$allorow1[ealloamt];
 }
$tota=$empayrow[ebasicda]+$empayrow[ehra]+$empayrow[eta]+$total;
print "<tr><td><b>&nbsp;&nbsp;Total (A)</td><td><b>".putComa($tota)."</td></tr>";

print "</tr></td></table>"; 

print "</TD><TD valign=top width=50%>";

print "<CENTER><TABLE BORDER=0 width=70%>";
if($empayrow[wdays]>0)
{
print "<tr><td colspan=2><U><b>DEDUCTIONS</td></tr>";

$sq="select * from $tbl3 where month(wdatefrm)='$month' and year(wdatefrm)='$year' and divi='$divi' and br='$br' and brcode='$brcode' and empcode='$empayrow[empcode]'";

$ded_res=mysqli_query($db,$sq) or die("er2:".mysqli_error($db));
 
while($dedow1=mysqli_fetch_array($ded_res))
{
 print "<tr><td>&nbsp;&nbsp;$dedow1[dedname]</td><td>".putcoma($dedow1[dedamt])."</td></tr>";
 $totded+=$dedow1[dedamt];
}
$ded_res1=mysqli_query($db,$sq);
$dedow=mysqli_fetch_array($ded_res1);
print "<tr><td>&nbsp;&nbsp;PF</td><td>".putcoma($dedow[pf])."</td></tr>";
print "<tr><td>&nbsp;&nbsp;ESI</td><td>".putComa($dedow[esi])."</td></tr>";
print "<tr><td>&nbsp;&nbsp;Other deduction</td><td>".putComa($dedow[otherded])."</td></tr>";
$totd=$totded+$dedow[pf]+$dedow[esi]+$dedow[otherded];
print "<tr><td><b>&nbsp;&nbsp;&nbsp; Total (B)</td><td><b>".putComa($totd)."</td></tr>";
print "<tr><td>&nbsp;</td><td></td></tr>";

print "<tr><td>&nbsp;</td><td></td></tr>";
}
$salpay=$tota-$totd;
print "<tr><td valign=bottom><FONT SIZE=4><B>Salary Payable (A - B)</td><td><FONT SIZE=4><B>".putComa($salpay)."</td></tr>";
print "</TABLE>"; 

print "</TD></TR>";

print "<TR><TD colspan=2><center>";
print "<hr><br>&nbsp;";

}

?>

<STYLE>
body,td{font-familY:'arial narrow';font-size:14}
</style>
