<?php 
$PageSecurity = 2;
$title = _('Employee Grade Master');
include('includes/SQL_CommonFunctions.inc');

if($_REQUEST['Submit'] != '')
{
      $sql_check_grade="select count(*) from emp_grade where grade_name='".$_REQUEST['name']."'";
      $result_check_grade=DB_query($sql_check_grade,$db);
      $rs_check_grade=DB_fetch_array($result_check_grade);
      $count_row=$rs_check_grade[0];
      if($count_row<1)
      {

			    $data['grade_code']                 =$_POST['code'];
			    $data['grade_name']                 =$_POST['name'];
			    $data['grade_amount']               =$_REQUEST['total'];
		        $data['basic_perc']                 =$_REQUEST['basic_perc'];
			    $data['basic_salary']               =$_REQUEST['basic_salary'];	  
				$data['allow_tot']                  =$_REQUEST['allow_tot'];
				$data['deduct_tot']                 =$_REQUEST['deduct_tot'];
				$data['CompanyId']                  =$_SESSION['ACGCompanyId'];
			   $s->RecordInsert('emp_grade',$data);
			   $Lastreq_id=DB_Last_Insert_ID($db,'emp_grade',$ErrMsg); 

			/*$sql="INSERT INTO emp_grade(id,grade_code,grade_name) VALUES('','".$_POST['code']."','".$_POST['name']."')";
			$result=DB_query($sql,$db);*/

			foreach($_REQUEST['designation'] as $key=>$value)
			{

			   $data_dtls['emp_grade_id']=$Lastreq_id;
			   $data_dtls['desigmaster_id']=$value;
			  $s->RecordInsert('emp_grade_dtls',$data_dtls);
			  $update=DB_query("update desigmaster set status=1 where id='".$value."'",$db);
			}

		     for($k=1;$k<$_REQUEST['ctr'];$k++)
					{
						$dataEmpSal['emp_grade_id']=$Lastreq_id;
						$dataEmpSal['allowance_deduction']=$_REQUEST['allid'][$k];
						$dataEmpSal['percentage']=$_REQUEST['aperc'][$k];
						$dataEmpSal['percentage_value']=$_REQUEST['allow'][$k];
						$dataEmpSal['all_ded_prefix']=$_REQUEST['prefix1'];
						$s->RecordInsert('emp_salary_grade',$dataEmpSal);
					}
					
					$dataEmpSpeSal['emp_grade_id']=$Lastreq_id;
					$dataEmpSpeSal['allowance_deduction']='100';
					$dataEmpSpeSal['percentage']='0.00';
					$dataEmpSpeSal['percentage_value']=$_REQUEST['special_allow'];
					$dataEmpSpeSal['all_ded_prefix']='A';
					$s->RecordInsert('emp_salary_grade',$dataEmpSpeSal);			
			
		
			
					for($K=1;$K<$_REQUEST['dctr'];$K++)
					{
						$dataEmpSalDed['emp_grade_id']=$Lastreq_id; 
						$dataEmpSalDed['allowance_deduction']=$_REQUEST['dedid'][$K];
						$dataEmpSalDed['percentage']=$_REQUEST['dperc'][$K]; 
						$dataEmpSalDed['percentage_value']=$_REQUEST['deduction'][$K]; 
						$dataEmpSalDed['all_ded_prefix']=$_REQUEST['prefix2'];
						$s->RecordInsert('emp_salary_grade',$dataEmpSalDed);
					}




			prnMsg( _('Record Inserted Successfully!'),'success');
			echo "<script>location.href='index.php?route=HRModule/employee_gradeMaster&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
	}
	else
	{
		prnMsg( _('This Employee Grade Already Exist please Enter New Employee Grade!'),'error');
	}		
}
if($_GET['id']!='' && $_GET['action']=='edit' && !isset($_REQUEST['Update']))
{
	$get_sql=DB_query("Select * from emp_grade where id='".$_GET['id']."'",$db);
	$get_row=DB_fetch_array($get_sql);
	
	$_REQUEST['code']=$get_row['grade_code'];
	$_REQUEST['name']=$get_row['grade_name'];
	$_REQUEST['total']=$get_row['grade_amount'];
	$grade_id='';
	$sql_grade1=DB_query("select desigmaster_id from emp_grade_dtls where emp_grade_id='".$_REQUEST['id']."'",$db);
	if(DB_num_rows($sql_grade1)>0)
	{
		while($row_grade=DB_fetch_array($sql_grade1))
		{
		$grade_id[]=$row_grade['desigmaster_id'];
	    }
	}

    $deduction_type='';
	$sql_grade11=DB_query("select all_ded_prefix,percentage,percentage_value,allowance_deduction from emp_salary_grade where emp_grade_id='".$_REQUEST['id']."'",$db);
	if(DB_num_rows($sql_grade11)>0)
	{
		while($row_grade1=DB_fetch_array($sql_grade11))
		{
		$deduction_type[$row_grade1['allowance_deduction']][$row_grade1['all_ded_prefix']]=$row_grade1;
	    }
	}


}
if($_REQUEST['Update'] != '' && $_REQUEST['id']!='')
{

       $data['grade_code']                 =$_POST['code'];
	   $data['grade_name']                 =$_POST['name'];
	   $data['grade_amount']               =$_REQUEST['total'];
	   $data['basic_perc']                 =$_REQUEST['basic_perc'];
	   $data['basic_salary']               =$_REQUEST['basic_salary'];	  
	   $data['allow_tot']                  =$_REQUEST['allow_tot'];
	   $data['deduct_tot']                 =$_REQUEST['deduct_tot'];
	   //$data['CompanyId']     =$_SESSION['ACGCompanyId'];
	   $condition="id='".$_REQUEST['id']."'";
	   $s->RecordEdit('emp_grade',$data,$condition);
	   $Lastreq_id=$_REQUEST['id']; 

     $check1=DB_query("select desigmaster_id from emp_grade_dtls where emp_grade_id='".$Lastreq_id."' ",$db);
     while($row1=DB_fetch_array($check1))
     {
      $update=DB_query("update desigmaster set status=0 where id='".$row1['desigmaster_id']."'",$db);	
     }	
  
	foreach($_REQUEST['designation'] as $key=>$value)
	{
       

    $check=DB_query("select * from emp_grade_dtls where emp_grade_id='".$Lastreq_id."' and desigmaster_id='".$value."'",$db);	
			if(DB_num_rows($check)>0)  {
			   $data_dtls['emp_grade_id']=$Lastreq_id;
			   $data_dtls['desigmaster_id']=$value;
			   $condi="emp_grade_id='".$Lastreq_id."' and desigmaster_id='".$value."'";
			   $s->RecordEdit('emp_grade_dtls',$data_dtls,$condi);
			   $update=DB_query("update desigmaster set status=1 where id='".$value."'",$db);
			}
			else
			{
			 $data_dtls['emp_grade_id']=$Lastreq_id;
			 $data_dtls['desigmaster_id']=$value;
			 $s->RecordInsert('emp_grade_dtls',$data_dtls);
			 $update=DB_query("update desigmaster set status=1 where id='".$value."'",$db);

			}

	}


 for($k=1;$k<$_REQUEST['ctr'];$k++)
			{
			$chkOtherAllwcId=DB_query("select * from emp_salary_grade where emp_grade_id='".$Lastreq_id."'
		     and allowance_deduction='".$_REQUEST['allid'][$k]."' and all_ded_prefix='".$_REQUEST['prefix1']."'",$db);	
			if(DB_num_rows($chkOtherAllwcId)>0)  {
				$dataEmpSal['emp_grade_id']=$Lastreq_id;
				$dataEmpSal['allowance_deduction']=$_REQUEST['allid'][$k];
				$dataEmpSal['percentage']=$_REQUEST['aperc'][$k];
				$dataEmpSal['percentage_value']=$_REQUEST['allow'][$k];
				$dataEmpSal['all_ded_prefix']=$_REQUEST['prefix1'];
				$condsal12="emp_grade_id='".$Lastreq_id."' and allowance_deduction='".$_REQUEST['allid'][$k]."'
				and all_ded_prefix='".$_REQUEST['prefix1']."'";
				$s->RecordEdit('emp_salary_grade',$dataEmpSal,$condsal12);	}
			else{
				$dataEmpSal['emp_grade_id']=$Lastreq_id;
				$dataEmpSal['allowance_deduction']=$_REQUEST['allid'][$k];
				$dataEmpSal['percentage']=$_REQUEST['aperc'][$k];
				$dataEmpSal['percentage_value']=$_REQUEST['allow'][$k];
				$dataEmpSal['all_ded_prefix']=$_REQUEST['prefix1'];
				$s->RecordInsert('emp_salary_grade',$dataEmpSal);}	

			}

			$chkspid=DB_query("select * from emp_salary_grade where emp_grade_id='".$Lastreq_id."' 
				and allowance_deduction=100 and all_ded_prefix='A'",$db);
			if(DB_num_rows($chkspid)>0)
			{
				$dataspecial1['percentage']='0.00';  
				$dataspecial1['percentage_value']=$_REQUEST['special_allow'];
				$CondSpecial1="emp_grade_id='".$Lastreq_id."' and allowance_deduction=100 and all_ded_prefix='A'";
				$s->RecordEdit('emp_salary_grade',$dataspecial1,$CondSpecial1);
			}
			else
			{
			$dataEmpSpeSal['emp_grade_id']=$Lastreq_id;
			$dataEmpSpeSal['allowance_deduction']='100';
			$dataEmpSpeSal['percentage']='0.00';
			$dataEmpSpeSal['percentage_value']=$_REQUEST['special_allow'];
			$dataEmpSpeSal['all_ded_prefix']='A';
			$s->RecordInsert('emp_salary_grade',$dataEmpSpeSal);			
		   } 
			
		
			
			for($K=1;$K<$_REQUEST['dctr'];$K++)
			{
				$chkDeduct=DB_query("select * from emp_salary_grade where emp_grade_id='".$Lastreq_id."' 
					and allowance_deduction='".$_REQUEST['dedid'][$K]."' and all_ded_prefix='".$_REQUEST['prefix2']."'",$db);	
					if(DB_num_rows($chkDeduct)>0)
					{
						$dataded1['percentage']=$_REQUEST['dperc'][$K];  
						$dataded1['percentage_value']=$_REQUEST['deduction'][$K];
						$CondDed="emp_grade_id='".$Lastreq_id."' and allowance_deduction='".$_REQUEST['dedid'][$K]."'
						and all_ded_prefix='".$_REQUEST['prefix2']."'";
						$s->RecordEdit('emp_salary_grade',$dataded1,$CondDed);
					}
					else
					{
							$dataEmpSalDed['emp_grade_id']=$Lastreq_id; 
							$dataEmpSalDed['allowance_deduction']=$_REQUEST['dedid'][$K];
							$dataEmpSalDed['percentage']=$_REQUEST['dperc'][$K]; 
							$dataEmpSalDed['percentage_value']=$_REQUEST['deduction'][$K]; 
							$dataEmpSalDed['all_ded_prefix']=$_REQUEST['prefix2'];
							$s->RecordInsert('emp_salary_grade',$dataEmpSalDed);
				  }

          }


prnMsg( _('Record Updated Successfully!'),'success');
echo "<script>location.href='index.php?route=HRModule/employee_gradeMaster&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}

if($_REQUEST['action']=='delete' && $_GET['id']!='')
{
 $delete=DB_query("delete from emp_grade_dtls where  emp_grade_id='".$_REQUEST['id']."'",$db); 	
 $delete=DB_query("delete from emp_salary_grade where  emp_grade_id='".$_REQUEST['id']."'",$db);
$update_sql="Delete from emp_grade where id='".$_REQUEST['id']."' ";
$update_res=DB_query($update_sql,$db);

prnMsg( _('Record Deleted Successfully!'),'success');
echo "<script>location.href='index.php?route=HRModule/employee_gradeMaster&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";	
}
?>
 <script type="text/javascript" language="javascript">
function check()
{

	 var code=document.getElementById("code").value;	  
	 if(code=='')
	{alert('Please enter code'); 
	document.getElementById("code").focus();
	return false;}

	if($("#name").val()=='')
	{
		alert("Please Select Grade Name");
		return false;
    }		
	 
	
}
</script>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain" >
<div class="tab_div">
<h1><?php echo $s->getField('modules_form','id',$_REQUEST['frmid'],'frm_name'); ?></h1>
<form action="" method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="3">
  <tr class="row1">
    <td width="12%" align="right">Code</td>
    <td width="30%"><input name="code" type="text" id="code" value="<?php echo $_REQUEST['code'];?>" size="30"  tabindex="1"></td>  
    <td width="20%" align="right">Name</td>
    <td><input name="name" type="text" id="name" value="<?php echo $_REQUEST['name'];?>" size="30"  tabindex="2"></td>
</tr>
<tr class="row1">
<td align="right" valign="top">Designation</td>
<td valign="top"><div style="overflow:auto; width:300px; min-height:50px; max-height:100px;">
	<?php $j=2;
	//echo "select id,designame,status from desigmaster where CompanyId='".$_SESSION['ACGCompanyId']."'";
$sql_des=DB_query("select id,designame,status from desigmaster where CompanyId='".$_SESSION['ACGCompanyId']."'  ",$db);
while($row_des=DB_fetch_array($sql_des))
{	
	$c=''; 
	if(isset($grade_id) && !empty($grade_id) && in_array($row_des['id'],$grade_id) && $row_des['status']==1)
	{
	$c="checked";	
?>
<input tabindex="<?php echo $j; ?>" type="checkbox" style="verticle-align:middle;" name="designation[]" <?php echo $c; ?> value="<?php echo $row_des['id']; ?>"><?php echo $row_des['designame']."<br>"; ?>
<?php } else if($row_des['status']==0) { 
	?>
<input tabindex="<?php echo $j; ?>" type="checkbox" style="verticle-align:middle;" name="designation[]" <?php echo $c; ?> value="<?php echo $row_des['id']; ?>"><?php echo $row_des['designame']."<br>"; ?>
<?php }
 ?>
<?php $j++; } ?>
</div></td>
<td align="right" valign="top">Total</td>	
<td valign="top"><input type="text" id="gross" name="total" value="<?php echo $_REQUEST['total'];?>" size="30"  tabindex="<?php echo $j; ?>" ></td>
</tr>
</table>
<br>
<table width="100%" border="0" cellpadding="3" cellspacing="0">	
	 <tr>
		<td valign="top" width="50%">
		<h3>Allowances Part (A)</h3> <input type="hidden" name="prefix1" id="prefix1" value="A" />
		<table width="100%" border="0" cellpadding="3" cellspacing="0">
		  <tr class="row1">
			<td align="center">Description</td>
			<td width="35%" align="center">%</td>
			<td width="35%" align="center">Value</td>
		  </tr>
		  <tr class="row1">
		  <td align="right">BASIC</td>
		  <td><input type="text" name="basic_perc" id="basic_perc" size="5" value="<?php echo $get_row['basic_perc'] ?>" tabindex="<?php echo $tt=$j+1; ?>"  /></td>
		  <td><input type="text" name="basic_salary" id="basic_salary" value="<?php echo trim($get_row['basic_salary']);?>" size="10" onfocus="calculate_basic()"  class="number"   tabindex="<?php echo $tt=$tt+1; ?>"  /></td>
		  </tr><?php
		  $all_sql=DB_query("Select * from allowmaster",$db); 
		  $i=1;
		 	 while($all_row=DB_fetch_array($all_sql))
		  	 {
		  		
		  		//$tabin=20;
		  		//$tabindex=$tabin+$i;

		  		//echo "<pre>";
		  		//print_r($deduction_type);
		  ?>
		  <tr class="row1">
			<td align="right"><?php echo $all_row['allowname'];?>
			  <input type="hidden" name="allow_code[<?php echo $i;?>]" id="allow_code_<?php echo $i;?>" value="<?php echo $all_row['allowcode'];?>" />
			  <input type="hidden" name="allid[<?php echo $i;?>]" id="allid_<?php echo $i;?>" value="<?php echo $all_row['id'];?>" />
			  </td>
			<td><input name="aperc[<?php echo $i;?>]" type="text" id="aperc_<?php echo $i;?>" value="<?php if(!empty($deduction_type)) echo $deduction_type[$all_row['id']][A]['percentage'];?>" size="5" tabindex="<?php echo (2*($tt+1));?>" onkeyup="cal_allvalue(this.value,<?php echo $i;?>);"  onblur="cal_allvalue(this.value,<?php echo $i;?>);"  /></td>
			<td><input name="allow[<?php echo $i;?>]" type="text" id="allow_<?php echo $i;?>" value="<?php if(!empty($deduction_type)) echo $deduction_type[$all_row['id']][A]['percentage_value'];?>" size="10" class="number" tabindex="<?php echo $j1=(2+(2*$tt));?>"  /></td>
			<!--onfocus="reversecal_allvalue(this.value,<?php //echo $i; ?>)" -->
		  </tr>
		  <?php $i++;} ?>
		  <input type="hidden" name="ctr" id="ctr" value="<?php echo $i;?>" />
		 <tr class="row1">
		 <td align="right">Special Allowance</td>
		 <td><input name="spc_allow" type="text" id="spc_allow" value="<?php if(!empty($deduction_type)) echo $deduction_type[100][A]['percentage'];?>" size="5" onblur="cal_special_allow()" tabindex="<?php echo ($j1+1);?>"  /></td>
		  <td><input type="text" name="special_allow" id="special_allow" value="<?php if(!empty($deduction_type)) { if(isset($deduction_type[100][A]['percentage_value'])){echo $deduction_type[100][A]['percentage_value'];} } else{ echo '0';} ?>" size="10"  tabindex="<?php echo $cj=($j1+2);?>" class="number"  /></td>
		 </tr>
		  <tr class="row1">
		 <td align="right">Gross Salary<font color="#FF0000" size="-1">*</font></td>
		 <td colspan="2"><input name="allow_tot" type="text" id="allow_tot" value="<?php echo $get_row['allow_tot'] ?>" onfocus="cal_alltot();cal_esi(this.value);data_str(this.value);" readonly="true" style="width:99%;" class="number" tabindex="<?php echo $mc=($cj+1); ?>"/></td>
		 </tr>		
		</table>
		</td>
		<td valign="top">
			<h3>Deduction(D)</h3> <input type="hidden" name="prefix2" id="prefix2" value="D" />
		<table width="100%" border="0" cellpadding="3" cellspacing="0">
		  <tr class="row1">
			<td align="center">Description</td>
			<td width="35%" align="center">%</td>
			<td width="35%" align="center">Value</td>
		 </tr>
		 <?php
		  $ded_sql=DB_query("Select * from deduction_master",$db); 
		 $j=1;
		  while($ded_row=DB_fetch_array($ded_sql))
		  {
		  ?>
	<tr class="row1">
			<td align="right"><?php echo $ded_row['name'];?>
			<input name="empdedtype[<?php echo $j;?>]"  id="empdedtype_<?php echo $j;?>" type="hidden" value="<?php  echo $ded_row['code'];?>" />
	
	   <input type="hidden" name="ded_code[<?php echo $j;?>]" id="ded_code_<?php echo $j;?>" value="<?php echo $ded_row['code'];?>" />
		<input type="hidden" name="dedid[<?php echo $j;?>]" id="dedid_<?php echo $j;?>" value="<?php echo $ded_row['id'];?>" />	  
			  </td> 
           <?php if($ded_row['code']!='Coupon'){ ?>
           <td><input name="dperc[<?php echo $j;?>]" type="text" id="dperc_<?php echo $j;?>" value="<?php if(!empty($deduction_type)) echo $deduction_type[$ded_row['id']][D]['percentage'];?>" size="5" onkeyup="cal_dedvalue(this.value,this.id,<?php echo $j;?>)" class="number" tabindex="<?php echo ($mc+$j);?>"  /></td><?php } ?>
			<td><input name="deduction[<?php echo $j;?>]" type="text" id="deduction_<?php echo $j;?>"
			 value="<?php if(!empty($deduction_type)) echo $deduction_type[$ded_row['id']][D]['percentage_value'];?>" size="10" class="number" tabindex="<?php echo $mc1= ($mc+$j+1);?>"  /></td>
		  </tr>
		  <?php $j++;} ?>
		  <input type="hidden" name="dctr" id="dctr" value="<?php echo $j;?>" />
		  <tr class="row1">
		 <td align="right">Total Deduction</td>
		 <td colspan="2"><input name="deduct_tot" type="text" id="deduct_tot" value="<?php echo $get_row['deduct_tot'] ?>" onfocus="cal_dedtot()" readonly="true" style="width:99%;" class="number"  tabindex="<?php echo $mc1; ?>" /></td>
		 </tr>
		</table>		
		</td>
	 </tr>	
	</table>
	<p align="center">
<?php if($_GET['action']=='edit'){?>
<input type="submit" value="Update" class="search" name="Update" <?php if($_SESSION['frmEdit']=='0'){?>disabled<?php } ?>>
<input type="hidden" name="row_id" value="<?php echo $_GET['id'];?>" id="row_id">
<?php } else {?>
<input type="submit" value="Submit" class="search" name="Submit" onclick="return check();" <?php if($_SESSION['frmcreate']=='0'){?>disabled<?php } ?>>
<?php }?>
</p>

</form>
<br>
<?php 
$grade_sql=DB_query("Select * from emp_grade",$db);
?>
<table width="100%" border="0" cellspacing="0" cellpadding="3" class="thborder">
<tr>
	<th width="20%" rowspan="2">Grade Code</th>
	<th rowspan="2">Grade Name</th>
	<th colspan="2" style="text-align:center;">Action</th>
</tr>
<tr>
	<th width="6%" style="text-align:center;">Edit</th>
	<th width="6%" style="text-align:center;">Delete</th>
</tr>
<?php
if(DB_num_rows($grade_sql)>0){
while($grade_row=DB_fetch_array($grade_sql))
{ 
?>
<tr>
<td><?php echo $grade_row['grade_code'];?></td>
<td><?php echo $grade_row['grade_name'];?></td>
<td align="center"><?php if($_SESSION['frmEdit']=='1'){?><a href="index.php?route=HRModule/employee_gradeMaster&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&id=<?php echo $grade_row['id'];?>&action=edit"><img src="images/icon-edit.png" height="15" width="15" title="Edit Document" /></a><?php } else{ ?><img src="images/icon-edit.png" height="15" width="15" style="opacity:0.6;" title="No Permission to Edit Document" /><?php } ?></td>
<td align="center"><?php if($_SESSION['frmDelete']=='1'){?>
<a href="index.php?route=HRModule/employee_gradeMaster&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&id=<?php echo $grade_row['id'];?>&action=delete" onClick="return confirm('Are you sure you want to delete this record?')"><img src="images/Icon_Delete.png" height="14" width="14" title="Delete Document" /></a><?php } else{ ?><img src="images/Icon_Delete.png" height="14" width="14" style="opacity:0.6;" title="No Permission to Delete Document" /><?php } ?></td>
</tr>
<?php } }
else
{?>
<tr>
<td colspan="4" align="center"><font color="#FF0000">NO RECORD FOUND!</font></td>
</tr>
<?php 
}?>
</table>
<script type="text/javascript">
function cal_allvalue(str,j)
{
//alert(j);
	var basic=document.getElementById("basic_salary").value;
	var totvalue=Math.round((basic*str)/100);
	document.getElementById("allow_"+j).value=Math.round(totvalue);
}
function calculate_basic()
{
	var gross=document.getElementById("gross").value;
	var basic_perc=document.getElementById("basic_perc").value;
	if(gross==''){gross=0;}
	if(basic_perc==''){basic_perc=0;}
	
	var totalbasic=gross*((basic_perc)/100);
	//alert(totalbasic);
	document.getElementById("basic_salary").value=Math.round(totalbasic);
	cal_alltot();
	
}

function cal_alltot()
{
	var Basic_SAL=document.getElementById("basic_salary").value;
	var total_allowance=0;
	var count = document.getElementById("ctr").value;
	
	var sa = document.getElementById("special_allow").value;
	if(sa=='') { sa=0; }
	for(var j=1;j<count;j++)
	{
	   if(document.getElementById("allow_"+j).value!='')
		var allowance = document.getElementById("allow_"+j).value;
		else 
		allowance=0;
		total_allowance=parseFloat(total_allowance)+parseFloat(allowance);
	}
	//var pf_Reimbursement=document.getElementById("pf_Reimbursement").value;
	//var medical_Reimbursement=document.getElementById("medical_Reimbursement").value;
	//document.getElementById("allow_tot").value=(parseFloat(total_allowance)+parseFloat(Basic_SAL)+parseFloat(pf_Reimbursement)+parseFloat(medical_Reimbursement)).toFixed(2);
	
	document.getElementById("allow_tot").value=Math.round((parseFloat(total_allowance)+parseFloat(Basic_SAL)+parseFloat(sa)));
	
	var g=parseFloat(document.getElementById("gross").value);
	var totalallowance=parseFloat(total_allowance)+parseFloat(Basic_SAL)+parseFloat(sa);
	//if(totalallowance<g)
//	{
//		alert("The TOTAL ALLOWANCE is less than the GROSS SALARY. Please re-enter the values to make them equal");
//	}
	if(totalallowance>g)
	{
		alert("The TOTAL ALLOWANCE is more than the GROSS SALARY. Please re-enter the values to make them equal");
	}
}

function cal_special_allow()
{
	var g=parseFloat(document.getElementById("gross").value);
	var Basic_SAL=document.getElementById("basic_salary").value;
	var total_allowance=0;
	var count = document.getElementById("ctr").value;
	for(var k=1;k<count;k++)
	{
		var allowance = document.getElementById("allow_"+k).value;
		total_allowance=parseFloat(total_allowance)+parseFloat(allowance);
	}
	
	var LTA=0;
	var LWF=0;
	if(LTA==''){LTA=0;}
	if(LWF==''){LWF=0;}
	var allow_basic1=(parseFloat(total_allowance)+parseFloat(Basic_SAL)+parseFloat(LTA)+parseFloat(LWF));
	var allow_basic2=g-allow_basic1;
	if(allow_basic2<0){allow_basic2=0.00;}
	document.getElementById("special_allow").value=Math.round(allow_basic2);
}

function cal_esi(str1)
{
	var gross_sal = str1;
	if(gross_sal>=0 && gross_sal<=15000)
	{
		var net_esi = ((4.75*(str1))/100);
		document.getElementById("esimployervalue").value=Math.round(net_esi);
		document.getElementById("ESIemployer").value="4.75";
		document.getElementById("esimployervalue").removeAttribute("readonly"); 
		document.getElementById("ESIemployer").removeAttribute("readonly"); 
		
	}
	else
	{
		document.getElementById("esimployervalue").value="0";
		document.getElementById("ESIemployer").value="0";
		document.getElementById("esimployervalue").setAttribute("readonly",true);
		document.getElementById("ESIemployer").setAttribute("readonly",true);
	}
}

function cal_dedvalue(str,esi_id,j)
{
	
 a=document.getElementById("empdedtype_"+j).value;
 //alert(a);
 var basic=document.getElementById("basic_salary").value;
 var grosssal=document.getElementById("allow_tot").value;
 //alert(grosssal);
 if(a=='PF')
 {
 	if(basic > 6501)
 	{
 		var basic=6500;
		var totvalue=basic*((str)/100);
		document.getElementById("deduction_"+j).value=Math.round(totvalue);
	}
	else
	{
		var basic=document.getElementById("basic_salary").value;
		var totvalue=basic*((str)/100);
		document.getElementById("deduction_"+j).value=Math.round(totvalue);
	}
 
 }	
 else if(a=='ESI')
 {
 	if(grosssal<15001)
	{
		//document.getElementById("esi_id").value='1.75';
		if (window.XMLHttpRequest)
		{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
		}
		else
		{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange=function()
		{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			var data=xmlhttp.responseText.split("__");
			document.getElementById("dperc_"+j).value=data[0];
			document.getElementById("deduction_"+j).value=Math.round(data[1]);
		}
		}
		
		//varsiteid=document.getElementById("emp_site").value;
		xmlhttp.open("GET","ajax_getesi2.php?str="+grosssal,true);
		xmlhttp.send();
	}
	else
	{
		document.getElementById("deduction_"+j).value='0.00';
	}
 }
 else
 {
 	var basic=document.getElementById("gross").value;
	var totvalue=basic*((str)/100);
	document.getElementById("deduction_"+j).value=Math.round(totvalue);
 }
 
}

	
function data_str(str1)
{
var gross_sal = str1;

   var t='';
		var count1=document.getElementById("dctr").value;	
			
		for(var i=1;i<count1;i++)
		{		
		if(document.getElementById("empdedtype_"+i).value=='ESI')
		{
		t=i;
		if (window.XMLHttpRequest)
		{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
		}
		else
		{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange=function()
		{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{		
		
		    var data=xmlhttp.responseText.split("__");
			if(data[0]==0)
			{
			document.getElementById("dperc_"+t).value=data[0];		
			document.getElementById("deduction_"+t).value=Math.round(data[1]);
			document.getElementById("dperc_"+t).setAttribute("readonly",true); 
		    document.getElementById("deduction_"+t).setAttribute("readonly",true);
			}
			else
			{
		   	document.getElementById("dperc_"+t).value=data[0];		
			document.getElementById("deduction_"+t).value=data[1];
			document.getElementById("dperc_"+t).removeAttribute("readonly"); 
		    document.getElementById("deduction_"+t).removeAttribute("readonly"); 
			}
		}
		}
		//var varsiteid=document.getElementById("emp_site").value;
		xmlhttp.open("GET","ajax_getesi1.php?str="+str1,true);
		xmlhttp.send();
	
	}	
		}
		
		
		

		
}

function calltaAll(val)
{
	if(val!='')
	{
	var Basic_SAL=document.getElementById("basic_salary").value;
	var ltaamt=(Basic_SAL*val)/100;
	document.getElementById("lta").value=Math.round(ltaamt);
	}
	else
	{
		document.getElementById("lta").value='0';
	}
}


function calLWFAll(val)
{
	if(val!='')
	{
	var Basic_SAL=document.getElementById("basic_salary").value;
	var ltaamt=(Basic_SAL*val)/100;
	document.getElementById("LWF").value=Math.round(ltaamt);
	}
	else
	{
		document.getElementById("LWF").value='0';
	}
}


function calmothellysal()
{
	var g=parseFloat(document.getElementById("gross").value);
	var sa = document.getElementById("special_allow").value;
	var Basic_SAL=document.getElementById("basic_salary").value;
	var total_allowance=0;
	var count = document.getElementById("ctr").value;
	for(var j=1;j<count;j++)
	{
	    if(document.getElementById("allow_"+j).value!='')
		var allowance = document.getElementById("allow_"+j).value;
		else
		allowance=0;
		total_allowance=parseFloat(total_allowance)+parseFloat(allowance);
	}
	var LTA=document.getElementById("lta").value;
	var LWF=document.getElementById("LWF").value;
	var ESI_employer_value=document.getElementById("esimployervalue").value;
	//alert(ESI_employer_value);
	
	if(g=='') { g=0;}
	if(sa=='') { sa=0;}
	if(Basic_SAL=='') { Basic_SAL=0;}
	if(LTA=='') { LTA=0;}
	if(LWF=='') { LWF=0;}
	if(ESI_employer_value=='') { ESI_employer_value=0;}
	var mothellyctc=parseFloat(total_allowance)+parseFloat(LTA)+parseFloat(LWF)+parseFloat(sa)+parseFloat(Basic_SAL)+parseFloat(ESI_employer_value);
	document.getElementById("monthelyctc1").value=Math.round(mothellyctc);
	
	if(mothellyctc!=g)
	{
		alert("Monthelly CTC Must Be Equal");
		return false;
	}
	
}

function calculate_esi(esi_percentage)
{
	var gross_sal = document.getElementById("allow_tot").value;
	var net_esi = ((esi_percentage*gross_sal)/100);
	document.getElementById("esimployervalue").value=Math.round(net_esi);	
}

function cal_dedtot()
{
	 var gr=document.getElementById("gross").value;
	var tot_deduction=0;
	var count=document.getElementById("dctr").value;
	for(var j=1;j<count;j++)
	{
		var deduction = document.getElementById("deduction_"+j).value;
		if(isNaN(deduction)) deduction=0;
		if(deduction=='') deduction=0;
		
		tot_deduction=parseFloat(tot_deduction)+parseFloat(deduction);
	}
	// if(isNaN(tot_deduction)) tot_deduction=0;
	document.getElementById("deduct_tot").value=Math.round(tot_deduction);
	cal_alltot();
}

function cal_gross()
{
	document.getElementById("gross_sal").value=document.getElementById("allow_tot").value;
}
function cal_net()
{
	var gsal=document.getElementById("gross_sal").value;
	var deduct=document.getElementById("deduct_tot").value;
	if(gsal=='') { gsal=0; } if(deduct=='') { deduct=0; } 
	var net=parseFloat(gsal)-parseFloat(deduct);
	document.getElementById("net_sal").value=Math.round(net);
}



	

</script>
