From c15121aa1aa4bb5843aa4e3f767882dfef46859f Mon Sep 17 00:00:00 2001 From: Venkatesh Date: Fri, 26 Jun 2026 11:50:54 +0530 Subject: [PATCH 1/3] CHANGE_MAIL_TEMPLATE --- app/Controllers/EmployeeController.php | 39 +++++++++---- app/Models/EmployeePolicyModel.php | 64 +++++++++++++++++++++- app/Views/mail/enrollment_status_tiles.php | 57 +++++++++++++++++++ app/Views/mail_template.php | 15 ++--- 4 files changed, 154 insertions(+), 21 deletions(-) create mode 100644 app/Views/mail/enrollment_status_tiles.php diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index 3aba419..1616f34 100755 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -3267,7 +3267,10 @@ class EmployeeController extends AdminController $sentCount = 0; try { $clientPolicy = $this->clientPolicyModel->find($filePolicyId); - $clientLogo = base_url() . 'public/uploads/logo/' . ($clientData['client_logo'] ?? ''); + $clientLogo = ''; + if (!empty($clientData['client_logo'])) { + $clientLogo = base_url() . 'public/uploads/logo/' . $clientData['client_logo']; + } $acm_Mails = $clientData['common_mails'] ?? ''; if(empty($acm_Mails)){ @@ -3282,6 +3285,11 @@ class EmployeeController extends AdminController : 'N/A'; $subject = 'Enrollment Closed - Enrolled Employee List | ' . ($clientData['client_name'] ?? ''); + $statusTilesHtml = $this->renderEnrollmentStatusTilesForMail( + $fileClientId, + (int) $file['client_branch_id'], + $filePolicyId + ); foreach ($hrRecipients as $hrRecipient) { $hrEmail = trim($hrRecipient['email'] ?? ''); @@ -3291,7 +3299,7 @@ class EmployeeController extends AdminController continue; } - $mailContent = $this->buildEnrollmentClosedHrMailContent([ + $mailContent = $statusTilesHtml . $this->buildEnrollmentClosedHrMailContent([ 'hr_name' => $hrName, 'client_name' => $clientData['client_name'] ?? '', 'policy_no' => $clientPolicy['policy_no'] ?? 'N/A', @@ -3355,6 +3363,17 @@ class EmployeeController extends AdminController } } + private function renderEnrollmentStatusTilesForMail(int $client_id, int $branch_id, int $policy_id): string + { + $counts = $this->employeePolicyModel->getEnrollmentStatusTileCounts( + $client_id, + $branch_id, + $policy_id + ); + + return view('mail/enrollment_status_tiles', ['counts' => $counts]); + } + private function buildEnrollmentClosedHrMailContent(array $data): string { $hrName = htmlspecialchars($data['hr_name'] ?? 'HR Team', ENT_QUOTES, 'UTF-8'); @@ -3368,19 +3387,19 @@ class EmployeeController extends AdminController
-
-

Dear ' . $hrName . ',

-

The enrollment window for ' . $clientName . ' has closed.

-

+

+
Dear ' . $hrName . ',
+
The enrollment window for ' . $clientName . ' has closed.
+
Policy No: ' . $policyNo . '
Enrollment Open Date: ' . $openDate . '
Enrollment Close Date: ' . $closeDate . ' -

-

+

+
Please find the attached Excel file with the enrolled employee list (' . $employeeCount . ' record' . ($employeeCount === 1 ? '' : 's') . '). -

-

Regards,
Nhance Team

+
+
Regards,
Nhance Team
diff --git a/app/Models/EmployeePolicyModel.php b/app/Models/EmployeePolicyModel.php index d75197c..834f295 100755 --- a/app/Models/EmployeePolicyModel.php +++ b/app/Models/EmployeePolicyModel.php @@ -1987,7 +1987,9 @@ class EmployeePolicyModel extends Model // Conditionally add where clauses - if ($client_id != 0 && !empty(trim($client_id))) { + if (is_string($client_id) && preg_match('/^[a-f0-9]{32}$/i', $client_id)) { + $result->where('MD5(emp.client_id)', $client_id); + } elseif ($client_id != 0 && !empty($client_id)) { $result->where('emp.client_id', $client_id); } if ($branch_id != 0 && !empty(trim($branch_id))) { @@ -2124,5 +2126,65 @@ class EmployeePolicyModel extends Model ->getRowArray(); } + /** + * Enrollment status tile counts (same logic as enrollment_list.php). + */ + public function getEnrollmentStatusTileCounts(int $client_id, int $branch_id, int $client_policy_id): array + { + $authSubQuery = '(SELECT user_id FROM auth_history WHERE user_type = "employee" GROUP BY user_id) auth_history'; + + $rows = $this->db->table('employees') + ->select('employees.id, employees.relationship, employees.emp_status, auth_history.user_id as logged_in_user_id') + ->join('employee_polices', 'employees.id = employee_polices.employee_id') + ->join($authSubQuery, 'employees.id = auth_history.user_id', 'left', false) + ->where('employees.client_id', $client_id) + ->where('employees.client_branch_id', $branch_id) + ->where('employees.is_active', 1) + ->where('employees.emp_status !=', 'truncated') + ->where('employee_polices.client_policy_id', $client_policy_id) + ->where('employee_polices.is_active', 1) + ->where('employee_polices.status !=', 'truncated') + ->groupBy('employees.id, employees.relationship, employees.emp_status, auth_history.user_id') + ->get() + ->getResultArray(); + + $counts = [ + 'emp_count' => 0, + 'enrolled' => 0, + 'not_enrolled' => 0, + 'logged_in' => 0, + 'not_logged_in' => 0, + 'draft' => 0, + ]; + + foreach ($rows as $row) { + if (strtolower(trim($row['relationship'] ?? '')) !== 'self') { + continue; + } + + $counts['emp_count']++; + + $isEnrolled = ($row['emp_status'] ?? '') === 'enrolled'; + if ($isEnrolled) { + $counts['enrolled']++; + } else { + $counts['not_enrolled']++; + } + + $isLoggedIn = !empty($row['logged_in_user_id']); + if ($isLoggedIn) { + $counts['logged_in']++; + } else { + $counts['not_logged_in']++; + } + + if (!$isEnrolled && $isLoggedIn) { + $counts['draft']++; + } + } + + return $counts; + } + } \ No newline at end of file diff --git a/app/Views/mail/enrollment_status_tiles.php b/app/Views/mail/enrollment_status_tiles.php new file mode 100644 index 0000000..afe5ed4 --- /dev/null +++ b/app/Views/mail/enrollment_status_tiles.php @@ -0,0 +1,57 @@ + 'Emp Count', 'value' => (int) ($counts['emp_count'] ?? 0), 'accent' => '#00999E'], + ['label' => 'Enroled', 'value' => (int) ($counts['enrolled'] ?? 0), 'accent' => '#0ab39c'], + ['label' => 'Not Enroled', 'value' => (int) ($counts['not_enrolled'] ?? 0), 'accent' => '#f06548'], + ['label' => 'Logged-In', 'value' => (int) ($counts['logged_in'] ?? 0), 'accent' => '#299cdb'], + ['label' => 'Not Logged-In', 'value' => (int) ($counts['not_logged_in'] ?? 0), 'accent' => '#878a99'], + ['label' => 'Draft', 'value' => (int) ($counts['draft'] ?? 0), 'accent' => '#f7b84b'], +]; +$tileRows = array_chunk($tiles, 3); +?> + +
+ + + + + + + +
+ Enrollment Summary +
+ + + + + + + + + + + +
+ + + + + + + +
 
+
+ +
+
+ +
+
+
 
+
+
diff --git a/app/Views/mail_template.php b/app/Views/mail_template.php index 5650efa..0ceac34 100644 --- a/app/Views/mail_template.php +++ b/app/Views/mail_template.php @@ -89,16 +89,11 @@ p{