<?php ob_start();
session_name('CAKEPHP'); session_start();
include("reportconfig.php");
// class db_query
//{
 
//function GetFieldValue($table,$condition ,$field)
//{

  //global $db;
  //echo "select ".$field." from ".$table." where  $condition ";
 // echo "<br>";
   	// $sql=mysqli_query($con, "select ".$field." from ".$table." where  $condition  ");
	// $r=mysqli_fetch_array($sql);
   //	return ($r[$field]);
//}
//}
//$s=new db_query();
$data='';
$data.="<table width='100%' border='0' cellspacing='2' cellpadding='2'>";
$data.="<tr>";
$data.="<th colspan='10'>Over Time Report</th>";
$data.="</tr>";
$data.="</table>";
$data2=$_SESSION['query1'];
 $ResultEmpData = mysqli_query($con, $data2);
   	 while($RowEmpData = mysqli_fetch_array($ResultEmpData))
	 {

  $Total_Otamount=	array();
     $GetRecord=$_SESSION['query'];

  $data.="<table width='100%' border='1' cellpadding='2' cellspacing='2'>";
  
  $data.="<tr>";
  $data.="<td ><b>Emp Name:".$RowEmpData['emp_name']."</b></td>";    
  $data.="<td><b>EmpCode:".$RowEmpData['emp_code']."</b></td>";
   $data.="<td><b>Emp Status:".$s->getField('shift_master','id',$s->GetFieldValue('empmaster',"id='".$RowEmpData['id']."'" ,'employee_type'),'shift_for')."</b></td>";
    $data.="<td  colspan='2'>&nbsp;</td>";
   $data.="</tr>";
  $data.="<tr bgcolor='#999999'>";
  $data.="<td ><strong>Date</strong></td>";
    $data.="<td><strong>OT Hours /Days </strong></td>";
    $data.="<td><strong>Wages Rate</strong></td>";
    $data.="<td><strong>Rate HR/DYs </strong></td>";
    $data.="<td><strong>IN/HR Days </strong></td>";
    $data.="<td><strong>OT Amount </strong></td>";
   $data.="</tr>";
     $ResultData = mysqli_query($con, $GetRecord);
   	 while($RowData = mysqli_fetch_array($ResultData))
	 {
	 $netgross_sal=$RowData['gross_sal'];
		   $CalOverTime=$OBJ_EMPSHIFT->ConvertTimeINTO_Mins($RowData['ot_hrs']) ;
 	      $DefineEmptype= $s->getField('shift_master','id',$RowData['emp_shift'],'shift_for');
				$dd=explode( '-',$RowData['attendance_date']);
				$workingdays= cal_days_in_month(CAL_GREGORIAN, $dd[1], $dd[0]);	
				
	 if( $DefineEmptype=='Staff' )
	 {
	    	 if($CalOverTime>=390 && $RowData['gross_sal']>10000){
			
			 $data.="<tr><td colspan='6'>----------</td></tr>";
			
			 }elseif($CalOverTime>=390){
 	 	
		 	$data.="<tr><td>".$RowData['attendance_date']."</td>";
			$data.="<td>".$RowData['ot_hrs']."</td>";
			 
	    	 $data.="<td>".$RowData['gross_sal']."</td>";
			$data.="<td>".$one_day_sal= round($RowData['gross_sal']/$workingdays,2)."</td>";
			$data.="<td>".$one_day_sal."</td>";
			$data.="<td>".$one_day_sal.$Total_Otamount[]=$one_day_sal."</td>";
		  $data.="</tr>";
		 }
		   
	 }
	 else if($RowData['ot_hrs']>0){
	 
	 $data.="<tr>";
			 $data.="<tr><td>".$RowData['attendance_date']."</td>";
			$data.="<td>".$RowData['ot_hrs']."</td>";
			 $data.="<td>";
			 if($RowData['gross_sal']>=5000)
			  '5000';
			 else			 
			 $RowData['gross_sal'];
			 $data.="</td>";
			$data.="<td>";
			if($RowData['gross_sal']>=5000)
 			$one_day_sal=round(5000/$workingdays,2); 
			else
			$one_day_sal=round($RowData['gross_sal']/$workingdays). 
						$hrsal=round($one_day_sal/8,2);
					  "</td>";
			$data.="<td>".$OBAMT=($CalOverTime*$hrsal/60)."</td>";
			$data."<td>".$OBAMT.$Total_Otamount[]=$OBAMT."</td>";
		  $data.="</tr>";
			
	 
	 }
 }   
  $data.="<tr>";
			   $data.="<td>&nbsp;</td>";
			   $data.="<td>&nbsp;</td>";
			   $data.="<td>&nbsp;</td>";
			   $data.="<td>&nbsp;</td>";
			   $data.="<td>Total OT Hours</td>";
			   $data.="<td>".array_sum($Total_Otamount)."</td>";
   $data.="</tr>";
   
 $data.="</table>";
 }
 //echo $data;
 //$header='';  		
 header("Content-type: application/x-msdownload"); 
header("Content-Disposition: attachment; filename=data.xls"); 
header("Pragma: no-cache"); 
header("Expires: 0"); 
print "$header\n$data";  

  ?>
  