<?php include('includes/fun-HRClass.php');
include('includes/fun-php.php');

	$payyear=$_REQUEST['payyear'];
		$paymonth=$_REQUEST['paymonth'];
		$emp_id=$_REQUEST['emp_id'];
 $GetRecord = "Select * from empmaster where  id='".$_REQUEST['emp_id']."' "; 	 
 $ResultData = DB_query($GetRecord,$db);
 if(!$ResultData )
  {
    die('Errror');
  }
  //echo  DB_num_rows($ResultData);
if( DB_num_rows($ResultData))
{

 $RowData = DB_fetch_array($ResultData);

  		  $empcode=$RowData['emp_code'];
		$emp_name=$RowData['emp_name'];
		$department=$RowData['department'];
		$designation=$RowData['designation'];
		$doj=$RowData['doj'];
		$PFno=$RowData['PFno'];
		$ESIno=$RowData['ESIno'];
		$emp_site=$RowData['emp_site'];
		$emp_basic=$RowData['basic_salary'];
		
		
		
		
		
	 $holiday=Count_Holidays($paymonth, $payyear );
	 
	  
 	  
   $GetRecord_process_sal = "Select * from master_process_salary where  emp_id='".$_REQUEST['emp_id']."' and payslip_month='".$paymonth."' and payslip_year='".$payyear."' "; 	 
 $ResultData_process = DB_query($GetRecord_process_sal,$db);
  $Process_RowData = DB_fetch_array($ResultData_process);
$mst_prosal=$Process_RowData['id'];
$basic_salary=$Process_RowData['basic_salary'];
$workingdays=$Process_RowData['workingdays'];
$total_workingday=$Process_RowData['total_workingday'];
$net_earning=$Process_RowData['net_earning'];
$loan_amount=$Process_RowData['loan'];
	  }
?><div style="width:800; margin-left:auto; margin-right:auto;">

<fieldset style="background-color:#FFFFFF;">
<legend style="font-size:16px;">Payslip</legend>
	<h1 style="font-size:18px; color:#666666" align="center"><?php echo stripslashes($_SESSION['CompanyRecord']['CompanyName'])?>.<br />
	<strong style="font-size:12px; font-weight:normal;">C-31 Okhla Indl. Area, Phase - I, Delhi - 20<br />
