<?
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");
$sql="select * from emp_pay where empcode='$empcode' order by ondate desc limit 1";
$em=mysqli_query($db,$sql);
$res=mysqli_fetch_array($em);
$con=$res[convay];
?>
<head>
<script>
var cur=1;
var cur_D=1;
var als=[];
var als_D=[];
als[0]='<option></option>';
var pfce;
var esice;
var pfp;
var esip;

//als[0]="</option>";
als_D[0]="<option></option>";

function chk(x)
{
 if(isNaN(x.value))
 {
  alert('Invalid Entry');x.value='';
  return false;
 }
}
function valid()
{
 if(document.f1.basic.value<=0)
  {
    alert('Invalid Basic');
    return false;
  }
}
function calc()
{

document.f1.basic.value=parseInt(document.f1.totsal.value)*60/100;
document.f1.da.value=parseInt(document.f1.totsal.value)*20/100;
document.f1.ta.value=parseInt(document.f1.totsal.value)*10/100;
document.f1.hra.value=parseInt(document.f1.totsal.value)*10/100;
//document.f1.pf.value=(parseInt(document.f1.totsal.value)*pfp/100)+parseInt(document.f1.da.value);

}
function insRow()
{
var x=document.getElementById('myTable').insertRow(cur)
var a1=x.insertCell(0)
var a=x.insertCell(1)
var y=x.insertCell(2)
var z=x.insertCell(3)	
a1.innerHTML="<center><input type=button value='-' onClick='delRow(this)'>";
a.innerHTML="<center>"+cur
var value="<center><select name=dr[]>";

for(k=0;k<als.length;k++)
 value=value+"<option>"+als[k]+"</option>";

value=value+"</select>";
y.innerHTML=value

z.innerHTML="<center><input type=text name=amt[] id=dr"+cur+" size=10>"
cur++; 

}


function insRow_D()
{
var x=document.getElementById('myTable_D').insertRow(cur_D)
var a1=x.insertCell(0)
var a=x.insertCell(1)
var y=x.insertCell(2)
var z=x.insertCell(3)	
a1.innerHTML="<center><input type=button value='-' onClick='delRow_D(this)'>";
a.innerHTML=cur_D
var value="<center><select name=dr_D[]>";

for(k=0;k<als_D.length;k++)
 value=value+"<option>"+als_D[k]+"</option>";

value=value+"</select>";
y.innerHTML=value


z.innerHTML="<center><input type=text name=amt_D[] id=dr_D"+cur_D+" size=10>"
cur_D++; 

}

function delRow(r)
{
 var i=r.parentNode.parentNode.rowIndex; 
 document.getElementById('myTable').deleteRow(i);
cur--;
}

function delRow_D(r)
{
 var i=r.parentNode.parentNode.rowIndex;
 document.getElementById('myTable_D').deleteRow(i);
cur_D--;
}

</script>

<style>
body,td{font-family:'arial narrow';letter-spacing:1;}
tr{background-color:e3ecd2}
th{background-color:c1d799}
.mnu{margin-left:5}
body{BACKGROUND-COLOR:fcfff1}
//input{text-align:right}
</style>

<form name='f1' action='updpaymast.php'>
<fieldset>
<legend style="color:red"><b>EDIT SALARY DETAILS</font></b></legend>
<center>
<table>
<tr><td> Employee</td><td colspan=5><select name='empcode'>
<?
$re=mysqli_query($db,"select empcode,empname,br from empmaster where empcode='$empcode' and brcode='$brcode' ") or die("ERR :".mysqli_error());
while($row=mysqli_fetch_array($re))
{
 print "\n<option value='$row[0]'>$row[1]-$row[2]</option>";
}
?>
</select>
</td></tr>

