Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
35f4f90ef1
@ -529,7 +529,7 @@ class EmployeeRestController extends AdminController
|
||||
{
|
||||
$is_from_copy = $this->request->getGet('is_from_copy') ?? null;
|
||||
|
||||
if($is_from_copy == false && $is_from_copy == null){
|
||||
if($is_from_copy == 'false' || $is_from_copy == false || $is_from_copy == 'null' || $is_from_copy == null){
|
||||
|
||||
$this->employeeModel->where('id', $this->request->getGet('id') )
|
||||
->where('is_active', 1 )
|
||||
@ -3645,7 +3645,7 @@ class EmployeeRestController extends AdminController
|
||||
}
|
||||
|
||||
|
||||
public function getPreEmployeePolicyCount()
|
||||
public function getPreEmployeePolicyCountOld()
|
||||
{
|
||||
log_message('error', 'STEP 1: getPreEmployeePolicyCount API called');
|
||||
|
||||
@ -3692,10 +3692,10 @@ class EmployeeRestController extends AdminController
|
||||
->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'])
|
||||
->whereIn('employees.emp_status', ['draft', 'enrolled'])
|
||||
->where('employees.family_floater_key', 'self')
|
||||
->where('employee_polices.is_active', 1)
|
||||
->whereIn('employee_polices.status', ['draft'])
|
||||
->whereIn('employee_polices.status', ['draft', 'enrolled'])
|
||||
->where('cp.enrolment_visibility', 1)
|
||||
->where('cp.open_for_enrollment', 1)
|
||||
->where('cp.policy_status', 1)
|
||||
@ -3730,6 +3730,157 @@ class EmployeeRestController extends AdminController
|
||||
}
|
||||
}
|
||||
|
||||
public function getPreEmployeePolicyCount()
|
||||
{
|
||||
log_message('error', 'STEP 1: getPreEmployeePolicyCount API called');
|
||||
|
||||
$request = $this->request->getJSON(true);
|
||||
$mobile_no = $request['mobile_number'] ?? null;
|
||||
$email_id = $request['email_id'] ?? null;
|
||||
$client_short_name = $request['client_short_name'] ?? null;
|
||||
|
||||
log_message('error', 'STEP 2: Received input - ' . json_encode($request));
|
||||
|
||||
/** ---------------------------------------------------------------
|
||||
* STEP 3: Resolve Client ID (If client_short_name passed)
|
||||
* --------------------------------------------------------------- */
|
||||
$clientId = null;
|
||||
if (!empty($client_short_name)) {
|
||||
log_message('error', 'STEP 3: Looking up client with short_name: ' . $client_short_name);
|
||||
|
||||
$client = $this->clientModel
|
||||
->select('id')
|
||||
->where('is_active', 1)
|
||||
->where('short_name', $client_short_name)
|
||||
->first();
|
||||
|
||||
if (!empty($client)) {
|
||||
$clientId = $client['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 4: Validate Request (either mobile or email is required)
|
||||
* --------------------------------------------------------------- */
|
||||
if (empty($mobile_no) && empty($email_id)) {
|
||||
log_message('error', 'STEP 5: Mobile number and Email both empty. Returning 0.');
|
||||
return $this->respond(['data' => 0, 'empNotEnrolledCount' => 0]);
|
||||
}
|
||||
|
||||
try {
|
||||
/** ---------------------------------------------------------------
|
||||
* STEP 6: Base Query Builder (extract common conditions)
|
||||
* --------------------------------------------------------------- */
|
||||
$baseQuery = $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)
|
||||
->where('employee_polices.is_active', 1)
|
||||
->where('cp.enrolment_visibility', 1)
|
||||
->where('cp.open_for_enrollment', 1)
|
||||
->where('cp.policy_status', 1)
|
||||
->whereIn('cp.policy_type_id', [1, 2, 3, 6, 7])
|
||||
->orderBy('employees.created_at', 'desc')
|
||||
->groupBy('employee_polices.client_policy_id');
|
||||
|
||||
// 🔹 Apply Client Filter if Provided
|
||||
if (!empty($clientId)) {
|
||||
$baseQuery->where('employees.client_id', $clientId);
|
||||
log_message('error', 'Applied client ID filter: ' . $clientId);
|
||||
}
|
||||
|
||||
// 🔹 Apply Mobile Filter if Provided
|
||||
if (!empty($mobile_no)) {
|
||||
$baseQuery->where('employees.mobile', $mobile_no);
|
||||
log_message('error', 'Applied mobile_no filter: ' . $mobile_no);
|
||||
}
|
||||
|
||||
// 🔹 Apply Email Filter if Provided
|
||||
if (!empty($email_id)) {
|
||||
$baseQuery->where('employees.email_corporate', $email_id);
|
||||
log_message('error', 'Applied email_id filter: ' . $email_id);
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------------------
|
||||
* STEP 7: Count Enrolled + Draft (eligible)
|
||||
* --------------------------------------------------------------- */
|
||||
$baseQuery->whereIn('employees.emp_status', ['draft', 'enrolled'])
|
||||
->whereIn('employee_polices.status', ['draft', 'enrolled'])
|
||||
->where('employees.family_floater_key', 'self');
|
||||
|
||||
$count = $baseQuery->get()->getNumRows();
|
||||
log_message('error', 'Eligible policy count = ' . $count);
|
||||
|
||||
/** ---------------------------------------------------------------
|
||||
* STEP 8: Count Only Draft (Not Enrolled yet)
|
||||
* --------------------------------------------------------------- */
|
||||
$notEnrolledQuery = $this->employeeModel
|
||||
->select("
|
||||
(
|
||||
SELECT COUNT(e2.id)
|
||||
FROM employees AS e2
|
||||
WHERE e2.is_active = 1
|
||||
AND e2.emp_status = 'draft'
|
||||
AND e2.emp_code = employees.emp_code
|
||||
) AS draft_count
|
||||
")
|
||||
->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)
|
||||
->where('employee_polices.is_active', 1)
|
||||
->where('cp.enrolment_visibility', 1)
|
||||
->where('cp.open_for_enrollment', 1)
|
||||
->where('cp.policy_status', 1)
|
||||
->whereIn('cp.policy_type_id', [1, 2, 3, 6, 7])
|
||||
->orderBy('employees.created_at', 'desc');
|
||||
|
||||
// 🔹 Apply Client Filter if Provided
|
||||
if (!empty($clientId)) {
|
||||
$notEnrolledQuery->where('employees.client_id', $clientId);
|
||||
log_message('error', 'Applied client ID filter: ' . $clientId);
|
||||
}
|
||||
|
||||
// 🔹 Apply Mobile Filter if Provided
|
||||
if (!empty($mobile_no)) {
|
||||
$notEnrolledQuery->where('employees.mobile', $mobile_no);
|
||||
log_message('error', 'Applied mobile_no filter: ' . $mobile_no);
|
||||
}
|
||||
|
||||
// 🔹 Apply Email Filter if Provided
|
||||
if (!empty($email_id)) {
|
||||
$notEnrolledQuery->where('employees.email_corporate', $email_id);
|
||||
log_message('error', 'Applied email_id filter: ' . $email_id);
|
||||
}
|
||||
|
||||
$notEnrolledQuery->whereIn('employees.emp_status', ['draft'])
|
||||
->whereIn('employee_polices.status', ['draft']);
|
||||
|
||||
$not_enrolled_count = $notEnrolledQuery->get()->getRowArray()['draft_count'] ?? 0;
|
||||
log_message('error', 'Not enrolled policy count = ' . $not_enrolled_count);
|
||||
|
||||
/** ---------------------------------------------------------------
|
||||
* STEP 9: Final Response
|
||||
* --------------------------------------------------------------- */
|
||||
return $this->respond([
|
||||
'pre_policy_count' => $count,
|
||||
'emp_not_enrolled_count' => (int) $not_enrolled_count
|
||||
]);
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
log_message('error', 'Exception occurred: ' . $e->getMessage());
|
||||
return $this->respond([
|
||||
'pre_policy_count' => 0,
|
||||
'emp_not_enrolled_count' => 0
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------
|
||||
|
||||
Loading…
Reference in New Issue
Block a user