File: /home/cafsindia/hrms_cafsinfotech_in/OLD/application_bk/controllers/Overtime_request.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Action_controller.php");
class Overtime_request extends Action_controller{
public function __construct(){
parent::__construct('overtime_request');
}
// LOAD PAGE QUICK LINK,FILTERS AND TABLE HEADERS
public function index(){
$data['encKey'] = $this->generateKey();
$this->page_info();
$data['module_sts'] = (int)$this->module_sts;
$data['quick_link'] = $this->quick_link;
$data['pick_list'] = $this->pick_list;
$data['form_info'] = $this->form_info;
$data['table_head'] = $this->table_head;
$data['fliter_list'] = $this->fliter_list;
$data['freeze_list'] = $this->freeze_list;
//LEAVE FINANCIAL YEAR GET FUNCTION
$leave_financial_info = $this->get_leave_financial_details();
$prime_financial_id = $leave_financial_info[0]->prime_leave_financial_year_id;
//FUNCTION FOR USING TO MANAGE MODULE EDIT VIEW AND CANCEL BUTTON VALIDATION ARRAY GET
$result = $this->overtime_request_data_arr($prime_financial_id);
$data['emp_cancel_arr'] = $result['emp_cancel_arr'];
$data['ot_status_arr'] = $result['ot_status_arr'];
$data['ot_cancel_arr'] = $result['ot_cancel_arr'];
$this->load->view("$this->control_name/manage",$data);
}
//FUNCTION FOR USING TO MANAGE MODULE EDIT VIEW AND CANCEL BUTTON VALIDATION ARRAY GET
public function overtime_request_data_arr($prime_financial_id){
$ot_status_query = 'SELECT prime_overtime_request_id as prime_id,first_approval_status,second_approval_status,approval_status,cancellation_request FROM cw_overtime_request WHERE cw_overtime_request.trans_status = 1 and financial_setting_id = "'.$prime_financial_id.'"';
// and cw_overtime_request.first_approval_status = 1 and cw_overtime_request.second_approval_status = 1 and cw_overtime_request.approval_status = 1
$ot_status_info = $this->db->query("CALL sp_a_run ('SELECT','$ot_status_query')");
$ot_status_result = $ot_status_info->result_array();
$ot_status_info->next_result();
$rslt = array();
$emp_cancel_arr = array();
$ot_status_rslt_arr = array();
$ot_cancel_rslt_arr = array();
foreach($ot_status_result as $ot_key => $ot_val){
$prime_id = $ot_val['prime_id'];
$emp_cancel_arr[$prime_id] = $ot_val;
$ot_status_rslt_arr[$prime_id] = $ot_val['approval_status'];
$ot_cancel_rslt_arr[$prime_id] = $ot_val['cancellation_request'];
}
//ALL ARRAYS ADD TO FINAL ARRAY
$rslt['emp_cancel_arr'] = $emp_cancel_arr;
$rslt['ot_status_arr'] = $ot_status_rslt_arr;
$rslt['ot_cancel_arr'] = $ot_cancel_rslt_arr;
return $rslt;
}
//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);
}
$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']);
$search_query = str_replace("@SELECT@",$this->select_query,$this->base_query);
$search_result = array();
//ADDED BASIC,FILTER,COMMON QUERY HERE
$role_condition = "";
if($this->role_condition){
$role_condition = $this->role_condition;
}
//CURRENT FINANCIAL YEAR ID
$leave_financial_info = $this->get_leave_financial_details();
$prime_financial_id = $leave_financial_info[0]->prime_leave_financial_year_id;
$fliter_query = "";
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) {
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{
$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);
}
}
$count_all_query = str_replace("@SELECT@","count(*) as allcount",$this->base_query);
$count_all_query = $count_all_query.' where '.$this->prime_table.'.trans_status = 1 AND financial_setting_id = '.$prime_financial_id;
$count_query = $count_all_query.' '.$role_condition.$fliter_query.$common_search;
$search_query .= " where $this->prime_table.trans_status = 1 AND financial_setting_id = $prime_financial_id $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_pro_qry = [];
$search_pro_qry[] = array("return"=>"total_count","qry"=>$count_all_query);
$search_pro_qry[] = array("return"=>"filtered_count","qry"=>$count_query);
$search_pro_qry[] = array("return"=>"search_result","qry"=>$search_query);
$search_info_rslt = $this->run_multi_qry($search_pro_qry);
$total_count = $search_info_rslt->rslt->total_count[0]->allcount;
$filtered_count = $search_info_rslt->rslt->filtered_count[0]->allcount;
$search_result = json_decode(json_encode($search_info_rslt->rslt->search_result),true);
if($search_result === null || $search_result === ''){
$search_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
//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;
//FOR DEPENDENT
$logged_emp_code = $this->session->userdata('logged_emp_code');
$data['empdata'] = $this->get_emp_request_data($logged_emp_code);
$data['get_depend_prime_id'] = $this->get_depend_fun();
$data['depend_label_id'] = $this->depend_label_fun();
$data['max_allow_date'] = $this->company_info[0]->max_allow_date;
$data['max_date_based'] = $this->company_info[0]->max_date_based;
//Get Employee details based on the logged employee
$emp_details_rlst = $this->emp_details($logged_emp_code);
$data['date_of_joining'] = date("d-m-Y",strtotime($emp_details_rlst[0]->date_of_joining));
$data['component_value'] = $emp_details_rlst[0]->$component;
$data['approve_type'] = $emp_details_rlst[0]->approve_type;
//Get salary day info
$month_day_info = $this->tos_day_info($logged_emp_code,"3"); // 3 => Leave Entry
$data['salary_start_date'] = $month_day_info['salary_start_date'];
$data['salary_end_date'] = $month_day_info['year_end_date'];
$data['fin_start_date'] = date("d-m-Y",strtotime($month_day_info['starting_date']));
$data['fin_end_date'] = date("d-m-Y",strtotime($month_day_info['ending_date']));
$this->load->view("$this->control_name/form",$data);
}
//SAVE MODEL DATA TO DATA BASE
public function save(){
//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);
}
//SAVE INFO FUNCTION
$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{
$unq_chk = array();
$prime_qry_key = "";
$prime_qry_value = "";
$prime_upd_query = "";
$form_id = $this->input->post($this->prime_id);
if($form_id !== '-1'){ //Decryption
$decRslt = $this->cryptoDecrypt(base64_decode(urldecode($form_id)));
$form_id = (int)$decRslt['prime_id'];
if(!$form_id){
echo json_encode(array('success' => false,'message' => 'Invalid Request..','table_data' => ""));
exit(0);
}
}else{
$form_id = 0;
}
$financial_info = $this->get_leave_financial_details();
$prime_financial_id = $financial_info[0]->prime_leave_financial_year_id;
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 === 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);
}
}
$value = str_replace('"',"xdbquot",$value);
$value = str_replace("'","xquot",$value);
$value = str_replace("&","xxamp",$value);
//Sanitize SQL InJection chars
$value = $this->sanitize_input($value, $field_type);
if(($input_view_type === 1) || ($input_view_type === 2)){
if((int)$field_isdefault === 1){
if($label_id !== 'employee_code' && $label_id !== 'category'){
$prime_qry_key .= $label_id.",";
$prime_qry_value .= '"'.$value.'",';
$prime_upd_query .= $label_id.' = "'.$value.'",';
$post_data[$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,);
}
}
if($label_id === "cancellation_request"){
$cancellation_request = $value;
}else
if($label_id === "cancellation_reason"){
$cancellation_reason = $value;
}else
if($label_id === "excess_work"){
$excess_work = $value;
}else
if($label_id === "entry_date"){
$entry_date = date("Y-m-d",strtotime($value));
}else
if($label_id === "shift_name"){
$shift_name = $value;
}else
if($label_id === "ot_type"){
$ot_type = $value;
}
}
}
if((int)$cancellation_request === 1){
$prime_upd_query .= 'approval_status = "1",';
$post_data['approval_status'] = 1;
$prime_upd_query .= 'first_approval_cancel_status="1",second_approval_cancel_status = "1",';
$post_data['first_approval_cancel_status'] = 1;
$post_data['second_approval_cancel_status'] = 1;
}
// //Update query if employee applied cancellation
//$category = $this->session->userdata('logged_role');
if($this->config->item("db_name") === 'tcl_hrms' || $this->config->item("db_name") === 'tcl_dev'){
$employee_code = $this->input->post('employee_code');
}else{
$employee_code = $this->session->userdata('logged_emp_code');
}
$common_emp_details_qry = 'select employee_code,date_of_joining,department,first_level_approval,second_level_approval,approve_type as approval_type,department,role as category FROM cw_employees WHERE trans_status=1 AND employee_code="'.$employee_code.'"';
$emp_data_info = $this->db->query("CALL sp_a_run ('SELECT','$common_emp_details_qry')");
$emp_data_result = $emp_data_info->result();
$emp_data_info->next_result();
$category = $emp_data_result[0]->category;
$first_level_approval = $emp_data_result[0]->first_level_approval;
$second_level_approval = $emp_data_result[0]->second_level_approval;
if(($first_level_approval === "" || $first_level_approval === "0") && ($second_level_approval === "" || $second_level_approval === "0")){
echo json_encode(array('success' => FALSE, 'message' => "Approver Details Not Mapped in Employee Master.!"));
exit(0);
}
foreach($emp_data_result[0] as $key => $val){
$post_data[$key] = $val;
$prime_qry_key .= $key.",";
$prime_qry_value .= '"'.$val.'",';
}
$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";
}
}
}
//Check Coff Settings Based Validations
// if((int)$ot_type === 4){
$this->compoff_validation($employee_code,$category,$excess_work,$ot_type);
// }
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
if((int)$cancellation_request === 2 && (int)$approval_status === 2){
echo json_encode(array('success' => false, 'message' => 'Already Your Leave Status Was Updated!!'));
}else{
$created_on = date("Y-m-d h:i:s");
if((int)$form_id === 0){
if($excess_work !== "" && $excess_work !== "0" && $excess_work !== "00:00"){
$ot_type_qry = "";
if((int)$ot_type === 3){
$ot_type_qry = ' and cw_overtime_entry.ot_type = "'.$ot_type.'"';
}
//CHECK EXIST COUNT IN OVERTIME ENTRY TABLE
$check_ot_exist_qry = 'select count(prime_overtime_entry_id) as count from cw_overtime_entry where cw_overtime_entry.employee_code = "'.$employee_code.'" and approval_status in (1,2) and cw_overtime_entry.entry_date = "'.$entry_date.'" '.$ot_type_qry.' and cw_overtime_entry.trans_status = 1';
$check_ot_exist_info = $this->db->query("CALL sp_a_run ('SELECT','$check_ot_exist_qry')");
$check_ot_exist_rslt = $check_ot_exist_info->result();
$check_ot_exist_info->next_result();
$ot_exist_count = (int)$check_ot_exist_rslt[0]->count;
if($ot_exist_count){
echo json_encode(array('success' => FALSE, 'message' => "This Request Already Exist? Please Check it.!"));
}else{
//check ot hours validation and ot permission setting based validations
$ot_hours_sts = $this->ot_hours_check($excess_work,$shift_name,$category,$employee_code,$ot_type,$entry_date);
if((int)$ot_hours_sts){
$prime_qry_key .= "financial_setting_id,trans_created_by,trans_created_date";
$prime_qry_value .= '"'.$prime_financial_id.'","'.$this->logged_id.'","'.$created_on.'"';
$prime_insert_query = "insert into $this->prime_table ($prime_qry_key) values ($prime_qry_value)";
//echo $prime_insert_query; die;
$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((int)$insert_id){
//overtime entry AND approval insert function
$this->ot_approval_insert($post_data,$insert_id,$prime_financial_id);
//FUNCTION FOR USING TO MANAGE MODULE EDIT VIEW AND CANCEL BUTTON VALIDATION ARRAY GET
$result = $this->overtime_request_data_arr($prime_financial_id);
$emp_cancel_arr = $result['emp_cancel_arr'];
$ot_status_arr = $result['ot_status_arr'];
$ot_cancel_arr = $result['ot_cancel_arr'];
echo json_encode(array('success' => TRUE, 'message' => "Successfully added", 'insert_id' => $insert_id, 'emp_cancel_arr' => $emp_cancel_arr, 'ot_status_arr' => $ot_status_arr, 'ot_cancel_arr' => $ot_cancel_arr));
}
}
}
}else{
echo json_encode(array('success' => FALSE, 'message' => "Could not Apply OT.. Because Don't have an Excess Hours for this Day..!"));
}
}else{
//CANCEL REQUEST
if((int)$cancellation_request === 1){
$this->cancel_entry($post_data,$form_id,$cancellation_request,$cancellation_reason);
$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 .'"';
// echo $prime_update_query; die;
$this->db->query("CALL sp_a_run ('UPDATE','$prime_update_query')");
//FUNCTION FOR USING TO MANAGE MODULE EDIT VIEW AND CANCEL BUTTON VALIDATION ARRAY GET
$result = $this->overtime_request_data_arr($prime_financial_id);
$emp_cancel_arr = $result['emp_cancel_arr'];
$ot_status_arr = $result['ot_status_arr'];
$ot_cancel_arr = $result['ot_cancel_arr'];
echo json_encode(array('success' => TRUE, 'message' => "Successfully updated",'insert_id' => $form_id, 'emp_cancel_arr' => $emp_cancel_arr, 'ot_status_arr' => $ot_status_arr, 'ot_cancel_arr' => $ot_cancel_arr));
}
}
}
}
}
//check OT approval process
public function ot_approval_insert($post_data,$form_id,$prime_financial_id){
$approval_insert_key = "";
$approval_insert_value = "";
$approval_update_qry = "";
$created_on = date("Y-m-d H:i:s");
foreach ($post_data as $key => $value) {
if($key === "category"){
$category = $value;
}
if($key === "employee_code"){
$employee_code = $value;
}
if($key === "entry_date"){
$entry_date = $value;
}
if($key === "shift_name"){
$shift_name = $value;
}
if($key === "shift_status"){
$shift_status = $value;
}
if($key === "ot_type"){
$ot_type = $value;
}
if($key === "in_time"){
$in_time = $value;
}
if($key === "out_time"){
$out_time = $value;
}
if($key === "early_coming"){
$early_coming = $value;
}
if($key === "excess_out"){
$excess_out = $value;
}
if($key === "excess_work"){
$excess_work = $value;
}
if($key === "ot_in_time"){
$ot_in_time = $value;
}
if($key === "ot_out_time"){
$ot_out_time = $value;
}
if($key === "approval_status"){
$approval_status = $value;
}
if($key === "request_type"){
$request_type = $value;
}
// if($key === "leave_approve_type"){
// $leave_approve_type = $value;
// }
// if($key === "first_level_approval"){
// $current_control = $value;
// }
if($key === "first_level_approval"){
$first_level_approval = $value;
}
if($key === "second_level_approval"){
$second_level_approval = $value;
}
if($key !== "over_time"){
$approval_insert_key .= $key.",";
$approval_insert_value .= '"'.$value.'",';
$approval_update_qry .= $key.' = "'.$value.'",';
}
}
//OT ENTRY INSERT QUERY
$ot_entry_val = '("'.$form_id.'","'.$prime_financial_id.'","'.$category.'","'.$employee_code.'","'.$shift_name.'","'.$shift_status.'","'.$entry_date.'","'.$in_time.'","'.$out_time.'","'.$ot_in_time.'","'.$ot_out_time.'","'.$early_coming.'","'.$excess_out.'","'.$excess_work.'","1","'.$ot_type.'","'.$this->logged_id.'","'.$created_on.'")';
$overtime_ins_qry = "INSERT INTO cw_overtime_entry (prime_overtime_request_id,financial_setting_id,category,employee_code,shift_name,shift_status,entry_date,in_time,out_time,ot_in_time,ot_out_time,early_coming,excess_out,excess_work,approval_status,ot_type,trans_created_by,trans_created_date) values $ot_entry_val";
$overtime_ins_info = $this->db->query("CALL sp_a_run ('INSERT','$overtime_ins_qry')");
$overtime_ins_rslt = $overtime_ins_info->result();
$overtime_ins_info->next_result();
if(!empty($overtime_ins_rslt)){
$approval_insert_key .= "over_time,prime_overtime_request_id,financial_setting_id,trans_created_by,trans_created_date";
$approval_insert_value .= '"'.$excess_work.'","'.$form_id.'","'.$prime_financial_id.'","'.$this->logged_id.'","'.$created_on.'"';
$approval_insert_query = "insert into cw_overtime_approval (".$approval_insert_key.") values (".$approval_insert_value.")";
$approval_insert_info = $this->db->query("CALL sp_a_run ('INSERT','$approval_insert_query')");
$approval_insert_result = $approval_insert_info->result();
$approval_insert_info->next_result();
//TIME ENTRY REQUEST STATUS UPDATE QUERY
if(!empty($overtime_ins_rslt)){
$time_entry_upd_qry = 'UPDATE cw_time_entry SET approval_type = "2",trans_updated_by = "'.$this->logged_id.'",trans_updated_date = "'.$created_on.'" WHERE cw_time_entry.employee_code = "'.$employee_code.'" and cw_time_entry.att_date = "'.$entry_date.'" and cw_time_entry.trans_status = 1';
$this->db->query("CALL sp_a_run ('UPDATE','$time_entry_upd_qry')");
}
}
$employee_detail_qry = 'select prime_employees_id,first_level_approval,second_level_approval from cw_employees where employee_code = "'.$employee_code.'" and trans_status = 1';
$employee_detail_info = $this->db->query("CALL sp_a_run ('SELECT','$employee_detail_qry')");
$employee_detail_result = $employee_detail_info->result();
$employee_detail_info->next_result();
$view_id = $employee_detail_result[0]->prime_employees_id;
$first_level_approval_code = $employee_detail_result[0]->first_level_approval;
$second_level_approval_code = $employee_detail_result[0]->second_level_approval;
$first_approval_qry = 'select company_email_id from cw_employees where employee_code = "'.$first_level_approval_code.'" and trans_status = 1';
$first_approval_info = $this->db->query("CALL sp_a_run ('SELECT','$first_approval_qry')");
$first_approval_result = $first_approval_info->result();
$first_approval_info->next_result();
$first_approval_mail = $first_approval_result[0]->company_email_id;
$second_approval_qry = 'select company_email_id from cw_employees where employee_code = "'.$second_level_approval_code.'" and trans_status = 1';
$second_approval_info = $this->db->query("CALL sp_a_run ('SELECT','$second_approval_qry')");
$second_approval_result = $second_approval_info->result();
$second_approval_info->next_result();
$second_approval_mail = $second_approval_result[0]->company_email_id;
}
//employee cancel ot request function
public function emp_request_cancel(){
$prime_id = (int)$this->input->post('prime_id');
$created_on = date("Y-m-d H:i:s");
$financial_info = $this->get_leave_financial_details();
$prime_financial_id = $financial_info[0]->prime_leave_financial_year_id;
$exist_request_qry = 'SELECT count(prime_overtime_request_id) as count FROM cw_overtime_request WHERE cw_overtime_request.trans_status = 1 and prime_overtime_request_id = "'.$prime_id.'" and financial_setting_id = "'.$prime_financial_id.'" and first_approval_status = 1 and second_approval_status = 1';
$exist_request_info = $this->db->query("CALL sp_a_run ('SELECT','$exist_request_qry')");
$exist_request_rslt = $exist_request_info->result();
$exist_request_info->next_result();
$exist_count = (int)$exist_request_rslt[0]->count;
if($exist_count === 1){
//request delete qry
$request_update_qry = 'UPDATE '. $this->prime_table .' SET trans_status = "0",trans_deleted_by = "'.$this->logged_id .'",trans_deleted_date = "'.$created_on.'" WHERE '. $this->prime_id .' = "'. $prime_id .'"';
$this->db->query("CALL sp_a_run ('UPDATE','$request_update_qry')");
//approval delete qry
$approval_update_qry = 'UPDATE cw_overtime_approval SET trans_status = "0",trans_deleted_by = "'.$this->logged_id .'",trans_deleted_date = "'.$created_on.'" WHERE cw_overtime_approval.prime_overtime_request_id = "'. $prime_id .'"';
$this->db->query("CALL sp_a_run ('UPDATE','$approval_update_qry')");
$table_name = "";
$where_cond = "";
//overtime entry delete qry
$request_entry_upd_qry = 'UPDATE cw_overtime_entry SET trans_status = "0",trans_deleted_by = "'.$this->logged_id .'",trans_deleted_date = "'.$created_on.'" WHERE cw_overtime_entry.prime_overtime_request_id = "'. $prime_id .'"';
$this->db->query("CALL sp_a_run ('UPDATE','$request_entry_upd_qry')");
echo json_encode(array('success' => true, 'message' => 'Successfully Deleted Your Request..!'));
}else{
echo json_encode(array('success' => false, 'message' => 'Request Should not Deleted..!'));
}
}
public function cancel_entry($post_data,$form_id,$cancellation_request,$cancellation_reason){
$created_on = date("Y-m-d H:i:s");
foreach ($post_data as $key => $value) {
if($key === "employee_code"){
$employee_code = $value;
}
if($key === "category"){
$category = $value;
}
if($key === "entry_date"){
$entry_date = date('Y-m-d',strtotime($value));
}
if($key === "approval_type"){
$approval_type = $value;
}
if($key === "first_level_approval"){
$current_control = $value;
}
if($key === "second_level_approval"){
$second_level_approval = $value;
}
if($key === "first_approval_cancel_status"){
$first_approval_can_sts = $value;
}
if($key === "second_approval_cancel_status"){
$second_approval_can_sts = $value;
}
if($key === "approval_status"){
$approval_status = $value;
}
}
if($cancellation_request === "1"){
//GTE DEFAULT FINANCIAL YEAR
$financial_info = $this->get_leave_financial_details();
$prime_financial_id = $financial_info[0]->prime_leave_financial_year_id;
$starting_date = date('Y-m-d',strtotime($financial_info[0]->starting_date));
$ending_date = date('Y-m-d',strtotime($financial_info[0]->ending_date));
$month_day_info = $this->get_tos_active_salary_date();
if(count($month_day_info ?? [])){
$salary_start_date = $month_day_info[$category]['salary_start_date'];
$salary_end_date = $month_day_info[$category]['salary_end_date'];
$year_end_date = $month_day_info[$category]['year_end_date'];
$check_sts = false;
if($entry_date >= $salary_start_date && $entry_date <= $salary_end_date){
$check_sts = true;
}
if($check_sts){
$upd_approval_qry = 'UPDATE cw_overtime_approval SET first_level_approval = "'. $current_control .'",second_level_approval = "'. $second_level_approval .'",cancellation_request = "'. $cancellation_request .'",cancellation_reason = "'. $cancellation_reason .'",first_approval_cancel_status = "'. $first_approval_can_sts .'",second_approval_cancel_status = "'. $second_approval_can_sts .'",approval_status = "'. $approval_status .'",trans_updated_by = "'.$this->logged_id.'", trans_updated_date = "'.$created_on.'" WHERE prime_overtime_request_id = "'.$form_id.'" and cw_overtime_approval.trans_status = 1';
$upd_approval_sts = $this->db->query("CALL sp_a_run ('UPDATE','$upd_approval_qry')");
if($upd_approval_sts){
return true;
}
}else{
echo json_encode(array('success' => FALSE, "message" => "Could not Cancel Your Request Because Payroll Processed for this Month...!"));
exit(0);
}
}else{
echo json_encode(array('success' => FALSE, 'message' => "Please Set Month Day for this Category..."));
exit(0);
}
}
}
//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(){
$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"));
}
}
//IMPORT FILE VIEW INFORMATION
public function import(){
$data['encKey'] = $this->generateKey();
$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;
//Category get for import a category wise OT
$category_qry = 'select prime_category_id,category_name from cw_category
where trans_status = 1'; $category_info = $this->db->query("CALL sp_a_run
('RUN','$category_qry')"); $category_result = $category_info->result();
$category_info->next_result();
$category_list[""] = "---- Category List----";
foreach($category_result as $excel){
$prime_id = $excel->prime_category_id;
$category_name = $excel->category_name;
$category_list[$prime_id] = $category_name;
}
$data['category_list'] = $category_list;
$this->load->view("$this->control_name/import",$data);
}
//Sheet Name display in import page
public function sheet_name(){
$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);
}
$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));
}
//excel export format function
// public function excel($module_id,$excel_format){
// $excel_format_qry = 'select excel_name,excel_line_column_name,excel_line_value from cw_util_excel_format_line inner join cw_util_excel_format on cw_util_excel_format.prime_excel_format_id = cw_util_excel_format_line.prime_excel_format_id where excel_line_module_id = "'.$module_id.'" and cw_util_excel_format_line.prime_excel_format_id ="'.$excel_format.'" and cw_util_excel_format.trans_status = 1 and cw_util_excel_format_line.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_name = str_replace(' ', '_', $excel_result[0]->excel_name);
// require_once APPPATH."/third_party/PHPExcel.php";
// $obj = new Spreadsheet();
// //Set the first row as the header row
// foreach($excel_result as $excel){
// $excel_line_column_name = $excel->excel_line_column_name;
// $excel_line_value = $excel->excel_line_value;
// $obj->getActiveSheet()->setCellValue($excel_line_value."1", $excel_line_column_name);
// }
// ob_end_clean();
// // Rename worksheet name
// $filename= $excel_name.".xls"; //save our workbook as this file name
// header('Content-Type: application/vnd.ms-excel'); //mime type
// header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
// header('Cache-Control: max-age=0'); //no cache
// ob_end_clean();
// //save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
// //if you want to save it as .XLSX Excel 2007 format
// $objWriter = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($obj, 'Excel5');
// //force user to download the Excel file without writing it to server's HD
// $objWriter->save('php://output');
// echo json_encode(array('success' => TRUE, 'output' => $excelOutput));
// }
//Check from Time Entry
public function check_time_entry(){
$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);
}
if($this->config->item("db_name") === 'tcl_hrms' || $this->config->item("db_name") === 'tcl_dev'){
$employee_code = $this->input->post('employee_code');
}else{
$employee_code = $this->session->userdata('logged_emp_code');
}
$entry_date = date("Y-m-d",strtotime($this->input->post('entry_date')));
$time_entry_qry = 'select date_format(cw_time_entry.punch_in, "%H:%i") as punch_in,date_format(cw_time_entry.punch_out, "%H:%i") as punch_out,if(cw_time_entry.early_in > 0, time_format(concat(floor(cw_time_entry.early_in/60),":",lpad(mod(cw_time_entry.early_in,60),2,"0")),"%H:%i"), cw_time_entry.early_in) as early_in,if(cw_time_entry.excess_out > 0, time_format(concat(floor(cw_time_entry.excess_out/60),":",lpad(mod(cw_time_entry.excess_out,60),2,"0")),"%H:%i"), cw_time_entry.excess_out) as excess_out,if(cw_time_entry.total_excess_hours > 0, time_format(concat(floor(cw_time_entry.total_excess_hours/60),":",lpad(mod(cw_time_entry.total_excess_hours,60),2,"0")),"%H:%i"), cw_time_entry.total_excess_hours) as total_excess_hours,if(break_deduction > 0, time_format(concat(floor(break_deduction/60),":",lpad(mod(break_deduction,60),2,"0")),"%H:%i"), break_deduction) as break_deduction,whole_day_status,shift_id,cw_shift_master.shift_name,cw_shift_master.from_time,cw_shift_master.to_time,cw_shift_master.shift_status,cw_shift_master.shift_start,cw_shift_master.shift_end,cw_shift_master.in_time as import_in_time,cw_shift_master.out_time as import_out_time from cw_time_entry inner join cw_shift_master on cw_shift_master.prime_shift_master_id = cw_time_entry.shift_id where cw_time_entry.employee_code = "'.$employee_code.'" and cw_time_entry.att_date = "'.$entry_date.'" and cw_time_entry.trans_status = 1 and cw_shift_master.trans_status = 1';
$time_entry_info = $this->db->query("CALL sp_a_run ('SELECT','$time_entry_qry')");
$time_entry_result = $time_entry_info->result();
$time_entry_info->next_result();
$punch_in = $time_entry_result[0]->punch_in;
$punch_out = $time_entry_result[0]->punch_out;
$early_in = $time_entry_result[0]->early_in;
$excess_out = $time_entry_result[0]->excess_out;
$shift_id = $time_entry_result[0]->shift_id;
$total_excess_hours = $time_entry_result[0]->total_excess_hours;
$break_deduction = $time_entry_result[0]->break_deduction;
$whole_day_status = $time_entry_result[0]->whole_day_status;
$shift_from_time = date("H:i",strtotime($time_entry_result[0]->from_time));
$shift_to_time = date("H:i",strtotime($time_entry_result[0]->to_time));
$import_in_time = date("H:i",strtotime($time_entry_result[0]->import_in_time));
$import_out_time = date("H:i",strtotime($time_entry_result[0]->import_out_time));
$shift_start = $time_entry_result[0]->shift_start;
$shift_end = $time_entry_result[0]->shift_end;
$shift_status = $time_entry_result[0]->shift_status;
if($time_entry_result){
echo json_encode(array('success' => TRUE, 'punch_in' => $punch_in, 'punch_out' => $punch_out, 'early_in' => $early_in, 'excess_out' => $excess_out, 'total_excess_hours' => $total_excess_hours, 'shift_id' => $shift_id, 'shift_from_time' => $shift_from_time, 'shift_to_time' => $shift_to_time, 'shift_status' => $shift_status, 'shift_start' => $shift_start, 'shift_end' => $shift_end, 'import_in_time' => $import_in_time, 'import_out_time' => $import_out_time, 'break_deduction' => $break_deduction));
}else{
echo json_encode(array('success' => FALSE, "message"=>"Data not Available in Time Entry Table.."));
}
}
function check_total_time(){
$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);
}
$total_hours = $this->input->post('total_hours');
$shift_name = $this->input->post('shift_name');
if($this->config->item("db_name") === 'tcl_hrms' || $this->config->item("db_name") === 'tcl_dev'){
$category = $this->input->post('category');
$employee_code = $this->input->post('employee_code');
}else{
$category = $this->session->userdata('logged_role');
$employee_code = $this->session->userdata('logged_emp_code');
}
$ot_type = $this->input->post('ot_type');
$entry_date = date('Y-m-d',strtotime($this->input->post('entry_date')));
$time_entry_qry = 'select break_deduction,if(break_deduction > 0, time_format(concat(floor(break_deduction/60),":",lpad(mod(break_deduction,60),2,"0")),"%H:%i"), break_deduction) as break_hours from cw_time_entry where employee_code = "'.$employee_code.'" and att_date = "'.$entry_date.'" and trans_status = 1';
$time_entry_info = $this->db->query("CALL sp_a_run ('SELECT','$time_entry_qry')");
$time_entry_result = $time_entry_info->result();
$time_entry_info->next_result();
$break_deduction = (int)$time_entry_result[0]->break_deduction;
$break_hours = $time_entry_result[0]->break_hours;
if($break_deduction > 0){
$total_mins = $this->hourstomins($total_hours);
$diff_mins = $total_mins - $break_deduction;
$final_hours = $this->hours_mins_cal($diff_mins);
}else{
$final_hours = $total_hours;
}
$ot_hours_sts = $this->ot_hours_check($final_hours,$shift_name,$category,$employee_code,$ot_type,$entry_date);
if((int)$ot_hours_sts){
echo json_encode(array('success' => TRUE,'total_hours'=>$total_hours,'final_hours'=> $final_hours,'break_deduction'=> $break_hours));
}
}
function ot_hours_check($total_hours,$shift_name,$category,$employee_code,$ot_type,$entry_date){
//HOURS TO MIN
$total_ot_mins = $this->time_to_min($total_hours);
$total_hours = date("H:i", strtotime($total_hours));
//GTE DEFAULT FINANCIAL YEAR
$financial_info = $this->get_leave_financial_details();
$prime_financial_id = $financial_info[0]->prime_leave_financial_year_id;
$starting_date = date('Y-m-d',strtotime($financial_info[0]->starting_date));
$ending_date = date('Y-m-d',strtotime($financial_info[0]->ending_date));
//check month day for this category
$month_day_info = $this->month_day_info($category,$starting_date,$ending_date);
if(count($month_day_info ?? [])){
$salary_start_date = date("Y-m-d",strtotime($month_day_info["salary_start_date"]));
$salary_end_date = date("Y-m-d",strtotime($month_day_info["salary_end_date"]));
$check_sts = false;
//echo "BSK $entry_date >= $salary_start_date && $entry_date <= $salary_end_date"; die;
//&& $entry_date <= $salary_end_date As discussed with Sanmuga raja 30aug2023
if($entry_date >= $salary_start_date){
$check_sts = true;
}
if($check_sts){
if((int)$ot_type !== 3){
$time_entry_qry = 'select whole_day_status,entry_flag,update_flag,if(cw_time_entry.total_excess_hours > 0, time_format(concat(floor(cw_time_entry.total_excess_hours/60),":",lpad(mod(cw_time_entry.total_excess_hours,60),2,"0")),"%H:%i"), cw_time_entry.total_excess_hours) as total_excess_hours,break_deduction from cw_time_entry where employee_code = "'.$employee_code.'" and att_date = "'.$entry_date.'" and trans_status = 1';
//echo $time_entry_qry; die;
$time_entry_info = $this->db->query("CALL sp_a_run ('SELECT','$time_entry_qry')");
$time_entry_result = $time_entry_info->result();
$time_entry_info->next_result();
$total_excess_hours = $time_entry_result[0]->total_excess_hours;
$entry_flag = $time_entry_result[0]->entry_flag;
$update_flag = $time_entry_result[0]->update_flag;
$whole_day_status = $time_entry_result[0]->whole_day_status;
//echo "BSK $total_excess_hours < $total_hours"; die;
if(($entry_flag === "U" || $update_flag === "U") && $whole_day_status !== "W"){
echo json_encode(array('success' => FALSE, "message" => "On this Day You are not Eligible for Apply OT Request.!Please Contact Admin?"));
}else{
if($total_excess_hours+1 < $total_hours){
//+1 added because we not consider the seconds here but consider seconds in procedure
echo json_encode(array('success' => FALSE, "message" => "Total OT Hours should not Exceeded the Excess Hours.!"));
}else{
return true;
}
}
}else{
return true;
}
}else{
echo json_encode(array('success' => FALSE, "message" => "Future Month or Already Payroll Processed For this Date! Please Check the Attendance Date.!"));
}
}else{
echo json_encode(array('success' => FALSE, 'message' => "Please Set Month Day for this Category.!"));
exit(0);
}
}
public function time_to_min($time) {
$timeArr = explode(':', $time);
$time_min = round(($timeArr[0]*60) + ($timeArr[1]) + ($timeArr[2]/60));
// $tot_hours = floor($time_min / 60).':'.(int)($time_min - floor($time_min / 60) * 60);
return $time_min;
}
}
?>