
<?
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>
tr,td{background-color:white}
</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);

$sq="select distinct * from $tbl1 where month(wgfrom)='$monthfrm' and year(wgfrom)='$yearfrm' and divi='$divi' and br='$br' and brcode='$brcode' order by empcode ";

$emppayres=mysqli_query($db,$sq) or die("er2:".mysqli_error($db));
$emppayres1=mysqli_query($db,$sq) or die("er2:".mysqli_error($db));

$sq="select distinct * from $tbl2 where month(wdatefrm)='$monthfrm' and year(wdatefrm)='$yearfrm' and divi='$divi' and br='$br' and brcode='$brcode'";

$allow_res=mysqli_query($db,$sq) or die("er2:".mysqli_error($db));
$allow_res1=mysqli_query($db,$sq) or die("er2:".mysqli_error($db));
//$allow_res2=mysqli_query($db,$sq) or die("er2:".mysqli_error($db));

$empayrow1=mysqli_fetch_array($emppayres1);
$sq="select * from $tbl3 where month(wdatefrm)='$monthfrm' and year(wdatefrm)='$yearfrm' and divi='$divi' and br='$br' and brcode='$brcode' and empcode='$empayrow1[empcode]'";

$ded_res=mysqli_query($db,$sq) or die("er2:".mysqli_error($db));
$ded_res1=mysqli_query($db,$sq);
$ded_res2=mysqli_query($db,$sq);

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

<center><span style={letter-spacing:5}>
<U><b>WAGE REGISTER -<?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>
Wage register from :<?print $monthfrm.'-'.$yearfrm?> to <?print $monthto.'-'.$yearto?>
</td></tr>
</table>

<CENTER><TABLE BORDER=0 cellspacing=1 cellpadding=4 bgcolor='silver' width=100%>
<tr><th>No<th>Name of Employee<th>Total Att.<th>No.of Days Paid<th>Total Salary (Basic+DA)<th>Earned (Basic+DA)<th>T.A <th>Earned <br>TA<th>CCA <th>E.CCA<th>
<?
if($monthfrm>=4&&$monthfrm<=5)
print "HRA";
?>
 <th>Total
<?
$allocnt=0;
$al=mysqli_query($db,"select distinct alloname from $tbl2 where month(wdatefrm)='$monthfrm' and year(wdatefrm)='$yearfrm' and divi='$divi' and br='$br' and brcode='$brcode'");
while($allorow1=mysqli_fetch_array($al))
 {
 print "<th>$allorow1[alloname]";
 $hasallow="y";
 $allocnt++;
 }
?>
<th colspan=3>Deduction
<th>Total Deduction<th>Net Salary Paid</tr>
<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>

<?
$al2=mysqli_query($db,"select distinct alloname from $tbl2 where month(wdatefrm)='$monthfrm' and year(wdatefrm)='$yearfrm' and divi='$divi' and br='$br' and brcode='$brcode'");

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

?>
<td></td><td></td><td></td><td align=center>PF<td align=center>ESI<td align=center>Adv/<br>other</td>
<?
$i=1;
$totebasicda=0;
$totbasicda=0;
$totta=0;
$toteta=0;
$tothra=0;
$totehra=0;
$totnet=0;
$totpf=0;
$totesi=0;
$ttotded=0;
$gtotded=0;
$tottilhra=0;
while($empayrow=mysqli_fetch_array($emppayres))
{
$allsq="select distinct * from $tbl2 where month(wdatefrm)='$monthfrm' and year(wdatefrm)='$yearfrm' and divi='$divi' and br='$br' and brcode='$brcode' and empcode='$empayrow[empcode]'";
//print $allsq;
$allow_res2=mysqli_query($db,$allsq) or die("er2:".mysqli_error($db));


$jvres=mysqli_query($db,"select max(jvno) from journal2 where brcode='$brcode'");
$jvrow=mysqli_fetch_array($jvres);
$jvno=($jvrow[0]+1);


$totded=0;
$totfornet=0;
$tottilhra=0;
print "\n<tr><td>".$i++."</td><td>".strtoupper($empayrow[ename])."</td><td align=center>$empayrow[wdays]</td>";
print "<td  align=center>$empayrow[dayspaid]</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($monthfrm>=4&&$monthfrm<=5)
	print "<td align=right>$empayrow[rent]</td>"; //
else
print "<td align=right>&nbsp;</td>"; //$empayrow[rent]
$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($monthfrm>=4&&$monthfrm<=5)
	$tottilhra+=$empayrow[rent];

$gtottilhra+=$tottilhra;

$totfornet=($empayrow[ebasicda]+$empayrow[eta]+$empayrow[ehra]+$empayrow[rent1]);
if($monthfrm>=4&&$monthfrm<=5)
	$totfornet+=$empayrow[rent];
print "<td align=right>".putComa($tottilhra)."</td>";
$jsql1="insert into journal2 values('2008-4-30','$jvno','Dr','Salary and Wages','$tottilhra','0','salary paid to ".strtoupper($empayrow[ename])." for the month $monthto-$yearto','$brcode','salary','','$empayrow[empcode]','')";
//print $jsql1.'<br>';
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)='$monthfrm' and year(wdatefrm)='$yearfrm' 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));
$dedow1=mysqli_fetch_array($ded_res);
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;


