CHANGE_THE_EMP_GET_API
This commit is contained in:
parent
bd46bd2e8b
commit
7dbdf444a0
@ -691,26 +691,139 @@ class EmployeeRestController extends AdminController
|
||||
public function getEmployeeAndDependenceByClientId()
|
||||
{
|
||||
try {
|
||||
$empData = $this->employeePolicyModel->getEmployeePolicy(
|
||||
$cardDataParam = strtolower(trim((string) ($this->request->getGet('card_data') ?? '')));
|
||||
$cardDataParam = str_replace(['-', ' '], '_', $cardDataParam);
|
||||
$search = trim((string) ($this->request->getGet('search') ?? ''));
|
||||
|
||||
$cardFilters = ['all', 'emp_count', 'submitted', 'logged_in', 'not_logged_in', 'draft'];
|
||||
|
||||
$empData = $this->employeePolicyModel->getEmployeePolicy(
|
||||
client_id: $this->request->getGet('client_id'),
|
||||
policy_id: $this->request->getGet('client_policy_id'),
|
||||
status: 0,
|
||||
branch_id: $this->request->getGet('client_branch_id'),
|
||||
status_type: 'hr',
|
||||
search: trim((string) ($this->request->getGet('search') ?? ''))
|
||||
);
|
||||
|
||||
search: $cardDataParam === 'all' ? '' : $search
|
||||
) ?: [];
|
||||
|
||||
if (in_array($cardDataParam, $cardFilters, true)) {
|
||||
$response = $this->prepareMemberCardDataResponse($empData, $cardDataParam);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'code' => 200,
|
||||
'data' => $response['data'],
|
||||
'card_data' => $response['card_data'],
|
||||
], 200);
|
||||
}
|
||||
|
||||
if ($empData) {
|
||||
return $this->respond(['status' => 'success', 'code' => 200, 'data' => $empData], 200);
|
||||
} else {
|
||||
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => []], 200);
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => []], 200);
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Build Member Details response for card_data filters (Self relationship only).
|
||||
*
|
||||
* @return array{data: array, card_data: array}
|
||||
*/
|
||||
private function prepareMemberCardDataResponse(array $empData, string $cardDataParam): array
|
||||
{
|
||||
$cardData = $this->buildMemberCardData($empData);
|
||||
|
||||
if ($cardDataParam === 'all') {
|
||||
return [
|
||||
'data' => [],
|
||||
'card_data' => $cardData,
|
||||
];
|
||||
}
|
||||
|
||||
$filteredData = array_values(array_filter($empData, function ($row) use ($cardDataParam) {
|
||||
return $this->matchesMemberCardFilter($row, $cardDataParam);
|
||||
}));
|
||||
|
||||
return [
|
||||
'data' => $filteredData,
|
||||
'card_data' => $cardData,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a row matches the selected card filter (Self only).
|
||||
*/
|
||||
private function matchesMemberCardFilter(array $row, string $cardDataParam): bool
|
||||
{
|
||||
if (strtolower(trim((string) ($row['relationship'] ?? ''))) !== 'self') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($cardDataParam === 'emp_count') {
|
||||
return true;
|
||||
}
|
||||
|
||||
$status = strtolower(trim((string) ($row['status'] ?? '')));
|
||||
$empStatus = strtolower(trim((string) ($row['emp_status'] ?? '')));
|
||||
$isSubmitted = in_array($status, ['submitted', 'enrolled'], true)
|
||||
|| $empStatus === 'enrolled';
|
||||
$isLoggedIn = strtolower((string) ($row['logged_in'] ?? '')) === 'yes';
|
||||
|
||||
return match ($cardDataParam) {
|
||||
'submitted' => $isSubmitted,
|
||||
'logged_in' => $isLoggedIn,
|
||||
'not_logged_in' => !$isLoggedIn,
|
||||
'draft' => !$isSubmitted,
|
||||
default => false,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Member Details badge counts — Self relationship only.
|
||||
*/
|
||||
private function buildMemberCardData(array $empData): array
|
||||
{
|
||||
$counts = [
|
||||
'emp_count' => 0,
|
||||
'submitted' => 0,
|
||||
'logged_in' => 0,
|
||||
'not_logged_in' => 0,
|
||||
'draft' => 0,
|
||||
];
|
||||
|
||||
foreach ($empData as $row) {
|
||||
if (strtolower(trim((string) ($row['relationship'] ?? ''))) !== 'self') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$counts['emp_count']++;
|
||||
|
||||
$status = strtolower(trim((string) ($row['status'] ?? '')));
|
||||
$empStatus = strtolower(trim((string) ($row['emp_status'] ?? '')));
|
||||
$isSubmitted = in_array($status, ['submitted', 'enrolled'], true)
|
||||
|| $empStatus === 'enrolled';
|
||||
|
||||
if ($isSubmitted) {
|
||||
$counts['submitted']++;
|
||||
}
|
||||
|
||||
$isLoggedIn = strtolower((string) ($row['logged_in'] ?? '')) === 'yes';
|
||||
if ($isLoggedIn) {
|
||||
$counts['logged_in']++;
|
||||
} else {
|
||||
$counts['not_logged_in']++;
|
||||
}
|
||||
|
||||
// Draft = Self who has not submitted (matches Emp Count - Submitted).
|
||||
if (!$isSubmitted) {
|
||||
$counts['draft']++;
|
||||
}
|
||||
}
|
||||
|
||||
return $counts;
|
||||
}
|
||||
|
||||
public function exportDataByClientPolicyId()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user