<?php
require_once("dompdf/dompdf_config.inc.php");
include_once("class/class.MySQL.php");
$db		= new MySQL();

if($_POST['form'] =='form5a'){
	$html 	= '<html><head>
	
		<style type="text/css">
		body {font-family: "Trebuchet MS";color: #202020;font-size: 12px;line-height: 16px; background: #fff;}
		.content {
		  padding: 20px 15px;
		  overflow: auto;
		}
		h1,
		h2,
		h3,
		h4,
		h5,
		h6,
		.h1,
		.h2,
		.h3,
		.h4,
		.h5,
		.h6 {
		  font-family: "Source Sans Pro", sans-serif;
		}
		.table{
			border-collapse:collapse;
			margin-bottom:15px;
		}
		.table td{border:2px #F4F4F4 solid; padding-left:5px;}
		.table tr{height:30px;color:#202020;font-size:12px; line-height:20px;}
		.title{font-weight:bold;}
		</style>
	  </head>
	  <body>';
	if($_POST['location_id']=="0"){
		$head="RETURN OF TAX PAYABLE BY EMPLOYER UNDER SUB-SECTION(1) OF SECTION 6-A OF THE
KERALA NON MONTHLY ON PROFESSION, TRADE, CALLINGS AND EMPLOYMENT ACT 1976.";
	}else{
		$head="RETURN OF TAX PAYABLE BY EMPLOYER UNDER SUB-SECTION(1) OF SECTION 6-A OF THE
KERALA ON PROFESSION, TRADE, CALLINGS AND EMPLOYMENT ACT 1976.";
	}

	 $html .='
	  <div class="content" style="page-break-after:always;">
	  <h4><div style="border:2px #000 solid;padding:5px 10px;text-align:center;width:10%;align:center;margin-left:300px;"> FORM 5A </div>
	  <div style="text-align:center;margin-top:5px;"></div>
	  </h4>
	  <table style="width:100%;">
		<tr>
		<td style="width:90%;"><h3 style="margin:0px 0px 5px 0px;">'.$head.'</h3> 
		</td>
		</tr>
		
		<tr>
		<td style="width:90%;">Return on Tax Payable for the month ending on  '.date('d M Y',strtotime($_POST['from_date'])).'
		</td>
		</tr>
		
		<tr>
		<td style="width:90%;">Name and Address of the Employer :<br/>
		</td>
		</tr>
		
		<tr>
		<td style="width:90%;">Registration Certificate No :
		</td>
		</tr>
		
		<tr>
		<td style="width:90%;">PTO Circle No. :
		</td>
		</tr>
		
		<tr>
		<td style="width:90%;">Number of employees during the month in respect of whom the tax payable is as under :-
		</td>
		</tr>
		
		</table>  
		 
		<table width="100%" border="1" cellspacing="2" cellpadding="2" class="table">
		  <tr>
			<td class="title">SI NO</td>
			<td class="title">Employees whose monthly salaries or
wages or both </td>
			<td class="title">No. of Employees </td>
			<td class="title">Rate of Tax</td>
			<td class="title">Amount of Tax Deducted</td>
			
		  </tr>';
	
		$i=1;	
		$sqlstring="SELECT * from professional_tax";
		
		
		/*if(isset($_REQUEST["from_date"])){
			$sqlstring.=" and STR_TO_DATE(date_join,'%d-%m-%Y') >= STR_TO_DATE('$_REQUEST[from_date]','%d-%m-%Y') ";
		}
		if(isset($_REQUEST["to_date"])){
			$sqlstring.=" and STR_TO_DATE('$_REQUEST[to_date]','%d-%m-%Y') >=STR_TO_DATE(date_join,'%d-%m-%Y') ";
		}*/
		
		
		$userdetails = $db->fetchQuery($sqlstring);
	$sum_cnt=0;
	$sum_tax=0;
		foreach ($userdetails as $details) {
			
			//$payroll = $db->fetchQuery("select count(distinct `userid`) as cnt from payroll_salary_pay WHERE CAST(`total_earnings` as UNSIGNED) >= ($details[min_amount]/6) and CAST(`total_earnings` as UNSIGNED) <= ($details[max_amount]/6)");
			
			$payroll_sql="select count(distinct `userid`) as cnt from payroll_salary_pay WHERE total_earnings >= ($details[min_amount]/6) ";
			if($details['max_amount']>0){
				$payroll_sql="and total_earnings <= ($details[max_amount]/6)";
			}
			
			
			$payroll = $db->fetchQuery($payroll_sql);
			
			foreach ($payroll as $payroll_dtl) {
			$cnt=$payroll_dtl['cnt'];
			$total_tax=$payroll_dtl['cnt']*$details['tax'];
			}
			if($details['max_amount']>0){
				$max= "To $details[max_amount]";
			}else{
				$max= "and Above ";
			}
			 $html .=  '<tr>
					<td>'.$i++.'</td>
					<td>'.$details['min_amount'].' '.$max.'</td>
					<td>'.$cnt.'</td>
					<td>'.$details['tax'].'</td>
					<td>'.$total_tax.'</td>				
				  </tr>';
				
				$sum_cnt+=$cnt;  
				$sum_tax+=$total_tax;  
		}
		$html .= '
		 <tr>
			<td class="title"  colspan="2" align="right">Total</td>
			<td class="title">'.$sum_cnt.'</td>
			<td class="title"></td>
			<td class="title">'.$sum_tax.'</td>
			
		  </tr>
		   <tr>
			<td class="title"  colspan="3" align="right">Add : Simple interest payable (if any) on the above
amount at two percent per month or part thereof ( vide
section II (2) of the Act ). </td>			
			<td class="title"></td>
			<td class="title"></td>
			
		  </tr>
		  
		  
		  <tr>
			<td class="title"  colspan="2" align="right">Grand Total</td>
			<td class="title">'.$sum_cnt.'</td>
			<td class="title"></td>
			<td class="title">'.$sum_tax.'</td>
			
		  </tr>
		  </table>
		
		
		
			Amount paid by cheque no. 
					<span style="padding-left:200px;">Dated</span>
					<span style="padding-left:150px;">for Rs </span>
					
					<br/><br/>
					
					
					Name of the Bank: 
					<br/><br/>
					
					
					
					
					I certify that all the employees who are liable to pay tax in my employment during the period of return have been covered by the
foregoing particulars. I also certify that the necessary revision in the amount of tax deductable from the salary or wages of the
employees on account variation in the salary or wages earned by them has been made wherever necessary.
I, solemnly declare that the above statements are true to the best of my knowledge and belief.
					
					<table width="100%" border="0" cellspacing="0" cellpadding="0">
				  <tr>
					<td width="20%" class="normal-fonts">Place: </td>
					<td width="44%" class="normal-fonts"></td>
					<td width="36%" class="normal-fonts">Signature of the employer:</td>
				  </tr>
				</table>
					
				<table width="100%" border="0" cellspacing="0" cellpadding="0">
				  <tr>
					<td width="20%" class="normal-fonts">Date : '.date('d-M-Y').'</td>
					<td width="44%" class="normal-fonts"></td>
					<td width="36%" class="normal-fonts">Status:</td>
				  </tr>
				</table>	
					
					
				   </div>
				   </body></html>';
	$dompdf = new DOMPDF();
	$dompdf->load_html($html);
	$dompdf->render();
	$dompdf->stream("PF-Form5.pdf");
}

?>