File: /home/cafsindia/hrms_patroniss_com/application/controllers/Payslip_report_09sep2021.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Base_controller.php");
class Payslip_report extends Base_controller{
public function __construct(){
parent::__construct('payslip_report');
if(!$this->Appconfig->isAppvalid()){
redirect('config');
}
// Load pdf library
$this->load->library('pdf');
$this->collect_base_info();
}
// LOAD PAGE WITH TABLE DATA
public function index(){
$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;
$from_query = 'select * from cw_form_setting where prime_module_id = "employees" 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;
$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;
}
//START TO VIEW AND DOWNLOAD PAYSLIPS
public function payslip_generation(){
$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[]')),",");
$suppressed_data = $this->input->post('suppressed_data_val');
$process_by = $this->input->post('process_by');
$pdf_type = $this->input->post('pdf_type');
$filter_count = count($fliter_label);
$fliter_query = "";
$search_count = 0;
$fandf_data = $this->input->post('fandf_data_val');
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 = "";
}
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);
}
$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));
$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);
}
$design_query = 'SELECT * FROM cw_print_design inner join cw_print_info on cw_print_info.prime_print_info_id = print_design_for WHERE 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;
//CATEGORY NAME AND CATEGORY BASED DESIGN DOWNLOAD
if((int)$pdf_type === 2){
if((int)$process_by === 2){ //ALL EMPLOYEES IS CATEGORY BASED
//substring_index(GROUP_CONCAT(DISTINCT cw_transactions.employee_code), ",", 20) as employee_code
$emp_code_query = 'SELECT GROUP_CONCAT(DISTINCT cw_transactions.employee_code) as employee_code from cw_transactions join cw_employees on cw_employees.employee_code = cw_transactions.employee_code where cw_employees.role = "'.$cat_id.'" '.$fliter_query.' and cw_transactions.trans_status = 1 and cw_transactions.process_month = "'.$payslip_month.'" '.$group_by_qry.'order by prime_employees_id ';
$emp_code_info = $this->db->query("CALL sp_a_run ('SELECT','$emp_code_query')");
$emp_code_result = $emp_code_info->result();
$emp_code_info->next_result();
$emp_code_rslt = $emp_code_result[0]->employee_code;
$emp_code_rslt = explode(",",$emp_code_rslt);
}else{ //USER CHOOSING EMPLOYEE LIST
$emp_code_rslt = $this->input->post('pdf_block_employees[]');
}
$this->load_print_combined_data($print_id,$emp_code_rslt,$payslip_month,$pdf_sheet_per_page,$pdf_design_result,$category_name,$suppressed_data);
echo json_encode(array('success'=>TRUE,'design_name'=>$design_name,'pdf_name'=>$pdf_name,'suppressed_data'=>$suppressed_data,'pdf_paper_size'=>$pdf_paper_size,'pdf_sheet_type'=>$pdf_sheet_type,'pdf_set_password'=>$pdf_set_password));
}else{
//For Single Sheet for all employee code
$emp_code = $this->input->post('pdf_block_employees');
$pdf_name = $emp_code;
$data = "<div id= 'content_$emp_code' >";
$data .= $this->load_print_data($print_id,$emp_code,$payslip_month);
$data = str_replace("<table cellspacing=\"0\" id=\"tbl\"", "<table cellspacing=\"0\" id='tbl_$emp_code' ", $data);
$data .= "<div>";
if((int)$suppressed_data === 1){
$file = "suppressed_data_".$emp_code.".html";
$myfile = fopen($file, "w") or die("Unable to open file!");
//<script src='./dist/jquery.min.js'></script>
$data .= "<script> $( document ).ready(function() {
$('#tbl_$emp_code tr td').each(function() {
var cellText = $.trim($(this).text());
if (cellText.length == '0') {
//$(this).closest('td').prev().empty();
//$(this).text('')
$(this).parent('tr').remove();
}else
if(cellText == '0.00'){
//$(this).closest('td').prev().empty();
//$(this).text('');
$(this).parent('tr').remove();
}
});
}); </script>";
$final_result = "<!DOCTYPE html><html><head>
</head><body>".$data."</body></html>";
fwrite($myfile, $final_result);
}else{
$final_result = "<!DOCTYPE html><html>
<head>
</head>
<body>".$data."</body></html>";
}
echo json_encode(array('success'=>TRUE,'design_name'=>$design_name,'pdf_name'=>$pdf_name,'suppressed_data'=>$suppressed_data,'final_result'=>$final_result,'pdf_paper_size'=>$pdf_paper_size,'pdf_sheet_type'=>$pdf_sheet_type,'pdf_set_password'=>$pdf_set_password));
}
}
//GET EMPLOYEE LIST SVK EDIT
public function get_employees_list(){
$category = $this->input->post('category');
$payslip_month = $this->input->post('payslip_month');
$emp_detail_query = 'SELECT CONCAT("<option value =",cw_transactions.employee_code," >",cw_employees.emp_name," - ",cw_transactions.employee_code,"</option>") as result_data FROM cw_transactions join cw_employees on cw_employees.employee_code = cw_transactions.employee_code WHERE cw_employees.role in ('.$category.') and cw_transactions.trans_status = 1 and cw_transactions.process_month = "'.$payslip_month.'"';
$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)){
$option = "<option value ='0'>No data Found</option>";
}
echo $option;
}
//COLLECT PRINT DESIGN DATA
public function load_print_data($print_doc_id,$emp_code,$payslip_month){
$data['print_sts'] = false;
$design_qry = 'SELECT * from cw_print_design where print_design_for = "'.$print_doc_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_doc_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();
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_qry = 'select * from cw_print_table where print_table_for_id = "'.$prime_print_block_id.'" and trans_status = 1';
$table_data = $this->db->query("CALL sp_a_run ('SELECT','$table_qry')");
$table_result = $table_data->result();
$table_data->next_result();
$line_table_query = "";
$cutome_table_check = array('transactions'=>'cw_transactions');
foreach($table_result as $table){
$line_prime_table = $table->line_prime_table;
$line_prime_col = $table->line_prime_col;
$line_join_type = $table->line_join_type;
$line_join_table = $table->line_join_table;
$line_join_col = $table->line_join_col;
$line_sort = $table->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_qry = 'select 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 prime_module_id = "'.$control_name.'" and label_name = "'.$column.'" and trans_status = "1"';
$form_data = $this->db->query("CALL sp_a_run ('SELECT','$form_qry')");
$form_result = $form_data->result();
$form_data->next_result();
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;
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_qry = 'select * from cw_print_table_where where where_for_id = "'.$prime_print_block_id.'" and trans_status = 1';
$where_data = $this->db->query("CALL sp_a_run ('SELECT','$where_qry')");
$where_result = $where_data->result();
$where_data->next_result();
//$where_condition = "";
if(!empty($where_result)){
$where_condition = str_replace('^','"',$where_result[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=\"$emp_code\"";
}
$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";
$final_data = $this->db->query("CALL sp_a_run ('SELECT','$final_qry')");
$final_result = $final_data->result();
$final_data->next_result();
$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_qry = 'select * from cw_print_split where trans_status = 1 and split_table_info ="'.$print_doc_id.'"';
$split_data = $this->db->query("CALL sp_a_run ('SELECT','$split_qry')");
$split_result = $split_data->result();
$split_data->next_result();
$split_array = array();
foreach($split_result as $split){
$split_info = $split->split_info;
$split_colum = $split->split_colum;
$split_array[$split_colum] = $split_info;
}
if($final_result){
$data['print_sts'] = true;
foreach($final_result as $rslt){
$count++;
$map_column = explode(",",$print_block_column);
$td_line = "";
foreach($map_column as $table_column){
$map_column = explode(".",$table_column);
$column = $map_column[1];
$value = $rslt->$column;
$replace_val = "@".$column."@";
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_result[0]->transactions_month;
$employee_code = $final_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 = ucwords(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($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($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);
}
}
}
$print_design = str_replace("<br>","",$print_design);
return $print_design;
}
//COLLECT PRINT DESIGN DATA
public function load_print_combined_data($print_doc_id,$emp_code_rslt,$payslip_month,$pdf_sheet_per_page,$pdf_design_result,$category_name,$suppressed_data){
$data['print_sts'] = false;
$design_qry = 'SELECT print_design from cw_print_design where print_design_for = "'.$print_doc_id.'" and trans_status = 1';
$design_data = $this->db->query("CALL sp_a_run ('SELECT','$design_qry')");
$design_result = $design_data->row();
$design_data->next_result();
$print_design = $design_result->print_design;
$print_design = str_replace('~','"',$print_design);
$block_qry = 'select cw_print_block.prime_print_block_id,cw_print_block.print_block_name,cw_print_block.print_block_type,cw_print_block.print_block_table,cw_print_block.print_block_column,cw_print_block.cumulative_data from cw_print_block where print_block_for = "'.$print_doc_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();
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_qry = 'select line_prime_table,line_prime_col,line_join_type,line_join_table,line_join_col,line_sort from cw_print_table where print_table_for_id = "'.$prime_print_block_id.'" and trans_status = 1';
$table_data = $this->db->query("CALL sp_a_run ('SELECT','$table_qry')");
$table_result = $table_data->result();
$table_data->next_result();
$cutome_table_check = array('transactions'=>'cw_transactions');
$results = array_map(function($table){
$line_prime_table = $table->line_prime_table;
$line_prime_col = $table->line_prime_col;
$line_join_type = $table->line_join_type;
$line_join_table = $table->line_join_table;
$line_join_col = $table->line_join_col;
$line_sort = $table->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 ";
}
}
return $line_table_query;
}, $table_result);
$line_table_query = implode('',$results);
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);
$column_name = '';
$module_name = '';
$check_column_array = array();
$check_table_array = array();
foreach($map_column as $table_column){
$map_column = explode(".",$table_column);
$table_name = $map_column[0];
$column = $map_column[1];
$check_table_array[$column] = $table_name;
$control_name = str_replace('cw_',"",$table_name);
if($control_name === "transactions"){
$check_column_array[] = $column;
$control_name = "employees";
}
$column_name .= "\"$column\",";
$module_name .= "\"$control_name\",";
}
$column_name = '('.rtrim($column_name,',').')';
$module_name = '('.rtrim($module_name,',').')';
$form_qry = "select cw_form_setting.prime_form_id,cw_form_setting.view_name,cw_form_setting.label_name,cw_form_setting.field_type,cw_form_setting.pick_list_type,cw_form_setting.pick_list,cw_form_setting.pick_table,cw_form_setting.auto_prime_id,cw_form_setting.auto_dispaly_value,cw_form_setting.prime_module_id from cw_form_setting where label_name IN $column_name and cw_form_setting.prime_module_id IN $module_name and trans_status = \"1\"";
$form_data = $this->db->query("CALL sp_a_run ('SELECT','$form_qry')");
$form_result = $form_data->result();
$form_data->next_result();
$k = 0;
foreach($form_result as $form){
$k++;
$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;
$table_name = $check_table_array[$label_name];
if (in_array($label_name, $check_column_array))
{
$table_name = 'cw_transactions';
}
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_qry = 'select where_condition from cw_print_table_where where where_for_id = "'.$prime_print_block_id.'" and trans_status = 1';
$where_data = $this->db->query("CALL sp_a_run ('SELECT','$where_qry')");
$where_result = $where_data->row();
$where_data->next_result();
$where_condition = "";
$i = 1;
$final_html = '';
$split_qry = 'select * from cw_print_split where trans_status = 1 and split_table_info ="'.$print_doc_id.'"';
$split_data = $this->db->query("CALL sp_a_run ('SELECT','$split_qry')");
$split_result = $split_data->result();
$split_data->next_result();
$split_array = array();
foreach($split_result as $split){
$split_info = $split->split_info;
$split_colum = $split->split_colum;
$split_array[$split_colum] = $split_info;
}
$emp_codes = '';
foreach($emp_code_rslt as $emp_code){
$emp_codes .= "\"$emp_code\",";
}
$emp_codes = '('.rtrim($emp_codes,',').')';
if(!$where_result){
$where_condition = str_replace('^','"',$where_result->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 $emp_codes";
}
$select_query = rtrim($select_query,',');
$select_query = rtrim($select_query,' , ');
$final_qry = "select $select_query from $line_table_query $pick_query where $where_trans $where_condition";
$final_data = $this->db->query("CALL sp_a_run ('SELECT','$final_qry')");
$final_rslt = $final_data->result();
$final_data->next_result();
$results = array_map(function($rslt){
$return_data['employee_data'] = $rslt;
$return_data['employee_code'] = $rslt->employee_code;
return $return_data;
}, $final_rslt);
$final_rslt = array_column($results,'employee_data','employee_code');
foreach ($emp_code_rslt as $emp_code){
$print_data = $print_design;
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_data = str_replace($replace_ytd_val,$ytd_value,$print_data);
}
}
}
$tr_line = "";
$th_line = "";
$count = 1;
$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");
$rslt = $final_rslt[$emp_code];
if($rslt){
$data['print_sts'] = true;
$map_column = explode(",",$print_block_column);
$td_line = "";
foreach($map_column as $table_column){
$map_column = explode(".",$table_column);
$column = $map_column[1];
$value = $rslt->$column;
$replace_val = "@".$column."@";
if($column == 'net_pay'){
$value = $rslt->$column;
$print_data = str_replace($replace_val,$value,$print_data);
$net_pay_val = $value;
$net_pay_words = $this->numbertowords($net_pay_val);
$net_pay_words = strtoupper($net_pay_words);
$print_data = str_replace("@net_pay_words@",$net_pay_words,$print_data);
}
if($split_array[$replace_val]){
//Process split informtion
$process_function = $split_array[$replace_val];
if((int)$process_function === 1){
$transactions_month = $rslt->transactions_month;
$employee_code = $rslt->employee_code;
$loan_info = $this->get_loan_value($transactions_month,$employee_code);
$print_data = str_replace($replace_val,$loan_info,$print_data);
}
}else{
if($print_block_type === 1){
$print_data = str_replace($replace_val,$value,$print_data);
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_data = str_replace($replace_val,$replace_value,$print_data);
}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_data = str_replace($replace_val,$replace_value,$print_data);
}
}
}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($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($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_data = str_replace($replce_block,$table_list,$print_data);
}
}
$print_data = str_replace("<br>","",$print_data);
if((int)$i % (int)$pdf_sheet_per_page === 0){
$page_break = "style='page-break-after:always;'";
}else{
$page_break = "";
}
$final_html .= "<div $page_break>".$print_data."</div><br/><br/>";
$i++;
}
$pdf_name = "combined_".$category_name;
if((int)$suppressed_data === 1){
$file = "suppressed_data.html";
$myfile = fopen($file, "w") or die("Unable to open file!");
//<script src='./dist/jquery.min.js'></script>
$final_html .= "
<script type='text/javascript' src='../../../dist/opensourcepos.min.js'></script>
<script> $( document ).ready(function() {
var i = 0;
$('table tr td').each(function() {
var cellText = $.trim($(this).text());
if (cellText.length == '0') {
$(this).closest('td').prev().empty();
$(this).text('')
}else
if(cellText == '0.00'){
$(this).closest('td').prev().empty();
$(this).text('');
}
i++;
});
}); </script>";
$final_html = "<!DOCTYPE html>
<head></head>
<style> table {
border-collapse: collapse;
font-size: 13px !important;
}
table td.fr-highlighted,.fr-view table th.fr-highlighted{
border:1px solid black !important;
font-size: 13px !important;
}
table td{
border-right: 1px solid #000;
text-transform: uppercase;
}
@media print {
.print_hide{display:none!important}
}
</style><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>".$final_html."</body></html>";
fwrite($myfile, $final_html);
}else{
$final_html = "<!DOCTYPE html><html>
<head>
<style>
table{
border: 1px !important;
border-collapse: collapse !important;
empty-cells: show !important;
max-width: 100% !important;
font-size: 13px !important;
}
tbody {
border: 1px !important;
border-collapse: collapse !important;
empty-cells: show !important;
max-width: 100% !important;
font-size: 13px !important;
}
td, th {
border: 1px solid #000 !important;
font-size: 13px !important;
}
td.fr-thick,th.fr-thick {
border-width: 2px !important;
}
table.fr-dashed-borders td, table.fr-dashed-borders th {
border-style: dashed !important;
}
@media print {
.print_hide{display:none!important}
}
</style>
</head><body id='print_data'><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>".$final_html."</body></html>";
}
$design_name = strtolower(str_replace(" ","_",$pdf_design_result[0]->print_info_name));
$folder = "payslip";
$folder1 = $category_name;
$folder2 = $payslip_month."_".$design_name;
$pdf_name = $pdf_name;
$final_html = $final_html;
$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.".html")){
chmod($folder."/".$folder1."/".$folder2."/".$pdf_name.".html", 0777);
unlink($folder."/".$folder1."/".$folder2."/".$pdf_name.".html");
}
file_put_contents($folder."/".$folder1."/".$folder2."/".$pdf_name.".html" , $final_html);
chmod($folder."/".$folder1."/".$folder2."/".$pdf_name.".html", 0777);
umask($oldmask);
}
//PDF GENERATIONS
public function get_pdf(){
$category = $this->input->post('category');
$content = $this->input->post('content');
$design_name = $this->input->post('design_name');
$pdf_name = $this->input->post('pdf_name');
$pdf_paper_size = $this->input->post('pdf_paper_size');
$pdf_sheet_type = $this->input->post('pdf_sheet_type');
$payslip_month = $this->input->post('payslip_month');
$pdf_set_password = $this->input->post('pdf_set_password');
$pdf_type = $this->input->post('pdf_type');
$emp_code = $this->input->post('value');
$suppressed = $this->input->post('sup');
$design_name = strtolower(str_replace(" ","_",$design_name));
$category_info = $this->db->query("CALL sp_a_run ('SELECT','SELECT category_name FROM `cw_category` where trans_status = 1 and prime_category_id = $category')");
$category_result = $category_info->result();
$category_info->next_result();
$category_name = $category_result[0]->category_name;
$category_name = strtolower(str_replace(" ","_",$category_name));
if((int)$suppressed === 1){
if((int)$pdf_type === 2){
unlink('./suppressed_data.html');
}else{
unlink("./suppressed_data_".$emp_code.".html");
}
$content = "$content";
}
if($content !== "" & $design_name !== ""){
// Load pdf library
//$this->load->library('pdf');
// Load HTML content
if((int)$pdf_type === 2){
$extension = '.pdf';
unlink('./suppressed_data.html');
$output = $content;
}else{
$extension = '.pdf';
$this->dompdf->loadHtml($content);
//$this->dompdf->setBasePath('/dist/froala/froala_style.min.css');
// (Optional) Setup the paper size and orientation
$this->dompdf->setPaper($pdf_paper_size, $pdf_sheet_type);
// Render the HTML as PDF
$this->dompdf->render();
if($pdf_set_password === "1"){
//SET Production
$password = $pdf_name;
$this->dompdf->get_canvas()->get_cpdf()->setEncryption($password, $password);
}
// Output the generated PDF (1 = download and 0 = preview)
$output = $this->dompdf->output();
}
//$folder = "./payslip/$category_name/".$payslip_month."_".$design_name;
$folder = "payslip";
$folder1 = $category_name;
$folder2 = $payslip_month."_".$design_name;
$pdf_name = $pdf_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."$extension")){
chmod($folder."/".$folder1."/".$folder2."/".$pdf_name."$extension", 0777);
unlink($folder."/".$folder1."/".$folder2."/".$pdf_name."$extension");
}
file_put_contents($folder."/".$folder1."/".$folder2."/".$pdf_name."$extension" , $final_html);
chmod($folder."/".$folder1."/".$folder2."/".$pdf_name."$extension", 0777);
umask($oldmask);
$path = "/".$folder."/".$folder1."/".$folder2;
echo json_encode(array('success'=>TRUE,'folder'=>$path));
}
}
//GETTING TABLE VIEW FOR EMPLOYEES
public function view_table_emp(){
$cat_id = $this->input->post('category');
$payslip_month = $this->input->post('payslip_month');
$process_by = $this->input->post('process_by');
$pdf_block_employees = ltrim(implode(",",$this->input->post('pdf_block_employees[]')),",");
$pdf_type = $this->input->post('pdf_type');
$pdf_block_employees = str_replace(",",'","',$pdf_block_employees);
$pdf_block_employees = '"'.$pdf_block_employees.'"';
$fandf_data = $this->input->post('fandf_data_val');
if((int)$fandf_data === 1){
$print_type_qry = " and print_type = 8";
}else{
$print_type_qry = " and print_type = 1";
}
$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();
$pdf_name = $pdf_design_result[0]->print_info_name;
$pdf_name = strtolower(str_replace(" ","_",$pdf_name));
if($pdf_design_result){
$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_view = $category_result[0]->category_name;
$category_name = strtolower(str_replace(" ","_",$category_name_view));
if((int)$pdf_type === 1){
if((int)$process_by === 2){
$emp_info = $this->db->query("CALL sp_a_run ('SELECT','SELECT prime_employees_id,emp_name,employee_code FROM `cw_employees` where trans_status = 1 and role = $cat_id')");
}else{
$emp_info = $this->db->query("CALL sp_a_run ('SELECT','SELECT prime_employees_id,emp_name,employee_code FROM `cw_employees` where trans_status = 1 and employee_code in ($pdf_block_employees)')");
}
$emp_result = $emp_info->result();
$emp_info->next_result();
$folder_name = $category_name."/".$payslip_month."_".$pdf_name;
if(!empty($emp_result)){
foreach($emp_result as $rlst){
$role = $rlst->role;
$emp_name = $rlst->emp_name;
$employee_code = $rlst->employee_code;
$file_path = "payslip/$folder_name/$employee_code.pdf";
$file_path = base_url().$file_path;
$filename = dirname(__FILE__).$file_path;
$filename = str_replace("application\controllers","",$filename);
$tble_line .= " <tr class='gradeU'>
<td>$employee_code</td>
<td>$emp_name</td>
<td>
<a class='btn btn-primary btn-sm' href='$file_path' target='_blank' ><span class='fa fa-eye' > </span> view </a>
<a class='btn btn-primary btn-sm' id='download_$employee_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('$folder_name') ><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{
$folder_name = $category_name."/".$payslip_month."_".$pdf_name;
$combined_name = "combined_".$category_name;
$file_path = "payslip/$folder_name/$combined_name.html";
$file_path = base_url().$file_path;
$filename = dirname(__FILE__).$file_path;
$filename = str_replace("application\controllers","",$filename);
$table_data = " <table class='table table-striped table-bordered' id='emp_details'>
<thead>
<tr>
<th>Category Name</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr class='gradeU'>
<td>$category_name_view</td>
<td>
<a class='btn btn-primary btn-sm' href='$file_path' target='_blank' type='application/pdf'><span class='fa fa-eye' > </span> view </a>
<a class='btn btn-primary btn-sm' id='download_$cat_id' href='$file_path' download><span class='fa fa-download' download> </span> Download </a>
</td>
</tr>
</tbody>
</table>";
}
echo json_encode(array('success' => true,'table_data' => $table_data));
}else{
$table_data = " <table class='table table-striped table-bordered' id='emp_details'>
<thead>
<tr>
<th>Category Name</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr><td colspan='2'>No Data Found</td></tr>
</tbody>
</table>";
echo json_encode(array('success' => false,'message' => "Pdf Settings Empty",'table_data' => $table_data));
}
}
//SINGLE EMPLOYEE VIEWS
public function emp_view(){
$cat_id = $this->input->post('cat_id');
$payslip_month = $this->input->post('payslip_month');
$employee_code = $this->input->post('employee_code');
$print_info_name = $this->input->post('pdf_name');
$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));
$combined_name = "combined_".$category_name;
if(!empty($employee_code) && !empty($payslip_month)){
$return_filename = base_url("/payslip/$category_name/$payslip_month".'_'."$print_info_name/$employee_code.pdf");
$filename = dirname(__FILE__)."payslip/$category_name/$payslip_month"."_"."$print_info_name/$employee_code.pdf";
$filename = str_replace("application\controllers","",$filename);
$filename = str_replace('/','//',$filename);
echo json_encode(array('success' => true,'message' => $return_filename));
}else{
$return_filename = base_url("/payslip/$category_name/$payslip_month".'_'."$print_info_name/$combined_name.pdf");
$filename = dirname(__FILE__)."payslip/$category_name/$payslip_month"."_"."$print_info_name/$combined_name.pdf";
$filename = str_replace("application\controllers","",$filename);
$filename = str_replace('/','//',$filename);
echo json_encode(array('success' => true,'message' => $return_filename));
}
}
//ZIP CREATIONS AND PATH UPDATES
public function download_zip(){
$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));
}
//PAYROLL DONE OR NOT CATEGORYWISE
public function salary_check(){
$category = $this->input->post('category');
$payslip_month = $this->input->post('payslip_month');
$pay_exist_qry = 'select count(*) as rslt_count from cw_transactions where transactions_month = "'.$payslip_month.'" and role ="'.$category.'" and trans_status = 1';
$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,'msg' => "Please proceed payroll for this month first?"));
}else{
echo json_encode(array('success' => True,'msg' => "Proceed, further processing!!!"));
}
}
//fandf completed or not checking
public function check_fandf(){
$fandf_data = $this->input->post('fandf_data_val');
$emp_code = $this->input->post('pdf_block_employees[]');
$tot_count = count(array_filter($emp_code));
$pdf_block_employees = ltrim(implode(",",$emp_code),",");
$pdf_block_employees = str_replace(",",'","',$pdf_block_employees);
$pdf_block_employees = '"'.$pdf_block_employees.'"';
$term_exist_qry = 'select count(*) as rslt_count from cw_transactions where employee_code in ('.$pdf_block_employees.') and trans_status = 1 and termination_status = 1';
$term_exist_data = $this->db->query("CALL sp_a_run ('SELECT','$term_exist_qry')");
$term_exist_result = $term_exist_data->result();
$term_exist_data->next_result();
$rslt_count = $term_exist_result[0]->rslt_count;
if((int)$rslt_count === (int)$tot_count){
echo json_encode(array('success' => True,'msg' => "Proceed fandf slip"));
}else{
echo json_encode(array('success' => False,'msg' => "Check select employees are terminated or not?"));
}
}
}
?>