<tr><td>Total Salary </td><td colspan=5><input type=text name=totsal value="<?print $res[totsal]?>" onKeyDown=chk(this); onChange=calc()></td> 
<tr><td>Basic Salary </td><td><input type=text name=basic value="<?print $res[basic]?>" onKeyDown=chk(this)></td>
	<?if($res[bapf]=='y')
	print "<td>Inc in PF</td><td><input type=checkbox value='y' name=bapf checked>";
	else
	print "<td>Inc in PF</td><td><input type=checkbox value='y' name=bapf>";?>
</td>
	<?if($res[baesi]=='y')
	print "<td>Inc in ESI</td><td><input type=checkbox value='y' name=baesi checked></td>";
	else
	print "<td>Inc in ESI</td><td><input type=checkbox value='y' name=baesi></td>";?>
</tr>
<tr><td>D.A </td><td><input type=text name=da value="<?print $res[da]?>" onKeyDown=chk(this)></td>
	<?if($res[dapf]=='y')
	print "<td>Inc in PF</td><td><input type=checkbox value='y' name=dapf checked></td>";
	else
	print "<td>Inc in PF</td><td><input type=checkbox value='y' name=dapf></td>";?>
	<?if($res[daesi]=='y')
	print "<td>Inc in ESI</td><td><input type=checkbox value='y' name=daesi checked></td>";
	else
	print "<td>Inc in ESI</td><td><input type=checkbox value='y' name=daesi></td>";?>
</tr>
<tr><td>Transport Allowance </td><td><input type=text name=ta value="<?print $res[ta]?>" onKeyDown=chk(this)></td>
	<?if($res[tapf]=='y')
	print "<td>Inc in PF</td><td><input type=checkbox value='y' name=tapf checked></td>";
	else
	print "<td>Inc in PF</td><td><input type=checkbox value='y' name=tapf></td>";?>
	<?if($res[taesi]=='y')
	print "<td>Inc in ESI</td><td><input type=checkbox value='y' name=taesi checked></td>";
	else
	print "<td>Inc in ESI</td><td><input type=checkbox value='y' name=taesi></td>";?>
</tr>
<tr><td>CCA </td><td><input type=text name=hra value="<?print $res[hra]?>" onKeyDown=chk(this)></td>
	<?if($res[hrapf]=='y')
	print "<td>Inc in PF</td><td><input type=checkbox value='y' name=hrapf checked></td>";
	else
	print "<td>Inc in PF</td><td><input type=checkbox value='y' name=hrapf></td>";?>
	<?if($res[hraesi]=='y')
	print "<td>Inc in ESI</td><td><input type=checkbox value='y' name=hraesi checked></td>";
	else
	print "<td>Inc in ESI</td><td><input type=checkbox value='y' name=hraesi></td>";?>
</tr>
<tr><td>Rent </td><td><input type=text name='rent' onKeyDown=chk(this) value="<?print $res[rent]?>"></td>
	<?if($res[rentpf]=='y')
	print "<td>Inc in PF</td><td><input type=checkbox value='y' name=rentpf checked></td>";
	else
	print "<td>Inc in PF</td><td><input type=checkbox value='y' name=rentpf></td>";?>
	<?if($res[rentesi]=='y')
	print "<td>Inc in ESI</td><td><input type=checkbox value='y' name=rentesi checked></td>";
	else
	print "<td>Inc in ESI</td><td><input type=checkbox value='y' name=rentesi></td>";?>
</tr>
<tr><td><font color='green'>Mobile </td><td><input type=text name='mob' onKeyDown=chk(this) value="<?print $res[mob]?>"></td>
	<td></td><td></td>
	<td></td><td></td>
</tr>
<tr><td><font color='green'>Daily Allow. </td><td><input type=text name='dallow' onKeyDown=chk(this) value="<?print $res[dallow]?>"></td>
	<td></td><td></td>
	<td></td><td></td>
</tr>
<tr><td><font color='green'>T.A </td><td><input type=text name='tta' onKeyDown=chk(this) value="<?print $res[tta]?>"></td>
	<td></td><td></td>
	<td></td><td></td>
