<center> <h2>Process Salary</h2></center>
<?php //error_reporting(0);
include('./includes/fun-php.php');
include('./includes/fun-HRClass.php');
$modid=$_REQUEST['modid'];
$frmid=$_REQUEST['frmid'];
$target_rurl="index.php?route=HRModule/SalaryProcess&modid=".$modid."&frmid=".$frmid."";
 $rurl_view="index.php?route=View_master_payslip&action=View&modid=".$modid."&frmid=".$frmid."";
    	if($_REQUEST['Search']   )
		{
 		$_SESSION['Mstemp_paysal']=array();			 
		$_SESSION['Mstemp']=array();
		$paystatus=true;  
		$_SESSION['payyear']=$_REQUEST['payyear'];
		$_SESSION['paymonth']=$_REQUEST['paymonth'];
		$_SESSION['empcode']=$_REQUEST['empcode'];
		$_SESSION['emptype']=$_REQUEST['emptype'];
		$_SESSION['emp_salprocess_site']=$_REQUEST['site'];
		$years=$_SESSION['payyear'];
		$month=$_SESSION['paymonth'];	   
		$empcode=$_SESSION['empcode'];
		$emptype=$_SESSION['emptype'];
		$emp_salprocess_site=$_SESSION['emp_salprocess_site'];
			
    }	 

 ?><table width="50%" border="0" cellpadding="0" cellspacing="0" align="center">
   
  <tr>
    <td align="left"  scope="row">Role : Monthly wages Calculation...</td>
  </tr>
  <tr>
    <td align="left"  scope="row">&nbsp;</td>
  </tr>
  <tr>
    <td align="left" >
<form action="" method="post">
	<table border="0" cellpadding="5" cellspacing="0"  width="80%">
	<tr>
		
<td width="10%">Site <?php //echo $_SESSION['emp_salprocess_site'];?>
 <select name="site" id="site" style="width:auto;">
<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 ($_SESSION['emp_salprocess_site']==$site_row['loccode']?'selected':'');?>><?php echo $site_row['locationname'];?></option>
<?php } ?>
</select></td>
		<td  width="20%">Employee Type: 
<select name="emptype" id="emptype" onchange="ShowDiv(this.value,'hid-empdiv','GetEmployee.php?site='+document.getElementById('site').value)" style="width:200px;" > 
	<option value="0" >---</option>
		<option value="Permanent" <?php echo($_SESSION['emptype']=='Permanent'?'selected':'')?>>Permanent</option>
		<option value="Temporary" <?php echo($_SESSION['emptype']=='Temporary'?'selected':'')?>>Temporary</option>
	</select>	
</td> 

		
		
		
		<td  width="20%"> Employee Code:
		<div id='hid-empdiv'>
	<select name="empcode" id="empcode" style="width:200px">
		<option value="All">All</option>
		<?php 
		$emp_sql=DB_query("Select id, emp_code,emp_name from empmaster order by emp_name",$db);
		while($emp_row=DB_fetch_array($emp_sql))
		{?>
			<option value="<?php echo $emp_row['id'];?>"<?php if($_SESSION['empcode']==$emp_row['id'])echo "selected";?>><?php echo $emp_row['emp_name'].' ( '.$emp_row['emp_code'].' ) ' ;?></option>
		<?php 	
		}
		?>
		
	</select>	</div></td>
<!-- <input type="text" name="empcode" value="<?php //echo $_REQUEST['empcode']; ?>">-->  
 <td  width="10%">Month :<br />
 <select name="paymonth"  style="width:auto;">
 <?php
 $arr=array(1=>"Jan","Feb","Mar","Apr","May","June","July","Aug","Sept","Oct","Nov","Dec");
 foreach ($arr as $key => $value) {
 	$p='';
 	if( $key==$_SESSION['paymonth'])
	$p='selected';
   ?><option value="<?php echo $key;?>" <?php echo $p;?> ><?php echo $value;?></option>
 <?php } ?></select>
	  </td> 
  
   <td>year :<br />
 <select name="payyear"  style="width:auto;">
 <?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 valign="bottom">	<input type="submit" name="Search"   value="Search"/> </td></tr></table>
	
	
</form>
    </td>
  </tr>
  
