File: /home/cafsindia/.trash/application.1/controllers/Form_sixteen_mapping.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Action_controller.php");
class Form_sixteen_mapping extends Action_controller{
public function __construct(){
parent::__construct('form_sixteen_mapping');
if(!$this->Appconfig->isAppvalid()){
redirect('config');
}
}
// LOAD PAGE WITH TABLE DATA
public function index(){
$financial_info = $this->get_financial_year();
$fin_set_id = $financial_info[0]->prime_financial_setting_id;
$form_sixteen_head_qry = 'select * from cw_form_sixteen where trans_status = 1';
$form_sixteen_head_info = $this->db->query("CALL sp_a_run ('SELECT','$form_sixteen_head_qry')");
$form_sixteen_head_result = $form_sixteen_head_info->result();
$form_sixteen_head_info->next_result();
$data['form_sixteen_head_result'] = $form_sixteen_head_result;
$tax_sec_10_qry = 'select cw_tax_section.tax_section,tax_act_details,tax_subsection_column from cw_tax_section inner join cw_tax_sub_section on cw_tax_sub_section.tax_section = cw_tax_section.prime_tax_section_id where cw_tax_sub_section.trans_status = 1 and cw_tax_sub_section.financial_setting_id = "'.$fin_set_id.'" and cw_tax_section.financial_setting_id = "'.$fin_set_id.'" and cw_tax_sub_section.tax_section = 1 order by subsection_order';
$tax_sec_10_info = $this->db->query("CALL sp_a_run ('SELECT','$tax_sec_10_qry')");
$tax_sec_10_result = $tax_sec_10_info->result();
$tax_sec_10_info->next_result();
$data['tax_sec_10_result'] = $tax_sec_10_result;
$tax_sec_16_qry = 'select cw_tax_section.tax_section,tax_act_details,tax_subsection_column from cw_tax_section inner join cw_tax_sub_section on cw_tax_sub_section.tax_section =cw_tax_section.prime_tax_section_id where cw_tax_sub_section.trans_status = 1 and cw_tax_sub_section.financial_setting_id = "'.$fin_set_id.'" and cw_tax_sub_section.tax_section = 2 order by subsection_order';
$tax_sec_16_info = $this->db->query("CALL sp_a_run ('SELECT','$tax_sec_16_qry')");
$tax_sec_16_result = $tax_sec_16_info->result();
$tax_sec_16_info->next_result();
$data['tax_sec_16_result'] = $tax_sec_16_result;
$tax_sec_80_qry = 'select cw_tax_section.tax_section,tax_act_details,tax_subsection_column from cw_tax_section inner join cw_tax_sub_section on cw_tax_sub_section.tax_section =cw_tax_section.prime_tax_section_id where cw_tax_sub_section.trans_status = 1 and cw_tax_sub_section.financial_setting_id = "'.$fin_set_id.'" and cw_tax_sub_section.tax_section = 3 order by subsection_order';
$tax_sec_80_info = $this->db->query("CALL sp_a_run ('SELECT','$tax_sec_80_qry')");
$tax_sec_80_result = $tax_sec_80_info->result();
$tax_sec_80_info->next_result();
$data['tax_sec_80_result'] = $tax_sec_80_result;
$tax_sec_6a_qry = 'select cw_tax_section.tax_section,tax_act_details,tax_subsection_column from cw_tax_section inner join cw_tax_sub_section on cw_tax_sub_section.tax_section =cw_tax_section.prime_tax_section_id where cw_tax_sub_section.trans_status = 1 and cw_tax_sub_section.financial_setting_id = "'.$fin_set_id.'" and cw_tax_sub_section.tax_section = 4 order by subsection_order';
$tax_sec_6a_info = $this->db->query("CALL sp_a_run ('SELECT','$tax_sec_6a_qry')");
$tax_sec_6a_result = $tax_sec_6a_info->result();
$tax_sec_6a_info->next_result();
$data['tax_sec_6a_result'] = $tax_sec_6a_result;
$oth_sec_qry = 'select cw_income_type.income_type,income_description,other_income_column from cw_other_income inner join cw_income_type on cw_income_type.prime_income_type_id =cw_other_income.income_type where cw_other_income.trans_status = 1 and prime_income_type_id in (1,2) order by cw_income_type.income_type';
$oth_sec_info = $this->db->query("CALL sp_a_run ('SELECT','$oth_sec_qry')");
$oth_sec_result = $oth_sec_info->result();
$oth_sec_info->next_result();
$data['oth_sec_result'] = $oth_sec_result;
$form16_temp_qry = 'select prime_form_sixteen_id,form16_value from cw_form16_template where fin_set_id = "'.$fin_set_id.'"';
$form16_temp_info = $this->db->query("CALL sp_a_run ('SELECT','$form16_temp_qry')");
$form16_temp_result = $form16_temp_info->result();
$form16_temp_info->next_result();
$data['form16_temp_result'] = $form16_temp_result;
$data['key'] = $this->generateKey();
$this->load->view("$this->control_name/manage",$data);
}
//LOAD MODEL PAGE VIEW WITH DATA
public function view($form_view_id =- 1){
//VIEW INFO FUNCTION
$this->view_info($form_view_id);
$data['module_sts'] = (int)$this->module_sts;
//VIEW, FORM INPUT
$data['view_info'] = $this->view_info;
$data['form_info'] = $this->form_info;
$data['formula_result'] = $this->formula_result;//for label color change
$data['role_based_condition'] = $this->role_based_condition;//for label name readonly options
$data['all_pick'] = $this->pick_list;//all pick result
//DEPENDENT AUTO PICKLIST
$data['auto_pick'] = $this->depen_auto_list;//dependent auto result
$data['condition_list'] = $this->form_condition_list;
//VIEW DATA
$base_query = str_replace("@SELECT@",$this->view_select,$this->base_query);
$form_view_qry = $base_query .' where '.$this->prime_table.'.'.$this->prime_id.' = '.$form_view_id.' and '.$this->prime_table.'.trans_status = 1';
$row_view_qry = 'select * from cw_form_view_setting where prime_view_module_id = "'.$this->control_name.'" and form_view_type = "3" and trans_status = 1';
$view_pro_qry = [];
$view_pro_qry[] = array("return"=>"form_view","qry"=>$form_view_qry);
$view_pro_qry[] = array("return"=>"row_view_list","qry"=>$row_view_qry);
$view_info_rslt = $this->run_multi_qry($view_pro_qry);
$form_view_rslt = $view_info_rslt->rslt->form_view[0];
$row_view_rslt = $view_info_rslt->rslt->row_view_list;
$data['form_view'] = $form_view_rslt;
$row_view_list = array();
foreach($row_view_rslt as $view){
$prime_form_view_id = $view->prime_form_view_id;
$row_set_data = $this->get_row_set_data($prime_form_view_id,$form_view_id);
$row_view_list[$prime_form_view_id] = $row_set_data;
}
$data['row_view_list'] = $row_view_list;
$data['edit_id'] = $form_view_id;
//FOR DEPENDENT
$data['get_depend_prime_id'] = $this->get_depend_fun();
$data['depend_label_id'] = $this->depend_label_fun();
$this->load->view("$this->control_name/form",$data);
}
//IMPORT FILE VIEW INFORMATION
public function import(){
$data['module_id'] = $this->control_name;
$excel_format_qry = 'select prime_excel_format_id,excel_name from cw_util_excel_format where excel_module_id = "'.$this->control_name.'" and trans_status = 1';
$excel_format = $this->db->query("CALL sp_a_run ('SELECT','$excel_format_qry')");
$excel_result = $excel_format->result();
$excel_format->next_result();
$excel_format_drop[""] = "---- Excel Format ----";
foreach($excel_result as $excel){
$prime_excel_format_id = $excel->prime_excel_format_id;
$excel_name = $excel->excel_name;
$excel_format_drop[$prime_excel_format_id] = $excel_name;
}
$data['excel_format_drop'] = $excel_format_drop;
$this->load->view("$this->control_name/import",$data);
}
//LOAD PAGE TABLE VIEW WITH DATA BASED ON SEARCH FILTERS
public function search(){
//SEARCH INFO FUNCTION
$this->search_info();
$module_sts = (int)$this->module_sts;
// if(!$module_sts){
// echo json_encode(array('success' => FALSE, 'message' => "Search Info Query Process Error..!"));
// exit(0);
// }else{
$search = $this->input->get('search');
$limit = $this->input->get('limit');
$offset = $this->input->get('offset');
$sort = $this->input->get('sort');
$order = $this->input->get('order');
$fliter_label = $this->input->get('fliter_label');
$fliter_type = $this->input->get('fliter_type');
$filter_cond = $this->input->get('filter_cond');
$fliter_val = $this->input->get('fliter_val');
$field_type = $this->input->get('input_field_type');
$filter_count = count($fliter_label ?? []);
$fliter_query = "";
$search_count = 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 '. $this->prime_table .".". $db_name ." ". $db_cond .' "'.$search_val.'"'; }
if((int)$table_name === 2){ $fliter_query .= ' and '. $this->cf_table .".". $db_name ." ". $db_cond .' "'.$search_val.'"'; }
}
}
$common_search = "";
if($search){
$count=0;
foreach($this->form_info as $setting){
$prime_form_id = $setting->prime_form_id;
$field_type = $setting->field_type;
$pick_list = $setting->pick_list;
$pick_table = $setting->pick_table;
$pick_list_type = $setting->pick_list_type;
$input_view_type = (int)$setting->input_view_type;
$auto_prime_id = $setting->auto_prime_id;
$auto_dispaly_value = $setting->auto_dispaly_value;
$label_id = strtolower(str_replace(" ","_",$setting->label_name));
$field_isdefault = (int)$setting->field_isdefault;
if($field_isdefault === 1){
$pick_sel_table = "$this->prime_table";
}else
if($field_isdefault === 2){
$pick_sel_table = "$this->cf_table";
}
$other_label_id = $pick_sel_table.".".$label_id;
if(($input_view_type === 1) || ($input_view_type === 2)){
if((int)$field_type === 4){
if(strtotime($search)){
$search_val = date('Y-m-d',strtotime($search));
$common_search .= ' or '. $other_label_id .' like "'.$search_val.'%"';
}
}else
if(((int)$field_type === 5) || ((int)$field_type === 7)){
if((int)$pick_list_type === 1){
$column_name = explode(",",$pick_list);
$column_name = $column_name[1];
}else{
$column_name = $pick_table."_value";
}
$pick_query_as = $pick_table."_".$prime_form_id;
$label_id = "$pick_query_as.$column_name";
$common_search .= ' or '. $label_id .' like "'.$search.'%"';
}else
if((int)$field_type === 9){
$pick_query_as = $pick_table."_".$prime_form_id;
$label_id = "$pick_query_as.$auto_dispaly_value";
$common_search .= ' or '. $label_id .' like "'.$search.'%"';
}else{
if(!strtotime($search)){
$common_search .= ' or '. $other_label_id .' like "'.$search.'%"';
}
}
}
}
if($common_search){
$common_search = ltrim($common_search,' or ');
$common_search = " and ($common_search)";
}
}
if(!$sort){ $sort = $this->prime_table.".".$this->prime_id; }
if(!$order){ $order = "asc"; }
$select_info = str_replace("@SELECT",$this->select_query,$this->base_query);
$search_query = $select_info. $this->pick_query;
//ADDED BASIC,FILTER,COMMON QUERY HERE
$basic_query = "";
if($this->table_search_info){
$basic_query = $this->table_search_info;
}
$search_query .= " where $this->prime_table.trans_status = 1 $basic_query $fliter_query $common_search";
$search_query .= " ORDER BY $sort $order";
$search_query .= " LIMIT $offset,$limit";
//FETCH RECORDS DATA
$search_data = $this->db->query("CALL sp_a_run ('SELECT','$search_query')");
$search_result = $search_data->result();
$num_rows = $search_data->num_rows();
$search_data->next_result();
$data_rows = array();
foreach ($search_result as $search){
$data_rows[]=get_dbdata_row($search,$this->table_info,$this->print_info,$this);
}
//$data_rows=$this->xss_clean($data_rows);
//FETCH RECORDS COUNT
$count_info = "count(*) as rslt_count";
$base_query = str_replace("@SELECT",$count_info,$this->base_query);
$search_query = $base_query. $this->pick_query;
$search_query .= " where $this->prime_table.trans_status = 1 $basic_query $fliter_query $common_search";
$count_data = $this->db->query("CALL sp_a_run ('SELECT','$search_query')");
$count_result = $count_data->result();
$count_data->next_result();
echo json_encode(array('total'=>$count_result[0]->rslt_count,'rows'=>$data_rows));
// }
}
//SAVE MODEL DATA TO DATA BASE
public function save(){
//SAVE INFO FUNCTION
$this->save_info();
$unq_chk = array();
$prime_qry_key = "";
$prime_qry_value = "";
$prime_upd_query = "";
$cf_qry_key = "";
$cf_qry_value = "";
$cf_upd_query = "";
$cf_has = false;
$form_id = (int)$this->input->post($this->prime_id);
$previous_data = $this->get_previous_view($form_id);
$previous_data = $previous_data[0];
$form_post_data = array();
foreach($this->form_info as $setting){
$field_type = $setting->field_type;
$input_view_type = (int)$setting->input_view_type;
$label_id = strtolower(str_replace(" ","_",$setting->label_name));
$field_isdefault = $setting->field_isdefault;
$unique_field = (int)$setting->unique_field;
$view_name = $setting->view_name;
$date_type = $setting->date_type;
if((int)$field_type === 5){
$value = trim($this->input->post($label_id));
$pick_array[$label_id] = $value;
}else
if((int)$field_type === 7){
$multi_name = $label_id."[]";
$value = trim(implode(",",$this->input->post($multi_name) ?? []));
}else{
$value = trim($this->input->post($label_id));
}
if((int)$field_type === 4){
if((int)$date_type === 1){
$value = date('Y-m-d',strtotime($value));
}else{
$value = $value;
}
}else
if((int)$field_type === 13){
$value = date('Y-m-d H:i:s',strtotime($value));
}else
if((int)$field_type === 8){//textbox only
$value = str_replace('"',"~",$value);
$value = str_replace("'","`",$value);
$value = str_replace("&","^",$value);
}else
if((int)$field_type === 10){//File Upload
$value = $value;
$remove_upload_fname = "old_".$label_id;
$remove_upload_file = $this->input->post($remove_upload_fname);
if($value !== $remove_upload_file){
unlink($remove_upload_file);
}
}
if(($input_view_type === 1) || ($input_view_type === 2)){
if((int)$field_isdefault === 1){
$prime_qry_key .= $label_id.",";
$prime_qry_value .= '"'.$value.'",';
$prime_upd_query .= $label_id.' = "'.$value.'",';
if($unique_field === 1){
$prime_unq_chk = $label_id.'= "'.$value.'"';
$query = "select count(*) as rslt_count from $this->prime_table where $this->prime_id != $form_id and $prime_unq_chk";
$unq_chk[] = array('label_id'=>$label_id,'view_name'=>$view_name,'query'=>$query,);
}
}else{
$cf_has = true;
$cf_qry_key .= $label_id.",";
$cf_qry_value .= '"'.$value.'",';
$cf_upd_query .= $label_id.' = "'.$value.'",';
if($unique_field === 1){
$cf_unq_chk = $label_id.'= "'.$value.'"';
$query = "select count(*) as rslt_count from $this->cf_table where $this->prime_id != $form_id and $cf_unq_chk";
$unq_chk[] = array('label_id'=>$label_id,'view_name'=>$view_name,'query'=>$query,);
}
}
}
}
$rslt_count = 0;
$can_process = array();
foreach($unq_chk as $unq_rslt){
$query = $unq_rslt['query'];
$label_id = $unq_rslt['label_id'];
$view_name = $unq_rslt['view_name'];
$unq_info = $this->db->query("CALL sp_a_run ('RUN','$query')");
$unq_result = $unq_info->result();
$unq_info->next_result();
if($unq_result){
$rslt_count = (int)$unq_result[0]->rslt_count;
if($rslt_count !== 0){
$can_process[] = $view_name." already exist";
}
}
}
if(count($can_process) > 0){
$can_process = array_values($can_process);
$can_process = implode(",<br/>", $can_process);
echo json_encode(array('success' => false, 'message' => $can_process,));
}else{
$created_on = date("Y-m-d h:i:s");
if((int)$form_id === 0){
$prime_qry_key .= "trans_created_by,trans_created_date";
$prime_qry_value .= '"'.$this->logged_id.'",'.'"'.$created_on.'"';
$prime_insert_query = "insert into $this->prime_table ($prime_qry_key) values ($prime_qry_value)";
$insert_info = $this->db->query("CALL sp_a_run ('INSERT','$prime_insert_query')");
$insert_result = $insert_info->result();
$insert_info->next_result();
$insert_id = $insert_result[0]->ins_id;
$cf_qry_key .= "trans_created_by,trans_created_date";
$cf_qry_value .= '"'.$this->logged_id.'",'.'"'.$created_on.'"';
$cf_insert_query = 'insert into ' .$this->cf_table. ' ('.$this->prime_id.','.$cf_qry_key.') values ("'.$insert_id.'",'.$cf_qry_value.')';
$insert_info = $this->db->query("CALL sp_a_run ('INSERT','$cf_insert_query')");
$insert_info->next_result();
echo json_encode(array('success' => TRUE, 'message' => "Successfully added", 'insert_id' => $insert_id));
}else{
$prime_upd_query .= 'trans_updated_by = "'. $this->logged_id .'",trans_updated_date = "'.$created_on.'"';
$prime_update_query = 'UPDATE '. $this->prime_table .' SET '. $prime_upd_query .' WHERE '. $this->prime_id .' = "'. $form_id .'"';
$this->db->query("CALL sp_a_run ('UPDATE','$prime_update_query')");
$cf_upd_query .= 'trans_updated_by = "'. $this->logged_id .'",trans_updated_date = "'.$created_on.'"';
$cf_update_query = 'UPDATE '. $this->cf_table .' SET '. $cf_upd_query .' WHERE '. $this->prime_id .' = "'. $form_id .'"';
$this->db->query("CALL sp_a_run ('UPDATE','$cf_update_query')");
echo json_encode(array('success' => TRUE, 'message' => "Successfully updated",'insert_id' => $form_id));
}
}
}
//UPDATE STATUS TO DELETE IN MODULE PRIMARY TABLE
public function delete(){
//Encryption
$encString = file_get_contents('php://input');
$_POST = $this->cryptoDecrypt($encString);
if(!$_POST){
echo json_encode(array('success' => false,'message' => 'Invalid Request..','table_data' => ""));
exit(0);
}
$delete_ids = implode(",",$this->input->post('delete_ids') ?? []);
$can_process = TRUE;
$delete_status = FALSE;
if($this->check_delete_status()){
$delete_status = TRUE;
$check_table_query = 'SELECT GROUP_CONCAT(prime_module_id) as prime_module_id,GROUP_CONCAT(label_name) as label_name from cw_form_setting WHERE pick_table = "'. $this->prime_table .'" and trans_status = 1 ';
$check_table_info = $this->db->query("CALL sp_a_run ('SELECT','$check_table_query')");
$check_table_rlst = $check_table_info->row();
$check_table_info->next_result();
if($check_table_rlst->prime_module_id){
$prime_module_id = explode(",",$check_table_rlst->prime_module_id);
$label_name = explode(",",$check_table_rlst->label_name);
$i = 0;
foreach($prime_module_id as $check_modules){
$table_name = "cw_".$check_modules;
$select_table = "$table_name.$label_name[$i]";
$select_where = " and $table_name.$label_name[$i] in ($delete_ids)";
$check_module_query = 'SELECT '.$select_table.' from '.$table_name.' WHERE '.$table_name.'.trans_status = 1 '.$select_where.' LIMIT 0,1';
$check_module_info = $this->db->query("CALL sp_a_run ('SELECT','$check_module_query')");
$values_count = $check_module_info->num_rows();
$check_module_info->next_result();
if((int)$values_count > 0){
$table_names .= "$check_modules,";
$can_process = False;
$delete_status = False;
}
$i++;
}
}
$table_names = rtrim($table_names,",");
if($delete_status){
$delete_query = 'DELETE FROM '. $this->prime_table .' WHERE '. $this->prime_id .' in ('. $delete_ids .')';
if($this->db->query("CALL sp_a_run ('RUN','$delete_query')")){
$row_set_query = 'SELECT form_view_label_name from cw_form_view_setting where form_view_type = "3" and prime_view_module_id = "'. $this->control_name .'" and trans_status = 1';
$row_set_info = $this->db->query("CALL sp_a_run ('SELECT','$row_set_query')");
$row_count = (int)$row_set_info->num_rows();
$row_set_info->next_result();
if($row_count !== 0){
$row_set_result = $row_set_info->result();
$delete_table_name = '';
$delete_table_condition = '';
foreach($row_set_result as $row_set){
$row_set_table_name = "cw_".$this->control_name."_".$row_set->form_view_label_name;
$delete_table_name .= "$row_set_table_name,";
$delete_table_condition .= " $row_set_table_name.$this->prime_id in ('$delete_ids') and";
}
$delete_table_name = rtrim($delete_table_name,',');
$delete_table_condition = rtrim($delete_table_condition,'and');
$delete_row_set_query = 'DELETE FROM '. $delete_table_name .' WHERE '. $delete_table_condition.'';
$this->db->query("CALL sp_a_run ('RUN','$delete_row_set_query')");
}
$can_process = False;
}
}
}
if($can_process){
$created_on = date("Y-m-d h:i:s");
$prime_upd_query .= 'trans_deleted_by = "'. $this->logged_id .'",trans_deleted_date = "'.$created_on.'"';
$prime_update_query = 'UPDATE '. $this->prime_table .' SET trans_status = 0,'. $prime_upd_query .' WHERE '. $this->prime_id .' in ('. $delete_ids .')';
if($this->db->query("CALL sp_a_run ('UPDATE','$prime_update_query')")){
echo json_encode(array('success' => TRUE, 'message' => "Successfully Deleted"));
}else{
echo json_encode(array('success' => FALSE, 'message' => "Unable to delete"));
}
}else
if($delete_status){
echo json_encode(array('success' => TRUE, 'message' => "Successfully Deleted"));
}else{
echo json_encode(array('success' => FALSE, 'message' => "Unable to delete, This value is already used in $table_names modules"));
}
}
//CHECK UNIQUE FIELD STATUS
public function check_delete_status(){
$check_delete_query = 'SELECT GROUP_CONCAT(unique_field) as unique_field from cw_form_setting WHERE prime_module_id = "'. $this->control_name .'" and trans_status = 1 ';
$check_delete_info = $this->db->query("CALL sp_a_run ('SELECT','$check_delete_query')");
$check_delete_rlst = $check_delete_info->row();
$check_delete_info->next_result();
$unique_info = explode(",",$check_delete_rlst->unique_field);
if(in_array('1', $unique_info ?? [])){
return TRUE;
}else{
return FALSE;
}
}
//UPDATE STATUS TO DELETE FOR UPLOAD FILES or DOCUMENTS
public function remove_file(){
//Encryption
$encString = file_get_contents('php://input');
$_POST = $this->cryptoDecrypt($encString);
if(!$_POST){
echo json_encode(array('success' => false,'message' => 'Invalid Request..','table_data' => ""));
exit(0);
}
$prime_id_val = $this->input->post('prime_id_val');
$is_defult = (int)$this->input->post('is_defult');
$input_name = $this->input->post('input_name');
$table_name = '';
if($is_defult === 1){
$table_name = $this->prime_table;
}else
if($is_defult === 2){
$table_name = $this->cf_table;
}
if($table_name){
$created_on = date("Y-m-d h:i:s");
$set_query = $input_name .' = "" ,trans_updated_by = "'. $this->logged_id .'",trans_updated_date = "'.$created_on.'"';
$update_query = 'UPDATE '.$table_name .' SET '. $set_query .' WHERE '. $this->prime_id .' = "'. $prime_id_val .'"';
$this->db->query("CALL sp_a_run ('UPDATE','$update_query')");
echo json_encode(array('success' => TRUE, 'message' => "Successfully updated"));
}else{
echo json_encode(array('success' => FALSE, 'message' => "Unable to process your request"));
}
}
//Sheet Name display in import page
public function sheet_name(){
$file_path = $this->input->post('file_path');
$filename = dirname(__FILE__)."/php_excel/PHPExcel/IOFactory.php";
include($filename);
$excel_obj = \PhpOffice\PhpSpreadsheet\IOFactory::load($file_path);
$sheet_count = $excel_obj->getSheetCount();
$sheet_name = array();
for($i = 0; $i< $sheet_count; $i++){
$sheet = $excel_obj->getSheet($i);
$sheet_name[] = $sheet->getTitle();
}
echo json_encode(array('sheet_name' =>$sheet_name));
}
public function save_mapping_data(){
$encString = file_get_contents('php://input');
$_POST = $this->cryptoDecrypt($encString);
if(!$_POST){
echo json_encode(array('success' => false,'message' => 'Invalid Request..','table_data' => ""));
exit(0);
}
$form_16_data = json_decode($this->input->post('form_16_data'));
$created_on = date("Y-m-d H:i:s");
$create_by = $this->logged_id;
$financial_info = $this->get_financial_year();
$fin_set_id = $financial_info[0]->prime_financial_setting_id;
$exit_form_tmp_qry = 'select count(*) as rslt_count from cw_form16_template where fin_set_id ="'.$fin_set_id.'"';
$exit_form_tmp_info = $this->db->query("CALL sp_a_run ('SELECT','$exit_form_tmp_qry')");
$exit_form_tmp_result = $exit_form_tmp_info->result();
$exit_form_tmp_info->next_result();
$form_count = $exit_form_tmp_result[0]->rslt_count;
if((int)$form_count === 0){
if(!empty($form_16_data)){
foreach($form_16_data as $entry_data){
$form16_key = $entry_data->name;
$form16_value = $entry_data->value;
$form16_key_arr = explode("_",$form16_key);
$prime_form16_id = $form16_key_arr[2];
$form_tmp_qry = 'INSERT INTO cw_form16_template (fin_set_id,prime_form_sixteen_id,form16_key,form16_value,trans_created_by,trans_created_date) value ("'.$fin_set_id.'","'.$prime_form16_id.'","'.$form16_key.'","'.$form16_value.'","'.$create_by.'","'.$created_on.'")';
$form_tmp_info = $this->db->query("CALL sp_a_run ('INSERT','$form_tmp_qry')");
$form_tmp_result = $form_tmp_info->result();
$form_tmp_info->next_result();
}
$msg = "Form 16 template is mapped successfully";
}
}else{
$truncate_qry = 'TRUNCATE TABLE cw_form16_template';
$this->db->query("CALL sp_a_run ('RUN','$truncate_qry')");
foreach($form_16_data as $entry_data){
$form16_key = $entry_data->name;
$form16_value = $entry_data->value;
$form16_key_arr = explode("_",$form16_key);
$prime_form16_id = $form16_key_arr[2];
$form_tmp_qry = 'INSERT INTO cw_form16_template (fin_set_id,prime_form_sixteen_id,form16_key,form16_value,trans_created_by,trans_created_date) value ("'.$fin_set_id.'","'.$prime_form16_id.'","'.$form16_key.'","'.$form16_value.'","'.$create_by.'","'.$created_on.'")';
$form_tmp_info = $this->db->query("CALL sp_a_run ('INSERT','$form_tmp_qry')");
$form_tmp_result = $form_tmp_info->result();
$form_tmp_info->next_result();
}
$msg = "Form 16 template is updated successfully";
}
echo json_encode(array('success' => TRUE,'msg'=>$msg));
}
public function fetch_data(){
$template_qry = 'SELECT form16_key,form16_value FROM cw_form16_template WHERE trans_status = 1';
$template_info = $this->db->query("CALL sp_a_run ('SELECT','$template_qry')");
$template_result = $template_info->result();
$template_info->next_result();
if($template_result){
echo json_encode(array('success' => TRUE,'msg'=>'ok proceed','form16'=>$template_result));
}else{
echo json_encode(array('success' => FALSE,'msg'=>'No Data Available!'));
}
}
}
?>