From 3d36d8d88e100cbfa519b275dbd62cc3049c0997 Mon Sep 17 00:00:00 2001 From: Gowtham M Date: Tue, 2 Dec 2025 17:16:35 +0530 Subject: [PATCH 01/17] App signature added in all rest api --- app/Config/Routes.php | 59 +++++++++++-------- .../RestAuthenticationController.php | 5 +- 2 files changed, 38 insertions(+), 26 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 7cdb968..d4957b6 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" => ["authJWT" , "appSignature"]], function ($routes) { // $routes->post("getVerifiedUserData", "RestAuthenticationController::getVerifiedUserData"); @@ -525,6 +501,39 @@ $routes->group("employeeRest", ["filter" => "authJWT"], function ($routes) { }); +$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"); $routes->get("sendPushNotification", "EmployeeRestController::sendPushNotification"); $routes->post("sendEmail", "EmployeeRestController::send_email"); diff --git a/app/Controllers/RestAuthenticationController.php b/app/Controllers/RestAuthenticationController.php index 7531d2e..8507be5 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(); } From bc1f91acea6e4410879a30554aee5365c685a014 Mon Sep 17 00:00:00 2001 From: Gowtham M Date: Tue, 2 Dec 2025 17:51:08 +0530 Subject: [PATCH 02/17] App signature added in all rest api --- app/Config/Feature.php | 2 +- app/Config/Filters.php | 1 + app/Config/Routes.php | 6 +++--- app/Filters/AuthJWT.php | 2 +- app/Filters/VerifyAppSignature.php | 2 ++ 5 files changed, 8 insertions(+), 5 deletions(-) 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 d4957b6..262e445 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -453,7 +453,7 @@ $routes->group("/api", ["filter" => "authJWT"], function ($routes) { // $routes->post("employeeRest/createOrUpdateEmployeePolicySiAmount", "EmployeeRestController::createOrUpdateEmployeePolicySiAmount"); // $routes->post("employeeRest/calculatePremium", "EmployeeRestController::calculatePremium"); -$routes->group("employeeRest", ["filter" => ["authJWT" , "appSignature"]], function ($routes) { +$routes->group("employeeRest", ['filter' => ['authJWT', 'appSignature'] ], function ($routes) { // $routes->post("getVerifiedUserData", "RestAuthenticationController::getVerifiedUserData"); @@ -501,7 +501,7 @@ $routes->group("employeeRest", ["filter" => ["authJWT" , "appSignature"]], funct }); -$routes->group("employeeRest", ['filter' => ["appSignature"] ], function ($routes) { +$routes->group("employeeRest", ['filter' => ['appSignature'] ], function ($routes) { //Employee login api's $routes->post("verifyEmployeeNumber", "RestAuthenticationController::verifyEmployeeWithMobileNumber"); @@ -547,7 +547,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/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/Filters/VerifyAppSignature.php b/app/Filters/VerifyAppSignature.php index a5257b2..56f5051 100644 --- a/app/Filters/VerifyAppSignature.php +++ b/app/Filters/VerifyAppSignature.php @@ -13,6 +13,8 @@ class VerifyAppSignature implements FilterInterface // Get the header sent by the Flutter app $clientSignature = $request->getHeaderLine('App-Signature'); + dd($clientSignature); + // Load the server's expected signature from the .env $validSignature = getenv('APP_SIGNATURE'); From 42a1d53b013ce7a57e85fb4ec46f2b5953333c6b Mon Sep 17 00:00:00 2001 From: Gowtham M Date: Tue, 2 Dec 2025 17:53:11 +0530 Subject: [PATCH 03/17] App signature added in all rest api --- app/Config/Routes.php | 2 +- app/Filters/VerifyAppSignature.php | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 262e445..928abe7 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -453,7 +453,7 @@ $routes->group("/api", ["filter" => "authJWT"], function ($routes) { // $routes->post("employeeRest/createOrUpdateEmployeePolicySiAmount", "EmployeeRestController::createOrUpdateEmployeePolicySiAmount"); // $routes->post("employeeRest/calculatePremium", "EmployeeRestController::calculatePremium"); -$routes->group("employeeRest", ['filter' => ['authJWT', 'appSignature'] ], function ($routes) { +$routes->group("employeeRest", ['filter' => ['appSignature' , 'authJWT'] ], function ($routes) { // $routes->post("getVerifiedUserData", "RestAuthenticationController::getVerifiedUserData"); diff --git a/app/Filters/VerifyAppSignature.php b/app/Filters/VerifyAppSignature.php index 56f5051..a5257b2 100644 --- a/app/Filters/VerifyAppSignature.php +++ b/app/Filters/VerifyAppSignature.php @@ -13,8 +13,6 @@ class VerifyAppSignature implements FilterInterface // Get the header sent by the Flutter app $clientSignature = $request->getHeaderLine('App-Signature'); - dd($clientSignature); - // Load the server's expected signature from the .env $validSignature = getenv('APP_SIGNATURE'); From 1801a85047852bee599f8146c2c362e0786e196f Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Wed, 3 Dec 2025 11:12:24 +0530 Subject: [PATCH 04/17] FIX_HEADER_FOR_APP_SIGNSTURE --- app/Helpers/RestAuthHelper.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/Helpers/RestAuthHelper.php b/app/Helpers/RestAuthHelper.php index 1308676..36457e0 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); From b6b9825fa8d575f2105fafef8546709f10d51f8e Mon Sep 17 00:00:00 2001 From: Gowtham M Date: Wed, 3 Dec 2025 12:51:43 +0530 Subject: [PATCH 05/17] GWM : relationship chabges on addONAPI --- app/Controllers/EmployeeRestController.php | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 0a478b4..73dfa6a 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -2229,34 +2229,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']]); } } } From f041cd3a293e56d5e5e85eb69c58499966471b9a Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Thu, 4 Dec 2025 15:23:01 +0530 Subject: [PATCH 06/17] CHANGE_ERROR_DATA --- app/Controllers/EmployeeRestController.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 0a478b4..2487b17 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -1457,7 +1457,19 @@ class EmployeeRestController extends AdminController 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); } } From 6cc12a873180cd1c26967cea86926d68b3351aaf Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Fri, 5 Dec 2025 12:18:07 +0530 Subject: [PATCH 07/17] FEAT_RETAIL_UENIFITS_LOGIN --- .../RestAuthenticationController.php | 80 ++++++++++++++++--- app/Helpers/RestAuthHelper.php | 58 +++++++++++++- 2 files changed, 126 insertions(+), 12 deletions(-) diff --git a/app/Controllers/RestAuthenticationController.php b/app/Controllers/RestAuthenticationController.php index 8507be5..6ab369e 100755 --- a/app/Controllers/RestAuthenticationController.php +++ b/app/Controllers/RestAuthenticationController.php @@ -264,26 +264,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'])) { @@ -321,7 +358,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'], @@ -332,11 +368,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') { @@ -350,6 +383,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', ' '); @@ -407,8 +441,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' => 'success', 'code' => 200, 'data' => [], 'post_enrollment' => json_decode($apiResponse, true)], 200); + } + return $this->respond(['status' => 'Invalid OTP','code' => 404,'data' => "", 'message' => "Invalid OTP"],200); } @@ -484,6 +533,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/Helpers/RestAuthHelper.php b/app/Helpers/RestAuthHelper.php index 36457e0..121c9cb 100644 --- a/app/Helpers/RestAuthHelper.php +++ b/app/Helpers/RestAuthHelper.php @@ -383,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) @@ -440,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 []; + } } From bad9a267fe133762494691528c07b387f5fc0007 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Fri, 5 Dec 2025 14:00:06 +0530 Subject: [PATCH 08/17] FIX_ISSUE --- app/Controllers/RestAuthenticationController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Controllers/RestAuthenticationController.php b/app/Controllers/RestAuthenticationController.php index 6ab369e..75e6cc4 100755 --- a/app/Controllers/RestAuthenticationController.php +++ b/app/Controllers/RestAuthenticationController.php @@ -92,7 +92,8 @@ class RestAuthenticationController extends AdminController if (isset($params['token']) && !empty($params['token'])) { $options['headers'] = [ 'Authorization' => 'Bearer ' . $params['token'], - 'Accept' => 'application/json' + 'Accept' => 'application/json', + 'App-Signature' => getenv('APP_SIGNATURE'), ]; } From 19096a99ae80447a6f0c242042c614bf3a59c12a Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Fri, 5 Dec 2025 14:20:56 +0530 Subject: [PATCH 09/17] FIX_ISSUE --- app/Controllers/RestAuthenticationController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Controllers/RestAuthenticationController.php b/app/Controllers/RestAuthenticationController.php index 75e6cc4..16132f4 100755 --- a/app/Controllers/RestAuthenticationController.php +++ b/app/Controllers/RestAuthenticationController.php @@ -456,7 +456,7 @@ class RestAuthenticationController extends AdminController // Call the third-party API function $apiResponse = $this->callThirdPartyAPI($retailApiParams, 'getVerifiedRetailUserData'); // print_r($apiResponse); die; - return $this->respond(['status' => 'success', 'code' => 200, 'data' => [], 'post_enrollment' => json_decode($apiResponse, true)], 200); + 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); From 1231e28e9951abcf5792bf3472a55d04bb451d6f Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Fri, 5 Dec 2025 14:35:40 +0530 Subject: [PATCH 10/17] FIX_HR_API_ISSUE --- app/Controllers/RestAuthenticationController.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/Controllers/RestAuthenticationController.php b/app/Controllers/RestAuthenticationController.php index 16132f4..22e834e 100755 --- a/app/Controllers/RestAuthenticationController.php +++ b/app/Controllers/RestAuthenticationController.php @@ -87,16 +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', - 'App-Signature' => getenv('APP_SIGNATURE'), - ]; + if (!empty($params['token'])) { + $options['headers']['Authorization'] = 'Bearer ' . $params['token']; } + $response = $client->get($url, $options); return $response->getBody(); From e1def8e953984e5c5d0e6fc69f15782a379f275b Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Sat, 6 Dec 2025 10:17:35 +0530 Subject: [PATCH 11/17] FEAT_COPY_POLICY --- app/Config/Routes.php | 2 + app/Controllers/EmployeeRestController.php | 372 +++++++++++++-------- 2 files changed, 235 insertions(+), 139 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 928abe7..eaf7741 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -499,6 +499,8 @@ $routes->group("employeeRest", ['filter' => ['appSignature' , 'authJWT'] ], func $routes->get("hrFileDownload", "EmployeeRestController::hrFileDownload"); $routes->post("hrFileUpload", "EmployeeRestController::hrFileUpload"); + $routes->get("copyActiveEmployeeAndDependentDetails", "EmployeeRestController::copyActiveEmployeeAndDependentDetails"); + }); $routes->group("employeeRest", ['filter' => ['appSignature'] ], function ($routes) { diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 93660a4..a9dd804 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -3682,154 +3682,248 @@ 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); + } + + $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) { + + $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'] = null; + + + $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' => "succese", '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 From 7c2716bfe11dfdf6b6710676fbce7b7b047d3086 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Sat, 6 Dec 2025 10:55:54 +0530 Subject: [PATCH 12/17] FIX_ISSUE --- 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 a9dd804..97bca21 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -3920,7 +3920,7 @@ class EmployeeRestController extends AdminController } if(!empty($data)){ - return $this->respond(['status' => "succese", 'code' => 200, 'data' => $data], 200); + return $this->respond(['status' => "success", 'code' => 200, 'data' => $data], 200); }else{ return $this->respond(['status' => "failed", 'code' => 404, 'message' => "No data found", 'data' => []], 200); } From dabe60b4988c320fb1a179e79b10e449075b430e Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Sat, 6 Dec 2025 11:23:58 +0530 Subject: [PATCH 13/17] FIX_GMC_TWO_POLICY --- app/Controllers/EmployeeRestController.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 97bca21..f3d0b2f 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -1437,12 +1437,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); + // return $this->respond(['status' => 'success','code' => 200,'data' => [$array]], 200); + $result[] = $array; } } @@ -1450,7 +1452,11 @@ 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{ From 1f740207c1ee46f1d9cf0d4e7222af589b0a1283 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Sat, 6 Dec 2025 15:19:54 +0530 Subject: [PATCH 14/17] FIX_EMP_DATA --- app/Controllers/EmployeeRestController.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index f3d0b2f..7a6692e 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -1163,10 +1163,20 @@ class EmployeeRestController extends AdminController $result = []; foreach ($empPolicy as $array) { + // Reset employee array - $empData = $employeeData; - - + // $empData = $employeeData; + $empData = $this->employeeModel + ->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)); From 2bb38af974617286257f6f1b09d185ed506bda7e Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Sat, 6 Dec 2025 16:06:00 +0530 Subject: [PATCH 15/17] FIX_ISSUE --- app/Controllers/EmployeeRestController.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 7a6692e..c2622a0 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -1163,10 +1163,11 @@ class EmployeeRestController extends AdminController $result = []; foreach ($empPolicy as $array) { - + // 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) @@ -3900,10 +3901,17 @@ class EmployeeRestController extends AdminController 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); @@ -3912,6 +3920,8 @@ class EmployeeRestController extends AdminController 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']; @@ -3920,7 +3930,7 @@ class EmployeeRestController extends AdminController $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'] = null; + $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); From 76cc67a417dacfb81ea6df2558d6547723ef174c Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Mon, 8 Dec 2025 10:32:32 +0530 Subject: [PATCH 16/17] FIX_COPY_ENBABLE --- app/Controllers/EmployeeRestController.php | 11 ++++++-- app/Helpers/utility_helper.php | 32 ++++++++++++++++++++++ app/Models/EmployeeModel.php | 3 +- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index c2622a0..d12c2a2 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -1160,7 +1160,8 @@ class EmployeeRestController extends AdminController if ($empPolicy) { - + + $latest_gmc_policy_id = getLatestGMCPolicy((array)$empPolicy); $result = []; foreach ($empPolicy as $array) { @@ -1259,6 +1260,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; @@ -1453,7 +1459,7 @@ class EmployeeRestController extends AdminController $result[] = $GmcParrentsData; } - if($this->request->getGet('policy') == 'GMC'){ + if($this->request->getGet('policy') == 'GMC' && !$checkGmcParentsPolicyExist){ // return $this->respond(['status' => 'success','code' => 200,'data' => [$array]], 200); $result[] = $array; } @@ -1473,6 +1479,7 @@ class EmployeeRestController extends AdminController }else{ return $this->respond(['status' => 'failed','code' => 404,'data' => []], 200); } + } catch (\Exception $e) { $errorData = [ 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') From f39dbe7d2073ea9ee07ed5308cf5ca0039e5ebcf Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Mon, 8 Dec 2025 11:23:03 +0530 Subject: [PATCH 17/17] FIX_DEPENDENT_DELETION --- app/Controllers/EmployeeRestController.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index d12c2a2..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{