Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
velz 2026-06-05 11:33:04 +05:30
commit dee4858327
7 changed files with 258 additions and 49 deletions

View File

@ -1015,34 +1015,27 @@ class DashboardController extends AdminController
$db2 = \Config\Database::connect('preDB');
$builder = $db2->table('employees');
$total_employee_draft_count = $builder->join('employee_polices', 'employees.id = employee_polices.employee_id')
->select('employee_polices.status, count(*) as count')
$total_employee_draft_count = $db2->table('employee_polices')
->join('employees', 'employees.id = employee_polices.employee_id')
->where('DATE(employee_polices.created_at)', $today)
->where('employee_polices.is_active', 1)
->where('employees.is_active', 1)
->whereIn('employee_polices.status', ['draft'])
->groupBy('employee_polices.status')
->where('employee_polices.status', 'draft')
->countAllResults();
$builder1 = $db2->table('employees');
$total_employee_enrolled_count = $builder1->join('employee_polices', 'employees.id = employee_polices.employee_id')
->select('employee_polices.status, count(*) as count')
$total_employee_enrolled_count = $db2->table('employee_polices')
->join('employees', 'employees.id = employee_polices.employee_id')
->where('DATE(employee_polices.created_at)', $today)
->where('employee_polices.is_active', 1)
->where('employees.is_active', 1)
->whereIn('employee_polices.status', ['enrolled'])
->groupBy('employee_polices.status')
->where('employee_polices.status', 'enrolled')
->countAllResults();
$builder2 = $db2->table('files');
$total_open_for_enrollemnt_policy_count = $builder2
->select('COUNT(*) as count')
->where('enrollment_open_date <=', $today)
->where('enrollment_close_date >=', $today)
$total_open_for_enrollemnt_policy_count = $db2->table('client_policy')
->where('open_date <=', $today)
->where('close_date >=', $today)
->where('is_active', 1)
->where('status', 'success')
->where('policy_status', 1)
->countAllResults();
$data = [

View File

@ -2266,6 +2266,7 @@ class EmployeeRestController extends AdminController
client_policy.insurer_id as insurer_id,
DATE_FORMAT(client_policy.policy_start_date, '%d-%m-%Y') AS policy_start_date,
DATE_FORMAT(client_policy.policy_end_date, '%d-%m-%Y') AS policy_expiry_date,
clients.client_logo as client_logo,
(
select COALESCE(ROUND(SUM(rata_premimum + gst)), 0)
from employee_polices
@ -2275,6 +2276,7 @@ class EmployeeRestController extends AdminController
) as total_premium,
CASE WHEN policy_type.allocg IN ('Non-EB', 'Marine') THEN 'Non-EB' ELSE 'EB' END as allocg
", false)
->join('clients', 'clients.id = client_policy.client_id', 'left')
->join('policy_type', 'policy_type.id = client_policy.policy_type_id', 'left')
->where('md5(client_policy.client_id)', $this->request->getGet('client_id'))
->where('client_policy.client_branch_id', $this->request->getGet('client_branch_id'))
@ -2293,6 +2295,7 @@ class EmployeeRestController extends AdminController
$value['policy_name'] = $policyTypeData->long_name;
$value['insurer_name'] = $insurerData->name;
$value['insurer_short_name'] = $insurerData->short_name;
$value['client_logo'] = ! empty($value['client_logo']) ? base_url() . 'public/uploads/logo/' . $value['client_logo'] : '';
$employeeDetails = $this->employeePolicyModel->getEmployeePolicy(client_id: $value['client_id'], policy_id: $value['client_policy_id'], status: 0, branch_id: $this->request->getGet('client_branch_id'), status_type: 'inactive');
// dd($employeeDetails);
$activeCount = 0;

View File

@ -39,6 +39,7 @@ use App\Helpers\ExcelSanitizeHelper;
use App\Models\NhanceBranchModel;
use App\Models\BDSDumpModel;
use App\Models\VehicleModel;
use CodeIgniter\CLI\CLI;
use Exception;
class PolicyTransactionController extends BaseController
@ -5324,21 +5325,18 @@ class PolicyTransactionController extends BaseController
$bdsInstallmentData = [];
try {
$bdsInstallmentData = $this->BdsPlacementModel->getClientInstallmentDetails();
$bdsInstallmentData = $this->BdsPlacementModel->getLeadInstallmentDetails();
} catch (Exception $e) {
$this->myLogger->logme('error', 'Exception: ' . $e->getMessage() . 'Page: ' . $e->getFile() . ' Line: ' . $e->getLine());
}
$this->myLogger->logme("error", "Data for BDS Installment " . json_encode($bdsInstallmentData));
// dd($bdsInstallmentData);
// print_r($bdsInstallmentData);die();
if (empty($bdsInstallmentData)) {
$this->myLogger->logme("error", "No Client Installment is Due in the 15th Day");
return false;
CLI::write("No Client Installment is Due in the 15th Day");
return ['status' => false, 'message' => 'No data found', 'response' => []];
}
foreach ($bdsInstallmentData as $installmentData) {
@ -5358,13 +5356,13 @@ class PolicyTransactionController extends BaseController
$this->myLogger->logme('error', 'res: ' . json_encode($res));
if ($res->status == 'success') {
return true;
return ['status' => true, 'message' => 'Mail sent successfully', 'response' => $res];
} else {
return false;
return ['status' => false, 'message' => 'Mail sent failed', 'response' => $res];
}
}
} catch (Exception $e) {
} catch (Exception $e) {
$this->myLogger->logme('error', 'Exception: ' . $e->getMessage() . 'Page: ' . $e->getFile() . ' Line: ' . $e->getLine());
}
}

