CHANGE_MAIL_TEMPLATE

This commit is contained in:
VENKATESHWARAN 2026-06-26 11:50:54 +05:30
parent 056af9ab45
commit c15121aa1a
4 changed files with 154 additions and 21 deletions

View File

@ -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
<div align="center">
<table width="100%" border="0" cellspacing="0" cellpadding="0" style="max-width:600px;">
<tr>
<td align="left" style="padding:15px; font-family:arial, sans-serif; font-size:14px; line-height:22px; color:#333333;">
<p>Dear ' . $hrName . ',</p>
<p>The enrollment window for <strong>' . $clientName . '</strong> has closed.</p>
<p>
<td align="left" style="padding:10px 15px 20px; font-family:arial, sans-serif; font-size:14px; line-height:24px; color:#333333;">
<div style="margin-bottom:16px;">Dear ' . $hrName . ',</div>
<div style="margin-bottom:16px;">The enrollment window for <strong>' . $clientName . '</strong> has closed.</div>
<div style="margin-bottom:16px;">
<strong>Policy No:</strong> ' . $policyNo . '<br>
<strong>Enrollment Open Date:</strong> ' . $openDate . '<br>
<strong>Enrollment Close Date:</strong> ' . $closeDate . '
</p>
<p>
</div>
<div style="margin-bottom:16px;">
Please find the attached Excel file with the enrolled employee list
(' . $employeeCount . ' record' . ($employeeCount === 1 ? '' : 's') . ').
</p>
<p>Regards,<br>Nhance Team</p>
</div>
<div>Regards,<br>Nhance Team</div>
</td>
</tr>
</table>

View File

@ -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;
}
}

View File

@ -0,0 +1,57 @@
<?php
$counts = $counts ?? [];
$tiles = [
['label' => '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);
?>
<div align="center" style="width:100%; margin:24px 0;">
<table width="100%" border="0" cellspacing="0" cellpadding="0" style="max-width:600px; border-collapse:collapse;">
<tr>
<td style="padding:0 12px 12px; font-family:arial, sans-serif; font-size:15px; font-weight:600; color:#343a40; text-align:left;">
Enrollment Summary
</td>
</tr>
<tr>
<td style="padding:0 8px;">
<table width="100%" border="0" cellspacing="0" cellpadding="0" style="border-collapse:collapse;">
<?php foreach ($tileRows as $rowTiles): ?>
<tr>
<?php foreach ($rowTiles as $tile): ?>
<td width="33%" align="center" valign="top" style="padding:6px;">
<table width="100%" border="0" cellspacing="0" cellpadding="0" style="border-collapse:collapse; background-color:#ffffff; border:1px solid #e9ecef; border-radius:8px;">
<tr>
<td height="4" style="background-color:<?= esc($tile['accent']) ?>; font-size:0; line-height:0; border-radius:8px 8px 0 0;">&nbsp;</td>
</tr>
<tr>
<td align="center" style="padding:18px 10px 20px;">
<div style="font-family:arial, sans-serif; font-size:26px; font-weight:700; color:#212529; line-height:1.1; margin:0 0 6px 0;">
<?= $tile['value'] ?>
</div>
<div style="font-family:arial, sans-serif; font-size:12px; font-weight:500; color:#6c757d; line-height:1.3; letter-spacing:0.2px;">
<?= esc($tile['label']) ?>
</div>
</td>
</tr>
</table>
</td>
<?php endforeach; ?>
<?php
$missingCells = 3 - count($rowTiles);
for ($i = 0; $i < $missingCells; $i++):
?>
<td width="33%" style="padding:6px; font-size:0; line-height:0;">&nbsp;</td>
<?php endfor; ?>
</tr>
<?php endforeach; ?>
</table>
</td>
</tr>
</table>
</div>

View File

@ -89,16 +89,11 @@ p{
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="mail-template-header">
<tr style="height:90px; background-color: #ffffff !important;">
<td align="left" class="client_logo" style="padding:5px;" width="50%">
<div style="
width:160px;
height:80px;
background-image:url('<?= $client_logo ?? "" ?>');
background-size:contain;
background-repeat:no-repeat;
background-position: center;
">
</div>
<?php if (!empty($client_logo)): ?>
<img src="<?= esc($client_logo) ?>"
alt="Client Logo"
style="height:auto; max-width:160px; max-height:80px; display:block;">
<?php endif; ?>
</td>
<td align="right" class="nhance_logo" style="padding:5px;" width="50%">
<img src="<?= base_url('/public/assets/images/Nhance-Logo-Final.png'); ?>"