<?php $PageSecurity = 3;
$table_name='empmaster';
  global $db; 
 
 if($_REQUEST['Process'])
 {
 
 	for($acr1=1;$acr1<$_REQUEST['ctr'];$acr1++)
	{
	//echo "<br>--------------------------emp_salary allowance---------------------------<br>";

		$update_sal_sql1=" Update emp_salary SET 
									percentage='".$_REQUEST['rev_aperc'][$acr1]."',  
									percentage_value ='".$_REQUEST['rev_allow'][$acr1]."'
									where emp_id='".$_REQUEST['empid']."' and allowance_deduction='".$_REQUEST['rev_allid'][$acr1]."'
									and all_ded_prefix='".$_REQUEST['rev_prefix1']."'";
		$update_sal1=DB_query($update_sal_sql1,$db);
	}
	for($acr2=1;$acr2<$_REQUEST['ctr'];$acr2++)
	{
		//echo "<br>--------------------emp_salary deduction-----------------------------<br>";

	 	$update_sal_sql2=" Update emp_salary SET 
									percentage='".$_REQUEST['rev_dperc'][$acr2]."',  
									percentage_value ='".$_REQUEST['rev_deduction'][$acr2]."'
									where emp_id='".$_REQUEST['empid']."' and allowance_deduction='".$_REQUEST['rev_dedid'][$acr2]."'
									and all_ded_prefix='".$_REQUEST['rev_prefix2']."'";
		$update_sal2=DB_query($update_sal_sql2,$db);
	}
	//echo "<br>---------------------empmaster updates----------------------------------<br>";
	
	   $update_sql = "Update empmaster SET
		   basic_salary='".$_REQUEST['rev_basic_salary']."',
			allow_tot='".$_REQUEST['rev_allow_tot']."',
			deduct_tot='".$_REQUEST['rev_deduct_tot']."',
			gross_sal='".$_REQUEST['rev_allow_tot']."',
 			net_sal='".($_REQUEST['rev_allow_tot']-$_REQUEST['rev_deduct_tot'])."' where id='".$_REQUEST['empid']."' "; 
		$update = DB_query($update_sql,$db); 
			

//echo "<br>-------------------empmaster_revised_sal------------------------------------<br>";
			
   	    $update_revrecord = "Update empmaster_revised_sal SET
		   locked='Y',
			modified_date='".date('Y-m-d')."' where id='".$_REQUEST['id']."'";
 	  $RecordUpdated = DB_query($update_revrecord,$db); 

		
$data_arr['empid']=$_REQUEST['empid'];
$data_arr['basic_salary']=$_REQUEST['basic_salary'];
$data_arr['allow_tot']=$_REQUEST['allow_tot'];
$data_arr['deduct_tot']=$_REQUEST['deduct_tot'];
$data_arr['gross_sal']=$_REQUEST['allow_tot'];
$data_arr['applicable_month']=$_REQUEST['applicable_month'];
$data_arr['increment_type']=$_REQUEST['increment_type'];
$data_arr['applicable_year']=$_REQUEST['applicable_year'];
$data_arr['increment_amount']=$_REQUEST['increment_amount'];
$data_arr['net_sal']=($_REQUEST['allow_tot']-$_REQUEST['deduct_tot']);
$data_arr['log_type']='org';
$sal_resultLog=$s->RecordInsert('LogReport_empmaster_revised_sal', $data_arr);
	$getlastid=DB_Last_Insert_ID($db,'LogReport_empmaster_revised_sal', 'id');
 		for($k=1;$k<$_REQUEST['ctr'];$k++)
			{
			
			$data1['emp_id']=$_REQUEST['empid'];
			$data1['mst_revid']=$getlastid;
			$data1['allowance_deduction']=$_REQUEST['allid'][$k];
			$data1['percentage']=$_REQUEST['aperc'][$k];
			$data1['percentage_value']=$_REQUEST['allow'][$k];
			$data1['posted_date']=date('Y-m-d');
			$data1['all_ded_prefix']=$_REQUEST['prefix1'];
				$LogReport=$s->RecordInsert('LogReport_empmaster_revi_sal_allowances', $data1);
			}
			for($K=1;$K<$_REQUEST['dctr'];$K++)
			{
				$data['emp_id']=$_REQUEST['empid'];
				$data['mst_revid']=$getlastid;
				$data['allowance_deduction']=$_REQUEST['dedid'][$K];
				$data['percentage']=$_REQUEST['dperc'][$K];
				$data['percentage_value']=$_REQUEST['deduction'][$K];
				$data['posted_date']=date('Y-m-d');
				$data['all_ded_prefix']=$_REQUEST['prefix2'];
				$LogReport=$s->RecordInsert('LogReport_empmaster_revi_sal_allowances', $data);
			}
			
 		 prnMsg( _('Employee Salary Processes Successfully'));
		 $s->pageLocation($target);

 }
 
 
    $condition="id='".$_GET['empid']."'";
	$result=$s->GetRecordById($table_name,  $condition);
	$get_row1=DB_fetch_array($result);
	$basic_perc=$get_row1['basic_perc'];
	$basic_salary=$get_row1['basic_salary'];
	$allow_tot=$get_row1['allow_tot'];
	$deduct_tot=$get_row1['deduct_tot'];
	$gross_sal=$get_row1['gross_sal'];
	$net_sal=$get_row1['net_sal'];
	$get_sql3=DB_query("Select * from emp_salary where emp_id='".$_GET['empid']."' and all_ded_prefix='A'",$db);
	$k=1;
	while($get_row3=DB_fetch_array($get_sql3))
	{
		$aperc[$k]=$get_row3['percentage'];  
		$allow[$k]=$get_row3['percentage_value'];
		$k++;
	}
	
	$get_sql4=DB_query("Select * from emp_salary where emp_id='".$_GET['empid']."' and all_ded_prefix='D'",$db);
	$K=1;
	while($get_row4=DB_fetch_array($get_sql4))
	{
		$dperc[$K]=$get_row4['percentage'];  
		$deduction[$K]=$get_row4['percentage_value'];
		$K++;
	}
	
