Compare commits
216 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b81c70fd4e | ||
|
|
58cc95d7d0 | ||
|
|
a8a6a6943c | ||
|
|
571f8fcc36 | ||
|
|
1c5a14475f | ||
|
|
7827ce17ed | ||
|
|
297c1da9ca | ||
|
|
74a7626973 | ||
|
|
10fc5c8e26 | ||
|
|
3881263b30 | ||
|
|
2b02e66225 | ||
|
|
a9c2ee4d39 | ||
|
|
48af9788a6 | ||
|
|
c5fcb67949 | ||
|
|
2c0dabf150 | ||
|
|
17e56f4e83 | ||
|
|
8cbd6002f3 | ||
|
|
fd0e76ba34 | ||
|
|
60f27c56a9 | ||
|
|
5b95279b64 | ||
|
|
dd15651966 | ||
|
|
af010ef913 | ||
|
|
27490efb9d | ||
|
|
21815f75d0 | ||
|
|
4ebd27090a | ||
|
|
a5ef6e21cf | ||
|
|
ebeff19d75 | ||
|
|
5b3f39ccb7 | ||
|
|
2a0d26a4ab | ||
|
|
415bf08983 | ||
|
|
af89c9e0d4 | ||
|
|
08211c2c33 | ||
|
|
d44edd14fe | ||
|
|
8c1c99b7cf | ||
|
|
9b816e6ffe | ||
|
|
78eec85f4d | ||
|
|
1d8b0faedb | ||
|
|
f3e6878bd0 | ||
|
|
1ebcb299e3 | ||
|
|
debefacdec | ||
|
|
d51be53bf1 | ||
|
|
5972ca802d | ||
|
|
e12ddfa326 | ||
|
|
1143f6c1a0 | ||
|
|
c8b32c8b2f | ||
|
|
6708ba2593 | ||
|
|
9f4f35e3d2 | ||
|
|
7d382a1eb2 | ||
|
|
940d568ead | ||
|
|
7c9880cd0a | ||
|
|
7c18705e75 | ||
|
|
bfb1406043 | ||
|
|
694ad36865 | ||
|
|
296d10142f | ||
|
|
65e5f3db24 | ||
|
|
3bea33033a | ||
|
|
8881496db5 | ||
|
|
4abaa59f5b | ||
|
|
e0e298c107 | ||
|
|
3552f6def4 | ||
|
|
e4e5c812e9 | ||
|
|
50f758c4f0 | ||
|
|
92d1b495ff | ||
|
|
ca24e29817 | ||
|
|
0a14d12a17 | ||
|
|
049ddc7867 | ||
|
|
57837dd38b | ||
|
|
a7268b1274 | ||
|
|
0b7ad7ce15 | ||
|
|
ecf4b60e21 | ||
|
|
ea42906717 | ||
|
|
15683de668 | ||
|
|
ce109c9792 | ||
|
|
7607c87387 | ||
|
|
2c341e9311 | ||
|
|
111f35d1af | ||
|
|
0f1d77c009 | ||
|
|
13f4129b7c | ||
|
|
cab52deccc | ||
|
|
62e7c54763 | ||
|
|
d6e5fa3832 | ||
|
|
050e1e9714 | ||
|
|
c494d909ec | ||
|
|
3eccfaa678 | ||
|
|
2b3969399c | ||
|
|
6574e603f4 | ||
|
|
15a57136a4 | ||
|
|
45743d57e5 | ||
|
|
530043c7bd | ||
|
|
1e779e4a74 | ||
|
|
cb5d871d0e | ||
|
|
329e9ca991 | ||
|
|
5dc8844c8e | ||
|
|
87b39097f0 | ||
|
|
0b55c1473f | ||
|
|
bb90a2642b | ||
|
|
ee9eeb95c2 | ||
|
|
0769ecba33 | ||
|
|
0d3f7d7e77 | ||
|
|
054fe57afe | ||
|
|
6cf8097590 | ||
|
|
8baaabb9e6 | ||
|
|
e1272226b7 | ||
|
|
5433b49347 | ||
|
|
1b34fc19bc | ||
|
|
01652cd7d8 | ||
|
|
5913b65864 | ||
|
|
7600453df6 | ||
|
|
b6ecb1a565 | ||
|
|
9b2599e42d | ||
|
|
ffbe751089 | ||
|
|
684bddd93d | ||
|
|
c4feb6d8e3 | ||
|
|
276fd10f20 | ||
|
|
9bed8731ec | ||
|
|
a1cfc45f15 | ||
|
|
9e1f8091ca | ||
|
|
5a6f3421f8 | ||
|
|
f188594fa2 | ||
|
|
bfc7d94ead | ||
|
|
59aeb3cd4c | ||
|
|
8c49be7f9a | ||
|
|
6e7f253dc1 | ||
|
|
afa4bc99b8 | ||
|
|
9a3e3fbfb6 | ||
|
|
e7e768b193 | ||
|
|
e2662624e7 | ||
|
|
0c39deb2e1 | ||
|
|
fe72e36d0e | ||
|
|
60a62bb24e | ||
|
|
3681a22f9e | ||
|
|
900a1bb0c7 | ||
|
|
0795b1527c | ||
|
|
b25db36699 | ||
|
|
ce610218e9 | ||
|
|
02e8b37625 | ||
|
|
fb992a50eb | ||
|
|
fa8b38c4f4 | ||
|
|
f338613264 | ||
|
|
2b73fbaa3c | ||
|
|
658615a322 | ||
|
|
c3408b6307 | ||
|
|
c473c8572b | ||
|
|
76b6221ca2 | ||
|
|
8bc77a4fce | ||
|
|
b45b639af4 | ||
|
|
2a6da8c70e | ||
|
|
649bf560c8 | ||
|
|
1b410f7c59 | ||
|
|
efa1832184 | ||
|
|
cb4aa5592c | ||
|
|
ebca238487 | ||
|
|
79bdb310e3 | ||
|
|
dfa0df5388 | ||
|
|
7da57e08d9 | ||
|
|
f8422c7178 | ||
|
|
18424b8cff | ||
|
|
8f50c64d00 | ||
|
|
86d7a5e77c | ||
|
|
25f86c7bb1 | ||
|
|
c70312a545 | ||
|
|
03763fc23a | ||
|
|
d460221f2f | ||
|
|
9216b857e1 | ||
|
|
71c12b1836 | ||
|
|
6f35703777 | ||
|
|
4d6c081ad8 | ||
|
|
c9563d2b1b | ||
|
|
34faa18b12 | ||
|
|
de5dde0234 | ||
|
|
d237d79863 | ||
|
|
380c7e1af3 | ||
|
|
2d64fd92a4 | ||
|
|
aca3acc24c | ||
|
|
357fb69fa3 | ||
|
|
d3a679576c | ||
|
|
f547989b55 | ||
|
|
259e82f74b | ||
|
|
694663389d | ||
|
|
386f44943e | ||
|
|
ff189e98bb | ||
|
|
0aeed144fc | ||
|
|
3071002c59 | ||
|
|
d8bdc78148 | ||
|
|
0eed656a70 | ||
|
|
a99c9d8f74 | ||
|
|
3caa5de0a0 | ||
|
|
255ccd7dfe | ||
|
|
f0d33eed8c | ||
|
|
039dd3b47f | ||
|
|
2ac673e187 | ||
|
|
cdadd1ebf3 | ||
|
|
da4297afda | ||
|
|
ad8f65110e | ||
|
|
f4236ee51c | ||
|
|
91709c0657 | ||
|
|
6583985722 | ||
|
|
c34d6167d0 | ||
|
|
77beddccec | ||
|
|
d86cc0ce23 | ||
|
|
ab337cf670 | ||
|
|
703d21d605 | ||
|
|
daae740799 | ||
|
|
e30491891c | ||
|
|
7be290fc02 | ||
|
|
a19731f82f | ||
|
|
d2269334a0 | ||
|
|
e5a620158c | ||
|
|
9231391b7c | ||
|
|
3d29b0753b | ||
|
|
4811c13f09 | ||
|
|
5a2a5feabc | ||
|
|
e03c438172 | ||
|
|
12b8409200 | ||
|
|
730b0a6075 | ||
|
|
63a077e3e5 |
@ -1,189 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Manual test for EmployeePolicyModel global search.
|
||||
*
|
||||
* Usage:
|
||||
* php spark test:employee-global-search
|
||||
* php spark test:employee-global-search --search Self
|
||||
* php spark test:employee-global-search --client_id cede2d63a7c04ebd4cb55a2228c7141a --client_policy_id 5769 --client_branch_id 444 --search john
|
||||
*/
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Models\EmployeePolicyModel;
|
||||
use CodeIgniter\CLI\BaseCommand;
|
||||
use CodeIgniter\CLI\CLI;
|
||||
use Config\Database;
|
||||
|
||||
class TestEmployeeGlobalSearch extends BaseCommand
|
||||
{
|
||||
protected $group = 'Testing';
|
||||
protected $name = 'test:employee-global-search';
|
||||
protected $description = 'Test getEmployeePolicy global search (emp_code, name, mobile, email, tpa_id, dob, relationship, status)';
|
||||
protected $usage = 'test:employee-global-search [--client_id ...] [--client_policy_id ...] [--client_branch_id ...] [--search ...]';
|
||||
|
||||
protected $options = [
|
||||
'--client_id' => 'Client id (md5 hash or numeric)',
|
||||
'--client_policy_id' => 'Client policy id',
|
||||
'--client_branch_id' => 'Client branch id',
|
||||
'--search' => 'Global search term',
|
||||
'--limit' => 'Max rows to print (default 10)',
|
||||
];
|
||||
|
||||
public function run(array $params)
|
||||
{
|
||||
$clientId = $this->optionValue($params, 'client_id', 'cede2d63a7c04ebd4cb55a2228c7141a');
|
||||
$clientPolicyId = $this->optionValue($params, 'client_policy_id', '5769');
|
||||
$clientBranchId = $this->optionValue($params, 'client_branch_id', '444');
|
||||
$search = $this->optionValue($params, 'search', '');
|
||||
$limit = (int) $this->optionValue($params, 'limit', '10');
|
||||
|
||||
$model = new EmployeePolicyModel();
|
||||
|
||||
$withoutSearch = $model->getEmployeePolicy(
|
||||
client_id: $clientId,
|
||||
policy_id: $clientPolicyId,
|
||||
status: 0,
|
||||
branch_id: $clientBranchId,
|
||||
status_type: 'hr'
|
||||
);
|
||||
|
||||
// Fallback to a real active employee_policy row when defaults have no data
|
||||
if (count($withoutSearch) === 0 && !$this->hasExplicitIds($params)) {
|
||||
$fixture = $this->findSampleIds();
|
||||
if ($fixture === null) {
|
||||
CLI::error('No active employee_policy rows found to test against.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$clientId = (string) $fixture['client_id'];
|
||||
$clientPolicyId = (string) $fixture['client_policy_id'];
|
||||
$clientBranchId = (string) $fixture['client_branch_id'];
|
||||
|
||||
CLI::write('Default IDs had no rows. Using sample from DB:', 'yellow');
|
||||
CLI::write(" client_id : {$clientId}");
|
||||
CLI::write(" client_policy_id : {$clientPolicyId}");
|
||||
CLI::write(" client_branch_id : {$clientBranchId}");
|
||||
CLI::newLine();
|
||||
|
||||
$withoutSearch = $model->getEmployeePolicy(
|
||||
client_id: $clientId,
|
||||
policy_id: $clientPolicyId,
|
||||
status: 0,
|
||||
branch_id: $clientBranchId,
|
||||
status_type: 'hr'
|
||||
);
|
||||
}
|
||||
|
||||
if ($search === '' && count($withoutSearch) > 0) {
|
||||
$search = (string) ($withoutSearch[0]['emp_code'] ?? $withoutSearch[0]['name'] ?? 'Self');
|
||||
CLI::write("No --search given. Using sample term from first row: {$search}", 'yellow');
|
||||
CLI::newLine();
|
||||
}
|
||||
|
||||
CLI::write('Params:', 'yellow');
|
||||
CLI::write(" client_id : {$clientId}");
|
||||
CLI::write(" client_policy_id : {$clientPolicyId}");
|
||||
CLI::write(" client_branch_id : {$clientBranchId}");
|
||||
CLI::write(' search : ' . ($search !== '' ? $search : '(none)'));
|
||||
CLI::newLine();
|
||||
|
||||
$withSearch = $model->getEmployeePolicy(
|
||||
client_id: $clientId,
|
||||
policy_id: $clientPolicyId,
|
||||
status: 0,
|
||||
branch_id: $clientBranchId,
|
||||
status_type: 'hr',
|
||||
search: $search
|
||||
);
|
||||
|
||||
CLI::write('Result counts:', 'green');
|
||||
CLI::write(' without search : ' . count($withoutSearch));
|
||||
CLI::write(' with search : ' . count($withSearch));
|
||||
CLI::newLine();
|
||||
|
||||
$rows = $search !== '' ? $withSearch : $withoutSearch;
|
||||
$preview = array_slice($rows, 0, max(1, $limit));
|
||||
|
||||
CLI::write('Preview fields (emp_code | name | mobile | email | tpa_id | dob | relationship | status):', 'yellow');
|
||||
foreach ($preview as $i => $row) {
|
||||
CLI::write(sprintf(
|
||||
'%d) %s | %s | %s | %s | %s | %s | %s | %s',
|
||||
$i + 1,
|
||||
$row['emp_code'] ?? '',
|
||||
$row['name'] ?? '',
|
||||
$row['mobile'] ?? '',
|
||||
$row['email_corporate'] ?? '',
|
||||
$row['tpa_id'] ?? '',
|
||||
$row['formatted_dob'] ?? ($row['dob'] ?? ''),
|
||||
$row['relationship'] ?? '',
|
||||
$row['status'] ?? ($row['emp_status'] ?? '')
|
||||
));
|
||||
}
|
||||
|
||||
if (count($rows) > $limit) {
|
||||
CLI::write('... ' . (count($rows) - $limit) . ' more row(s)');
|
||||
}
|
||||
|
||||
if ($search !== '' && count($withSearch) > 0) {
|
||||
CLI::newLine();
|
||||
CLI::write('Matched sample JSON:', 'green');
|
||||
CLI::write(json_encode(array_map(static function ($row) {
|
||||
return [
|
||||
'emp_code' => $row['emp_code'] ?? null,
|
||||
'name' => $row['name'] ?? null,
|
||||
'mobile' => $row['mobile'] ?? null,
|
||||
'email_corporate' => $row['email_corporate'] ?? null,
|
||||
'tpa_id' => $row['tpa_id'] ?? null,
|
||||
'dob' => $row['dob'] ?? null,
|
||||
'formatted_dob' => $row['formatted_dob'] ?? null,
|
||||
'relationship' => $row['relationship'] ?? null,
|
||||
'status' => $row['status'] ?? null,
|
||||
'emp_status' => $row['emp_status'] ?? null,
|
||||
];
|
||||
}, array_slice($withSearch, 0, 3)), JSON_PRETTY_PRINT));
|
||||
} elseif ($search !== '') {
|
||||
CLI::write('No rows matched the search term.', 'red');
|
||||
}
|
||||
}
|
||||
|
||||
private function optionValue(array $params, string $name, string $default = ''): string
|
||||
{
|
||||
$value = $params[$name] ?? CLI::getOption($name);
|
||||
if ($value === null || $value === false || $value === '') {
|
||||
return $default;
|
||||
}
|
||||
|
||||
return (string) $value;
|
||||
}
|
||||
|
||||
private function hasExplicitIds(array $params): bool
|
||||
{
|
||||
foreach (['client_id', 'client_policy_id', 'client_branch_id'] as $key) {
|
||||
$value = $params[$key] ?? CLI::getOption($key);
|
||||
if ($value !== null && $value !== false && $value !== '') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function findSampleIds(): ?array
|
||||
{
|
||||
$db = Database::connect('default');
|
||||
$row = $db->query(
|
||||
"SELECT emp.client_id, ep.client_policy_id, emp.client_branch_id
|
||||
FROM employee_polices ep
|
||||
JOIN employees emp ON emp.id = ep.employee_id
|
||||
WHERE ep.is_active = 1
|
||||
AND emp.is_active = 1
|
||||
ORDER BY ep.id DESC
|
||||
LIMIT 1"
|
||||
)->getRowArray();
|
||||
|
||||
return $row ?: null;
|
||||
}
|
||||
}
|
||||
@ -363,7 +363,7 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) {
|
||||
$routes->post('checkSIMapping','ClientController::checkSIMapping');
|
||||
$routes->post('deleteMapping','ClientController::deleteMapping');
|
||||
$routes->get('removeLevelContacts','ClientController::removeLevelContacts');
|
||||
$routes->get("downloadEmployeeListExcel", "EmployeeRestController::downloadEmployeeListExcel");
|
||||
|
||||
});
|
||||
|
||||
$routes->group("policy_tranction", ["filter" => "authMVC"], function ($routes) {
|
||||
@ -488,7 +488,6 @@ $routes->group("employeeRest", ['filter' => [ 'GlobalPostFileUploadGuard', 'appS
|
||||
$routes->post("iAgreeForAddOn", "EmployeeRestController::iAgreeForAddOn");
|
||||
|
||||
$routes->get("exportDataByClientPolicyId", "EmployeeRestController::exportDataByClientPolicyId");
|
||||
$routes->get("downloadEmployeeListExcel", "EmployeeRestController::downloadEmployeeListExcel");
|
||||
|
||||
$routes->get("getPolicyLevelEmployeeSummaryData", "EmployeeRestController::getPolicyLevelEmployeeSummaryData");
|
||||
$routes->get("exportCashDepositData", "EmployeeRestController::exportCashDepositData");
|
||||
|
||||
@ -691,139 +691,19 @@ class EmployeeRestController extends AdminController
|
||||
public function getEmployeeAndDependenceByClientId()
|
||||
{
|
||||
try {
|
||||
$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: $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);
|
||||
}
|
||||
|
||||
$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');
|
||||
|
||||
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()
|
||||
@ -903,108 +783,6 @@ class EmployeeRestController extends AdminController
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Download employee + dependent list Excel.
|
||||
* Filters: client_id, branch_id, policy_id only (same as getEmployeePolicy base filters).
|
||||
* Columns: Emp Code, Name, TPA ID, Relationship, Date Of Birth, Gender, Mobile, Email, Status
|
||||
*/
|
||||
public function downloadEmployeeListExcel()
|
||||
{
|
||||
try {
|
||||
$clientId = $this->request->getGet('client_id');
|
||||
$branchId = $this->request->getGet('branch_id');
|
||||
$policyId = $this->request->getGet('policy_id');
|
||||
|
||||
$empData = $this->employeePolicyModel->getEmployeePolicy(
|
||||
client_id: $clientId,
|
||||
policy_id: $policyId,
|
||||
status: 0,
|
||||
branch_id: $branchId
|
||||
);
|
||||
|
||||
if (!count($empData)) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => [], 'message' => 'No employee data found'], 200);
|
||||
}
|
||||
|
||||
$headers = [
|
||||
'Emp Code' => 'emp_code',
|
||||
'Name' => 'name',
|
||||
'TPA ID' => 'tpa_id',
|
||||
'Relationship' => 'relationship',
|
||||
'Date Of Birth' => 'formatted_dob',
|
||||
'Gender' => 'gender',
|
||||
'Mobile' => 'mobile',
|
||||
'Email' => 'email_corporate',
|
||||
'Status' => 'status',
|
||||
];
|
||||
|
||||
$spreadsheet = new Spreadsheet();
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
$sheet->setTitle('Employee List');
|
||||
|
||||
$column = 'A';
|
||||
foreach ($headers as $header => $dbField) {
|
||||
$sheet->setCellValue($column . '1', $header);
|
||||
$column++;
|
||||
}
|
||||
|
||||
$headerRange = 'A1:I1';
|
||||
$sheet->getStyle($headerRange)->getFont()->setBold(true);
|
||||
$sheet->getStyle($headerRange)->getFill()
|
||||
->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
|
||||
->getStartColor()->setRGB('BDD7EE');
|
||||
|
||||
$row = 2;
|
||||
foreach ($empData as $employee) {
|
||||
$column = 'A';
|
||||
foreach ($headers as $dbField) {
|
||||
$value = $employee[$dbField] ?? '';
|
||||
|
||||
if ($dbField === 'formatted_dob' && empty($value) && !empty($employee['dob'])) {
|
||||
$value = date('d/m/Y', strtotime($employee['dob']));
|
||||
}
|
||||
|
||||
if ($dbField === 'gender' && $value !== '') {
|
||||
$genderLower = strtolower(trim((string) $value));
|
||||
if ($genderLower === 'male' || $genderLower === 'm') {
|
||||
$value = 'M';
|
||||
} elseif ($genderLower === 'female' || $genderLower === 'f') {
|
||||
$value = 'F';
|
||||
}
|
||||
}
|
||||
|
||||
$sheet->setCellValue($column . $row, $value);
|
||||
$column++;
|
||||
}
|
||||
$row++;
|
||||
}
|
||||
|
||||
foreach (range('A', 'I') as $col) {
|
||||
$sheet->getColumnDimension($col)->setAutoSize(true);
|
||||
}
|
||||
|
||||
$policyName = $empData[0]['policy_name'] ?? 'Employee';
|
||||
$filename = preg_replace('/[^A-Za-z0-9_\-]/', '_', $policyName) . '-Employee-List.xlsx';
|
||||
|
||||
// Write to memory and return via CI Response so CORS after() filters still run.
|
||||
// Raw header() + exit skips filters and causes CORS errors for cross-origin fetch.
|
||||
$tempFile = tempnam(sys_get_temp_dir(), 'emp_list_');
|
||||
$writer = new Xlsx($spreadsheet);
|
||||
$writer->save($tempFile);
|
||||
$excelData = file_get_contents($tempFile);
|
||||
@unlink($tempFile);
|
||||
|
||||
return $this->response
|
||||
->setStatusCode(200)
|
||||
->setHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
|
||||
->setHeader('Content-Disposition', 'attachment;filename="' . $filename . '"')
|
||||
->setHeader('Cache-Control', 'max-age=0')
|
||||
->setBody($excelData);
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
//not in use
|
||||
public function getClientPolicy()
|
||||
{
|
||||
@ -2406,36 +2184,6 @@ class EmployeeRestController extends AdminController
|
||||
// }
|
||||
// }
|
||||
|
||||
private function hasValidClientLogo(?string $logo): bool
|
||||
{
|
||||
if ($logo === null || trim($logo) === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$path = parse_url(trim($logo), PHP_URL_PATH) ?? trim($logo);
|
||||
$filename = basename(rtrim($path, '/'));
|
||||
|
||||
return $filename !== '' && strcasecmp($filename, 'logo') !== 0;
|
||||
}
|
||||
|
||||
private function getPreClientLogoUrl($preClientId): string
|
||||
{
|
||||
if (is_string($preClientId) && preg_match('/^[a-f0-9]{32}$/i', $preClientId)) {
|
||||
$preClient = $this->clientModel->where('MD5(id)', $preClientId)->first();
|
||||
} else {
|
||||
$preClient = $this->clientModel->where('id', $preClientId)->first();
|
||||
}
|
||||
|
||||
$logoFilename = $preClient['client_logo'] ?? '';
|
||||
$logoPath = ROOTPATH . 'public/uploads/logo/' . $logoFilename;
|
||||
|
||||
if (!empty($logoFilename) && file_exists($logoPath)) {
|
||||
return base_url() . 'public/uploads/logo/' . $logoFilename;
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getClientDetails()
|
||||
{
|
||||
try {
|
||||
@ -2443,48 +2191,28 @@ class EmployeeRestController extends AdminController
|
||||
$pre_branch_id = $this->request->getGet('pre_branch_id');
|
||||
$post_client_id = $this->request->getGet('post_client_id');
|
||||
$post_branch_id = $this->request->getGet('post_branch_id');
|
||||
|
||||
// Both pre and post: prefer post data; fall back to pre logo if post has none
|
||||
if (!empty($pre_client_id) && !empty($post_client_id)) {
|
||||
$restAuthController = new RestAuthenticationController;
|
||||
$queryParams = [
|
||||
'client_id' => $post_client_id,
|
||||
'client_branch_id' => $post_branch_id
|
||||
];
|
||||
$postResponse = $restAuthController->callThirdPartyGETAPI($queryParams, 'getClientDetails');
|
||||
$postData = is_string($postResponse) ? json_decode($postResponse, true) : null;
|
||||
|
||||
if (
|
||||
is_array($postData)
|
||||
&& (($postData['status'] ?? '') === 'success' || (int) ($postData['code'] ?? 0) === 200)
|
||||
&& !empty($postData['data']['client'])
|
||||
) {
|
||||
$postLogo = $postData['data']['client']['client_logo'] ?? '';
|
||||
if (!$this->hasValidClientLogo($postLogo)) {
|
||||
$postData['data']['client']['client_logo'] = $this->getPreClientLogoUrl($pre_client_id);
|
||||
}
|
||||
|
||||
return $this->respond($postData, 200);
|
||||
}
|
||||
|
||||
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => []], 200);
|
||||
}
|
||||
|
||||
|
||||
if (!empty($pre_client_id)) {
|
||||
|
||||
if (is_string($pre_client_id) && preg_match('/^[a-f0-9]{32}$/i', $pre_client_id)) {
|
||||
$client = $this->clientModel->where('MD5(id)', $pre_client_id)->first();
|
||||
} else {
|
||||
}else{
|
||||
$client = $this->clientModel->where('id', $pre_client_id)->first();
|
||||
}
|
||||
}
|
||||
|
||||
if ($client) {
|
||||
$client['client_logo'] = $this->getPreClientLogoUrl($pre_client_id);
|
||||
|
||||
|
||||
$client['client_logo'] = base_url() . 'public/uploads/logo/' . $client['client_logo'];
|
||||
|
||||
$clientPolicy = $this->clientPolicyModel
|
||||
->where('client_id', $client['id'] ?? null)
|
||||
->where('client_branch_id', $pre_branch_id)
|
||||
->findAll();
|
||||
|
||||
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'code' => 200,
|
||||
@ -2493,34 +2221,27 @@ class EmployeeRestController extends AdminController
|
||||
'client_policy' => $clientPolicy
|
||||
]
|
||||
], 200);
|
||||
} else {
|
||||
|
||||
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => []], 200);
|
||||
}
|
||||
|
||||
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => []], 200);
|
||||
}
|
||||
|
||||
if (!empty($post_client_id)) {
|
||||
} elseif (!empty($post_client_id)) {
|
||||
|
||||
$restAuthController = new RestAuthenticationController;
|
||||
|
||||
$queryParams = [
|
||||
'client_id' => $post_client_id,
|
||||
'client_branch_id' => $post_branch_id
|
||||
];
|
||||
$postResponse = $restAuthController->callThirdPartyGETAPI($queryParams, 'getClientDetails');
|
||||
$postData = is_string($postResponse) ? json_decode($postResponse, true) : null;
|
||||
return $restAuthController->callThirdPartyGETAPI($queryParams, 'getClientDetails');
|
||||
|
||||
if (
|
||||
is_array($postData)
|
||||
&& !empty($postData['data']['client'])
|
||||
&& !$this->hasValidClientLogo($postData['data']['client']['client_logo'] ?? '')
|
||||
) {
|
||||
$postData['data']['client']['client_logo'] = '';
|
||||
return $this->respond($postData, 200);
|
||||
}
|
||||
|
||||
return $postResponse;
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
@ -4906,21 +4627,21 @@ class EmployeeRestController extends AdminController
|
||||
(
|
||||
SELECT id FROM client_policy
|
||||
WHERE policy_type_id = 3
|
||||
AND base_policy = gmc_client_policy_id AND is_active = 1
|
||||
AND base_policy = gmc_client_policy_id
|
||||
LIMIT 1
|
||||
) AS gmc_parent_policy_id,
|
||||
|
||||
(
|
||||
SELECT id FROM client_policy
|
||||
WHERE policy_type_id = 4
|
||||
AND base_policy = gmc_client_policy_id AND is_active = 1
|
||||
AND base_policy = gmc_client_policy_id
|
||||
LIMIT 1
|
||||
) AS gmc_topup_policy_id,
|
||||
|
||||
(
|
||||
SELECT id FROM client_policy
|
||||
WHERE policy_type_id = 72
|
||||
AND base_policy = gmc_client_policy_id AND is_active = 1
|
||||
AND base_policy = gmc_client_policy_id
|
||||
LIMIT 1
|
||||
) AS opd_topup_policy_id
|
||||
")
|
||||
@ -4931,7 +4652,6 @@ class EmployeeRestController extends AdminController
|
||||
->where([
|
||||
'employees.is_active' => 1,
|
||||
'employee_polices.is_active' => 1,
|
||||
'client_policy.is_active' => 1,
|
||||
'client_policy.policy_type_id' => 2,
|
||||
'employees.family_floater_key' => 'self',
|
||||
'employees.emp_code' => $emp_code ?? null,
|
||||
|
||||
@ -82,7 +82,7 @@ class EmployeePolicyModel extends Model
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
public function getEmployeePolicy($client_id = 0, $policy_id = 0, $status = [], $branch_id = 0, $emp_code = "", $emp_name = "", $status_type = "", $search = "")
|
||||
public function getEmployeePolicy($client_id = 0, $policy_id = 0, $status = [], $branch_id = 0, $emp_code = "", $emp_name = "", $status_type = "")
|
||||
{
|
||||
// dd($status);
|
||||
|
||||
@ -301,10 +301,6 @@ class EmployeePolicyModel extends Model
|
||||
$result->like('emp.name', $emp_name);
|
||||
}
|
||||
|
||||
if (!empty($search)) {
|
||||
$this->applyEmployeeGlobalSearch($result, $search);
|
||||
}
|
||||
|
||||
// Always check these conditions
|
||||
$result->where('employee_polices.is_active', 1)
|
||||
->where('emp.is_active', 1);
|
||||
@ -315,30 +311,6 @@ class EmployeePolicyModel extends Model
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Global search across emp_code, name, mobile, email, tpa_id, dob, relationship, status.
|
||||
*/
|
||||
protected function applyEmployeeGlobalSearch($builder, string $search)
|
||||
{
|
||||
$search = trim($search);
|
||||
if ($search === '') {
|
||||
return $builder;
|
||||
}
|
||||
|
||||
return $builder->groupStart()
|
||||
->like('emp.emp_code', $search)
|
||||
->orLike('emp.name', $search)
|
||||
->orLike('emp.mobile', $search)
|
||||
->orLike('emp.email_corporate', $search)
|
||||
->orLike('employee_polices.tpa_id', $search)
|
||||
->orLike('emp.dob', $search)
|
||||
->orWhere("DATE_FORMAT(emp.dob, '%d/%m/%Y') LIKE " . $this->db->escape('%' . $search . '%'), null, false)
|
||||
->orLike('emp.relationship', $search)
|
||||
->orLike('employee_polices.status', $search)
|
||||
->orLike('emp.emp_status', $search)
|
||||
->groupEnd();
|
||||
}
|
||||
|
||||
// public function getEmployeePolicy($client_id = 0, $policy_id = 0, $status = [], $branch_id = 0, $emp_code = "", $emp_name = "")
|
||||
// {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user