Merge branch 'dev' of bitbucket.org:jubilian/nhance-enrollment into dev

This commit is contained in:
VENKATESHWARAN 2025-06-30 12:53:00 +05:30
commit ef057590c9
4 changed files with 219 additions and 87 deletions

View File

@ -435,6 +435,7 @@ $routes->post("/employeeRest/verifyEmployeeEmailId", "RestAuthenticationControll
//HR login api's //HR login api's
$routes->post("/employeeRest/verifyHrWithMobileNumber", "RestAuthenticationController::verifyHrWithMobileNumber"); $routes->post("/employeeRest/verifyHrWithMobileNumber", "RestAuthenticationController::verifyHrWithMobileNumber");
$routes->post("/employeeRest/verifyHrWithEmail", "RestAuthenticationController::verifyHrWithEmail");
$routes->post("/employeeRest/getVerifiedHrData", "RestAuthenticationController::getVerifiedHrData"); $routes->post("/employeeRest/getVerifiedHrData", "RestAuthenticationController::getVerifiedHrData");
$routes->group("/api", ["filter" => "authJWT"], function ($routes) { $routes->group("/api", ["filter" => "authJWT"], function ($routes) {
@ -476,7 +477,8 @@ $routes->group("employeeRest", ["filter" => "authJWT"], function ($routes) {
$routes->post("iAgreeForAddOn", "EmployeeRestController::iAgreeForAddOn"); $routes->post("iAgreeForAddOn", "EmployeeRestController::iAgreeForAddOn");
$routes->get("exportDataByClientPolicyId", "EmployeeRestController::exportDataByClientPolicyId"); $routes->get("exportDataByClientPolicyId", "EmployeeRestController::exportDataByClientPolicyId");
$routes->get("getCashDepositData", "EmployeeRestController::getCashDepositData");
$routes->get("getPolicyLevelEmployeeSummaryData", "EmployeeRestController::getPolicyLevelEmployeeSummaryData");
$routes->get("exportCashDepositData", "EmployeeRestController::exportCashDepositData"); $routes->get("exportCashDepositData", "EmployeeRestController::exportCashDepositData");
$routes->get("removeEmpAndEmpPolicyData", "EmployeeRestController::removeEmpAndEmpPolicyData"); $routes->get("removeEmpAndEmpPolicyData", "EmployeeRestController::removeEmpAndEmpPolicyData");

View File

@ -230,16 +230,23 @@ class EmployeeRestController extends AdminController
try { try {
$data = $this->request->getJSON(); $data = $this->request->getJSON();
// dd($data); //enrolment check
$openForEnrollment = $this->findThePolicyIsOpenForEnrollment($data[0]->client_policy_id);
$validationFailed = $this->employeeHelper->validation_addEmployeeAndDependence($data); if($openForEnrollment == false){
return $this->respond(['status' => 'failed','code' => 404,'data' => [],'message' => 'Enrollment closed.'], 200);
if($validationFailed){
return $this->respond(['status' => 'failed','code' => 404,'data' => "validation_addEmployeeAndDependence failed ..!!"], 404);
} }
$openForEnrollment = $this->findThePolicyIsOpenForEnrollment($data[0]->client_policy_id); //dependent duplicate check
if($openForEnrollment == false){ return $this->respond(['status' => 'failed','code' => 404,'data' => 'Enrollment closed'], 404); } if ( ! isset($data[0]->id) ) {
$validationFailed = $this->employeeHelper->validation_addEmployeeAndDependence($data);
if($validationFailed){
return $this->respond(['status' => 'failed','code' => 404,'data' => [],'message' => "Relation already exists."], 200);
}
}
if ($data) { if ($data) {
@ -288,14 +295,14 @@ class EmployeeRestController extends AdminController
$this->updatePremiumAmount($data[0]->client_policy_id , $data[0]->emp_code , $data[0]->client_branch_id); $this->updatePremiumAmount($data[0]->client_policy_id , $data[0]->emp_code , $data[0]->client_branch_id);
$result = []; $result = [];
return $this->respond(['status' => 'success','code' => 200,'data' => $result], 200); return $this->respond(['status' => 'success','code' => 200,'data' => $result,'message' => "Successfully updated."], 200);
} else { } else {
$result = "No Matches"; $result = "No Matches";
return $this->respond(['status' => 'failed','code' => 404,'data' => $result], 404); return $this->respond(['status' => 'failed','code' => 404,'data' => $result,'message' => "Action failed."], 200);
} }
} }
} catch (\Exception $e) { } catch (\Exception $e) {
return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500); return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage(),'message' => "Action failed."], 500);
} }
} }
@ -2480,72 +2487,68 @@ class EmployeeRestController extends AdminController
} }
public function getCashDepositData() public function getPolicyLevelEmployeeSummaryData()
{ {
$ClientPolicyData = $this->clientPolicyModel->select('client_policy.client_id as clientId , client_policy.insurer_id as insurerId,insurers.name as insurer_name') $hr_id = $this->request->getGet('hr_id');
->join('insurers', 'client_policy.insurer_id = insurers.id', 'left') $restAuthController = new RestAuthenticationController;
->where('client_policy.client_id', $this->request->getGet('client_id') ) //call and get allowed policy data from post enrollment
->where('client_policy.client_branch_id', $this->request->getGet('client_branch_id') ) $queryParams = [
->where('client_policy.is_active', 1 ) 'hr_id' => $hr_id,
->where('client_policy.policy_status', 1) 'request_for' => 'pre_enrollment'
->groupBy('client_policy.insurer_id') ];
->findAll(); $HRAccessRes = $restAuthController->callThirdPartyGETAPI($queryParams,'getHRAccessData');
$result = []; $HRAccessData = json_decode($HRAccessRes,true);
if(isset($HRAccessData['data']['allowed_pre_policies']))
{
$policyId = json_decode($HRAccessData['data']['allowed_pre_policies'],true);
}else{
$policyId = [];
}
if(count($ClientPolicyData)) if(count($policyId) == 0){
{ return $this->respond(['status' => 'failed','code' => (count($policyId) ? 200 : 404),'data' => [] ], 200);
foreach ($ClientPolicyData as $key => $value) { }
$data['clientId'] = $value['clientId'];
$data['insurerId'] = $value['insurerId']; $ClientPolicyData = $this->clientPolicyModel->select('client_policy.id as client_policy_id , client_policy.client_id as client_id, client_policy.policy_type_id as policy_type_id, client_policy.is_addon as is_addon , client_policy.open_for_enrollment as OpenForEnrollment , client_policy.inception_type as inception_type ')
$data['insurerName'] = $value['insurer_name']; ->where('client_policy.client_id', $this->request->getGet('client_id') )
$data['depositData'] = $this->clientPolicyModel->getdepositData($value['clientId'],$value['insurerId']); ->where('client_policy.client_branch_id', $this->request->getGet('client_branch_id') )
$data['balance'] = count($data['depositData']) ? $data['depositData'][0]->balance : 0; ->where('client_policy.is_active', 1 )
->where('client_policy.policy_status', 1)
$data['policyDetails'] = []; ->whereIn('client_policy.id', $policyId)
$ClientPolicyData = $this->clientPolicyModel->select('client_policy.id as client_policy_id , client_policy.client_id as client_id, client_policy.policy_type_id as policy_type_id, client_policy.is_addon as is_addon , client_policy.open_for_enrollment as OpenForEnrollment , client_policy.inception_type as inception_type ') ->findAll();
$result = [];
->where('client_policy.insurer_id', $value['insurerId'] ) // dd( $ClientPolicyData);
->where('client_policy.client_id', $this->request->getGet('client_id') ) foreach ($ClientPolicyData as $key => $value)
->where('client_policy.client_branch_id', $this->request->getGet('client_branch_id') ) {
->where('client_policy.is_active', 1 ) $policyTypeData = $this->policyTypeModel->where('id',$value['policy_type_id'])->get()->getRow();
->where('client_policy.policy_status', 1) $value['type'] = $policyTypeData->policy_type;
->findAll(); $value['policy_name'] = $policyTypeData->long_name;
// dd( $ClientPolicyData); $employeeDetails = $this->employeePolicyModel->getEmployeePolicy( client_id:$value['client_id'],policy_id: $value['client_policy_id'],status:0,branch_id:$this->request->getGet('client_branch_id'));
foreach ($ClientPolicyData as $key => $value) $enrolledCount = 0;
$draftCount = 0;
if(count($employeeDetails))
{ {
$policyTypeData = $this->policyTypeModel->where('id',$value['policy_type_id'])->get()->getRow(); foreach ($employeeDetails as $item) {
$value['type'] = $policyTypeData->policy_type; if ($item['emp_status'] === 'enrolled') {
$value['policy_name'] = $policyTypeData->long_name; $enrolledCount++;
$employeeDetails = $this->employeePolicyModel->getEmployeePolicy( client_id:$value['client_id'],policy_id: $value['client_policy_id'],status:0,branch_id:$this->request->getGet('client_branch_id')); } elseif ($item['emp_status'] === 'draft') {
$enrolledCount = 0; $draftCount++;
$draftCount = 0;
if(count($employeeDetails))
{
foreach ($employeeDetails as $item) {
if ($item['emp_status'] === 'enrolled') {
$enrolledCount++;
} elseif ($item['emp_status'] === 'draft') {
$draftCount++;
}
} }
} }
$value['totalMembersCount'] = count($employeeDetails);
$value['membersCountOfEnrolled'] = $enrolledCount;
$value['membersCountOfDraft'] = $draftCount;
array_push($data['policyDetails'],$value);
} }
array_push($result,$data);
} $value['totalMembersCount'] = count($employeeDetails);
} $value['membersCountOfEnrolled'] = $enrolledCount;
$value['membersCountOfDraft'] = $draftCount;
array_push($result,$value);
}
if($result) if($result)
{ {

View File

@ -73,9 +73,23 @@ class RestAuthenticationController extends AdminController
return $response->getBody(); return $response->getBody();
} }
public function callThirdPartyGETAPI($queryParams, $endPoint)
{
$client = \Config\Services::curlrequest();
$url = env('POST_ENROLLMENT_BASEURL') . $endPoint;
$response = $client->get($url, [
'query' => $queryParams, // pass as query parameters
'http_errors' => false // prevent exception on non-200 status
]);
return $response->getBody();
}
// employee auth api's start
public function verifyEmployeeWithMobileNumber() public function verifyEmployeeWithMobileNumber()
{ {
@ -268,6 +282,11 @@ class RestAuthenticationController extends AdminController
} }
} }
// employee auth api's end
// HR auth api's start
public function verifyHrWithMobileNumber() public function verifyHrWithMobileNumber()
{ {
try { try {
@ -283,8 +302,74 @@ class RestAuthenticationController extends AdminController
$result = ['user_verification' => true ,'message' => "Verified Successfully"]; $result = ['user_verification' => true ,'message' => "Verified Successfully"];
return $this->respond(['status' => 'success','code' => 200,'data' => $result],200); return $this->respond(['status' => 'success','code' => 200,'data' => $result],200);
} else { } else {
$result = ['user_verification' => false , 'message' => "User not found"]; // Call the third-party API function
return $this->respond(['status' => 'failed','code' => 404,'data' => $result],200); return $this->callThirdPartyAPI($this->request->getJSON(),'verifyHrWithMobileNumber');
}
} catch (\Throwable $th) {
return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500);
}
}
public function verifyHrWithEmail()
{
try {
$data = $this->request->getJSON();
$email = $data->email;
$HrData = $this->hrModel->where('email', $email)
->where('contact_type', 'client')
->where('is_active', 1)
->first();
if ($HrData) {
$otp = random_int(100000, 999999);
$sql = "
UPDATE level_contacts
SET otp = ?
WHERE email = ?
AND contact_type = 'client'
AND is_active = 1
";
$db = db_connect();
$update = $db->query($sql, [$otp, $email]);
if($update)
{
$data->otp = $otp;
$this->callThirdPartyAPI($data, 'updateHROTP');
$common = [
'login_type' => 'HR login',
'login_email' => $email,
'mail_type' => 'otp_mail'
];
$subject = 'Nhance user verification - OTP';
$mail_content = $otp . ' is your verification code for Nhance.';
$res = MailHelper::send_email(['mail' => $email, 'subject' => $subject, 'common' => $common, 'message' => $mail_content]);
$this->myLogger->logme("info", $res);
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);
}
} else {
$result = ['user_verification' => false, 'message' => "Verification failed , try again"];
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => $result], 200);
}
} else {
// Call the third-party API function
return $this->callThirdPartyAPI($this->request->getJSON(),'verifyHrWithEmail');
} }
} catch (\Throwable $th) { } catch (\Throwable $th) {
@ -296,11 +381,23 @@ class RestAuthenticationController extends AdminController
public function getVerifiedHrData() public function getVerifiedHrData()
{ {
try { try {
$mobile_number = $this->request->getJSON()->mobile_number; // mobile number
$otp_verification = $this->request->getJSON()->otp_verification; $otp_verification = isset($this->request->getJSON()->otp_verification) ? $this->request->getJSON()->otp_verification : null;
$mobile_number = isset($this->request->getJSON()->mobile_number) ? $this->request->getJSON()->mobile_number : null;
// email id
$otp = isset($this->request->getJSON()->otp) ? $this->request->getJSON()->otp : null;
$email = isset($this->request->getJSON()->email) ? $this->request->getJSON()->email : null;
if (isset($mobile_number))
{
$hrData = $this->hrModel->where('mobile', $mobile_number)->where('contact_type', 'client')->first();
}else{
$hrData = $this->hrModel->where('email', $email)->where('contact_type', 'client')->where('otp', $otp)->first();
}
if ($hrData && $otp_verification == true || $hrData && isset($this->request->getJSON()->otp) )
{
$hrData = $this->hrModel->where('mobile', $mobile_number)->first();
if ($hrData && $otp_verification == true) {
$auth = HttpRequestHelper::getRequestInfo(); $auth = HttpRequestHelper::getRequestInfo();
if ($auth) { if ($auth) {
$data = [ $data = [
@ -316,15 +413,46 @@ class RestAuthenticationController extends AdminController
} }
$hrData = $this->hrModel ->select('level_contacts.* , client_branch.client_id as client_id') if(isset($this->request->getJSON()->mobile_number)){
$hrData = $this->hrModel ->select('level_contacts.* , client_branch.client_id as client_id')
->join('client_branch', 'level_contacts.ref_id = client_branch.id', 'left')
->where('level_contacts.mobile', $mobile_number )
->where('level_contacts.contact_type', 'client')
->find();
}else if(isset($this->request->getJSON()->otp)){
$this->hrModel->where('email', $email)->where('otp', $otp)->where('contact_type', 'client')->set(['otp'=>null])->update();
$hrData = $this->hrModel ->select('level_contacts.* , client_branch.client_id as client_id')
->join('client_branch', 'level_contacts.ref_id = client_branch.id', 'left') ->join('client_branch', 'level_contacts.ref_id = client_branch.id', 'left')
->where('level_contacts.mobile', $mobile_number ) ->where('level_contacts.email', $email )
->where('level_contacts.contact_type', 'client')
->find(); ->find();
}
//call and get allowed module data from post enrollment
$queryParams = [
'hr_id' => $hrData['0']['id'],
'request_for' => 'pre_enrollment'
];
$HRAccessRes = $this->callThirdPartyGETAPI($queryParams,'getHRAccessData');
$HRAccessData = json_decode($HRAccessRes,true);
if(isset($HRAccessData['data']['allowed_modules'])){ $hrData['0']['allowed_modules'] = json_decode($HRAccessData['data']['allowed_modules'],true)['pre']; }else{ $hrData['0']['allowed_modules'] = []; }
$result = JWTToken::encode($hrData['0']); $result = JWTToken::encode($hrData['0']);
return $this->respond(['status' => 'success','code' => 200,'data' => $result],200);
// Call the third-party API function
$apiResponse = $this->callThirdPartyAPI($this->request->getJSON(),'getVerifiedHrData');
return $this->respond(['status' => 'success','code' => 200,'data' => $result , 'post_enrollment'=> json_decode($apiResponse, true)],200);
} else { } else {
return $this->respond(['status' => 'failed','code' => 404,'data' => "Invalid OTP"],200);
// Call the third-party API function
$apiResponse = $this->callThirdPartyAPI($this->request->getJSON(),'getVerifiedHrData');
return $this->respond(['status' => 'failed','code' => 404,'data' => "Invalid OTP" , 'post_enrollment'=> json_decode($apiResponse, true)],200);
} }
} catch (\Exception $e) { } catch (\Exception $e) {
return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()],500); return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()],500);

View File

@ -30,12 +30,12 @@ class EmployeeHelper
public function validation_addEmployeeAndDependence($data){ public function validation_addEmployeeAndDependence($data){
$employeeData = $this->employeeModel->where('emp_code',$data[0]->emp_code) $employeeData = $this->employeeModel->where('emp_code',$data[0]->emp_code)
->where('client_id',$data[0]->client_id) ->where('client_id',$data[0]->client_id)
->where('client_branch_id',$data[0]->client_branch_id) ->where('client_branch_id',$data[0]->client_branch_id)
->where('is_active', 1 ) ->where('is_active', 1 )
->where('is_addon_value',0) ->where('is_addon_value',0)
->findAll(); ->findAll();
$arr [] = $data; $arr [] = $data;
@ -81,7 +81,7 @@ class EmployeeHelper
if(isset($employee_policy->payable_employee) && $employee_policy->payable_employee == 1) if(isset($employee_policy->payable_employee) && $employee_policy->payable_employee == 1)
{ {
if(isset($employee_policy->rata_premimum)){ $dependent_and_si_premium_value = $dependent_and_si_premium_value + $employee_policy->rata_premimum;} if(isset($employee_policy->rata_premimum)){ $dependent_and_si_premium_value = $dependent_and_si_premium_value + $employee_policy->rata_premimum;}
if(isset($employee_policy->gst)){ $dependent_and_si_gst_value = $dependent_and_si_gst_value + $employee_policy->gst;} if(isset($employee_policy->gst)){ $dependent_and_si_gst_value = $dependent_and_si_gst_value + $employee_policy->gst;}
} }
$temp['is_value_exist'] = true; $temp['is_value_exist'] = true;
@ -160,7 +160,6 @@ class EmployeeHelper
$input_relationship = $data[0]->relationship ; $input_relationship = $data[0]->relationship ;
var_dump($newData);
foreach($newData as $index => $eachData){ foreach($newData as $index => $eachData){