<center> <h2>Pay Slip Salary</h2>
</center>
<?php //error_reporting(0);
include('includes/fun-php.php');
include('includes/fun-HRClass.php');
$modid=$_REQUEST['modid'];
$frmid=$_REQUEST['frmid'];

$rurl="index.php?route=HRModule/master_payslip&action=View&modid=".$modid."&frmid=".$frmid."";
 $rurl_view="index.php?route=HRModule/View_master_payslip&action=View&modid=".$modid."&frmid=".$frmid."";

   





function OThours($empid,$month, $years)
{
	global $db;
	     $GetRecord = "Select sum(ot_hrs) as OThours from daily_attendance where employee='".$empid."' and  month(attendance_date)='".$month."'  and  year(attendance_date)='".$years."'  group by year(attendance_date) ,month(attendance_date) ";	   	   
       $ResultData = DB_query($GetRecord,$db);
	  // echo DB_num_rows($ResultData);
   	  $RowData = DB_fetch_array($ResultData);
	   return( $RowData['OThours']);
}
$curernt_year=$_REQUEST['payyear'];
$curernt_month=$_REQUEST['paymonth'];
//echo $curernt_month.$curernt_year."is on a " . date("w", mktime(0, 0, 0, 7, $curernt_month, $curernt_year));
?>     
 

<?php


  
  
 

