<?php //error_reporting(0);
include('includes/fun-HRClass.php');
include('includes/fun-php.php');
unset( $_SESSION['EMP_BONUS']);

if($_REQUEST['Search']   )
		{
 		$to_date=$_REQUEST['to_date'];
		$from_date=$_REQUEST['from_date'];	   
		$empcode=$_REQUEST['empcode'];
		$emptype=$_REQUEST['emptype'];
		$emp_salprocess_site=$_REQUEST['site'];
 }

	?>

<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Employee Bonus Report</h1>

<form action="" method="post">
  <table border="0" cellpadding="3" cellspacing="0" width="100%">
    <tr class="row1">
        <td width="12%" align="right">Branch</td>	
	      <td width="20%"><select name="site" id="site" >
          <option value="000">---ALL---</option>
          <?php 
  $site_sql=DB_query("Select loccode, locationname from locations  where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')",$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 width="12%" align="right">Employment Type</td>
        <td width="20%"><select name="emptype" id="emptype" onchange="ShowDiv(this.value,'hid-empdiv','GetEmployee.php?site='+document.getElementById('site').value);">
	 	 <option value="0" >---</option>
          <option value="Permanent"<?php echo($_REQUEST['emptype']=='Permanent'?'selected':'')?>>Permanent</option>
          <option value="Temporary"<?php echo($_REQUEST['emptype']=='Temporary'?'selected':'')?>>Temporary</option>
        </select>
      </td>     
      <td width="12%" align="right">Employee</td> 
      <td>
	  <div id='hid-empdiv'>
	  <select name="empcode" id="empcode" >
          <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>
        <!-- <input type="text" name="empcode" value="<?php //echo $_REQUEST['empcode']; ?>">-->
      </td>
  </tr>
  <tr class="row1">
      <td align="right">From Date</td>
      <td>
	       <input name="from_date" type="text" value="<?php  echo $_REQUEST['from_date']?>" class="datepicker"  />	 
      </td>
      <td align="right">To Date</td>
      <td>
	  	  <input name="to_date" type="text" value="<?php  echo $_REQUEST['to_date']?>" class="datepicker"  />
      </td>
      <td colspan="2"></td>
  </tr>
  <tr class="row1">
      <td colspan="6" style="text-align:center;"><input type="submit" name="Search" value="Search" class="search" /></td>
  </tr>
  </table>
</form>

<?php 
if($_REQUEST['Search']   )
{
$to_date=ConvertSQLDate($_REQUEST['to_date']);
$from_date=ConvertSQLDate($_REQUEST['from_date']);
$getmonth=substr($to_date,5,2);
$getmonth1=substr($from_date,5,2);
$getyear=substr($to_date,0,4);
$getyear1=substr($from_date,0,4);
   $filter='';
   
//   if($emptype['emptype']!='')
  //  $filter.=" and   A.employment_type='".$_REQUEST['emptype']."'";
 //      if($_REQUEST['site']!='000')
//   $filter.=" and  A.emp_site='".$_REQUEST['site']."'";
	 
	  
?>
	<p align="right"><a href="Report_EmpBonusDetails.php" target="_blank"><img src="images/excel_img.jpg" width="18" title="Download Excel File"></a></p>

 <?php
  if($_REQUEST['empcode']=='All')
  {
 // echo "Select * from   empmaster   where 1=1 ";
    $GetEmp =DB_query( "Select * from   empmaster   where 1=1 ",$db);	 
	}
else{
//echo "Select * from   empmaster   where  id='".$_REQUEST['empcode']."' ";
  $GetEmp =DB_query( "Select * from   empmaster   where id='".$_REQUEST['empcode']."'  ",$db);  
  }
  if($_REQUEST['from_date'] != '' && $_REQUEST['to_date'] != '')
 	$filter.=" ( B.payslip_month >= '".$getmonth1."' and  B.payslip_month <='".$getmonth."' ) and  ( B.payslip_year >= '".$getyear1."' and  B.payslip_year <='".$getyear."' ) ";

   while($RowEmp = DB_fetch_array($GetEmp))
   {
    //  echo "sdsdfdf";
	 	$s=new db_query();	
	   $emp_site=$s->GetFieldValue('empmaster',"id='".$RowEmp['id']."'" ,'emp_site');	
        	 $GetRecord = "Select B.basic_salary As EMPBASIC,B.* from   master_process_salary B where B.emp_id='".$RowEmp['id']."'  and  $filter";
  
  	 $_SESSION['EMP_BONUS']=$GetRecord ;
     $ResultData = DB_query($GetRecord,$db);
	   
	      $numrows = DB_num_rows($ResultData);
	  // if($numrows = DB_num_rows($ResultData))
	  {
 	 ?>
<table width="100%" border="0" cellpadding="3" cellspacing="0" class="thborder">
  <tr>
  	<th colspan="4"><?php 
  	echo $s->GetFieldValue('empmaster',"id='".$RowEmp['id']."'" ,'emp_name');
  	echo "(".$s->GetFieldValue('empmaster',"id='".$RowEmp['id']."'" ,'emp_code').")";
  	?></th>	 
  </tr>
  <tr>
		<th width="10%">Month</th>
		<th width="10%">Year</th>
		<th width="30%">Total Basic</th>
		<th>Bonus Amount</th>
  </tr>
  <?php 
  $k=1;  
  while($RowData = DB_fetch_array($ResultData))
   	  {  
	  
	  if( $emp_site==$_REQUEST['site']){
	  ?>
	<tr>   
		<td><?php  echo GetMonth($RowData['payslip_month']);?></td>
		<td><?php  echo $RowData['payslip_year'];?></td>
		<td ><?php  echo $RowData['EMPBASIC'];?></td>
		<td><?php 	echo "  ".round($RowData['EMPBASIC']*8.33*.01)."  ";	?></td>
	</tr>
  <?php } } ?>
</table>
<br>
<?php  
}}}
?>
</div>
</div>