<?php //error_reporting(0);
$PageSecurity = 3;
 include ('includes/session.inc');
  include ('includes/function_lib.php');
  include('includes/fun-php.php');
include('includes/fun-HRClass.php');
 $years=$_SESSION['payyear'];
$month=$_SESSION['paymonth'];	
$_SESSION['payyear']=$years;
$_SESSION['paymonth']=$month;
 global $db;
  echo '<link href="'.$rootpath. '/css/'. $_SESSION['Theme'] .'/default.css" rel="stylesheet" type="text/css" />';
?>
<script type="text/javascript" language="javascript">
  function toggle_visibility(id) {
	
	 
       var e = document.getElementById(id);
	       e.style.display = 'none';
		       //alert(e.style.display);
			   window.print();
    }

</script>
 <h2><center><?php echo stripslashes($_SESSION['CompanyRecord']['CompanyName']);?><br />Register of Wages</center></h2>
	 
	  <table width="100%" border="0" align="right">
  	<tr >
	<td width="80%">Salary Wages Sheet For The M/O <?php  echo GetMonth($month).',&nbsp;'.$years?></td>
	<td width="10%"><div align="right">Run Date:</div></td>
    <td width="10%" ><?php echo date('d/m/Y')?></td></tr>
	<tr><td></td>
	<td><div align="right">Run Time:</div></td>
	<td ><?php  echo date("H:i:s"); ?></td>
  </tr>
</table>

 
 <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($_SESSION['emptype']=='Temporary'){ $colspan="colspan='4'";}?>
		<td <?php echo $colspan;?>><?php if($_REQUEST['emptype']=='Temporary'){?>
		  <div align="center"><b>OT</b>
		    <?php }else  ?>
	    &nbsp;</div></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 Loan </strong></td>      <td><strong>Adv Bal </strong></td>    
     <td><strong>Total Deduction</strong></td>
      <td><strong>
        <?php if($_SESSION['emptype']=='Temporary')echo "Gross Wages"; else echo "Net Pay";?>
      </strong></td>
     <?php if($_SESSION['emptype']=='Temporary'){?> 
	 <td><strong>OT Hours</strong></td>
    <td><strong>OT amount</strong></td>
    <?php } ?>
    <?php if($_SESSION['emptype']=='Temporary'){?> 
	<td><strong>Net Pay</strong></td>
	<?php } ?>
     <td ><strong>Signature</strong></td>  
        </tr>
        <?php
		
       $filter=$_SESSION['filter1'];
	   $acg_total_allownace=array();
	   $acg_total_deduction=array();
	   $arr_OT_amount=array();
		$arr_OTnetpay=array();
  	    $GetRecord = "Select * from empmaster where  $filter  order by designation ";
  	  	 //  echo $GetRecord;
     $ResultData = DB_query($GetRecord,$db);
	  // echo DB_num_rows($ResultData);
	  $fstatus=1;
	  $i=1;$kl=0;
   	  while($RowData = DB_fetch_array($ResultData))
   	  {
	  $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><?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 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');?>&nbsp;</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));
		$arr_basic[]=$gbasic
		 ?>		</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);*/
	
		
 		 ?>		 </td>
       	 <?php }
		}else{echo "<td>-</td>";}
	  }	 
	  
	  	$acg_total_allownace[]=$allowance_amount;
?>
<td><?php  echo $RowData['gross_sal']."<br>-----<br>";echo $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*/
			 
	 		 ?>		 </td>
       	 <?php }
		}else{echo "<td>-</td>";}
	  }
	  $acg_total_deduction[]=$deduction_amount;	
