
<?
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' and design not like '%MECHANIC TRAINEE%' 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>Father's/Husband Name<th>Designation<th>Basic+DA<th>Actually Paid<th>Total Attendance<th>Overtime Worked<th>Gross Wage<th colspan=3>Deduction<th>Total Deduction<th>Wages<th>Date of Payment<th>Signature of the Employee
<?
$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' ");
?>
</tr>
<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td>PF</td><td>ESI</td><td>Other</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++;
 }

?>

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

$sql="select * from empmaster where brcode='$brcode' and empname = '$empayrow[ename]'";
$empmas=mysqli_query($db,$sql);
$empmaster=mysqli_fetch_array($empmas);

$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>".strtoupper($empmaster[fname])."</td><td>".strtoupper($empayrow[design])."</td><td></td>";
//print "<td align=right>$empayrow[basicda]</td>";
//print "<td align=right>$mebasicda</td>";
//print "<td align=center>$empayrow[wdays]</td><td></td>";
//print "<td  align=center>$empayrow[dayspaid]</td><td></td>";
//print "<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($db));
$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($db));
$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($db));

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>";
print "<td  align=center>$empayrow[dayspaid]</td><td></td>";
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($db));
$dedow1=mysqli_fetch_array($ded_res);

if($brcode=='AUT009')
{
$pf=round($dedow1[pf]);
$esi=ceil($dedow1[esi]+$mesi_inc1[newesi]);

}
else
{
$pf=ceil($dedow1[pf]);
$esi=ceil($dedow1[esi]+$mesi_inc1[newesi]);
}
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($mesi_inc1[prof_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+$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];
$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><td></td><td></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></td><td align=right>".putComa($gtottilhra)."</td><td></td><td></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($gtottilhra)."</td>";
print "<td>".putComa(round($totpf))."</td><td align=right>".putComa(round($totesi))."</td><td align=right>".putComa($gtotother_ded)."<td align=right>".putComa($gtotded)."</td>";
print "<td align=right>".putComa($totnet)."</td><td></td><td></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>
