From 3b56b0d1f83575d505b5a1358481ed64aa926c9b Mon Sep 17 00:00:00 2001 From: Venkatesh Date: Tue, 12 May 2026 17:17:01 +0530 Subject: [PATCH] FIX_Opportunities_TOGGLE_ISSUE --- app/Controllers/LeadsController.php | 20 ++++++++++---------- app/Views/leads_form.php | 10 +++++++--- app/Views/leads_form_handler.php | 15 ++++++++++++--- app/Views/leads_non_eb.php | 16 ++++++++++++++++ 4 files changed, 45 insertions(+), 16 deletions(-) diff --git a/app/Controllers/LeadsController.php b/app/Controllers/LeadsController.php index 9eb1da12..66337c36 100644 --- a/app/Controllers/LeadsController.php +++ b/app/Controllers/LeadsController.php @@ -1014,10 +1014,10 @@ class LeadsController extends BaseController $insertCount[] = $insert; $this->insertLeadStatus($insert, $value['status'], 3); - if (in_array((int) $value['lead_type'], [1, 3], true) && $value['status'] == 'won') { - $leadDataForClient = $this->leadsModel->find($insert); - $this->createClientWithLeadData($leadDataForClient); - } + // if (in_array((int) $value['lead_type'], [1, 3], true) && $value['status'] == 'won') { + // $leadDataForClient = $this->leadsModel->find($insert); + // $this->createClientWithLeadData($leadDataForClient); + // } if ($value['lead_form_type'] == 1) { //for this push the job to the calculateMembersDemography() function @@ -1045,12 +1045,12 @@ class LeadsController extends BaseController $this->insertMultiFilesData($data[0]['multi_file_data'], $id, $data[0]['lead_form_type']); $this->insertLeadStatus($id, $data[0]['status'], 3); - if (in_array((int) $data[0]['lead_type'], [1, 3], true) && $data[0]['status'] == 'won') { - $leadDataForClient = $this->leadsModel->find($id); - if (empty($leadDataForClient['is_client_created'])) { - $this->createClientWithLeadData($leadDataForClient); - } - } + // if (in_array((int) $data[0]['lead_type'], [1, 3], true) && $data[0]['status'] == 'won') { + // $leadDataForClient = $this->leadsModel->find($id); + // if (empty($leadDataForClient['is_client_created'])) { + // $this->createClientWithLeadData($leadDataForClient); + // } + // } return $this->respond(['status' => true, 'lead_id' => $id, 'message' => "Opportunity updated successfully", 'data' => $data], 200); } diff --git a/app/Views/leads_form.php b/app/Views/leads_form.php index e2242c4f..836ec3b8 100644 --- a/app/Views/leads_form.php +++ b/app/Views/leads_form.php @@ -822,11 +822,15 @@ $('#lost_reason').val(res.data.lost_reason || ''); $('#notes').val(res.data.notes); - let existingClientId = res.data.client_id || res.data.is_client_created || 0; + const isExistingClient = res.data.client_id !== undefined + && res.data.client_id !== null + && String(res.data.client_id) !== '' + && String(res.data.client_id) !== '0'; + let existingClientId = isExistingClient ? res.data.client_id : 0; console.log('existingClientId', existingClientId); - if (lead_type == 3) { - if (existingClientId && existingClientId != 0) { + if (lead_type == 1 || lead_type == 3) { + if (isExistingClient) { $('#exixting_client').prop('checked', true).trigger('change'); } else { $('#exixting_client').prop('checked', false).trigger('change'); diff --git a/app/Views/leads_form_handler.php b/app/Views/leads_form_handler.php index 96987f29..426f43fe 100644 --- a/app/Views/leads_form_handler.php +++ b/app/Views/leads_form_handler.php @@ -831,6 +831,10 @@ if (isset($selected_lead_type)) { let policy_type_id = data.policy_type_id || null; let lead_type = data.lead_type || null; + const isExistingClient = data.client_id !== undefined + && data.client_id !== null + && String(data.client_id) !== '' + && String(data.client_id) !== '0'; if ([1, 6, 7].includes(policy_type_id)) { let newId = 'appendAreaForClaim_' + dataIncrement; @@ -849,7 +853,7 @@ if (isset($selected_lead_type)) { if (lead_type == 1 || lead_type == 3) { $('.claim-row').hide(); - if(data.is_client_created == null || data.is_client_created == 0 || data.is_client_created == ""){ + if(!isExistingClient){ $('#exixting_client').prop('checked', false); $('#exixting_client').prop('disabled', true); @@ -1117,7 +1121,12 @@ if (isset($selected_lead_type)) { leadTypeBsedHideAndShow(lead_type); - if(data.client_id == 0 || data.client_id == null){ + const isExistingClient = data.client_id !== undefined + && data.client_id !== null + && String(data.client_id) !== '' + && String(data.client_id) !== '0'; + + if(!isExistingClient){ temp_client_id = 0; }else{ temp_client_id = data.client_id @@ -1125,7 +1134,7 @@ if (isset($selected_lead_type)) { if(lead_type == 1 || lead_type == 3){ - if(data.is_client_created == null || data.is_client_created == 0 || data.is_client_created == ""){ + if(!isExistingClient){ $('#exixting_client').prop('checked', false); $('#exixting_client').prop('disabled', true); diff --git a/app/Views/leads_non_eb.php b/app/Views/leads_non_eb.php index a0d9946e..0bd1f5ab 100644 --- a/app/Views/leads_non_eb.php +++ b/app/Views/leads_non_eb.php @@ -561,6 +561,22 @@ var pageBackButton = '