<?
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($save)
{
 $ondate=$y.'-'.$m.'-'.$d;
if(!checkdate($m,$d,$y))
{
 print "<script>alert('Invalid Date'); history.back(1);</script>";
 return;
}

//***********************
return;
/*
 $rs=mysqli_query($db,"select * from salary_master where ondate='$ondate' and empcode='$emp'")or die(mysqli_error($db));
 if(mysqli_num_rows($rs)>0)
 {
   print "<script> alert('Duplicate entry'); history.back(1); </script>";
   return;
 }
 $sql="insert into salary_master (empcode,basic, da,ta,hra,pf,esi,brcode,ondate,convay,uniform, edu,tax) values('$emp','$basic','$da', '$ta','$hra', '$pf', '$esi' ,'$brcode'  ,'$ondate','$convay','$uniform' ,'$edu','$tax')";
  mysqli_query($db,$sql) or die(mysqli_error($db));
 print "<font color=green> Data has been saved</font>";
*/
}


 if($del)
  {mysqli_query($db,"delete from salary_master where code='$code'");}
?>
<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()
{
<?
if($brcode == 'AUT009' || $brcode == 'AUT103')
{ 
?>
	document.f1.basic.value=parseInt(document.f1.totsal.value)*40/100;
	document.f1.da.value=parseInt(document.f1.totsal.value)*40/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);
<?
}
else
{
?>
	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=cur
var value="<select name=dr[]>";

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

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

z.innerHTML="<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="<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="<input type=text name=amt_D[] id=dr_D"+cur_D+" size=10>"
cur_D++; 

}

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

function delRow_D(r)
{
 var i=r.parentNode.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='svpaymast.php'>
<fieldset>
<legend style="color:red"><b>SALARY DETAILS</font></b></legend>
<center>
<table>
<tr><td>Select Employee</td><td colspan=5><select name='empcode'>
<?
$re=mysqli_query($db,"select empcode,empname,br from empmaster where brcode='$brcode' and year(doret)<=0 order by br,empname") or die("ERR :".mysqli_error($db));
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 onKeyDown=chk(this); onChange=calc()></td> 
<tr><td>Basic Salary </td><td><input type=text name=basic onKeyDown=chk(this)></td> 
	<td>Inc in PF</td><td><input type=checkbox value='y' name=bapf checked></td>
	<td>Inc in ESI</td><td><input type=checkbox value='y' name=baesi checked></td>

</tr>
<tr><td>D.A </td><td><input type=text name=da onKeyDown=chk(this)></td>
	<td>Inc in PF</td><td><input type=checkbox value='y' name=dapf checked></td>
	<td>Inc in ESI</td><td><input type=checkbox value='y' name=daesi checked></td>
</tr>
<tr><td>Transport Allowance </td><td><input type=text name='ta' onKeyDown=chk(this)></td>
	<td>Inc in PF</td><td><input type=checkbox value='y' name=tapf></td>
	<td>Inc in ESI</td><td><input type=checkbox value='y' name=taesi checked></td>
</tr>
<tr><td>CCA </td><td><input type=text name='hra' onKeyDown=chk(this)></td>
	<td>Inc in PF</td><td><input type=checkbox value='y' name=hrapf></td>
	<td>Inc in ESI</td><td><input type=checkbox value='y' name=hraesi checked></td>
</tr>

<tr><td>Rent </td><td><input type=text name='rent' onKeyDown=chk(this)></td>
	<td>Inc in PF</td><td><input type=checkbox value='y' name=rentpf></td>
	<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)></td>
	<td colspan=4><font color='green'>This will not come in Pay Slip</td>
</tr>
<tr><td><font color='green'>Daily Allow. </td><td><input type=text name='dallow' onKeyDown=chk(this)></td>
	<td colspan=4><font color='green'>This will not come in Pay Slip</td>
</tr>
<tr><td><font color='green'>T.A </td><td><input type=text name='tta' onKeyDown=chk(this)></td>
	<td colspan=4><font color='green'>This will not come in Pay Slip</td>
</tr>
<tr><td><font color='green'>Convayance</td><td><input type=text name='convay' onKeyDown=chk(this)></td>
	<td colspan=4><font color='green'>This will not come in Pay Slip</td>
</tr>


<tr><td>On Date </td><td colspan=5>
<input type=text name=d size=2 onKeyDown=chk(this) value='<?print date("d",time())?>'>
<input type=text name=m size=2 onKeyDown=chk(this) value='<?print date("m",time())?>'>
<input type=text name=y size=4 onKeyDown=chk(this) value='<?print date("Y",time())?>'>
</td></tr>
<tr><td>Password</td><td><input type=password name='pswd'></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>
<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>

</table><br>

</fieldset>


<fieldset>
 <legend> Deductions</legend>
Add <input type="button" onclick="insRow_D()" value=" + ">
<center>
<table id="myTable_D" border="1"  width=70%>
<tr><td width=50 align=center>Remove<td>No.<td align=center>Name<td  width=100 align=center>Amount 
</table><br>
</fieldset>

<input type=submit value='save' name='save'>
</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>";


 
?>