(PAY SLIP FOR THE MONTH OF <?php echo GetMonth($_REQUEST['paymonth']).'&nbsp;'. $_REQUEST['payyear']?></strong>	</h1>
	<br /><br /> 
	<!-- Table 1 --->  <div style="font-size:11px; font-family:Arial, Helvetica, sans-serif;">
		
		
	<table width="100%" border="0" cellspacing="2" cellpadding="3">
  
  <tr>
    <th width="13%">Emp. Code</th>
    <td width="8%"><input type="text" style="width:60px;"   value="<?php  echo $empcode;?>" readonly="true"/></td>
    <th width="14%">Emp. Name</th>
    <td width="16%"><input type="text" style="width:auto;"   value="<?php  echo $emp_name;?>" readonly="true" /></td>
    <th width="8%">Dept.</th>
    <td width="15%"><input type="text" style="width:100px;"  value="<?php  echo $s->GetFieldValue('deptmaster',"deptcode='". $department."'",'deptname');?>"  readonly="true" /></td>
    <th width="11%">Desig.</th>
    <td width="15%" height="35px"><input type="text" style="width:100px;"   value="<?php  echo $s->GetFieldValue('desigmaster',"desigcode='". $designation."'",'designame');?>"  readonly="true" /></td>
  </tr>
  <tr>
    <th>D.O.J.</th>
    <td><input name="text" type="text" style="width:60px;"  value="<?php  echo ConvertSQLDate($doj);?>" readonly="true" /></td>
    <th>P.F. No.</th>
    <td><input name="text2" type="text" style="width:100px;"   value="<?php  echo $PFno;?>" readonly="true" /></td>
    <th>E.S.I. No.</th>
    <td><input name="text3" type="text" style="width:90px;"   value="<?php  echo $ESIno;?>" readonly="true" /></td>
    <th>Location</th>
    <td height="35px"><input name="text4" type="text" style="width:100px;"  value="<?php  
	 echo $s->GetFieldValue('locations',"loccode='". $emp_site."'",'locationname');?>" readonly="true" /></td>
  </tr>
  <tr>
    <th>Mont. Days</th>
    <td><input name="text5" type="text" style="width:60px;"   value=" <?php  echo $total_workingday;?>" readonly="true" /></td>
    <th>Work. Days</th>
    <td><?php 
	  $weekdays= payable_day($emp_id,$paymonth, $payyear,'WL');
	?>
	<input name="text6" type="text" style="width:100px;"   value="<?php  echo $total_workingday-$weekdays ;?>"readonly="true" /></td>
    <th> H.O.</th>
    <td><input name="text7" type="text" style="width:90px;"  value="<?php  echo $holiday?>"readonly="true" /></td>
    <th>Leave</th>
    <td height="35px"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td>C.L.</td>
        <td>E.L.</td>
        <td>C.S.</td>
      </tr>
      <tr>
        <td> 
		<?php      $emp_CL=payable_emp_leave_apply($emp_id,$paymonth, $payyear,'CL');
		
		
		   
		    $emp_EL= payable_emp_leave_apply($emp_id,$paymonth, $payyear,'EL');
			
			 
		     $emp_CS= payable_emp_leave_apply($emp_id,$paymonth, $payyear,'CS');
			 // not used
			//  payable_day_leavetype($emp_id,$paymonth, $payyear,'CL');
			//$emp_EL= payable_day_leavetype($emp_id,$paymonth, $payyear,'EL');
			// payable_day_leavetype($emp_id,$paymonth, $payyear,'CS');
		?>
		<input name="text8" type="text" style="width:20px;"   value="<?php  echo $emp_CL?>" readonly="true" /></td>
        <td><input name="text8" type="text" style="width:20px;"   value="<?php  echo $emp_EL?>"readonly="true" /></td>
        <td><input name="text8" type="text" style="width:20px;"   value="<?php  echo $emp_CS?>"readonly="true" /></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <th>Loan Bal.</th>
    <td>
	<?php    $loan_management=$s->GetFieldValue('loan_management',"emp_id='".$emp_id."'",'loan_balance');?>
	<input name="text9" type="text" style="width:60px;"  value="<?php echo $loan_management;?>"readonly="true" /></td>
    <th>Pay Days</th>
    <td>
	
	<input name="text10" type="text" style="width:100px;" value="<?php echo $workingdays;?>" readonly="true" /></td>
    <th>Absent</th>
    <td>
	<?php 
	
	$absent= payable_day($emp_id,$paymonth, $payyear,'A');?>
	<input name="text11" type="text" style="width:70px;"   value="<?php  echo $absent;?>"readonly="true" /></td>
    <th>Leave Bal.</th>
    <td height="35px"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td>C.L.</td>
        <td>E.L.</td>
        <td>C.S.</td>
      </tr>
      <tr>
        <td> 
		<?php   $bemp_CL= $s->GetFieldValue('emp_leave',"emp_id='".$emp_id."' and leave_type='CL'",'leave_days');
		 $bemp_EL= $s->GetFieldValue('emp_leave',"emp_id='".$emp_id."' and leave_type='EL'",'leave_days');
		  $bemp_CS= $s->GetFieldValue('emp_leave',"emp_id='".$emp_id."' and leave_type='CS'",'leave_days');
		   
		?>
		<input name="text8" type="text" style="width:20px;"   value="<?php  echo $bemp_CL?>" readonly="true" /></td>
        <td><input name="text8" type="text" style="width:20px;"   value="<?php  echo $bemp_EL?>"readonly="true" /></td>
        <td><input name="text8" type="text" style="width:20px;"   value="<?php  echo $bemp_CS?>"readonly="true" /></td>
      </tr>
    </table></td>
  </tr>
</table>
	<!-- close Table 1 --->	</div>
	<!-- Table 2 --->  <div style="font-size:11px; font-family:Arial, Helvetica, sans-serif;">
	  <!-- close Table 2 --->
</div>

	<!-- Table 3 --->  <div style="font-size:11px; font-family:Arial, Helvetica, sans-serif;">
	  <!-- close Table 3 --->
</div>

	<!-- Table 4 --->  <div style="font-size:11px; font-family:Arial, Helvetica, sans-serif;">
	  <!-- close Table 4 --->
</div>
	<h2 style="font-size:13px; color:#006699; text-align:left;">Salary Details</h2>

	<!-- Table 4 --->  <div style="font-size:11px; font-family:Arial, Helvetica, sans-serif;">
	<table width="80%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="25%" valign="top"><table width="100%" border="0" cellspacing="2" cellpadding="3">
      <tr>
        <th width="20%"><center>
          Earnings
        </center></th>
        <th width="20%"><center>
          Entitled
        </center></th>
      </tr>
      <tr>
        <th width="20%" height="30">Basic</th>
        <td width="20%"  height="30" ><?php  echo  $emp_basic;?></td>
      </tr>
      <?php 
	$earning=array();
		$q1 =DB_query("Select * from allowmaster   ",$db); 
	  while($rq1=DB_fetch_array($q1))
	  { 
		
		 ?>
      <tr>
        <th width="20%" height="30" ><strong><?php echo $rq1['allowcode'];?> </strong></th>

            <?php 
		
	    $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 width="20%" height="30" ><?php   		 echo $row['percentage_value'];	
					$earning[]=$row['percentage_value']; ?>        </td>
        <?php } echo "<tr>";
		} 
	  }	
	  
	  
	
	 
	
  ?>
      <tr>
        <th width="20%">Total</th>
        <td width="20%" ><strong><?php echo array_sum($earning);?></strong></td>
      </tr>
    </table></td>
    <td width="25%" valign="top" >
	
	
	<table width="100%" border="0" cellspacing="2" cellpadding="3">
      <tr>
        <th width="9%">Payable      </th>
      </tr>
      <tr>
        <td width="20%" height="30" ><?php  echo $basic_salary;?></td>
      </tr>
      <?php 
	$earning=array();
		$q1 =DB_query("Select * from allowmaster   ",$db); 
	  while($rq1=DB_fetch_array($q1))
	  { 
 		 ?>
      <tr>
			<?php 
			 
			$query =DB_query("Select * from payslip_salary where emp_id='".$emp_id."' and allowance_id='".$rq1['id']."' and mst_prosal='".$mst_prosal."' and allowance_type='A'",$db);
			if(DB_num_rows($query))
			{
			 while($row=DB_fetch_array($query))
			 {
			?>
			 
			<td width="20%" height="30" >
			
			
			<?php   echo $row['allowance_amount'];	
						$earning[]=$row['allowance_amount']; ?>        </td>
			<?php } 
			} 
			else{
			echo "<td width='20%' height='30' >222</td>";
			}
		echo "<tr>";
		 
	  }	
   ?>
      </tr>
      <tr>
        <td width="9%" ><strong><?php echo array_sum($earning);?></strong></td>
      </tr>
    </table></td>
     <td width="25%" valign="top">
	 <table width="100%" border="0" cellspacing="2" cellpadding="3">
       <tr>
         <th width="18%"><center>
