Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
velz 2025-07-09 17:22:51 +05:30
commit e469a820da
2 changed files with 19 additions and 48 deletions

View File

@ -2774,7 +2774,8 @@ class EmployeeRestController extends AdminController
//for get the pre enrollment policy count
$empMobileNo = $this->request->getGet('mobile_no');
$prePolicyCount = $this->getPreEmployeePolicyCount($empMobileNo);
$clientId = $this->request->getGet('client_id');
$prePolicyCount = $this->getPreEmployeePolicyCount($empMobileNo, $clientId);
$whereArrayForId = [];
foreach ( $employeeData as $key => $value) { array_push($whereArrayForId, $value['id']); }
@ -3625,7 +3626,7 @@ class EmployeeRestController extends AdminController
], 200);
}
public function getPreEmployeePolicyCount($mobile_no)
public function getPreEmployeePolicyCount($mobile_no, $clientId)
{
log_message('error', 'getPreEmployeePolicyCount called with mobile: ' . var_export($mobile_no, true));
@ -3656,7 +3657,12 @@ class EmployeeRestController extends AdminController
->where('cp.open_for_enrollment', 1)
->whereIn('cp.policy_type_id', [1,2,6,7])
->where('employees.mobile', $mobile_no)
->orderBy('employees.created_at', 'desc')
->groupBy('employee_polices.client_policy_id');
if(!empty($clientId)){
$builder->where('employees.client_id', $clientId);
}
log_message('error', 'Executing policy count query...');
$query = $builder->get();

View File

@ -290,65 +290,30 @@ class RestAuthenticationController extends AdminController
$requestData = $this->request->getJSON();
log_message('debug', 'Request data: ' . json_encode($requestData));
$mobile_number = $requestData->mobile_number ?? null;
$email_id = $requestData->email_id ?? null;
$new_mpin = $requestData->new_mpin ?? $requestData->mpin ?? null;
$old_mpin = $requestData->old_mpin ?? null;
$is_mpin_skipped = $requestData->is_mpin_skipped ?? null;
$is_biometric_enabled = $requestData->is_biometric_enabled ?? null;
$client_id = $requestData->client_id ?? null;
$employee_id = $requestData->employee_id ?? null;
$mpin = $requestData->mpin ?? null;
if (!$new_mpin) {
log_message('warning', 'MPIN is missing.');
if (!$mpin) {
log_message('error', 'MPIN is missing.');
return $this->response->setJSON(['status' => false, 'message' => 'MPIN is required.']);
}
$query = $this->employeeModel->where('relationship', 'self');
log_message('info', 'Query initialized with relationship=self');
if ($mobile_number) {
$query->where('mobile', $mobile_number);
log_message('info', "Filtering by mobile number: {$mobile_number}");
} elseif ($email_id) {
$query->where('email_corporate', $email_id);
log_message('info', "Filtering by email ID: {$email_id}");
} else {
log_message('warning', 'Neither mobile number nor email ID provided.');
return $this->response->setJSON(['status' => false, 'message' => 'Mobile number or Email ID is required.']);
if (!$employee_id) {
log_message('error', 'employee_id is missing.');
return $this->response->setJSON(['status' => false, 'message' => 'employee_id is required.']);
}
if (!empty($old_mpin)) {
$query->where('mpin', $old_mpin);
log_message('info', "Verifying old MPIN: {$old_mpin}");
}
$employeeData = $query->first();
log_message('debug', 'Employee lookup result: ' . json_encode($employeeData));
if (!$employeeData) {
log_message('warning', 'Employee not found or invalid old MPIN.');
return $this->response->setJSON(['status' => false, 'message' => 'Employee not found or invalid MPIN.']);
}
$mpin_data_to_update = ['mpin' => $new_mpin];
if ($is_mpin_skipped != null && $is_biometric_enabled != null) {
$mpin_data_to_update['is_mpin_skipped'] = $is_mpin_skipped;
$mpin_data_to_update['is_biometric_enabled'] = $is_biometric_enabled;
log_message('info', 'Updating MPIN, MPIN skip flag, and biometric flag.');
} else {
log_message('info', 'Updating MPIN only.');
}
$updated = $this->employeeModel->update($employeeData['id'], $mpin_data_to_update);
$updated = $this->employeeModel->where('id', $employee_id)->set(['mpin' => $mpin])->update();
if ($updated) {
log_message('info', "MPIN updated successfully for employee ID: {$employeeData['id']}");
log_message('info', "MPIN updated successfully for employee ID: {$employee_id}");
return $this->response->setJSON([
'status' => true,
'message' => 'MPIN updated successfully.'
]);
} else {
log_message('error', "Failed to update MPIN for employee ID: {$employeeData['id']}");
log_message('error', "Failed to update MPIN for employee ID: {$employee_id}");
return $this->response->setJSON([
'status' => false,
'message' => 'Failed to update MPIN.'