From f8dab3cb590eabd5548462b40137b11b10769fcd Mon Sep 17 00:00:00 2001 From: Venkatesh Date: Mon, 6 Jul 2026 15:58:31 +0530 Subject: [PATCH] FIX_RENEWAL_POLICY_NOT_LISTED_IN_THE_POLICY_LIST_PAGE --- app/Controllers/ClientController.php | 2 +- app/Controllers/LeadsController.php | 8 +++++++ app/Models/LeadsModel.php | 35 +++++++++++++++++++--------- app/Views/client_list.php | 2 +- app/Views/client_policy.php | 2 +- 5 files changed, 35 insertions(+), 14 deletions(-) diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 90b426ce..b56714a0 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -1037,7 +1037,7 @@ class ClientController extends AdminController $editData['client_branch'] = $this->clientBranchModel->where(['client_id' => $id, 'is_active' => 1])->findAll(); $editData['client_relation'] = $this->clientRMModel->where(['client_id' => $id, 'is_active' => 1])->findAll(); $editData['client_branch']['role'] = get_role_id(); - $editData['lead_data'] = $this->leadsModel->getLeadForInsertClientList(null, $id, 'update'); + $editData['lead_data'] = $this->leadsModel->getLeadForInsertClientList([1,3,2], $id, 'update'); $clientPoliceData = $this->clientPolicyModel->getClientPolicyByClientId($id); foreach ($clientPoliceData as $key => $value) { diff --git a/app/Controllers/LeadsController.php b/app/Controllers/LeadsController.php index ecc9ed74..bd343eee 100644 --- a/app/Controllers/LeadsController.php +++ b/app/Controllers/LeadsController.php @@ -4539,6 +4539,14 @@ class LeadsController extends BaseController return $this->respond(['status' => false, 'message' => 'Failed to create policy', 'data' => null], 200); } + if (empty($client_id) && ! empty($data['client_id'])) { + $client_id = $data['client_id']; + } + + if (empty($branch_id) && ! empty($data['client_branch_id'])) { + $branch_id = $data['client_branch_id']; + } + $result = $this->createClientPolicyWithLeadData($data, $client_id, $branch_id); // print_r($result); die; diff --git a/app/Models/LeadsModel.php b/app/Models/LeadsModel.php index 5ebd7f13..1d20863a 100644 --- a/app/Models/LeadsModel.php +++ b/app/Models/LeadsModel.php @@ -190,7 +190,7 @@ class LeadsModel extends Model public function getLeadForInsertClientList($type = null, $client_id = null, $from = null) { $query = $this->db->table('leads') - ->select('leads.*, user_profiles.first_name as user_name, policy_type.allocg') + ->select('leads.*, user_profiles.first_name as user_name, policy_type.allocg, policy_type.policy_type as policy_type_name') ->join('user_profiles', 'leads.created_by = user_profiles.id') ->join('policy_type', 'leads.policy_type_id = policy_type.id', 'left') ->where('leads.is_active', 1) @@ -200,13 +200,24 @@ class LeadsModel extends Model $query->where("(leads.is_policy_created = '' OR leads.is_policy_created IS NULL)"); if ($client_id) { - $query->join('clients', 'clients.id = ' . (int) $client_id) - ->join('client_branch', 'client_branch.client_id = clients.id AND client_branch.is_active = 1') - ->where('leads.client_name = clients.client_name', null, false) - ->where('leads.client_short_name = clients.short_name', null, false) - ->where('leads.branch_name = client_branch.branch_name', null, false) - ->where('leads.branch_code = client_branch.branch_code', null, false) - ->groupBy('leads.id'); + $clientId = (int) $client_id; + $query->groupStart() + ->where('leads.client_id', $clientId) + ->orWhere( + "EXISTS ( + SELECT 1 + FROM clients c + INNER JOIN client_branch cb ON cb.client_id = c.id AND cb.is_active = 1 + WHERE c.id = {$clientId} + AND leads.client_name = c.client_name + AND leads.client_short_name = c.short_name + AND leads.branch_name = cb.branch_name + AND leads.branch_code = cb.branch_code + )", + null, + false + ) + ->groupEnd(); } } else { $query->groupStart() @@ -214,14 +225,16 @@ class LeadsModel extends Model ->orWhere("(leads.is_policy_created = '' OR leads.is_policy_created IS NULL)") ->groupEnd(); - if ($type) { - $query->whereIn('leads.lead_type', $type); - } + if ($client_id) { $query->where('leads.client_id', $client_id); } } + if ($type) { + $query->whereIn('leads.lead_type', $type); + } + $query->groupStart() ->where("policy_type.allocg != 'EB'") ->orWhere("(policy_type.allocg = 'EB' AND leads.proposel_data IS NOT NULL AND leads.proposel_data <> '')") diff --git a/app/Views/client_list.php b/app/Views/client_list.php index 88e26a8c..18b3a859 100755 --- a/app/Views/client_list.php +++ b/app/Views/client_list.php @@ -244,7 +244,7 @@ table.dataTable thead th { - + diff --git a/app/Views/client_policy.php b/app/Views/client_policy.php index 101ab426..5b54fbe1 100755 --- a/app/Views/client_policy.php +++ b/app/Views/client_policy.php @@ -396,7 +396,7 @@ input:checked + .slider_blue::before { - +