<?php include('includes/fun-php.php');?>
<fieldset>
<legend>Full Final Settlement</legend>
<form action="" method="post">
<table width="100%%" border="0" cellspacing="1" cellpadding="2" align="left">
  <tr>
    <td>Branch</td>
    <td>  <select name="site" id="site" style="width:107px" onchange="ShowDiv(this.value,'hid-empdiv','GetEmployee.php?sheet_type=fullfinalsettlemet');">
          <option value="000">---ALL---</option>
          <?php 
  $site_sql=DB_query("Select loccode, locationname from locations",$db); 
while($site_row=DB_fetch_array($site_sql)){
?>
          <option value="<?php echo $site_row['loccode'];?>"<?php echo ($_REQUEST['site']==$site_row['loccode']?'selected':'');?>><?php echo $site_row['locationname'];?></option>
          <?php } ?>
        </select>	</td>
    <td>Employee Name</td>
     <td><div id='hid-empdiv'><select name="empcode" id="empcode" style="width:107px" onchange="ShowDiv(this.value,'hid_revised','revised_salary.php')">
          <option value="All">--All--</option>
          <?php 
		$emp_sql=DB_query("Select id, emp_code,emp_name from empmaster order by emp_name ASC",$db);
		while($emp_row=DB_fetch_array($emp_sql))
		{?>
          <option value="<?php echo $emp_row['id'];?>"<?php if($_REQUEST['empcode']==$emp_row['id'])echo "selected";?>><?php echo $emp_row['emp_name'].' ( '.$emp_row['emp_code'].' ) ' ;?></option>
          <?php 	
		}
		?>
        </select></div>	</td>
		<td><input name="GO" value="GO" type="submit"></td>
  </tr>