Deduction
         </center></th>
         <th width="9%"><center>
           Amount
         </center></th>
       </tr>

       <?php 
	$deduction=array();
	  $query_allowances =DB_query("Select * from deduction_master   ",$db); 
	  while($row_allowances=DB_fetch_array($query_allowances))
	  { 
 		 ?>
       <tr> 
         <th width="20%" height="30"><strong><?php echo $row_allowances['code'] ;?> </strong></th>
         <?php  
		
	    $query =DB_query("Select * from payslip_salary where emp_id='".$emp_id."' and allowance_id='".$row_allowances['id']."' and mst_prosal='".$mst_prosal."'  and allowance_type='D'",$db);
		if(DB_num_rows($query))
		{
       	 while($row=DB_fetch_array($query))
	 	 {
       	?>
         <td width="20%" height="30" ><?php   		 echo $row['allowance_amount'];	
					$deduction[]=$row['allowance_amount']; ?>         </td>
         <?php }
		}  
		 else{
			echo "<td width='20%' height='30' >222</td>";
			}
		  echo "<tr>";
		
	  }	
 	
  ?>
       </tr>
       <tr>
         <th width="18%">Total</th>
         <td width="9%" ><strong><?php echo array_sum($deduction);?></strong></td>
       </tr>
       <tr>
         <th>Loan  </th>
         <td ><?php  echo $loan_amount;?>&nbsp;</td>
       </tr>
     </table>	 </td>
  </tr>
  <tr>
  <th ><strong>NetPay</strong></th>
  <td colspan="2"><?php echo $net_earning ;?></td>
  </tr>
</table>

    <!-- close Table 4 --->
    </div>
</fieldset>
</div>