$jsql2="insert into journal2 values('2008-4-30','$jvno','Cr','PF Payable','0','$dedow1[pf]', 'pf paid to ".strtoupper($empayrow[ename])." for the month $monthto-$yearto' ,'$brcode','salary','','$empayrow[empcode]','')";

$jsql3="insert into journal2 values('2008-4-30','$jvno','Cr','ESI Payable','0','$dedow1[esi]', 'esi paid to ".strtoupper($empayrow[ename])." for the month $monthto-$yearto' ,'$brcode','salary','','$empayrow[empcode]','')";

//" to ESI Payable ".$dedow1[esi];
$jsql4="insert into journal2 values('2008-4-30','$jvno','Cr','ADVANCE-".strtoupper($empayrow[ename])."','0','$dedow1[otherded]', 'advance paid to ".strtoupper($empayrow[ename])." for the month $monthto-$yearto' ,'$brcode','salary','','$empayrow[empcode]','')";

//" to ADVANCE-".strtoupper($empayrow[ename]) .' '.$dedow1[otherded];

print "<td align=right>".putcoma($totded)."</td><td align=right>".putComa($totfornet)."</td>";
print "</tr>";
$jsql5="insert into journal2 values('2008-4-30','$jvno','Cr','Salary Payable','0','$totfornet', 'salary paid to ".strtoupper($empayrow[ename])." for the month $monthto-$yearto' ,'$brcode','salary','','$empayrow[empcode]','')";

$jsql10="insert into payjv (date,jvno,empcode,ename,brcode,br) values('2008-4-30','$jvno','$empayrow[empcode]', '$empayrow[ename]', '$empayrow[brcode]','$empayrow[br]')";

//" to Salary Payable ".$totfornet;
//print "<tr><td colspan=20>$jsql1 <br>$jsql2<br>$jsql3<br>$jsql4 <br>$jsql5</td></tr>";

if($divi=='vehicle')
{
/* mysqli_query($db,$jsql1) or die('j1'.mysqli_error($db));
 mysqli_query($db,$jsql2) or die('j2'.mysqli_error($db));
 mysqli_query($db,$jsql3) or die('j3'.mysqli_error($db));
 mysqli_query($db,$jsql4) or die('j4'.mysqli_error($db));
 mysqli_query($db,$jsql5) or die('j5'.mysqli_error($db));
 mysqli_query($db,$jsql10) or die('j10'.mysqli_error($db));
*/
}
}
print "<tr><td colspan=4 align=center><b>Total</td><td align=right>". putComa($totbasicda)."</td><td align=right>".putComa($totebasicda)."</td><td align=right>".putComa($totta)."</td>";
print "<td align=right>".putComa($toteta)."</td><td align=right>".putComa($tothra)."</td>";
print "<td align=right>".putComa($totehra)."</td><td>".putComa($totrent)."</td>";
print "<td>".putComa($gtottilhra)."</td>";
for($k=0;$k<$allocnt;$k++)
 print "<td align=right>$tallo</td>";
$totnet+=$tallo;
print "<td>".putComa($totpf)."</td><td align=right>".putComa($totesi)."</td><td align=right>".putComa($ttotded)."<td align=right>".putComa($gtotded)."</td>";
print "<td align=right>".putComa($totnet)."</td>";
$pfcontri=($totpf*13.11/12);
$esicontri=($totesi*13.11/12);
$jvno++;
$jsql6="insert into journal2 values('2008-4-30','$jvno','Dr','PF Employer Contribution','$pfcontri','0', 'PF emp contribution for the month $monthto-$yearto', '$brcode','salary','','$empayrow[empcode]','')";

$jsql7="insert into journal2 values('2008-4-30','$jvno','Cr','PF Payable','0','$pfcontri', 'PF emp contribution for the month $monthto-$yearto', '$brcode','salary','','$empayrow[empcode]','')";


$jsql8="insert into journal2 values('2008-4-30','$jvno','Dr','ESI Employer Contribution','$esicontri','0', 'ESI emp contribution for the month $monthto-$yearto', '$brcode','salary','','$empayrow[empcode]','')";

$jsql9="insert into journal2 values('2008-4-30','$jvno','Cr','ESI Payable','0','$esicontri', 'ESI emp contribution for the month $monthto-$yearto', '$brcode','salary','','$empayrow[empcode]','')";


print "</table>";
//print $sql6.'<br>'.$sql7.'<br>';
//print $sql8.'<br>'.$sql9;
//print '<br>'.$sql10;

if($divi=='vehicle')
{ print "<br><b>post..";

/* mysqli_query($db,$jsql6) or die('j6'.mysqli_error($db));
 mysqli_query($db,$jsql7) or die('j7'.mysqli_error($db));
 mysqli_query($db,$jsql8) or die('j8'.mysqli_error($db));
 mysqli_query($db,$jsql9) or die('j9'.mysqli_error($db));*/
}
?>

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