
<?
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());
$emppayres1=mysqli_query($db,$sq) or die("er2:".mysqli_error());

$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());
$allow_res1=mysqli_query($db,$sq) or die("er2:".mysqli_error());
//$allow_res2=mysqli_query($db,$sq) or die("er2:".mysqli_error());

$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());
$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
<?
print "<th>HRA";
$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>Incentive 
<th>Overtime 
<th>Mob.Inc
<th>Total

<th colspan=10>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><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' ");
$allcnt=0;
while($allorow2=mysqli_fetch_array($al2))
 {
 print "<td></td>";
$allcnt++;
 }

?>
<td></td><td></td><td></td><td></td><td></td><td align=center>PF<td align=center>ESI<td align=center>Laptop</td><td align=center>Mobile<td align=center>Advance</td><td align=center>TDS</td><td align=center>Prof.Tax</td><td align=center>Kshema<br>nidhi</td><td align=center>Medi<br>claim</td><td align=center>Other<br>ded</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;
$gtotinc=0;
$gtotot=0;
$gtotmob_all=0;
$gtotlaptop=0;
$gtotmob_ded=0;
$tottilhra=0;
while($empayrow=mysqli_fetch_array($emppayres))
{


$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;
$tallo=0;
$meta=number_format(ceil($empayrow[eta]),2);
$mehra=number_format(ceil($empayrow[ehra]),2);
$mebasicda=number_format(ceil($empayrow[ebasicda]),2);
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>$mebasicda</td><td align=right>$empayrow[ta]</td><td align=right>$meta</td><td align=right>$empayrow[hra]</td><td align=right>$mehra</td>";
print "<td align=right>$empayrow[rent]</td>"; //

$totebasicda+=ceil($empayrow[ebasicda]);
$totbasicda+=$empayrow[basicda];
$totta+=$empayrow[ta];
$toteta+=ceil($empayrow[eta]);
$tothra+=$empayrow[hra];
$totehra+=ceil($empayrow[ehra]);

$totrent+=$empayrow[rent];

//$empayrow[basicda]+
$tottilhra=(ceil($empayrow[ebasicda])+ceil($empayrow[eta])+ceil($empayrow[ehra]));
//+$empayrow[rent]);

//if($monthfrm>=14&&$monthfrm<=15)
$tottilhra+=$empayrow[rent];



$totfornet=($empayrow[ebasicda]+ceil($empayrow[eta])+ceil($empayrow[ehra])+$empayrow[rent]);

$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]','')";
//***************************************************************
$al21=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' ")or die(mysqli_error());
$allcnt=0;
$m=0;
$sq="select * from esiinc where month(fordate)='$monthfrm' and year(fordate)='$yearfrm' and divi='$divi' and br='$br' and brcode='$brcode' and ename='$empayrow[ename]'";
$mesi_inc=mysqli_query($db,$sq) or die("er2:".mysqli_error());
$mesi_inc1=mysqli_fetch_array($mesi_inc);

while($allorow2=mysqli_fetch_array($al21))
 {

$allsq="select * from $tbl2 where alloname like'$allorow2[0]' and month(wdatefrm)='$monthfrm' and year(wdatefrm)='$yearfrm' and divi='$divi' and br='$br' and brcode='$brcode' and empcode='$empayrow[empcode]'";
$allow_res2=mysqli_query($db,$allsq) or die("er2:".mysqli_error());

if(mysqli_num_rows($allow_res2)<=0) //&& $hasallow=='y')
 {
   print "<td align=right>0.00</td>";
$alloarr[$m]+=0;
 $m++;
 }
else
while($allorow=mysqli_fetch_array($allow_res2))
 {
 print "<td align=right>".putComa($allorow[ealloamt])."</td>";
 $tallo+=$allorow[ealloamt];
 $alloarr[$m]+=$allorow[ealloamt]; 
 $m++;
 }
}
print "<td align=right>".putComa($mesi_inc1[inc])."</td>";
print "<td align=right>".putComa($mesi_inc1[ot])."</td>";
print "<td align=right>".putComa($mesi_inc1[mob_all])."</td>";
//print '<br>tallo'.$tallo;
$tottilhra+=$tallo+$mesi_inc1[inc]+$mesi_inc1[ot]+$mesi_inc1[mob_all];
$gtottilhra+=$tottilhra;
print "<td align=right>".putComa($tottilhra)."</td>";
//****************************************
$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());
$dedow1=mysqli_fetch_array($ded_res);
$mprof_tax = 0;
if($brcode=='AUT009')
{
$pf=round($dedow1[pf]);
$esi=ceil($dedow1[esi]+$mesi_inc1[newesi]);
//$esi=ceil($dedow1[esi]);
}
else
{
$pf=ceil($dedow1[pf]);
$esi=ceil($dedow1[esi]);
$esi=ceil($dedow1[esi]+$mesi_inc1[newesi]);
}
if ($mesi_inc1[prof_tax]<=0)
{
	if($brcode=='AUT009'||$brcode=='AUT103')
	{
		$mprof_tax=round($dedow1[ptaxamt]);
	}
}
else
{
	$mprof_tax = $mesi_inc1[prof_tax];
}
print "<td align=right>".putcoma($pf)."</td>";
print "<td align=right>".putComa($esi)."</td>";
print "<td align=right>".putComa($mesi_inc1[laptop])."</td>";
print "<td align=right>".putComa($mesi_inc1[mob_ded])."</td>";
print "<td align=right>".putComa($mesi_inc1[advance])."</td>";
print "<td align=right>".putComa($mesi_inc1[tds])."</td>";
print "<td align=right>".putComa($mprof_tax)."</td>";
print "<td align=right>".putComa($mesi_inc1[kshemanidhi])."</td>";
print "<td align=right>".putComa($mesi_inc1[mediclaim])."</td>";
print "<td align=right>".putComa($mesi_inc1[other_ded])."</td>";