</table>
<?php if($_REQUEST['daction']){
?><div><?php  echo "Record " .$_REQUEST['daction'].' Successfully';?></div>
<?php 
}?>
<!---->
<div style="width: 800px; height:400px; overflow: scroll;" >
<?php 
//echo $_SESSION['empcode'];
if($_REQUEST['UnProcess'])
{
 	 for($i=0;$i<count($_REQUEST['SalaryProcessed']);$i++){
 	  $condition=" payslip_month ='".$_SESSION['paymonth']."' and  payslip_year ='".$_SESSION['payyear']."'  and emp_id ='".$_REQUEST['SalaryProcessed'][$i]."' ";
	  $getmst_processid=$s->GetFieldValue('master_process_salary',$condition ,'id');
	  $s->DeleteRecord('master_process_salary',$condition);
 	  $condition2="mst_prosal in ($getmst_processid) and emp_id  =".$_REQUEST['SalaryProcessed'][$i]."";
	  $s->DeleteRecord('payslip_salary',$condition2);
 	 }
	 
	 
	  $s->PageLocation($target_rurl.'&daction=Deleted');
	 
}


if($_REQUEST['Save'])
{
 	
 	
	$_REQUEST['Search']=1; 

 	 	 for($i=0,$lx=0;$i<count($_SESSION['Mstemp1']);$i++,$lx++)
	 {
	 
		if(in_array($_SESSION['Mstemp1'][$i][0], $_REQUEST['SalaryProcessed'])) 
		 {	
		
		$data['emp_id'] =$_SESSION['Mstemp1'][$i][0];
		$data['payslip_month'] = $_SESSION['Mstemp1'][$i][1];
		$data['payslip_year'] =$_SESSION['Mstemp1'][$i][2];
		$data['total_workingday'] = $_SESSION['Mstemp1'][$i][3];
		$data['workingdays'] = $_SESSION['Mstemp1'][$i][4];
 		$data['basic_salary'] = $_SESSION['Mstemp1'][$i][5];
		$data['loan'] =$_SESSION['Mstemp1'][$i][6];
		$data['loan_masterid'] =$_SESSION['Mstemp1'][$i][7];
		$data['advance_balance'] =$_SESSION['Mstemp1'][$i][8];
		$data['balance_loanamt'] =$_SESSION['Mstemp1'][$i][8];
		$data['net_earning'] = $_SESSION['Mstemp1'][$i][10];
		$data['OThours'] = $_SESSION['Mstemp1'][$i][11];
		$data['OTBasicAmount'] = $_SESSION['Mstemp1'][$i][12];
		$data['gross_salary'] = $_SESSION['Mstemp1'][$i][13];
		$data['locked'] = 'Y';
		$data['created_date'] = date('Y-m-d');
	 
	 //-------------------UPDATE DATA IN --------emp_loan_details And - loan_management----------------------------------------+
	$data_loanupdate['paid_status ']='Y';
	$data_loanupdate['balance_amount']=$_SESSION['Mstemp1'][$i][8]-$_SESSION['Mstemp1'][$i][6];
	
	
	$cond1="loanid='".$_SESSION['Mstemp1'][$i][7]."' and loan_month ='".$_SESSION['Mstemp1'][$i][1]."' and 
	year(loan_paid_date) ='".$_SESSION['payyear']."'";
	
	$s->RecordEdit('emp_loan_details', $data_loanupdate, $cond1);
		
//	$getloanamt=$s->GetFieldValue('loan_management',"id='".$_SESSION['Mstemp'][$i][11]."'",'loan_balance');
	//$_SESSION['Mstemp1'][$i][6];
	$data_loan_management['loan_balance']=$_SESSION['Mstemp1'][$i][8]-$_SESSION['Mstemp1'][$i][6];
	
	$cond2="id='".$_SESSION['Mstemp1'][$i][7]."'";
	$s->RecordEdit('loan_management', $data_loan_management, $cond2);
  	 //------------------------------------------------------------------------------------------------------------------------	
	$data['balance_loanamt'] =$data_loan_management['loan_balance'];
	$insert=$s->RecordInsert('master_process_salary', $data);

	 
	$last=  DB_Last_Insert_ID($db,'master_process_salary', 'id');
		for($l=0,$j=0;$j<count($_SESSION['Mstemp_paysal']);$j++,$l++)
		{
		   if($_SESSION['Mstemp_paysal'][$j][0]==$_SESSION['Mstemp1'][$i][0])
		   {
			  $data_arr['mst_prosal']=$last;
			  $data_arr['emp_id']=$_SESSION['Mstemp_paysal'][$j][0];;
			  $data_arr['allowance_id']=$_SESSION['Mstemp_paysal'][$j][1];;
			  $data_arr['allowance_amount']=$_SESSION['Mstemp_paysal'][$j][2];;
			  $data_arr['allowance_type']=$_SESSION['Mstemp_paysal'][$j][3];
 			  $insert=$s->RecordInsert('payslip_salary', $data_arr);
			}
		}	
 	     }	
		
 	}
	  $s->PageLocation($target_rurl.'&daction=Insert');
	
	
}

    	if($_REQUEST['Search']   )
		{
			 	
		
	 
?>
<form action="" method="post">
<table width="100%" border="1" cellspacing="1" cellpadding="3">
	<tr style="background-color:#999999"><td colspan="8">&nbsp;</td>
		<?php $q4 =DB_query("Select * from allowmaster   ",$db); 
	 	 	  $all_rows=DB_num_rows($q4);?>
		<td colspan="<?php echo $all_rows+1;?>"><b>EARNINGS</b></td>
		<td  rowspan="2" valign="top"><b>GROSS WAGES </b></td>
		<?php 
		$q3 =DB_query("Select * from deduction_master   ",$db); 
		$ded_rows=DB_num_rows($q3) ;
		?>
		<td colspan="<?php echo $ded_rows+3;?>"><b>DEDUCTIONS</b>	    </td>
		
		<td><b>TOTAL</b></td>
		<?php if($_REQUEST['emptype']=='Temporary'){ $colspan="colspan='2'";}?>
		<td <?php echo $colspan;?>><?php if($_REQUEST['emptype']=='Temporary'){?>
		  <div align="center"><b>OT</b>
		    <?php }else  ?>
	    &nbsp;</div></td>
		<td>&nbsp;</td>
	</tr>
        <tr style="background-color:#999999">
        <td><strong> Sr. No.</strong></td>
        <td><strong> Emp Code</strong></td>
        <td><strong>Emp Name</strong></td>
        <td><strong>Designation </strong></td>
        <td ><strong>Month<br>
          Days</strong></td>
        <td><strong>Sal Days</strong></td>
        <td><strong>P.F.<br>
          No</strong></td>
		   <td><strong>E.S.I.<br>
	       No</strong></td>

        <!-- <td >Monthly Salary</td> -->
        <td ><strong>Payable  Basic</strong></td>
<?php
	  $net_earning=0;
	  $query_allowances =DB_query("Select * from allowmaster   ",$db); 
	  $j=1;
	  $n=DB_num_rows($query_allowances);
	  $nx= round(70/$n,2);
	  while($row_allowances=DB_fetch_array($query_allowances))
	  { 		  
?> 
    	<td><strong><?php echo $row_allowances['allowcode'];?>
          <input name="allowmasterid[]" type="hidden"  value="<?php echo $row_allowances['id'];?>"/>
    	</strong></td>         
     <?php } ?>
     
     <?php $query_allowances =DB_query("Select * from deduction_master   ",$db); 
	 	   $n=DB_num_rows($query_allowances);
	   	   $nx1= round(70/($n+3),1);
	  while($row_allowances=DB_fetch_array($query_allowances))
	  {	  
	  ?> 
    	<td ><strong><?php echo $row_allowances['code'];?>
          <input name="deductionid[]" type="hidden"  value="<?php echo $row_allowances['id'];?>"/>		
	      </strong></td>         
     <?php } ?>
	 
     <td><strong>Adv </strong></td>      
     <td><strong>Loan Bal </strong></td>    
     <td><strong>Total Deduction</strong></td>
      <td><strong>
        <?php if($_REQUEST['emptype']=='Temporary')echo "Gross Wages"; else echo "Net Pay";?>
      </strong></td>
     <?php if($_REQUEST['emptype']=='Temporary'){?> 
	 <td><strong>OT Hours</strong></td>
    <td><strong>OT amount</strong></td>
    <?php } ?>
    <?php if($_REQUEST['emptype']=='Temporary'){?> 
	<td><strong>Net Pay</strong></td>
	<?php } ?>
     <td ><strong>Signature</strong></td>  <td ><strong>Loc</strong></td>
        </tr>
        <?php
  $filter='';
 if($_SESSION['empcode']!='All')
   $filter.=" id='".$_SESSION['empcode']."' ";
   else
   $filter.=" 1=1 ";
   
   if($_SESSION['emptype']!='')
    $filter.=" and  employment_type='".$_SESSION['emptype']."'";
       if($_SESSION['emp_salprocess_site']!='000')
   $filter.=" and  emp_site='".$_SESSION['emp_salprocess_site']."'";

  
	   $GetRecord = "Select * from empmaster where  $filter  and blocked!=1 ";
 	 
 	  // echo $GetRecord;
      $ResultData = DB_query($GetRecord,$db);
if( DB_num_rows($ResultData))
{
	  $fstatus=1;
	  $i=1;$kl=0;$_SESSION['Mstemp1']=array();
   	  while($RowData = DB_fetch_array($ResultData))
   	  {
	 //echo "<br>----------------------------------------<br>  Select * from daily_attendance where  employee='".$RowData['id']."'  and month(attendance_date)='".$month."' and year(attendance_date)='".$years."'";
	  $CHKDailyEntry =DB_query("Select * from daily_attendance where  employee='".$RowData['id']."'  and month(attendance_date)='".$month."' and year(attendance_date)='".$years."'",$db);
	  
	 //  echo "<br>Select * from daily_attendance where  employee='".$RowData['id']."'  and month(attendance_date)='".$month."' and year(attendance_date)='".$years."'";
		// echo  DB_num_rows($CHKDailyEntry);
	 if(DB_num_rows($CHKDailyEntry)>0)
	 {
    	  
 		  $emp_id=	$RowData['id'];
	  $condition="payslip_month='".$month."' and payslip_year='".$years."' and emp_id='".$emp_id."'";
 	   $Locked= $s->GetFieldValue('master_process_salary',$condition ,'locked');
	   if($Locked=='Y')
	    $fstatus=0;
 	 //($Locked=='' || $Locked=='N')
	 {
	    $fstatus=1;
		  $lt=0;	
	  	  $emp_id=	$RowData['id'];
		  $gross_sal=$RowData['gross_sal'];
		  $basic_sal=$RowData['basic_salary'];
		  $basic_perc=$RowData['basic_perc'];
		 $over_timestatus= $RowData['over_time'];
		 $emp_weekly_off = $RowData['emp_weekly_off'];
   	      $workingdays= cal_days_in_month(CAL_GREGORIAN, $month, $years);
	      $one_day_sal= round(($basic_sal/$workingdays),2)		;   	 
		  
 			
/*
$payable_day = payable_day($emp_id,$month, $years,'P');
$holiday=Count_Holidays($month, $years );	
   $leave_sql="Select * from leavemaster";
   $leave_res=DB_query($leave_sql,$db);  
   while($leave_row=DB_fetch_array($leave_res))
   {
    $leave_val=payable_day_leavetype($emp_id,$month, $years,$leave_row['leavecode']);
	$lt=$lt+$leave_val;   
    }  
   	 $weeklyoff= CountSatSun($month, $years,$emp_weekly_off );
$lt=$lt+$weeklyoff;	   
	        $absent= payable_day($emp_id,$month, $years,'A');    
        	 $absent_total_days =$workingdays-$absent-($payable_day+$holiday+$lt ); 
             $absent_withoutinfo=$workingdays -($payable_day+$holiday+$lt );  
	          $ACGpaydays=$workingdays- $absent_withoutinfo;
		    
*/			
			  $ACGpaydays =  Calculate_EmpSalaryDays($emp_id,$month, $years,'P',$emp_weekly_off);
		     if($workingdays<$ACGpaydays)
			 $ACGpaydays=$workingdays  ;
			
			
			  $paid_gross=$ACGpaydays*$one_day_sal;
			  
			  
			  
			  
  
			  
 
         ?>
      <tr bgcolor="#FFFFFF">
        <td><input name="SalaryProcessed[]" type="checkbox" value="<?php echo $RowData['id']; ?>" /><?php //echo $i ;
		/*echo "<br>Weeklyoff:".$weeklyoff;
		echo "<br>Absent:".$absent;
		echo "<br>Pay:".$payable_day;
		echo "<br>Working:".$payable_day;
		echo "<br>holiday:".$holiday;
		echo "<br>lt:".$lt;*/
		?></td>
        <td><?php echo $RowData['emp_code']; ?>&nbsp;</td>
       <td> <?php 
	   if($RowData['payment_mode']=='Cash')
	   {echo $RowData['emp_name'];}
	   else
	   {echo $RowData['emp_name']."<br/><br/>".$RowData['bank_name']." A/C No. ".$RowData['bank_account'];} ?>&nbsp;</td>
       <td><?php echo $fnLib->getField('desigmaster','desigcode',$RowData['designation'],'designame');?></td>
        <td ><?php echo  $workingdays= cal_days_in_month(CAL_GREGORIAN, $month, $years);
        

		 ?></td>
		 
		 
        <td ><?php echo $ACGpaydays; ?></td>
           <td ><?php echo $RowData['PFno'] ?>&nbsp;</td>
              <td ><?php echo $RowData['ESIno'] ?>&nbsp;</td>
        <!--  <td ><?php echo $RowData['gross_sal']; ?></td> -->
        <td ><?php 
		echo $RowData['basic_salary']."<br>-----<br>";
		echo $gbasic= round(($paid_gross));;
							
		
		 ?>		</td>
       
       
       	<?php $deduction_amount=array();$allowance_amount=array();
       	
		
  	$q1 =DB_query("Select * from allowmaster   ",$db); 
	  while($rq1=DB_fetch_array($q1))
	  { 
		
		//echo "<br><br>Select * from emp_salary where emp_id='".$emp_id."' and allowance_deduction='".$rq1['id']."' and all_ded_prefix='A'";
		
	    $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 >
  
       		<?php  
       
	//echo	 $row['all_ded_prefix'];
       	if($row['percentage']==0.00 )
       	{
       	$allowance=($row['percentage_value']/$workingdays)*$ACGpaydays;
		}
		else {
				$allowance=.01*$gbasic*$row['percentage']*$ACGpaydays;	
		}
		 
		 echo $row['percentage_value']."<br>-----<br>";
		 echo (round($allowance)!=0?round($allowance):'-');
		 //if($row['all_ded_prefix']=='A') 
		$allowance_amount[]=round($allowance);
		/*	else
		$deduction_amount[]=round($allowance);*/
		$_SESSION['Mstemp_paysal'][] =array($emp_id,$row['allowance_deduction'],round($allowance),$row['all_ded_prefix']);
		 ?>		 </td>
       	 <?php }
		}else{echo "<td>-</td>";}
	  }	 
?>
<td><?php echo $RowData['gross_sal']."<br>-----<br>";echo $gross_salary=$gbasic+array_sum($allowance_amount);?>

</td>
       <?php 
//------------------------------------------------------------------------------------------
		
  	$q2 =DB_query("Select * from deduction_master   ",$db); 
	  while($rq2=DB_fetch_array($q2))
	  { 
	//	echo "Select * from emp_salary where emp_id='".$emp_id."' and allowance_deduction='".$rq2['id']."' and all_ded_prefix='D'<br>";
	    $query =DB_query("Select * from emp_salary where emp_id='".$emp_id."' and allowance_deduction='".$rq2['id']."' and all_ded_prefix='D'",$db);
		if(DB_num_rows($query))
		{
       	 while($row=DB_fetch_array($query))
	 	 {
       	?>
       	<td >
   <?php  
 	// echo	 '==>'.$row['percentage'];
       	if($row['percentage']==0.00 )
       	{
			$allowance=($row['percentage_value']/$workingdays)*$ACGpaydays;
		}
		else 
		{
			$allowance=.01*($gbasic+array_sum($allowance_amount))*$row['percentage'];	
		}
		 
		  
		   if(strtolower($rq2['name'])=='pf' && $allowance!=0)
		   {
		 
		   		echo round($gbasic*.0833);
				echo "<br>";
				echo round($gbasic*.0367);
				echo "<br>";
				echo $allowance=(round($gbasic*.0833)+round($gbasic*.0367));
				  
		   }else{
		 
		  echo (round($allowance)!=0?round($allowance):'-');
		 
		  } $deduction_amount[]=round($allowance);
		
		/* if($row['all_ded_prefix']=='A') 
		$allowance_amount[]=round($allowance);
		else*/
			 
		$_SESSION['Mstemp_paysal'][]=array($emp_id,$row['allowance_deduction'],round($allowance),$row['all_ded_prefix']);
		 ?>		 </td>
       	 <?php }
		}else{echo "<td>-</td>";}
	  }	
	  
	  

?>
  		 <td><?php   $AdvLoan=advance_loan($emp_id,$month,$years);
		 echo ($AdvLoan[0]>0?$AdvLoan[0]:'-');
		 	  	

		 ?></td>
		 <td>  <?php  $x=EmpBalanceAmount($emp_id,$AdvLoan[1],$month);
		  echo ($x>0?$x:'-');
		 
		 ?></td> 
	     <td>&nbsp;<?php echo round(array_sum($deduction_amount),0)+$AdvLoan[0]; 	?></td>
         
		 
		 <?php  
	   			 $netpayable=$paid_gross+round(array_sum($allowance_amount)-array_sum($deduction_amount),0);   
				 if($AdvLoan!=0)
				 $netpayable=$netpayable-$AdvLoan[0];
				 
				 
				 
				
	   				
	   	?>       
      	<td>
		<?php echo ($netpayable!=0?round($netpayable):0);?>		</td>
          <?php //echo $OT=round(GetOverTime($emp_id,$month,$years),0);
          	if($over_timestatus=='Yes')
          	   $OT=round(GetOverTime($emp_id,$month,$years),0);
			   
			   
			   
			   
          	 ?>
       <?php if($_REQUEST['emptype']=='Temporary')
	   {
	   			$startdate=firstOfMonth($month,$years);
				$end_date=lastOfMonth($month,$years);
				$week_off_day=GetDay($emp_weekly_off);
				$finalWorkHours='';
				$total_work_hrs_in_month='00:00';
	   			for($i=$startdate;$i<=$end_date;$i++)
				{
					if(DayOfDate($i)==$week_off_day)
					{
						$array_of_week_off[]=$i;
						$check_week_off_present="Select work_hrs,pres_abs from daily_attendance where attendance_date='".$i."' and employee='".$emp_id."'";
						//echo $check_week_off_present."<br>";
						$check_result=DB_query($check_week_off_present,$db);
						//echo DB_num_rows($check_result);
						if(DB_num_rows($check_result)>0)
						{
							$check_row=DB_fetch_array($check_result);
							if($check_row['pres_abs']=='P')
							{
								$work_hours=$check_row['work_hrs'];
								$total_work_hrs_in_month_BRK=explode(':',$total_work_hrs_in_month);
								$work_hours_BRK=explode(':',$work_hours);
								$total_hours=$total_work_hrs_in_month_BRK[0]+$work_hours_BRK[0];
								$total_min=$total_work_hrs_in_month_BRK[1]+$work_hours_BRK[1];
								$total_work_hrs_in_month=$total_hours.":".$total_min;
								$quotient=$total_min/60;
								$q=explode(".",$quotient);
								if($q[0]!=0)
								{$r=$total_min%60;}
								else
								{$r=$total_min;}
								$finalWorkHours=($total_hours+$q[0]).":".$r;
							}	
							
						}
					}
					
				}
	   
	   ?>
	    <td><?php $OTHOUR=getOTHours($emp_id,$month,$years);
		$OTHOUR_brk=explode(':',$OTHOUR);
		$finalWorkHours_brk=explode(':',$finalWorkHours);
		$h=$OTHOUR_brk[0]+$finalWorkHours_brk[0];
		$m=$OTHOUR_brk[1]+$finalWorkHours_brk[1];
		$quot=$m/60;
		$qt=explode(".",$quot);
		if($qt[0]!=0)
		{$r=$m%60;}
		else
		{$r=$m;}
		echo $h.":".$r;
		$disOThour=$h.":".$r;
		?>
		         </td>
		
		<td><?php if($over_timestatus=='Yes')
          	   {
			   		$OT=GetOverTime_Calculation($emp_id,$month,$years,$_REQUEST['site']);
			   		 $DefineEmptype= $s->getField('shift_master','id',$RowData['employee_type'],'shift_for');
					if($DefineEmptype=='Worker')
					{
						if($gross_sal<5000){$rate=$gross_sal;}else{$rate="5000";}
						$one_day_salary=$rate/$workingdays;
						$one_hour_salary=$one_day_salary/8;
						$one_min_salary=$one_hour_salary/60;
						
						$tot1=round($finalWorkHours_brk[0]*$one_hour_salary);
						$tot2=round($finalWorkHours_brk[1]*$one_min_salary);
						$total=$tot1+$tot2;
					}
					//else if($DefineEmptype=='Staff')
			   }
			   else
			   {$OT='-';}
		
		 if($DefineEmptype=='Worker')
					{echo $t=$OT+$total;}else{echo $t=$OT;}?>
		        </td><?php }?>
		 
		 
		 
		 
		 <?php if($_REQUEST['emptype']=='Temporary'){?> 
		  <td><?php   $t1=$t+$netpayable;
          	echo round($t1);?></td><?php } ?>
         <td width="20%">&nbsp;</td>
		    <td width="2%">
<?php 
	    

		
  $condition="payslip_month='".$month."' and payslip_year='".$years."' and emp_id='".$emp_id."'";
 $Lockedid= $s->GetFieldValue('master_process_salary',$condition ,'id');
$_SESSION['AcgMst_Process_Salary'][]= $Lockedid;
$_SESSION['AcgMst_Emp_Process_Salary'][]= $emp_id;
echo ($Locked==''?'N':'Y');
//echo  $s->getField('master_process_salary','payslip_month',$month,'locked'); ?>&nbsp;</td>
      </tr>
       <?php 
	  	
 	  

        $_SESSION['Mstemp1'][$kl]=array($RowData['id'],$month,$years,$workingdays,$ACGpaydays,$gbasic,$AdvLoan[0],$AdvLoan[1],$x,$netpayable,$netpayable,$disOThour,$OT,$gross_salary,$Locked,array_sum($allowance_amount),array_sum($deduction_amount));
	// echo "<pre>";
  //   print_r($_SESSION['Mstemp1']);
	
   // $_SESSION['Mstemp1'][$kl]=array($RowData['id'],$month,$years,$workingdays, $ACGpaydays,$gbasic,$AdvLoan[0],$x,$netpayable,$OTHOUR,$OT );
$_SESSION['Mstemp'][]=array($RowData['id'],$month,$years,$gbasic,$workingdays,'',0,0,$OT,0,$AdvLoan[0],$AdvLoan[1],$AdvLoan[2],array_sum($allowance_amount),array_sum($deduction_amount),$t1,ucwords(number_to_words($t1)));
	 


}

$i++;

       }  $kl++;;
}
}else{

 echo "<tr><td colspan=30>No Record Found</td></tr>";
} 
  
//if($fstatus==0){
?>
<!--<tr><td colspan="28"> 
	<?php   $m=date('m')-1;
 
	//if($month!=date('m') && $years!=date('Y') && $Locked!='Y')
	///{?>
 	<?php //} ?>
</td></tr>-->
<?php //}?>
    </table>
<?php // echo DB_num_rows($CHKDailyEntry);
 
//	 if( DB_num_rows($CHKDailyEntry)>0){
	 
	 if($Locked!='Y'){
	 ?>
    	<input type="submit" name="Save"  value="Process Salary" />
		<?php } ?>
 	  <input type="submit" name="UnProcess"  value="UnProcess Salary"  />
     	<div id="foo">
  	  <p align="center">
	
  	</div> 
  <?php //} ?>	
  <a href="#"  onclick="popup('Print-SalaryProcess.php',600,600) ">Click Here to Download</a></p>
  </form>
    
       <?php } ?></div>