MERGE_UAT_BUG_FIXES

This commit is contained in:
Ubuntu 2026-07-07 10:34:54 +05:30
commit 606aa81e06
3 changed files with 358 additions and 41 deletions

View File

@ -5431,7 +5431,7 @@ class PolicyTransactionController extends BaseController
}
$this->myLogger->logme("error", "Data for BDS Installment " . json_encode($bdsInstallmentData));
// print_rr($bdsInstallmentData);die();
// dd($bdsInstallmentData);die();
if (empty($bdsInstallmentData)) {
$this->myLogger->logme("error", "No Client Installment is Due in the 5th Day");
@ -5474,44 +5474,63 @@ class PolicyTransactionController extends BaseController
try {
$installment_amount = $data['installment_amount'];
$payment_date = date('d-m-Y', strtotime($data['payment_date']));
$client = $data['client_name'];
$branch = $data['branch_name'];
$sales_person_mail = $data['sales_person'];
$heads = $data['heads'];
$admins = $data['admins'];
$buisness_team = $data['buisness_team'];
$policy_no = $data['policy_no'];
$client_short_name = isset($data['short_name']) && $data['short_name'] != null ? $data['short_name'] : $data['client_name'];
helper('excel_util_helper');
$subject = "Installment Amount Due For Client - {$client_short_name} - Policy NO({$policy_no}) is Due On - {$payment_date}";
$installment_amount = (float) ($data['installment_amount'] ?? 0);
$payment_date = date('d-m-Y', strtotime($data['payment_date']));
$client = $data['client_name'];
$branch = $data['branch_name'];
$sales_person_mail = $data['sales_person'];
$policy_no = trim((string) ($data['policy_no'] ?? ''));
$client_short_name = isset($data['short_name']) && $data['short_name'] != null ? $data['short_name'] : $data['client_name'];
$formatted_amount = '₹ ' . formatIndianCurrency(number_format($installment_amount, 2, '.', ''));
$is_overdue = strtotime($data['payment_date']) < strtotime(date('Y-m-d'));
$policy_label = $policy_no !== '' ? "Policy #{$policy_no}" : 'Policy Pending';
$policy_period = '';
$message = "Policy Installment for Client - {$client}, Branch - {$branch} is Due on {$payment_date}
with amount of {$installment_amount}.<br>
Policy No : {$policy_no}";
if (!empty($data['policy_start_date']) && !empty($data['policy_end_date'])) {
$policy_period = date('d-m-Y', strtotime($data['policy_start_date']))
. ' to '
. date('d-m-Y', strtotime($data['policy_end_date']));
}
$subject = $is_overdue
? "Overdue Installment Reminder - {$client_short_name} | {$policy_label} | Due {$payment_date}"
: "Installment Payment Reminder - {$client_short_name} | {$policy_label} | Due {$payment_date}";
$message = view('bds_installment_reminder_email_template', [
'client_name' => $client,
'branch_name' => $branch,
'policy_no' => $policy_no !== '' ? $policy_no : 'Not Assigned',
'policy_type' => $data['policy_type'] ?? '',
'insurer_name' => $data['insurer_name'] ?? '',
'policy_period' => $policy_period,
'payment_date' => $payment_date,
'installment_amount' => $formatted_amount,
'is_overdue' => $is_overdue,
'generated_on' => date('d-m-Y H:i'),
]);
$contactPersonEmail = trim((string) ($data['contact_person_email'] ?? ''));
$to_mail = array_merge(
array_column($heads, 'email'),
array_column($admins, 'email'),
array_column($buisness_team, 'email'),
[$data['acm_email']],
[$sales_person_mail],
$contactPersonEmail !== '' ? [$contactPersonEmail] : []
);
$to_mail = array_values(array_unique(array_filter($to_mail)));
$to_mail = array_values(array_unique(array_filter($to_mail, static function ($email) {
return is_string($email) && filter_var(trim($email), FILTER_VALIDATE_EMAIL);
})));
$this->myLogger->logme("error", "Selected To Address : " . json_encode($to_mail));
// dd($to_mail);
return [
'to_mail' => $to_mail,
'message' => $message,
'subject' => $subject
];
} catch (Exception $e) {
$this->myLogger->logme('error', 'Exception: ' . $e->getMessage() . 'Page: ' . $e->getFile() . ' Line: ' . $e->getLine());

View File

@ -135,37 +135,56 @@ class BdsPlacementModel extends Model
{
/** @var BdsConfig $config */
$config = config(BdsConfig::class);
// print_r($config);die();
if (!$config->shouldFetchInstallmentRemindersToday()) {
return [];
}
$heads = $this->db->table('user_profiles')
->select('email')->where(['role' => 5, 'is_active' => 1])
->get()->getResultArray();
// $heads = $this->db->table('user_profiles')
// ->select('email')->where(['role' => 5, 'is_active' => 1])
// ->get()->getResultArray();
$admins = $this->db->table('user_profiles')
->select('email')->where(['role' => 1, 'is_active' => 1])
->get()->getResultArray();
// $admins = $this->db->table('user_profiles')
// ->select('email')->where(['role' => 1, 'is_active' => 1])
// ->get()->getResultArray();
$businessTeam = $this->db->table("user_teams ut")
->select("up.email")
->join('user_profiles up', 'up.id = ut.user_id AND up.is_active = 1')
->where(["ut.team_id" => 7, "ut.is_active" => 1])
->get()->getResultArray();
// $businessTeam = $this->db->table("user_teams ut")
// ->select("up.email")
// ->join('user_profiles up', 'up.id = ut.user_id AND up.is_active = 1')
// ->where(["ut.team_id" => 7, "ut.is_active" => 1])
// ->get()->getResultArray();
$builder = $this->db->table("lead_installment_payment_details lipd")
->select("lipd.*, COALESCE(ct.client_name, leads.client_name) as client_name, COALESCE(ct.short_name, leads.client_short_name) as short_name, COALESCE(cb.branch_name, leads.branch_name) as branch_name, leads.salse_person_id, leads.contact_person_email, cp.policy_no")
->select("
lipd.*,
COALESCE(ct.client_name, leads.client_name) as client_name,
COALESCE(ct.short_name, leads.client_short_name) as short_name,
COALESCE(cb.branch_name, leads.branch_name) as branch_name,
leads.salse_person_id,
leads.contact_person_email,
leads.contact_person_name,
leads.contact_person_mobile,
COALESCE(cp.policy_no, cp_src.policy_no) as policy_no,
COALESCE(cp.policy_start_date, cp_src.policy_start_date) as policy_start_date,
COALESCE(cp.policy_end_date, cp_src.policy_end_date) as policy_end_date,
COALESCE(ins.name, ins_src.name) as insurer_name,
COALESCE(pt.policy_type, pt_src.policy_type) as policy_type,
leads.acm_id,
leads.is_policy_created
")
->join("leads", "leads.id = lipd.lead_id")
->join("clients ct", "ct.id = leads.client_id", "left")
->join("client_branch cb", "cb.id = leads.client_branch_id", "left")
->join("client_policy cp", "cp.id = leads.source_policy_id", "left")
->join("client_policy cp", "cp.id = leads.is_policy_created", "left")
->join("client_policy cp_src", "cp_src.id = leads.source_policy_id", "left")
->join("insurers ins", "ins.id = cp.insurer_id", "left")
->join("insurers ins_src", "ins_src.id = cp_src.insurer_id", "left")
->join("policy_type pt", "pt.id = cp.policy_type_id", "left")
->join("policy_type pt_src", "pt_src.id = cp_src.policy_type_id", "left")
->where("lipd.is_active", 1)
->where("lipd.utr_no IS NULL OR lipd.utr_no = ''");
$targetPaymentDate = $this->addBusinessDays($config->installmentReminderBusinessDays);
// print_r($targetPaymentDate);die();
if ($config->installmentReminderFetchOverduePendingUtr) {
$builder->groupStart()
@ -178,27 +197,46 @@ class BdsPlacementModel extends Model
$data = $builder->get()->getResultArray();
// print_r($this->db->getLastQuery()->getQuery());die();
foreach ($data as &$row) {
$sales_person_ids = json_decode($row['salse_person_id'], true);
$sales_person_id = $sales_person_ids[0] ?? null;
$acm_id = $row['acm_id'] ?? null;
if ($acm_id) {
$acm_user = $this->db->table('user_profiles')
->select('email, first_name, last_name')
->where('id', (int) $acm_id)
->get()
->getRowArray();
$row['acm_email'] = $acm_user['email'] ?? 'N/A';
$row['acm_name'] = trim(
($acm_user['first_name'] ?? '') . ' ' . ($acm_user['last_name'] ?? '')
) ?: 'Not Assigned';
} else {
$row['acm_email'] = 'N/A';
$row['acm_name'] = 'Not Assigned';
}
if ($sales_person_id) {
$user = $this->db->table('user_profiles')
->select('email')
->select('email, first_name, last_name')
->where('id', (int) $sales_person_id)
->get()
->getRowArray();
$row['sales_person'] = $user['email'] ?? 'N/A';
$row['sales_person_name'] = trim(
($user['first_name'] ?? '') . ' ' . ($user['last_name'] ?? '')
) ?: 'Not Assigned';
} else {
$row['sales_person'] = 'Not Assigned';
$row['sales_person_name'] = 'Not Assigned';
}
$row['heads'] = $heads;
$row['admins'] = $admins;
$row['buisness_team'] = $businessTeam;
// $row['heads'] = $heads;
// $row['admins'] = $admins;
// $row['buisness_team'] = $businessTeam;
}
return $data;

View File

@ -0,0 +1,260 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body {
font-family: 'Segoe UI', Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f7f6;
color: #333;
-webkit-text-size-adjust: 100%;
}
.container {
width: 100%;
max-width: 640px;
margin: 0 auto;
background: #ffffff;
border-radius: 8px;
overflow: hidden;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.06);
}
.header {
background: linear-gradient(135deg, #1f618d, #21618c, #117a65);
color: #ffffff;
padding: 24px 20px;
text-align: center;
}
.header h1 {
margin: 0;
font-size: 22px;
letter-spacing: 0.3px;
}
.header-subtitle {
margin-top: 6px;
font-size: 13px;
opacity: 0.92;
}
.content {
padding: 24px 20px;
}
.alert-banner {
padding: 14px 16px;
border-radius: 6px;
margin-bottom: 20px;
font-size: 14px;
line-height: 1.5;
}
.alert-overdue {
background: #fdecea;
border-left: 4px solid #c0392b;
color: #922b21;
}
.alert-upcoming {
background: #eaf4fb;
border-left: 4px solid #2980b9;
color: #1f4e79;
}
.intro {
font-size: 14px;
line-height: 1.7;
color: #2c3e50;
margin: 0 0 18px;
}
.section-title {
font-size: 16px;
color: #2c3e50;
border-bottom: 2px solid #3498db;
display: inline-block;
margin: 0 0 12px;
padding-bottom: 4px;
}
.details-table {
width: 100%;
border-collapse: collapse;
margin-bottom: 20px;
}
.details-table td {
padding: 10px 12px;
border-bottom: 1px solid #ecf0f1;
font-size: 13px;
vertical-align: top;
}
.details-table td.label {
width: 38%;
color: #7f8c8d;
font-weight: 600;
background: #f8f9fa;
}
.details-table td.value {
color: #2c3e50;
}
.amount-highlight {
font-size: 18px;
font-weight: bold;
color: #c0392b;
}
.status-badge {
display: inline-block;
padding: 3px 10px;
border-radius: 12px;
font-size: 11px;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.4px;
}
.status-pending {
background: #fdebd0;
color: #b9770e;
}
.status-overdue {
background: #fadbd8;
color: #922b21;
}
.next-steps {
background: #f8f9fa;
border-radius: 6px;
padding: 14px 16px;
margin-top: 8px;
}
.next-steps h4 {
margin: 0 0 8px;
font-size: 14px;
color: #2c3e50;
}
.next-steps ul {
margin: 0;
padding-left: 18px;
font-size: 13px;
line-height: 1.7;
color: #566573;
}
.note {
font-size: 12px;
color: #7f8c8d;
line-height: 1.6;
margin-top: 16px;
font-style: italic;
}
.footer {
background: #f8f9fa;
padding: 14px 18px;
text-align: center;
font-size: 11px;
color: #95a5a6;
line-height: 1.5;
}
@media only screen and (max-width: 480px) {
.content {
padding: 16px 14px;
}
.header h1 {
font-size: 19px;
}
.details-table td.label {
width: 42%;
}
}
</style>
</head>
<body>
<div class="container" style="width:100%;max-width:640px;margin:0 auto;background:#ffffff;border-radius:8px;overflow:hidden;box-shadow:0 4px 10px rgba(0,0,0,0.06);">
<div class="header" style="background:#1f618d;color:#ffffff;padding:24px 20px;text-align:center;">
<h1>Policy Installment Payment Reminder</h1>
<div class="header-subtitle">Nhance India Insurance</div>
</div>
<div class="content" style="padding:24px 20px;">
<?php if (!empty($is_overdue)): ?>
<div class="alert-banner alert-overdue" style="padding:14px 16px;border-radius:6px;margin-bottom:20px;font-size:14px;line-height:1.5;background:#fdecea;border-left:4px solid #c0392b;color:#922b21;">
<strong>Payment Overdue:</strong> The installment for <strong><?= esc($client_name ?? '') ?></strong> was due on <strong><?= esc($payment_date ?? '') ?></strong>. Kindly arrange the payment at the earliest to keep the policy active.
</div>
<?php else: ?>
<div class="alert-banner alert-upcoming" style="padding:14px 16px;border-radius:6px;margin-bottom:20px;font-size:14px;line-height:1.5;background:#eaf4fb;border-left:4px solid #2980b9;color:#1f4e79;">
<strong>Payment Reminder:</strong> An installment payment for <strong><?= esc($client_name ?? '') ?></strong> is due on <strong><?= esc($payment_date ?? '') ?></strong>. Please review the details below.
</div>
<?php endif; ?>
<p class="intro" style="font-size:14px;line-height:1.7;color:#2c3e50;margin:0 0 18px;">
This is a reminder that a policy installment payment is <?= !empty($is_overdue) ? 'overdue' : 'upcoming' ?> for
<strong><?= esc($client_name ?? '') ?></strong> (<?= esc($branch_name ?? '-') ?> branch).
Kindly process the payment on or before the due date to ensure uninterrupted policy coverage.
</p>
<h3 class="section-title" style="font-size:16px;color:#2c3e50;border-bottom:2px solid #3498db;display:inline-block;margin:0 0 12px;padding-bottom:4px;">
Payment Details
</h3>
<table class="details-table" style="width:100%;border-collapse:collapse;margin-bottom:20px;">
<tr>
<td class="label" style="width:38%;padding:10px 12px;border-bottom:1px solid #ecf0f1;font-size:13px;color:#7f8c8d;font-weight:600;background:#f8f9fa;">Organization</td>
<td class="value" style="padding:10px 12px;border-bottom:1px solid #ecf0f1;font-size:13px;color:#2c3e50;"><?= esc($client_name ?? '-') ?></td>
</tr>
<tr>
<td class="label" style="width:38%;padding:10px 12px;border-bottom:1px solid #ecf0f1;font-size:13px;color:#7f8c8d;font-weight:600;background:#f8f9fa;">Branch</td>
<td class="value" style="padding:10px 12px;border-bottom:1px solid #ecf0f1;font-size:13px;color:#2c3e50;"><?= esc($branch_name ?? '-') ?></td>
</tr>
<tr>
<td class="label" style="width:38%;padding:10px 12px;border-bottom:1px solid #ecf0f1;font-size:13px;color:#7f8c8d;font-weight:600;background:#f8f9fa;">Policy Number</td>
<td class="value" style="padding:10px 12px;border-bottom:1px solid #ecf0f1;font-size:13px;color:#2c3e50;"><?= esc($policy_no ?? 'Not Assigned') ?></td>
</tr>
<?php if (!empty($policy_type)): ?>
<tr>
<td class="label" style="width:38%;padding:10px 12px;border-bottom:1px solid #ecf0f1;font-size:13px;color:#7f8c8d;font-weight:600;background:#f8f9fa;">Policy Type</td>
<td class="value" style="padding:10px 12px;border-bottom:1px solid #ecf0f1;font-size:13px;color:#2c3e50;"><?= esc($policy_type) ?></td>
</tr>
<?php endif; ?>
<?php if (!empty($insurer_name)): ?>
<tr>
<td class="label" style="width:38%;padding:10px 12px;border-bottom:1px solid #ecf0f1;font-size:13px;color:#7f8c8d;font-weight:600;background:#f8f9fa;">Insurance Company</td>
<td class="value" style="padding:10px 12px;border-bottom:1px solid #ecf0f1;font-size:13px;color:#2c3e50;"><?= esc($insurer_name) ?></td>
</tr>
<?php endif; ?>
<?php if (!empty($policy_period)): ?>
<tr>
<td class="label" style="width:38%;padding:10px 12px;border-bottom:1px solid #ecf0f1;font-size:13px;color:#7f8c8d;font-weight:600;background:#f8f9fa;">Policy Period</td>
<td class="value" style="padding:10px 12px;border-bottom:1px solid #ecf0f1;font-size:13px;color:#2c3e50;"><?= esc($policy_period) ?></td>
</tr>
<?php endif; ?>
<tr>
<td class="label" style="width:38%;padding:10px 12px;border-bottom:1px solid #ecf0f1;font-size:13px;color:#7f8c8d;font-weight:600;background:#f8f9fa;">Due Date</td>
<td class="value" style="padding:10px 12px;border-bottom:1px solid #ecf0f1;font-size:13px;color:#2c3e50;"><strong><?= esc($payment_date ?? '-') ?></strong></td>
</tr>
<tr>
<td class="label" style="width:38%;padding:10px 12px;border-bottom:1px solid #ecf0f1;font-size:13px;color:#7f8c8d;font-weight:600;background:#f8f9fa;">Amount Payable</td>
<td class="value amount-highlight" style="padding:10px 12px;border-bottom:1px solid #ecf0f1;font-size:18px;font-weight:bold;color:#c0392b;"><?= esc($installment_amount ?? '-') ?></td>
</tr>
<tr>
<td class="label" style="width:38%;padding:10px 12px;border-bottom:1px solid #ecf0f1;font-size:13px;color:#7f8c8d;font-weight:600;background:#f8f9fa;">Status</td>
<td class="value" style="padding:10px 12px;border-bottom:1px solid #ecf0f1;font-size:13px;color:#2c3e50;">
<span class="status-badge <?= !empty($is_overdue) ? 'status-overdue' : 'status-pending' ?>" style="display:inline-block;padding:3px 10px;border-radius:12px;font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:0.4px;background:<?= !empty($is_overdue) ? '#fadbd8' : '#fdebd0' ?>;color:<?= !empty($is_overdue) ? '#922b21' : '#b9770e' ?>;">
<?= !empty($is_overdue) ? 'Payment Overdue' : 'Payment Pending' ?>
</span>
</td>
</tr>
</table>
<div class="next-steps" style="background:#f8f9fa;border-radius:6px;padding:14px 16px;margin-top:8px;">
<h4 style="margin:0 0 8px;font-size:14px;color:#2c3e50;">Important Instructions</h4>
<ul style="margin:0;padding-left:18px;font-size:13px;line-height:1.7;color:#566573;">
<li>Please arrange the installment payment of <strong><?= esc($installment_amount ?? '') ?></strong> on or before <strong><?= esc($payment_date ?? '') ?></strong>.</li>
<li>After making the payment, kindly share the payment reference / UTR details for confirmation and record update.</li>
<li>If the payment has already been made, please share the transaction details at the earliest.</li>
<li>For any clarification regarding the amount or due date, please coordinate with the concerned team.</li>
</ul>
</div>
<p class="note" style="font-size:12px;color:#7f8c8d;line-height:1.6;margin-top:16px;font-style:italic;">
Timely payment helps ensure continuous insurance coverage. Thank you for your cooperation.
</p>
</div>
<div class="footer" style="background:#f8f9fa;padding:14px 18px;text-align:center;font-size:11px;color:#95a5a6;line-height:1.5;">
This is an automated notification from Nhance India Insurance. Please do not reply to this email.
<br>Generated on <?= esc($generated_on ?? date('d-m-Y H:i')) ?>
</div>
</div>
</body>
</html>