//********Revished salary************************************************************
	 $condition="id='".$_REQUEST['id']."'";
	$result_rev=$s->GetRecordById('empmaster_revised_sal',  $condition);
	$get_row_rev=DB_fetch_array($result_rev);
	$rev_basic_perc=$get_row_rev['basic_perc'];
	$rev_basic_salary=$get_row_rev['basic_salary'];
	$rev_allow_tot=$get_row_rev['allow_tot'];
	$rev_deduct_tot=$get_row_rev['deduct_tot'];
	$rev_gross_sal=$get_row_rev['gross_sal'];
	$rev_net_sal=$get_row_rev['net_sal'];
	$increment_type=$get_row_rev['increment_type'];
	$applicable_month=$get_row_rev['applicable_month'];
 	$increment_amount=$get_row_rev['increment_amount'];
 	$applicable_year=$get_row_rev['applicable_year'];
	  $locked=$get_row_rev['locked'];
	
	//echo "Select * from empmaster_revi_sal_allowances where mst_revid='".$_REQUEST['id']."' and all_ded_prefix='A'";
  $get_sql_rev=DB_query("Select * from empmaster_revi_sal_allowances where mst_revid='".$_REQUEST['id']."' and all_ded_prefix='A'",$db);
	$k=1;
	while($get_row_rev=DB_fetch_array($get_sql_rev))
	{
		$rev_aperc[$k]=$get_row_rev['percentage'];  
		$rev_allow[$k]=$get_row_rev['percentage_value'];
		$k++;
	}
	
	$get_sql_drev=DB_query("Select * from empmaster_revi_sal_allowances where mst_revid='".$_REQUEST['id']."' and all_ded_prefix='D'",$db);
	$K=1;
	while($get_rowdrev=DB_fetch_array($get_sql_drev))
	{
		$rev_dperc[$K]=$get_rowdrev['percentage'];  
		$rev_deduction[$K]=$get_rowdrev['percentage_value'];
		$K++;
	}

	
 

 ?>
<h3 align="left">Salary Details</h3>
<form action="" method="post">
 <div>
 <table width="100%" border="0">
  <tr>
    <td> 
