<?php 
session_name('CAKEPHP'); session_start();
$PageSecurity = 1;
include('config.php');
include('includes/ConnectDB.inc');
include('includes/function_lib.php');
include('includes/LanguageSetup.php');
include('includes/DateFunctions.inc');
include('includes/fun-php.php');
include('includes/fun-HRClass.php');


    global $db;
	$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'];
		$dob=$RowData['dob'];
		$bankac=$RowData['bank_account'];
		$bankname=$RowData['bank_name'];
		
	 	$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'];
		$mst_emp_id=$Process_RowData['emp_id'];
		
		$basic_salary=$Process_RowData['basic_salary'];
		$workingdays=$Process_RowData['workingdays'];
		$payslip_month = $Process_RowData['payslip_month'];
		if($payslip_month == '1' || $payslip_month == '3' || $payslip_month == '5' || $payslip_month == '7' || $payslip_month == '8' || $payslip_month == '10' || $payslip_month == '12')
			$payslip_month = '31';
		if($payslip_month == '2')
			$payslip_month = '28';
		if($payslip_month == '4' || $payslip_month == '6' || $payslip_month == '9' || $payslip_month == '11')
			$payslip_month = '30';
		$total_workingday=$Process_RowData['workingdays'];
		$net_earning=$Process_RowData['net_earning'];
		$loan_amount=$Process_RowData['loan'];
		$advance_balance=$Process_RowData['advance_balance'];
		$rev_sal_amt=$Process_RowData['rev_sal_amt'];
	 }
  $Compamies=DB_query("select * from companies",$db);
  $CompamiesRow=DB_fetch_array($Compamies);
  $sql1 = "SELECT * FROM companies where CompanyId='".$_SESSION['ACGCompanyId']."'";
  $sqlres = DB_query($sql1,$db);
  $companyRow = DB_fetch_array($sqlres);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
  <meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
<title>Payslip Report</title>

<script type="text/javascript" language="javascript">
  function toggle_visibility(id) 
  {
    var e = document.getElementById(id);
	e.style.display = 'none';
	window.print();
  }
</script>

<style type="text/css" media="print">
  @page port {size: portrait;}
@page land {size: landscape;}
 .portrait {page: port;}
.wrapper {page: land;}

</style>

<style type="text/css"> 
@print {size: portrait; margin:10px;}

