From 515aa28db8128bab5ca420952a9191f2f5a91d3c Mon Sep 17 00:00:00 2001 From: Venkatesh Date: Mon, 15 Jun 2026 09:26:14 +0530 Subject: [PATCH] FEAT_INSTALLMNT_CONFIG --- .env.sample | 12 ++++ app/Config/BdsConfig.php | 64 +++++++++++++++++++ .../PolicyTransactionController.php | 18 +++++- app/Models/BdsPlacementModel.php | 24 ++++++- app/Views/client_policy.php | 8 +-- 5 files changed, 114 insertions(+), 12 deletions(-) create mode 100644 app/Config/BdsConfig.php diff --git a/.env.sample b/.env.sample index b288c04c..65018cd5 100755 --- a/.env.sample +++ b/.env.sample @@ -153,6 +153,18 @@ LEAD_CLIENT_FROM_MAIL_ID = # BDS Daily Report Emails Configuration bds.dailyReportEmails = +# BDS Installment Reminder (pending UTR / overdue) — used by getLeadInstallmentDetails / sendInstallmentRemainderMail cron +# Master switch: when false, no installment reminder records are fetched +bds.installmentReminder.enabled = true +# Business days ahead of today to match upcoming payment_date (was hardcoded 5) +bds.installmentReminder.businessDays = 5 +# When true, also fetch records with null UTR whose payment_date is already past (overdue) +bds.installmentReminder.fetchOverduePendingUtr = false +# When true, fetch every day; when false, only on days listed in bds.installmentReminder.days +bds.installmentReminder.daily = true +# Comma-separated weekdays (mon,tue,wed,thu,fri,sat,sun) — used only when daily = false +bds.installmentReminder.days = mon,tue,wed,thu,fri + #-------------------------------------------------------------------- # MEDI ASSIST WELLNESS SSO Configuration diff --git a/app/Config/BdsConfig.php b/app/Config/BdsConfig.php new file mode 100644 index 00000000..100c746c --- /dev/null +++ b/app/Config/BdsConfig.php @@ -0,0 +1,64 @@ +installmentReminderEnabled = $this->envToBool( + env('bds.installmentReminder.enabled', 'true') + ); + $this->installmentReminderBusinessDays = max( + 0, + (int) env('bds.installmentReminder.businessDays', 5) + ); + $this->installmentReminderFetchOverduePendingUtr = $this->envToBool( + env('bds.installmentReminder.fetchOverduePendingUtr', 'false') + ); + $this->installmentReminderDaily = $this->envToBool( + env('bds.installmentReminder.daily', 'true') + ); + + $days = env('bds.installmentReminder.days', 'mon,tue,wed,thu,fri'); + $this->installmentReminderDays = array_values(array_filter(array_map( + static fn (string $day): string => strtolower(substr(trim($day), 0, 3)), + explode(',', (string) $days) + ))); + } + + public function shouldFetchInstallmentRemindersToday(): bool + { + if (!$this->installmentReminderEnabled) { + return false; + } + + if ($this->installmentReminderDaily) { + return true; + } + + $today = strtolower(date('D')); + + return in_array($today, $this->installmentReminderDays, true); + } + + private function envToBool(mixed $value): bool + { + return in_array(strtolower((string) $value), ['1', 'true', 'yes', 'on'], true); + } +} diff --git a/app/Controllers/PolicyTransactionController.php b/app/Controllers/PolicyTransactionController.php index 02852b26..a7592ca0 100644 --- a/app/Controllers/PolicyTransactionController.php +++ b/app/Controllers/PolicyTransactionController.php @@ -40,6 +40,7 @@ use App\Models\NhanceBranchModel; use App\Models\BDSDumpModel; use App\Models\VehicleModel; use CodeIgniter\CLI\CLI; +use Config\BdsConfig; use Exception; class PolicyTransactionController extends BaseController @@ -5349,6 +5350,16 @@ class PolicyTransactionController extends BaseController $this->myLogger->logme("error", "Cron Job For Send Installment Remainder Mail Started"); try { + /** @var BdsConfig $bdsConfig */ + $bdsConfig = config(BdsConfig::class); + if (!$bdsConfig->shouldFetchInstallmentRemindersToday()) { + $this->myLogger->logme( + 'error', + 'Installment reminder fetch skipped (bds.installmentReminder.enabled / daily / days config)' + ); + CLI::write('Installment reminder fetch skipped per .env configuration'); + return ['status' => false, 'message' => 'Fetch skipped per configuration', 'response' => []]; + } $bdsInstallmentData = []; @@ -5418,14 +5429,17 @@ class PolicyTransactionController extends BaseController Policy No : {$policy_no}"; + $contactPersonEmail = trim((string) ($data['contact_person_email'] ?? '')); + $to_mail = array_merge( array_column($heads, 'email'), array_column($admins, 'email'), array_column($buisness_team, 'email'), - [$sales_person_mail] + [$sales_person_mail], + $contactPersonEmail !== '' ? [$contactPersonEmail] : [] ); - $to_mail = array_unique($to_mail); + $to_mail = array_values(array_unique(array_filter($to_mail))); $this->myLogger->logme("error", "Selected To Address : " . json_encode($to_mail)); diff --git a/app/Models/BdsPlacementModel.php b/app/Models/BdsPlacementModel.php index c0267eb8..84b349a1 100644 --- a/app/Models/BdsPlacementModel.php +++ b/app/Models/BdsPlacementModel.php @@ -3,6 +3,7 @@ namespace App\Models; use CodeIgniter\Model; +use Config\BdsConfig; class BdsPlacementModel extends Model { @@ -132,6 +133,13 @@ class BdsPlacementModel extends Model public function getLeadInstallmentDetails() { + /** @var BdsConfig $config */ + $config = config(BdsConfig::class); + + if (!$config->shouldFetchInstallmentRemindersToday()) { + return []; + } + $heads = $this->db->table('user_profiles') ->select('email')->where(['role' => 5, 'is_active' => 1]) ->get()->getResultArray(); @@ -147,14 +155,24 @@ class BdsPlacementModel extends Model ->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") + ->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") ->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", $this->addBusinessDays(5)); + ->where("lipd.utr_no IS NULL"); + + $targetPaymentDate = $this->addBusinessDays($config->installmentReminderBusinessDays); + + if ($config->installmentReminderFetchOverduePendingUtr) { + $builder->groupStart() + ->where('lipd.payment_date', $targetPaymentDate) + ->orWhere('lipd.payment_date <', date('Y-m-d')) + ->groupEnd(); + } else { + $builder->where('lipd.payment_date', $targetPaymentDate); + } $data = $builder->get()->getResultArray(); diff --git a/app/Views/client_policy.php b/app/Views/client_policy.php index 7be33e5e..101ab426 100755 --- a/app/Views/client_policy.php +++ b/app/Views/client_policy.php @@ -1546,14 +1546,8 @@ input:checked + .slider_blue::before { return isNaN(parsed.getTime()) ? null : parsed; } - var policyMonthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; - function formatPolicyDisplayDate(inputDate) { - var d = parsePolicyDate(inputDate); - if (!d) { - return (inputDate && String(inputDate).trim() !== '') ? String(inputDate) : ''; - } - return d.getDate() + '/' + policyMonthNames[d.getMonth()] + '/' + d.getFullYear(); + return formatPolicyFormDate(inputDate); } function formatPolicyFormDate(inputDate) {