<h4 align="center">Old salary</h4>
<table width="100%" border="0" cellspacing="1" cellpadding="2">
  <tr>
    <td valign="top"><table width="100%" border="0" cellspacing="1" cellpadding="2">
      <tr>
        <th colspan="3"><div align="center"><strong>ALLOWANCES</strong> <strong>(A) </strong></div><input type="hidden" name="prefix1" id="prefix1" value="A" /></th>
      </tr>
      <tr>
        <th><strong>DESCRIPTION</strong></th>
        <!--<th><strong>%</strong></th>-->
        <th><strong>VALUE</strong></th>
      </tr>
	  <tr>
	  <th><strong>BASIC</strong></th>
	  <!--<td><input type="text" name="basic_perc" id="basic_perc" value="<?php //echo $basic_perc;?>" size="5" onblur="calculate_basic(this.value)" tabindex="41"/></td>-->
	  <td><input type="text" name="basic_salary" id="basic_salary" value="<?php echo trim($basic_salary);?>" size="10"  class="number" tabindex="42" readonly="true"/></td>
	  </tr>
      <?php
	  $all_sql=DB_query("Select * from allowmaster",$db); 
	 $i=1;
	  while($all_row=DB_fetch_array($all_sql))
	  {
	  ?>
	  <tr>
        <th><strong><?php echo $all_row['allowcode'];?></strong>
          <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'];?>" />		  </th>
<!--<td><input name="aperc[<?php //echo $i;?>]" type="text" id="aperc_<?php //echo $i;?>" value="<?php //echo $aperc[$i];?>" size="5" onblur="cal_allvalue(this.value,<?php //echo $i;?>)" tabindex="42+<?php //echo (2*$i);?>"/></td>-->
        <td><input name="allow[<?php echo $i;?>]" type="text" id="allow_<?php echo $i;?>" value="<?php echo $allow[$i];?>" size="10" class="number" tabindex="42+<?php echo $i;?>" readonly="true"/></td>
      </tr>
	  <?php $i++;} ?>
	  <input type="hidden" name="ctr" id="ctr" value="<?php echo $i;?>" />
	 <tr>
	 <th><strong>TOTAL  </strong></th>
	 <td colspan="2"><input name="allow_tot" type="text" id="allow_tot" value="<?php echo $allow_tot;?>" size="15"   readonly="true" tabindex="47"/></td>
	 </tr>
    </table></td>
    <td><table width="100%" border="0" cellspacing="1" cellpadding="2">
      <tr>
        <th colspan="3"><strong>DEDUCTION(D)</strong><input type="hidden" name="prefix2" id="prefix2" value="D" /></th>
      </tr>
      <tr>
        <th><strong>DESCRIPTION</strong></th>
        <th><strong>%</strong></th>
        <th><strong>VALUE</strong></th>
      </tr>
     <?php
	  $ded_sql=DB_query("Select * from deduction_master",$db); 
	 $j=1;
	  while($ded_row=DB_fetch_array($ded_sql))
	  {
	  ?>
	  <tr>
        <th><strong><?php echo $ded_row['name'];?>
		<input name="empdedtype[<?php echo $j;?>]"  id="empdedtype_<?php echo $j;?>" type="hidden" value="<?php echo $ded_row['name'];?>" />
		
		
		
		</strong>
		<?php 
		if($ded_row['code']=='TDS')
		{$r='';}
		else{$r="readonly";}
		?>
          <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'];?>" />		  </th>
<td><input name="dperc[<?php echo $j;?>]" type="text" id="dperc_<?php echo $j;?>" value="<?php echo $dperc[$j];?>" size="5" onblur="cal_dedvalue(this.value,<?php echo $j;?>)" class="number"/></td>
        <td><input name="deduction[<?php echo $j;?>]" type="text" id="deduction_<?php echo $j;?>" value="<?php echo $deduction[$j];?>" size="10" class="number" <?php echo $r;?>/></td>
      </tr>
	  <?php $j++;} ?>
	  <input type="hidden" name="dctr" id="dctr" value="<?php echo $j;?>" />
	  <tr>
	 <th><strong>TOTAL  </strong></th>
	 <td colspan="2"><input name="deduct_tot" type="text" id="deduct_tot" value="<?php echo $deduct_tot;?>" size="15"  readonly="true"/></td>
	 </tr>
	  <tr>
	    <th>Net&nbsp;</th>
	    <td colspan="2"><input name="net_sal" type="text" id="net_sal" value="<?php echo $allow_tot-$deduct_tot;?>" size="15"  readonly="true"/></td>
	    </tr>
    </table></td>
  </tr>
  
  
