File: /home/cafsindia/hrms_allyindian_com/application_bk/controllers/Form_16_view.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Action_controller.php");
class Form_16_view extends Action_controller{
public function __construct(){
parent::__construct('form_16_view');
}
// LOAD PAGE QUICK LINK,FILTERS AND TABLE HEADERS
public function index(){
$data['key'] = $this->generateKey();
//PAGE INFO FUNCTION
$this->page_info();
$data['module_sts'] = (int)$this->module_sts;
$data['quick_link'] = $this->quick_link;
$data['pick_list'] = $this->pick_list;
$data['table_head'] = $this->table_head;
$data['fliter_list'] = $this->fliter_list;
$user_role = $this->session->userdata('logged_user_role');
$where = '';
if((int)$user_role !== 1 && (int)$user_role !== 2){
$emp_code = $this->session->userdata('logged_emp_code');
$where = ' and employee_code = "'.$emp_code.'" ';
}
$employee_info_query = 'SELECT employee_code,emp_name FROM `cw_employees` where trans_status = 1 and prime_employees_id !=1 '.$this->role_condition .$where;
$employee_info = $this->db->query("CALL sp_a_run ('SELECT','$employee_info_query')");
$employee_result = $employee_info->result();
$employee_info->next_result();
$employee_list[""] = "---- Select Employee ----";
foreach($employee_result as $for){
$emp_code = $for->employee_code;
$emp_name = $for->emp_name;
$employee_list[$emp_code] = $emp_code." - ".$emp_name;
}
$data['employee_list'] = $employee_list;
$startDate = "2020-04-01";
$endDate = date("Y-m-d",strtotime('+1 years'));
$fin_qry = 'SELECT prime_financial_setting_id as id,CONCAT(DATE_FORMAT(start_date,"%Y")," - ",DATE_FORMAT(end_date,"%y")) as value FROM `cw_financial_setting` WHERE trans_status = 1';
$fin_info = $this->db->query("CALL sp_a_run ('SELECT','$fin_qry')");
$fin_rslt = $fin_info->result();
$fin_info->next_result();
$fy_list[""] = "---- Select ----";
foreach($fin_rslt as $val){
$fy_id = $val->id;
$fy_name = $val->value;
$fy_list[$fy_id] = $fy_name;
}
$data['fy_list'] = $fy_list;
$this->load->view("$this->control_name/manage",$data);
}
public function check_form_16(){
$encString = file_get_contents('php://input');
$_POST = $this->cryptoDecrypt($encString);
if(!$_POST){
echo json_encode(array('success' => false,'message' => 'Url Expired.. Please refresh the page and try again....','table_data' => ""));
exit(0);
}
$emp_code = $this->input->post('emp_code');
$financial_year = $this->input->post('financial_year');
$tble_line = "";
// GET FINANCIAL YEAR
$fin_year_qry = 'SELECT start_date,end_date,CONCAT(DATE_FORMAT(start_date,"%Y")," - ",DATE_FORMAT(end_date,"%y")) as value FROM `cw_financial_setting` WHERE prime_financial_setting_id = "'.$financial_year.'"';
$fin_year_info = $this->db->query("CALL sp_a_run ('SELECT','$fin_year_qry')");
$fin_year_rslt = $fin_year_info->result();
$fin_year_info->next_result();
$fin_end_year = date('Y',strtotime($fin_year_rslt[0]->end_date));
$fin_st_end = $fin_year_rslt[0]->value;
// GET PAN NUMBER
$pan_num_qry ='select pan_number from cw_employees where employee_code="'.$emp_code.'"';
$pan_num_info = $this->db->query("CALL sp_a_run ('SELECT','$pan_num_qry')");
$pan_number_rslt = $pan_num_info->result();
$pan_num_info->next_result();
$pan_number = $pan_number_rslt[0]->pan_number;
$db_name = $this->config->item("db_name");
// CHECK ENCRYPTION FROM COMPANY INFORMATION
$company_information = $this->company_info();
$encrypted_pdf = $company_information[0]->encrypted_pdf;
if((int)$encrypted_pdf === 1){
$db_name = $this->config->item("db_name");
$file_name = $db_name."_".$emp_code."_".$fin_end_year;
$enc_file = $this->encryptFilename($file_name,$db_name);
$enc_file_name = $enc_file."_".$emp_code;
}else{
$enc_file_name = $emp_code;
}
$folder = "form_16B/form_16B_".$fin_end_year;
if($db_name === "hare_hrms_db"){
$month_year = date('Y', $financial_year);
$check_month = "2022-23";
if($financial_year <= $check_month){
$file_path = "$folder/".strtoupper($pan_number).".pdf";
}else{
$file_path = "$folder/".$enc_file_name.".pdf";
}
}else{
$file_path = "$folder/".$enc_file_name.".pdf";
}
if(file_exists($file_path)){
$file_path = base_url().$file_path;
$filename = dirname(__FILE__).$file_path;
//FOR PATH ENCODE
$enc_path = base64_encode($file_path);
$filename = str_replace("application\controllers","",$filename);
$tble_line .= " <tr class='gradeU'>
<td>$emp_code _ $fin_st_end</td>
<td>
<a class='btn btn-primary btn-sm' onclick=pdf_viewer('$enc_path')><span class='fa fa-eye' > </span> view </a>
<a class='btn btn-primary btn-sm' id='download_$emp_code' onclick=download_form16('download_$emp_code','$enc_path') download '><span class='fa fa-download' download> </span> Download </a>
</td>
</tr>";
}else{
$tble_line = "<tr class='gradeU'>
<td colspan='2' style='text-align:center;'>No data found</td>
</tr>";
}
$table_data = "<table class='table table-striped table-bordered' id='emp_details'>
<thead>
<tr>
<th>Financial Year</th>
<th>Action</th>
</tr>
</thead>
<tbody>
$tble_line
</tbody>
</table>";
echo json_encode(array('success' => true,'table_data' => $table_data));
}
}
?>