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_cafsinfotech_in/OLD/application/controllers/Pf_challan_report.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Action_controller.php");
class Pf_challan_report  extends Action_controller{	
	public function __construct(){
		parent::__construct('pf_challan_report');
		if(!$this->Appconfig->isAppvalid()){
			redirect('config');
		}
	}
	
	// LOAD PAGE WITH TABLE DATA
	public function index(){
		$data['key']           = $this->generateKey();
		$this->load->view("$this->control_name/manage",$data);
	}	
	public function generate_challan(){
		$encString             = file_get_contents('php://input');
		$_POST                 = $this->cryptoDecrypt($encString);
		if(!$_POST){
			echo json_encode(array('success' => false,'message' => 'Invalid Request..','table_data' => ""));
			exit(0);
		}
		$pf_month = $this->input->post('pf_month');
		//Check PF Settings
		$settings_exist_qry    = "select count(*) as settings_count from cw_pf_challan_setting where trans_status = 1";
		$settings_exist_data   = $this->db->query('CALL sp_a_run ("SELECT","'.$settings_exist_qry.'")');
		$settings_exist_result = $settings_exist_data->result();
		$settings_exist_data->next_result();
		$settings_exist_count  = $settings_exist_result[0]->settings_count;
		if((int)$settings_exist_count === 0){
			echo json_encode(array('success' => FALSE, 'message' => "PF Challan Settings not completed"));
			exit(0);
		}
		$transaction_exist_qry    = "select count(*) as trans_count from cw_transactions where trans_status = 1 and role != 1 and transactions_month = '$pf_month'";
		$transaction_exist_data   = $this->db->query('CALL sp_a_run ("SELECT","'.$transaction_exist_qry.'")');
		$transaction_exist_result = $transaction_exist_data->result();
		$transaction_exist_data->next_result();
		$transaction_exit_count = $transaction_exist_result[0]->trans_count;
		if($transaction_exit_count == 0){
			echo json_encode(array('success' => FALSE, 'message' => "Payroll is not completed for this month $pf_month?"));
			exit(0);
		}else{
			$pf_get_column_query  = 'SELECT  CONCAT(transaction_type, ".", matching_field) AS fieldname  from cw_pf_challan_setting where cw_pf_challan_setting.trans_status = 1 order by order_no ASC';
			$pf_get_column_data   = $this->db->query("CALL sp_a_run ('SELECT','$pf_get_column_query')");
			$pf_get_column_result = $pf_get_column_data->result();
			$pf_get_column_data->next_result();
			$i=0;
			foreach ($pf_get_column_result as $value) {
				if((int)$i===0)
					$transaction_type = $value->fieldname;
				else
				$transaction_type .=','.$value->fieldname;
				$i++;
			}
			$concatstart="SELECT CONCAT(";
			$concatstart_string_replace = str_replace(',',',"#~#",',$transaction_type);
			$concatend=")";
			$DataField="$concatstart$concatstart_string_replace$concatend";
			$pfchallan_data_query = $DataField.' AS data from cw_transactions inner join cw_employees on cw_transactions.employee_code=cw_employees.employee_code where cw_transactions.transactions_month="'.$pf_month.'" and cw_transactions.trans_status = 1 AND cw_transactions.pf_eligibility = 1';
			$pfchallan_data   = $this->db->query("CALL sp_a_run ('SELECT','$pfchallan_data_query')");
			$pfchallan_data_result = $pfchallan_data->result();
			$pfchallan_data->next_result();
			$pf_challan_data_write = "";
			foreach ($pfchallan_data_result as $value){
				$pf_challan_data_write.= "$value->data \n";
			}
			
			$folder = "pf_challan";
			if (!file_exists($folder)){
				mkdir($folder, 0777, true);
			}
			$file_name = $pf_month."_pf_challan.txt";
			$myfile = fopen($folder."/".$file_name, "w") or die("Unable to open file!");	
			fwrite($myfile, $pf_challan_data_write);
			fclose($myfile);
			echo json_encode(array('success' => TRUE, 'message' => "Successfully Saved",'file_name' => $file_name));
		}
	}
}
?>