From 3f85b80cbe9892fa8b1976faf7a811c96affbf1e Mon Sep 17 00:00:00 2001 From: velz Date: Wed, 4 Dec 2024 09:33:29 +0530 Subject: [PATCH 01/12] CHNAGE_PULL_DATA_FROM_AUDIT_HISTORY_DISABLED_TEMPORARLY --- app/Helpers/excel_util_helper.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/app/Helpers/excel_util_helper.php b/app/Helpers/excel_util_helper.php index a371ed98..9a27ab9b 100755 --- a/app/Helpers/excel_util_helper.php +++ b/app/Helpers/excel_util_helper.php @@ -1091,25 +1091,25 @@ if (!function_exists('premium_calculation_manager')) //check emp records if($emp_data['file_id'] == null && $emp_data['temp']['emp_status'] == 'draft' && $emp_data['temp']['policy_status'] == 'draft') { - $original_emp_records = get_emp_records_from_audit_history($emp_data['temp']['emp_id']); - if(is_array($original_emp_records)) - { - // Kint::dump($original_emp_records); - $emp_data = replace_original_data(original_data:$original_emp_records,current_data:$emp_data); - // Kint::dump($value); - } + // $original_emp_records = get_emp_records_from_audit_history($emp_data['temp']['emp_id']); + // if(is_array($original_emp_records)) + // { + // // Kint::dump($original_emp_records); + // // $emp_data = replace_original_data(original_data:$original_emp_records,current_data:$emp_data); + // // Kint::dump($value); + // } } //check emp policy records if($emp_data['file_id'] == null && $emp_data['temp']['emp_status'] == 'draft' && $emp_data['temp']['policy_status'] == 'draft') { - $original_emp_policy_records = get_emp_policy_records_from_audit_history($emp_data['temp']['emp_policy_id']); - if(is_array($original_emp_policy_records)) - { - // Kint::dump($original_emp_records); - $emp_data['policy_details'] = replace_original_data(original_data:$original_emp_policy_records,current_data:$emp_data['policy_details']); - // Kint::dump($policy_data); - } + // $original_emp_policy_records = get_emp_policy_records_from_audit_history($emp_data['temp']['emp_policy_id']); + // if(is_array($original_emp_policy_records)) + // { + // // Kint::dump($original_emp_records); + // $emp_data['policy_details'] = replace_original_data(original_data:$original_emp_policy_records,current_data:$emp_data['policy_details']); + // // Kint::dump($policy_data); + // } }//end of fetching data from audit history table From 0186713b9171a2a5c69987bf72241d67ea73d3a0 Mon Sep 17 00:00:00 2001 From: Gowtham M Date: Wed, 4 Dec 2024 12:02:57 +0530 Subject: [PATCH 02/12] CHNAGE_in client feedback --- app/Config/Routes.php | 1 + app/Controllers/EmployeeRestController.php | 16 +++++-- .../RestAuthenticationController.php | 44 ++++++++++++++++++- app/Models/EmployeeModel.php | 2 +- 4 files changed, 57 insertions(+), 6 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index a6472417..afee44d1 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -393,6 +393,7 @@ $routes->post("/employeeRest/verifyEmployeeNumber", "RestAuthenticationControlle $routes->post("/employeeRest/getVerifiedUserData", "RestAuthenticationController::getVerifiedUserData"); $routes->post("/employeeRest/verifyMpin", "RestAuthenticationController::verifyMpin"); $routes->post("/employeeRest/checkMpin", "RestAuthenticationController::checkMpin"); +$routes->post("/employeeRest/verifyEmployeeEmailId", "RestAuthenticationController::verifyEmployeeWithEmailId"); //HR login api's $routes->post("/employeeRest/verifyHrWithMobileNumber", "RestAuthenticationController::verifyHrWithMobileNumber"); diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index f0f1925e..298ce98a 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -1050,9 +1050,11 @@ class EmployeeRestController extends AdminController // Construct value for policy type GPA - if($getSlabAndGridData['grid_master']['policy_type'] == "GPA" && $this->request->getGet('policy') == 'GPA'){ + // $getSlabAndGridData['grid_master']['policy_type'] == "GPA" + if($array->policy_type_id == 1 && $this->request->getGet('policy') == 'GPA') + { - // Filter employee data where the family_floater_key is 'self' + // Filter employee data where the family_floater_key is 'self' $selfData = array_filter($empData, fn($arr) => trim(strtolower($arr['family_floater_key'])) === 'self'); $employee_policy = $this->employeePolicyModel->where('employee_id',$selfData[0]['id'])->where('client_policy_id',$array->ClientPolicyId)->where('is_active', 1 )->get()->getRow(); @@ -1087,7 +1089,9 @@ class EmployeeRestController extends AdminController } // Construct value for policy type GMC - }else if($getSlabAndGridData['grid_master']['policy_type'] == "GMC" && $this->request->getGet('policy') == 'GMC' ){ + // $getSlabAndGridData['grid_master']['policy_type'] == "GMC" + }else if($array->policy_type_id == 2 && $this->request->getGet('policy') == 'GMC' ) + { @@ -1461,6 +1465,9 @@ class EmployeeRestController extends AdminController foreach ($array as $key => $value) { if ($value > 0 && $key != 'elders_count') { if ($value != 0 && $key === 'childrens') { + + if($value > 2){ $value = 2; } + for ($i = 1; $i <= $value; $i++) { $result[] = "child" . $i; } @@ -1617,6 +1624,7 @@ class EmployeeRestController extends AdminController $responce['OpenForEnrollment'] = $array['open_for_enrollment']; $responce['policy_terms'] = $decodedArray; $responce['policy_type_id'] = $array['policy_type_id']; + $responce['is_member_modify_allowed'] = $array['is_member_modify_allowed']; $responce['disclaimer'] = $array['disclaimer']; $tpaArray = $this->employeeModel->select('employees.name as name , employee_polices.tpa_id as tpa_id , employee_polices.rand_string as rand_string') @@ -1909,6 +1917,7 @@ class EmployeeRestController extends AdminController $this->employeeModel->where('emp_code', $emp_code ) ->where('client_id', $client_id ) ->where('is_active', 1 ) + ->where('emp_status', 'draft' ) ->set(array('emp_status'=>'enrolled')) ->update(); @@ -1927,6 +1936,7 @@ class EmployeeRestController extends AdminController $this->employeePolicyModel->where('client_policy_id', $value ) ->where('is_active', 1 ) ->where('employee_id', $empDataValue['id'] ) + ->where('status', 'draft' ) ->set(array('status'=>'enrolled')) ->update(); } diff --git a/app/Controllers/RestAuthenticationController.php b/app/Controllers/RestAuthenticationController.php index 14b61d7d..4d646997 100755 --- a/app/Controllers/RestAuthenticationController.php +++ b/app/Controllers/RestAuthenticationController.php @@ -90,19 +90,59 @@ class RestAuthenticationController extends AdminController return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500); } } + + public function verifyEmployeeWithEmailId() + { + try { + $email = $this->request->getJSON()->email; + + + $employeeData = $this->employeeModel->where('email', $email) + ->where('relationship', 'self') + ->where('emp_status !=', 'truncated') + ->where('is_active', 1) + ->first(); + + if ($employeeData) { + + $result = ['user_verification' => true ,'message' => "Verified Successfully"]; + return $this->respond(['status' => 'success','code' => 200,'data' => $result],200); + } else { + $result = ['user_verification' => false , 'message' => "User not found"]; + return $this->respond(['status' => 'failed','code' => 404,'data' => $result],200); + + } + } catch (\Throwable $th) { + return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500); + } + } public function getVerifiedUserData() { try { - $mobile_number = $this->request->getJSON()->mobile_number; + $otp_verification = $this->request->getJSON()->otp_verification; if (isset($this->request->getJSON()->login_by_hr)) { $employeeData = $this->employeeModel->where('id', $this->request->getJSON()->employee_id)->where('relationship', 'self')->first(); }else{ - $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->first(); + $mobile_number = $this->request->getJSON()->mobile_number; + $email_id = $this->request->getJSON()->email_id; + + + $employeeData = $this->employeeModel->where('relationship', 'self'); + + if (isset($mobile_number)) { + $employeeData = $employeeData->where('mobile', $mobile_number); + } else { + $employeeData = $employeeData->where('email', $email_id); + } + + $employeeData = $employeeData->first(); + + } diff --git a/app/Models/EmployeeModel.php b/app/Models/EmployeeModel.php index b84b96a9..edffa781 100755 --- a/app/Models/EmployeeModel.php +++ b/app/Models/EmployeeModel.php @@ -149,7 +149,7 @@ class EmployeeModel extends Model { return $this->db->table('employee_polices') - ->select(' policy_type.long_name as Policy_Name , client_policy.policy_terms as Policy_Terms, client_policy.client_id as ClientId, client_policy.policy_id as PolicyId,client_policy.id as ClientPolicyId, client_policy.open_for_enrollment as OpenForEnrollment , employee_polices.tpa_id as tpa_id , employee_polices.rand_string as rand_string') // Select all columns from both tables + ->select(' policy_type.long_name as Policy_Name , client_policy.policy_terms as Policy_Terms, client_policy.client_id as ClientId, client_policy.policy_id as PolicyId,client_policy.id as ClientPolicyId, client_policy.open_for_enrollment as OpenForEnrollment, client_policy.is_member_modify_allowed, client_policy.disclaimer,client_policy.policy_type_id , employee_polices.tpa_id as tpa_id , employee_polices.rand_string as rand_string') // Select all columns from both tables ->join('client_policy', 'client_policy.id = employee_polices.client_policy_id') ->join('policy_type', 'policy_type.id = client_policy.policy_type_id') ->where('client_policy.policy_status', 1) From 04526853fdc2946858808b2782a27df61cd24c29 Mon Sep 17 00:00:00 2001 From: velz Date: Wed, 4 Dec 2024 19:55:57 +0530 Subject: [PATCH 03/12] FIX_ENROLMENT_IS_ADD_ON_KEY&DOC_FORMAT&SELF_NOT_AVAIL_ISSUE&GET_VERIFIED_USER_API --- app/Controllers/EmployeeServiceController.php | 463 +++++++----------- .../RestAuthenticationController.php | 8 +- public/sample_excel/enrollment.xlsx | Bin 7762 -> 7777 bytes 3 files changed, 190 insertions(+), 281 deletions(-) diff --git a/app/Controllers/EmployeeServiceController.php b/app/Controllers/EmployeeServiceController.php index 0d2cc5f9..7297c26c 100755 --- a/app/Controllers/EmployeeServiceController.php +++ b/app/Controllers/EmployeeServiceController.php @@ -1036,7 +1036,7 @@ class EmployeeServiceController extends AdminController } } - if(($file['action'] == 'inception' || $file['action'] == 'missed_inception' || $file['action'] == 'addition' || $file['action'] == 'enrollment') || ($policy_details['policy_type_id'] == 3 && $is_self_available_in_policy_terms) && ($policy_details['base_policy'] == null || $policy_details['base_policy'] == 0)) // 3 is GMC parents dep addon) + if((($file['action'] == 'inception' || $file['action'] == 'missed_inception' || $file['action'] == 'addition' || $file['action'] == 'enrollment') || ($policy_details['policy_type_id'] == 3 && $is_self_available_in_policy_terms)) && ($policy_details['base_policy'] == null || $policy_details['base_policy'] == 0)) // 3 is GMC parents dep addon) { $res = check_self_available_in_family($family,$file['action']); if(!$res['is_self_found']) @@ -1049,7 +1049,7 @@ class EmployeeServiceController extends AdminController //check self avaialbe either same policy DB level(i.e.) gMC parents if($file['action'] == 'dependent_addition' || ($policy_details['policy_type_id'] == 3 && !$is_self_available_in_policy_terms)) // 3 is GMC parents as base policy not as dep addon) { - $self_details = $this->employeeModel->getEmpFamilybyEmpCode(emp_code: trim($emp_id),client_id: $file['client_id'],emp_status: ['active'],policy_status:['active'],client_branch_id:[ $file['client_branch_id'] ],relationship:['self']); + $self_details = $this->employeeModel->getEmpFamilybyEmpCode(emp_code: trim($emp_id),client_id: $file['client_id'],emp_status: ['active','draft','enrolled'],policy_status:['active','draft','enrolled'],client_branch_id:[ $file['client_branch_id'] ],relationship:['self']); // dd($self_details); if(!count($self_details)) { @@ -1928,297 +1928,200 @@ public function getFileMetaDataByFileId($file_id, $status = 'success'){ } + public function employeesEnrollmentInsert($params) + { -public function employeesEnrollmentInsert($params) -{ - - helper('excel_util_helper'); - //get file name - $file_id = $params['file_id']; - $file = $this->fileModel->find($file_id); - // dd($file); - $return = []; - if (!isset($file)) { - //file not found in DB - return array('status' => false, 'msg' => 'file not found in DB'); - } - $file_name_with_path = WRITEPATH . "/uploads/excel/" . $file['file_name']; - - //check physical file - if (!file_exists($file_name_with_path)) { - //file not found update status and reason - $message = "Physical file not found"; - // echo $message; - $this->myLogger->logme('error', ($message . ' for file id ' . $file_id)); - $this->fileModel->where('id', $file_id)->set(['status' => 'failed', 'reason' => json_encode(['error_summary' => array_count_values([5]), 'error_data' => $message])])->update(); - return array('error_summary' => [5], 'error_data' => $message); - } - - //get excel data - $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($file_name_with_path); - $sheet = $spreadsheet->getActiveSheet(); - - $highestRowAndColumn = $sheet->getHighestRowAndColumn(); - $result = ['error_type' => 2, 'error_summary' => [], 'error_data' => []]; - $columns_to_check = $this->enrollment_excel_columns; - $keys = array_keys($columns_to_check); - $allowedHighestColumn = end($columns_to_check); - $excel_data = $sheet->rangeToArray('A1:' . $allowedHighestColumn['col_cell_name'] . $highestRowAndColumn['row']); - // print_r($keys);die(); - //get existing units in the current branch - $existing_units = $this->clientBranchModel->getExisitingUnits(client_id: $file['client_id'], client_branch_id: $file['client_branch_id']); - //remove header - unset($excel_data[0]); - // dd($excel_data); - $emp_emails = []; - - //check is welcome notification enabled - $notification = $this->notificationModel->where('client_id', $file['client_id'])->where('template_name', 'member_welcome_mail')->first(); - // dd($notification); - $client_details = $this->clientModel->where('id', $file['client_id'])->first(); - -// dd($excel_data); - $emp_emails = []; // Initialize an empty array to store employee email. - - foreach ($excel_data as $key => $row) { - $is_row_empty = check_row_is_empty_or_null($row); - if (!$is_row_empty) { - $value = []; - $policy_data = []; - $temp_unit = ''; - if (empty($row[12])) { - $temp_unit = $existing_units[0]; + helper('excel_util_helper'); + //get file name + $file_id = $params['file_id']; + $file = $this->fileModel->find($file_id); + // dd($file); + $return = []; + if(!isset($file)) + { + //file not found in DB + return array('status' => false, 'msg' => 'file not found in DB'); + } + $file_name_with_path = WRITEPATH."/uploads/excel/".$file['file_name']; + + //check physical file + if(!file_exists($file_name_with_path)) + { + //file not found update status and reason + $message = "Physical file not found"; + // echo $message; + $this->myLogger->logme('error',($message . ' for file id ' . $file_id)); + $this->fileModel->where('id', $file_id)->set(['status' => 'failed','reason' => json_encode(['error_summary' => array_count_values([5]),'error_data' => $message])])->update(); + return array('error_summary' => [5], 'error_data' => $message); } - $value['emp_code'] = $row[1]; - $value['name'] = $row[2]; - $value['doj'] = (!empty($row[3]) ? convert_string_to_date($row[3], 'Y-m-d') : null); - $value['gender'] = $row[4]; - $value['relationship'] = ucfirst(trim($row[5])); - $value['dob'] = convert_string_to_date($row[6], 'Y-m-d'); - $value['email_corporate'] = $row[7]; - $value['mobile'] = $row[8]; - $value['band'] = $row[10]; - $value['basic_pay'] = $row[11]; - $value['unit'] = $temp_unit; - $value['family_floater_key'] = null; - $value['client_id'] = $file['client_id']; - $value['client_branch_id'] = $file['client_branch_id']; - $value['file_id'] = $file_id; + //get excel data + $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($file_name_with_path); + $sheet = $spreadsheet->getActiveSheet(); + + $highestRowAndColumn = $sheet->getHighestRowAndColumn(); + $result = ['error_type' => 2,'error_summary' => [], 'error_data' => [] ]; + $columns_to_check = $this->enrollment_excel_columns; + $keys = array_keys($columns_to_check); + $allowedHighestColumn = end($columns_to_check); + $excel_data = $sheet->rangeToArray('A1:' . $allowedHighestColumn['col_cell_name'] . $highestRowAndColumn['row']); + // print_r($keys);die(); + //get existing units in the current branch + $existing_units = $this->clientBranchModel->getExisitingUnits(client_id: $file['client_id'],client_branch_id: $file['client_branch_id']); + //remove header + unset($excel_data[0]); + // dd($excel_data); + $emp_emails = []; + //check is welcome notification enabled + $notification = $this->notificationModel->where('client_id',$file['client_id'])->where('template_name','member_welcome_mail')->first(); + // dd($notification); + $client_details = $this->clientModel->where('id', $file['client_id'])->first(); + $policy_details = $this->clientPolicyModel->where('id', $file['policy_id'])->first(); - $value['temp']['emp_id'] = null; // dummy value for using exisitng funciton in model - if (strtolower(trim($value['relationship'])) === 'mother' || strtolower(trim($value['relationship'])) === 'father') { - $relation = 'parent'; - } else if (strtolower(trim($value['relationship'])) === 'son' || strtolower(trim($value['relationship'])) === 'daughter') { - $relation = 'child'; - } else if (strtolower(trim($value['relationship'])) === 'father in law' || strtolower(trim($value['relationship'])) === 'mother in law') { - $relation = 'parent_in_law'; - } else if (strtolower(trim($value['relationship'])) === 'spouse') { - $relation = 'spouse'; - } else { - $relation = 'self'; - } - $value['family_floater_key'] = $relation; + // dd($policy_details); - $policy_data['basic_cover_si'] = $row[9]; - $policy_data['date_coverage'] = $row[13]; - $policy_data['client_policy_id'] = $file['policy_id']; + foreach ($excel_data as $key => $row) + { + $is_row_empty = check_row_is_empty_or_null($row); + if(!$is_row_empty) + { - $employee = $this->employeeModel->checkExistingEmployee($value, $file['client_branch_id']); - unset($value['temp']); - //save employee table - // dd($employee['id']); - if ($employee !== null) { - $value['updated_by'] = $file['created_by']; - $value['id'] = $employee['id']; - $value['emp_status'] = 'draft'; - - $log_message = 'Enrollment Update Employee - ' . $employee['name'] . '(' . $employee['emp_code'] . ') with PK ' . $employee['id']; - } else { - $value['emp_status'] = 'draft'; - $value['created_by'] = $file['created_by']; - $log_message = 'Enrollment Insert Employee- ' . $value['name'] . '(' . $value['emp_code'] . ') with PK '; - } - - $this->employeeModel->save($value); - if (isset($value['id'])) { - $emp_id = $value['id']; - } else { - $emp_id = $this->employeeModel->getInsertID(); - $log_message .= $emp_id; - } - - // $emp_id = $this->employeeModel->getInsertID(); - // if($emp_id != 0){ $log_message .= $emp_id; } - // else{ $emp_id = $employee['id']; } - - $this->myLogger->logme('error', $log_message); - - //save policy table - $employee_policy = $this->employeePolicyModel->checkExistingEmpPolicy(['employee_id' => $emp_id, 'client_policy_id' => $file['policy_id']]); - if (count($employee_policy)) { - $policy_data['updated_by'] = $file['created_by']; - $policy_data['id'] = $employee_policy[0]['id']; - $policy_data['status'] = 'draft'; - - $log_message = 'Update Employee Policy for ' . $value['name'] . '(' . $value['emp_code'] . ') with PK- ' . $employee_policy[0]['id'] . ' client policy ID ' . $employee_policy[0]['client_policy_id'] . ' with SI ' . $policy_data['basic_cover_si']; - // echo 'insert policy'; - } else { - $policy_data['employee_id'] = $emp_id; - $policy_data['client_policy_id'] = $file['policy_id']; - $policy_data['created_by'] = $file['created_by']; - $policy_data['status'] = 'draft'; - $log_message = 'Insert Employee Policy for ' . $value['name'] . '(' . $value['emp_code'] . ') - client policy id -' . $file['policy_id'] . ' - with SI ' . $policy_data['basic_cover_si']; - // echo 'update policy'; - } - - $this->employeePolicyModel->save($policy_data); - // $emp_policy_id = $this->employeePolicyModel->getInsertID(); - $emp_policy_id = isset($policy_data['id']) ? $policy_data['id'] : $this->employeePolicyModel->getInsertID(); - $this->myLogger->logme('error', $log_message); - - //save email of self for send mail later - if (isset($notification) && $notification['enabled'] == 1 && $notification['mail_content'] != '') { - if (strtolower($value['relationship']) == 'self' && $value['email_corporate'] != "") { - $params['dataToInsert'] = $value; //holds employee master data - $params['notification'] = $notification; - $params['client_data'] = $client_details; - $params['common'] = [ - 'client_id' => $file['client_id'], - 'client_branch_id' => $file['client_branch_id'], - 'client_policy_id' => $file['policy_id'], - 'employee_policy_id' => $emp_policy_id ?? null, - 'employee_id' => $emp_id, - 'mail_type' => 'member_welcome_mail', - ]; - - //store email and mail content via helper to send notification - $emp_emails[] = sendMailNotification::sendMailNotification('member_welcome_mail', $params); - // Kint::dump($emp_emails); - // Kint::dump($key.'-'.count($excel_data)); - // if mail count is 20 send bulk mail and reset emp_emails variable - // if (count($emp_emails) == 20 || $key == count($excel_data) ) { - // $job_details = new Jobs(); - // $r = Jobs::addJob(['job_name' => 'bulk_mail','payload' => $emp_emails]); - // // echo 'Mail triggered'; - // $emp_emails = []; - // } - - } - $value['family_floater_key'] = $relation; - - $policy_data['basic_cover_si'] = $row[9]; - $policy_data['date_coverage'] = $row[13]; - $policy_data['client_policy_id'] = $file['policy_id']; - - $employee = $this->employeeModel->checkExistingEmployee($value, $file['client_branch_id']); - unset($value['temp']); - //save employee table - // dd($employee['id']); - if ($employee !== null) { - $value['updated_by'] = $file['created_by']; - $value['id'] = $employee['id']; - $value['emp_status'] = 'draft'; - - $log_message = 'Enrollment Update Employee - ' . $employee['name'] . '(' . $employee['emp_code'] . ') with PK ' . $employee['id']; - } else { - $value['emp_status'] = 'draft'; - $value['created_by'] = $file['created_by']; - $log_message = 'Enrollment Insert Employee- ' . $value['name'] . '(' . $value['emp_code'] . ') with PK '; - } - - $this->employeeModel->save($value); - if (isset($value['id'])) { - $emp_id = $value['id']; - } else { - $emp_id = $this->employeeModel->getInsertID(); - $log_message .= $emp_id; - } - - // $emp_id = $this->employeeModel->getInsertID(); - // if($emp_id != 0){ $log_message .= $emp_id; } - // else{ $emp_id = $employee['id']; } - - $this->myLogger->logme('error', $log_message); - - //save policy table - $employee_policy = $this->employeePolicyModel->checkExistingEmpPolicy(['employee_id' => $emp_id, 'client_policy_id' => $file['policy_id']]); - if (count($employee_policy)) { - $policy_data['updated_by'] = $file['created_by']; - $policy_data['id'] = $employee_policy[0]['id']; - $policy_data['status'] = 'draft'; - - $log_message = 'Update Employee Policy for ' . $value['name'] . '(' . $value['emp_code'] . ') with PK- ' . $employee_policy[0]['id'] . ' client policy ID ' . $employee_policy[0]['client_policy_id'] . ' with SI ' . $policy_data['basic_cover_si']; - // echo 'insert policy'; - } else { - $policy_data['employee_id'] = $emp_id; - $policy_data['client_policy_id'] = $file['policy_id']; - $policy_data['created_by'] = $file['created_by']; - $policy_data['status'] = 'draft'; - $log_message = 'Insert Employee Policy for ' . $value['name'] . '(' . $value['emp_code'] . ') - client policy id -' . $file['policy_id'] . ' - with SI ' . $policy_data['basic_cover_si']; - // echo 'update policy'; - } - - $this->employeePolicyModel->save($policy_data); - $emp_policy_id = $this->employeePolicyModel->getInsertID(); - $this->myLogger->logme('error', $log_message); - - //save email of self for send mail later - if (isset($notification) && $notification['enabled'] == 1 && $notification['mail_content'] != '') { - if (strtolower($value['relationship']) == 'self' && $value['email_corporate'] != "") { - $params['dataToInsert'] = $value; //holds employee master data - $params['notification'] = $notification; - $params['client_data'] = $client_details; - $params['common'] = [ - 'client_id' => $file['client_id'], - 'client_branch_id' => $file['client_branch_id'], - 'client_policy_id' => $file['policy_id'], - 'employee_policy_id' => $emp_policy_id ?? null, - 'employee_id' => $emp_id, - 'mail_type' => 'member_welcome_mail', - ]; - - //store email and mail content via helper to send notification - $emp_emails[] = sendMailNotification::sendMailNotification('member_welcome_mail', $params); - // Kint::dump($emp_emails); - // Kint::dump($key.'-'.count($excel_data)); - // if mail count is 20 send bulk mail and reset emp_emails variable - // if (count($emp_emails) == 20 || $key == count($excel_data)) { - // $job_details = new Jobs(); - // $r = Jobs::addJob(['job_name' => 'bulk_mail', 'payload' => $emp_emails]); - // // echo 'Mail triggered'; - // $emp_emails = []; - // } + $value = []; + $policy_data = []; + $temp_unit = ''; + if(empty($row[12])) + { + $temp_unit = $existing_units[0]; } + + $value['emp_code'] = $row[1]; + $value['name'] = $row[2]; + $value['doj'] = (!empty($row[3]) ? convert_string_to_date($row[3],'Y-m-d'): null); + $value['gender'] = $row[4]; + $value['relationship'] = ucfirst(trim($row[5])); + $value['dob'] = convert_string_to_date($row[6],'Y-m-d'); + $value['email_corporate'] = $row[7]; + $value['mobile'] = $row[8]; + $value['band'] = $row[10]; + $value['basic_pay'] = $row[11]; + $value['unit'] = $temp_unit; + $value['family_floater_key'] = null; + $value['client_id'] = $file['client_id']; + $value['client_branch_id'] = $file['client_branch_id']; + $value['file_id'] = $file_id; + $value['is_addon_value'] = $policy_details['policy_type_id'] == 3 ? 1 : 0; + + $value['temp']['emp_id'] = null; // dummy value for using exisitng funciton in model + if (strtolower(trim($value['relationship'])) === 'mother' || strtolower(trim($value['relationship'])) === 'father') { + $relation = 'parent'; + } else if(strtolower(trim($value['relationship'])) === 'son' || strtolower(trim($value['relationship'])) === 'daughter'){ + $relation = 'child'; + }else if(strtolower(trim($value['relationship'])) === 'father in law' || strtolower(trim($value['relationship'])) === 'mother in law'){ + $relation = 'parent_in_law'; + }else if(strtolower(trim($value['relationship'])) === 'spouse'){ + $relation = 'spouse'; + }else{ + $relation = 'self'; + } + $value['family_floater_key'] = $relation; + + $policy_data['basic_cover_si'] = $row[9]; + $policy_data['date_coverage'] = $row[13] != "" && $row[13] != null ? change_date_format($row[13],'d-M-Y','Y-m-d') : null; + $policy_data['client_policy_id'] = $file['policy_id']; + + $employee = $this->employeeModel->checkExistingEmployee($value,$file['client_branch_id']); + unset($value['temp']); + //save employee table + // dd($employee['id']); + if($employee !== null) + { + $value['updated_by'] = $file['created_by']; + $value['id'] = $employee['id']; + $value['emp_status'] = 'draft'; + + $log_message = 'Enrollment Update Employee - '.$employee['name'].'('.$employee['emp_code'].') with PK '.$employee['id']; + } + else + { + $value['emp_status'] = 'draft'; + $value['created_by'] = $file['created_by']; + $log_message = 'Enrollment Insert Employee- '.$value['name'] .'('.$value['emp_code'] .') with PK '; + } + + $this->employeeModel->save($value); + if (isset($value['id'])) + { $emp_id = $value['id']; } + else { $emp_id = $this->employeeModel->getInsertID(); + $log_message .= $emp_id; + } + + // $emp_id = $this->employeeModel->getInsertID(); + // if($emp_id != 0){ $log_message .= $emp_id; } + // else{ $emp_id = $employee['id']; } + + $this->myLogger->logme('error',$log_message); + + //save policy table + $employee_policy = $this->employeePolicyModel->checkExistingEmpPolicy(['employee_id' => $emp_id,'client_policy_id' => $file['policy_id']]); + if(count($employee_policy)) + { + $policy_data['updated_by'] = $file['created_by']; + $policy_data['id'] = $employee_policy[0]['id']; + $policy_data['status'] = 'draft'; + + $log_message = 'Update Employee Policy for '. $value['name'].'('. $value['emp_code'].') with PK- ' . $employee_policy[0]['id'] .' client policy ID '.$employee_policy[0]['client_policy_id'].' with SI '.$policy_data['basic_cover_si']; + // echo 'insert policy'; + } + else + { + $policy_data['employee_id'] = $emp_id; + $policy_data['client_policy_id'] = $file['policy_id']; + $policy_data['created_by'] = $file['created_by']; + $policy_data['status'] = 'draft'; + $log_message = 'Insert Employee Policy for '. $value['name'].'('. $value['emp_code'].') - client policy id -'. $file['policy_id'].' - with SI '.$policy_data['basic_cover_si']; + // echo 'update policy'; + } + + $this->employeePolicyModel->save($policy_data); + $emp_policy_id = $this->employeePolicyModel->getInsertID(); + $this->myLogger->logme('error',$log_message); + + //save email of self for send mail later + if (isset($notification) && $notification['enabled'] == 1 && $notification['mail_content'] != '') + { + if(strtolower($value['relationship']) == 'self' && $value['email_corporate'] != "") + { + $params['dataToInsert'] = $value; //holds employee master data + $params['notification'] = $notification; + $params['client_data'] = $client_details; + + //store email and mail content via helper to send notification + $emp_emails[] = sendMailNotification::sendMailNotification('member_welcome_mail', $params); + } + } + }// endof if row is empty check + } //end of for loop + + + // for bulk mail queue job push + if (!empty($emp_emails) && count($emp_emails) > 0) { + + $emp_emails = array_chunk($emp_emails, 20); + + foreach ($emp_emails as $key => $value) { + $job_details = new Jobs(); + $r = Jobs::addJob(['job_name' => 'bulk_mail', 'payload' => $value]); } - } // endof if row is empty check - } //end of for loop - - // dd($emp_emails); - - // for bulk mail queue job push - if (!empty($emp_emails) && count($emp_emails) > 0) { - - $emp_emails = array_chunk($emp_emails, 20); - - foreach ($emp_emails as $key => $value) { - $job_details = new Jobs(); - $r = Jobs::addJob(['job_name' => 'bulk_mail', 'payload' => $value]); } - } - $this->fileModel->where('id', $file_id)->set(['status' => 'success', 'reason' => ''])->update(); - $this->myLogger->logme("error", '{file_id} uploaded success', ['file_id' => $file_id]); + $this->fileModel->where('id', $file_id)->set(['status' => 'success','reason' => ''])->update(); + $this->myLogger->logme("error",'{file_id} uploaded success',['file_id' => $file_id]); - $this->setPullNotification($this->getFileMetaDataByFileId($file_id, 'success')); + $this->setPullNotification($this->getFileMetaDataByFileId($file_id,'success')); - return true; - - - } - -} + return true; + }//end of employeesEnrollmentInsert } \ No newline at end of file diff --git a/app/Controllers/RestAuthenticationController.php b/app/Controllers/RestAuthenticationController.php index 14b61d7d..a7b77c09 100755 --- a/app/Controllers/RestAuthenticationController.php +++ b/app/Controllers/RestAuthenticationController.php @@ -102,7 +102,13 @@ class RestAuthenticationController extends AdminController { $employeeData = $this->employeeModel->where('id', $this->request->getJSON()->employee_id)->where('relationship', 'self')->first(); }else{ - $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->first(); + //$employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->first(); + $employeeData = $this->employeeModel->where('mobile', $mobile_number) + ->where('relationship', 'self') + ->where('emp_status !=', 'truncated') + ->where('is_active', 1) + ->first(); + } diff --git a/public/sample_excel/enrollment.xlsx b/public/sample_excel/enrollment.xlsx index 568e3b5e8e6c534f0f3fbb277383bb8cf3bfb1d6..b23bb77d685b223cb8f2c38ac154cab19f580aee 100755 GIT binary patch delta 3529 zcmZ8kc{mhY7oV}K$Zi;e$x^nlE21n}V=N z!o(n3$gT`!`=sZ2zvcdO&pG#;bI*OwdG7h0A@vz`7PFhQbX))?CMH0vZd4hID3JDK zFINJp(EKLw-n2rv+erKi6|T^Y(t*u&M;lzAmj`KL2vyMO8kh<9s0~flax{r*WeOha zD=m!z&_0=~2+AZU9?;ZM{5J-*mLi()RV&ZK7+VoNOP?@P0Wx8Q{WQk8ML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J_+p5MZRf5wF)QA<(ad~ zaTI_s`t7y%fr?v)u;RKN;`tcl4U2??CC9X~-diiCBd|G!8}#guY_F+PdxdhZF9mO_ zQEY@o(FrWYdUW2Ve3$vc4f_KP2Xx(!fFVfLYXR9+Hs$Z^pY-hwKv1XOgpQZe=13|? zmGn*olhs|8B3Xx@jZ3v3C`I3E%BZ324gVg(ke<1{ApeAYRix`;OKtf^62kC{NxT*I z_n#Jl?4m|=TTCCdKX)x7YfpN%rfM&H2`KoQzVtqdXWK(7c7@T?quYE#r2Fpnn3 Date: Wed, 4 Dec 2024 19:57:08 +0530 Subject: [PATCH 04/12] FIX_DOC_FORMAT_HANDLED_IN_HR_UPLOAD --- app/Controllers/EmployeeRestController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index abb15d65..8a1eed85 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -845,7 +845,7 @@ class EmployeeRestController extends AdminController 'basic_pay'=> $extra['11'][$index], 'unit'=> isset($extra['12'][$index]) ? $extra['12'][$index] : null, 'client_branch_id' => $client_branch_id, - 'date_coverage' => $extra['13'][$index] + 'date_coverage' => $extra['13'][$index] != "" && $extra['13'][$index] != null ? change_date_format($extra['13'][$index],'d-M-Y','Y-m-d') : null ]; $basic_cover_si_value = null; From 870fbfc75fed462bf4f94f99efa4717e1cdd147f Mon Sep 17 00:00:00 2001 From: Gowtham M Date: Thu, 5 Dec 2024 08:37:21 +0530 Subject: [PATCH 05/12] CHANGE_live issue and client feedback --- app/Controllers/EmployeeRestController.php | 23 ++++++-- .../RestAuthenticationController.php | 56 +++++++++++++++---- 2 files changed, 64 insertions(+), 15 deletions(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index ffe3486d..1785d543 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -1691,6 +1691,10 @@ class EmployeeRestController extends AdminController if($array['is_addon'] == 3 && $array['policy_type_id'] == 3)//dependent add on policy { + + if($this->request->getGet('client_id') == 8) // This changes only for client "sterling" + { + $selfGMC = $this->employeeModel->select('employees.name , employee_polices.basic_cover_si') ->join('employee_polices', 'employees.id = employee_polices.employee_id') ->join('client_policy', 'client_policy.id = employee_polices.client_policy_id AND client_policy.policy_type_id = 2') @@ -1709,6 +1713,9 @@ class EmployeeRestController extends AdminController // To reindex the array to have a proper 0 index $responce['SlabRates'] = array_values($filteredSlabRates); + } + + // Map family floaters that already exist in the employee table $familyFloates = $policy_terms->family_floaters; // remove parent and parent-in-law from familyFloaters @@ -1828,8 +1835,12 @@ class EmployeeRestController extends AdminController $whereArray = []; foreach ( $decodedArray->family_floaters as $key => $value) { if($value != 0){ - if($key == 'parents'){ $text = 'parent'; }else if($key == 'childrens'){ $text = 'child'; }else if($key == 'parents-in-law'){$text = 'parent_in_law';}else{ $text = $key; } - array_push($whereArray,$text); + if($key == 'parents'){ $text = ["parent"]; } + else if($key == 'childrens'){ $text = ["child"]; } + else if($key == 'parents-in-law'){ $text = ["parent_in_law"];} + else if($key ==='either-parents-pil') { $text = ["parent", "parent_in_law"];} + else{ $text = $key; } + $whereArray = array_merge($whereArray, $text); } } @@ -1878,8 +1889,12 @@ class EmployeeRestController extends AdminController $whereArray = []; foreach ( $decodedArray->family_floaters as $key => $value) { if($value != 0){ - if($key == 'parents'){ $text = 'parent'; }else if($key == 'childrens'){ $text = 'child'; }else if($key == 'parents-in-law'){$text = 'parent_in_law';}else{ $text = $key; } - array_push($whereArray,$text); + if($key == 'parents'){ $text = ["parent"]; } + else if($key == 'childrens'){ $text = ["child"]; } + else if($key == 'parents-in-law'){ $text = ["parent_in_law"];} + else if($key ==='either-parents-pil') { $text = ["parent", "parent_in_law"];} + else{ $text = $key; } + $whereArray = array_merge($whereArray, $text); } } diff --git a/app/Controllers/RestAuthenticationController.php b/app/Controllers/RestAuthenticationController.php index 4d646997..f663a40b 100755 --- a/app/Controllers/RestAuthenticationController.php +++ b/app/Controllers/RestAuthenticationController.php @@ -128,8 +128,9 @@ class RestAuthenticationController extends AdminController { $employeeData = $this->employeeModel->where('id', $this->request->getJSON()->employee_id)->where('relationship', 'self')->first(); }else{ - $mobile_number = $this->request->getJSON()->mobile_number; - $email_id = $this->request->getJSON()->email_id; + + $mobile_number = isset($this->request->getJSON()->mobile_number) ? $this->request->getJSON()->mobile_number : null; + $email_id = isset($this->request->getJSON()->email_id) ? $this->request->getJSON()->email_id : null; $employeeData = $this->employeeModel->where('relationship', 'self'); @@ -257,11 +258,20 @@ class RestAuthenticationController extends AdminController public function saveMpin() { try { - $mobile_number = $this->request->getJSON()->mobile_number; + + $mobile_number = isset($this->request->getJSON()->mobile_number) ? $this->request->getJSON()->mobile_number : null; + $email_id = isset($this->request->getJSON()->email_id) ? $this->request->getJSON()->email_id : null; + + if (isset($mobile_number)) { + $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->first(); + } else { + $employeeData = $this->employeeModel->where('email', $email_id)->where('relationship', 'self')->first(); + } + $mpin = $this->request->getJSON()->mpin; - $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->first(); + if ($employeeData) { $id= $employeeData["id"]; @@ -288,12 +298,20 @@ class RestAuthenticationController extends AdminController public function updateMpin() { try { - $mobile_number = $this->request->getJSON()->mobile_number; + + $mobile_number = isset($this->request->getJSON()->mobile_number) ? $this->request->getJSON()->mobile_number : null; + $email_id = isset($this->request->getJSON()->email_id) ? $this->request->getJSON()->email_id : null; $old_mpin = $this->request->getJSON()->old_mpin; $mpin = $this->request->getJSON()->new_mpin; - - $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('mpin', $old_mpin)->where('relationship', 'self')->first(); + if (isset($mobile_number)) + { + $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('mpin', $old_mpin)->where('relationship', 'self')->first(); + }else{ + $employeeData = $this->employeeModel->where('email', $email_id)->where('mpin', $old_mpin)->where('relationship', 'self')->first(); + } + + if ($employeeData) { $id= $employeeData["id"]; @@ -320,10 +338,17 @@ class RestAuthenticationController extends AdminController public function verifyMpin() { try { - $mobile_number = $this->request->getJSON()->mobile_number; + + $mobile_number = isset($this->request->getJSON()->mobile_number) ? $this->request->getJSON()->mobile_number : null; + $email_id = isset($this->request->getJSON()->email_id) ? $this->request->getJSON()->email_id : null; $mpin = $this->request->getJSON()->mpin; - $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->first(); + if (isset($mobile_number)) + { + $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->first(); + }else{ + $employeeData = $this->employeeModel->where('email', $email_id)->where('relationship', 'self')->first(); + } if ($employeeData && $mpin == $employeeData["mpin"]) { $auth = HttpRequestHelper::getRequestInfo(); @@ -355,10 +380,19 @@ class RestAuthenticationController extends AdminController public function checkMpin() { try { - $mobile_number = $this->request->getJSON()->mobile_number; + $mobile_number = isset($this->request->getJSON()->mobile_number) ? $this->request->getJSON()->mobile_number : null; + $email_id = isset($this->request->getJSON()->email_id) ? $this->request->getJSON()->email_id : null; + $mpin = $this->request->getJSON()->mpin; + + if (isset($mobile_number)) + { + $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->first(); + }else{ + $employeeData = $this->employeeModel->where('email', $email_id)->where('relationship', 'self')->first(); + } - $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->first(); + if ($employeeData && $employeeData["mpin"] != null) { From ee33bbf48a9d4451a8ab9662698567aedd02f012 Mon Sep 17 00:00:00 2001 From: Gowtham M Date: Thu, 5 Dec 2024 12:33:56 +0530 Subject: [PATCH 06/12] CHANGE_ error in live : GWM --- app/Controllers/EmployeeRestController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index df90fccd..525f3fa9 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -1839,7 +1839,7 @@ class EmployeeRestController extends AdminController else if($key == 'childrens'){ $text = ["child"]; } else if($key == 'parents-in-law'){ $text = ["parent_in_law"];} else if($key ==='either-parents-pil') { $text = ["parent", "parent_in_law"];} - else{ $text = $key; } + else{ $text = [$key]; } $whereArray = array_merge($whereArray, $text); } } @@ -1893,7 +1893,7 @@ class EmployeeRestController extends AdminController else if($key == 'childrens'){ $text = ["child"]; } else if($key == 'parents-in-law'){ $text = ["parent_in_law"];} else if($key ==='either-parents-pil') { $text = ["parent", "parent_in_law"];} - else{ $text = $key; } + else{ $text = [$key]; } $whereArray = array_merge($whereArray, $text); } } From f2de214a4860387975394cfd08210e59e964db69 Mon Sep 17 00:00:00 2001 From: Gowtham M Date: Thu, 5 Dec 2024 17:50:05 +0530 Subject: [PATCH 07/12] CHANGE_direct live change : GWM --- app/Config/Routes.php | 2 +- app/Controllers/EmployeeRestController.php | 77 ++++++++++++++++++++-- 2 files changed, 73 insertions(+), 6 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 4f0213c0..f4942153 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -452,7 +452,7 @@ $routes->group("employeeRest", ["filter" => "authJWT"], function ($routes) { $routes->get("sendPushNotification", "EmployeeRestController::sendPushNotification"); $routes->post("sendEmail", "EmployeeRestController::send_email"); -// $routes->post("employeeUpload", "EmployeeRestController::employeeUpload"); +$routes->get("getFamilyPolicyDetails", "EmployeeRestController::getFamilyPolicyDetails"); // Ticketing System diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 525f3fa9..601958e3 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -1736,7 +1736,7 @@ class EmployeeRestController extends AdminController foreach ($addOnEmployeeData as $key => $value) { if ($value['family_floater_key'] === $dependent) { $employee_policy = $this->employeePolicyModel->where('employee_id',$value['id'])->where('client_policy_id',$array['id'])->where('is_active', 1 )->get()->getRow(); - if(isset($employee_policy->basic_cover_si)){ $dependent_and_si_value = $employee_policy->basic_cover_si; } + if(isset($employee_policy->basic_cover_si)){ $dependent_and_si_value = ($dependent_and_si_value == 0) ? $employee_policy->basic_cover_si : $dependent_and_si_value; } if(isset($employee_policy->rata_premimum)){ $dependent_and_si_premium_value = $dependent_and_si_premium_value + $employee_policy->rata_premimum;} if(isset($employee_policy->gst)){ $dependent_and_si_gst_value = $dependent_and_si_gst_value + $employee_policy->gst;} @@ -1857,7 +1857,7 @@ class EmployeeRestController extends AdminController foreach ($BasePolicyEmployeeData as $key => $value) { $employee_policy = $this->employeePolicyModel->where('employee_id',$value['id'])->where('client_policy_id',$array['id'])->where('is_active', 1 )->get()->getRow(); - if(isset($employee_policy->basic_cover_si)){ $only_si_value = $employee_policy->basic_cover_si; } + if(isset($employee_policy->basic_cover_si)){ $only_si_value = ($only_si_value == 0) ? $employee_policy->basic_cover_si : $only_si_value; } if(isset($employee_policy->rata_premimum)){ $only_si_premium_value = $only_si_premium_value + $employee_policy->rata_premimum;} if(isset($employee_policy->gst)){ $only_si_gst_value = $only_si_gst_value + $employee_policy->gst;} $temp3['is_value_exist'] = true; @@ -1910,7 +1910,7 @@ class EmployeeRestController extends AdminController foreach ($BasePolicyEmployeeData as $key => $value) { $employee_policy = $this->employeePolicyModel->where('employee_id',$value['id'])->where('client_policy_id',$array['id'])->where('is_active', 1 )->get()->getRow(); - if(isset($employee_policy->basic_cover_si)){ $only_si_value = $employee_policy->basic_cover_si; } + if(isset($employee_policy->basic_cover_si)){ $only_si_value = ($only_si_value == 0) ? $employee_policy->basic_cover_si : $only_si_value; } if(isset($employee_policy->rata_premimum)){ $only_si_premium_value = $only_si_premium_value + $employee_policy->rata_premimum;} if(isset($employee_policy->gst)){ $only_si_gst_value = $only_si_gst_value + $employee_policy->gst;} $temp3['is_value_exist'] = true; @@ -2282,8 +2282,19 @@ class EmployeeRestController extends AdminController if($clientPolicy[0]['is_addon'] == 2)//Topup { - $empData = $this->employeeModel->where('emp_code',$this->request->getGet('emp_code')) - ->where('is_addon_value', 0 )->findAll(); + + if($clientPolicy[0]['policy_type_id'] == 4)//GMC-Topup + { + $empData = $this->employeeModel->where('emp_code',$this->request->getGet('emp_code')) + ->where('is_addon_value', 0 ) + ->findAll(); + }else if($clientPolicy[0]['policy_type_id'] == 5)//GMC-Parent-Topup + { + $empData = $this->employeeModel->where('emp_code',$this->request->getGet('emp_code')) + ->where('is_addon_value', 1 ) + ->findAll(); + } + if(count($empData)) { foreach ($empData as $key => $value) { @@ -2652,6 +2663,62 @@ class EmployeeRestController extends AdminController // log_message('error', $e->getMessage()); // } // } + + + public function getFamilyPolicyDetails() + { + // Get query parameters + $empCode = $this->request->getGet('emp_code'); + $clientId = $this->request->getGet('client_id'); + $clientBranchId = $this->request->getGet('client_branch_id'); + + if (!$empCode || !$clientId || !$clientBranchId) { + return $this->fail("emp_code, client_id, and client_branch_id are required parameters."); + } + + // Fetch employee family details + $employees = $this->employeeModel->select('id,emp_code,name,relationship,dob,emp_status,is_addon_value')->where([ + 'emp_code' => $empCode, + 'client_id' => $clientId, + 'client_branch_id' => $clientBranchId, + 'is_active' => 1 + ])->findAll(); + + if (empty($employees)) { + return $this->failNotFound("No employees found for the provided parameters."); + } + + // Collect employee IDs + $employeeIds = array_column($employees, 'id'); + + // Fetch policies related to the employee IDs + $policies = $this->employeePolicyModel->whereIn('employee_id', $employeeIds)->where('is_active',1)->findAll(); + + if (empty($policies)) { + return $this->failNotFound("No policies found for the provided employees."); + } + + // Structure the response + $result = []; + foreach ($policies as $policy) { + $policyEmployees = array_filter($employees, function ($emp) use ($policy) { + return $emp['id'] === $policy['employee_id']; + }); + + $result[] = [ + 'policy_id' => $policy['id'], + 'client_policy_id' => $policy['client_policy_id'], + 'uhid' => $policy['uhid'], + 'status' => $policy['status'], + 'basic_cover_si' => $policy['basic_cover_si'], + 'date_coverage' => $policy['date_coverage'], + 'policy_end_date' => $policy['policy_end_date'], + 'members' => array_values($policyEmployees), + ]; + } + + return $this->respond(['family_policies' => $result]); + } From fc0a9592d31b9404da44cd56211a96ba6c021622 Mon Sep 17 00:00:00 2001 From: velz Date: Fri, 6 Dec 2024 10:40:18 +0530 Subject: [PATCH 08/12] CHANGE_REMOVED_SI_IN_FLOATER_POLICY --- app/Controllers/EmployeeRestController.php | 2 +- app/Helpers/sendMailNotification.php | 4 ++-- app/Models/EmployeeModel.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index df90fccd..747b272d 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -346,7 +346,7 @@ class EmployeeRestController extends AdminController ->where('client_policy_id',$value['policy_details']['client_policy_id'] ) ->where('employee_id' , $value['temp']['emp_id'] ) ->where('is_active', 1 ) - ->set(array('premium'=> $value['policy_details']['premium'] , 'rata_premimum'=> $value['policy_details']['rata_premimum'] , 'gst'=> $value['policy_details']['gst'] )) + ->set(array('basic_cover_si' => $value['policy_details']['basic_cover_si'],'premium'=> $value['policy_details']['premium'] , 'rata_premimum'=> $value['policy_details']['rata_premimum'] , 'gst'=> $value['policy_details']['gst'] )) ->update(); } diff --git a/app/Helpers/sendMailNotification.php b/app/Helpers/sendMailNotification.php index e6b6edf9..26ee4af5 100755 --- a/app/Helpers/sendMailNotification.php +++ b/app/Helpers/sendMailNotification.php @@ -282,11 +282,11 @@ class sendMailNotification $premium = ''; $gst_forself = ''; - if(checkFamilyFloaters($policy_premium_data, $client_policy_data, $inner_item)){ + // if(checkFamilyFloaters($policy_premium_data, $client_policy_data, $inner_item)){ $si = '₹ ' .format_indian_number($inner_item['basic_cover_si']); $premium = '₹ ' .format_indian_number(round($inner_item['premium'])); $gst_forself = '₹ ' .format_indian_number(round($inner_item['gst'])); - } + // } $temp_data .= ''; $temp_data .= '' . $inner_item['name'] . ($inner_item['relationship'] == 'Self' ? ' (' . $inner_item['emp_code'] . ')' : '') . ''; diff --git a/app/Models/EmployeeModel.php b/app/Models/EmployeeModel.php index edffa781..9fd8fbdb 100755 --- a/app/Models/EmployeeModel.php +++ b/app/Models/EmployeeModel.php @@ -149,7 +149,7 @@ class EmployeeModel extends Model { return $this->db->table('employee_polices') - ->select(' policy_type.long_name as Policy_Name , client_policy.policy_terms as Policy_Terms, client_policy.client_id as ClientId, client_policy.policy_id as PolicyId,client_policy.id as ClientPolicyId, client_policy.open_for_enrollment as OpenForEnrollment, client_policy.is_member_modify_allowed, client_policy.disclaimer,client_policy.policy_type_id , employee_polices.tpa_id as tpa_id , employee_polices.rand_string as rand_string') // Select all columns from both tables + ->select(' policy_type.long_name as Policy_Name , client_policy.policy_terms as Policy_Terms, client_policy.client_id as ClientId, client_policy.policy_id as PolicyId,client_policy.id as ClientPolicyId, client_policy.open_for_enrollment as OpenForEnrollment,client_policy.disclaimer,client_policy.policy_type_id , employee_polices.tpa_id as tpa_id , employee_polices.rand_string as rand_string') // Select all columns from both tables ->join('client_policy', 'client_policy.id = employee_polices.client_policy_id') ->join('policy_type', 'policy_type.id = client_policy.policy_type_id') ->where('client_policy.policy_status', 1) From 01b30e4360222d3fae7dba87f1d32eb6c0dba61e Mon Sep 17 00:00:00 2001 From: Srinivas-Saravanan Date: Fri, 6 Dec 2024 10:44:31 +0530 Subject: [PATCH 09/12] FEAT_MAIL SENT HISTORY ADDED --- Job_Queue.txt | 1 + app/Controllers/MasterController.php | 12 ++-- app/Helpers/GmailResponseHandler.php | 94 ++++++++++++++++++++++++++++ app/Helpers/JWTToken.php | 2 +- app/Helpers/MailHelper.php | 23 ++++--- app/Models/GmailSentHistoryModel.php | 11 ++++ job_queue | 1 + phpqueue.bat | 42 +++++++++++++ phpqueue.pid | 1 + phpqueue.sh | 56 +++++++++++++++++ phpsetvariable.sh | 13 ++++ 11 files changed, 243 insertions(+), 13 deletions(-) create mode 100755 Job_Queue.txt create mode 100644 app/Helpers/GmailResponseHandler.php create mode 100644 app/Models/GmailSentHistoryModel.php create mode 100755 job_queue create mode 100644 phpqueue.bat create mode 100644 phpqueue.pid create mode 100755 phpqueue.sh create mode 100755 phpsetvariable.sh diff --git a/Job_Queue.txt b/Job_Queue.txt new file mode 100755 index 00000000..56a6051c --- /dev/null +++ b/Job_Queue.txt @@ -0,0 +1 @@ +1 \ No newline at end of file diff --git a/app/Controllers/MasterController.php b/app/Controllers/MasterController.php index 1599bac2..a875e437 100755 --- a/app/Controllers/MasterController.php +++ b/app/Controllers/MasterController.php @@ -30,6 +30,8 @@ use App\Models\StateModel; use App\Models\PolicyTypeModel; use App\Models\CDMasterModel; use App\Models\ClientDepositModel; +use App\Models\EmployeePolicyModel; +use App\Models\FileModel; use App\Models\InsurerExcelExportTemplateModel; use App\Models\SettingsModel; use App\Models\VehicleModel; @@ -1574,7 +1576,7 @@ class MasterController extends AdminController $to = $this->request->getPost('to'); $subject = $this->request->getPost('subject'); $mail_content = $this->request->getPost('content'); - + $common = ['mail_type'=>'test_mail_ui']; /*****CHOOSE ANY ONE AT A TIME, COMMENT ANOTHER ONE******/ /*****CALLING DIRECLT USING LIB******/ @@ -1591,7 +1593,7 @@ class MasterController extends AdminController /*****CALLING DIRECLT USING LIB******/ /*****CALLING VIA MAIL HELPER******/ - $res = MailHelper::send_email(['mail' => $to, 'subject' => $subject, 'message' => $mail_content]); + $res = MailHelper::send_email(['mail' => $to, 'subject' => $subject,'common'=>$common ,'message' => $mail_content]); return $this->respond(['status' => 'success','code' => 200,'data' => $res],200); /*****CALLING VIA MAIL HELPER******/ @@ -1623,10 +1625,10 @@ class MasterController extends AdminController ["filePath" => ROOTPATH."public/sample_excel/sample_inception.xls","fileName" => "sample_inception.xls"], ["filePath" => ROOTPATH."public/assets/images/login_bg.jpg","fileName" => "login_bg.jpg"] ]; - - + $common = ['mail_type'=>'test_mail_cli']; $email_id = CLI::getOption('to') ? CLI::getOption('to') : $email_id; - $res = MailHelper::send_email(['mail' => $email_id, 'subject' => 'Mail Via CLI', 'message' => $message,'attachments' => $attachments]); + $res = MailHelper::send_email(['mail' => $email_id, 'subject' => 'Mail Via CLI', 'message' => $message,'attachments' => $attachments,'common'=>$common]); + echo "Inside the master controller"; print_r($res); } diff --git a/app/Helpers/GmailResponseHandler.php b/app/Helpers/GmailResponseHandler.php new file mode 100644 index 00000000..27347b94 --- /dev/null +++ b/app/Helpers/GmailResponseHandler.php @@ -0,0 +1,94 @@ +store_gmail_response_data($params); + $this->gmail_response_logger($params); + + } + catch(Exception $e) + { + + $error = $e->getMessage(); + echo "An Error Occured" . $error; + log_message('error',$error); + + } + } + + + public function store_gmail_response_data($params){ + // foreach ($params as $key => $value){ + // $prepare_data = [ + // $key => $value + // ]; + // } + // $data = [ + // 'email' => isset($params['params']['mail']) ? $params['params']['mail'] : null, + // 'bcc' => isset($params['params']['bcc']) ? json_encode($params['params']['bcc']) : null, + // 'cc' => isset($params['params']['cc']) ? json_encode($params['params']['cc']) : null, + // 'message' => isset($params['params']['message']) ? $params['params']['message'] : null, + // 'attachments' => isset($params['params']['attachments']) ? json_encode($params['params']['attachments']) : null, + // 'client_id' => isset($params['params']['common']['client_id']) ? $params['params']['common']['client_id'] : null, + // 'client_branch_id' => isset($params['params']['common']['client_branch_id']) ? $params['params']['common']['client_branch_id'] : null, + // 'client_policy_id' => isset($params['params']['common']['client_policy_id']) ? $params['params']['common']['client_policy_id'] : null, + // 'employee_policy_id' => isset($params['params']['common']['employee_policy_id']) ? $params['params']['common']['employee_policy_id'] : null, + // 'employee_id' => isset($params['params']['common']['employee_id']) ? $params['params']['common']['employee_id'] : null, + // 'mail_type' => isset($params['params']['common']['mail_type']) ? $params['params']['common']['mail_type'] : null, + // 'gmail_api_status' => isset($params['gmail_api']['status']) ? $params['gmail_api']['status'] : null, + // 'gmail_api_id' => isset($params['gmail_api']['data']['id']) ? $params['gmail_api']['data']['id'] : null + // ]; + // Initialize data array + $data = []; + // print_r($params['params']['common']);die(); + if (isset($params['params']['common'])) { + foreach ($params['params']['common'] as $key => $value) { + $data[$key] = isset($value) ? $value : null; + } + unset($params['params']['common']); + } + if (isset($params['params'])){ + foreach($params['params'] as $key => $value){ + $arr = ['bcc','cc','attachments']; + if(in_array($key,$arr)){ + $data[$key] = isset($value)?json_encode($value):null; + }else{ + $data[$key] = isset($value)?$value:null; + } + } + } + if(isset($params['gmail_api']['status']) && $params['gmail_api']['status'] == 1 ){ + $data['gmail_api_status'] = isset($params['gmail_api']['status']) ? $params['gmail_api']['status'] : null; + $data['gmail_api_id'] = isset($params['gmail_api']['data']['id']) ? $params['gmail_api']['data']['id'] : null; + $data['received_message'] = isset($params['gmail_api']['data']['labelIds']) ? json_encode($params['gmail_api']['data']['labelIds']) : null; + + } + elseif(isset($params['gmail_api']['status']) && $params['gmail_api']['status'] == false ){ + $data['gmail_api_status'] = $params['gmail_api']['status']; + if(isset($params['gmail_api']['data'])){ + $data['received_message'] = json_encode($params['gmail_api']['data']); + } + } + + $gmailModel = new GmailSentHistoryModel(); + $save_status = $gmailModel->insert($data); + + + } + + public function gmail_response_logger($params){ + + } + + +} \ No newline at end of file diff --git a/app/Helpers/JWTToken.php b/app/Helpers/JWTToken.php index 196bdaca..41d76b5c 100755 --- a/app/Helpers/JWTToken.php +++ b/app/Helpers/JWTToken.php @@ -11,7 +11,7 @@ use Firebase\JWT\SignatureInvalidException; // use Psr\Http\Message\RequestInterface; use CodeIgniter\HTTP\RequestInterface; use ReflectionClass; - +use Exception; use App\Models\EmployeeModel; use App\Models\LevelContactModel; diff --git a/app/Helpers/MailHelper.php b/app/Helpers/MailHelper.php index 0bc21c46..78f5983b 100755 --- a/app/Helpers/MailHelper.php +++ b/app/Helpers/MailHelper.php @@ -11,7 +11,6 @@ use PHPMailer\PHPMailer\Exception; use App\Models\JobModel; - class MailHelper { public static function send_email_smtp($params) @@ -94,7 +93,7 @@ class MailHelper $subject = $params['subject']; $message = $params['message']; $attachments = isset($params['attachments']) && count($params['attachments']) ? $params['attachments'] : []; - + $common = isset($params['common'])?$params['common']:''; //check BCC mail if (isset($params['bcc'])) { $bcc = $params['bcc']; @@ -118,26 +117,36 @@ class MailHelper if(isset($params['reply_to']) && !empty($params['reply_to'])){ $reply_to = $params['reply_to']; } + $MailDataHelper = new GmailResponseHandler(); + $res['params'] = $params; try { - $res = $gmailapi->sendMessage($emaill, $subject, $message, 'no-reply@nhanceindia.in', $reply_to, $cc, $bcc,$attachments); - - if($res['status']) + $res['gmail_api'] = $gmailapi->sendMessage($emaill, $subject, $message, 'no-reply@nhanceindia.in', $reply_to, $cc, $bcc,$attachments); + if($res['gmail_api']['status']) { + $response = $res; + // $MailDataHelper->receive_and_distribute_param_to_functions($response); return json_encode(['status' => 'success','code' => 200, 'message'=>('Email Sent Successfully...'.$emaill),'data' => $res,],200); } else { $myLogger->logme('error', "mail sent failed - $emaill"); + $response = $res; + // $MailDataHelper->receive_and_distribute_param_to_functions($response); return json_encode(['status' => 'failed','code' => 404,'message'=>( 'Email Sent Failed...' . $emaill ),'data' => $res ],404); } } catch (Exception $e) { - $msg = $e->getMessage(); + $msg['error'] = $e->getMessage(); + $msg['params'] = $params; $myLogger->logme('error', "mail sent failed - $msg"); + $response = $msg; + // $MailDataHelper->receive_and_distribute_param_to_functions($response); return json_encode(['status' => 'failed','code' => 500,'data' => $msg],500); - } + } + + } diff --git a/app/Models/GmailSentHistoryModel.php b/app/Models/GmailSentHistoryModel.php new file mode 100644 index 00000000..9a0ae8ea --- /dev/null +++ b/app/Models/GmailSentHistoryModel.php @@ -0,0 +1,11 @@ +nul + if not errorlevel 1 ( + echo phpqueue.bat is already running. Exiting. + exit /b + ) +) + +REM Write the current process ID (PID) to the PID file +echo %PROCESS_ID% > "%PID_FILE%" + +REM Main loop +:loop +REM Check if the Job_Queue file exists +if not exist "%JOB_QUEUE_FILE%" ( + echo Job Queue file not found. + exit /b +) + +REM Read the value of Job_Queue from the file +set /p Job_Queue=<%JOB_QUEUE_FILE% + +if "%Job_Queue%"=="1" ( + REM Run PHP job processing + php "%ROOT_DIR%htdocs/nhance/public/index.php" cli/processjob +) else ( + echo No job to process. +) + +REM Sleep for 1 second before the next iteration +timeout /T 1 >nul +goto loop diff --git a/phpqueue.pid b/phpqueue.pid new file mode 100644 index 00000000..db08d2ac --- /dev/null +++ b/phpqueue.pid @@ -0,0 +1 @@ +575 diff --git a/phpqueue.sh b/phpqueue.sh new file mode 100755 index 00000000..f1e7176b --- /dev/null +++ b/phpqueue.sh @@ -0,0 +1,56 @@ +!/bin/bash +while true; do + echo "Running job at $(date)" + /usr/bin/php /opt/lampp/htdocs/nhance/public/index.php cli/processjob + !/bin/bash +!/bin/bash + +# Read the Job_Queue variable from the temporary file +#!/bin/bash + +#!/bin/bash + +#!/bin/bash + +# Define the root directory for the project and PID file path +#!/bin/bash + +# Define paths +# ROOT_DIR=$(dirname "$(realpath "$0")") +# JOB_QUEUE_FILE="$ROOT_DIR/job_queue" +# PID_FILE="$ROOT_DIR/phpqueue.pid" + + +# # Check if the script is already running +# if [[ -f "$PID_FILE" ]] && kill -0 "$(cat $PID_FILE)" 2>/dev/null; then +# echo "phpqueue.sh is already running. Exiting." +# exit 1 +# fi + +# # Write the current process ID (PID) to the PID file +# echo $$ > "$PID_FILE" + +# # Ensure the PID file is removed on script exit +# trap "rm -f $PID_FILE" EXIT + +# # Main loop +# while true; do +# # Check if the Job_Queue file exists +# if [[ ! -f "$JOB_QUEUE_FILE" ]]; then +# echo "Job Queue file not found." +# exit 1 +# fi + +# # Read the value of Job_Queue from the file +# Job_Queue=$(cat "$JOB_QUEUE_FILE") + +# if [[ "$Job_Queue" -eq 1 ]]; then +# /usr/bin/php /opt/lampp/htdocs/nhance/public/index.php cli/processjob +# else +# echo "No job to process." +# fi + +# # Sleep for 1 second before the next iteration +# sleep 1 +# done + diff --git a/phpsetvariable.sh b/phpsetvariable.sh new file mode 100755 index 00000000..69c1b0ac --- /dev/null +++ b/phpsetvariable.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# Validate input argument +# if [[ "$1" == "1" ]]; then +# echo "1" > /opt/lampp/htdocs/nhance/Job_Queue +# echo "Job Queue variable has been set to: 1" +# elif [[ "$1" == "0" ]]; then +# echo "0" > /opt/lampp/htdocs/nhance/Job_Queue +# echo "Job Queue variable has been set to: 0" +# else +# echo "Invalid argument. Use 1 to enable the queue or 0 to disable it." +# exit 1 +# fi From a552e06adfa71e31ea3ce72b381803a469e9abfb Mon Sep 17 00:00:00 2001 From: Srinivas-Saravanan Date: Fri, 6 Dec 2024 10:47:20 +0530 Subject: [PATCH 10/12] FEAT_GMAIL RESPONSE HELPER ADDED --- Job_Queue.txt | 1 - job_queue | 1 - phpqueue.bat | 42 ------------------------------------------ phpqueue.pid | 1 - phpsetvariable.sh | 13 ------------- 5 files changed, 58 deletions(-) delete mode 100755 Job_Queue.txt delete mode 100755 job_queue delete mode 100644 phpqueue.bat delete mode 100644 phpqueue.pid delete mode 100755 phpsetvariable.sh diff --git a/Job_Queue.txt b/Job_Queue.txt deleted file mode 100755 index 56a6051c..00000000 --- a/Job_Queue.txt +++ /dev/null @@ -1 +0,0 @@ -1 \ No newline at end of file diff --git a/job_queue b/job_queue deleted file mode 100755 index c2270834..00000000 --- a/job_queue +++ /dev/null @@ -1 +0,0 @@ -0 \ No newline at end of file diff --git a/phpqueue.bat b/phpqueue.bat deleted file mode 100644 index 5247ccff..00000000 --- a/phpqueue.bat +++ /dev/null @@ -1,42 +0,0 @@ -@echo off -setlocal enabledelayedexpansion - -REM Get the directory of the current script -set "ROOT_DIR=%~dp0" -set "JOB_QUEUE_FILE=%ROOT_DIR%job_queue" -set "PID_FILE=%ROOT_DIR%phpqueue.pid" - -REM Check if the script is already running -if exist "%PID_FILE%" ( - for /f "tokens=*" %%i in (%PID_FILE%) do set PID=%%i - tasklist /fi "PID eq !PID!" | findstr /i "!PID!" >nul - if not errorlevel 1 ( - echo phpqueue.bat is already running. Exiting. - exit /b - ) -) - -REM Write the current process ID (PID) to the PID file -echo %PROCESS_ID% > "%PID_FILE%" - -REM Main loop -:loop -REM Check if the Job_Queue file exists -if not exist "%JOB_QUEUE_FILE%" ( - echo Job Queue file not found. - exit /b -) - -REM Read the value of Job_Queue from the file -set /p Job_Queue=<%JOB_QUEUE_FILE% - -if "%Job_Queue%"=="1" ( - REM Run PHP job processing - php "%ROOT_DIR%htdocs/nhance/public/index.php" cli/processjob -) else ( - echo No job to process. -) - -REM Sleep for 1 second before the next iteration -timeout /T 1 >nul -goto loop diff --git a/phpqueue.pid b/phpqueue.pid deleted file mode 100644 index db08d2ac..00000000 --- a/phpqueue.pid +++ /dev/null @@ -1 +0,0 @@ -575 diff --git a/phpsetvariable.sh b/phpsetvariable.sh deleted file mode 100755 index 69c1b0ac..00000000 --- a/phpsetvariable.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -# Validate input argument -# if [[ "$1" == "1" ]]; then -# echo "1" > /opt/lampp/htdocs/nhance/Job_Queue -# echo "Job Queue variable has been set to: 1" -# elif [[ "$1" == "0" ]]; then -# echo "0" > /opt/lampp/htdocs/nhance/Job_Queue -# echo "Job Queue variable has been set to: 0" -# else -# echo "Invalid argument. Use 1 to enable the queue or 0 to disable it." -# exit 1 -# fi From c6f06828e01b475227ef4beb77d13db6be92bf7c Mon Sep 17 00:00:00 2001 From: Srinivas-Saravanan Date: Sat, 7 Dec 2024 14:44:44 +0530 Subject: [PATCH 11/12] FEAT_ECARD SENT STATUS FLAG ADDED --- app/Controllers/ClientController.php | 6 +-- app/Controllers/DashboardController.php | 14 +++++-- app/Controllers/EmployeeController.php | 2 +- app/Controllers/EmployeeServiceController.php | 2 +- app/Helpers/GmailResponseHandler.php | 39 +++++++++++++++++-- app/Helpers/MailHelper.php | 12 +++--- app/Models/EmployeePolicyModel.php | 3 +- 7 files changed, 59 insertions(+), 19 deletions(-) diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index efcd633e..6191c995 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -181,7 +181,7 @@ class ClientController extends AdminController print_rr($attachments); } - public function testingForReviewMail($client_id = 77, $emp_code = 'EMP001-K1', $mail_active = 0) //this function for only tsesting some logics not use for business logic + public function testingForReviewMail($client_id = 77, $emp_code = 'EMP001-K1', $mail_active = 1) //this function for only tsesting some logics not use for business logic { $client_policy_ids = $this->employeeModel @@ -3708,8 +3708,8 @@ class ClientController extends AdminController public function sendextraparam(){ - $employeeRestController = new EmployeeServiceController(); - $employeeRestController->employeesEnrollmentInsert(['file_id' => 683]); + // $employeeRestController = new EmployeeServiceController(); + // $employeeRestController->employeesEnrollmentInsert(['file_id' => 715]); // $dashBoardController = new DashboardController(); // $client_policy_data = $this->clientPolicyModel->getPolicyDetailsForRemainder($client_id=159, $client_branch_id=126); diff --git a/app/Controllers/DashboardController.php b/app/Controllers/DashboardController.php index 1a8c8382..b4843a59 100755 --- a/app/Controllers/DashboardController.php +++ b/app/Controllers/DashboardController.php @@ -417,8 +417,9 @@ class DashboardController extends AdminController // Send the mail notification $mail_result = sendMailNotification::sendMailNotification('member_reminder_mail', $params); + // dd($mail_result); // $this->myLogger->logme('error', 'Mail sent result: ' . json_encode($mail_result)); - $reminder_whole_mail[] = $mail_result; + $reminder_whole_mail[] = $mail_result[0]; } } } else { @@ -483,7 +484,7 @@ class DashboardController extends AdminController // Send the mail notification $mail_result = sendMailNotification::sendMailNotification('member_reminder_mail', $params); // $this->myLogger->logme('error', 'Mail sent result: ' . json_encode($mail_result)); - $reminder_whole_mail[] = $mail_result; + $reminder_whole_mail[] = $mail_result[0]; } } } else { @@ -496,14 +497,14 @@ class DashboardController extends AdminController } // dd($reminder_whole_mail); + // print_rr($reminder_whole_mail); die; // Process and queue bulk emails if (!empty($reminder_whole_mail) && count($reminder_whole_mail) > 0) { $reminder_whole_mail = array_chunk($reminder_whole_mail, 20); - foreach ($reminder_whole_mail as $key => $value) { - $job_details = new Jobs(); + // $job_details = new Jobs(); $r = Jobs::addJob(['job_name' => 'bulk_mail', 'payload' => $value]); } } @@ -517,6 +518,8 @@ class DashboardController extends AdminController public function sendManualReminder($client_id, $client_branch_id) { + $this->myLogger->logme('error','Log Works'); + $this->myLogger->logme('error', "sendManualRemainder called with client_id: {$client_id}, client_branch_id: {$client_branch_id}"); $client_policy_data = $this->clientPolicyModel->getPolicyDetailsForRemainder($client_id, $client_branch_id); @@ -526,6 +529,8 @@ class DashboardController extends AdminController if ($client_policy_data) { $result = $this->sendRemainderMail($client_policy_data); + log_message('error',json_encode($result)); + $this->myLogger->logme('error',$result); $this->myLogger->logme('error', "Manual Remainder Mail sending result: " . ($result ? 'success' : 'failure')); if ($result) { @@ -552,6 +557,7 @@ class DashboardController extends AdminController { return $this->respond(['status' => false, 'code' => 400, 'message' => 'No template found','message2' => 'Failed' ], 200); } + $emp_data = $this->employeePolicyModel->getEmployeePolicyForEcard($policy_id); if(count($emp_data) == 0) diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index 02c01d34..75893afd 100755 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -108,7 +108,7 @@ class EmployeeController extends AdminController emp_name : $filterData['emp_name'] ?? null, status : $filterData['status'] ?? [], ); - + log_message('error',json_encode($data['employees'])); // Set getData in $data array with the processed $filterData $data['getData'] = $filterData; } diff --git a/app/Controllers/EmployeeServiceController.php b/app/Controllers/EmployeeServiceController.php index 7297c26c..953d270b 100755 --- a/app/Controllers/EmployeeServiceController.php +++ b/app/Controllers/EmployeeServiceController.php @@ -2095,7 +2095,7 @@ public function getFileMetaDataByFileId($file_id, $status = 'success'){ $params['dataToInsert'] = $value; //holds employee master data $params['notification'] = $notification; $params['client_data'] = $client_details; - + $params['common'] = []; //store email and mail content via helper to send notification $emp_emails[] = sendMailNotification::sendMailNotification('member_welcome_mail', $params); } diff --git a/app/Helpers/GmailResponseHandler.php b/app/Helpers/GmailResponseHandler.php index 27347b94..f2cb07f7 100644 --- a/app/Helpers/GmailResponseHandler.php +++ b/app/Helpers/GmailResponseHandler.php @@ -2,10 +2,19 @@ namespace App\Helpers; +use App\Models\EmployeePolicyModel; use App\Models\GmailSentHistoryModel; use Exception; + class GmailResponseHandler{ + private $myLogger; + + public function __construct() + { + $this->myLogger = \Config\Services::mylogger(); + + } public function receive_and_distribute_param_to_functions($params) @@ -14,6 +23,7 @@ class GmailResponseHandler{ $this->store_gmail_response_data($params); $this->gmail_response_logger($params); + $this->client_id_flag_setter($params); } catch(Exception $e) @@ -81,13 +91,34 @@ class GmailResponseHandler{ } $gmailModel = new GmailSentHistoryModel(); - $save_status = $gmailModel->insert($data); - - + $save_status = $gmailModel->insert($data); } - public function gmail_response_logger($params){ + public function gmail_response_logger($params) + { + $this->myLogger->logme('error',json_encode($params)); + } + public function client_id_flag_setter($params) + { + try{ + if (isset($params['params']['common']['mail_type'])){ + if($params['params']['common']['mail_type'] == 'member_ecard_mail'){ + $employeePolicyModel = new EmployeePolicyModel(); + $update_status = $employeePolicyModel->where('id',$params['params']['common']['employee_policy_id'])->set('ecard_sent_status',1)->update(); + if($update_status){ + $this->myLogger->logme('error',"ecard_sent_status updated for ".$params['params']['common']['employee_policy_id']); + }else{ + $this->myLogger->logme('error','ecard_sent_status failed to update'); + } + } + + } + } + catch(Exception $e){ + $error = $e->getMessage(); + $this->myLogger->logme('error','An Error Occured - '.$error); + } } diff --git a/app/Helpers/MailHelper.php b/app/Helpers/MailHelper.php index 78f5983b..6116bc0c 100755 --- a/app/Helpers/MailHelper.php +++ b/app/Helpers/MailHelper.php @@ -126,14 +126,14 @@ class MailHelper if($res['gmail_api']['status']) { $response = $res; - // $MailDataHelper->receive_and_distribute_param_to_functions($response); + $MailDataHelper->receive_and_distribute_param_to_functions($response); return json_encode(['status' => 'success','code' => 200, 'message'=>('Email Sent Successfully...'.$emaill),'data' => $res,],200); } else { $myLogger->logme('error', "mail sent failed - $emaill"); $response = $res; - // $MailDataHelper->receive_and_distribute_param_to_functions($response); + $MailDataHelper->receive_and_distribute_param_to_functions($response); return json_encode(['status' => 'failed','code' => 404,'message'=>( 'Email Sent Failed...' . $emaill ),'data' => $res ],404); } @@ -142,7 +142,7 @@ class MailHelper $msg['params'] = $params; $myLogger->logme('error', "mail sent failed - $msg"); $response = $msg; - // $MailDataHelper->receive_and_distribute_param_to_functions($response); + $MailDataHelper->receive_and_distribute_param_to_functions($response); return json_encode(['status' => 'failed','code' => 500,'data' => $msg],500); } @@ -152,7 +152,7 @@ class MailHelper public static function bulk_mail(array $mails = []) { - // print_r();die; + // print_r($mails);die; $model = new JobModel(); $start = microtime(true); $runtime= 0; @@ -165,7 +165,9 @@ class MailHelper return json_encode(['status' => 'success','code' => 200, 'message'=>'Email Sent Successfully...'],200); } catch (\Throwable $th) { - return json_encode(['status' => 'failed','code' => 500],500); + $error = $th->getMessage(); + log_message('error',$error); + return json_encode(['status' => 'failed','code' => 500,'error'=>$error],500); } } diff --git a/app/Models/EmployeePolicyModel.php b/app/Models/EmployeePolicyModel.php index 2d285bb6..6708da05 100755 --- a/app/Models/EmployeePolicyModel.php +++ b/app/Models/EmployeePolicyModel.php @@ -33,6 +33,7 @@ class EmployeePolicyModel extends Model "rand_string", "is_active", "claim_status", + 'ecard_sent_status' ]; // Callbacks @@ -125,7 +126,6 @@ class EmployeePolicyModel extends Model ->join('client_branch', 'emp.client_branch_id = client_branch.id') //cm - client master ->orderBy('emp.emp_code', 'ASC') ->orderBy('employee_polices.employee_id', 'ASC'); - // Conditionally add where clauses if ($client_id != 0 && !empty($client_id)) { $result->where('emp.client_id', $client_id); @@ -194,6 +194,7 @@ class EmployeePolicyModel extends Model $result->where('employee_polices.is_active', 1) ->where('employee_polices.status', 'active') ->where('employee_polices.tpa_id is not null') + ->where('employee_polices.ecard_sent_status',0) ->where('emp.relationship','Self'); return $result->findAll(); From 8a319604f7e23d6f72257e9ca89b52ffda8ded90 Mon Sep 17 00:00:00 2001 From: velz Date: Mon, 9 Dec 2024 09:15:04 +0530 Subject: [PATCH 12/12] FIX_DATE_FORMAT_NEW_FUNC --- app/Controllers/EmployeeServiceController.php | 4 +- app/Helpers/excel_util_helper.php | 29 ++++--- app/Helpers/utility_helper.php | 87 ++++++++++++++++++- 3 files changed, 106 insertions(+), 14 deletions(-) diff --git a/app/Controllers/EmployeeServiceController.php b/app/Controllers/EmployeeServiceController.php index 7297c26c..b743247d 100755 --- a/app/Controllers/EmployeeServiceController.php +++ b/app/Controllers/EmployeeServiceController.php @@ -1980,7 +1980,9 @@ public function getFileMetaDataByFileId($file_id, $status = 'success'){ $policy_details = $this->clientPolicyModel->where('id', $file['policy_id'])->first(); // dd($policy_details); - + + //get policy slab rates + $slab_details = $this->policiesModel->getPolicySlabRatesForEmpOnboard($file['policy_id'],$file['client_id']); foreach ($excel_data as $key => $row) { $is_row_empty = check_row_is_empty_or_null($row); diff --git a/app/Helpers/excel_util_helper.php b/app/Helpers/excel_util_helper.php index 9a27ab9b..76cf51a3 100755 --- a/app/Helpers/excel_util_helper.php +++ b/app/Helpers/excel_util_helper.php @@ -1209,7 +1209,7 @@ if (!function_exists('premium_calculation_manager')) $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; foreach ($temp_slab_rates as $skey => $slab_value) { - if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) + if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null || $slab_value['premium_type'] == 3 ) )) { $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); @@ -1232,7 +1232,7 @@ if (!function_exists('premium_calculation_manager')) foreach ($temp_slab_rates as $skey => $slab_value) { $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; - if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) + if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null || $slab_value['premium_type'] == 3) )) { // dd($slab_value); $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; @@ -1253,7 +1253,7 @@ if (!function_exists('premium_calculation_manager')) foreach ($temp_slab_rates as $skey => $slab_value) { $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; - if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) + if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null || $slab_value['premium_type'] == 3 ) )) { $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); @@ -1273,7 +1273,7 @@ if (!function_exists('premium_calculation_manager')) foreach ($temp_slab_rates as $skey => $slab_value) { $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; - if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) + if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null || $slab_value['premium_type'] == 3) )) { // echo $emp_data['name']; $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; @@ -1295,7 +1295,7 @@ if (!function_exists('premium_calculation_manager')) foreach ($temp_slab_rates as $skey => $slab_value) { $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; - if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) + if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null || $slab_value['premium_type'] == 3) )) { $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); @@ -1317,7 +1317,7 @@ if (!function_exists('premium_calculation_manager')) foreach ($temp_slab_rates as $skey => $slab_value) { - if($slab_value['grade'] == $employee_received_band && $slab_value['unit'] == $emp_data['unit'] && $slab_value['si'] == $employee_received_si && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) + if($slab_value['grade'] == $employee_received_band && $slab_value['unit'] == $emp_data['unit'] && $slab_value['si'] == $employee_received_si && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null || $slab_value['premium_type'] == 3) )) { // $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; @@ -1339,7 +1339,7 @@ if (!function_exists('premium_calculation_manager')) foreach ($temp_slab_rates as $skey => $slab_value) { - if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] )) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) + if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] )) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null || $slab_value['premium_type'] == 3) )) { $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); @@ -1366,7 +1366,7 @@ if (!function_exists('premium_calculation_manager')) if( $slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $max_age && $slab_value['age_to'] >= $max_age) && (($slab_value['premium_type'] == 1 && - ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] )) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) ) ) + ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] )) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null || $slab_value['premium_type'] == 3) ) ) { $emp_data['policy_details']['basic_cover_si'] = $employee_received_si; $emp_data['policy_details']['date_coverage'] = isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']; @@ -1391,7 +1391,7 @@ if (!function_exists('premium_calculation_manager')) { if($slab_value['si'] == $employee_received_si && $slab_value['grade'] == $employee_received_band && $slab_value['unit'] == $emp_data['unit'] && (($slab_value['premium_type'] == 1 && - ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] )) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) + ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] )) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null || $slab_value['premium_type'] == 3) )) { //calculate premium based on count // echo $emp_data['name']; @@ -1420,7 +1420,7 @@ if (!function_exists('premium_calculation_manager')) $emp_data['policy_details']['basic_cover_si'] = null; foreach ($temp_slab_rates as $skey => $slab_value) { - if( $slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ((($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) && $slab_value['relationship'] == $employee_relationship) || ($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) )) ) + if( $slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ((($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null || $slab_value['premium_type'] == 3) && $slab_value['relationship'] == $employee_relationship) || ($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) )) ) { $emp_data['policy_details']['basic_cover_si'] = $employee_received_si; @@ -1445,7 +1445,7 @@ if (!function_exists('premium_calculation_manager')) $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; foreach ($temp_slab_rates as $skey => $slab_value) { - if( $slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && ((($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) && $slab_value['relationship'] == $employee_relationship) || ($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) )) ) + if( $slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && ((($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null || $slab_value['premium_type'] == 3) && $slab_value['relationship'] == $employee_relationship) || ($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) )) ) { $emp_data['policy_details']['basic_cover_si'] = $employee_received_si; @@ -1466,6 +1466,13 @@ if (!function_exists('premium_calculation_manager')) default: $myLogger->logme('error',($emp_data['emp_code'].'-'.$emp_data['name'].' - grid type not found')); } + + //this if condition for premium calculated & premium type 3 (familiy floater but premium calculated every individual implemented later) then remove si amount only for dependents (not self) + if($is_match_found && strtolower($emp_data['relationship']) != 'self' && $temp_slab_rates[0]['premium_type'] == 3) + { + //set dependent si to 0 + $emp_data['policy_details']['basic_cover_si'] = 0; + } if(!$is_match_found) { $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; diff --git a/app/Helpers/utility_helper.php b/app/Helpers/utility_helper.php index fe345717..ca339500 100755 --- a/app/Helpers/utility_helper.php +++ b/app/Helpers/utility_helper.php @@ -24,9 +24,9 @@ if (!function_exists('generate_uuid')) { } } -if (!function_exists('change_date_format')) { +if (!function_exists('change_date_format2')) { - function change_date_format($data, $source_format, $output_format) + function change_date_format2($data, $source_format, $output_format) { $data = trim($data); // echo $data, $source_format, $output_format;return true; @@ -501,3 +501,86 @@ if (!function_exists('isJsonString')) { return (json_last_error() === JSON_ERROR_NONE); // Check if the last JSON error is "no error" } } + +if (!function_exists('isValidDate')) { + function isValidDate($date, $format) { + $parsed_date = DateTime::createFromFormat($format, $date); + return $parsed_date && $parsed_date->format($format) === $date; + } +} + + +if (!function_exists('change_date_format')) +{ + + function change_date_format($date_str, $source_format = null, $output_format = 'Y-m-d') { + + $date_str = trim($date_str); + // Allowed date formats + $allowed_formats = [ + // Day Month Year (clear unambiguous formats) + 'd M Y', // 01 Dec 2024 + 'd-M-Y', // 01-Dec-2024 + 'd/M/Y', // 01/Dec/2024 + 'd.M.Y', // 01.Dec.2024 + 'd,M,Y', // 01,Dec,2024 + + // Month Day Year (clear unambiguous formats) + 'M d Y', // Dec 01 2024 + 'M-d-Y', // Dec-01-2024 + 'M/d/Y', // Dec/01/2024 + 'M.d.Y', // Dec.01.2024 + 'M,d,Y', // Dec,01,2024 + + // Year Month Day (clear unambiguous formats) + 'Y M d', // 2024 Dec 01 + 'Y-M-d', // 2024-Dec-01 + 'Y/M/d', // 2024/Dec/01 + 'Y.M.d', // 2024.Dec.01 + 'Y,M,d', // 2024,Dec,01 + + // Year Numeric Month Numeric Day + 'Y-m-d', // 2024-12-01 + 'Y/m/d', // 2024/12/01 + 'Y.m.d', // 2024.12.01 + 'Y,m,d', // 2024,12,01 + ]; + + try { + // Case 1: Source and Output formats are provided + if ($source_format !== null && $output_format !== null) { + $date = DateTime::createFromFormat($source_format, $date_str); + if (!$date) { + throw new Exception("Invalid date string for source format: $source_format"); + } + return $date->format($output_format); + } + + // Case 2: Source format is provided, Output format is null + if ($source_format !== null && $output_format === null) { + $date = DateTime::createFromFormat($source_format, $date_str); + if (!$date) { + throw new Exception("Invalid date string for source format: $source_format"); + } + return $date->format('Y-m-d'); // MySQL default format + } + + // Case 3: Source format is null, auto-detect format + if ($source_format === null) { + foreach ($allowed_formats as $format) { + if (isValidDate($date_str, $format)) { + $date = DateTime::createFromFormat($format, $date_str); + return $date->format($output_format); // Default is MySQL format + } + } + // If no format matches, throw an exception + $allowed_placeholders = implode(', ', $allowed_formats); + throw new Exception("Invalid date string format. Allowed formats: $allowed_placeholders"); + } + } catch (Exception $e) { + return "Error: " . $e->getMessage(); + } + + return null; + } +}