?>
  		 <td><?php   $AdvLoan=advance_loan($emp_id,$month,$years);
		 echo ($AdvLoan[0]>0?$AdvLoan[0]:'-');
		 $arr_advloan[]=($AdvLoan[0]>0?$AdvLoan[0]:0);
		 
		 
		 ?></td>
		 <td>  <?php $x=EmpBalanceAmount($emp_id,$AdvLoan[1],$month);
		  
		 $t=$x-$AdvLoan[0];
		  echo ($t>0?$t:'-');
		   $arr_advbalance[]=($t>0?$t:'-');
		 ?></td> 
	     <td>&nbsp;<?php echo round(array_sum($deduction_amount),0)+$AdvLoan[0]; 	?></td>
        <?php  $arr_total_deducation[]=round(array_sum($deduction_amount),0)+$AdvLoan[0];?>
		 
		 <?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);
		$arr_netpay[]=($netpayable!=0?round($netpayable):0);
		
		?>		</td>
          <?php //echo $OT=round(GetOverTime($emp_id,$month,$years),0);
          	if($over_timestatus=='Yes')
			 	$OT=GetOverTime_Calculation($emp_id,$month,$years, $_SESSION['emp_salprocess_site']);
				 else
			  	 $OT='-';
          	  // $OT=round(GetOverTime($emp_id,$month,$years),0);
           	 ?>
       <?php if($_SESSION['emptype']=='Temporary'){?>
	    <td>
		<?php  echo  $OTHOUR=getOTHours($emp_id,$month,$years);?>  &nbsp;      </td>
		<td>  
		<?php 
	    		 echo $OT;
			$arr_OT_amount[] =$OT;
		?>  &nbsp;       </td><?php }?>
		 
		 
		 
		 
		 <?php if($_SESSION['emptype']=='Temporary'){?> 
		  <td><?php   $t1=$OT+$netpayable;
          	echo round($t1);
		 $arr_OTnetpay[]=$t1;
			?> </td><?php } ?>
         <td width="20%">&nbsp;</td>
		    
<?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; 
      </tr>
      
       <?php 
       
 

}

$i++;

       }
} 
  

?>
<tr bgcolor="#FFFFFF">
        <td>&nbsp;</td>
        <td >&nbsp;</td>
        <td >&nbsp;</td>
        <td><strong>Total</strong></td>
        <td >&nbsp;</td>
        <td >&nbsp;</td>
        <td >&nbsp;</td>
        <td ><?php   // echo "<pre>"; print_r($acg_total_allownace);?></td>
        <td ><?php echo array_sum($arr_basic);?>&nbsp;</td>
		
       <?php   $klp=0;
	   $grandtotal=array();
 	   	$q1 =DB_query("Select * from allowmaster   ",$db); 
	  while($rq1=DB_fetch_array($q1))
	  {
	   $p=array();
	    for($kl=0;$kl<count($acg_total_allownace);$kl++)
	   {
	     $p[]=$acg_total_allownace[$kl][$klp];;
 	   } 
 	   $grandtotal[]=array_sum($p);
 	   ?>
 	    <td ><?php		// echo "<pre>"; print_r($p); 
		echo		   array_sum($p);
		?> &nbsp;</td>
		<?php  $klp++; }		 ?>
		
		
		
        <td><?php  echo array_sum($grandtotal)+array_sum($arr_basic)?></td>
      <?php  $klp1=0;
	  $q2 =DB_query("Select * from deduction_master   ",$db); 
	  while($rq2=DB_fetch_array($q2))
	  { 
	    $p=array();
	    for($kl=0;$kl<count($acg_total_deduction);$kl++)
	   {
	     $p[]=$acg_total_deduction[$kl][$klp1];;
 	   } 
	   
	    $grand_deduction_total[]=array_sum($p);

		?>
 		    <td ><?php // echo "<pre>"; print_r($p); 
			
			
				echo   array_sum($p);?> &nbsp;</td>
		<?php  $klp1++; } ?>
		
        <td><?php  echo array_sum($arr_advloan)?>&nbsp;</td>
		    <td><?php  echo array_sum($arr_advbalance)?>&nbsp;</td>
      <td><?php  echo array_sum($arr_total_deducation)?>&nbsp;</td>
	   <td><?php echo  array_sum($arr_netpay);?></td>
	   <?php if($_SESSION['emptype']=='Temporary'){?> 
		  <td>&nbsp;</td>
		  <td><?php  echo array_sum($arr_OT_amount)?>&nbsp;</td>
		  
		  <?php } ?>
	   <td><?php 	   echo  array_sum($arr_OTnetpay);?></td> 
        <td>&nbsp;</td>
   </tr>
</table>
  
  
   <div id="foo"><p align="center">
<a href="#" onclick="javascript:toggle_visibility('foo');" >Print</a>    
</p>
</div>
 