File: //home/cafsindia/hrms_allyindian_com/application/controllers/Payslip_report.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Action_controller.php");
use Dompdf\Dompdf;
use DOMDocument;
class Payslip_report extends Action_controller{
private $emp_data_rslt;
public function __construct(){
parent::__construct('payslip_report');
if(!$this->Appconfig->isAppvalid()){
redirect('config');
}
$emp_data_qry = 'select employee_code,emp_name,date_of_birth,date_of_joining from cw_employees where trans_status = 1';
$emp_data = $this->db->query("CALL sp_a_run ('SELECT','$emp_data_qry')");
$empresult = $emp_data->result_array();
$emp_data->next_result();
$this->emp_data_rslt = array_reduce($empresult, function ($result, $arr) {
$result[$arr['employee_code']] = $arr;
return $result;
}, array());
}
// $this->load->library('pdf');
// LOAD PAGE QUICK LINK,FILTERS AND TABLE HEADERS
public function index(){
//Get Category
$role_info = $this->db->query("CALL sp_a_run ('SELECT','SELECT * FROM `cw_category` where trans_status = 1 and prime_category_id !=1')");
$role_result = $role_info->result();
$role_info->next_result();
$category_list[""] = "---- Select Category ----";
foreach($role_result as $for){
$role_id = $for->prime_category_id;
$category_name = $for->category_name;
$category_list[$role_id] = $category_name;
}
$data['category_list'] = $category_list;
$group_query = 'select label_name,view_name from cw_form_setting where prime_module_id = "employees" and field_show = "1" and input_view_type !=3 and field_type in (5,7) ORDER BY input_for,field_sort asc';
$group_info = $this->db->query("CALL sp_a_run ('SELECT','$group_query')");
$group_result = $group_info->result();
$group_info->next_result();
$group_by[""] = "---- Select Group ----";
foreach($group_result as $rlst){
$col_name = "cw_employees.".$rlst->label_name;
$view_name = $rlst->view_name;
$group_by[$col_name] = $view_name;
}
$data['group_by'] = $group_by;
//Get filter
$from_query = 'select * from cw_form_setting where prime_module_id = "employees" and field_type in (5,7) and field_show = "1" ORDER BY input_for,field_sort asc';
$form_data = $this->db->query("CALL sp_a_run ('SELECT','$from_query')");
$form_result = $form_data->result();
$form_data->next_result();
$fliter_list = $this->get_filter_data($form_result);
$data['fliter_list'] = $fliter_list;
$data['key'] = $this->generateKey();
$this->load->view("$this->control_name/manage",$data);
}
//PROVIDE QUERY AND DROPDOWN VALUES
public function get_filter_data($form_result){
$filter = array();
foreach($form_result as $setting){
$prime_form_id = (int)$setting->prime_form_id;
$prime_module_id = $setting->prime_module_id;
$input_view_type = (int)$setting->input_view_type;
$input_for = (int)$setting->input_for;
$field_type = (int)$setting->field_type;
$label_id = $setting->label_name;
$label_name = ucwords($setting->view_name);
$field_length = $setting->field_length;
$field_decimals = $setting->field_decimals;
$pick_list_type = (int)$setting->pick_list_type;
$pick_list = $setting->pick_list;
$pick_table = $setting->pick_table;
$auto_prime_id = $setting->auto_prime_id;
$auto_dispaly_value = $setting->auto_dispaly_value;
$field_isdefault = (int)$setting->field_isdefault;
$file_type = (int)$setting->file_type;
$mandatory_field = (int)$setting->mandatory_field;
$unique_field = (int)$setting->unique_field;
$search_show = (int)$setting->search_show;
$array_list = array();
if($label_id != 'role' && $label_id != 'employee_code' && $label_id != 'emp_name'){
if(($field_type === 5) || ($field_type === 7)){
if($pick_list_type === 1){
$pick_list_val = explode(",",$pick_list);
$pick_list_val_1 = $pick_list_val[0];
$pick_list_val_2 = $pick_list_val[1];
if($pick_table == "cw_category"){
$qry = " and prime_category_id != 1";
}else{
$qry = "";
}
if($pick_table == "cw_payroll_formula"){
$pick_query = "select $pick_list from $pick_table where trans_status = 1";
$pick_data = $this->db->query("CALL sp_a_run ('SELECT','$pick_query')");
$pick_result = $pick_data->result();
$pick_data->next_result();
$array_list[""] = "---- $label_name ----";
foreach($pick_result as $pick){
$pick_key = $pick->$pick_list_val_1;
$pick_val = ucwords(str_replace("_"," ",$pick->$pick_list_val_2));
$array_list[$pick_key] = $pick_val;
}
}else{
if($label_id === "excemption_component"){
$pick_query = "select $pick_list from $pick_table where trans_status = 1 and tax_section = 1 $qry";
}else{
$pick_query = "select $pick_list from $pick_table where trans_status = 1 $qry";
}
$pick_data = $this->db->query("CALL sp_a_run ('SELECT','$pick_query')");
$pick_result = $pick_data->result();
$pick_data->next_result();
$array_list[""] = "---- $label_name ----";
foreach($pick_result as $pick){
$pick_key = $pick->$pick_list_val_1;
$pick_val = $pick->$pick_list_val_2;
$array_list[$pick_key] = $pick_val;
}
}
}else
if($pick_list_type === 2){
$pick_list_val_1 = $pick_table."_id";
$pick_list_val_2 = $pick_table."_value";
$pick_list_val_3 = $pick_table."_status";
$pick_query = "select $pick_list_val_1,$pick_list_val_2 from $pick_table where $pick_list_val_3 = 1";
$pick_data = $this->db->query("CALL sp_a_run ('SELECT','$pick_query')");
$pick_result = $pick_data->result();
$pick_data->next_result();
$array_list[""] = "---- $label_name ----";
foreach($pick_result as $pick){
$pick_key = $pick->$pick_list_val_1;
$pick_val = $pick->$pick_list_val_2;
$array_list[$pick_key] = $pick_val;
}
}
}
if(($input_view_type === 1) || ($input_view_type === 2)){
$filter[] = array('label_id'=> $label_id, 'field_isdefault'=> $field_isdefault, 'array_list'=> $array_list, 'field_type'=> $field_type);
}
}
}
return $filter;
}
// Get Employee Code
public function get_employees_list(){
$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);
}
$category = $this->input->post('category');
$payslip_month = $this->input->post('payslip_month');
$emp_detail_query = 'SELECT CONCAT("<option value =",cw_transactions.employee_code," >",cw_transactions.emp_name," - ",cw_transactions.employee_code,"</option>") as result_data FROM cw_transactions WHERE cw_transactions.role in ('.$category.') and cw_transactions.process_month = "'.$payslip_month.'" and cw_transactions.trans_status = 1';
$emp_detail_info = $this->db->query("CALL sp_a_run ('SELECT','$emp_detail_query')");
$emp_detail_result = $emp_detail_info->result();
$emp_detail_info->next_result();
$result_data = array_column($emp_detail_result,'result_data');
$option = "<option value=''>---- Select Employee ----</option>".implode('',$result_data);
if(empty($emp_detail_result)){
echo json_encode(array('success'=>FALSE,'message'=>"No Data Found for this Month"));
}else{
echo json_encode(array('success'=>TRUE,'option'=>$option));
}
}
function get_fund_card($scheme_code,$as_date=null){
$post_url = $this->auth_url.'fundcard';
$post_data = new stdClass;
$post_data->auth = $this->auth_code;
$post_data->scheme_code = $scheme_code;
$post_data->plan_name = "";
if($as_date){
$post_data->as_on = $as_date;
}else{
$post_data->as_on = $this->as_date;
}
$fund_card_curl = curl_init();
curl_setopt($fund_card_curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($fund_card_curl, CURLOPT_HEADER, 0);
curl_setopt($fund_card_curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($fund_card_curl, CURLOPT_POST, 1);
curl_setopt($fund_card_curl, CURLOPT_VERBOSE, 1);
curl_setopt($fund_card_curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($fund_card_curl, CURLOPT_URL,$post_url);
curl_setopt($fund_card_curl, CURLOPT_POSTFIELDS, json_encode($post_data));
return $fund_card_curl;
}
// Pdf Generate
public function payslip_generation(){
$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);
}
$suppressed_data = $this->input->post('suppressed_data_val');
$fandf_data = $this->input->post('fandf_data_val');
$emp_codes = $this->input->post('pdf_block_employees');
$cat_id = $this->input->post('category');
$payslip_month = $this->input->post('payslip_month');
$fliter_label = $this->input->post('fliter_label');
$fliter_type = $this->input->post('fliter_type');
$filter_cond = $this->input->post('filter_cond');
$fliter_val = $this->input->post('fliter_val');
$input_field_type = $this->input->post('input_field_type');
$group_by = ltrim(implode(",",$this->input->post('group_by[]')),",");
$process_by = $this->input->post('process_by');
$process_mode = $this->input->post('process_mode');
$pdf_type = $this->input->post('pdf_type');
$filter_count = count($fliter_label ?? []);
$fliter_query = "";
$search_count = 0;
if((int)$fandf_data === 1){
$print_type_qry = " and print_type = 8";
$term_qry = " and termination_status = 1";
}else{
$print_type_qry = " and print_type = 1";
$term_qry = " and stop_pay_status = 0";
}
for($i=0;$i<=(int)$filter_count;$i++){
$db_name = $fliter_label[$i];
$table_name = $fliter_type[$i];
$db_cond = $filter_cond[$i];
$db_value = $fliter_val[$i];
$field_type = $field_type[$i];
if(($db_cond) && ($db_value)){
$search_count++;
if((int)$field_type === 4){
$search_val = date("Y-m-d",strtotime($db_value));
}else{
$search_val = $db_value;
}
if($db_cond === "LIKE"){ $search_val = "$db_value%"; }
if((int)$table_name === 1){ $fliter_query .= ' and cw_employees.'. $db_name ." ". $db_cond .' "'.$search_val.'"'; }
}
}
if($group_by){
$group_by_qry = "group by $group_by";
}else{
$group_by_qry = "";
}
$pay_exist_qry = 'select count(*) as rslt_count from cw_transactions where transactions_month = "'.$payslip_month.'" and role ="'.$cat_id.'" and trans_status = 1 '.$term_qry;
$pay_exist_data = $this->db->query("CALL sp_a_run ('SELECT','$pay_exist_qry')");
$pay_exist_result = $pay_exist_data->result();
$pay_exist_data->next_result();
$rslt_count = $pay_exist_result[0]->rslt_count;
if((int)$rslt_count === 0){
echo json_encode(array('success' => FALSE,'message' => "Please proceed fandf for this month first?"));
exit(0);
}
$pdf_design_info = $this->db->query("CALL sp_a_run ('SELECT','SELECT * FROM `cw_pdf_setting` inner join cw_print_info on cw_print_info.prime_print_info_id = cw_pdf_setting.pdf_info_name where cw_pdf_setting.trans_status = 1 and pdf_block_for = $cat_id $print_type_qry')");
$pdf_design_result = $pdf_design_info->result();
$pdf_design_info->next_result();
if($pdf_design_result){
$print_id = $pdf_design_result[0]->pdf_info_name;
$pdf_sheet_per_page = $pdf_design_result[0]->pdf_sheet_per_page;
$pdf_set_password = $pdf_design_result[0]->pdf_set_password;
$pdf_paper_size = $pdf_design_result[0]->pdf_paper_size;
$pdf_sheet_type = $pdf_design_result[0]->pdf_sheet_type;
}else{
echo json_encode(array('success'=>FALSE,'message'=>"Pdf Settings Empty"));
exit(0);
}
$category_info = $this->db->query("CALL sp_a_run ('SELECT','SELECT category_name FROM `cw_category` where trans_status = 1 and prime_category_id = $cat_id')");
$category_result = $category_info->result();
$category_info->next_result();
$category_name = $category_result[0]->category_name;
$category_name = strtolower(str_replace(" ","_",$category_name));
$design_query = 'SELECT * FROM cw_print_design inner join cw_print_info on cw_print_info.prime_print_info_id = cw_print_design.print_design_for WHERE cw_print_design.print_design_for ="'.$print_id.'"';
$design_info = $this->db->query("CALL sp_a_run ('SELECT','$design_query')");
$design_result = $design_info->result();
$design_info->next_result();
$design_name = $design_result[0]->print_info_name;
$design_name = strtolower(str_replace(" ","_",$design_name));
$design_qry = 'SELECT print_design from cw_print_design where print_design_for = "'.$print_id.'" and trans_status = 1';
$design_data = $this->db->query("CALL sp_a_run ('SELECT','$design_qry')");
$design_result = $design_data->result();
$design_data->next_result();
$print_design = $design_result[0]->print_design;
$print_design = str_replace('~','"',$print_design);
$block_qry = 'select * from cw_print_block where print_block_for = "'.$print_id.'" and trans_status = 1';
$block_data = $this->db->query("CALL sp_a_run ('SELECT','$block_qry')");
$block_result = $block_data->result();
$block_data->next_result();
$table_qry = 'select * from cw_print_table where trans_status = 1';
$table_data = $this->db->query("CALL sp_a_run ('SELECT','$table_qry')");
$table_result = $table_data->result_array();
$table_data->next_result();
$print_table_result = array_reduce($table_result, function ($result, $arr) {
$result[$arr['print_table_for_id']] = $arr;
return $result;
}, array());
$emp_code_arr = implode('","', $emp_codes);
$emp_qry = 'SELECT prime_employees_id,emp_name,employee_code FROM `cw_employees` where trans_status = 1 and employee_code in ("'.$emp_code_arr.'") '.$fliter_query.''.$group_by_qry.'';
$emp_info = $this->db->query("CALL sp_a_run ('SELECT','$emp_qry')");
$emp_rslt = $emp_info->result_array();
$emp_info->next_result();
$emp_rslt = array_reduce($emp_rslt, function ($result, $arr) {
$result[$arr['employee_code']] = $arr;
return $result;
}, array());
$emp_codes = array_values(array_column($emp_rslt, 'employee_code'));
$split_qry = 'select * from cw_print_split where trans_status = 1';
$split_data = $this->db->query("CALL sp_a_run ('SELECT','$split_qry')");
$split_result_arr = $split_data->result_array();
$split_data->next_result();
$split_result_arr = array_reduce($split_result_arr, function($result, $arr){
$result[$arr['split_table_info']] = $arr;
return $result;
}, array());
$where_qry = 'select where_condition,where_for_id from cw_print_table_where where trans_status = 1';
$where_data = $this->db->query("CALL sp_a_run ('SELECT','$where_qry')");
$where_result = $where_data->result_array();
$where_data->next_result();
$where_result = array_reduce($where_result, function($result, $arr){
$result[$arr['where_for_id']] = $arr;
return $result;
}, array());
$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"';
$form_data = $this->db->query("CALL sp_a_run ('SELECT','$form_qry')");
$form_result_array = $form_data->result_array();
$form_data->next_result();
$form_result_array = array_reduce($form_result_array, function($result, $arr){
$result[$arr['prime_module_id']][$arr['label_name']][] = $arr;
return $result;
}, array());
$emp_codes_array = array_filter($emp_codes);
$in_empcode = implode(',', $emp_codes_array);
$in_empcode = str_replace(',', '","', $in_empcode);
if((int)$process_mode === 1){
$folder_name = "payslip/".$category_name."/".$payslip_month."_".$design_name;
$final_qry_array = $this->load_all_data($design_result,$print_design,$block_result,$print_table_result,$print_id,$emp_code,$payslip_month,$split_result_arr,$where_result,$form_result_array,$in_empcode);
$final_qry = $final_qry_array['final_qry'];
$split_array = $final_qry_array['split_array'];
$map_column = $final_qry_array['map_column'];
$print_design = $final_qry_array['print_design'];
$block_result = $final_qry_array['block_result'];
$assign_date_formate_list = $final_qry_array['assign_date_formate_list'];
$final_qry_data = $this->db->query("CALL sp_a_run ('SELECT','$final_qry')");
$final_qry_result = $final_qry_data->result();
$final_qry_data->next_result();
$tble_line = "";
foreach($block_result as $block){
$print_block_type = (int)$block->print_block_type;
$print_block_column = $block->print_block_column;
if($final_qry_result){
$data['print_sts'] = true;
$emp_detail_arr = array();
$emp_data_arr = array();
$final_data_rslt = array();
foreach($final_qry_result as $rslt){
$count++;
$map_column = explode(",",$print_block_column);
$td_line = "";
$print_design = $final_qry_array['print_design'];
foreach($map_column as $table_column){
$map_column = explode(".",$table_column);
$column = $map_column[1];
$value = $rslt->$column;
$replace_val = "@".$column."@";
// echo "$replace_val :: $value<br>";
if($column == 'net_pay'){
$value = $rslt->$column;
$print_design = str_replace($replace_val,$value,$print_design);
$net_pay_val = $value;
$net_pay_words = $this->numbertowords($net_pay_val);
$net_pay_words = strtoupper($net_pay_words);
$print_design = str_replace("@net_pay_words@",$net_pay_words,$print_design);
}
if($split_array[$replace_val]){
//Process split informtion
$process_function = $split_array[$replace_val];
if((int)$process_function === 1){
$transactions_month = $final_qry_result[0]->transactions_month;
$employee_code = $final_qry_result[0]->employee_code;
$loan_info = $this->get_loan_value($transactions_month,$employee_code);
$print_design = str_replace($replace_val,$loan_info,$print_design);
}
}else{
if($print_block_type === 1){
$print_design = str_replace($replace_val,$value,$print_design);
foreach($assign_date_formate_list as $key=>$formate){
if($column == 'transactions_month'){//transactions month static updated
$start = "@".$key."_";
$end = "_".$key."@";
$replace_val = $start.$column.$end;
$value = date('Y-m-d',strtotime("01-".$rslt->$column));
$date_value = date_create($value);
$replace_value = strtoupper(date_format($date_value,$formate));
$print_design = str_replace($replace_val,$replace_value,$print_design);
}else{//not static month updated
$start = "@".$key."_";
$end = "_".$key."@";
$replace_val = $start.$column.$end;
$replace_val = $start.$column.$end;
$date_value = date_create($value);
$replace_value = date_format($date_value,$formate);
$print_design = str_replace($replace_val,$replace_value,$print_design);
}
}
}else
if($print_block_type === 2){
$td_line .= "<td style='text-align:center;'>$value</td>";
}
if($count === 1){
$head_name = ucwords(str_replace("_"," ",$column));
if(($value === "") || ($value === "0.00") || ($value === "0") || (!$value)){
$th_line = "";
}else{
$th_line .= "<th style='text-align:center;'>$head_name</th>";
}
}
}
if($column === 'employee_code'){
$emp_code = $value;
}else
if($column === 'emp_name'){
$emp_name = $value;
}
}
if($print_block_type === 2){
if($count === 1){
if(($value === "") || ($value === "0.00") || ($value === "0") || (!$value)){
$th_line = "";
}else{
$th_line = "$th_line";
$tr_line .= "<tr>$td_line</tr>";
}
}
}
/*if((int)$suppressed_data === 1){
$print_design = str_replace("<br>","",$print_design);
}*/
$print_design = str_replace("<br>","",$print_design);
if($print_block_type === 2){
$table_list = "<table style='width:100%;'><thead>$th_line</thead><tbody>$tr_line</tbody></table>";
$replce_block = "@".strtolower(str_replace(" ","_",$print_block_name))."@";
$print_design = str_replace($replce_block,$table_list,$print_design);
}
if((int)$pdf_type === 1){
$emp_data_arr[$emp_code]['emp_code'] = $emp_code;
$emp_data_arr[$emp_code]['print_design'] = $print_design;
}else
if((int)$pdf_type === 2){
$emp_data_arr[$emp_code]= $print_design;
}
}
}
}
$get_pdf_design = "";
foreach ($emp_data_arr as $i => $emp_detail) {
if((int)$pdf_type === 1){
$emp_code = $emp_detail['emp_code'];
$print_design = $emp_detail['print_design'];
$final_html = "<!DOCTYPE html>
<head></head>
<style> table {
border-collapse: collapse;
}
table td.fr-highlighted,.fr-view table th.fr-highlighted{
border:1px solid black !important;
}
</style><body>".$print_design."</body></html>";
$fetchURL = $this->get_pdf($design_name,$pdf_paper_size,$pdf_sheet_type,$pdf_set_password,$pdf_sheet_per_page,$print_id,$final_html,$category_name,$payslip_month,$emp_code,$process_by,$pdf_type,$suppressed_data);
}else
if((int)$pdf_type === 2){
$get_pdf_design .= $emp_detail;
}
}
if((int)$pdf_type === 2){
$final_rslt = "<!DOCTYPE html>
<head></head><body><div class='print_hide'><a href='javascript:window.print();' class='btn btn-info btn-sm', id='show_print_button'> <i class='fa fa-print fa-lg'></i> Print</a></div>".$get_pdf_design."</body></html>";
$folder_name = $category_name."/".$payslip_month."_".$design_name;
$get_pdf = $this->get_pdf($design_name,$pdf_paper_size,$pdf_sheet_type,$pdf_set_password,$pdf_sheet_per_page,$print_id,$final_rslt,$category_name,$payslip_month,$emp_code,$process_by,$pdf_type,$suppressed_data);
}
}
$folder_name = "payslip/".$category_name."/".$payslip_month;
$dw_all = $category_name."/".$payslip_month;
$table_data = $this->view_emp_details($emp_codes_array,$process_by,$pdf_type,$process_mode,$folder_name,$suppressed_data,$category_name,$emp_rslt,$dw_all);
echo json_encode(array('success' => true,'message' => '', 'table_data' => $table_data));
}
public function get_pdf($design_name,$pdf_paper_size,$pdf_sheet_type,$pdf_set_password,$pdf_sheet_per_page,$print_id,$content,$category_name,$payslip_month,$emp_code,$process_by,$pdf_type,$suppressed_data){
$folder = "./payslip/$category_name/".$payslip_month;
if((int)$pdf_type === 1){
$file_type = ".pdf";
}else
if((int)$pdf_type === 2){
$file_type = ".html";
$emp_code = "combined_".$category_name;
}
$path = $this->generate_pdf_bulk($content,$folder,$emp_code,$pdf_sheet_type,$pdf_paper_size,$pdf_set_password,$file_type,$suppressed_data,$process_by,$pdf_type);
return $path;
}
public function load_all_data($design_result,$print_design,$block_result,$print_table_result,$print_id,$emp_code,$payslip_month,$split_result_arr,$where_result,$form_result_array,$in_empcode){
$data['print_sts'] = false;
foreach($block_result as $block){
$prime_print_block_id = $block->prime_print_block_id;
$print_block_name = $block->print_block_name;
$print_block_type = (int)$block->print_block_type;
$print_block_table = $block->print_block_table;
$print_block_column = $block->print_block_column;
$cumulative_data = $block->cumulative_data;
$table_result = $print_table_result[$prime_print_block_id];
$line_table_query = "";
$cutome_table_check = array('transactions'=>'cw_transactions');
//foreach($table_result as $table){
$line_prime_table = $table_result['line_prime_table'];
$line_prime_col = $table_result['line_prime_col'];
$line_join_type = $table_result['line_join_type'];
$line_join_table = $table_result['line_join_table'];
$line_join_col = $table_result['line_join_col'];
$line_sort = $table_result['line_sort'];
$module_name = str_replace("cw_","",$line_prime_table);
$prime_id = "prime_".$module_name."_id";
$join_module_name = str_replace("cw_","",$line_join_table);
$join_prime_id = "prime_".$join_module_name."_id";
if((int)$line_sort === 1){
if($cutome_table_check[$module_name]){
$line_prime_table = " $line_prime_table ";
}else{
$line_prime_table = " $line_prime_table ";
}
if($cutome_table_check[$join_module_name]){
$line_join_table = " $line_join_table on $line_join_col = $line_prime_col";
}else{
$line_join_table = " $line_join_table on $line_join_col = $line_prime_col ";
}
$line_table_query .= " $line_prime_table $line_join_type join $line_join_table";
}else{
if($cutome_table_check[$join_module_name]){
$line_table_query .= " $line_join_type join $line_join_table on $line_join_col = $line_prime_col ";
}else{
$line_table_query .= " $line_join_type join $line_join_table on $line_join_col = $line_prime_col ";
}
}
//}
if(!$line_table_query){
$module_name = str_replace("cw_","",$print_block_table);
$prime_id = "prime_".$module_name."_id";
$line_table_query = " $print_block_table ";
}
if(!$print_block_column){
$print_block_column = "*";
}else{
$select_query = "";
$pick_query = "";
$map_column = explode(",",$print_block_column);
foreach($map_column as $table_column){
$map_column = explode(".",$table_column);
$table_name = $map_column[0];
$column = $map_column[1];
$control_name = str_replace('cw_',"",$table_name);
if($control_name === "transactions"){
$control_name = "employees";
}
$form_result = $form_result_array[$control_name][$column];
foreach($form_result as $form){
$prime_form_id = (int)$form['prime_form_id'];
$view_name = $form['view_name'];
$label_name = $form['label_name'];
$field_type = (int)$form['field_type'];
$pick_list_type = (int)$form['pick_list_type'];
$pick_list = $form['pick_list'];
$pick_table = $form['pick_table'];
$auto_prime_id = $form['auto_prime_id'];
$auto_dispaly_value = $form['auto_dispaly_value'];
//echo "BSK $label_name :: $field_type <br/>";
if($label_name){
if((int)$field_type === 4){
$select_query .= 'DATE_FORMAT('.$table_name.'.'.$label_name.', "%d-%m-%Y") as '.$label_name.' , ';
}else
if(($field_type === 5) || ($field_type === 7)){
if($pick_list_type === 1){
$pick_list_val = explode(",",$pick_list);
$pick_list_val_1 = $pick_list_val[0];
$pick_list_val_2 = $pick_list_val[1];
$pick_query_as = $pick_table."_".$prime_form_id;
$select_query .= "$pick_query_as.$pick_list_val_2 as $label_name , ";
$pick_query .= " left join $pick_table as $pick_query_as on $pick_query_as.$pick_list_val_1 = $table_name.$label_name ";
}else
if($pick_list_type === 2){
$pick_list_val_1 = $pick_table."_id";
$pick_list_val_2 = $pick_table."_value";
$pick_list_val_3 = $pick_table."_status";
$pick_query_as = $pick_table."_".$prime_form_id;
$select_query .= "$pick_query_as.$pick_list_val_2 as $label_name , ";
$pick_query .= " left join $pick_table as $pick_query_as on $pick_query_as.$pick_list_val_1 = $table_name.$label_name ";
}
}else
if($field_type === 9){
$pick_query_as = $pick_table."_".$prime_form_id;
$select_query .= "$pick_query_as.$auto_dispaly_value as $label_name,";
$pick_query .= " left join $pick_table as $pick_query_as on $pick_query_as.$auto_prime_id = $table_name.$label_name ";
}else
if(($field_type === 2) || ($field_type === 3)){
$label_ytd = $label_name."_ytd";
$select_ytd_query .= "sum($table_name.$label_name) as $label_ytd, ";
$select_query .= "$table_name.$label_name , ";
}else{
$select_query .= "$table_name.$label_name , ";
}
}
}
}
}
$where_trans = "";
$where_trans_info = explode(",",$print_block_table);
foreach($where_trans_info as $trans_info){
if($trans_info === "cw_transactions"){
$select_query .= "cw_transactions.transactions_month , ";
}
$where_trans .= "$trans_info.trans_status = 1 and ";
}
$where_trans = rtrim($where_trans,'and ');
$where_rslt = $where_result[$prime_print_block_id];
// $where_condition = "";
if(!empty($where_rslt)){
$where_condition = str_replace('^','"',$where_rslt[0]->where_condition);
$where_condition = str_replace('@logged_id@',$emp_id,$where_condition);
$where_condition = str_replace('@input_month@',$payslip_month,$where_condition);
$session_date_list = array("logged_DMY"=>"d-m-Y","logged_YMD"=>"Y-m-d","logged_MY"=>"m-Y","logged_YM"=>"Y-m","logged_Y"=>"Y");
$session_query = 'select session_value from cw_session_value where session_for = 1 and trans_status = "1"';
$session_data = $this->db->query("CALL sp_a_run ('SELECT','$session_query')");
$session_result = $session_data->result();
$session_data->next_result();
foreach($session_result as $rslt){
$session_value = $rslt->session_value;
if($session_value !== "access_data"){
$exist_val = "@".$session_value."@";
if($session_date_list[$session_value]){
$date_formate = $session_date_list[$session_value];
$saved_session_val = date($date_formate);
}else{
$saved_session_val = $this->session->userdata($session_value);
}
$where_condition = str_replace($exist_val,$saved_session_val,$where_condition);
}
}
}else{
$where_condition = " and cw_transactions.transactions_month=\"$payslip_month\" and cw_transactions.employee_code in(\"$in_empcode\")";
}
$select_query = rtrim($select_query,',');
$select_query = rtrim($select_query,' , ');
if((int)$cumulative_data === 1){
$start_fin_date = $this->financial_info[0]->start_date;
$start_fin_date = date('m-Y',strtotime($start_fin_date));
$select_ytd_query = rtrim($select_ytd_query,',');
$select_ytd_query = rtrim($select_ytd_query,' , ');
$where_ytd_condition = ' and cw_transactions.employee_code="'.$emp_code.'" and date_format(str_to_date(transactions_month, "%m-%Y") , "%Y-%m") >= date_format(str_to_date("'.$start_fin_date.'", "%m-%Y"), "%Y-%m") and date_format(str_to_date(transactions_month, "%m-%Y") , "%Y-%m") <= date_format(str_to_date("'.$payslip_month.'", "%m-%Y"), "%Y-%m")';
$final_ytd_qry = "select $select_ytd_query from $line_table_query $pick_query where $where_trans $where_ytd_condition";
$final_ytd_data = $this->db->query("CALL sp_a_run ('SELECT','$final_ytd_qry')");
$final_ytd_result = $final_ytd_data->result();
$final_ytd_data->next_result();
foreach($final_ytd_result as $ytd_rslt){
$map_column = explode(",",$print_block_column);
foreach($map_column as $table_column){
$map_column = explode(".",$table_column);
$ytd_column = $map_column[1]."_ytd";
$ytd_value = $ytd_rslt->$ytd_column;
$replace_ytd_val = "@".$ytd_column."@";
$print_design = str_replace($replace_ytd_val,$ytd_value,$print_design);
}
}
}
$final_qry = "select $select_query from $line_table_query $pick_query where $where_trans $where_condition";
$tr_line = "";
$th_line = "";
$count = 0;
$assign_date_formate_list = array("DMY"=>"d-m-Y","YMD"=>"Y-m-d","MY"=>"F-Y","YM"=>"Y-F","D"=>"d","M"=>"M","Y"=>"Y");
$split_array = array();
$split_result = $split_result_arr[$print_id];
foreach($split_result as $split){
$split_info = $split->split_info;
$split_colum = $split->split_colum;
$split_array[$split_colum] = $split_info;
}
}
$map_column = explode(",",$print_block_column);
$final_qry_array = array('final_qry'=>$final_qry,'split_array'=>$split_array,'map_column'=>$map_column,'print_design'=>$print_design,'assign_date_formate_list'=>$assign_date_formate_list,'block_result'=>$block_result);
return $final_qry_array;
}
public function generate_pdf_bulk($table_data,$folder,$file_name,$set_paper,$paper_size,$pdf_set_password,$file_type,$suppressed_data,$process_by,$pdf_type){
if((int)$suppressed_data === 1){
$dom = new \DOMDocument();
$dom->loadHTML($table_data);
$xpath = new \DOMXPath($dom);
//loop all <tr> element.
foreach ($xpath->query('//tr') as $tr) {
$get_cls = $tr->getAttribute("class");
$tds = $tr->getElementsByTagName('td');
// if($get_cls !== 'except'){
for ($i = 0; $i <= count($tr); $i++){
// get table cell value.
$table_cell_value = $tds->item($i)->nodeValue;
if($table_cell_value === '0.00'){
if($tr){
$tr->parentNode->removeChild($tr);
}
}
}
// }
}
// get the result
$saved_html = preg_replace('~<(?:!DOCTYPE|/?(?:html|body))[^>]*>\s*~i', '', $dom->saveHTML());
}else{
$saved_html = $table_data;
}
$folder = $folder;
$file_name = $file_name;
$pdf = new DOMPDF(array('enable_remote' => true,"enable_font_subsetting" => true));
// Load HTML content
$pdf->loadHtml($saved_html);
// (Optional) Setup the paper size and orientation
$pdf->setPaper($paper_size, $set_paper);
// Render the HTML as PDF
if((int)$process_by === 2 && (int)$pdf_type === 2){
// $pdf->render();
}else{
$pdf->render();
}
if($pdf_set_password === "1"){
//SET Production
$dob = date("d-m-Y",strtotime($this->emp_data_rslt[$file_name]['date_of_birth']));
$doj = date("d-m-Y",strtotime($this->emp_data_rslt[$file_name]['date_of_joining']));
$password = $dob."@".$doj;
$password = str_replace("-", "", $password);
$pdf->get_canvas()->get_cpdf()->setEncryption($password, $password);
}
// Output the generated PDF (1 = download and 0 = preview)
$output = $pdf->output();
$final_html = $output;
$oldmask = umask(0);
if (!file_exists($folder)){
mkdir($folder, 0777, true);
}
//File write
file_put_contents($folder."/".$file_name.$file_type , $final_html);
chmod($folder."/".$file_name.$file_type, 0777);
umask($oldmask);
if($file_type === ".html"){
if(file_exists($folder)){
unlink($folder."/".$file_name.$file_type);
}
$file = $folder."/".$file_name.$file_type;
$myfile = fopen($file, "w") or die("Unable to open file!");
$saved_html = "<!DOCTYPE html>
<html>
<head></head>
<body>".$saved_html."</body>
</html>";
fwrite($myfile, $saved_html);
}
$path = $folder."/".$file_name.$file_type;
return $path;
}
public function download_zip(){
//Encryption
$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);
}
$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);
}
$path_name = $this->input->post('path_name');
$path = "./payslip/".$path_name."/";
$zip = new ZipArchive();
$filename = "./payslip/".$path_name.".zip";
if ($zip->open($filename, ZipArchive::CREATE)!==TRUE) {
exit("cannot open <$filename>\n");
}
$dir = $path;
if (is_dir($dir)){
if ($dh = opendir($dir)){
while (($file = readdir($dh)) !== false){
if (is_file($dir.$file)) {
if($file != '' && $file != '.' && $file != '..'){
$zip->addFile($dir.$file);
}
}
}
closedir($dh);
}
}
$zip->close();
$filename = str_replace("./","",$filename);
echo json_encode(array('success' => true,'filename' => $filename));
}
public function view_emp_details($emp_codes_array,$process_by,$pdf_type,$process_mode,$folder_name,$suppressed_data,$category_name,$emp_rslt,$dw_all){
if((int)$pdf_type === 1){
$tble_line = "";
foreach ($emp_codes_array as $key => $emp_code) {
$emp_name = $emp_rslt[$emp_code]['emp_name'];
$file_path = $folder_name."/".$emp_code.".pdf";
$exist_file = './'.$folder_name."/".$emp_code.".pdf";
$exist_process = true;
if((int)$process_mode === 2){
if(file_exists($exist_file)){
$exist_process = true;
}else{
$exist_process = false;
}
}
$file_path = base_url().$file_path;
$filename = dirname(__FILE__).$file_path;
$filename = str_replace("application\controllers","",$filename);
if($exist_process){
$tble_line .= " <tr class='gradeU'>
<td>$emp_code</td>
<td>$emp_name</td>
<td>
<a class='btn btn-primary btn-sm' onclick=pdf_viewer('$file_path')><span class='fa fa-eye' > </span> view </a>
<a class='btn btn-primary btn-sm' id='download_$emp_code' href='$file_path' download '><span class='fa fa-download' download> </span> Download </a>
</td>
</tr>";
}
}
if((int)$process_by === 2){
$tfoot_list ="<tfoot>
<tr class='gradeU'><td></td><td style='text-align:center;'><a class='btn btn-primary btn-sm' onclick = download_zip('$dw_all') ><span class='fa fa-download' > </span> Download All </a></td><td></td></tr>
</tfoot>";
}else{
$tfoot_list ="";
}
$table_data = " <table class='table table-striped table-bordered' id='emp_details'>
<thead>
<tr>
<th>Employee Code</th>
<th>Employee Name</th>
<th>Action</th>
</tr>
</thead>
<tbody>
$tble_line
</tbody>
$tfoot_list
</table>";
}else{
$combined_name = "combined_".$category_name;
$file_path = "$folder_name/$combined_name.html";
$exist_file = './'.$folder_name.'/'.$combined_name.'.html';
$file_path = base_url().$file_path;
$filename = dirname(__FILE__).$file_path;
$filename = str_replace("application\controllers","",$filename);
$exist_process = true;
if((int)$process_mode === 2){
if(file_exists($exist_file)){
$exist_process = true;
}else{
$exist_process = false;
}
}
$tble_line = "";
if($exist_process){
$tble_line .= "<tr class='gradeU'>
<td>$category_name</td>
<td>
<a class='btn btn-primary btn-sm' onclick=pdf_viewer('$file_path')><span class='fa fa-eye' > </span> view </a>
<a class='btn btn-primary btn-sm' id='download_$combined_name' href='$file_path' download><span class='fa fa-download' download> </span> Download </a>
</td>
</tr>";
}else{
$tble_line .= "";
}
$table_data = " <table class='table table-striped table-bordered' id='emp_details'>
<thead>
<tr>
<th>Category Name</th>
<th>Action</th>
</tr>
</thead>
<tbody>
$tble_line
</tbody>
</table>";
}
return $table_data;
}
}