FIX_POLICY_COUNT : RV

This commit is contained in:
VENKATESHWARAN 2025-07-10 11:32:18 +05:30
parent 0c2f5ee4d1
commit d73cd89f8f
2 changed files with 69 additions and 2 deletions

View File

@ -507,5 +507,6 @@ $routes->get("sendCroneRemainderMail", "DashboardController::sendCroneRemainderM
$routes->get("getEmployeePolicy", "EmployeeRestController::getEmployeePolicy");
$routes->get("getAddOnPolicy", "EmployeeRestController::getAddOnPolicy");
$routes->post("addEmployeeAndDependence", "EmployeeRestController::addEmployeeAndDependence");
$routes->post("getPreEmployeePolicyCount", "EmployeeRestController::getPreEmployeePolicyCount");

View File

@ -3315,10 +3315,76 @@ class EmployeeRestController extends AdminController
return false;
}
public function getPreEmployeePolicyCount()
{
log_message('error', 'STEP 1: getPreEmployeePolicyCount API called');
$request = $this->request->getJSON(true);
$mobile_no = $request['mobile_number'] ?? null;
$client_short_name = $request['client_short_name'] ?? null;
log_message('error', 'STEP 2: Received input - ' . json_encode($request));
// Step 3: Fetch client ID based on short name
$clientId = null;
if (!empty($client_short_name)) {
log_message('error', 'STEP 3: Looking up client with short_name: ' . $client_short_name);
$client_data = $this->clientModel
->where('is_active', 1)
->where('short_name', $client_short_name)
->first();
if ($client_data) {
$clientId = $client_data['id'];
log_message('error', 'STEP 4: Found client ID: ' . $clientId);
} else {
log_message('error', 'STEP 4: No client found for short_name: ' . $client_short_name);
}
} else {
log_message('error', 'STEP 3: client_short_name is empty.');
}
// Step 5: Validate mobile number
if (empty($mobile_no)) {
log_message('error', 'STEP 5: Mobile number is empty or null. Returning 0.');
return $this->respond(['data' => 0]);
}
try {
log_message('error', 'STEP 6: Building employee policy count query');
$builder = $this->employeeModel
->join('employee_polices', 'employees.id = employee_polices.employee_id')
->join('client_policy cp', 'employee_polices.client_policy_id = cp.id')
->where('employees.is_active', 1)
->whereIn('employees.emp_status', ['draft', 'enrolled'])
->where('employee_polices.is_active', 1)
->whereIn('employee_polices.status', ['draft', 'enrolled'])
->where('cp.enrolment_visibility', 1)
->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', 'STEP 7: Applied client ID filter: ' . $clientId);
} else {
log_message('error', 'STEP 7: No client ID filter applied.');
}
$count = $builder->get()->getNumRows();
log_message('error', 'STEP 8: Final policy count = ' . $count);
return $this->respond(['data' => $count]);
} catch (\Throwable $e) {
log_message('error', 'STEP 9: Exception occurred - ' . $e->getMessage());
return $this->respond(['data' => 0]);
}
}
}