<center> <h2>Over Time  Report</h2>
</center>
<?php //error_reporting(0);
include('includes/fun-php.php');
$modid=$_REQUEST['modid'];
$frmid=$_REQUEST['frmid'];

$rurl="index.php?route=master_payslip&action=View&modid=".$modid."&frmid=".$frmid."";
 
     ?>
	 
<form action="" method="post">
	<table border="0" cellpadding="0" cellspacing="0"  width="70%">
	<tr><td>Employee Code: <input type="text" name="empcode" value="<?php echo $_REQUEST['empcode']; ?>"> </td>
<td>Branch:&nbsp; 

<select name="site" id="site">
<option value="000">---Select Site---</option>
<?php 
if($_REQUEST['site']!='000'){
$site_sql=DB_query("Select loccode, locationname from locations where loccode in (".$_SESSION['AssignedSites'].")",$db);}
else
{$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>Month :
 <select name="paymonth"  style="width:120px;">
 <?php
 $arr=array(1=>"Jan","Feb","Mar","Apr","May","June","July","Aug","Sept","Oct","Nov","Dec");
 foreach ($arr as $key => $value) {
 	$p='';
 	if( $key==$_REQUEST['paymonth'])
	$p='selected';
   ?><option value="<?php echo $key;?>" <?php echo $p;?> ><?php echo $value;?></option>
 <?php } ?></select>
	  </td> 
  
   <td>year :
 <select name="payyear"  style="width:120px;">
 <?php
 
 for($i=date('Y');$i>2000;$i--)
 {
 	$p='';
 	if( $i==$_REQUEST['payyear'])
	$p='selected';
 ?><option value="<?php echo $i;?>" <?php echo $p;?>><?php echo $i;?></option>
 <?php 
 }
 ?></select>
	  </td>       
	<td>	<input type="submit" name="Search"   value="Search"/> </td></tr></table>
	
	
</form>	

<?php 
  if($_REQUEST['Search'] )
  {
	   $paystatus=true;  
	   $years=$_REQUEST['payyear'];
	   $month=$_REQUEST['paymonth'];
	   $empcode=$_REQUEST['empcode'];
	   $site=$_REQUEST['site'];
	 
?> <br />
 <table width="100%" border="1" cellpadding="2" cellspacing="2">
  <tr bgcolor="#999999">
    <td><strong>EmpCode</strong></td>
    <td><strong>Name</strong></td>
	 <td><strong>Wages Rate</strong></td>
    <td><strong>Rate HR/DYs </strong></td>
    <td><strong>IN/HR Days </strong></td>
    <td><strong>OT Amount </strong></td>
   </tr>
   <?php $Total_Otamount=	0;
   //  and A.emp_code='".$empcode."' 
   $Total_OThours=0;
     echo    $GetRecord = "Select A.emp_code,A.emp_site ,A.employee_type as emp_shift ,A.emp_name,A.basic_salary,A.basic_perc,A.gross_sal ,sum(B.ot_hrs) As OTHRS ,B.pres_abs,
	B.shift_start,B.shiftstart_AMPM  ,B.shift_end,B.shiftend_AMPM,B.time_in ,B.timein_AMPM,B.time_out,B.timeout_AMPM ,B.work_hrs  ,B.ot_hrs ,B.attendance_date from empmaster A, daily_attendance B  where  A.id=B.employee and month(attendance_date)='".$month."' and year(attendance_date)='".$years."' and A.emp_site='".$site."' group by A.emp_code order by attendance_date asc";	  		 	   
	

	
     $ResultData = DB_query($GetRecord,$db);
   	 while($RowData = DB_fetch_array($ResultData))
	 {
	 
	 
	 $netgross_sal=$RowData['gross_sal'];
	 $DefineEmptype= $s->getField('shift_master','id',$RowData['emp_shift'],'shift_for');
 
   if(strtolower($DefineEmptype)=='staff')
   {
 	 if($RowData['gross_sal']<=10000 ){
 	 
	  $range=3;
	 }
	  if($RowData['gross_sal']>10000)
	  {
	  $range=4;}
	  $range_amount=$RowData['gross_sal'];
   } 
   else
   {
   		if($RowData['gross_sal']<=5000){
			$range=1;
			$range_amount=$RowData['gross_sal'];
			}
			
		  if($RowData['gross_sal']>5000 ) {
		  $range=2;
		  $range_amount=5000;
		  }
   } 
	   
		  
		 
   $getOT="select * from ot_salary_master where emp_shift='".$RowData['emp_shift']."' and emp_site='".$RowData['emp_site']."' and salary_range='".$range."'";
		 $ResultDataOT = DB_query($getOT,$db);
		  while($OTRowData = DB_fetch_array($ResultDataOT)){
 				 	    $salary_based=$OTRowData['salary_based'];
					 $OThours=$OTRowData['OThours'];
					 $OTleaveday=$OTRowData['OTleaveday'];
 					 }  		 		 
			 
			 
			   
			 
		 
		 ?>
   
  <tr>
    
    <td><?php  echo $RowData['emp_code']."(".$RowData['emp_shift']."(".$DefineEmptype;
	
	// 	echo $s->getField('ot_salary_master','id',$RowData['emp_shift'],'shift_category');
	?></td>
     <td><?php  echo $RowData['emp_name']?></td>
	     <td><?php  echo $RowData['gross_sal']."(".$range.")"?></td>
    <td><?php 
	 
		$dd=explode( '-',$RowData['attendance_date']);
		$workingdays= cal_days_in_month(CAL_GREGORIAN, $dd[1], $dd[0]);	  
		//echo $range_amount;
	  
	     if(strtolower($DefineEmptype)!='staff')
		 {
		 
			 if($range_amount==5000)  
			 $one_day_sal= ($range_amount/$workingdays) ; 	  	   
			 else		 
			 $one_day_sal= ($RowData['gross_sal']/$workingdays); 	  	   
		}
		else
		{
			$one_day_sal= ($RowData['gross_sal']/$workingdays); 	
		} 		
	  	 
	  	   //$RowData['emp_shift']."<br>";
	       $calculate_shift_hours=8;
	       //GET_Shift_hours($RowData['emp_shift']);
	 
        $timeArr1 = explode(':', $calculate_shift_hours);
     	$decTime1 = ($timeArr1[0]*60) + ($timeArr1[1]) + ($timeArr1[2]/60);    
 	    $sal_persec=round($one_day_sal/$decTime1,2); 
		$timeArr = explode(':', $calculate_shift_hours);
 	    $decTime = ($timeArr[0]*60) + ($timeArr[1]) + ($timeArr[2]/60); 
	//	echo $decTime;echo "<br>";
	   echo $sal= round($one_day_sal/$calculate_shift_hours,2);
 
	?></td>
     <td><?php    
	 if(strtolower($DefineEmptype)=='staff')  {
	 if($RowData['OTHRS']>$OThours)
	 {
	    if(strtolower($salary_based)=='leave')
	     echo $RowData['OTHRS'].'<br>'.round($RowData['OTHRS']/$OThours,0).'(L-CS)';
		 else{
		    if($OThours>0){
		     $c= round($RowData['OTHRS']/$OThours,0);
			 echo   ($RowData['OTHRS']*$c)."<br>($c days sal )";
			 }else echo "0";
		 }
 	 }
 	 }
	 else{
	 echo ($RowData['OTHRS']!=0?$RowData['OTHRS']:'');
	 }
		 ?></td>
     <td><?php 	
	 
	 if(strtolower($DefineEmptype)=='staff')  
	 { 
	   
		 if($salary_based=='Hours' && $RowData['OTHRS']>$OThours)
		 {
		  $c= round($RowData['OTHRS']/$OThours,0);
		 echo $calsal=round(($decTime1*$sal)/60,0);
		 //echo '<br>';
			echo "33333333333333";
		  //echo $calsal= $sal*$c;
		 }
		 else{
		 	echo "fsdsdfdfhg";
		 		 echo $calsal= round($sal,0) ;
		 }
	 }else{
	
	 	 if($salary_based=='Hours')
		 {
  		  echo $calsal= round($sal*($RowData['OTHRS']!=0?$RowData['OTHRS']:''),0);
		 }else  if($salary_based=='ActualAmount')
		 {
 		  echo $calsal= round($sal*($RowData['OTHRS']!=0?$RowData['OTHRS']:''),0);
		 }
	 
	 }
	 $Total_Otamount+=$calsal;
	 // $salary_based.'+==>'.$OThours.'==>'.$OTleaveday;?></td>
     
    <?php } ?>
   </tr>
</table>
<?php } ?>