</table>
</form>
<br /><br />
<?php if($_REQUEST['GO'])
{
 
     $condition="id='".$_REQUEST['empcode']."'";
	$result=$s->GetRecordById('empmaster',  $condition);
	$get_row1=DB_fetch_array($result);
	$emp_id=$_REQUEST['empcode'];
	$emp_code=$get_row1['emp_code'];
	$emp_basic=$get_row1['basic_salary'];
	$empnet_sal=$get_row1['net_sal'];
	$emp_name=$get_row1['emp_name'];
	$designation=$get_row1['designation'];
	  $dol=$get_row1['dol'];
	 $doj=$get_row1['doj'];
	
 
 $GetRecord_process_sal = "Select * from master_process_salary where  emp_id='".$_REQUEST['empcode']."' and payslip_month='".(substr($dol, 5, 2)-1) ."' and payslip_year='".substr($dol, 0, 4)."' "; 	 
 $ResultData_process = DB_query($GetRecord_process_sal,$db);
$Process_RowData = DB_fetch_array($ResultData_process);
 $mst_prosal=$Process_RowData['id'];
$basic_salary=$Process_RowData['basic_salary'];
$workingdays=$Process_RowData['workingdays'];
$total_workingday=$Process_RowData['total_workingday'];
$net_earning=$Process_RowData['net_earning'];
$loan_amount=$Process_RowData['loan'];
$OThours=$Process_RowData['OThours'];
$OTBasicAmount=$Process_RowData['OTBasicAmount'];
$balance_loanamt=$Process_RowData['balance_loanamt'];
 $oneday_sal=$empnet_sal/$workingdays;
   //$countGratuity		 =substr($dol, 0, 4)-substr($doj, 0,4);
   $countGratuity =get_months_between_date($doj,$dol);
?>


<table width="100%" border="0">
  <tr>
    <td><strong>Month:<?php echo GetMonth(substr($dol, 5, 2)-1); ?></strong></td>
    <td><strong>DOJ:</strong>&nbsp;<?php echo ConvertSQLDate($doj); ?></td>
    <td><strong>DOL:</strong>&nbsp;<?php echo ConvertSQLDate($dol); ?></td>
  </tr>
  <tr>
    <td><strong>Emp Code :
      <?php  echo $emp_code;?>
    </strong></td>
    <td><strong>Name :
      <?php  echo $emp_name;?>
    </strong></td>
    <td><strong>Desig :
      <?php     echo $s->GetFieldValue('desigmaster',"desigcode='". $designation."'",'designame');?>
    </strong></td>
  </tr>
  <tr>
    <td><strong>Salary Days :<?php  echo $total_workingday;?></strong></td>
    <td><strong>OT Days : <?php     ?></strong></td>
    <td><strong>OT Hours :<?php  echo $OThours;?></strong></td>
  </tr>
  
  <tr>
    <td colspan="3"><table width="100%"   cellpadding="0" cellspacing="0">
  <tr>
    <td width="25%" valign="top">
	
	<table width="100%" border="0" cellspacing="2" cellpadding="3" >
      <tr>
        <td width="20%" colspan="2"><center>
          <strong>Rate of Wages </strong>
        </center></td>
      </tr>
      <tr  >
        <td width="20%" height="30" ><strong>Basic</strong></td>
        <td width="20%"  height="30" ><?php  echo  $emp_basic;?></td>
      </tr>
      <?php 
	$earning=array();
		$q1 =DB_query("Select * from allowmaster",$db); 
	  while($rq1=DB_fetch_array($q1))
	  { 
		
		 ?>
      <tr>
        <td width="20%" height="30" ><strong><?php echo $rq1['allowcode'];?> </strong></td>

            <?php 
		
	    $query =DB_query("Select * from emp_salary where emp_id='".$emp_id."' and allowance_deduction='".$rq1['id']."' and all_ded_prefix='A'",$db);
		if(DB_num_rows($query))
		{
       	 while($row=DB_fetch_array($query))
	 	 {
       	?>
       
        <td width="20%" height="30" ><?php   		 echo $row['percentage_value'];	
					$earning[]=$row['percentage_value']; 
					?>        </td>
        <?php } echo "<tr>";
		} 
	  }	
	  
	  
	
	 
	
  ?>
      <tr>
        <td width="20%"><strong>Total</strong></td>
        <td width="20%" ><strong><?php echo (array_sum($earning)+$emp_basic);?></strong></td>
      </tr>
    </table></td>
    <td width="25%" valign="top" >
	
	
	<table width="100%" border="0" cellspacing="2" cellpadding="3">
      <tr>
        <td width="9%"><strong> <center>           Gross wages     </center> </strong></td>
      </tr>
      <tr>
        <td width="20%" height="30" ><?php  echo $basic_salary;?></td>
      </tr>
      <?php 
	$earning=array();
	
		$q1 =DB_query("Select * from allowmaster   ",$db); 
	  while($rq1=DB_fetch_array($q1))
	  { 
 		 ?>
      <tr>
			<?php 
 			$query =DB_query("Select * from payslip_salary where emp_id='".$emp_id."' and allowance_id='".$rq1['id']."' and mst_prosal='".$mst_prosal."' and allowance_type='A'",$db);
			if(DB_num_rows($query))
			{
			 while($row=DB_fetch_array($query))
			 {
			?>
			 
			<td width="20%" height="30" >
			
			
			<?php   echo $row['allowance_amount'];	
						$earning[]=$row['allowance_amount']; ?>        </td>
			<?php } 
			} 
			else{
			echo "<td width='20%' height='30' > </td>";
			}
		echo "<tr>";
		 
	  }	
   ?>
      </tr>
      <tr>
        <td width="9%" ><strong><?php echo (array_sum($earning)+$basic_salary);?></strong></td>
      </tr>
    </table></td>
     <td width="25%" valign="top">
	 <table width="100%" border="0" cellspacing="2" cellpadding="3">
       <tr>
         <td colspan="2"><center>
           <strong>Deduction</strong>
        
              
           </center></td>
         </tr>

       <?php 
	$deduction=array();
	  $query_allowances =DB_query("Select * from deduction_master   ",$db); 
	  while($row_allowances=DB_fetch_array($query_allowances))
	  { 
 		 ?>
       <tr> 
         <td width="20%" height="30"><strong><?php echo $row_allowances['code'] ;?> </strong></td>
         <?php  
		
	    $query =DB_query("Select * from payslip_salary where emp_id='".$emp_id."' and allowance_id='".$row_allowances['id']."' and mst_prosal='".$mst_prosal."'  and allowance_type='D'",$db);
		if(DB_num_rows($query))
		{
       	 while($row=DB_fetch_array($query))
	 	 {
       	?>
         <td width="20%" height="30" ><?php   		 echo $row['allowance_amount'];	
					$deduction[]=$row['allowance_amount']; ?>         </td>
         <?php }
		}  
		 else{
			echo "<td width='20%' height='30' >222</td>";
			}
		  echo "<tr>";
		
	  }	
 	
  ?>
       </tr>
       
   
       <tr>
         <td width="20%"><strong>Total</strong></td>
         <td width="20%" ><strong><?php echo array_sum($deduction);?></strong></td>
       </tr>
     </table>	 </td>
  </tr>
   
</table>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp; </td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><strong>Net Salary Amount </strong></td>
    <td><?php echo $net_earning;?>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><strong>Casual Leavs </strong></td>
    <td><?php    $TCL= $s->GetFieldValue('emp_leave',"emp_id='".$_REQUEST['empcode']."' and leave_type='CL'" ,'leave_days');
	echo $TotalCL= $oneday_sal* $TCL;
	
	?>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><strong>Earn Leaves </strong></td>
  <td><?php echo $TEL= $s->GetFieldValue('emp_leave',"emp_id='".$_REQUEST['empcode']."' and leave_type='EL'" ,'leave_days');
  echo $TotalEL= $oneday_sal* $TEL;
  ?>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><strong>EL Due for Next Year </strong></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><strong>Gratuity</strong></td>
    <td><?php 
	  if($countGratuity>5){
	   echo  round($emp_basic*($countGratuity/12)*15/26,2);
	  }
	?>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><strong>Loan Balance </strong></td>
    <td><?php echo $balance_loanamt; ?>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><strong>Full Final Amount </strong></td>
    <td><?php echo $TotalCL+$TotalEL+$net_earning ?></td>
    <td>&nbsp;</td>
  </tr>
</table>

<?php 
}
?>
</fieldset>