MOON
Server: Apache
System: Linux nserver.cafsindia.com 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: cafsindia (1002)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: /home/cafsindia/hrms_patroniss_com/application/controllers/Pt_report.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Base_controller.php");
class Pt_report  extends Base_controller{
	
	public function __construct(){
		parent::__construct('pt_report');
		if(!$this->Appconfig->isAppvalid()){
			redirect('config');
		}
		$this->collect_base_info();
	}
	
	// LOAD PAGE WITH TABLE DATA
	public function index(){
	$location_info   = $this->db->query("CALL sp_a_run ('SELECT','SELECT * FROM `cw_professional_tax_location` where trans_status = 1')");
		$location_result = $location_info->result();
		$location_info->next_result();
		$location[""] = "---- Select Location ----";
		foreach($location_result as $for){
			$location_id   = $for->prime_professional_tax_location_id;
			$location_name = $for->professional_tax_location;
			$location[$location_id] = $location_name;
		}
		$data['location'] = $location;
		$this->load->view("$this->control_name/manage",$data);
	}
	
	public function pt_save(){	
		$location_name       = $this->input->post('location_name');
		$process_month       = $this->input->post('process_month');
		$location            = (int)$this->input->post('location');
		$report_model        = (int)$this->input->post('report_model');
		$today_date          = date("d-m-Y H:i:s");
		$company = 'select company_name from cw_company_information where cw_company_information.trans_status = 1';
		$comp_info    = $this->db->query("CALL sp_a_run ('SELECT','$company')");
		$comp_result  = $comp_info->row();
		$comp_info->next_result();
		$company_name = $comp_result->company_name;
		$address      = $comp_result->address;
		if($report_model === 1){
			$qry = 'select cw_employees.employee_code,cw_employees.emp_name,cw_transactions.net_pay,cw_transactions.professional_tax from cw_transactions inner join cw_employees on cw_employees.employee_code = cw_transactions.employee_code where transactions_month ="'.$process_month.'" and cw_transactions.professional_tax_location ="'.$location.'" and cw_transactions.trans_status = 1';
				$qry_info   = $this->db->query("CALL sp_a_run ('SELECT','$qry')");
				$qry_result = $qry_info->result();
				$qry_info->next_result();
				$total_employees =  count($qry_result);
				$tr_line = "";
				$total_pay  = 0;
				$total_pt   = 0;
				foreach($qry_result as $rslt){
					$code                  = $rslt->employee_code;
					$name                  = $rslt->emp_name;
					$net_pay               = $rslt->net_pay;
					$professional_tax      = $rslt->professional_tax;
					$total_pay             = $total_pay + $net_pay;
					$total_pt              = $total_pt + $professional_tax;
					$tr_line .= "<tr><td>$code</td><td>$name</td><td>$net_pay</td><td>$professional_tax</td></tr>";
				}
					$total_pay   = number_format((float)$total_pay, 2, '.', '');
					$total_pt    = number_format((float)$total_pt, 2, '.', '');
					
					if($employee_code == '' && $name == ''){
					$tr_line .= "<tr style='text-align:center;font-weight:bold;'><td colspan='6'>No Data Found!!</td></tr>";
					}else{
					$tr_line .= "<tr style='text-align:center;font-weight:bold;'><td>Total Employees :$total_employees</td><td>Total</td><td>$total_pay</td><td>$total_pt</td></tr>";
					}
				$table_data = "<div style='width:700px; margin-left: auto; margin-right: auto; padding: 15px; background-color: #EEEEEE; border-radius: 3px; box-shadow: 0 2px 2px 0 rgba(0,0,0,0.14), 0 3px 1px -2px rgba(0,0,0,0.12), 0 1px 5px 0 rgba(0,0,0,0.2);'>
				<table style='width:100%;border-collapse: collapse;border-spacing: 0;border-color: #CCCCCC !important;border: 0px;text-align: left;font-size: 14px;background-color: #FFFFFF;' border='1' cellspacing='0' cellpadding='4'>
				<tr>
				<td colspan='2'><h3 style='text-align:center;'>PROFESSIONAL TAX REPORT</h3></td>
				</tr>
				<tr>
				<td colspan='2' style='border-bottom:none !important;'>
				<h3 style='color:#d3434d;margin:10px;font-size:21px;font-weight:bold;text-align:center;'>".$company_name."
				</h3>
				</td>
				</tr>
				<tr>
				<td style='border-right:none !important;border-top:none !important;'>
				<h3 style='color:#d3434d;margin:10px;font-size:16px;font-weight:bold;'>Professional Tax for the Month of ".strtoupper(date("M-Y",strtotime("01-".$this->input->post('process_month'))))."- Location -".$location_name."</h3>
				</td>
				<td style='text-align:center;font-weight:bold;border-top:none !important;border-left:none !important;'>".$today_date."</td>
				</tr>
				</table>
				<table style='width:100%;border-collapse: collapse;border-spacing: 0;border-color: #CCCCCC !important;border: 0px;font-size: 14px;background-color:#FFFFFF;' border='1' cellspacing='0' cellpadding='4'>
				<thead>
				</thead>
				<tbody>
				<tr style='background-color:#f2f2f2;color: #000000;font-weight:bold;'>
					<th>Code</th>
					<th>Name</th>
					<th>Net Pay</th>
					<th>Profession Tax</th>
				</tr>
					$tr_line
				</tbody>
				</table>
				</div>";
				$table_data = "<!DOCTYPE html><html> <body>".$table_data."</body></html>";
		}else
		if($report_model === 2){
			$qry = 'select earning_range_from,earning_range_to, professional_tax,count(employees_id) as total_employees from cw_transactions inner join cw_professional_tax_tax_range on prime_professional_tax_id=professional_tax_location WHERE transactions_month ="'.$process_month.'" and professional_tax_location ="'.$location.'" and cw_transactions.trans_status = 1 GROUP by professional_tax';
				$stat_info   = $this->db->query("CALL sp_a_run ('SELECT','$qry')");
				$stat_result = $stat_info->result();
				$stat_info->next_result();
				$total_prof = 0;
				foreach($stat_result as $stat){
					$earning_range_from = $stat->earning_range_from;
					$earning_range_to   = $stat->earning_range_to;
					$total_employees    = $stat->total_employees;
					$professional_tax   = $stat->professional_tax;
					$tax_amt            = $total_employees * $professional_tax;
					$tax_amt            = number_format((float)$tax_amt, 2, '.', '');
					$total_prof         = $total_prof + $tax_amt;
					$stat_line .= "<tr><td>$earning_range_from - $earning_range_to</td><td>$total_employees</td><td>$professional_tax</td><td>$tax_amt</td></tr>";
					}
					$total_prof  = number_format((float)$total_prof, 2, '.', '');				
					if($total_employees == ''){
					$stat_line .= "<tr style='text-align:center;font-weight:bold;'><td colspan='4'>No Data Found!!</td></tr>";
					}else{
					$stat_line .= "<tr style='text-align:center;font-weight:bold;'><td colspan='3' style='text-align:right'>Total Rs.</td><td>$total_prof</td></tr>";
					}
				$table_data = "<div style='width:700px; margin-left: auto; margin-right: auto; padding: 0px; background-color: #EEEEEE; border-radius: 3px; box-shadow: 0 2px 2px 0 rgba(0,0,0,0.14), 0 3px 1px -2px rgba(0,0,0,0.12), 0 1px 5px 0 rgba(0,0,0,0.2);'>
				<table style='width:100%;border-collapse: collapse;border-spacing: 0;border-color: #CCCCCC !important;border: 0px;text-align: left;font-size: 14px;background-color: #FFFFFF;' border='1' cellspacing='0' cellpadding='4'>
				<tr>
				<td colspan='2'><h3 style='text-align:center;'>(See Rule 12)</h3>
				<p><h3 style='text-align:center;'>RETURNS OF TAX PAYABLE BY EMPLOYER </h3></p>
				<h4 style='margin-left:20px;'>Under Sub - Section (1) of Section 7 of the ".$location_name." Tax on <br/>Professions,Trades,Callings and Employments Act,1987</h4>
				<h4 style='color:#d3434d;margin:10px;font-size:16px;font-weight:bold;'>Return of tax payable for the month ending on ".strtoupper(date("M-Y",strtotime("01-".$this->input->post('process_month'))))."</h4>
				</td>
				</tr>
				<tr><td><h4>Name Of The Employer:</h4></td><td><h4 style='color:#d3434d;margin:10px;font-size:21px;font-weight:bold;text-align:center;'>".$company_name."</h4></td></tr>
				<tr><td colspan='2'><h4>Address:  ".$address."</h4></td></tr>
				<tr><td colspan='2'><h4>Registration Certificate No.</h4>
				<h4>Number of employees during the month in respect of whom the tax is payable is as under:</h4></td></tr>
				</table>
				<table style='width:100%;border-collapse: collapse;border-spacing: 0;border-color: #CCCCCC !important;border: 0px;font-size: 14px;background-color:#FFFFFF;' border='1' cellspacing='0' cellpadding='4'>
				<thead>
				</thead>
				<tbody>
				<tr style='background-color:#f2f2f2;color: #000000;font-weight:bold;'>
					<th>Employees Whose Monthly Salaries Or wages or both are</th>
					<th>Number Of Employees</th>
					<th>Rate Of Tax Per Month Rs.</th>
					<th>Amount Of Tax Deducted Rs.</th>
				</tr>
					$stat_line
					<tr><td colspan='3'><h5>Add: Simple Interest payable (if any) on the above amount at two percent per month or part there of(vide Section 11 of the Act)</h5></td><td></td></tr>
					<tr><td colspan='3' style='text-align:right'>Grand Total</td><td>$total_prof</td></tr><tr><td>Amount Paid:  $total_prof</td><td colspan='2'> Under challan no.</td><td>dated:</td></tr>
					<tr><td colspan='4'>I Certify that all the employees who are liable to pay the tax in my employ during the period of return have been  covered by the forgoing particulars..I also certify that the necessary revision in the amount of tax deductible from the salary of wages of the employees on account of variation in the salary or wages earned by team been made whatever necessary.<br/><br/></td></tr>
					<tr><td colspan='3' style='border-bottom:none !important;border-right:none !important;'>I, shri</td><td style='border-bottom:none !important;border-left:none !important;'>Solemnly declare that the</td></tr>
					<tr><td colspan='4' style='border-top:none !important;'>above statments are true to the best of my knowledge and belief.<br/></td></tr>
					<tr><td colspan='2'>Place</td><td colspan='2'>Signature<span style='color:#bbbbbb;margin-left:70px;'>(Employer)</span></td></tr>
					<tr><td colspan='2'>Date</td><td colspan='2'>Status</td></tr>
				</tbody>
				</table>
				</div>";
				$table_data = "<!DOCTYPE html><html> <body>".$table_data."</body></html>";
					
				}
				//$combine_data .= $table_data; //For Combine all pdf
			$folder = $this->generate_pdf($table_data,$location_name,$process_month,$location,$report_model);
			echo json_encode(array('success' => TRUE,'folder' => $folder,'process_month' => $process_month));
	}
	