View File

@ -10,6 +10,7 @@ use App\Models\SalesLeadNoteModel;
use App\Models\SalesTargetModel;
use App\Models\UserModel;
use App\Models\ClientModel;
use App\Helpers\MailHelper;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\API\ResponseTrait;
@ -330,7 +331,10 @@ class SalesController extends BaseController
return $this->fail($this->leadModel->errors());
}
return $this->respondCreated(['status' => 'success', 'id' => $this->leadModel->getInsertID()]);
$leadId = $this->leadModel->getInsertID();
$this->sendLeadCreateMail($leadId, $data);
return $this->respondCreated(['status' => 'success', 'id' => $leadId]);
} catch (\Exception $e) {
return $this->failServerError($e->getMessage());
}
@ -2595,4 +2599,132 @@ public function salesManagerLevelDashboard($userId, $current_fin_year = null, $f
];
}
}
/**
* Send lead-create notification email when the logged-in user's branch is Chennai.
*/
private function sendLeadCreateMail(int $leadId, array $leadData): void
{
try {
if (!$this->isLoggedInUserChennaiBranch()) {
return;
}
$toMail = trim((string) getenv('LEAD_CREATE_MAIL'));
if ($toMail === '') {
log_message('error', 'sendLeadCreateMail: LEAD_CREATE_MAIL is not configured.');
return;
}
$recipientEmails = array_filter(array_map('trim', explode(',', $toMail)));
if (empty($recipientEmails)) {
log_message('error', 'sendLeadCreateMail: No valid recipients in LEAD_CREATE_MAIL.');
return;
}
$creator = $this->getLeadCreateMailCreatorDetails();
$assignedUser = $this->userModel->where('id', $leadData['assigned_to'] ?? 0)->first() ?? [];
$companyName = $leadData['company_name'] ?? '';
$subject = 'New Lead Created - ' . $companyName;
$message = $this->buildLeadCreateMailMessage(
$companyName,
$leadData['email'] ?? '',
$leadData['phone'] ?? '',
$leadData['status'] ?? '',
$creator['name'] ?? '',
$creator['email'] ?? '',
$creator['branch'] ?? '',
$assignedUser['first_name'] ?? '',
$assignedUser['email'] ?? '',
date('d/m/Y h:i A')
);
$res = MailHelper::send_email([
'mail' => $recipientEmails,
'subject' => $subject,
'message' => $message,
'common' => ['module' => 'sales', 'pk' => $leadId, 'mail_type' => 'lead_create'],
]);
$resDecoded = is_string($res) ? json_decode($res, true) : $res;
if (!isset($resDecoded['status']) || $resDecoded['status'] !== 'success') {
log_message('error', 'sendLeadCreateMail: Email send failed - ' . json_encode($resDecoded));
}
} catch (\Throwable $e) {
log_message('error', 'sendLeadCreateMail: ' . $e->getMessage());
}
}
private function isLoggedInUserChennaiBranch(): bool
{
$userId = get_session_userid();
if (empty($userId)) {
return false;
}
$row = $this->userModel
->select('id')
->where('id', $userId)
->where('nhance_branch_id', 1)
->first();
return !empty($row);
}
private function getLeadCreateMailCreatorDetails(): array
{
$userId = get_session_userid();
$db = \Config\Database::connect();
$row = $db->table('user_profiles up')
->select('up.first_name, up.email, nb.branch_name')
->join('nhance_branch nb', 'nb.id = up.nhance_branch_id', 'left')
->where('up.id', $userId)
->get()
->getRowArray();
if (!$row) {
return ['name' => '', 'email' => '', 'branch' => ''];
}
return [
'name' => $row['first_name'] ?? '',
'email' => $row['email'] ?? '',
'branch' => $row['branch_name'] ?? '',
];
}
private function buildLeadCreateMailMessage(
string $companyName,
string $leadEmail,
string $leadMobile,
string $leadStatus,
string $createdByName,
string $createdByEmail,
string $createdByBranch,
string $assignedUserName,
string $assignedUserEmail,
string $createdDateTime
): string {
$e = static fn (?string $value): string => htmlspecialchars((string) ($value ?? ''), ENT_QUOTES, 'UTF-8');
return '<p>Hello Team,</p>'
. '<p>A new lead has been created</p>'
. '<h3>Lead Details</h3>'
. '<p><strong>Company Name :</strong> ' . $e($companyName) . '</p>'
. '<p><strong>Email :</strong> ' . $e($leadEmail) . '</p>'
. '<p><strong>Mobile :</strong> ' . $e($leadMobile) . '</p>'
. '<p><strong>Status :</strong> ' . $e($leadStatus) . '</p>'
. '<h3>Created By</h3>'
. '<p><strong>Name :</strong> ' . $e($createdByName) . '</p>'
. '<p><strong>Email :</strong> ' . $e($createdByEmail) . '</p>'
. '<p><strong>Branch :</strong> ' . $e($createdByBranch) . '</p>'
. '<h3>Assigned To</h3>'
. '<p><strong>Name :</strong> ' . $e($assignedUserName) . '</p>'
. '<p><strong>Email :</strong> ' . $e($assignedUserEmail) . '</p>'
. '<h3>Created On</h3>'
. '<p><strong>Date &amp; Time :</strong> ' . $e($createdDateTime) . '</p>'
. '<p>Regards,<br>NHANCE INDIA INSURANCE BROKING PRIVATE LIMITED</p>';
}
}

