diff --git a/app/Config/Feature.php b/app/Config/Feature.php index 0bc45c6..af76291 100755 --- a/app/Config/Feature.php +++ b/app/Config/Feature.php @@ -21,7 +21,7 @@ class Feature extends BaseConfig * - property $filtersInfo, instead of $filterInfo * - CodeIgniter\Router\RouteCollection::getFiltersForRoute(), instead of getFilterForRoute() */ - public bool $multipleFilters = false; + public bool $multipleFilters = true; /** * Use improved new auto routing instead of the default legacy version. diff --git a/app/Config/Filters.php b/app/Config/Filters.php index 0909c51..76924a2 100755 --- a/app/Config/Filters.php +++ b/app/Config/Filters.php @@ -39,6 +39,7 @@ class Filters extends BaseConfig 'CloseDbConnection' => CloseDbConnection::class, 'Cors' => Cors::class, 'appSignature' => VerifyAppSignature::class, + ]; /** diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 7cdb968..eaf7741 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -439,45 +439,21 @@ $routes->cli('cli/check_bounce_mail_cli', 'MasterController::testCheckBounceMail $routes->cli('cli/app_check_list', 'MasterController::appCheckList'); $routes->cli('cli/new_gdrive_token', 'GoogleDriveController::generateNewGoogleDriveAccessToken'); -//Employee login api's -$routes->post("/employeeRest/verifyEmployeeNumber", "RestAuthenticationController::verifyEmployeeWithMobileNumber"); -$routes->post("/employeeRest/getVerifiedUserData", "RestAuthenticationController::getVerifiedUserData"); -$routes->post("/employeeRest/verifyEmployeeEmailId", "RestAuthenticationController::verifyEmployeeWithEmailId"); -// $routes->post("/employeeRest/saveMpin", "RestAuthenticationController::saveMpin"); -//HR login api's -$routes->post("/employeeRest/verifyHrWithMobileNumber", "RestAuthenticationController::verifyHrWithMobileNumber"); -$routes->post("/employeeRest/verifyHrWithEmail", "RestAuthenticationController::verifyHrWithEmail"); -$routes->post("/employeeRest/getVerifiedHrData", "RestAuthenticationController::getVerifiedHrData"); - $routes->group("/api", ["filter" => "authJWT"], function ($routes) { $routes->post("logined", "RestAuthenticationController::logined"); $routes->post("getId", "RestAuthenticationController::getUserIdFromToken"); }); -// MPIN api's -$routes->post("employeeRest/saveMpin", "RestAuthenticationController::saveMpin"); -$routes->post("employeeRest/updateMpin", "RestAuthenticationController::updateMpin"); -$routes->post("/employeeRest/verifyMpin", "RestAuthenticationController::verifyMpin"); -$routes->post("/employeeRest/checkMpin", "RestAuthenticationController::checkMpin"); -$routes->post("employeeRest/forgotMPIN", "RestAuthenticationController::forgotMPIN"); -$routes->post("employeeRest/updateMobileNumber", "RestAuthenticationController::updateMobileNumber"); -// PASSWORD api's -$routes->post("employeeRest/savePassword", "RestAuthenticationController::savePassword"); -$routes->post("employeeRest/changePassword", "RestAuthenticationController::changePassword"); -$routes->post("employeeRest/verifyPassword", "RestAuthenticationController::verifyPassword"); -$routes->post("employeeRest/verifyOtp", "RestAuthenticationController::verifyOtp"); -$routes->post("employeeRest/checkPassword", "RestAuthenticationController::checkPassword"); -$routes->get("employeeRest/downloadSampleExcel", "EmployeeRestController::downloadSampleExcel"); // $routes->post("employeeRest/createOrUpdateEmployeePolicySiAmount", "EmployeeRestController::createOrUpdateEmployeePolicySiAmount"); // $routes->post("employeeRest/calculatePremium", "EmployeeRestController::calculatePremium"); -$routes->group("employeeRest", ["filter" => "authJWT"], function ($routes) { +$routes->group("employeeRest", ['filter' => ['appSignature' , 'authJWT'] ], function ($routes) { // $routes->post("getVerifiedUserData", "RestAuthenticationController::getVerifiedUserData"); @@ -523,6 +499,41 @@ $routes->group("employeeRest", ["filter" => "authJWT"], function ($routes) { $routes->get("hrFileDownload", "EmployeeRestController::hrFileDownload"); $routes->post("hrFileUpload", "EmployeeRestController::hrFileUpload"); + $routes->get("copyActiveEmployeeAndDependentDetails", "EmployeeRestController::copyActiveEmployeeAndDependentDetails"); + +}); + +$routes->group("employeeRest", ['filter' => ['appSignature'] ], function ($routes) { + + //Employee login api's + $routes->post("verifyEmployeeNumber", "RestAuthenticationController::verifyEmployeeWithMobileNumber"); + $routes->post("getVerifiedUserData", "RestAuthenticationController::getVerifiedUserData"); + $routes->post("verifyEmployeeEmailId", "RestAuthenticationController::verifyEmployeeWithEmailId"); + // $routes->post("saveMpin", "RestAuthenticationController::saveMpin"); + + + //HR login api's + $routes->post("verifyHrWithMobileNumber", "RestAuthenticationController::verifyHrWithMobileNumber"); + $routes->post("verifyHrWithEmail", "RestAuthenticationController::verifyHrWithEmail"); + $routes->post("getVerifiedHrData", "RestAuthenticationController::getVerifiedHrData"); + + // MPIN api's + $routes->post("saveMpin", "RestAuthenticationController::saveMpin"); + $routes->post("updateMpin", "RestAuthenticationController::updateMpin"); + $routes->post("verifyMpin", "RestAuthenticationController::verifyMpin"); + $routes->post("checkMpin", "RestAuthenticationController::checkMpin"); + $routes->post("forgotMPIN", "RestAuthenticationController::forgotMPIN"); + $routes->post("updateMobileNumber", "RestAuthenticationController::updateMobileNumber"); + + // PASSWORD api's + $routes->post("savePassword", "RestAuthenticationController::savePassword"); + $routes->post("changePassword", "RestAuthenticationController::changePassword"); + $routes->post("verifyPassword", "RestAuthenticationController::verifyPassword"); + $routes->post("verifyOtp", "RestAuthenticationController::verifyOtp"); + $routes->post("checkPassword", "RestAuthenticationController::checkPassword"); + $routes->get("downloadSampleExcel", "EmployeeRestController::downloadSampleExcel"); + + }); $routes->get("getEmployeeActiveOrInactivePolicy", "EmployeeRestController::getEmployeeActiveOrInactivePolicy"); @@ -538,7 +549,7 @@ $routes->cli("cli/sendCroneRemainderMail", "DashboardController::sendCroneRemain $routes->get('enrollOpendAndClose', 'DashboardController::updatePolicyEnrollmentStatus'); $routes->get("sendCroneRemainderMail", "DashboardController::sendCroneRemainderMail"); -$routes->get("getEmployeePolicy", "EmployeeRestController::getEmployeePolicy"); +// $routes->get("getEmployeePolicy", "EmployeeRestController::getEmployeePolicy"); $routes->get("getAddOnPolicy", "EmployeeRestController::getAddOnPolicy"); $routes->post("addEmployeeAndDependence", "EmployeeRestController::addEmployeeAndDependence"); $routes->post("getPreEmployeePolicyCount", "EmployeeRestController::getPreEmployeePolicyCount"); diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 0a478b4..7946fc4 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -526,16 +526,22 @@ class EmployeeRestController extends AdminController try { if($this->request->getGet('id')) - { - $this->employeeModel->where('id', $this->request->getGet('id') ) - ->where('is_active', 1 ) - ->set(array('is_active'=> 0 )) - ->update(); + { + $is_from_copy = $this->request->getGet('is_from_copy') ?? null; + + if($is_from_copy == false && $is_from_copy == null){ + + $this->employeeModel->where('id', $this->request->getGet('id') ) + ->where('is_active', 1 ) + ->set(array('is_active'=> 0 )) + ->update(); + } $this->employeePolicyModel->where('employee_id',$this->request->getGet('id') ) ->where('is_active', 1 ) ->set(array('is_active'=> 0 )) ->update(); + return $this->respond(['status' => 'success','code' => 200,'data' =>[] ], 200); }else{ @@ -1160,13 +1166,25 @@ class EmployeeRestController extends AdminController if ($empPolicy) { - + + $latest_gmc_policy_id = getLatestGMCPolicy((array)$empPolicy); $result = []; foreach ($empPolicy as $array) { - // Reset employee array - $empData = $employeeData; - + // Reset employee array + // $empData = $employeeData; + $empData = $this->employeeModel + ->select('employees.*') + ->join('employee_polices', 'employee_polices.employee_id = employees.id') + ->where('employees.emp_code',$emp_code) + ->where('employees.client_id',$client_id) + ->where('employees.client_branch_id',$client_branch_id) + ->where('employee_polices.client_policy_id',$array->ClientPolicyId) + ->where('employees.is_active', 1 ) + ->where('employee_polices.is_active', 1 ) + ->where('employees.is_addon_value',0) + ->findAll(); + // Removes specific keys from the decoded array and assigns the result to $refusingData $decodedArray = json_decode($array->Policy_Terms); $refusingData = (object) array_diff_key((array) $decodedArray, array_flip($keysToRemove)); @@ -1248,6 +1266,11 @@ class EmployeeRestController extends AdminController $array->to_be_added_relationship = []; $array->existing_relationship = []; + if(!empty($latest_gmc_policy_id) && $latest_gmc_policy_id == $array->ClientPolicyId){ + $array->copy_dependence_data_enable = true; + }else{ + $array->copy_dependence_data_enable = false; + } // Map family floaters that already exist in the employee table $familyFloates = $array->Policy_Terms->family_floaters; @@ -1437,12 +1460,14 @@ class EmployeeRestController extends AdminController if($checkGmcParentsPolicyExist) { $GmcParrentsData = $this->getGmcParrentsPolicy($checkGmcParentsPolicyExist,$emp_code,$client_id,$client_branch_id); - return $this->respond(['status' => 'success','code' => 200,'data' => [$array,$GmcParrentsData]], 200); - + // return $this->respond(['status' => 'success','code' => 200,'data' => [$array,$GmcParrentsData]], 200); + $result[] = $array; + $result[] = $GmcParrentsData; } - if($this->request->getGet('policy') == 'GMC'){ - return $this->respond(['status' => 'success','code' => 200,'data' => [$array]], 200); + if($this->request->getGet('policy') == 'GMC' && !$checkGmcParentsPolicyExist){ + // return $this->respond(['status' => 'success','code' => 200,'data' => [$array]], 200); + $result[] = $array; } } @@ -1450,14 +1475,31 @@ class EmployeeRestController extends AdminController // $result[] = $array; } - return $this->respond(['status' => 'success','code' => 200,'data' => []], 200); + if(!empty($result) && $this->request->getGet('policy') == 'GMC'){ + return $this->respond(['status' => 'success','code' => 200,'data' => $result], 200); + }else{ + return $this->respond(['status' => 'success','code' => 200,'data' => []], 200); + } }else{ return $this->respond(['status' => 'failed','code' => 404,'data' => []], 200); } + } catch (\Exception $e) { - return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getLine()], 500); + + $errorData = [ + 'message' => $e->getMessage(), + 'file' => $e->getFile(), + 'line' => $e->getLine(), + 'code' => $e->getCode(), + 'trace' => $e->getTraceAsString(), + 'trace_array' => $e->getTrace(), // full array version (optional) + 'function' => $e->getTrace()[0]['function'] ?? null, + 'class' => $e->getTrace()[0]['class'] ?? null, + ]; + + return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getLine(), 'error_data' => $errorData], 500); } } @@ -2229,34 +2271,34 @@ class EmployeeRestController extends AdminController } - $array['relationship'] = []; + $responce['relationship'] = []; foreach ($array['to_be_added_relationship'] as $key => $value) { if($value['relationship'] == 'Spouse'){ - array_push($array['relationship'],['relationship' => 'Spouse','age_validation' => $value['age_validation'],'client_policy_id'=>$array['id']]); + array_push($responce['relationship'],['relationship' => 'Spouse','age_validation' => $value['age_validation'],'client_policy_id'=>$array['id']]); }else if($value['relationship'] == 'Child'){ - array_push($array['relationship'], ['relationship' => 'Son','age_validation' => $value['age_validation'],'client_policy_id'=>$array['id']]); - array_push($array['relationship'], ['relationship' => 'Daughter','age_validation' => $value['age_validation'],'client_policy_id'=>$array['id']]); + array_push($responce['relationship'], ['relationship' => 'Son','age_validation' => $value['age_validation'],'client_policy_id'=>$array['id']]); + array_push($responce['relationship'], ['relationship' => 'Daughter','age_validation' => $value['age_validation'],'client_policy_id'=>$array['id']]); }else if($value['relationship'] == 'Parent'){ $Father = array_search('Father',$array['existing_relationship']); $Mother = array_search('Mother',$array['existing_relationship']); if ($Father === false && $Mother === false) { - array_push($array['relationship'], ['relationship' => 'Father','age_validation' => $value['age_validation'],'client_policy_id'=>$array['id']]); - array_push($array['relationship'], ['relationship' => 'Mother','age_validation' => $value['age_validation'],'client_policy_id'=>$array['id']]); + array_push($responce['relationship'], ['relationship' => 'Father','age_validation' => $value['age_validation'],'client_policy_id'=>$array['id']]); + array_push($responce['relationship'], ['relationship' => 'Mother','age_validation' => $value['age_validation'],'client_policy_id'=>$array['id']]); }else if ($Father !== false && $Mother === false) { - array_push($array['relationship'], ['relationship' => 'Mother','age_validation' => $value['age_validation'],'client_policy_id'=>$array['id']]); + array_push($responce['relationship'], ['relationship' => 'Mother','age_validation' => $value['age_validation'],'client_policy_id'=>$array['id']]); } else if ($Mother !== false && $Father === false) { - array_push($array['relationship'], ['relationship' => 'Father','age_validation' => $value['age_validation'],'client_policy_id'=>$array['id']]); + array_push($responce['relationship'], ['relationship' => 'Father','age_validation' => $value['age_validation'],'client_policy_id'=>$array['id']]); } }else if($value['relationship'] == 'Parent in law'){ $FatherinLaw = array_search('Father in Law',$array['existing_relationship']); $MotherinLaw = array_search('Mother in Law',$array['existing_relationship']); if ($FatherinLaw === false && $MotherinLaw === false) { - array_push($array['relationship'], ['relationship' => 'Father in Law','age_validation' => $value['age_validation'],'client_policy_id'=>$array['id']]); - array_push($array['relationship'], ['relationship' => 'Mother in Law','age_validation' => $value['age_validation'],'client_policy_id'=>$array['id']]); + array_push($responce['relationship'], ['relationship' => 'Father in Law','age_validation' => $value['age_validation'],'client_policy_id'=>$array['id']]); + array_push($responce['relationship'], ['relationship' => 'Mother in Law','age_validation' => $value['age_validation'],'client_policy_id'=>$array['id']]); }else if ($FatherinLaw !== false && $MotherinLaw === false) { - array_push($array['relationship'], ['relationship' => 'Mother in Law','age_validation' => $value['age_validation'],'client_policy_id'=>$array['id']]); + array_push($responce['relationship'], ['relationship' => 'Mother in Law','age_validation' => $value['age_validation'],'client_policy_id'=>$array['id']]); } else if ($MotherinLaw !== false && $FatherinLaw === false) { - array_push($array['relationship'], ['relationship' => 'Father in Law','age_validation' => $value['age_validation'],'client_policy_id'=>$array['id']]); + array_push($responce['relationship'], ['relationship' => 'Father in Law','age_validation' => $value['age_validation'],'client_policy_id'=>$array['id']]); } } } @@ -3670,154 +3712,257 @@ class EmployeeRestController extends AdminController - - //-------------------------------------------------------------------------------------------- - public function hrFileUpload() - { - try { - // Check file - $file = $this->request->getFile('file_name'); - if (!$file) { - return $this->response->setJSON([ - 'status' => false, - 'message' => "Invalid file or file not uploaded.", - 'data' => "No Data" - ]); - } + //-------------------------------------------------------------------------------------------- - // Upload folder path - $uploadPath = WRITEPATH . 'uploads/hr_files/'; - - // If directory not exists, create it - if (!is_dir($uploadPath)) { - mkdir($uploadPath, 0777, true); - } - - // New file name with timestamp - $newFileName = time() . '_' . $file->getRandomName(); - - // Move file - $file->move($uploadPath, $newFileName); - - // Prepare data - $data = [ - 'client_id' => $this->request->getPost('client_id'), - 'client_branch_id' => $this->request->getPost('client_branch_id'), - 'policy_no' => $this->request->getPost('policy_no'), - 'file_name' => $newFileName, - 'file_action' => $this->request->getPost('file_action'), - 'status' => $this->request->getPost('status'), - 'created_by' => $this->request->getPost('created_by'), - 'updated_by' => $this->request->getPost('created_by'), - ]; - - // Save into DB - $this->hrFileUploadModel->insert($data); - - return $this->respondCreated([ - 'status' => true, - 'message' => 'File uploaded successfully', - 'data' => $data + public function hrFileUpload() + { + try { + // Check file + $file = $this->request->getFile('file_name'); + if (!$file) { + return $this->response->setJSON([ + 'status' => false, + 'message' => "Invalid file or file not uploaded.", + 'data' => "No Data" ]); - - } catch (\Exception $e) { - return $this->failServerError($e->getMessage()); } - - } - - public function hrFileDownload($id = null) - { - try { - - $file_id = $this->request->getGet('id') ?? $id; - - // Find record - $record = $this->hrFileUploadModel->find($file_id); - - if (!$record) { - return $this->failNotFound("File record not found"); - } - - $uploadPath = WRITEPATH . 'uploads/hr_files/'; - $filePath = $uploadPath . $record['file_name']; - - if (!file_exists($filePath)) { - return $this->failNotFound("File not found on server"); - } - - // Force file download - return $this->response->download($filePath, null) - ->setFileName($record['file_name']); - } catch (\Exception $e) { - return $this->failServerError($e->getMessage()); + + // Upload folder path + $uploadPath = WRITEPATH . 'uploads/hr_files/'; + + // If directory not exists, create it + if (!is_dir($uploadPath)) { + mkdir($uploadPath, 0777, true); } + + // New file name with timestamp + $newFileName = time() . '_' . $file->getRandomName(); + + // Move file + $file->move($uploadPath, $newFileName); + + // Prepare data + $data = [ + 'client_id' => $this->request->getPost('client_id'), + 'client_branch_id' => $this->request->getPost('client_branch_id'), + 'policy_no' => $this->request->getPost('policy_no'), + 'file_name' => $newFileName, + 'file_action' => $this->request->getPost('file_action'), + 'status' => $this->request->getPost('status'), + 'created_by' => $this->request->getPost('created_by'), + 'updated_by' => $this->request->getPost('created_by'), + ]; + + // Save into DB + $this->hrFileUploadModel->insert($data); + + return $this->respondCreated([ + 'status' => true, + 'message' => 'File uploaded successfully', + 'data' => $data + ]); + + } catch (\Exception $e) { + return $this->failServerError($e->getMessage()); } - - public function hrFileList() - { - try { - $request = service('request'); - $builder = $this->hrFileUploadModel; - - // Allowed filter keys - $filters = [ - 'client_id', - 'client_branch_id', - 'policy_no', - 'file_action', - 'status', - 'created_by' - ]; - - // Apply filters dynamically - foreach ($filters as $key) { - $value = $request->getGetPost($key); // supports both GET and POST - if (!empty($value)) { - $builder->where($key, $value); + + } + + public function hrFileDownload($id = null) + { + try { + + $file_id = $this->request->getGet('id') ?? $id; + + // Find record + $record = $this->hrFileUploadModel->find($file_id); + + if (!$record) { + return $this->failNotFound("File record not found"); + } + + $uploadPath = WRITEPATH . 'uploads/hr_files/'; + $filePath = $uploadPath . $record['file_name']; + + if (!file_exists($filePath)) { + return $this->failNotFound("File not found on server"); + } + + // Force file download + return $this->response->download($filePath, null) + ->setFileName($record['file_name']); + } catch (\Exception $e) { + return $this->failServerError($e->getMessage()); + } + } + + public function hrFileList() + { + try { + $request = service('request'); + $builder = $this->hrFileUploadModel; + + // Allowed filter keys + $filters = [ + 'client_id', + 'client_branch_id', + 'policy_no', + 'file_action', + 'status', + 'created_by' + ]; + + // Apply filters dynamically + foreach ($filters as $key) { + $value = $request->getGetPost($key); // supports both GET and POST + if (!empty($value)) { + $builder->where($key, $value); + } + } + + // Fetch results + $data = $builder->findAll(); + + return $this->respond([ + 'status' => true, + 'message' => 'File list fetched successfully', + 'data' => $data + ]); + } catch (\Exception $e) { + return $this->failServerError($e->getMessage()); + } + } + + public function hrFileUploadMasters() + { + try { + //for inception upload + $data['actions'] = ['inception' => 'Inception (Employee + Dependents)', 'missed_inception' => 'Missed Inception (Employee + Dependents)', 'addition' => 'Addition (Employee + Dependents)', 'dependent_addition' => 'Dependent Addition (Only Dependents)', 'deletion' => 'Deletion', 'correction' => 'Correction', 'si_enhancement' => 'SI Enhancement']; + + return $this->respond([ + 'status' => true, + 'message' => 'File inception upload masters', + 'data' => $data + ]); + } catch (\Exception $e) { + return $this->failServerError($e->getMessage()); + } + } + + public function downloadSampleExcel() + { + $employeeController = new EmployeeController(); + $file_path = $employeeController->downloadSampleExcelFile('enrollment', 1); + if(empty($file_path)){ + return $this->respond(['status' => "success", 'code' => 404, 'data' => "", "message" => "Sample file not avilable"], 200); + }else{ + return $this->respond(['status' => "success", 'code' => 200, 'data' => $file_path], 200); + } + + } + + + // copy the active enrolled employee data + public function copyActiveEmployeeAndDependentDetails() + { + $received_payload = $this->request->getGet(); + $client_id = $received_payload['client_id'] ?? null; + $emp_code = $received_payload['emp_code'] ?? null; + $new_client_policy_id = $received_payload['new_client_policy_id'] ?? null; + + if (empty($client_id)) { + return $this->respond(['status' => "failed", 'code' => 404, 'message' => "client_id is required"], 200); + } + + if (empty($new_client_policy_id)) { + return $this->respond(['status' => "failed", 'code' => 404, 'message' => "client_policy_id is required"], 200); + } + + if (empty($emp_code)) { + return $this->respond(['status' => "failed", 'code' => 404, 'message' => "emp_code is required"], 200); + } + + $client_policy_data = $this->clientPolicyModel + ->where('is_active', 1) + ->where('client_id', $client_id) + ->where('id', $new_client_policy_id) + ->whereIn('policy_type_id', [2, 3, 4, 5]) + ->first(); + + if (empty($client_policy_data)) { + return $this->respond(['status' => "failed", 'code' => 404, 'message' => "Policy data not found", 'data' => []], 200); + } + + $policy_terms = $client_policy_data['policy_terms'] ?? null; + + if (empty($policy_terms)) { + return $this->respond(['status' => "failed", 'code' => 404, 'message' => "Policy terms not found", 'data' => []], 200); + } + + $policy_terms = json_decode($policy_terms, true); + + $family_floaters = $policy_terms['family_floaters']; + + $empData = $this->employeeModel + ->where('emp_code', $emp_code) + ->where('client_id', $client_id) + ->where('emp_status', 'enrolled') + ->where('is_active', 1) + ->findAll(); + + if (empty($empData)) { + return $this->respond(['status' => "failed", 'code' => 404, 'message' => "employee data not found", 'data' => []], 200); + } + + $selfData = array_column( + array_filter($empData, function($row) { + return isset($row['relationship']) && strtolower($row['relationship']) == 'self'; + }), + 'id' + ); + + $selfId = !empty($selfData) ? reset($selfData) : null; + $floters = $this->FloterConvertion($family_floaters); + + $data = []; + foreach ($floters as $familyFloatesValue) { + + $dependent = preg_replace('/\d/', '', $familyFloatesValue); + + if (count($empData)) { + foreach ($empData as $key => $value) { + if ($value['family_floater_key'] === $dependent) { + + $employee_policy = $this->employeePolicyModel->where('employee_id', $selfId)->where('client_policy_id',$new_client_policy_id)->where('is_active', 1 )->get()->getRow(); + + $temp['is_value_exist'] = true; + $temp['data']['family_floater_key'] = $familyFloatesValue; + $temp['data']['employee_id'] = $value['id']; + $temp['data']['relationship'] = $value['relationship']; + $temp['data']['name'] = $value['name']; + $temp['data']['dob'] = $this->convertDateFormatDMY($value['dob']); + $temp['data']['client_policy_id'] = $new_client_policy_id; + $temp['data']['form_type'] = $dependent; + $temp['data']['basic_cover_si'] = isset($employee_policy->basic_cover_si) ? $employee_policy->basic_cover_si : 0; + + + $temp['data']['age_validation'] = $this->getAgeRange($policy_terms, $familyFloatesValue); + + + array_push($data, $temp); + unset($empData[$key]); + $floters = array_diff($floters, [$familyFloatesValue]); + break; } } - - // Fetch results - $data = $builder->findAll(); - - return $this->respond([ - 'status' => true, - 'message' => 'File list fetched successfully', - 'data' => $data - ]); - } catch (\Exception $e) { - return $this->failServerError($e->getMessage()); } } - - public function hrFileUploadMasters() - { - try { - //for inception upload - $data['actions'] = ['inception' => 'Inception (Employee + Dependents)', 'missed_inception' => 'Missed Inception (Employee + Dependents)', 'addition' => 'Addition (Employee + Dependents)', 'dependent_addition' => 'Dependent Addition (Only Dependents)', 'deletion' => 'Deletion', 'correction' => 'Correction', 'si_enhancement' => 'SI Enhancement']; - - return $this->respond([ - 'status' => true, - 'message' => 'File inception upload masters', - 'data' => $data - ]); - } catch (\Exception $e) { - return $this->failServerError($e->getMessage()); - } - } - - public function downloadSampleExcel() - { - $employeeController = new EmployeeController(); - $file_path = $employeeController->downloadSampleExcelFile('enrollment', 1); - if(empty($file_path)){ - return $this->respond(['status' => "success", 'code' => 404, 'data' => "", "message" => "Sample file not avilable"], 200); - }else{ - return $this->respond(['status' => "success", 'code' => 200, 'data' => $file_path], 200); - } - - } + if(!empty($data)){ + return $this->respond(['status' => "success", 'code' => 200, 'data' => $data], 200); + }else{ + return $this->respond(['status' => "failed", 'code' => 404, 'message' => "No data found", 'data' => []], 200); + } + } } \ No newline at end of file diff --git a/app/Controllers/RestAuthenticationController.php b/app/Controllers/RestAuthenticationController.php index 7531d2e..22e834e 100755 --- a/app/Controllers/RestAuthenticationController.php +++ b/app/Controllers/RestAuthenticationController.php @@ -69,7 +69,10 @@ class RestAuthenticationController extends AdminController { $client = \Config\Services::curlrequest(); $url = env('POST_ENROLLMENT_BASEURL').$endPoint; - $response = $client->post( $url, ['json' => $postData, 'http_errors' => false ] ); + $headers = [ + 'App-Signature' => getenv('APP_SIGNATURE'), + ]; + $response = $client->post( $url, ['json' => $postData, 'headers' => $headers , 'http_errors' => false ] ); // return json_decode($response->getBody(), true); return $response->getBody(); } @@ -84,15 +87,17 @@ class RestAuthenticationController extends AdminController $options = [ 'query' => $queryParams, 'http_errors' => false, + 'headers' => [ + 'App-Signature' => getenv('APP_SIGNATURE'), + 'Accept' => 'application/json' + ] ]; - if (isset($params['token']) && !empty($params['token'])) { - $options['headers'] = [ - 'Authorization' => 'Bearer ' . $params['token'], - 'Accept' => 'application/json' - ]; + if (!empty($params['token'])) { + $options['headers']['Authorization'] = 'Bearer ' . $params['token']; } + $response = $client->get($url, $options); return $response->getBody(); @@ -261,26 +266,63 @@ class RestAuthenticationController extends AdminController $empdata = RestAuthHelper::getPreAndPostDataByEmailOrMobile(['email_id' => $email]); // print_r($empdata); die; + $otp = random_int(100000, 999999); + if(empty($empdata)){ $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithEmailId: No employee data found both PRE & POST"); log_message('error', ' '); log_message('error', '************************ PRE END ********************************'); + + $retailUserdata = RestAuthHelper::getRetailUserData(['email_id' => $email]); + // print_r($retailUserdata); die; + + if (!empty($retailUserdata)) { + + $retailApiParams['client_id'] = $retailUserdata['id']; + $retailApiParams['email_id'] = $email; + $retailApiParams['otp'] = $otp; + + // update the otp in retail user + $api_response = $this->callThirdPartyAPI($retailApiParams, 'updateRetailUserAuthDetails'); + $api_response = json_decode($api_response ?? '{}', true) ?? $api_response; + // print_r($api_response); die; + if (isset($api_response['status']) && $api_response['status'] == true) { + + //send Email + $retail_common = [ + 'client_id' => $retailUserdata['id'], + 'client_branch_id' => null, + 'client_policy_id' => null, + 'employee_policy_id' => null, + 'employee_id' => null, + 'mail_type' => 'retail_user_otp_mail', + ]; + + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithEmailId: Sending Retail user OTP email to " . $email); + $res = $this->sendEmailOtp($email, $otp, $retail_common); + + if (json_decode($res)->status == 'success') { + $result = ['user_verification' => true, 'message' => "Verified Successfully"]; + return $this->respond(['status' => 'success', 'code' => 200, 'data' => $result], 200); + } else { + $result = ['user_verification' => false, 'message' => "Mail sending failed , try again"]; + return $this->respond(['status' => 'failed', 'code' => 404, 'data' => $result], 200); + } + } + } + $result = ['user_verification' => false , 'message' => "User not found"]; return $this->respond(['status' => 'failed','code' => 404,'data' => $result],200); } $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithEmailId: employee data both PRE & POST = " . json_encode($empdata)); - - $employeeData = []; if (isset($empdata['pre']) && !empty($empdata['pre'])) { $employeeData = $empdata['pre']; $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithEmailId: Using PRE data"); } - $otp = random_int(100000, 999999); - if (isset($employeeData['employee_id'])) { @@ -318,7 +360,6 @@ class RestAuthenticationController extends AdminController $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithEmailId: Calling callThirdPartyAPI for updateEmpOTP"); } - //send Email $common = [ 'client_id' => $employeeData['client_id'], @@ -329,11 +370,8 @@ class RestAuthenticationController extends AdminController 'mail_type' => 'otp_mail', ]; - $subject = 'Nhance user verification - OTP'; - $mail_content = $otp . ' is your verification code for Nhance.'; - $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithEmailId: Sending OTP email to " . $employeeData['email_corporate']); - $res = MailHelper::send_email(['mail' => $employeeData['email_corporate'], 'subject' => $subject, 'common' => $common, 'message' => $mail_content]); + $res = $this->sendEmailOtp($employeeData['email_corporate'], $otp, $common); $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithEmailId: Mail response = " . $res); if (json_decode($res)->status == 'success') { @@ -347,6 +385,7 @@ class RestAuthenticationController extends AdminController $result = ['user_verification' => false, 'message' => "Mail sending failed , try again"]; return $this->respond(['status' => 'failed', 'code' => 404, 'data' => $result], 200); } + } else { $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithEmailId: OTP update failed in PRE DATABASE"); log_message('error', ' '); @@ -404,8 +443,23 @@ class RestAuthenticationController extends AdminController if(empty($empdata)){ $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - getVerifiedUserData: empdata is empty"); - log_message('error', ' '); - log_message('error', '************************ PRE END ********************************'); + + $retailUserdata = RestAuthHelper::getRetailUserData(['email_id' => $email_id, 'mobile_number' => $mobile_number, 'otp' => $otp]); + // print_r($retailUserdata); die; + + if (!empty($retailUserdata)) { + + $retailApiParams['client_id'] = $retailUserdata['id']; + $retailApiParams['email_id'] = $email_id; + $retailApiParams['mobile_number'] = $mobile_number; + $retailApiParams['otp'] = $otp; + + // Call the third-party API function + $apiResponse = $this->callThirdPartyAPI($retailApiParams, 'getVerifiedRetailUserData'); + // print_r($apiResponse); die; + return $this->respond(['status' => 'failed', 'code' => 200, 'data' => [], 'post_enrollment' => json_decode($apiResponse, true)], 200); + } + return $this->respond(['status' => 'Invalid OTP','code' => 404,'data' => "", 'message' => "Invalid OTP"],200); } @@ -481,6 +535,15 @@ class RestAuthenticationController extends AdminController // employee auth api's end + public function sendEmailOtp($email, $otp, $common) + { + $subject = 'Nhance user verification - OTP'; + $mail_content = $otp . ' is your verification code for Nhance.'; + $response = MailHelper::send_email(['mail' => $email, 'subject' => $subject, 'common' => $common, 'message' => $mail_content]); + + return $response; + } + diff --git a/app/Filters/AuthJWT.php b/app/Filters/AuthJWT.php index 484372a..262a5e5 100755 --- a/app/Filters/AuthJWT.php +++ b/app/Filters/AuthJWT.php @@ -20,7 +20,7 @@ class AuthJWT implements FilterInterface { public function before(RequestInterface $request, $arguments = null) { - $jwt = $request->getHeader('Authorization'); + $jwt = $request->getHeaderLine('Authorization'); if ($jwt) { if (JWTToken::validateJWT($jwt)) { diff --git a/app/Helpers/RestAuthHelper.php b/app/Helpers/RestAuthHelper.php index 1308676..121c9cb 100644 --- a/app/Helpers/RestAuthHelper.php +++ b/app/Helpers/RestAuthHelper.php @@ -346,6 +346,9 @@ class RestAuthHelper $client = \Config\Services::curlrequest(); $endPoint = 'getPostEmployeeDataForAuth'; $url = env('POST_ENROLLMENT_BASEURL') . $endPoint; + $headers = [ + 'App-Signature' => getenv('APP_SIGNATURE'), + ]; $postData = []; @@ -368,7 +371,7 @@ class RestAuthHelper log_message('error', 'Sending POST to external API: ' . $url); log_message('error', 'POST payload: ' . json_encode($postData)); - $response = $client->post($url, ['json' => $postData, 'http_errors' => false]); + $response = $client->post($url, ['json' => $postData, 'headers' => $headers , 'http_errors' => false]); $post_json = $response->getBody(); // log_message('error', 'Response from API: ' . $post_json); @@ -380,7 +383,7 @@ class RestAuthHelper return $data; } - log_message('warning', 'No mobile or email present in params for post fetch.'); + log_message('error', 'No mobile or email present in params for post fetch.'); } public static function updatePreMpin(array $params) @@ -437,4 +440,60 @@ class RestAuthHelper log_message('warning', '[updatePostMpin] Missing required parameters: employee_id or mpin'); return false; } + + // ---------------------------------------------------------------------------------------------- + + public static function getRetailUserData(array $params) + { + log_message('error', 'Function getRetailUserData called with: ' . json_encode($params)); + + $mobile_number = $params['mobile_number'] ?? null; + $email_id = $params['email_id'] ?? null; + $otp = $params['otp'] ?? null; + $old_mpin = $params['old_mpin'] ?? null; + + if (!empty($mobile_number) || !empty($email_id)) { + + $client = \Config\Services::curlrequest(); + $endPoint = 'getRetailUserData'; + $url = env('POST_ENROLLMENT_BASEURL') . $endPoint; + $headers = [ + 'App-Signature' => getenv('APP_SIGNATURE'), + ]; + + $postData = []; + + if (!empty($mobile_number)) { + $postData['mobile_number'] = $mobile_number; + } + + if (!empty($email_id)) { + $postData['email_id'] = $email_id; + } + + if (!empty($otp)) { + $postData['otp'] = $otp; + } + + if (!empty($old_mpin)) { + $postData['old_mpin'] = $old_mpin; + } + + log_message('error', 'Sending POST to external API: ' . $url); + log_message('error', 'POST payload: ' . json_encode($postData)); + + $response = $client->post($url, ['json' => $postData, 'headers' => $headers, 'http_errors' => false]); + + $post_json = $response->getBody(); + // print_r($post_json); + + $post_data = json_decode($post_json, true); + + $data = $post_data['data'] ?? []; + log_message('error', 'Parsed post_data: ' . json_encode($data)); + return $data; + } + + return []; + } } diff --git a/app/Helpers/utility_helper.php b/app/Helpers/utility_helper.php index 3372200..765b8af 100755 --- a/app/Helpers/utility_helper.php +++ b/app/Helpers/utility_helper.php @@ -666,3 +666,35 @@ if (!function_exists('check_pay_by_employee_or_company')) { } +if (!function_exists('getLatestGMCPolicy')) { + + function getLatestGMCPolicy(array $empPolicy) + { + try{ + $filtered = array_filter($empPolicy, function ($row) { + $type = is_object($row) ? $row->policy_type_id : $row['policy_type_id']; + return isset($type) && (int)$type === 2; + }); + + if (count($filtered) > 1) { + + usort($filtered, function ($a, $b) { + $dateA = is_object($a) ? $a->policy_end_date : $a['policy_end_date']; + $dateB = is_object($b) ? $b->policy_end_date : $b['policy_end_date']; + return strtotime($dateB) <=> strtotime($dateA); + }); + + $row = reset($filtered); + return is_object($row) ? ($row->ClientPolicyId ?? null) : ($row['ClientPolicyId'] ?? null); + } + + return null; + + }catch(\Exception $e){ + log_message('error', 'Exception getLatestGMCPolicy :' . $e->getMessage()); + return null; + } + } + +} + diff --git a/app/Models/EmployeeModel.php b/app/Models/EmployeeModel.php index 2cfc852..c556bdb 100755 --- a/app/Models/EmployeeModel.php +++ b/app/Models/EmployeeModel.php @@ -166,7 +166,8 @@ class EmployeeModel extends Model client_policy.disclaimer, client_policy.policy_type_id , employee_polices.tpa_id as tpa_id , - employee_polices.rand_string as rand_string + employee_polices.rand_string as rand_string, + client_policy.policy_end_date ', FALSE) // 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')