</table>
 </td>
    <td> 
<h4 align="center">Revised Salary</h4>

<table width="100%" border="0" cellspacing="1" cellpadding="2">
  <tr>
    <td valign="top"><table width="100%" border="0" cellspacing="1" cellpadding="2">
      <tr>
        <th colspan="3"><div align="center"><strong>ALLOWANCES</strong> <strong>(A) </strong></div><input type="hidden" name="rev_prefix1" id="rev_prefix1" value="A" /></th>
      </tr>
      <tr>
        <th><strong>DESCRIPTION</strong></th>
        <!--<th><strong>%</strong></th>-->
        <th><strong>VALUE</strong></th>
      </tr>
	  <tr>
	  <th><strong>BASIC</strong></th>
	  <!--<td><input type="text" name="basic_perc" id="basic_perc" value="<?php //echo $basic_perc;?>" size="5" onblur="calculate_basic(this.value)" tabindex="41"/></td>-->
	  <td><input type="text" name="rev_basic_salary" id="rev_basic_salary" value="<?php echo trim($rev_basic_salary);?>" size="10"  class="number" tabindex="42"/></td>
	  </tr>
      <?php
	  $all_sql=DB_query("Select * from allowmaster",$db); 
	 $i=1;
	  while($all_row=DB_fetch_array($all_sql))
	  {
	  ?>
	  <tr>
        <th><strong><?php echo $all_row['allowcode'];?></strong>
          <input type="hidden" name="rev_allow_code[<?php echo $i;?>]" id="rev_allow_code_<?php echo $i;?>" value="<?php echo $all_row['allowcode'];?>" />
		  <input type="hidden" name="rev_allid[<?php echo $i;?>]" id="rev_allid_<?php echo $i;?>" value="<?php echo $all_row['id'];?>" />		  </th>
<!--<td><input name="aperc[<?php //echo $i;?>]" type="text" id="aperc_<?php //echo $i;?>" value="<?php //echo $aperc[$i];?>" size="5" onblur="cal_allvalue(this.value,<?php //echo $i;?>)" tabindex="42+<?php //echo (2*$i);?>"/></td>-->
        <td><input name="rev_allow[<?php echo $i;?>]" type="text" id="rev_allow_<?php echo $i;?>" value="<?php echo $rev_allow[$i];?>" size="10" class="number" tabindex="42+<?php echo $i;?>"/></td>
      </tr>
	  <?php $i++;} ?>
	  <input type="hidden" name="ctr" id="ctr" value="<?php echo $i;?>" />
	 <tr>
	 <th><strong>TOTAL  </strong></th>
	 <td colspan="2"><input name="rev_allow_tot" type="text" id="rev_allow_tot" value="<?php echo $rev_allow_tot;?>" size="15" onfocus="cal_alltot()"   tabindex="47"/></td>
	 </tr>
    </table></td>
    <td><table width="100%" border="0" cellspacing="1" cellpadding="2">
      <tr>
        <th colspan="3"><strong>DEDUCTION(D)</strong><input type="hidden" name="rev_prefix2" id="rev_prefix2" value="D" /></th>
      </tr>
      <tr>
        <th><strong>DESCRIPTION</strong></th>
        <th><strong>%</strong></th>
        <th><strong>VALUE</strong></th>
      </tr>
     <?php
	  $ded_sql=DB_query("Select * from deduction_master",$db); 
	 $j=1;
	  while($ded_row=DB_fetch_array($ded_sql))
	  {
	  ?>
	  <tr>
        <th><strong><?php echo $ded_row['name'];?>
		<input name="rev_empdedtype[<?php echo $j;?>]"  id="rev_empdedtype_<?php echo $j;?>" type="hidden" value="<?php echo $ded_row['name'];?>" />
		
		
		
		</strong>
		<?php 
		if($ded_row['code']=='TDS')
		{$r='';}
		else{$r="readonly";}
		?>
          <input type="hidden" name="rev_ded_code[<?php echo $j;?>]" id="rev_ded_code_<?php echo $j;?>" value="<?php echo $ded_row['code'];?>" />
	<input type="hidden" name="rev_dedid[<?php echo $j;?>]" id="rev_dedid_<?php echo $j;?>" value="<?php echo $ded_row['id'];?>" />		  </th>
<td><input name="rev_dperc[<?php echo $j;?>]" type="text" id="rev_dperc_<?php echo $j;?>" value="<?php echo $rev_dperc[$j];?>" size="5" onblur="cal_dedvalue(this.value,<?php echo $j;?>)" class="number"/></td>
        <td><input name="rev_deduction[<?php echo $j;?>]" type="text" id="rev_deduction_<?php echo $j;?>" value="<?php echo $rev_deduction[$j];?>" size="10" class="number" <?php echo $r;?>/></td>
      </tr>
	  <?php $j++;} ?>
	  <input type="hidden" name="rev_dctr" id="rev_dctr" value="<?php echo $j;?>" />
	  <tr>
	 <th><strong>TOTAL  </strong></th>
	 <td colspan="2"><input name="rev_deduct_tot" type="text" id="rev_deduct_tot" value="<?php echo $rev_deduct_tot;?>" size="15" onfocus="cal_dedtot()" /></td>
	 </tr>
	 
	 
	  <tr>
	    <th>Net Rev Sal</th>
	    <td colspan="2"><input name="rev_net_sal" type="text" id="rev_net_sal" value="<?php echo $rev_net_sal;?>" size="15"  readonly="true" onfocus="cal_rev_net_sal()"/></td>
	    </tr>
    </table></td>
  </tr>
  
  