</tr>
<tr><td><font color='green'>Convayance</td><td>
<input type=text name='convay' onKeyDown=chk(this) value='<?print $con; ?>'></td>
	<td></td><td></td>
	<td></td><td></td>
</tr>

<tr><td>On Date </td><td colspan=5>
<?
$ond=explode('-',$res[ondate]);
if($ond[0]<=0)
{$ond[0]=date('Y');
$ond[1]=date('m');
$ond[2]=date('d');
}
?>dd
<input type=text name=d size=2 readonly onKeyDown=chk(this) value='<?print $ond[2]?>'>
mm
<input type=text name=m size=2 readonly onKeyDown=chk(this) value='<?print $ond[1]?>'>
yy
<input type=text name=y size=4 readonly onKeyDown=chk(this) value='<?print $ond[0]?>'>
</td></tr>
<tr><td bgcolor=c1d799 colspan=6 align=center></td></tr>
</table>
</center>
</fieldset>

<fieldset>
<legend> Allowances </legend>
Add <input type="button" onclick="insRow()" value=" + ">
<center>
<?
$sql="select * from emp_pay_allow where empcode='$res[empcode]' and ondata='$res[ondate]'";
$al=mysqli_query($db,$sql) or die (mysqli_error());
?>
<table id="myTable" border="1" width=70%>
<tr><td width=50 align=center>Remove<td align=center>No.
<td align=center>Name<td width=100 align=center>Amount </td></tr>
<?
$x=1;
while($al_res=mysqli_fetch_array($al))
{
print "<tr><td width=50 align=center><input type=button value='-' onClick='delRow(this)'><td align=center>".$x++;
print "<td align=center><input type=text size=20 name='dr[]' value='$al_res[allow]'>";
print "<td align=center><input type=text size=10 name='amt[]' value='$al_res[amt]' style='text-align:right'>";
print "\n<script>cur++; </script>";
}
?>
</table><br>

</fieldset>


<fieldset>
<legend> Deductions </legend>
Add <input type="button" onclick="insRow_D()" value=" + ">
<center>
<?
$sql="select * from emp_pay_ded where empcode='$res[empcode]' and ondata='$res[ondate]'";
$al=mysqli_query($db,$sql) or die (mysqli_error());
?>
<table id="myTable_D" border="1" width=70%>
<tr><td width=50 align=center>Remove<td align=center>No.
<td align=center>Name<td width=100 align=center>Amount </td></tr>
<?
$x=1;
while($al_res=mysqli_fetch_array($al))
{
print "<tr><td width=50 align=center><input type=button value='-' onClick='delRow_D(this)'><td align=center>".$x++;
print "<td align=center><input type=text size=20 name='dr_D[]' value='$al_res[allow]'>";
print "<td align=center><input type=text size=10 name='amt_D[]' value='$al_res[amt]' style='text-align:right'>";
print "\n<script>cur_D++; </script>";
}
?>
</table><br>

</fieldset>
<input type=submit value='Update'>
</form>











<?
//include("../opendb.php");
$re=mysqli_query($db,"select * from allomast where brcode='$brcode' order by 3");
$i=1;
while($row=mysqli_fetch_row($re))
{
 print "\n<script>als[$i]='$row[2]' </script>";
 $i++;
}

$re=mysqli_query($db,"select * from dedmast  where brcode='$brcode' order by 3");
$i=1;
while($row=mysqli_fetch_row($re))
{
 print "\n<script>als_D[$i]='$row[2]' </script>";
 $i++;
}

$repf=mysqli_query($db,"select * from celmast where brcode='$brcode'");
$repfrow=mysqli_fetch_array($repf);
print "<script>pfce='$repfrow[0]'; esice='$repfrow[2]'; pfp='$repfrow[1]'; esip='$repfrow[3]';</script>";
?>


