From 1fbcd5fcee39bd0d13b73847ebc50472850551e5 Mon Sep 17 00:00:00 2001 From: Venkatesh Date: Tue, 4 Aug 2026 18:36:48 +0530 Subject: [PATCH 1/3] FIX_BCC --- app/Controllers/EmployeeRestController.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 01c6ceea..4ddd32a7 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -6477,7 +6477,7 @@ class EmployeeRestController extends AdminController $db = \Config\Database::connect(); $clientData = $this->clientModel - ->select('id, client_name, email') + ->select('id, client_name, email, common_mails') ->where('id', $clientId) ->first(); @@ -6517,6 +6517,11 @@ class EmployeeRestController extends AdminController $recipientEmails[] = trim((string) $clientData['email']); } + $clientCommonMails = array_filter(array_map('trim', explode(',', (string) ($clientData['common_mails'] ?? '')))); + foreach ($clientCommonMails as $commonMail) { + $recipientEmails[] = $commonMail; + } + foreach ($branchHrEmails as $branchHrEmailRow) { $recipientEmails[] = trim((string) ($branchHrEmailRow['email'] ?? '')); } @@ -6527,9 +6532,18 @@ class EmployeeRestController extends AdminController } } - $recipientEmails = array_values(array_unique(array_filter($recipientEmails, static function ($email) { - return filter_var($email, FILTER_VALIDATE_EMAIL); - }))); + $uniqueEmails = []; + foreach ($recipientEmails as $email) { + $email = trim((string) $email); + if ($email === '' || ! filter_var($email, FILTER_VALIDATE_EMAIL)) { + continue; + } + $emailKey = strtolower($email); + if (! isset($uniqueEmails[$emailKey])) { + $uniqueEmails[$emailKey] = $email; + } + } + $recipientEmails = array_values($uniqueEmails); if (empty($recipientEmails)) { log_message('error', '[DependentAddMail] No recipient emails found for client_id=' . $clientId . ', branch_id=' . $branchId); From a432fd2ad75b6b24262d3d6d0f8b01392a2a99ac Mon Sep 17 00:00:00 2001 From: Venkatesh Date: Thu, 6 Aug 2026 10:12:02 +0530 Subject: [PATCH 2/3] FIX_HR_ACCESS_CONTROLL_BRANCH_POLICY_MAPPING --- app/Controllers/ClientController.php | 126 ++++++++++++++++++--------- app/Views/hr_access_controll.php | 13 +-- 2 files changed, 90 insertions(+), 49 deletions(-) diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index e5573f82..04668957 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -8970,7 +8970,8 @@ class ClientController extends AdminController $hrAccessData['post_hr_data'] = $this->clientBranchModel ->select('lc.id as post_hr_id, lc.name as hr_name, lc.mobile as hr_mobile, lc.email as hr_mail , - client_branch.id as post_branch_id , client_branch.branch_name as post_branch_name') + client_branch.id as post_branch_id , client_branch.branch_name as post_branch_name, + client_branch.pre_branch_id as linked_pre_branch_id') ->join('level_contacts lc', 'client_branch.id = lc.ref_id') ->where('client_branch.is_active', 1) ->where('lc.is_active', 1) @@ -9012,32 +9013,53 @@ class ClientController extends AdminController return $combinedHrAccessData; } - $post_branch = $this->clientBranchModel->select('pre_branch_id')->where('client_id',$client_id)->get()->getResultArray()[0]??[]; - - $pre_client_data = $db2->table('client_branch cb') - ->join('clients c', "c.id = cb.client_id") - ->where('c.is_active',1) - ->where('cb.is_active', 1) - ->where('cb.id', $post_branch['pre_branch_id']??'') - ->get()->getRowArray(); - - - if (empty($pre_client_data)) { + // Collect all linked pre_branch_ids for this post client (not only the first branch) + $post_branches = $this->clientBranchModel + ->select('pre_branch_id') + ->where('client_id', $client_id) + ->where('is_active', 1) + ->findAll(); + $preBranchIds = array_values(array_unique(array_filter(array_map( + static fn($row) => $row['pre_branch_id'] ?? null, + $post_branches + )))); + if (empty($preBranchIds)) { $hrAccessData['pre_hr_data'] = []; $hrAccessData['pre_policy_data'] = []; - $combinedHrAccessData = $this->constructHrAccessData($hrAccessData, $client_id , $pre_client_data['id']??''); + $combinedHrAccessData = $this->constructHrAccessData($hrAccessData, $client_id, ''); return $combinedHrAccessData; } + // Explicitly select c.id as pre_client_id to avoid id column collision from the join + $pre_client_rows = $db2->table('client_branch cb') + ->select('c.id as pre_client_id') + ->join('clients c', 'c.id = cb.client_id') + ->where('c.is_active', 1) + ->where('cb.is_active', 1) + ->whereIn('cb.id', $preBranchIds) + ->get() + ->getResultArray(); + + $preClientIds = array_values(array_unique(array_filter(array_column($pre_client_rows, 'pre_client_id')))); + + if (empty($preClientIds)) { + $hrAccessData['pre_hr_data'] = []; + $hrAccessData['pre_policy_data'] = []; + $combinedHrAccessData = $this->constructHrAccessData($hrAccessData, $client_id, ''); + return $combinedHrAccessData; + } + + $pre_client_id = $preClientIds[0]; + $hrAccessData['pre_hr_data'] = $db2->table('client_branch') ->select('lc.id as pre_hr_id, lc.name as hr_name, lc.mobile as hr_mobile, lc.email as hr_mail - , client_branch.id as pre_branch_id , client_branch.branch_name as pre_branch_name ' ) + , client_branch.id as pre_branch_id , client_branch.branch_name as pre_branch_name, client_branch.client_id as pre_client_id') ->join('level_contacts lc', 'client_branch.id = lc.ref_id') ->where('client_branch.is_active', 1) ->where('lc.is_active', 1) ->where('lc.contact_type', 'client') - ->where('client_branch.client_id', $pre_client_data['id']) + ->whereIn('client_branch.client_id', $preClientIds) ->get() ->getResultArray(); @@ -9045,14 +9067,13 @@ class ClientController extends AdminController ->select('client_policy.id as client_policy_id, client_policy.policy_no as policy_no, policy_type.policy_type, client_policy.policy_status , client_policy.client_branch_id as branch_id') ->join('policy_type', 'client_policy.policy_type_id = policy_type.id') ->where('client_policy.is_active', 1) - ->where('client_policy.client_id', $pre_client_data['id']) + ->whereIn('client_policy.client_id', $preClientIds) // ->orderBy('client_policy_id', 'desc') ->orderBy('client_policy.policy_status', 'desc') ->get() ->getResultArray(); - // dd($hrAccessData); - $combinedHrAccessData = $this->constructHrAccessData($hrAccessData, $client_id ,$pre_client_data['id']); + $combinedHrAccessData = $this->constructHrAccessData($hrAccessData, $client_id, $pre_client_id); return $combinedHrAccessData; } @@ -9065,27 +9086,44 @@ class ClientController extends AdminController $hrAccessTableData = $data['hr_access_table_data']; $merged = []; - // Merge based on mobile and email + // Merge based on mobile + email, preferring the linked pre_branch_id when available foreach ($postHrs as $post) { $found = false; + $linkedPreBranchId = !empty($post['linked_pre_branch_id']) ? (int) $post['linked_pre_branch_id'] : null; + $matchedIndex = null; + + // Prefer contact match on the linked pre branch foreach ($preHrs as $index => $pre) { - - if ( trim($post['hr_mobile']) == trim($pre['hr_mobile']) && trim($post['hr_mail']) == trim($pre['hr_mail']) ) { - - $merged[] = [ - 'pre_hr_id' => $pre['pre_hr_id'], - 'post_hr_id' => $post['post_hr_id'], - 'hr_name' => $post['hr_name'], - 'hr_mobile' => $post['hr_mobile'], - 'hr_mail' => $post['hr_mail'], - 'pre_branch_id' => $pre['pre_branch_id'] ?? null, - 'post_branch_id' => $post['post_branch_id'] ?? null, - 'post_branch_name' => $post['post_branch_name'] ?? null - ]; - unset($preHrs[$index]); // remove matched pre_hr - $found = true; + $contactMatch = trim((string) $post['hr_mobile']) === trim((string) $pre['hr_mobile']) + && trim((string) $post['hr_mail']) === trim((string) $pre['hr_mail']); + if (!$contactMatch) { + continue; + } + if ($linkedPreBranchId !== null && (int) ($pre['pre_branch_id'] ?? 0) === $linkedPreBranchId) { + $matchedIndex = $index; break; } + if ($matchedIndex === null) { + $matchedIndex = $index; // fallback: first contact match + } + } + + if ($matchedIndex !== null) { + $pre = $preHrs[$matchedIndex]; + $merged[] = [ + 'pre_hr_id' => $pre['pre_hr_id'], + 'post_hr_id' => $post['post_hr_id'], + 'hr_name' => $post['hr_name'], + 'hr_mobile' => $post['hr_mobile'], + 'hr_mail' => $post['hr_mail'], + // Prefer the branch link from post→pre mapping when present + 'pre_branch_id' => $linkedPreBranchId ?: ($pre['pre_branch_id'] ?? null), + 'post_branch_id' => $post['post_branch_id'] ?? null, + 'post_branch_name' => $post['post_branch_name'] ?? null, + 'pre_client_id' => $pre['pre_client_id'] ?? ($pre_client_id ?? null), + ]; + unset($preHrs[$matchedIndex]); + $found = true; } if (!$found) { @@ -9095,9 +9133,10 @@ class ClientController extends AdminController 'hr_name' => $post['hr_name'], 'hr_mobile' => $post['hr_mobile'], 'hr_mail' => $post['hr_mail'], - 'pre_branch_id' => $pre['pre_branch_id'] ?? null, - 'post_branch_id' => $post['post_branch_id'] ?? null , - 'post_branch_name' => $post['post_branch_name'] ?? null + 'pre_branch_id' => $linkedPreBranchId, // do not reuse leftover $pre from prior loop + 'post_branch_id' => $post['post_branch_id'] ?? null, + 'post_branch_name' => $post['post_branch_name'] ?? null, + 'pre_client_id' => $pre_client_id ?? null, ]; } } @@ -9118,8 +9157,9 @@ class ClientController extends AdminController 'hr_mobile' => $pre['hr_mobile'], 'hr_mail' => $pre['hr_mail'], 'pre_branch_id' => $pre['pre_branch_id'] ?? null, - 'post_branch_id' => $post['post_branch_id'] ?? null , - 'post_branch_name' => $post['post_branch_name'] ?? null + 'post_branch_id' => null, // do not reuse leftover $post from prior loop + 'post_branch_name' => null, + 'pre_client_id' => $pre['pre_client_id'] ?? ($pre_client_id ?? null), ]; } @@ -9145,7 +9185,7 @@ class ClientController extends AdminController 'pre_branch_id' => $hr['pre_branch_id'] ?? null, 'post_branch_id' => $hr['post_branch_id'] ?? null , 'post_branch_name' => $hr['post_branch_name'] ?? null , - 'pre_client_id' => $pre_client_id ?? null + 'pre_client_id' => $hr['pre_client_id'] ?? ($pre_client_id ?? null) ]; } @@ -9204,7 +9244,7 @@ class ClientController extends AdminController 'pre_branch_id' => $hr['pre_branch_id'] ?? null, 'post_branch_id' => $hr['post_branch_id'] ?? null , 'post_branch_name' => $hr['post_branch_name'] ?? null , - 'pre_client_id' => $pre_client_id ?? null, + 'pre_client_id' => $hr['pre_client_id'] ?? ($pre_client_id ?? null), 'type_of_access_data' => $type_of_access_data ?? null ]; @@ -9237,7 +9277,7 @@ class ClientController extends AdminController 'pre_branch_id' => $hr['pre_branch_id'] ?? null, 'post_branch_id' => $hr['post_branch_id'] ?? null , 'post_branch_name' => $hr['post_branch_name'] ?? null , - 'pre_client_id' => $pre_client_id ?? null, + 'pre_client_id' => $hr['pre_client_id'] ?? ($pre_client_id ?? null), 'type_of_access_data' => $type_of_access_data ?? null ]; @@ -9281,7 +9321,7 @@ class ClientController extends AdminController 'pre_branch_id' => $hr['pre_branch_id'] ?? null, 'post_branch_id' => $hr['post_branch_id'] ?? null , 'post_branch_name' => $hr['post_branch_name'] ?? null , - 'pre_client_id' => $pre_client_id ?? null, + 'pre_client_id' => $hr['pre_client_id'] ?? ($pre_client_id ?? null), 'type_of_access_data' => $type_of_access_data ?? null ]; } diff --git a/app/Views/hr_access_controll.php b/app/Views/hr_access_controll.php index d0443eb8..e86a03e3 100644 --- a/app/Views/hr_access_controll.php +++ b/app/Views/hr_access_controll.php @@ -128,10 +128,11 @@ $key = $key + 1; // Calculate data counts per user for toggling rules + // Cast to int — DB drivers may return branch ids as string or int $prePolicyCount = 0; if (!empty($pre_policy_data)) { foreach ($pre_policy_data as $p) { - if (!empty($value['pre_hr_id']) && $value['pre_branch_id'] === $p['branch_id']) { + if (!empty($value['pre_hr_id']) && (int) $value['pre_branch_id'] === (int) $p['branch_id']) { $prePolicyCount++; } } @@ -140,7 +141,7 @@ $postPolicyCount = 0; if (!empty($post_policy_data)) { foreach ($post_policy_data as $p) { - if (!empty($value['post_hr_id']) && $value['post_branch_id'] === $p['branch_id']) { + if (!empty($value['post_hr_id']) && (int) $value['post_branch_id'] === (int) $p['branch_id']) { $postPolicyCount++; } } @@ -186,7 +187,7 @@ Pre enrollment -
+
@@ -219,13 +220,13 @@ // $listed_pre[] = $policies['branch_id'].'-'.$policies['policy_no']; // } - if(empty($value['pre_hr_id']) || $value['pre_branch_id'] !== $policies['branch_id']){ + if (empty($value['pre_hr_id']) || (int) $value['pre_branch_id'] !== (int) $policies['branch_id']) { continue; } ?>
> + > @@ -287,7 +288,7 @@ // $listed_post[] = $policies['branch_id'].'-'.$policies['policy_no']; // } - if(empty($value['post_hr_id']) || $value['post_branch_id'] !== $policies['branch_id']){ + if (empty($value['post_hr_id']) || (int) $value['post_branch_id'] !== (int) $policies['branch_id']) { continue; } From 3bee26e5400e01653c7d9c026c443f932fc90fb9 Mon Sep 17 00:00:00 2001 From: Venkatesh Date: Thu, 6 Aug 2026 10:30:18 +0530 Subject: [PATCH 3/3] CHANGE_THE_TEXT --- app/Views/hr_activity_history.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Views/hr_activity_history.php b/app/Views/hr_activity_history.php index 3612b6cd..6863ddce 100644 --- a/app/Views/hr_activity_history.php +++ b/app/Views/hr_activity_history.php @@ -98,7 +98,7 @@ table.dataTable tbody td { - +