@media print{
body{ margin:0px; padding:0px;  font-size:12px; line-height: 18px; font-family: Arial, Helvetica, sans-serif; color:#000; font-weight:normal;}

h1,h2,h3,h4,h5,p{ margin:0px; padding:0px;}
p{ text-align:left;}

h1{
  font-size: 20px; line-height: 24px;
  font-weight:normal;
  font-family:Arial, Helvetica, sans-serif !important;
}
h2{
  font-size: 18px; line-height: 22px;
  font-weight:normal;
  font-family:Arial, Helvetica, sans-serif !important;
}
thead{display: table-header-group;}
.wrapper{width:99%; height: auto; float:left; border:#000000 1px solid; border-bottom:#000000 1px solid;}
.div_first, .div_first .full{
  width: 100%; height: auto;
  /*border-bottom: #000000 1px solid;
  border-top: #000000 1px solid;*/
  /*border-left: #000000 1px solid;
  border-right: #000000 1px solid;*/
  float: left; position: relative;
}
 .div_first .left
  {
    width:18%; text-align:left; height:auto; vertical-align:middle; height:auto; padding: 1%; float:left;
  }
  .div_first .middle
  {
    width:58%; text-align:center; padding: 1%; margin:0 auto; float: left;
  }
  .div_first .right
  {
    width:18%; text-align:right; padding: 1%; float: left;
  }

.div_first .full{text-align: center; border: 0;}
.div_second, .div_third, .div_forth{
  width: 100%;
  height:auto;
  border-top: #000000 1px solid;
  /*border-bottom: #000000 1px solid;*/
  /*border-left: #000000 1px solid;
  border-right: #000000 1px solid;*/
  float: left;
}
.div_second table tr th, .div_second table tr td{border-right:#000000 0px solid; border-bottom:#000000 1px solid;}
.div_second table tr th{text-align: left;}
.div_second table tr th:last-child, .div_second table tr td:last-child{border-right:0;}
.div_second table tr:last-child td{border-bottom:0;}
.div_second table tr td > table tr td{border-right:#000000 1px solid; border-bottom:#000000 1px solid;}
.div_second table tr td > table tr td:last-child{border-right:0;}
.div_second table tr td > table tr:last-child td{border-bottom:0;}

.div_third table tr th, .div_third table tr td{ border-bottom:#000 1px solid; border-right:#000 1px solid;}
.div_third table tr th{background-color:transparent; text-align: left;}
.div_third table tr th:last-child, .div_third table tr td:last-child{border-right:none;}
.div_third table tr:last-child td{border-bottom:none;}

.div_forth table tr th, .div_forth table tr td{ border-bottom:#000 1px solid; border-right:#000 1px solid;}
.div_forth table tr th{background-color: #ccc; text-align: left;}
.div_forth table tr th:last-child, .div_forth table tr td:last-child{border-right:none;}
.div_forth table tr:last-child td{border-bottom:none;}

.f12{ font-weight: bold; color:#000; font-size:12px;}
.f11{color:#000; font-size:12px; font-weight: normal; line-height:18px;}
.f14{color:#000; font-size:18px;}
.mt26{margin-top:4px; width:90%;}
.mt27{margin-top:0px; width:70%;}
.mt28{margin-top:0px; width:100%;}
.border_top{border-top:#000 1px solid;}
.border_bottom{border-bottom:#000 1px solid;}
.wdt1{width:8%;}
.wdt2{width:100px;}
.wdt3{width: 66px;}
.wdt4{width: 80px;}
.wdt5{width: 52px;}
.wdt6{width: 60px;}
}

@media screen{
/* CSS Document */
body{ margin:0px; padding:0px; background-color:#fff; font-size:12px; line-height: 18px; font-family: Arial, Helvetica, sans-serif; color:#000; font-weight:normal;}
h1,h2,h3,h4,h5,p{ margin:0px; padding:0px;}
p{ text-align:left;}

#foo{width:1070px; height: auto; margin:0px auto;}
.wrapper{width:1070px; height: auto; margin:10px auto; border-top:#000000 1px solid;}

h1{
  font-size: 24px; line-height: 28px;
  font-weight:bold;
  font-family:Arial, Helvetica, sans-serif !important;
}
h2{
  font-size: 18px; line-height: 22px;
  font-weight:normal;
  font-family:Arial, Helvetica, sans-serif !important;  
}
.div_first, .div_first .full{
  width: 100%; height: auto;
  /*border-bottom: #000000 1px solid;
  border-top: #000000 1px solid;*/
  border-left: #000000 1px solid;
  border-right: #000000 1px solid;
  float: left; position: relative; display: table;
}
.div_first .full{text-align: center; border: 0; margin:10px 0 0;}
.div_first .left, .div_first .middle, .div_first .right{float: left; display: table-cell; vertical-align: middle;}
.div_first .left
{
  width:18%; text-align:center; height:auto; vertical-align:middle; padding: 1%; 
}
.div_first .middle
{
  width:58%; text-align:center; padding: 1%; position: relative; margin:0 auto;
}
.div_first .right
{
  width:18%; text-align:center; padding:1%; 
}
.div_second, .div_third, .div_forth{
  width: 100%; height: auto;
  /*border-bottom: #000000 1px solid;*/
  border-top: #000000 1px solid;
  border-left: #000000 1px solid;
  border-right: #000000 1px solid;
  float: left;
}
.div_second table tr th, .div_second table tr td{border-right:#000000 0px solid; border-bottom:#000000 1px solid;}
.div_second table tr th{background-color: #ccc; text-align: left;}
.div_second table tr th:last-child, .div_second table tr td:last-child{border-right:0;}
/*.div_second table tr:last-child td{border-bottom:0;}*/
.div_second table tr td > table tr td{border-right:#000000 1px solid; border-bottom:#000000 1px solid;}
.div_second table tr td > table tr td:last-child{border-right:0;}
.div_second table tr td > table tr:last-child td{border-bottom:0;}

.div_third table tr th, .div_third table tr td{ border-bottom:#000 1px solid; border-right:#000 1px solid;}
.div_third table tr th{background-color: #ccc; text-align: left;}
.div_third table tr th:last-child, .div_third table tr td:last-child{border-right:none;}
.div_third table tr:last-child td{border-bottom:none;}

.div_forth{border-bottom:#000000 1px solid;}

.f12{font-weight: bold; color:#000; font-size:12px;}
.f11{ color:#000; font-size:12px; font-weight: normal; line-height:18px;}
.f14{ color:#000; font-size:18px;}
.mt26{margin-top:4px; width:90%;}
.mt27{margin-top:0px; width:100%;}
.mt28{margin-top:0px; width:90%;}
.border_top{border-top:#000 1px solid;}
.border_bottom{border-bottom:#000 1px solid;}
.wdt1{width:10%;}
.wdt2{width:180px;}
.wdt3{width: 66px;}
.wdt4{width: 120px;}
.wdt5{width: 52px;}
.wdt6{width: 70px;}
}
</style>
</head>
<body>
 
<div id="foo">
  <p style="text-align:right;"><input type="button" onclick="javascript:toggle_visibility('foo');" value="Print" /></p>
</div>
<div class="wrapper">
<div class="div_first">
<?php $logoImage=($CompamiesRow['CompanyLogo']=='')?'electra.jpg':$CompamiesRow['CompanyLogo']; ?>
      <div class="left"><img src="Setup/CompanyLogo/<?php echo $logoImage;  ?>" class="mt26" /></div>
      <div class="middle"><?php 
    if($CompamiesRow['CompanyName']!="") {echo "<h1>".$CompamiesRow['CompanyName']."</h1>"; } else { echo "";}
    
    if($InoRow['deladd1']!="") { echo $InoRow['deladd1']; } else { echo "";}
    if($InoRow['deladd2']!="") { echo ", ". $InoRow['deladd2']; } else { echo "";}
    if($InoRow['deladd3']!="") { echo ", ". $InoRow['deladd3']; } else { echo "";}
    if($InoRow['city']!="") { echo ", ". $s->getFieldValue("city_master", "id='".$InoRow['city']."'", "city"); } else { echo "";}
    if($InoRow['pincode']!="") { echo " - ".$InoRow['pincode']; } else { echo "";}
    if($InoRow['state']!="") { echo ", ". $s->getFieldValue("state_master", "id='".$InoRow['state']."'", "state"); } else { echo "";}
    if($InoRow['country']!="") { echo ", ". $s->getFieldValue("country_master", "id='".$InoRow['country']."'", "country");
    
     } else { echo "";}
    ?>
     <div class="full"><span class="f11"><?php echo "Phone No.:".$CompamiesRow['Phone'].",   Fax No.: ".$CompamiesRow['fax'].", Email ID.: ".$CompamiesRow['email'].",   Website: ".$CompamiesRow['website']; ?><br>
  <?php  echo $_SESSION['mess']; ?>
  </span></div>
      <h2>PAY SLIP FOR THE MONTH OF <?php echo GetMonth($_REQUEST['paymonth']).'&nbsp;'. $_REQUEST['payyear']?></h2>
      </div>
      <div class="right"></div>
</div>

<div class="div_second">	
<table width="100%" align="center" border="0" cellpadding="3" cellspacing="0">
  <tr class="f11">
    <td width="13%" class="f12">Emp Code</td>
    <td width="26%"><?php echo $empcode;?></td>
    <td width="13%" class="f12">Emp Name</td>
    <td width="26%"><?php echo $emp_name;?></td>
    <td width="13%" class="f12">Month Days</td>
    <td><?php echo $payslip_month;?></td>
  </tr>
  <?php 
  $present_query = "select * from emp_leave_apply where empid = '".$_REQUEST['emp_id']."' and month(approved_date_from) = '".$paymonth."' and approve_status='Y'";
  $present_query_res = DB_query($present_query,$db) or die(DB_error());	
  $cl_days = 0;
  $el_days = 0;
  $sl_days = 0;
  while($present_query_result = DB_fetch_array($present_query_res))
  {
  	$leave_type = $present_query_result['leave_type'];
	$select_type_query = "select * from leavemaster where id = '".$leave_type."'";
	$select_type_res = DB_query($select_type_query,$db) or die(DB_error());
	$select_type_result = DB_fetch_array($select_type_res);
	
	if($select_type_result['leavecode'] == "CL")
		$cl_days = $cl_days + $present_query_result['total_approval_days'];
		
	if($select_type_result['leavecode'] == "EL")
		$el_days = $el_days + $present_query_result['total_approval_days'];
		
	if($select_type_result['leavecode'] == "SL")
		$sl_days = $sl_days + $present_query_result['total_approval_days'];
		
  }
  ?>

 <?php
 	$payable_day_query = "select COUNT(DISTINCT attendance_date) AS AttDate from daily_attendance where employee='".$_REQUEST['emp_id']."' and month(attendance_date)='".$_REQUEST['paymonth']."' and  year(attendance_date)='".$_REQUEST['payyear']."' and pres_abs='P'";
	$query_leave_res = DB_query($payable_day_query,$db) or die(DB_error());
	$query_leave_result = DB_fetch_array($query_leave_res);
	  $payable_day = $query_leave_result['AttDate'];	
	
	//$GetRecord = "Select sum(total_approval_days) AS AttDate  from emp_leave_apply where empid='".$_REQUEST['emp_id']."' and  month(approved_date_from)='".$_REQUEST['paymonth']."' and  year(approved_date_from)='".$_REQUEST['payyear']."'";	
	
	
	 $leave_day_query = "Select sum(total_approval_days) AS AttDate  from emp_leave_apply where empid='".$_REQUEST['emp_id']."' and  month(approved_date_from)='".$_REQUEST['paymonth']."' and  year(approved_date_from)='".$_REQUEST['payyear']."'";
	$leave_day_res = DB_query($leave_day_query,$db) or die(DB_error());
	$leave_day_result = DB_fetch_array($leave_day_res);
	 $leave_day = $leave_day_result['AttDate'];
	
	$total_workingday = $payable_day;
	
 ?>
  <tr class="f11">
    <td class="f12">Department</td>
    <td><?php  echo $s->GetFieldValue('deptmaster',"id='". $department."'",'deptname');?></td>
    <td class="f12">Designation</td>
    <td><?php  echo $s->GetFieldValue('desigmaster',"id='". $designation."'",'designame');?></td>
    <td class="f12">Present Days</td>
    <td><?php echo $total_workingday ;?></td>
  </tr>
  <tr class="f11">
    <td class="f12">Location</td>
    <td><?php  
	 echo $s->GetFieldValue('locations',"loccode='". $emp_site."'",'locationname');?></td>
    <td class="f12">Bank A/C No.</td>
    <td><?php echo $bankac; ?>&nbsp;</td>
    <td class="f12">Salary Of Days</td>
    <td><?php echo $workingdays;?></td>
  </tr>
  <tr class="f11">
    <td class="f12">Date Of Birth</td>
    <td><?php  echo  ConvertSQLDate($dob);  ?></td>
    <td class="f12">Date Of Joining</td>
    <td><?php  echo ConvertSQLDate($doj);?></td>
    <td class="f12">Holiday</td>
    <td><?php 
		$holiday_day_query = "select COUNT(DISTINCT attendance_date) AS AttDate from daily_attendance where employee='".$_REQUEST['emp_id']."' and month(attendance_date)='".$_REQUEST['paymonth']."' and  year(attendance_date)='".$_REQUEST['payyear']."' and pres_abs='HO'";
	$holiday_day_query_res = DB_query($holiday_day_query,$db) or die(DB_error());
	$holiday_day_query_result = DB_fetch_array($holiday_day_query_res);
	echo $holiday_day = $holiday_day_query_result['AttDate'];
	?>
	</td>
  </tr>
  <tr class="f11">
    <td class="f12">P.F. No.</td>
    <td><?php  echo $PFno;?>&nbsp;</td>
    <td class="f12">E.S.I. No.</td>
    <td><?php  echo $ESIno;?>&nbsp;</td>
    <td class="f12">Absent</td>
    <td><?php 
	$payable_day_query = "select COUNT(DISTINCT attendance_date) AS AttDate from daily_attendance where employee='".$_REQUEST['emp_id']."' and month(attendance_date)='".$_REQUEST['paymonth']."' and  year(attendance_date)='".$_REQUEST['payyear']."' and pres_abs='A'";
	$query_leave_res = DB_query($payable_day_query,$db) or die(DB_error());
	$query_leave_result = DB_fetch_array($query_leave_res);
	echo $payable_day = $query_leave_result['AttDate'];
		?></td>
  </tr>
  <tr class="f11">
    <td class="f12">Casual Leave</td>
    <td><?php echo $cl_days;?>&nbsp;</td>
    <td class="f12">Earned Leave</td>
    <td><?php echo $el_days;?>&nbsp;</td>
    <td class="f12">Sick Leave</td>
    <td><?php echo $sl_days;?>&nbsp;</td>
  </tr>
</table>
<br>

	<table width="100%" cellpadding="3" cellspacing="0" border="0" style="border:0;">
  <tr>
    <td width="25%" valign="top" style="border:0;">
	<table width="100%" cellspacing="0" cellpadding="3" border="0" style="border:#000 1px solid; border-collapse:collapse;">
      <tr>
        <th width="40%" class="f12">Earnings</th>
        <th class="f12">Entitled</th>
      </tr>
      <tr>
        <td class="f12">Basic</td>
		<?php $entitled = array(); ?>
        <td class="f11" align="right"><?php  echo  $emp_basic; $entitled[] = $emp_basic; ?></td>
      </tr>
      <?php 
	$earning=array();
	$earning1=array();
		$q1 =DB_query("Select * from allowmaster",$db); 
	  while($rq1=DB_fetch_array($q1))
	  { 
		 
		 ?>
      <tr>
        <td class="f12"><?php echo $rq1['allowcode'];?></td>
			<?php 
			   // $query =DB_query("Select * from emp_salary where emp_id='".$emp_id."' and allowance_deduction='".$rq1['id']."' and all_ded_prefix='A'",$db);
      // echo "Select * from payslip_salary where emp_id='".$emp_id."'
       //and allowance_id='".$rq1['id']."' and mst_prosal='".$mst_prosal."'  and allowance_type='A' ";

       $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 class="f11" align="right"><?php echo $row['allowance_amount']; $entitled[]=$row['allowance_amount']; ?></td>
        		<?php } 
				}?>
			</tr>	 
	  <?php }  ?>
	  	<tr>
        <td class="f12">Special Allow.</td>
			<?php 
			  //  $query =DB_query("Select * from emp_salary where emp_id='".$emp_id."' and allowance_deduction=100 and all_ded_prefix='A'",$db);
            // echo "Select * from payslip_salary where emp_id='".$emp_id."'
     //  and allowance_id='".$rq1['id']."' and mst_prosal='".$mst_prosal."'  and allowance_type='A' and allowance_id=100";

       $query =DB_query("Select * from payslip_salary where emp_id='".$emp_id."'
        and mst_prosal='".$mst_prosal."'  and allowance_type='A' and allowance_id=100",$db);
				if(DB_num_rows($query))
				{
       	 			while($row=DB_fetch_array($query))
	 	 			{
       				?>
       	<td class="f11" align="right">
					<?php 
						echo $row['allowance_amount']; $entitled[]=$row['allowance_amount']; 
						$earning1[]=$row['allowance_amount']
					?>
					</td>
        		<?php } 
				}?>
			</tr>	
			<tr>
        <td class="f12">Reserve Pay</td>			
       	<td class="f11" align="right"></td>        	
			</tr>
      
    </table></td>
    <td width="30%" valign="top" style="border:0;">	
	<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border:#000 1px solid; border-collapse:collapse;">
      <tr>
        <th width="50%" class="f12">Payable</th>
		    <th class="f12">YTD</th>
      </tr>
      <tr>
        <td class="f11" align="right">
		<?php
		echo $cal_ytd = round($basic_salary,2);
		
		//$cal_ytd = round((($basic_salary/$workingdays)*$payslip_month),2); 
		$arr_payable[]=$cal_ytd;
		//echo round((($basic_salary/$workingdays)*$payslip_month),2);
		?></td>
		<td class="f11" align="right"><?php  echo round(($cal_ytd*12),2);$ytd_total[] = round(($cal_ytd*12),2);?></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);*/
		//	$query =DB_query("Select * from emp_salary where emp_id='".$emp_id."' and allowance_deduction='".$rq1['id']."' 
				//and all_ded_prefix='A'",$db);

       $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 class="f11" align="right">	
			<?php   
			$cal_payable = $row['allowance_amount'];
			$cal_ytd_2 = round((($cal_payable/$payslip_month)*($workingdays)),2);
			$arr_payable[] = $cal_ytd_2;
			echo round((($cal_payable/$payslip_month)*($workingdays)),2);
//			$earning[]=$row['allowance_amount']; ?></td>
			<td class="f11" align="right"><?php  echo round(($cal_ytd_2*12),2);$ytd_total[] = round(($cal_ytd_2*12),2);	
						//$earning[]=$row['allowance_amount']; ?></td>
			<?php } 
			} 
			else{?>
			<?php }
	  }	
   ?>
      </tr>
	  <tr>
	  
	  <?php 
	  	
			    //$query =DB_query("Select * from emp_salary where emp_id='".$emp_id."' and allowance_deduction=100 and all_ded_prefix='A'",$db);
         $query =DB_query("Select * from payslip_salary where emp_id='".$emp_id."'
        and mst_prosal='".$mst_prosal."'  and allowance_type='A' and allowance_id=100",$db);

				if(DB_num_rows($query))
				{
       	 			while($row=DB_fetch_array($query))
	 	 			{
					////////////////////////////////////////////'''''''''''''''''''''''''''''''''''''''
       				?>
       				<td class="f11" align="right"><?php
					$cal_allowance = $row['allowance_amount'];
					echo $cal_allowavce_val = round((($cal_allowance/$payslip_month)*($workingdays)),2);
					$arr_payable[] = $cal_allowavce_val;
					//$earning[]=$row['percentage_value']
					?>
					</td>
					<td class="f11" align="right">
					<?php 
					
					echo $x = round(($cal_allowavce_val*12),2);
					$ytd_total[] = 	round(($cal_allowavce_val*12),2);
					?>
					</td>
        		<?php } 
				}?>
      </tr>
       <tr>
       		<td class="f11" align="right"><?php					
					echo $rev_sal_amt;
					$arr_payable[] = $rev_sal_amt;
					//$earning[]=$row['percentage_value']
					?>
					</td>
					<td class="f11" align="right"></td>		
      </tr>
      
    </table></td>
     <td valign="top" style="border:0;">
	 <table width="100%" border="1" cellspacing="0" cellpadding="3" style="border:#000 1px solid; border-collapse:collapse;">
       <tr>
         <th width="40%" class="f12">Deduction</th>
         <th width="30%" class="f12">Amount</th>
         <th class="f12">YTD</th>
       </tr>

       <?php 
	$deduction=array();
	  $query_allowances =DB_query("Select * from deduction_master   ",$db); 
	  while($row_allowances=DB_fetch_array($query_allowances))
	  { 
 		 ?>
       <tr> 
         <td class="f12"><?php echo $row_allowances['code'] ;?></td>
         <?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 class="f11" align="right">
		 <?php 
		 	echo $row['allowance_amount'];	
			$deduction[]=$row['allowance_amount'];	
		?>
		</td>
         <td class="f11" align="right">
		 <?php 
		 	$tyd_deduction = round((($row['allowance_amount']/$payslip_month)*($workingdays)),2);
			echo round(($tyd_deduction*12));
			$deduction_2[] = round(($tyd_deduction*12));
		  ?></td>
         <?php }
		}  
		 else{
			echo "<td></td>";
			}
		  echo "<tr>";
		
	  }	
 	
  ?></tr>       
       <tr>
         <td class="f12">Loan</td>
         <td class="f11" align="right">
		 <?php  
		 	echo $loan_amount;
			$deduction[] = $loan_amount;
		?></td>
         <td class="f11" align="right">
		 <?php 
		 	echo round(($loan_amount*12),2);
		 	$deduction_2[] = round(($loan_amount*12),2);
		 ?></td>
       </tr>
	   <tr>
         <td class="f12">Advance Amt</td>
         <td class="f11" align="right">
		 <?php  
		 	echo $advance_balance;
			$deduction[] = $advance_balance;
		?></td>
         <td class="f11" align="right"></td>
       </tr>
       
     </table>	 </td>
  </tr>
  <tr>
  <td width="30%" valign="top" class="f12" style="border:0;">
  <table width="100%" border="1" cellspacing="0" cellpadding="3" style="border:#000 1px solid; border-collapse:collapse;">
  <tr>
    <td width="40%" align="left">Total</td>
    <td align="right"><?php echo round((array_sum($entitled)),2);?></td>
  </tr>
  </table>
  </td>
  <td width="30%" valign="top" class="f12" style="border:0;">
  <table width="100%" border="1" cellspacing="0" cellpadding="3" style="border:#000 1px solid; border-collapse:collapse;">
  <tr>
    <td width="50%" align="right"><?php echo round((array_sum($arr_payable)),2);?></td>
    <td align="right"><?php echo round((array_sum($ytd_total)),2);?></td>
  </tr>
  </table>  
  <td valign="top" class="f12" style="border:0;">
  <table width="100%" border="1" cellspacing="0" cellpadding="3" style="border:#000 1px solid; border-collapse:collapse;">
  <tr>
    <td width="40%">Total</td>
    <td width="30%" align="right"><?php echo round(array_sum($deduction),2);?></td>
    <td align="right"><?php echo round(array_sum($deduction_2),2);?></td>
  </tr>
</table>
</td>
  </tr>
  <tr>
  <td colspan="3" align="center" class="f12" style="text-align:center;">NetPay (Rs.) : <?php echo round($net_earning) ;?></td>
  </tr>
   <tr>
  <td colspan="3" align="center" class="f12" style="text-align:center;">TDS Deduction (Rs.) : <?php echo round($Process_RowData['tds_deduction']) ;?></td>
  </tr>
  <tr>
  <td colspan="3" align="center" class="f12" style="text-align:center;">In Words Rupees :  <?php  echo ucwords(convert_number_to_words(round($net_earning)))  ?> only</td>
  <tr>
  <td colspan="3" align="left" class="f12">&nbsp;</td>
  </tr>
  </tr>
  <tr>
  <td align="left" class="f12" colspan="3">Bank Name</td>
  </tr>
  <tr>
  <td align="left" class="f12" colspan="3" style="padding-left:10px;"><?php echo $bankname; ?></td> 
  </tr>
</table>


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

</div>

<?php
function convert_number_to_words($number) {
   
   
    $hyphen      = '-';
    $conjunction = ' and ';
    $separator   = ', ';
    $negative    = 'negative ';
    $decimal     = ' point ';
    $dictionary  = array(
        0                   => 'zero',
        1                   => 'one',
        2                   => 'two',
        3                   => 'three',
        4                   => 'four',
        5                   => 'five',
        6                   => 'six',
        7                   => 'seven',
        8                   => 'eight',
        9                   => 'nine',
        10                  => 'ten',
        11                  => 'eleven',
        12                  => 'twelve',
        13                  => 'thirteen',
        14                  => 'fourteen',
        15                  => 'fifteen',
        16                  => 'sixteen',
        17                  => 'seventeen',
        18                  => 'eighteen',
        19                  => 'nineteen',
        20                  => 'twenty',
        30                  => 'thirty',
        40                  => 'fourty',
        50                  => 'fifty',
        60                  => 'sixty',
        70                  => 'seventy',
        80                  => 'eighty',
        90                  => 'ninety',
        100                 => 'hundred',
        1000                => 'thousand',
        1000000             => 'million',
        1000000000          => 'billion',
        1000000000000       => 'trillion',
        1000000000000000    => 'quadrillion',
        1000000000000000000 => 'quintillion'
    );
   
    if (!is_numeric($number)) {
        return false;
    }
   
    if (($number >= 0 && (int) $number < 0) || (int) $number < 0 - PHP_INT_MAX) {
        // overflow
        trigger_error(
            'convert_number_to_words only accepts numbers between -' . PHP_INT_MAX . ' and ' . PHP_INT_MAX,
            E_USER_WARNING
        );
        return false;
    }

    if ($number < 0) {
        return $negative . convert_number_to_words(abs($number));
    }
   
    $string = $fraction = null;
   
    if (strpos($number, '.') !== false) {
        list($number, $fraction) = explode('.', $number);
    }
   
    switch (true) {
        case $number < 21:
            $string = $dictionary[$number];
            break;
        case $number < 100:
            $tens   = ((int) ($number / 10)) * 10;
            $units  = $number % 10;
            $string = $dictionary[$tens];
            if ($units) {
                $string .= $hyphen . $dictionary[$units];
            }
            break;
        case $number < 1000:
            $hundreds  = $number / 100;
            $remainder = $number % 100;
            $string = $dictionary[$hundreds] . ' ' . $dictionary[100];
            if ($remainder) {
                $string .= $conjunction . convert_number_to_words($remainder);
            }
            break;
        default:
            $baseUnit = pow(1000, floor(log($number, 1000)));
            $numBaseUnits = (int) ($number / $baseUnit);
            $remainder = $number % $baseUnit;
            $string = convert_number_to_words($numBaseUnits) . ' ' . $dictionary[$baseUnit];
            if ($remainder) {
                $string .= $remainder < 100 ? $conjunction : $separator;
                $string .= convert_number_to_words($remainder);
            }
            break;
    }
   
    if (null !== $fraction && is_numeric($fraction)) {
        $string .= $decimal;
        $words = array();
        foreach (str_split((string) $fraction) as $number) {
            $words[] = $dictionary[$number];
        }
        $string .= implode(' ', $words);
    }
   
    return $string;
}
?>
</body>
</html>