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

$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;
mysqli_query($db,"delete from emp_pay_allow where empcode='$empcode' and ondata='$ondate'") or die(mysqli_error($db));
mysqli_query($db,"delete from emp_pay_ded where empcode='$empcode' and ondata='$ondate'");

for($k=0;$k<$i;$k++)
{
$sql="insert into emp_pay_allow values('$empcode','$dr[$k]','$amt[$k]','$ondate')";

mysqli_query($db,$sql) or die('allow:'.mysqli_error($db));
}

for($k=0;$k<$j;$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($db));
}

//$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="update emp_pay set totsal='$totsal',basic='$basic',bapf='$bapf',baesi='$baesi',da='$da',dapf='$dapf',daesi='$daesi',ta='$ta',tapf='$tapf',taesi='$taesi',hra='$hra', hrapf='$hrapf',hraesi='$hraesi',rent='$rent',rentpf='$rentpf',rentesi='$rentesi',mob='$mob',dallow='$dallow',tta='$tta',convay='$convay' where empcode='$empcode' and ondate='$ondate' and brcode='$brcode'";

mysqli_query($db,$sql) or die(mysqli_error($db));
?>
<script>
alert('Data has been updated');
 document.location='editpaymast.php';
</script>

