FIX_UPDATE_MPIN : RV
This commit is contained in:
parent
48f0c8f499
commit
0c2f5ee4d1
@ -2531,8 +2531,8 @@ class EmployeeRestController extends AdminController
|
||||
|
||||
$value['type'] = $policyTypeData->policy_type;
|
||||
$value['policy_name'] = $policyTypeData->long_name;
|
||||
$value['insurer_name'] = $insurerData->name;
|
||||
$value['insurer_short_name'] = $insurerData->short_name;
|
||||
$value['insurer_name'] = $insurerData->name ?? null;
|
||||
$value['insurer_short_name'] = $insurerData->short_name ?? null;
|
||||
$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'));
|
||||
$enrolledCount = 0;
|
||||
$draftCount = 0;
|
||||
|
||||
@ -817,7 +817,7 @@ class RestAuthenticationController extends AdminController
|
||||
$mobile_number = isset($this->request->getJSON()->mobile_number) ? $this->request->getJSON()->mobile_number : null;
|
||||
$email_id = isset($this->request->getJSON()->email_id) ? $this->request->getJSON()->email_id : null;
|
||||
|
||||
$empdata = RestAuthHelper::getPreAndPostDataByEmailOrMobile(['email_id' => $email_id, 'mobile_number' => $mobile_number]);
|
||||
$empdata = RestAuthHelper::getPreAndPostDataByEmailOrMobile(['email_id' => $email_id, 'mobile_number' => $mobile_number, 'check_mpin' => true]);
|
||||
// print_r($empdata); die;
|
||||
|
||||
if(empty($empdata)){
|
||||
|
||||
@ -177,6 +177,7 @@ class RestAuthHelper
|
||||
$email_id = $params['email_id'] ?? null;
|
||||
$otp = $params['otp'] ?? null;
|
||||
$old_mpin = $params['old_mpin'] ?? null;
|
||||
$check_mpin = $params['check_mpin'] ?? null;
|
||||
|
||||
if (empty($mobile_number) && empty($email_id)) {
|
||||
log_message('error', 'Both mobile_number and email_id are empty. Returning null.');
|
||||
@ -218,6 +219,29 @@ class RestAuthHelper
|
||||
|
||||
if ($latest_data['client_short_name'] === $other_data['client_short_name']) {
|
||||
log_message('error', 'client_short_name match. Returning both records.');
|
||||
|
||||
if ($check_mpin !== null && ($pre_data['mpin'] !== null || $post_data['mpin'] !== null)) {
|
||||
|
||||
// Case: Pre MPIN is missing, update it from Post
|
||||
if ($pre_data['mpin'] === null && $post_data['mpin'] !== null) {
|
||||
$data = [
|
||||
'client_id' => $pre_data['client_id'],
|
||||
'employee_id' => $pre_data['id'],
|
||||
'mpin' => $post_data['mpin'],
|
||||
];
|
||||
$response = self::updatePreMpin($data);
|
||||
|
||||
// Case: Post MPIN is missing, update it from Pre
|
||||
} elseif ($post_data['mpin'] === null && $pre_data['mpin'] !== null) {
|
||||
$data = [
|
||||
'client_id' => $post_data['client_id'],
|
||||
'employee_id' => $post_data['id'],
|
||||
'mpin' => $pre_data['mpin'],
|
||||
];
|
||||
$response = self::updatePostMpin($data);
|
||||
}
|
||||
}
|
||||
|
||||
return ['pre' => $pre_data, 'post' => $post_data];
|
||||
}
|
||||
}
|
||||
@ -351,5 +375,58 @@ class RestAuthHelper
|
||||
log_message('warning', 'No mobile or email present in params for post fetch.');
|
||||
}
|
||||
|
||||
public static function updatePreMpin(array $params)
|
||||
{
|
||||
log_message('info', 'Function updatePostMpin called with: ' . json_encode($params));
|
||||
|
||||
$employee_id = $params['employee_id'] ?? null;
|
||||
$mpin = $params['mpin'] ?? null;
|
||||
|
||||
if (empty($employee_id) || empty($mpin)) {
|
||||
log_message('error', 'Missing employee_id or mpin in updatePreMpin');
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
$employeeModel = new EmployeeModel();
|
||||
$result = $employeeModel
|
||||
->where('id', $employee_id)
|
||||
->set('mpin', $mpin)
|
||||
->update();
|
||||
|
||||
log_message('info', 'MPIN update status (Pre): ' . var_export($result, true));
|
||||
return $result;
|
||||
} catch (\Exception $e) {
|
||||
log_message('error', 'Exception in updatePreMpin: ' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function updatePostMpin(array $params)
|
||||
{
|
||||
if (isset($params['mpin']) && isset($params['employee_id'])) {
|
||||
|
||||
$client = \Config\Services::curlrequest();
|
||||
$endPoint = 'updateEmpMPIN';
|
||||
$url = env('POST_ENROLLMENT_BASEURL') . $endPoint;
|
||||
|
||||
log_message('info', '[updatePostMpin] Sending POST to external API: ' . $url);
|
||||
log_message('debug', '[updatePostMpin] Request Payload: ' . json_encode($params));
|
||||
|
||||
$response = $client->post($url, ['json' => $params, 'http_errors' => false]);
|
||||
|
||||
$post_json = $response->getBody();
|
||||
log_message('info', '[updatePostMpin] Raw API Response: ' . $post_json);
|
||||
|
||||
$post_data = json_decode($post_json, true);
|
||||
|
||||
$data = $post_data['data'] ?? [];
|
||||
log_message('debug', '[updatePostMpin] Parsed Response Data: ' . json_encode($data));
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
log_message('warning', '[updatePostMpin] Missing required parameters: employee_id or mpin');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user