$totded+=$pf+$esi+$dedow1[otherded]+$dedow1[ptaxamt]+$mesi_inc1[laptop]+$mesi_inc1[mob_ded]+$mesi_inc1[advance]+$mesi_inc1[tds]+$mesi_inc1[prof_tax]+$mesi_inc1[kshemanidhi]+$mesi_inc1[mediclaim]+$mesi_inc1[other_ded];
$totfornet=($tottilhra-$totded);
$totfornet=$totfornet;
$totnet+=$totfornet;
$totpf+=$dedow1[pf];
$totesi+=$dedow1[esi]+$mesi_inc1[newesi];
$ttotded+=$dedow1[otherded];
$gtotded+=$totded;
$gtotptx+=$dedow1[ptaxamt];
$gtotinc+=$mesi_inc1[inc];
$gtotot+=$mesi_inc1[ot];
$gtotmob_all+=$mesi_inc1[mob_all];
$gtotlaptop+=$mesi_inc1[laptop];
$gtotmob_ded+=$mesi_inc1[mob_ded];
$gtotadvance+=$mesi_inc1[advance];
$gtottds+=$mesi_inc1[tds];
$gtotprof_tax+=$mesi_inc1[prof_tax]+$mprof_tax;
$gtotkshemanidhi+=$mesi_inc1[kshemanidhi];
$gtotmediclaim+=$mesi_inc1[mediclaim];
$gtotother_ded+=$mesi_inc1[other_ded];

/*$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());
 mysqli_query($db,$jsql2) or die('j2'.mysqli_error());
 mysqli_query($db,$jsql3) or die('j3'.mysqli_error());
 mysqli_query($db,$jsql4) or die('j4'.mysqli_error());
 mysqli_query($db,$jsql5) or die('j5'.mysqli_error());
 mysqli_query($db,$jsql10) or die('j10'.mysqli_error());
*/
}
}
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>";
for($k=0;$k<$m;$k++)
{ print "<td align=right>".putComa($alloarr[$k])."</td>";
  $kallo+=$alloarr[$k];
}

print "<td align=right>".putComa($gtotinc)."</td>";
print "<td align=right>".putComa($gtotot)."</td>";
print "<td align=right>".putComa($gtotmob_all)."</td>";
//$gtottilhra+=$kallo;
print "<td>".putComa($gtottilhra)."</td>";
$totnet+=$totrent;
//$totnet+=$tallo; changed
//$totnet+=$kallo;
print "<td>".putComa(round($totpf))."</td><td align=right>".putComa(round($totesi))."</td><td align=right>".putComa($gtotlaptop)."</td><td align=right>".putComa($gtotmob_ded)."</td><td align=right>".putComa($gtotadvance)."</td><td align=right>".putComa($gtottds)."</td><td align=right>".putComa($gtotprof_tax)."</td><td align=right>".putComa($gtotkshemanidhi)."</td><td align=right>".putComa($gtotmediclaim)."</td><td align=right>".putComa($gtotother_ded)."<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());
 mysqli_query($db,$jsql7) or die('j7'.mysqli_error());
 mysqli_query($db,$jsql8) or die('j8'.mysqli_error());
 mysqli_query($db,$jsql9) or die('j9'.mysqli_error());*/
}
?>

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