CHANGE_HR_PRE_POLICY_COUNT_AND_POLICY_LIST

This commit is contained in:
VENKATESHWARAN 2026-06-23 12:55:03 +05:30
parent 38f04bb176
commit fe40fbc5d8
3 changed files with 90 additions and 27 deletions

View File

@ -3162,8 +3162,9 @@ class EmployeeRestController extends AdminController
public function getPolicyLevelEmployeeSummaryData()
{
$hr_id = $this->request->getGet('hr_id');
$client_id = $this->request->getGet('client_id');
$client_branch_id = $this->request->getGet('client_branch_id');
$restAuthController = new RestAuthenticationController;
//call and get allowed policy data from post enrollment
$queryParams = [
@ -3174,35 +3175,78 @@ class EmployeeRestController extends AdminController
$HRAccessData = json_decode($HRAccessRes,true);
if(isset($HRAccessData['data']['allowed_pre_policies']))
{
$policyId = json_decode($HRAccessData['data']['allowed_pre_policies'],true);
$allowedPolicyIds = json_decode($HRAccessData['data']['allowed_pre_policies'],true);
}else{
$policyId = [];
$allowedPolicyIds = [];
}
if(count($policyId) == 0){
return $this->respond(['status' => 'failed','code' => (count($policyId) ? 200 : 200),'data' => [] ], 200);
if(empty($allowedPolicyIds)){
return $this->respond(['status' => 'failed','code' => 200,'data' => [] ], 200);
}
$openEnrollmentPolicies = $this->employeePolicyModel
->select('employee_polices.client_policy_id')
->join('employees', 'employee_polices.employee_id = employees.id')
->whereIn('employee_polices.client_policy_id', $allowedPolicyIds)
->where('md5(employees.client_id)', $client_id)
->where('employees.client_branch_id', $client_branch_id)
->where('employee_polices.enrollment_open_date <= CURDATE()', null, false)
->where('employee_polices.enrollment_close_date >= CURDATE()', null, false)
->where('employee_polices.enrollment_open_date IS NOT NULL', null, false)
->where('employee_polices.enrollment_close_date IS NOT NULL', null, false)
->where('employees.is_active', 1)
->where('employee_polices.is_active', 1)
->whereIn('employee_polices.status', ['draft', 'enrolled'])
->whereIn('employees.emp_status', ['draft', 'enrolled'])
->groupBy('employee_polices.client_policy_id')
->findAll();
$policyId = array_column($openEnrollmentPolicies, 'client_policy_id');
if(empty($policyId)){
return $this->respond(['status' => 'failed','code' => 200,'data' => [] ], 200);
}
$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, client_policy.policy_no as policy_no, client_policy.insurer_id as insurer_id, DATE_FORMAT(client_policy.policy_end_date, "%d-%m-%Y") AS policy_expiry_date ')
->where('md5(client_policy.client_id)', $this->request->getGet('client_id') )
->where('client_policy.client_branch_id', $this->request->getGet('client_branch_id') )
->where('md5(client_policy.client_id)', $client_id )
->where('client_policy.client_branch_id', $client_branch_id )
->where('client_policy.is_active', 1 )
->where('client_policy.policy_status', 1)
->whereIn('client_policy.id', $policyId)
->findAll();
$loggedInCounts = [];
$clientPolicyIds = array_column($ClientPolicyData, 'client_policy_id');
if (!empty($clientPolicyIds)) {
$loggedInRows = $this->employeeModel
->select('employee_polices.client_policy_id, COUNT(DISTINCT employees.id) as logged_in_count')
->join('employee_polices', 'employees.id = employee_polices.employee_id')
->join('auth_history', 'employees.id = auth_history.user_id AND auth_history.user_type = "employee"', 'inner')
->whereIn('employee_polices.client_policy_id', $clientPolicyIds)
->where('md5(employees.client_id)', $client_id)
->where('employees.client_branch_id', $client_branch_id)
->where('employees.relationship', 'Self')
->where('employees.is_active', 1)
->where('employee_polices.is_active', 1)
->groupBy('employee_polices.client_policy_id')
->findAll();
foreach ($loggedInRows as $loggedInRow) {
$loggedInCounts[$loggedInRow['client_policy_id']] = (int) $loggedInRow['logged_in_count'];
}
}
$result = [];
// dd( $ClientPolicyData);
foreach ($ClientPolicyData as $key => $value)
{
$policyTypeData = $this->policyTypeModel->where('id',$value['policy_type_id'])->get()->getRow();
$insurerData = $this->insurerModel->where('id',$value['insurer_id'])->get()->getRow();
$value['type'] = $policyTypeData->policy_type;
$value['policy_name'] = $policyTypeData->long_name;
$value['type'] = $policyTypeData->policy_type ?? null;
$value['policy_name'] = $policyTypeData->long_name ?? null;
$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'));
$employeeDetails = $this->employeePolicyModel->getEmployeePolicy( client_id:$value['client_id'],policy_id: $value['client_policy_id'],status:0,branch_id:$client_branch_id);
$enrolledCount = 0;
$draftCount = 0;
if(count($employeeDetails))
@ -3219,18 +3263,17 @@ class EmployeeRestController extends AdminController
$value['totalMembersCount'] = count($employeeDetails);
$value['membersCountOfEnrolled'] = $enrolledCount;
$value['membersCountOfDraft'] = $draftCount;
$value['membersCountOfLoggedIn'] = $loggedInCounts[$value['client_policy_id']] ?? 0;
array_push($result,$value);
}
if($result)
{
return $this->respond(['status' => 'success','code' => (count($result) ? 200 : 200),'data' => $result ], 200);
return $this->respond(['status' => 'success','code' => 200,'data' => $result ], 200);
}else{
return $this->respond(['status' => 'failed','code' => (count($result) ? 200 : 200),'data' => [] ], 200);
return $this->respond(['status' => 'failed','code' => 200,'data' => [] ], 200);
}
}

View File

@ -88,14 +88,14 @@ class EmployeePolicyModel extends Model
$status_query = "employee_polices.status"; // Default fallback
if ($status_type == "hr") {
$status_query = "CASE
WHEN employee_polices.status = 'enrolled' THEN 'under process'
ELSE employee_polices.status
END as status";
}
// if ($status_type == "hr") {
// $status_query = "CASE
// WHEN employee_polices.status = 'enrolled' THEN 'under process'
// ELSE employee_polices.status
// END as status";
// }
$result = $this->select([
$selectColumns = [
'employee_polices.*',
'policy_type.policy_type as policy_name',
'im.short_name as insurer_short_name',
@ -214,9 +214,19 @@ class EmployeePolicyModel extends Model
ELSE NULL
END
)) AS newly_added_updated_at",
];
$status_query
], false)
if ($status_type === 'hr') {
$selectColumns[] = "(CASE
WHEN emp.relationship = 'Self'
THEN IF(auth_history.user_id IS NOT NULL, 'Yes', 'No')
ELSE NULL
END) AS logged_in";
}
$selectColumns[] = $status_query;
$result = $this->select($selectColumns, false)
->join('employees emp', 'employee_polices.employee_id = emp.id')
->join('client_policy cp', 'employee_polices.client_policy_id = cp.id') //cp - client policy
->join('policies pm', 'cp.policy_id = pm.id', 'left') //pm - policy master
@ -226,8 +236,18 @@ class EmployeePolicyModel extends Model
->join('tpa tpam', 'cp.tpa_id = tpam.id', 'left') //tpam - tpa master
->join('tpa_branch tpab', 'cp.tpa_branch_id = tpab.id', 'left') //tpab - tpa branch
->join('clients cm', 'cp.client_id = cm.id') //cm - client master
->join('client_branch', 'emp.client_branch_id = client_branch.id') //cm - client master
->orderBy('emp.emp_code', 'ASC')
->join('client_branch', 'emp.client_branch_id = client_branch.id'); //cm - client master
if ($status_type === 'hr') {
$result->join(
"(SELECT user_id FROM auth_history WHERE user_type = 'employee' GROUP BY user_id) auth_history",
'emp.id = auth_history.user_id',
'left',
false
);
}
$result->orderBy('emp.emp_code', 'ASC')
->orderBy('employee_polices.employee_id', 'ASC');

Binary file not shown.