From f72bbfe79974b17bbde25155b89e402cb5df5c28 Mon Sep 17 00:00:00 2001 From: Venkatesh Date: Tue, 30 Jun 2026 11:17:03 +0530 Subject: [PATCH] FIX_MULTIPLE_POLICY_CREATE_IN_THE_LEAD_NEED_TO_LIST_IN_THE_DROPDOWN --- app/Controllers/ClientController.php | 2 +- app/Models/LeadsModel.php | 40 +++++++++++++++++++--------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index beadfa73..d9f3ea9c 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([2], $id); + $editData['lead_data'] = $this->leadsModel->getLeadForInsertClientList(null, $id, 'update'); $clientPoliceData = $this->clientPolicyModel->getClientPolicyByClientId($id); foreach ($clientPoliceData as $key => $value) { diff --git a/app/Models/LeadsModel.php b/app/Models/LeadsModel.php index ba841687..5ebd7f13 100644 --- a/app/Models/LeadsModel.php +++ b/app/Models/LeadsModel.php @@ -187,30 +187,46 @@ class LeadsModel extends Model return $data->orderBy('leads.id', 'desc')->findAll(); } - public function getLeadForInsertClientList($type = null, $client_id = null) + 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') ->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) - ->where('leads.status', 'won') - ->groupStart() + ->where('leads.status', 'won'); + + if ($from === 'update') { + $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'); + } + } else { + $query->groupStart() ->where("(leads.is_client_created = '' OR leads.is_client_created IS NULL)") ->orWhere("(leads.is_policy_created = '' OR leads.is_policy_created IS NULL)") - ->groupEnd() - ->groupStart() - ->where("policy_type.allocg != 'EB'") - ->orWhere("(policy_type.allocg = 'EB' AND leads.proposel_data IS NOT NULL AND leads.proposel_data <> '')") ->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); + } + if ($client_id) { + $query->where('leads.client_id', $client_id); + } } + $query->groupStart() + ->where("policy_type.allocg != 'EB'") + ->orWhere("(policy_type.allocg = 'EB' AND leads.proposel_data IS NOT NULL AND leads.proposel_data <> '')") + ->groupEnd(); + $result = $query->get()->getResultArray(); return $result; }