if($_REQUEST['action']=='Edit'  )
  {
	   $paystatus=true;  
	     
		$chkjoining=$s->getField('empmaster','id', $_REQUEST['emp_id'] ,'doj');
		 $GetSalRecord = "Select * from master_process_salary where id='".$_REQUEST['id']."'  ";
		  $ResultSalData = DB_query($GetSalRecord,$db);	   
   	     $RowSalData = DB_fetch_array($ResultSalData);
		 $years=$RowSalData['payslip_year'];
	     $month=$RowSalData['payslip_month'];
		 $OTAmount	 =$RowSalData['OTAmount'];
		 $OTBasicAmount  	 =$RowSalData['OTBasicAmount'];
		 $OThours	 =$RowSalData['OThours'];
		 $advancetax	 =$RowSalData['advancetax'];
		 $loan	 =$RowSalData['loan'];$ptax	 =$RowSalData['ptax'];
		  $net_earning	 =$RowSalData['net_earning'];
		  $total_deduction	 =$RowSalData['total_deduction'];
		 $netpay	 =$net_earning- $total_deduction;
		 $wordamt	 =$RowSalData['wordamt'];
		 $addinsal=$RowSalData['addinsal'];
		   $Locked=$RowSalData['locked'];
		 
		 
 }	  
     
	if($paystatus)
	{
	 $net_earning=array() ;
	 	  $GetRecord = "Select A.id as EmpID,A.emp_code,A.emp_name,
	A.department,A.designation,B.basic_salary,A.emp_weekly_off,A.gross_sal,
	B.payslip_month,B.payslip_year,B.workingdays,B.net_earning  ,B.total_deduction  ,B.netpay  ,B.wordamt  ,B.id as MSPID  from empmaster A ,master_process_salary B where  A.id='".$_REQUEST['emp_id']."'  and A.id=B.emp_id and   B.payslip_month='".$month."' and  B.payslip_year ='".$years."'  ";	  
		 	   
			   
			

       $ResultData = DB_query($GetRecord,$db);
	  // echo DB_num_rows($ResultData);
   	   $RowData = DB_fetch_array($ResultData);
	   $emp_id=$RowData['id'];
	   $emp_code=$RowData['emp_code'];
	    $emp_name=$RowData['emp_name'];
	   $fh_name=$RowData['fh_name'];
	   $department=$RowData['department'];
	   $designation=$RowData['designation'];
	   $basic_salary=$RowData['basic_salary'];
	   $net_earning[]=  $basic_salary ;
	      $emp_weekly_off=$RowData['emp_weekly_off'];;
	   $basic_perc=$RowData['basic_perc'];;
	   $gross_sal=$RowData['gross_sal'];;
	 if($_REQUEST['action']!='Edit')  {
	 $OThours=OThours($emp_id,$month, $years);
	 if($OThours=='')
	 $OThours=0;
     $OTBasicAmount=0;
	 $OTAmount=0;
	 $loan	 =0.00;;
	 $ptax	 =0.00;;
	 $advancetax	 =0.00;;
	 $addinsal='N';
	 $Locked='N';
	 }
	 $lt=0;
	   
	     
 
?>
<form action="" method="post">
<input type="hidden" name="emp_id" value="<?php echo $emp_id; ?>"/>
<input type="hidden" name="payslip_year" value="<?php echo $years; ?>"/>
<input type="hidden" name="payslip_month" value="<?php echo$month; ?>"/>
<input type="hidden" name="basic_salary" value="<?php  echo $basic_salary; ?>"/>
<table  border="1" width="80%" cellpadding="0" cellspacing="0">
<tr>
<td  colspan="3"><h3><div align="center"><?php echo stripslashes($_SESSION['CompanyRecord']['CompanyName'])?></div></h3></td>
</tr>



 <tr>
  <td width="33%" >&nbsp;</td> 
  <td width="33%"><strong>Month of: 
    <?php  echo GetMonth($month)."&nbsp;&nbsp;".$years;?> </strong></td>
  <td width="33%" ><strong> </strong></td>
</tr>
<tr>
  <td width="33%" >&nbsp;</td> 
  <td width="33%"><strong>Earning</strong></td><td width="33%" ><strong>Deductions</strong></td>
</tr>
 <tr>
  <td valign="top" >
 	 <table  border="0" width="100%" cellpadding="0" cellspacing="2">
     <tr>
     <td width="50%">Employee Code</td>
      <td width="50%"><?php echo  $emp_code; ?></td>
     </tr>
     <tr>
       <td >Employee Name</td>
       <td><?php echo  $emp_name; ?></td>
     </tr>
     <tr>
       <td >Father's Name</td>
        <td><?php echo  $fh_name; ?></td>
     </tr>
     <tr>
       <td >Department</td>
       <td><?php echo  $department; ?></td>
     </tr>
     <tr>
       <td >Designation</td>
       <td><?php echo  $designation; ?></td>
     </tr>
     <tr>
       <td >Working Days</td>
       <td><?php  
	  echo  $workingdays= cal_days_in_month(CAL_GREGORIAN, $month, $years);
	 // echo "<br>";
	   $one_day_sal= round(($gross_sal/$workingdays),2);?>
      <input name="workingdays"  id="workingdays" type="hidden" value="<?php echo $workingdays;?>" />
      </td>
     </tr>
     <tr>
       <td>Present Days</td>
       <td><?php 
      $payable_day= payable_day($emp_id,$month, $years,'P');
	 
       echo $payable_day; ?></td>
     </tr>
     <tr>
       <td >Holiday </td>
       <td>
       	<?php  echo  $holiday=Count_Holidays($month, $years );
       ?>
       	 </td>
     </tr>
     
     <?php 
   $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;
   ?>
      <tr>
       <td ><?php echo $leave_row['leavename']; ?> </td>
       <td><?php  echo ($leave_val==''?'0':$leave_val) ;?></td>
     </tr> 
  
    <?php } ?> 
     
      <tr>
       <td >weekly Off </td>
       <td>
       	<?php  
		  echo  $weeklyoff= CountSatSun($month, $years,$emp_weekly_off );
		   $lt=$lt+$weeklyoff;;
       	 ?> </td>
     </tr>
     <tr>
       <td >Absent </td>
       <td>
       	<?php //echo $lt; 
       $absent= payable_day($emp_id,$month, $years,'A');    	
       	?><?php echo payable_day($emp_id,$month, $years,'A'); ?></td>
     </tr>
      <tr>
       <td >Absent without information </td>
       <td>
       	<?php 
       	// $workingdays."=".$payable_day."=".$holiday."=".$lt;
        	 $absent_total_days =$workingdays-$absent-($payable_day+$holiday+$lt ); 
             $absent_withoutinfo=$workingdays -($payable_day+$holiday+$lt );  
	        $ACGpaydays=$workingdays- $absent_withoutinfo;
		// echo $ACGpaydays.'=='.$one_day_sal;
	        $paid_gross=$ACGpaydays*$one_day_sal;
       	?>
    <?php echo $absent_total_days; ?></td>
     </tr>
      <tr>
       <td >Payable Days</td>
       <td>
    
       	<?php echo $ACGpaydays; ?></td>
     </tr>
     </table>
  
  </td> 
  <td  valign="top"><table  border="0" width="100%" cellpadding="0" cellspacing="2">
    <tr>
      <td width="50%">Basic Salary
      	<?php // echo $gross_sal;?>
      	</td>
      <td width="50%">
      	<?php //$gbasic= round(($basic_perc*$paid_gross*.01),2); ?>
         	<?php $gbasic=$basic_salary;
			
			
			echo $gbasic; ?>
      	</td>
    </tr>
       <?php
	  
	 $query_allowances =DB_query("Select * from allowmaster",$db); 
	 $j=0;
	  while($row_allowances=DB_fetch_array($query_allowances))
	  {
	 
  		         $query22 =DB_query(" Select * from  payslip_salary   where   allowance_type='A' and   mst_prosal='".$RowData['MSPID']."'   and allowance_id='".$row_allowances['id']."'  ",$db); 
		   while( $row22=DB_fetch_array($query22))
		  {
	 		    
		   
	  ?>
          <tr>
      <td> 
      	<?php echo $row_allowances['allowcode'];?>      </td>
       <td> 
	<?php  
	$net_earning[]= $row22['allowance_amount'] ;
	echo ($row22['allowance_amount']!=0?$row22['allowance_amount']:0);  
       ?>      </td>
   	 </tr>
  
    <?php
	}
	
	 $j++; } ?>
    
    <tr>
    <td>Other Earning:<br />Add in Sal: </td>
        <td> <br />
        	 
        	<?php echo ($addinsal=='Y'?'Yes':'No') ;?>
         </td>
    </tr>
    <tr>
      <td>OT Hours</td>
      <td>
       <?php echo  $OThours;?>
      
      </td>
    </tr>
    <tr>
      <td>OT Basic</td>
      <td>
      <?php	 
      echo  $OTBasicAmount;     ?>
      </td>
    </tr>
     <tr>
      <td>OT AMT</td>
      <td> 
      	<?php echo $OTAmount; ?>
      </td>
    </tr>
    
    
  </table></td>
  
  
  <td valign="top"><table  border="0" width="100%" cellpadding="0" cellspacing="2">
    
        <?php  if($_REQUEST['action']!='Edit'  ){$total_deduction=0;}
	  $ded_sql=DB_query("Select * from deduction_master",$db); 
	 $k=0;
	  while($ded_row=DB_fetch_array($ded_sql))
	  {
	  
  $query22 =DB_query(" Select * from  payslip_salary   where   allowance_type='D' and   mst_prosal='".$RowData['MSPID']."'   and allowance_id='".$ded_row['id']."'  ",$db); 

 		         while( $row22=DB_fetch_array($query22)){
	  ?>
      <tr>
      <td> 
      	<?php echo $ded_row['code'];?>      </td>
       <td> 
	<?php  echo ($row22['allowance_amount']!=0?$row22['allowance_amount']:0);  
       ?>      </td>
   	 </tr>
    <?php } $k++;} ?>
     <tr>
    <td>Loan:</td>
    <td> 
 <?php 
	echo $loan;
 ?>
