FEAT_INSTALLMNT_CONFIG

This commit is contained in:
VENKATESHWARAN 2026-06-15 09:26:14 +05:30
parent 90ca29b748
commit 515aa28db8
5 changed files with 114 additions and 12 deletions

View File

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

64
app/Config/BdsConfig.php Normal file
View File

@ -0,0 +1,64 @@
<?php
namespace Config;
use CodeIgniter\Config\BaseConfig;
class BdsConfig extends BaseConfig
{
public bool $installmentReminderEnabled = false;
public int $installmentReminderBusinessDays = 5;
public bool $installmentReminderFetchOverduePendingUtr = false;
public bool $installmentReminderDaily = false;
/** @var string[] Lowercase three-letter day abbreviations, e.g. mon, tue */
public array $installmentReminderDays = [];
public function __construct()
{
parent::__construct();
$this->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);
}
}

View File

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

View File

@ -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();

View File

@ -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) {