</table>
    </td>
  </tr>
</table>




<div style="clear:both; margin:0px;"></div>
</div><!-- Table close 2 -->

<!-- Table close 3 --><div>


<table width="90%" border="0" cellspacing="1" cellpadding="2" align="left">
  <tr>
    <th>Applicable From Month</th>
	<td>
	<select name="applicable_month"  style="width:100%">
          <?php
 $arr=array(1=>"Jan","Feb","Mar","Apr","May","June","July","Aug","Sept","Oct","Nov","Dec");
 foreach ($arr as $key => $value) {
 	$p='';
 	if( $key==$applicable_month)
	$p='selected';
   ?>
          <option value="<?php echo $key;?>" <?php echo $p;?> ><?php echo $value;?></option>
          <?php } ?>
        </select>
		 
	</td>
	
	 
	<td>
	 
		<select name="applicable_year"  style="width:100%">
          <?php
 
 for($i=date('Y');$i>2000;$i--)
 {
 	$p='';
 	if( $i==$applicable_year)
	$p='selected';
 ?>
          <option value="<?php echo $i;?>" <?php echo $p;?>><?php echo $i;?></option>
          <?php 
 }
 ?>
        </select>
	</td>
    <th>Increment Type</th>
	
	<td>
	 
	<select style="width:auto;" name="increment_type">
		<option value="Annual" <?php echo  $increment_type=='Annual'?'selected':''; ?>>Annual</option>
		<option value="Promotional" <?php echo  $increment_type=='Promotional'?'selected':''; ?>>Promotional</option>
		<option value="other" <?php echo  $increment_type=='Other'?'selected':''; ?>>Other</option>
			</select>
	</td>
	<th>Increment Amount</th>
	<td><input type="text" style="width:auto;"  name="increment_amount" id='increment_amount'  value="<?php echo $increment_amount;?>" onfocus="cal_increment_amount()"/></td>
	</tr>
</table>
</div><!-- Table close 3 -->

<?php if(  $locked!='Y'){?>
<div style="width:200px; margin-left:auto; margin-right:auto;">
 	<input type="submit" value="Process"  name="Process"/> 
 </div>
<?php } ?>

</form>
 