</td>

    </tr>
    <tr>
    <td>Advance:</td>
    <td><?php  echo $advancetax;   ?>
    	  </td>
    </tr>
    
     <tr>
    <td>P.Tax:</td>
    <td> <?php echo $ptax ?> 
    	</td>
    </tr>
  </table></td>
</tr>


<tr>
<td><table width="100%"><tr><td width="50%">Total Earning: </td><td  width="50%">
<?php  echo $RowData['net_earning'] ;?>

 

<?php  echo $RowData['net_earning']  ;?></td></tr></table></td>  
<td><table width="100%"><tr><td width="50%">Net Earning: </td><td  width="50%">
<?php echo   array_sum($net_earning) ?>
 </td></tr></table></td>  

<td><table width="100%"><tr><td width="50%">Total Deductions: </td><td  width="50%">
 <?php echo   $RowData['total_deduction']?>
</td></tr></table></td>  

 
</tr>
<tr>
 <td colspan="2"><div align="right">Net payable:</div></td>
<td><?php 

   $netpayable=  array_sum($net_earning)-$total_deduction;?>
   <?php echo $netpayable;  ?>

</td>
</tr>
<tr>
<td colspan="3">

<table width="100%">
<tr>
 <td width="14%" >Inwords</td>
<td width="86%" colspan="2">
	 <?php  echo ucwords(number_to_words($netpayable)); 
 ?>
&nbsp;</td>
</tr>
<tr>
 <td >Received PaySlip</td>
<td colspan="2">&nbsp;</td>
</tr>

<tr>
 <td >Signature</td>
<td colspan="2"> <div align="right" style="padding-right:20px;">Authorised Signature</div></td>
</tr>



</table>
</td></tr>
</table>
<a href="#"   onclick='popup("PaySlip.php?id=<?php echo $_REQUEST['id']?>&emp_id=<?php echo $_REQUEST['emp_id']?>&action=Edit",600,600)'>Print</a>
</form>
<?php 
	}
	
?>

 
 