View File

@ -114,6 +114,59 @@ class BdsPlacementModel extends Model
return $data;
}
public function getLeadInstallmentDetails()
{
$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();
$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, cp.policy_no")
->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")
->where("lipd.is_active", 1)
->where("lipd.utr_no IS NULL")
->where("lipd.payment_date", date('Y-m-d', strtotime('+15 days')));
$data = $builder->get()->getResultArray();
foreach ($data as &$row) {
$sales_person_ids = json_decode($row['salse_person_id'], true);
$sales_person_id = $sales_person_ids[0] ?? null;
if ($sales_person_id) {
$user = $this->db->table('user_profiles')
->select('email')
->where('id', (int) $sales_person_id)
->get()
->getRowArray();
$row['sales_person'] = $user['email'] ?? 'N/A';
} else {
$row['sales_person'] = 'Not Assigned';
}
$row['heads'] = $heads;
$row['admins'] = $admins;
$row['buisness_team'] = $businessTeam;
}
return $data;
}
public function getClientInstallmentDetails_olds()
{

View File

@ -166,19 +166,19 @@
</div>
<div class="content" style="padding:20px;">
<div class="report-date" style="color:#7f8c8d;font-size:13px;margin-bottom:16px;text-align:right;">Date: <?= $today ?></div>
<div class="report-date" style="color:#7f8c8d;font-size:13px;margin-bottom:16px;text-align:right;">Date: <?= $today ?? "" ?></div>
<!-- File Operations -->
<h3 class="section-title" style="font-size:17px;color:#2c3e50;border-bottom:2px solid #3498db;display:inline-block;margin:18px 0 12px;padding-bottom:4px;">Inception &amp; Endorsement (File Upload)</h3>
<div class="stats-grid">
<div class="stat-card" style="width:100%;display:block;background:#f8f9fa;padding:12px 14px;border-radius:6px;border-left:4px solid #3498db;box-sizing:border-box;margin-bottom:10px;">
<div class="stat-label">Total Inception</div>
<div class="stat-value"><?= $total_inception_count ?></div>
<div class="stat-value"><?= $total_inception_count ?? 0 ?></div>
<div class="stat-note">Employee file uploads marked as inception</div>
</div>
<div class="stat-card" style="width:100%;display:block;background:#f8f9fa;padding:12px 14px;border-radius:6px;border-left:4px solid #3498db;box-sizing:border-box;margin-bottom:10px;">
<div class="stat-label">Total Endorsement</div>
<div class="stat-value"><?= $total_endorsement_count ?></div>
<div class="stat-value"><?= $total_endorsement_count ?? 0 ?></div>
<div class="stat-note">All noninception successful uploads</div>
</div>
</div>
@ -203,12 +203,12 @@
<div class="stats-grid">
<div class="stat-card" style="width:100%;display:block;background:#f8f9fa;padding:12px 14px;border-radius:6px;border-left:4px solid #e67e22;box-sizing:border-box;margin-bottom:10px;">
<div class="stat-label">TPA (Inception / Endorsement)</div>
<div class="stat-value"><?= $total_tpa_incetion_count ?> / <?= $total_tpa_endorsement_count ?></div>
<div class="stat-value"><?= $total_tpa_incetion_count ?? 0 ?> / <?= $total_tpa_endorsement_count ?? 0 ?></div>
<div class="stat-note">Successful TPA events</div>
</div>
<div class="stat-card" style="width:100%;display:block;background:#f8f9fa;padding:12px 14px;border-radius:6px;border-left:4px solid #9b59b6;box-sizing:border-box;margin-bottom:10px;">
<div class="stat-label">Insurer (Inception / Endorsement)</div>
<div class="stat-value"><?= $total_insurer_incetion_count ?> / <?= $total_insurer_endorsement_count ?></div>
<div class="stat-value"><?= $total_insurer_incetion_count ?? 0 ?> / <?= $total_insurer_endorsement_count ?? 0 ?></div>
<div class="stat-note">Successful insurer events</div>
</div>
</div>
@ -218,22 +218,22 @@
<div class="stats-grid">
<div class="stat-card" style="width:100%;display:block;background:#f8f9fa;padding:12px 14px;border-radius:6px;border-left:4px solid #27ae60;box-sizing:border-box;margin-bottom:10px;">
<div class="stat-label">Opportunities &amp; Won</div>
<div class="stat-value"><?= $total_opportunity_count ?> / <?= $total_placement_count ?></div>
<div class="stat-value"><?= $total_opportunity_count ?? 0 ?> / <?= $total_placement_count ?? 0 ?></div>
<div class="stat-note">Total opportunities created vs converted</div>
</div>
<div class="stat-card" style="width:100%;display:block;background:#f8f9fa;padding:12px 14px;border-radius:6px;border-left:4px solid #16a085;box-sizing:border-box;margin-bottom:10px;">
<div class="stat-label">RFQ (Created / Sent to Insurer)</div>
<div class="stat-value"><?= $total_rfq_created_count ?> / <?= $total_rfq_insurer_send_count ?></div>
<div class="stat-value"><?= $total_rfq_created_count ?? 0 ?> / <?= $total_rfq_insurer_send_count ?? 0 ?></div>
<div class="stat-note">Movement from opportunity to RFQ</div>
</div>
<div class="stat-card" style="width:100%;display:block;background:#f8f9fa;padding:12px 14px;border-radius:6px;border-left:4px solid #2980b9;box-sizing:border-box;margin-bottom:10px;">
<div class="stat-label">QCR (Created / Sent to Client)</div>
<div class="stat-value"><?= $total_qcr_created_count ?> / <?= $total_qcr_client_send_count ?></div>
<div class="stat-value"><?= $total_qcr_created_count ?? 0 ?> / <?= $total_qcr_client_send_count ?? 0 ?></div>
<div class="stat-note">Quotes prepared and shared</div>
</div>
<div class="stat-card" style="width:100%;display:block;background:#f8f9fa;padding:12px 14px;border-radius:6px;border-left:4px solid #8e44ad;box-sizing:border-box;margin-bottom:10px;">
<div class="stat-label">Total Leads &amp; Activities</div>
<div class="stat-value"><?= $total_lead_count ?> / <?= $total_activity_count ?></div>
<div class="stat-value"><?= $total_lead_count ?? 0 ?> / <?= $total_activity_count ?? 0 ?></div>
<div class="stat-note">Lead entries and logged touchpoints</div>
</div>
</div>
@ -243,12 +243,12 @@
<div class="stats-grid">
<div class="stat-card" style="width:100%;display:block;background:#f8f9fa;padding:12px 14px;border-radius:6px;border-left:4px solid #d35400;box-sizing:border-box;margin-bottom:10px;">
<div class="stat-label">Total BDS Transactions</div>
<div class="stat-value"><?= $total_bds_count ?></div>
<div class="stat-value"><?= $total_bds_count ?? 0 ?></div>
<div class="stat-note">All policy transactions processed</div>
</div>
<div class="stat-card" style="width:100%;display:block;background:#f8f9fa;padding:12px 14px;border-radius:6px;border-left:4px solid #c0392b;box-sizing:border-box;margin-bottom:10px;">
<div class="stat-label">BDS (Policy / Endorsement)</div>
<div class="stat-value"><?= $total_bds_policy_wise_count ?> / <?= $total_bds_endorsement_wise_count ?></div>
<div class="stat-value"><?= $total_bds_policy_wise_count ?? 0?> / <?= $total_bds_endorsement_wise_count ?? 0 ?></div>
<div class="stat-note">Split of inceptions vs endorsements</div>
</div>
</div>
@ -289,7 +289,7 @@
<div class="stats-grid">
<div class="stat-card" style="width:100%;display:block;background:#f8f9fa;padding:12px 14px;border-radius:6px;border-left:4px solid #d35400;box-sizing:border-box;margin-bottom:10px;">
<div class="stat-label">Total Claims Registered for the day</div>
<div class="stat-value"><?= $total_claim_count ?></div>
<div class="stat-value"><?= $total_claim_count ?? 0 ?></div>
<div class="stat-note"></div>
</div>
</div>

View File

@ -379,7 +379,7 @@ $vd_col_width_px = nhance_dt_column_widths_px($vd_header_labels, $vd_col_max_len
? (string) $row->amt_updated_by_name
: (!empty($row->amt_updated_by) ? ('User #' . $row->amt_updated_by) : '-');
$historyUpdatedAt = !empty($row->amt_updated_at)
? date('d M Y, h:i A', strtotime((string) $row->amt_updated_at))
? date('d/m/Y h:i A', strtotime((string) $row->amt_updated_at))
: '-';
?>
<tr id="<?php echo $row->id;?>"
@ -387,7 +387,7 @@ $vd_col_width_px = nhance_dt_column_widths_px($vd_header_labels, $vd_col_max_len
data-transaction-type="<?= esc((string) $row->transaction_type, 'attr') ?>"
data-credit="<?= esc((string) $creditAmount, 'attr') ?>"
data-debit="<?= esc((string) $debitAmount, 'attr') ?>">
<td><?php echo date('d-M-Y h:i A', strtotime($row->created_at)); ?></td>
<td><?php echo date('d/m/Y h:i A', strtotime($row->created_at)); ?></td>
<td><?php echo isset($row->record_date)? date('d-M-Y', strtotime($row->record_date)):'-' ?></td>
<td><?php echo $row->unit ?? ' - '; ?></td>
<!-- <td><?php echo $row->policy_name ?? '<center> - </center>'; ?></td> -->
@ -481,14 +481,14 @@ $vd_col_width_px = nhance_dt_column_widths_px($vd_header_labels, $vd_col_max_len
<div class="deposit-history-meta-row">
<div class="deposit-history-meta-label">
<i class="mdi mdi-account-outline"></i>
<span>Changed by</span>
<span>Modified by</span>
</div>
<div class="deposit-history-meta-value" id="history_updated_by">-</div>
</div>
<div class="deposit-history-meta-row">
<div class="deposit-history-meta-label">
<i class="mdi mdi-calendar-month-outline"></i>
<span>Changed at</span>
<span>Modified at</span>
</div>
<div class="deposit-history-meta-value" id="history_updated_at">-</div>
</div>
@ -668,6 +668,38 @@ $vd_col_width_px = nhance_dt_column_widths_px($vd_header_labels, $vd_col_max_len
});
nhanceListDataTableBeforeInit();
function depositExportFormatBody(data, row, column, node) {
if (column === 6 || column === 7) {
var $input = $(node).find('.deposit-inline-input');
if ($input.length) {
var val = ($input.val() || '').trim();
return val !== '' ? val : '-';
}
var $tr = $(node).closest('tr');
var credit = parseFloat($tr.attr('data-credit')) || 0;
var debit = parseFloat($tr.attr('data-debit')) || 0;
if (column === 6) {
return credit > 0 ? String(credit) : '-';
}
return debit > 0 ? String(debit) : '-';
}
if (column === 8) {
var $balanceSpan = $(node).find('.deposit-balance-wrap > span').first();
if ($balanceSpan.length) {
return ($balanceSpan.text() || '').trim();
}
return ($(node).text() || '').trim();
}
if (typeof data === 'string' && data.indexOf('<') !== -1) {
return $('<div>').html(data).text().trim();
}
return data;
}
var depositExportOptions = {
format: {
body: depositExportFormatBody
}
};
var depositPageStorageKey = 'view_deposit_datatable_page_' + window.location.pathname + window.location.search;
function getStoredDepositPage() {
var page = parseInt(sessionStorage.getItem(depositPageStorageKey), 10);
@ -780,7 +812,7 @@ $vd_col_width_px = nhance_dt_column_widths_px($vd_header_labels, $vd_col_max_len
extend: 'csv',
text: '<i class="mdi mdi-file-delimited " ></i><span class=" btn-custom"> CSV </span>',
title: 'CD TransactionDetails',
exportOptions: { columns: '' },
exportOptions: $.extend(true, { columns: '' }, depositExportOptions),
className: 'app-btn-primary ',
},
{
@ -788,9 +820,7 @@ $vd_col_width_px = nhance_dt_column_widths_px($vd_header_labels, $vd_col_max_len
text: '<i class="mdi mdi-file-excel " ></i><span class=" btn-custom"> EXCEL </span>',
title: 'CD TransactionDetails',
sheetName: 'CD TransactionDetails',
exportOptions: {
orthogonal: 'sort'
}
exportOptions: $.extend(true, { orthogonal: 'sort' }, depositExportOptions)
}
]
}