File: //home/cafsindia/hrms_allyindian_com/application_bk/controllers_bk07FEB2026/Payslip_view.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Action_controller.php");
class Payslip_view extends Action_controller{
public function __construct(){
parent::__construct('payslip_view');
}
// LOAD PAGE QUICK LINK,FILTERS AND TABLE HEADERS
public function index(){
$data['key'] = $this->generateKey();
//PAGE INFO FUNCTION
$this->load->view("$this->control_name/manage",$data);
}
public function check_payslip(){
$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);
}
$from_month = $this->input->post('from_month');
$to_month = $this->input->post('last_month');
$emp_code = $this->session->userdata('logged_emp_code');
$db_name = $this->config->item("db_name");
$company_info = $this->company_info();
$payslip_based_on = $company_info[0]->payslip_based_on;
$encrypted_pdf = $company_info[0]->encrypted_pdf;
if(!$payslip_based_on){
echo json_encode(array('success' => false,'message' => 'In Company Information Payslip Based On has to be updated','table_data' => $table_data));
exit(0);
}else{
$emp_qry = 'select '.$payslip_based_on.' from cw_employees where trans_status = 1 and employee_code = "'.$emp_code.'"';
$emp_info = $this->db->query("CALL sp_a_run ('SELECT','$emp_qry')");
$emp_rslt = $emp_info->result();
$emp_info->next_result();
$payslip_based_id = $emp_rslt[0]->$payslip_based_on;
$form_qry = 'select prime_module_id,prime_form_id,view_name,label_name,field_type,pick_list_type,pick_list,pick_table,auto_prime_id,auto_dispaly_value from cw_form_setting where trans_status = "1" and prime_module_id = "employees" and label_name = "'.$payslip_based_on.'" ';
$form_data = $this->db->query("CALL sp_a_run ('SELECT','$form_qry')");
$form_result_arr = $form_data->result_array();
$form_data->next_result();
//Get Payslip based on column name - START
$pick_table = $form_result_arr[0]['pick_table'];
$pick_list = $form_result_arr[0]['pick_list'];
$name_qry = 'select '.$pick_list.' from '.$pick_table.' where trans_status = 1';
$name_data = $this->db->query("CALL sp_a_run ('SELECT','$name_qry')");
$name_result = $name_data->result_array();
$name_data->next_result();
$pick_list_arr = explode(",",$pick_list);
$pick_id = $pick_list_arr[0];
$pick_name = $pick_list_arr[1];
$payslip_arr = array();
foreach ($name_result as $key => $value) {
$payslip_arr[$value[$pick_id]] = str_replace(" ", "_", $value[$pick_name]);
}
$payslip_based_val = $payslip_arr[$payslip_based_id]; // get exact popup data text
$pdf_name_query = 'select prime_print_info_id,print_info_module_id,print_info_name from cw_print_info where pdf_design_for REGEXP "(^|,)('.$payslip_based_id.')(,|$)" and print_info_module_id = "employees" and print_type = 1 and trans_status = 1';
$pdf_name_info = $this->db->query("CALL sp_a_run ('SELECT','$pdf_name_query')");
$pdf_name_result = $pdf_name_info->result();
$pdf_name_info->next_result();
$module_name = $pdf_name_result[0]->print_info_module_id;
$template_design = strtolower(str_replace(' ', '_', $pdf_name_result[0]->print_info_name));
$start_date = "01-".$from_month;
$end_date = "01-".$to_month;
$start_date = date('Y-m-d', strtotime($start_date));
$end_date = date('Y-m-d', strtotime($end_date));
$start = strtotime($start_date);
$month = strtotime($start_date);
$end = strtotime($end_date);
$tble_line = "";
$tble_no_line = "";
$i = 0;
$j = 0;
while($month <= $end){
$payslip_month = date('m-Y', $month);
$payslip_month_name = date('F Y', $month);
if((int)$encrypted_pdf === 1){
$file_name = $db_name."_".$emp_code."_".$payslip_month;
$enc_file = $this->encryptFilename($file_name,$db_name);
$enc_file_name = $enc_file."_".$emp_code;
}else{
$enc_file_name = $emp_code;
}
if($db_name === "hare_hrms_db"){
$month_year = date('Y-m', $month);
$check_month = "2023-08";
if($month_year < $check_month){
$payslip_month_name = "C0001_".strtoupper(date('F_Y', $month));
$file_path = "payslip/$payslip_month_name/$emp_code.pdf";
}else{
$file_path = "./pdf_generation/".$module_name."/".$template_design."/".$payslip_month.'/'.$payslip_based_on."_".strtolower($payslip_based_val).'/'.$enc_file_name.'.pdf';
}
}else{
$file_path = "./pdf_generation/".$module_name."/".$template_design."/".$payslip_month.'/'.$payslip_based_on."_".strtolower($payslip_based_val).'/'.$enc_file_name.'.pdf';
}
if(file_exists($file_path)){
$file_path = base_url().$file_path;
$enc_path = base64_encode($file_path);
$file_path = base64_encode($file_path);
$file_path = base64_encode($file_path);
$tble_line .= "<tr class='gradeU'>
<td>$payslip_month_name</td>
<td>
<a class='fa fa-folder-open' id='view_btn' onclick=pdf_viewer('$file_path') style='color: blue;'> view</a>
<a class='fa fa-download' id='download_btnn' onclick=download_payslip('download_$emp_code','$enc_path') id='download_$emp_code'> Download</a>
</td>
</tr>";
$j++;
}else{
$tble_no_line = " <tr class='gradeU'>
<td colspan='2' style='text-align:center;'>No data found</td>
</tr>";
}
$month = strtotime("+1 month", $month);
$i++;
}
$tbl_body = "";
if((int)$j >= 1){
$tbl_body = $tble_line;
}else{
$tbl_body = $tble_no_line;
}
$table_data = " <table class='table table-striped table-bordered' id='emp_details'>
<thead>
<tr>
<th>Payslip Month</th>
<th>Action</th>
</tr>
</thead>
<tbody>
$tbl_body
</tbody>
</table>";
echo json_encode(array('success' => true,'message' => 'Payslip Details','table_data' => $table_data));
}
}
}
?>