<?
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($pswd!='patmz')
{
 print "<script> alert('Invalid Password') </script>";
 return;
}
$i=0;
foreach($dr as $a)
{
 if(strlen($a)>0)
 {
 $dr[$i]=$a; 	
 $i++;
 }
}

$i=0;
foreach($amt as $a)
{
 if(strlen($a)>0)
 {
 $amt[$i]=$a; 
 $i++;
 }
}

$j=0;
foreach($dr_D as $a)
{
 if(strlen($a)>0)
 {
 $dr_D[$j]=$a; 
 $j++;
 }
}

$j=0;
foreach($amt_D as $a)
{
 if(strlen($a)>0)
 {
 $amt_D[$j]=$a; 
 $j++;
 }
}

 $ondate=$y.'-'.$m.'-'.$d;

if(!checkdate($m,$d,$y))
{
 print "<script>alert('Invalid Date'); history.back(1);</script>";
 return;
}
$celres=mysqli_query($db,"select * from celmast ");
 $celrow=mysqli_fetch_array($celres);

$basic2=0;

for($k=0;$k<$i;$k++)
{
$allres=mysqli_query($db,"select * from allomast where allname='$dr[$k]'");
$allrow=mysqli_fetch_array($allres);
 if($allrow[pf]=='y')
  $basic2+=$amt[$k];
 if($allrow[esi]=='y')
  $basic2+=$amt[$k];

$sql="insert into emp_pay_allow values('$empcode','$dr[$k]','$amt[$k]','$ondate')";
mysqli_query($db,$sql) or die('allow:'.mysqli_error());
}

for($k=0;$k<$j;$k++)
{
$dedres=mysqli_query($db,"select * from dedmast where allname='$dr_D[$k]'");
$dedrow=mysqli_fetch_array($dedres);
 if($dedrow[pf]=='y')
  $basic2-=$amt_D[$k];
 if($dedrow[esi]=='y')
  $basic2-=$amt_D[$k];

$sql="insert into emp_pay_ded values('$empcode','$dr_D[$k]','$amt_D[$k]','$ondate')";
mysqli_query($db,$sql) or die('ded:'.mysqli_error());
}

//$basic+=$basic2;
/*
if($basic<=$celrow[pf])
 $pf=($basic*$celrow[pfp])/100;
else
 $pf=($celrow[pf]*$celrow[pfp])/100;
 

if($basic<=$celrow[esi])
 $esi=($basic*$celrow[esip])/100;
else
 $esi=($celrow[esi]*$celrow[esip])/100;
*/

$sql="insert into emp_pay values('$empcode','$totsal','$basic','$bapf','$baesi','$da','$dapf','$daesi','$ta','$tapf','$taesi','$hra', '$hrapf','$hraesi','$ondate','$brcode','$rent','$rentpf','$rentesi','$mob','$dallow','$tta','$convay')";

mysqli_query($db,$sql) or die(mysqli_error());
?>
<script>
 document.location='paymast.php';
</script>

