From bbe2a3d9ab539797929db0a9e712e8293097e239 Mon Sep 17 00:00:00 2001 From: Venkatesh Date: Thu, 4 Jun 2026 11:54:40 +0530 Subject: [PATCH] CHANGE_INSTAMENT_REMIDER_MAIL_BDS_TO_LEAD --- .../PolicyTransactionController.php | 18 +++---- app/Models/BdsPlacementModel.php | 53 +++++++++++++++++++ 2 files changed, 61 insertions(+), 10 deletions(-) diff --git a/app/Controllers/PolicyTransactionController.php b/app/Controllers/PolicyTransactionController.php index 26da53b2..a8d1ab90 100644 --- a/app/Controllers/PolicyTransactionController.php +++ b/app/Controllers/PolicyTransactionController.php @@ -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()); } } diff --git a/app/Models/BdsPlacementModel.php b/app/Models/BdsPlacementModel.php index 947f8a0f..e27ecd9c 100644 --- a/app/Models/BdsPlacementModel.php +++ b/app/Models/BdsPlacementModel.php @@ -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() {