		public function generate_pdf($table_data,$location_name,$process_month,$location,$report_model){
			$location_name = strtolower(str_replace(" ","_",$location_name));
			if($report_model == 1){
				$model_name = "Detail";
			}else 
			if($report_model == 2){
				$model_name = "Statutory";
			}
			// Load pdf library
			$this->load->library('pdf');
				// Load HTML content 
			$this->dompdf->loadHtml($table_data);
				// (Optional) Setup the paper size and orientation
			$this->dompdf->setPaper('A4', 'portrait');
				// Render the HTML as PDF
			$this->dompdf->render();
				// Output the generated PDF (1 = download and 0 = preview)
			$output = $this->dompdf->output();
			$folder     = "pt_report";
			$folder1    = $process_month;
			$folder2    = $model_name;
			$pdf_name   = $location_name;
			$final_html = $output;
			$oldmask    = umask(0);
			if(!file_exists($folder)){
				mkdir($folder, 0777, true);
			}
			
			if(!file_exists($folder."/".$folder1)){
				mkdir($folder."/".$folder1, 0777, true);
			}
			
			if(!file_exists($folder."/".$folder1."/".$folder2)){
				mkdir($folder."/".$folder1."/".$folder2, 0777, true);
			}
			
			//Check File Exist
			if(file_exists($folder."/".$folder1."/".$folder2."/".$pdf_name.".pdf")){
				chmod($folder."/".$folder1."/".$folder2."/".$pdf_name.".pdf", 0777);
				unlink($folder."/".$folder1."/".$folder2."/".$pdf_name.".pdf");
			}
			file_put_contents($folder."/".$folder1."/".$folder2."/".$pdf_name.".pdf", $final_html);
			chmod($folder."/".$folder1."/".$folder2."/".$pdf_name.".pdf", 0777);
			umask($oldmask);
			$path = $folder."/".$folder1."/".$folder2."/".$pdf_name.".pdf";
			chmod($path, 0777, true);
			return $path;
		}
}
?>