File: /home/cafsindia/uds.cafsinfotech.in/smart_hrms_dev/application/controllers/Custom_approval.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Custom_base_controller.php");
require('./phpmailer/class.phpmailer.php');
class Custom_approval extends Custom_base_controller{
public function __construct(){
parent::__construct('custom_approval');
if(!$this->Appconfig->isAppvalid()){
redirect('config');
}
}
// LOAD PAGE WITH TABLE DATA$
public function index(){
//PAGE INFO FUNCTION
$this->page_info();
$data['encKey'] = $this->generateKey();
$data['module_sts'] = (int)$this->module_sts;
$data['quick_link'] = $this->quick_link;
$data['form_info'] = $this->form_info;
$data['table_head'] = $this->table_head;
$data['pick_list'] = $this->pick_list;
$data['fliter_list'] = $this->fliter_list;
$data['freeze_list'] = $this->freeze_list;
$data['aadhar_validation'] = $this->company_info[0]->aadhar_validation;
$data['creation'] = $this->company_info[0]->creation;
$data['manager_role'] = $this->company_info[0]->manager_approval;
$data['hr_role'] = $this->company_info[0]->hr_approval;
$data['confirm_period'] = $this->company_info[0]->confirm_period;
$this->load->view("custom_approval/manage",$data);
}
//LOAD TABEL WITH FILTERS
public function search(){
$dec_data = $this->cryptoDecrypt($_POST['Payload']);
$_POST = $dec_data['data'];
if(!$_POST){
echo json_encode(array('success' => false,'message' => 'Invalid Request..'));
exit(0);
}
//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{
$draw = $this->input->post('draw');
$start = $this->input->post('start');
$per_page = $this->input->post('length');
$order = $this->input->post('order');
$order_col = $this->input->post('columns');
$search = $this->input->post('search');
$column = $order[0]['column'];
$order_sor = $order[0]['dir'];
$order_col = $order_col[$column]['data'];
$search = trim($search['value']);
$manager_reason = $this->input->post('manager_reason_arr');
$search_query = str_replace("@SELECT@",$this->select_query,$this->base_query);
//ADDED BASIC,FILTER,COMMON QUERY HERE
$this->prime_table ="cw_custom_employees";
$fliter_query = "";
$filter_data = FALSE;
foreach($this->fliter_list as $fliter){
$label_id = $fliter->label_name;
$field_isdefault = (int)$fliter->field_isdefault;
$field_type = (int)$fliter->field_type;
$prime_form_id = $fliter->prime_form_id;
if($field_isdefault === 1){
$column_name = $this->prime_table .".$label_id";
$search_val = $this->input->post("$label_id");
if($search_val){
if($field_type === 4){
$search_val = date('Y-m-d',strtotime($search_val));
$fliter_query .= ' and '.$column_name.' = "'.$search_val.'"';
}else
if(($field_type === 5) || ($field_type === 7)){
$search_val = trim(implode('","',$search_val));
$fliter_query .= ' and '.$column_name.' in ("'.$search_val.'")';
}else
if($field_type === 9){
$search_id = 'filter_'.$label_id.'_hidden_'.$prime_form_id;
$search_val = $this->input->post("$search_id");
$fliter_query .= ' and '.$column_name.' in ("'.$search_val.'")';
}else
if($field_type === 13){
$search_val = date('Y-m-d H:i:s',strtotime($search_val));
$fliter_query .= ' and '.$column_name.' = "'.$search_val.'"';
}else{
$fliter_query .= ' and '.$column_name.' LIKE "'.$search_val.'%"';
}
}
}
}
$common_search = "";
if($search){
foreach($this->table_head as $setting){
$prime_form_id = $setting->prime_form_id;
$field_type = (int)$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){
if(($input_view_type === 1) || ($input_view_type === 2)){
$search_label = "$this->prime_table.$label_id";
$search_val = "";
if($field_type === 4){ // having issues in date search
if(strtotime($search)){
$search_val = date('Y-m-d',strtotime($search));
$common_search .= ' or '. $search_label .' like "%'.$search_val.'%"';
}
}else
if(($field_type === 5) || ($field_type === 7) || ($field_type === 9)){
$result = array_filter($this->pick_list[$label_id]['array_list'] ?? [], function ($item) use ($search) {
$search = str_replace("~",'"',$search);
$search = str_replace("`","'",$search);
$search = str_replace("^","&",$search);
if (stripos($item, $search) !== false) {
return true;
}
return false;
});
if($result){
$pick_key = implode('", "', array_keys($result ?? []) ?? []);
$common_search .= ' or '. $search_label .' in("'.$pick_key.'")';
}
}else{
$search = str_replace('"',"~",$search);
$search = str_replace("'","`",$search);
$search = str_replace("&","^",$search);
$common_search .= ' or '. $search_label .' like "%'.$search.'%"';
}
}
}
}
if($common_search){
$common_search = ltrim($common_search,' or ');
$common_search = " and ($common_search)";
$common_search = str_replace("(,","(",$common_search);
$common_search = str_replace("()","(0)",$common_search);
}
}
$role_condition = "";
if($this->role_condition){
$role_condition = $this->role_condition;
}
if($common_search){
$common_search = rtrim($common_search,' and ');
}
$count_all_query = str_replace("@SELECT@","count(*) as allcount",$this->base_query);
$search_total = $this->db->query($count_all_query);
$search_total_info = $search_total->result();
$total_count = $search_total_info[0]->allcount;
$count_query = str_replace("@SELECT@","count(*) as allcount",$this->base_query);
$count_query .= " where $this->prime_table.trans_status = 1 and (employee_code = '' or employee_code is null) $role_condition $fliter_query $common_search";
$search_count = $this->db->query($count_query);
$search_info = $search_count->result();
$filtered_count = $search_info[0]->allcount;
$search_query .= " where $this->prime_table.trans_status = 1 and (employee_code = '' or employee_code is null) $role_condition $fliter_query $common_search";
$search_query .= " ORDER BY $order_col $order_sor";
if((int)$per_page !== -1){
$search_query .= " LIMIT $start,$per_page";
}
$search_data = $this->db->query($search_query);
$search_result = $search_data->result();
echo json_encode(array("draw" => intval($draw),"recordsTotal" => $total_count,"recordsFiltered" => $filtered_count,"data" => $search_result));
}
}
//LOAD MODEL PAGE VIEW WITH DATA
public function view($form_view_id=-1){
$data['primeId'] = $form_view_id;
if($form_view_id !== -1){
//Decrypt prime id from URL
$decRslt = $this->cryptoDecrypt(base64_decode(urldecode($form_view_id)));
$form_view_id = $decRslt['prime_id'];
if(!$form_view_id){
echo json_encode(array('success' => false,'message' => 'Invalid Request..','table_data' => ""));
exit(0);
}
}
//VIEW INFO FUNCTION
$this->view_info($form_view_id);
$data['encKey'] = $this->generateKey();
$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
$data['hr_role'] = $this->company_info[0]->hr_approval;
$data['manager_role'] = $this->company_info[0]->manager_approval;
$data['creation'] = $this->company_info[0]->creation;
//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;
/*============ UDY EMPLOYEE CUSTOME BLOCK ============*/
$arr = array();
foreach($this->Module->get_all_modules($this->control_name) as $module){
$module->module_id = $this->xss_clean($module->module_id);
$module->grant = $this->xss_clean($this->Module->has_grant($this->control_name,$module->module_id, $form_view_id));
$module->access = $this->xss_clean($this->Module->has_access($this->control_name,$module->module_id, $form_view_id));
//$modules[] = $module;
$menu = str_replace(" ","_",strtolower($module->menu_name)); //."_".$module->menu_id
$submenu = str_replace(" ","_",strtolower($module->sub_menu_name));
if(!$submenu){
$submenu = "sub_".$menu;
}
$arr[$menu][$submenu][] = $module;
}
$data['all_modules'] = $arr;
/*============ UDY EMPLOYEE CUSTOME BLOCK ============*/
$data['edit_id'] = $form_view_id;
$emp_details_columns = 'select employee_code,emp_name from `cw_employees` where trans_status =1';
$emp_details_info = $this->db->query("CALL sp_a_run ('SELECT','$emp_details_columns')");
$emp_details_result = $emp_details_info->result();
$emp_details_info->next_result();
$emp_details[""] = "---- Select Column ----";
foreach($emp_details_result as $emp_column){
$employee_code = $emp_column->employee_code;
$emp_name = $emp_column->emp_name;
$emp_details[$this->xss_clean($employee_code)] = $this->xss_clean($emp_name);
}
$data['emp_details'] = $emp_details;
$minimum_age = $this->company_info[0]->minimum_age;
$maximum_age = $this->company_info[0]->maximum_age;
$data['minimum_age'] = $minimum_age;
$data['maximum_age'] = $maximum_age;
$data['aadhar_validation'] = $this->company_info[0]->aadhar_validation;
$data['hr_role'] = $this->company_info[0]->hr_approval;
$data['manager_role'] = $this->company_info[0]->manager_approval;
//FOR DEPENDENT
$data['get_depend_prime_id'] = $this->get_depend_fun();
$data['depend_label_id'] = $this->depend_label_fun();
$data['aadhar_map_column'] = $this->aadhar_map_column();
$allow_past_date = $this->company_info[0]->allow_past_date;
$allow_future_date = $this->company_info[0]->allow_future_date;
$data['allow_past_date'] = date("d-m-Y", strtotime(date('Y-m-d') . " -$allow_past_date day"));
$data['allow_future_date'] = date("d-m-Y", strtotime(date('Y-m-d') . " +$allow_future_date day"));
$data['confirm_period'] = $this->company_info[0]->confirm_period;
//FOR DEPENDENT
$data['get_depend_prime_id'] = $this->get_depend_fun();
$data['depend_label_id'] = $this->depend_label_fun();
//Get unique fields
$uniq_field_qry = 'select CONCAT("#",label_name) as label_name from cw_form_setting where cw_form_setting.prime_module_id = "employees" and input_view_type IN(1,2) and field_show = 1 and unique_field = 1 and trans_status = 1';
$uniq_field_info = $this->db->query("CALL sp_a_run ('SELECT','$uniq_field_qry')");
$uniq_field_rslt = $uniq_field_info->result_array();
$uniq_field_info->next_result();
$data['unique_lables'] = implode(",",array_column($uniq_field_rslt, 'label_name'));
$this->load->view("custom_approval/form",$data);
}
//SAVE MODEL DATA TO DATA BASE
public function save(){
$this->save_info();
$module_sts = (int)$this->module_sts;
if(!$module_sts){
echo json_encode(array('success' => FALSE, 'message' => "Save Info Query Process Error...!"));
exit(0);
}else{
$prime_qry_key = "";
$prime_qry_value = "";
$prime_upd_query = "";
$form_id = (int)$this->input->post($this->prime_id);
$previous_data = $this->get_previous_view($form_id);
$previous_data = $previous_data[0];
$emp_log = array();
$emp_log['prime_custom_employees_id'] = $form_id;
$post_data = array();
//COMPANY INFORMATION DETAILS
$allow_past_date = (int)$this->company_info[0]->allow_past_date;
$allow_future_date = (int)$this->company_info[0]->allow_future_date;
$creation = $this->company_info[0]->creation;
$creation = explode(',', $creation);
//Get required input values
$hr_status = $this->input->post("hr_status");
$mobile_no = $this->input->post("mobile_number");
$employee_code = $this->input->post("employee_code");
$user_name = $this->input->post("employee_code");
$date_of_birth = $this->input->post("date_of_birth");
$date_of_joining = $this->input->post("date_of_joining");
$category = $this->input->post("role");
$emp_name = $this->input->post("emp_name");
$aadhar_card_no = $this->input->post("aadhar_card_no");
$save_type = $this->input->post("save_type");
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){
if($value){
$value = date('Y-m-d H:i:s',strtotime($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)){
$value = str_replace('"',"~",$value);
$value = str_replace("'","`",$value);
$value = str_replace("&","^",$value);
if((int)$field_isdefault === 1){
$status_label_arr = ['hr_status' => 'hr_status','manager_status' => 'manager_status'];
//HR STATUS CHANGE ONLY FOR CREATION TO ADD OR UPDATE
if(in_array($this->logged_user_role, $creation) && $status_label_arr[$label_id]){
if((int)$save_type === 2 && $label_id === 'hr_status'){
$value = "2";
}else
if((int)$save_type === 2 && $label_id === 'manager_status'){
$value = "1";
}
}
if($label_id === 'user_right'){
$user_right = $value;
}
$prime_qry_key .= $label_id.",";
$prime_qry_value .= '"'.$value.'",';
$prime_upd_query .= $label_id.' = "'.$value.'",';
}
$emp_log[$label_id] = $value;
$post_data[$label_id] = $value;
}
}
$minimum_age = $this->company_info[0]->minimum_age;
$maximum_age = $this->company_info[0]->maximum_age;
if((int)$minimum_age === 0 || (int)$maximum_age === 0){
echo json_encode(array('success' => false, 'message' => "Please set age limit"));
exit(0);
}
$minimum_date = date("d-m-Y", strtotime($date_of_birth. " + $minimum_age year"));
$maximum_date = date("d-m-Y", strtotime($date_of_birth. " + $maximum_age year"));
if(strtotime($date_of_joining) <= strtotime($minimum_date)){
echo json_encode(array('success' => false, 'message' => "Date of joining and date of birth minimum difference is $minimum_age years, please change the date?"));
exit(0);
}else
if(strtotime($date_of_joining) >= strtotime($maximum_date)){
echo json_encode(array('success' => false, 'message' => "Date of joining and date of birth maximum difference is $maximum_age years, please change the date?"));
exit(0);
}
//DR CODE FOR USER ROLE BASED DATE OF JOINING VALIDATE START
$today_date = date('d-m-Y');
$past_date = date('Y-m-d', strtotime("-$allow_past_date days", strtotime($today_date)));
$future_date = date('Y-m-d', strtotime("+$allow_future_date days", strtotime($today_date)));
$doj = date('Y-m-d', strtotime($date_of_joining));
//SELECT HR STATUS QUERY
$emp_data_qry = "select hr_status from cw_custom_employees where prime_custom_employees_id = $form_id and trans_status = 1";
$emp_data_info = $this->db->query("CALL sp_a_run ('SELECT','$emp_data_qry')");
$emp_data_rslt = $emp_data_info->result();
$emp_data_info->next_result();
$emp_hr_status = (int)$emp_data_rslt[0]->hr_status;
//FIRST TIME INSERT
if(!$emp_hr_status){
$emp_hr_status = $hr_status;
}
$hr_status_arr = ['1' => '1','4' => '4',];
if(in_array((int)$this->logged_user_role, $creation) && in_array($emp_hr_status, $hr_status_arr)){
if($past_date > $doj || $future_date < $doj){
$past_date = date('d-m-Y',strtotime($past_date));
$future_date = date('d-m-Y',strtotime($future_date));
echo json_encode(array('success' => false, 'message' => "Please should Add Date of joining in Between $past_date and $future_date.!"));
exit(0);
}
}
//DR CODE FOR USER ROLE BASED DATE OF JOINING VALIDATE END
$bank_account_number = $this->input->post("bank_account_number");
$re_enter_account_number = $this->input->post("re_enter_account_number");
if($bank_account_number !== $re_enter_account_number){
echo json_encode(array('success' => false, 'message' => "Bank account number and re enter account number not matched."));
exit(0);
}
if($this->check_emp_code($user_name,$form_id)){
$created_on = date("Y-m-d h:i:s");
$post_json_data = json_encode($post_data);
if((int)$form_id === 0){
//function for vaidate a unique and mandate fields via procedure
$error_sts_arr = $this->unique_procedure_valid($post_json_data);
$error_count = count($error_sts_arr ?? []);
if($error_sts_arr[0] === 1){
$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;
$send_mail_status = "";
if((int)$this->email_count > 0){
$send_mail_status = $this->dynamic_mail_sent($insert_id,$pick_array,$previous_data);
}
//SMS SEND -> ENABLE AFTER CONTENT GIVEN
// $sms_content_qry = 'SELECT * FROM cw_sms_content WHERE sms_for = "onboard_pass" AND trans_status = 1';
// $content_info = $this->db->query("CALL sp_a_run ('SELECT','$sms_content_qry')");
// $content_rslt = $content_info->result();
// $content_info->next_result();
// $sms_content = $content_rslt[0]->sms_content;
// $template_id = $content_rslt[0]->template_id;
// $sms_rlst = $this->trigger_sms($mobile_no,$sms_content,$template_id,$user_name);
echo json_encode(array('success' => TRUE, 'message' => "Successfully added $send_mail_status", 'insert_id' => $insert_id, 'check' => ""));
}else{
echo json_encode(array('success' => FALSE, 'check' => "Procedure", 'message' => "Validation Check Error..?","table_info" => $error_sts_arr));
exit(0);
}
}else{
//function for vaidate a unique and mandate fields via procedure
$error_sts_arr = $this->unique_procedure_valid($post_json_data);
$error_count = count($error_sts_arr ?? []);
if($error_sts_arr[0] === 1){
// if(in_array($this->logged_user_role, $creation)){
// if((int)$save_type === 2){
// $prime_upd_query.= 'hr_status = "2",';
// }
// }
if($emp_log){
$emp_label_name = array_keys($emp_log);
$emp_label_value = implode(",",$emp_label_name);
$cus_emp_data_qry = "select $emp_label_value from cw_custom_employees where prime_custom_employees_id = $form_id";
$cus_emp_data_data = $this->db->query("CALL sp_a_run ('SELECT','$cus_emp_data_qry')");
$cus_emp_data_rslt = $cus_emp_data_data->result_array();
$cus_emp_data_data->next_result();
$fin_emp_result = $cus_emp_data_rslt[0];
$emp_data_dif = array_diff_assoc($fin_emp_result ?? [],$emp_log);
$created_on = date("Y-m-d H:i:s");
$logged_id = $this->logged_id;
$cus_prime_qry_value = "";
$cus_prime_qry_key = "prime_custom_employees_id,aadhar_card_no,emp_name,label_name,old_value,new_value,trans_created_by,trans_created_date";
foreach($emp_data_dif as $emp_key=>$emp_value){
$old_label_val = $fin_emp_result[$emp_key];
$new_label_val = $emp_log[$emp_key];
if(($old_label_val != $new_label_val) && ($old_label_val !=='0.00' && $new_label_val !='') && ($old_label_val !=='0000-00-00' && $new_label_val !='')){
$cus_prime_qry_value .= "(\"$form_id\",\"$aadhar_card_no\",\"$emp_name\",\"$emp_key\",\"$old_label_val\",\"$new_label_val\",\"$logged_id\",\"$created_on\"),";
}
}
if(!empty($cus_prime_qry_value)){
$cus_prime_qry_value = rtrim($cus_prime_qry_value,',');
$cus_prime_insert_query = "insert into cw_custom_employees_log ($cus_prime_qry_key) values $cus_prime_qry_value";
$cus_insert_info = $this->db->query("CALL sp_a_run ('INSERT','$cus_prime_insert_query')");
$cus_insert_result = $cus_insert_info->result();
$cus_insert_info->next_result();
}
}
$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')");
if(((int)$hr_status === 3) && ((int)$employee_code !== '') && ((int)$category > 0)){ //username updated in employee master
$prime_qry_key .= "user_name,password,trans_created_by,trans_created_date";
$prime_qry_value .= '"'.$user_name.'","'.md5($user_name).'","'.$this->logged_id.'",'.'"'.$created_on.'"';
$prime_insert_query = "insert into cw_employees ($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;
if($insert_id){
$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_data = $this->db->query("CALL sp_a_run ('SELECT','$view_qry')");
$view_result = $view_data->result();
$view_data->next_result();
$row_view_list = array();
foreach($view_result as $view){
$prime_form_view_id = $view->prime_form_view_id;
$form_view_label_name = $view->form_view_label_name;
$this->custom_rowset_save($prime_form_view_id,$form_view_label_name,$form_id,$insert_id);
}
}
$this->update_grants($insert_id,$user_right);
}
$send_mail_status = "";
if((int)$this->email_count > 0){
$send_mail_status = $this->dynamic_mail_sent($form_id,$pick_array,$previous_data);
}
echo json_encode(array('success' => TRUE, 'message' => "Successfully updated $send_mail_status",'insert_id' => $form_id, 'check' => ""));
}else{
echo json_encode(array('success' => FALSE, 'check' => "Procedure", 'message' => "Validation Check Error..?","table_info" => $error_sts_arr));
exit(0);
}
}
}else{
echo json_encode(array('success' => FALSE, 'message' => "Employee Code Already Exists",'category_status'=>TRUE, 'check' => ""));
}
}
}
public function trigger_sms($mobile_number,$sms_content,$template_id,$user_name){
$password = md5($user_name);
//Get sms Configuration data
$sms_config_query = 'SELECT sms_url,sms_sender_id,sms_username,sms_password,entityid FROM cw_company_information WHERE trans_status = 1';
$sms_config_info = $this->db->query("CALL sp_a_run ('SELECT','$sms_config_query')");
$sms_config_result = $sms_config_info->result();
$sms_config_info->next_result();
if($sms_config_result){
$sms_url = $sms_config_result[0]->sms_url;
$sms_user = $sms_config_result[0]->sms_username;
$sms_pwd = $sms_config_result[0]->sms_password;
$sender_id = $sms_config_result[0]->sms_sender_id;
$entityid = $sms_config_result[0]->entityid;
}
$url = "$sms_url?username=$sms_user&password=$sms_pwd&type=0&dlr=1&destination=$mobile_number&entityid=$entityid&source=$sender_id&message=".urlencode($sms_content)."&tempid=$template_id";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$output = curl_exec($ch);
curl_close($ch);
if($ch){
return true;
}
}
public function update_grants($ins_id,$user_right){
$emp_perm_grants_ary = array();
if($user_right){
$emp_permission_qry = 'insert into cw_grants (permission_id, grants_menu_id, grants_sub_menu_id, access_add, access_update, access_delete, `access_search`, access_export, access_import, prime_employees_id) select permission_id,grants_menu_id,grants_sub_menu_id,access_add,access_update,access_delete,access_search,access_export,access_import,'.$ins_id.' from cw_employee_permission where cw_employee_permission.trans_status =1 and cw_employee_permission.role = "'.$user_right.'"';
$emp_permission_data = $this->db->query("CALL sp_a_run ('INSERT','$emp_permission_qry')");
$emp_permission_rslt = $emp_permission_data->result();
$emp_permission_data->next_result();
}
return true;
}
//employee code exit or not
public function employee_code_exit(){
$emp_code = $this->input->post('emp_code');
$category = $this->input->post('category');
$emp_code_check_qry = 'select count(employee_code) as rslt_count from cw_employees where employee_code = "'.$emp_code.'"';
$emp_code_check_info = $this->db->query("CALL sp_a_run ('RUN','$emp_code_check_qry')");
$emp_code_check_result = $emp_code_check_info->result();
$emp_code_check_info->next_result();
$rslt_count = $emp_code_check_result[0]->rslt_count;
if((int)$rslt_count > 0){
$last_emp_code_check_qry = 'select MAX(employee_code) as employee_code from cw_employees where role = "'.$category.'" order by employee_code desc';
$last_emp_code_check_info = $this->db->query("CALL sp_a_run ('SELECT','$last_emp_code_check_qry')");
$last_emp_code_check_result = $last_emp_code_check_info->result();
$last_emp_code_check_info->next_result();
$last_emp_code = $last_emp_code_check_result[0]->employee_code;
echo json_encode(array('success' => FALSE, 'message' => "Employee code is already exit! this is your last employee code: $last_emp_code enter after this number"));
}else{
echo json_encode(array('success' => TRUE, 'message' => "Continue to update employee status"));
}
}
//rowset data saved based on primary form id
public function custom_rowset_save($prime_form_view_id,$form_view_label_name,$form_id,$insert_id){
$module_id = $this->control_name;
$cust_table_name = "cw_custom_".$module_id."_".$form_view_label_name;
$prime_table_name = "cw_".$module_id."_".$form_view_label_name;
$prime_tab_id = "prime_custom_".$module_id."_id";
$find_data_qry = 'select * from '.$cust_table_name.' where trans_status = 1 and '.$prime_tab_id.' = '.$form_id;
$find_data_info = $this->db->query("CALL sp_a_run ('SELECT','$find_data_qry')");
$find_data_result = $find_data_info->result();
$find_data_info->next_result();
$form_qry = 'select * from cw_form_setting where prime_module_id = "'.$module_id.'" and input_for = "'.$prime_form_view_id.'" and field_show = "1" 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();
$prime_qry_key = "";
$prime_qry_value = "";
foreach($find_data_result as $find_rslt){
$prime_qry_key = "prime_".$module_id."_id,";
$prime_qry_value = '"'.$insert_id.'",';
foreach($form_result as $setting){
$label_id = strtolower(str_replace(" ","_",$setting->label_name));
$value = $find_rslt->$label_id;
$prime_qry_key .= $label_id.",";
$prime_qry_value .= '"'.$value.'",';
}
$prime_qry_key .= "trans_created_by,trans_created_date";
$prime_qry_value .= '"'.$this->logged_id.'",'.'"'.$created_on.'"';
$prime_insert_query = "insert into $prime_table_name ($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();
}
return true;
}
public function get_employee_code(){
$role = $this->input->post('role');
$check_code_gen_qry = 'select code_type from cw_employee_code_auto where trans_status = 1';
$check_code_gen_data = $this->db->query("CALL sp_a_run ('SELECT','$check_code_gen_qry')");
$check_code_gen_result = $check_code_gen_data->result();
$check_code_gen_data->next_result();
$code_gen_mode = $check_code_gen_result[0]->code_type;
$sts = 0;
if((int)$code_gen_mode === 1){
$sts = 1;
$result = $this->get_digits($role);
if($result){
echo json_encode(array('success' => TRUE, 'sts' => $sts, 'digits' => $result));
}else{
echo json_encode(array('success' => FALSE, 'sts' => $sts, 'message' => "Employee Code Auto Not Updated for this role"));
}
}else{
echo json_encode(array('sts' => $sts,'message' => "Manually enter the Employee code"));
}
}
public function get_digits($role){
$select_qry = 'select * from cw_employee_code_auto where (category = "'.$role.'" or category = "All") and trans_status = 1';
$select_data = $this->db->query("CALL sp_a_run ('SELECT','$select_qry')");
$select_result = $select_data->result();
$select_data->next_result();
$num_rows = $select_data->num_rows();
$prefix = $select_result[0]->prefix;
$start_value = $select_result[0]->start_value;
$category = $select_result[0]->category;
$prefix_count = 0;
$prefix_qry = "";
if($prefix){
$prefix = strtoupper($prefix);
$prefix_count = strlen($prefix);
$prefix_qry = ' and employee_code like "%'.$prefix.'%"';
}
if($category === "All"){
$emp_count_qry = 'select MAX(CONVERT(SUBSTRING_INDEX(replace(employee_code,"'.$prefix.'",""),"-",-1),UNSIGNED INTEGER)) as employee_code from cw_employees where prime_employees_id != 1 '.$prefix_qry;
}else{
$emp_count_qry = 'select MAX(CONVERT(SUBSTRING_INDEX(replace(employee_code,"'.$prefix.'",""),"-",-1),UNSIGNED INTEGER)) as employee_code from cw_employees where role = "'.$role.'" and prime_employees_id != 1 and employee_code != ""'.$prefix_qry;
}
$emp_count_data = $this->db->query("CALL sp_a_run ('SELECT','$emp_count_qry')");
$emp_count_result = $emp_count_data->result();
$emp_count_data->next_result();
//$emp_count = $emp_count_data->num_rows();
$max_count = $emp_count_result[0]->employee_code;
if($max_count){
if((int)$num_rows > 0){
/*$digits = $this->digit_check($prefix,$start_value,$max_count);*/
// $max_count = substr($max_count,$prefix_count);
$max_count = substr($max_count,0);
if($max_count < $start_value){
$max_count = $start_value-1;
}
$digits = $max_count +1;
$max_digit = strlen($max_count);
$final_digit = strlen($digits);
$check_digit = $max_digit - $final_digit;
if($check_digit === 0){
return $prefix."".$digits;
}else{
$digits = str_pad($digits,$max_digit,"0",STR_PAD_LEFT);
return $prefix."".$digits;
}
}else{
return false;
}
}else{
return $prefix."".$start_value;
}
}
public function check_emp_code($emp_code,$form_id = -1){
if($emp_code){
$select_tl_qry = 'select * from cw_employees where employee_code = "'.$emp_code.'" and trans_status = 1';
if((int)$form_id > 0){
$select_tl_qry .= " and prime_employees_id != $form_id";
}
$select_tl_data = $this->db->query("CALL sp_a_run ('SELECT','$select_tl_qry')");
$count = $select_tl_data->num_rows();
$select_tl_data->next_result();
if((int)$count > 0){
return FALSE;
}else{
return TRUE;
}
}else{
return TRUE;
}
}
//Make Not Joined
public function not_joined(){
$not_joined_ids = implode(",",$this->input->post('not_joined_ids'));
$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 WHERE '. $this->prime_id .' in ('. $not_joined_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"));
}
}
public function curl($post_url,$post_data=null){
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $post_url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $post_data,
));
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
public function company_information(){
$config_query = 'select hr_approval,manager_approval from cw_company_information where trans_status = 1';
$config_info = $this->db->query("CALL sp_a_run ('SELECT','$config_query')");
$config_rslt = $config_info->result();
$config_info->next_result();
$user_role_arr = $config_rslt[0];
return $user_role_arr;
}
public function check_aadhar_data(){
$this->save_info();
$aadhar_no = $this->input->post("aadhar_no");
$employee_qry = 'select termination_status,new_hire,emp_name,employee_code,separation_reason from cw_employees where trans_status = 1 and aadhar_card_no = "'.$aadhar_no.'" order by prime_employees_id desc';
$employee_info = $this->db->query("CALL sp_a_run ('SELECT','$employee_qry')");
$employee_rslt = $employee_info->result();
$employee_info->next_result();
if($employee_rslt[0]->termination_status === "0"){
$th_line = "<th>Employee Code</th><th>Employee Name</th>";
$tr_line = "<tr>
<td>".$employee_rslt[0]->employee_code."</td>
<td>".$employee_rslt[0]->emp_name."</td>
</tr>";
$table_data = "<table class='table table-striped table-bordered' id='aadhar_detail'>
<thead>
$th_line
</thead>
<tbody>
$tr_line
</tbody>
</table>";
echo json_encode(array('success'=>TRUE,'message'=>"This employee Already active",'table_data' => $table_data,"otp_sts"=>0));
exit(0);
}
if((int)$employee_rslt[0]->new_hire === 2){
echo json_encode(array('success'=>FALSE,'message'=>"This Employee Permanent Terminated","otp_sts"=>0));
exit(0);
}
$custom_emp_qry = 'select * from cw_custom_employees where trans_status = 1 and aadhar_card_no = "'.$aadhar_no.'" and hr_status != 3 order by prime_custom_employees_id desc';
$custom_emp_info = $this->db->query("CALL sp_a_run ('SELECT','$custom_emp_qry')");
$custom_emp_rslt = $custom_emp_info->result();
$custom_emp_info->next_result();
if((int)count($custom_emp_rslt ?? []) >0){
echo json_encode(array('success'=>FALSE,'message'=>"Already data found","otp_sts"=>0));
exit(0);
}
if(count($employee_rslt ?? []) > 0 || count($custom_emp_rslt ?? []) > 0){
if($employee_rslt){
$employee_code = $employee_rslt[0]->employee_code;
$employee_name = $employee_rslt[0]->emp_name;
}else{
$employee_code = $custom_emp_rslt[0]->employee_code;
$employee_name = $custom_emp_rslt[0]->emp_name;
}
$last_payroll_qry = 'select * from cw_transactions where trans_status = 1 and employee_code = "'.$employee_code.'" order by DATE_FORMAT(str_to_date(CONCAT("01-", process_month), "%d-%m-%Y"), "%Y-%m") desc';
$last_payroll_info = $this->db->query("CALL sp_a_run ('SELECT','$last_payroll_qry')");
$last_payroll_rslt = $last_payroll_info->result();
$last_payroll_info->next_result();
$trans_month = $last_payroll_rslt[0]->transactions_month;
if(!$trans_month){
$trans_month = "payroll not process for this employee";
}
$th_line = "<th>Employee Code</th><th>Employee Name</th><th>Remark</th><th>New Hire</th>";
$tr_line = "<tr>
<td>$employee_code</td>
<td>$employee_name</td>
<td><textarea type='text' class='form-control' id='aadhar_emp_remark' name='aadhar_emp_remark' placeholder='Remark' readonly>".$separation_reason." & ".$trans_month."</textarea></td>
<td><select class='form-control input-sm select2' id='aadhar_new_hire' name='aadhar_new_hire' onchange='newhire_data(this.value,$aadhar_no);'><option value=''>--- Select New Hire---</option><option value='1'>Proceed</option></select></td>
</tr>";
$table_data = "<table class='table table-striped table-bordered' id='aadhar_detail'>
<thead>
$th_line
</thead>
<tbody>
$tr_line
</tbody>
</table>";
echo json_encode(array('success'=>TRUE,'message'=>"This Employee Already Inactive",'table_data' => $table_data,"otp_sts"=>0));
}else{
$token = $this->company_info[0]->aadhar_token;
$url = $this->company_info[0]->generate_otp_url;
$send_data = json_encode(array("id_number"=>$aadhar_no));
$res_decode = $this->send_curl_data($aadhar_no,$url,$token,$send_data);
try {
$aadhar_res = $this->check_response($res_decode);
$mgs = $aadhar_res['message'];
if(!$aadhar_res['success_status']){
$success = false;
}else{
$success = true;
}
$success = $success;
}
//catch exception
catch(Exception $e) {
$mgs = "Aadhar or token not correct";
$success = false;
}
echo json_encode(array('success'=>FALSE,'message'=>$mgs,"aadhar_res"=>$aadhar_res,"otp_sts"=>1,'success_sts'=>$success,'mgs'=>$mgs));
}
}
public function fetch_employee_data(){
$aadhar_no = $this->input->post("aadhar_no");
$emp_qry = 'select * from cw_employees where trans_status = 1 and aadhar_card_no = "'.$aadhar_no.'" order by prime_employees_id desc';
$emp_info = $this->db->query("CALL sp_a_run ('SELECT','$emp_qry')");
$emp_rslt = $emp_info->result();
$emp_info->next_result();
$form_setting = $this->form_setting_data("employees");
$not_in_array = array('aadhar_no','employee_code','hr_status','permanent_address','present_address','date_of_onboard','date_of_joining','send_otp','aadhar_validate_sts','termination_status');
$emp_value = array();
$ins_key = "";
$ins_val = "";
foreach ($form_setting as $key => $value) {
if (!in_array($key, $not_in_array)){
$emp_value[$key]['emp_val'] = $emp_rslt[0]->$key;
$emp_value[$key]['field_type'] = $value['field_type'];
$emp_value[$key]['mandatory_field'] = $value['mandatory_field'];
if($key === "date_of_birth"){
$emp_value[$key]['emp_val'] = date('d-m-Y',strtotime($emp_rslt[0]->$key));
$ins_key .= $key.',';
$ins_val .= '"'.$emp_rslt[0]->$key.'",';
}else
if($key === "enroll_type"){
$emp_value[$key]['emp_val'] = 2;
$ins_key .= $key.',';
$ins_val .= '2,';
}else
if($key === "new_hire_status"){
$emp_value[$key]['emp_val'] = 2;
$ins_key .= $key.',';
$ins_val .= '2,';
}else{
if($emp_rslt[0]->$key){
$ins_key .= $key.',';
$ins_val .= '"'.$emp_rslt[0]->$key.'",';
}
}
}
}
$emp_value['date_of_onboard']['emp_val'] = date('d-m-Y');
$emp_value['enroll_type']['emp_val'] = 2;
$emp_value['new_hire_status']['emp_val'] = 2;
$insert_arr = array('insert_key'=>$ins_key,'insert_val'=>$ins_val);
// echo "<pre>";
// print_r($emp_value);die;
$insert_id = $this->save_aadhar_details($aadhar_no,'',2,$insert_arr,'');
echo json_encode(array('success'=>TRUE,'message'=>"",'emp_value' => $emp_value,'insert_id'=>$insert_id));
}
//aadhar column mapping
public function aadhar_map_column(){
$aadhar_map_qry = 'select loc_name,db_name from cw_aadhar_mapping where trans_status = 1';
$aadhar_map_info = $this->db->query("CALL sp_a_run ('SELECT','$aadhar_map_qry')");
$aadhar_map_rslt = $aadhar_map_info->result_array();
$aadhar_map_info->next_result();
$aadhar_map_rslt = array_reduce($aadhar_map_rslt, function($result, $arr){
$result[$arr['loc_name']] = $arr['db_name'];
return $result;
}, array());
return $aadhar_map_rslt;
}
public function save_aadhar(){
$this->save_info();
$aadhar_no = $this->input->post("aadhar_no");
$send_otp = $this->input->post("send_otp");
$aadhar_client_id = $this->input->post("aadhar_client_id");
$skip_val = $this->input->post("skip_val");
$insert_sts = true;
if((int)$skip_val !== 1){
$token = $this->company_info[0]->aadhar_token;
$url = $this->company_info[0]->send_otp_url;
$send_data = json_encode(array("client_id"=>$aadhar_client_id,"otp"=>$send_otp));
$aadhar_map_column = $this->aadhar_map_column();
$check_otp = $this->send_curl_data($aadhar_no,$url,$token,$send_data);
try {
$aadhar_res = $this->check_response($check_otp);
$mgs = $aadhar_res['message'];
if(!$aadhar_res['success_status']){
$success = false;
}else{
$success = true;
}
$success = $success;
}
//catch exception
catch(Exception $e) {
$mgs = "Aadhar or token not correct";
// $mgs = $res_decode->message;
$success = false;
}
$check_otp = $check_otp->data;
$map_data = array();
$add_value = "";
$ins_val = "";
$ins_key = "";
foreach ($aadhar_map_column as $key => $value) {
if($key === "dob"){
$get_dob = $check_otp->$key;
$date_1 = new datetime($get_dob);
$date_2 = new datetime(date('Y-m-d'));
$differ = $date_2->diff($date_1);
$age = (string)$differ->y;
$map_data[$value] = date('d-m-Y',strtotime($check_otp->$key));
$map_data['emp_age']= $age;
$ins_val .= '"'.$check_otp->$key.'",';
$ins_key .= $value.",";
$ins_val .= '"'.$age.'",';
$ins_key .= "emp_age,";
}else
if($key === "gender"){
$gender_val = $check_otp->$key;
if($gender_val == 'M' || $gender_val == 'm'){
$gender = 1;
}else
if($gender_val == 'F' || $gender_val == 'f'){
$gender = 2;
}else{
$gender = 3;
}
$map_data[$value] = $gender;
$ins_val .= '"'.$gender.'",';
$ins_key .= $value.",";
}else
if($key === "father_name"){
$care_of_val = $check_otp->care_of;
$care_of_value = str_replace(array('S/O:','D/O:','W/O:','S/O','D/O','W/O',':'),'',$care_of_val);
$father_name = ltrim($care_of_value," ");
// $map_data[$value] = $father_name;
$ins_val .= '"'.$father_name.'",';
$ins_key .= $value.",";
}else
if($key === "profile_image"){
$my_base64_string = $check_otp->$key;
$aadhar_image = strtolower(str_replace(' ','_', $check_otp->full_name));
if($aadhar_image){
$aadhar_image = $aadhar_image."_".strtotime(date('d-m-Y'));
$upload_key = "upload_".$value;
$map_data[$value] = "upload_files/custom_approval/$aadhar_image.png";
$img_val = "upload_files/custom_approval/$aadhar_image.png";
$ins_val .= '"'.$img_val.'",';
$ins_key .= $value.",";
}
$get_host_name = $_SERVER['HTTP_HOST'];
$get_host_name = strtolower($get_host_name);
if($get_host_name !== "localhost"){
chmod("upload_files/custom_approval", 0777);
}
if(!file_exists("upload_files/custom_approval")) {
mkdir("upload_files/custom_approval", 0777, true);
}
file_put_contents("upload_files/custom_approval/$aadhar_image.png", base64_decode($my_base64_string));
}
/*else
if($key === "date_of_onboard"){
$ins_val .= '"'.date("Y-m-d").'",';
$ins_key .= "date_of_onboard,";
}*/
else{
$map_data[$value] = $check_otp->$key;
if($check_otp->$key){
$ins_val .= '"'.$check_otp->$key.'",';
$ins_key .= $value.",";
}
}
if(!$check_otp->$key){
$address = $check_otp->address;
$map_data[$value] = $address->$key;
if($address->$key){
$add_value .= $address->$key.",";
if($address->$key){
$ins_key .= $value.",";
$ins_val .= '"'.$address->$key.'",';
}
}
}
}
$skip_value = 1;
$map_data[$value] = $father_name;
$emp_age = $map_data['emp_age'];
$pin_code = $map_data['pin_code'];
$per_address = rtrim($add_value,',').",".$pin_code;
$ins_key .= 'enroll_type,new_hire_status,permanent_address,present_address,';
$ins_val .= '1,1,"'.$per_address.'","'.$per_address.'",';
if($success){
$min_age = $this->company_info[0]->minimum_age;
$max_age = $this->company_info[0]->maximum_age;
if(((int)$emp_age < (int)$min_age) || ((int)$emp_age > (int)$max_age)){
$success = false;
echo json_encode(array('success'=>FALSE,'message'=>"Age limit $min_age-$max_age only"));
exit(0);
}
}
}else
if((int)$skip_val === 1){
$ins_key = "aadhar_card_no,enroll_type,new_hire_status,";
$ins_val = "$aadhar_no,2,1,";
$skip_value = 2;
$success = true;
}
$map_data["enroll_type"] = $skip_value;
$map_data["new_hire_status"] = 1;
$insert_arr = array('insert_key'=>$ins_key,'insert_val'=>$ins_val);
if($success){
$insert_id = $this->save_aadhar_details($aadhar_no,$send_otp,$skip_value,$insert_arr,$per_address);
//$date_of_onboard = date('d-m-Y');
$mgs = "Verification Successfully";
}
echo json_encode(array('success'=>$success,'message'=>$mgs,'insert_id' => $insert_id,'map_data'=>$map_data,"aadhar_image"=>$aadhar_image,"permanent_address"=>$per_address,'present_address'=>$per_address,'date_of_onboard'=>date('d-m-Y'),'aadhar_validate_sts'=>$skip_value));
}
public function save_aadhar_details($aadhar_no,$send_otp,$skip_val,$insert_arr,$per_address){
$created_on = date("Y-m-d h:i:s");
$prime_qry_key .= $insert_arr['insert_key'];
$prime_qry_value .= $insert_arr['insert_val'];
$prime_qry_key .= "termination_status,aadhar_no,send_otp,aadhar_validate_sts,hr_status,date_of_onboard,trans_created_by,trans_created_date";
$prime_qry_value .= '0,"'.$aadhar_no.'","'.$send_otp.'","'.$skip_val.'","1","'.date("Y-m-d").'","'.$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;
return $insert_id;
}
public function send_curl_data($aadhar_no,$url,$token,$send_data){
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>$send_data,
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer '.$token.'',
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
curl_close($curl);
$res_decode = json_decode($response);
return $res_decode;
}
public function check_response($res_decode) {
if($res_decode) {
$response = $res_decode->data;
$client_id = $response->client_id;
$otp_sent = $response->otp_sent;
$if_number = $response->if_number;
$valid_aadhaar = $response->valid_aadhaar;
$message = $res_decode->message;
$success_status = $res_decode->success;
$status_code = $res_decode->status_code;
$res_arr = array('client_id'=>$client_id,'otp_sent'=>$otp_sent,'if_number'=>$if_number,'valid_aadhaar'=>$valid_aadhaar,'message'=>$message,'success_status'=>$success_status,'status_code'=>$status_code);
return $res_arr;
}else{
return false;
// throw new Exception("Aadhar or token not correct");
}
}
//on change unique input validation
public function input_uniq_validation(){
$post_data = $this->input->post('post_data');
$post_json_data = json_encode($post_data);
$valid_unique = $this->db->query("CALL sp_validate_unique ('$post_json_data')");
$valid_unique_rslt = $valid_unique->result_array();
$valid_unique->next_result();
if($valid_unique_rslt[0]){
echo json_encode(array('success' => FALSE, 'message' => "Unique Error..!Please View Unique Error Table?","table_info" => $valid_unique_rslt));
exit(0);
}else{
echo json_encode(array('success' => TRUE, 'message' => "Proceed..!"));
}
}
//function for validate a unique fields via procedure
public function unique_procedure_valid($post_json_data){
$validation_sts_arr = array();
//unique procedure call
$valid_unique = $this->db->query("CALL sp_validate_unique ('$post_json_data')");
$valid_unique_rslt = $valid_unique->result_array();
$valid_unique->next_result();
if($valid_unique_rslt[0]){
$validation_sts_arr = $valid_unique_rslt;
return $validation_sts_arr;
// exit(0);
}else{
return $validation_sts_arr = array(1);
}
}
//IFSC CODE BASED BANK DETAILS GET
public function get_bank_details(){
$ifsc_code = $this->input->post("ifsc_code");
$get_api_data = $this->get_api_data($ifsc_code);
$bank_name = $get_api_data->BANK;
$bank_branch = $get_api_data->BRANCH;
if($bank_name){
echo json_encode(array('success'=>TRUE,'message'=>"",'bank_name' => $bank_name,"bank_branch"=>$bank_branch,'get_api_data'=>$get_api_data));
}else{
echo json_encode(array('success'=>false,'message'=>"IFSC code Wrong"));
}
}
//API BASED ON IFSC CODE
public function get_api_data($ifsc_code) {
$json = @file_get_contents("https://ifsc.razorpay.com/".$ifsc_code);
$arr = json_decode($json);
return $arr;
}
//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');
$input_val = $this->input->post('input_val');
if($input_val){
chmod($input_val, 0777);
unlink($input_val);
}
$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"));
}
}
}
?>