From a59e19d4254f15580cd88d10e161fccbb5154b57 Mon Sep 17 00:00:00 2001 From: "sanjeev.p" Date: Fri, 17 Apr 2026 14:25:55 +0530 Subject: [PATCH] FIX_Bug --- app/Controllers/LeadsController.php | 34 ++++++++++++++++++++++------- app/Views/leads_list.php | 7 +++--- app/Views/leads_non_eb.php | 6 ++--- 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/app/Controllers/LeadsController.php b/app/Controllers/LeadsController.php index 48ba5646..4f59c8ae 100644 --- a/app/Controllers/LeadsController.php +++ b/app/Controllers/LeadsController.php @@ -659,8 +659,14 @@ class LeadsController extends BaseController $request_data = $this->request->getPost(); $data = sanitizeInputArrayAdvanced($request_data); $data['client_type'] = 1; + $actual_lead_id = $data['actual_lead_id'] ?? null; // adjust to however you get this - if ($data['lead_type'] != 1) { + $isType1Flow = $data['lead_type'] == 1 || (!empty($actual_lead_id) && $actual_lead_id != 0 && $data['lead_type'] == 3); + + + // if ($data['lead_type'] != 1) + if (!$isType1Flow) { + // lead_type != 1 (and not the special type-3 override) → fetch client data $client_data = $this->clientModel->where('id', $data['client_id'])->where('is_active', 1)->first(); $data['client_name'] = $client_data['client_name']; $data['client_short_name'] = $client_data['short_name']; @@ -760,7 +766,8 @@ class LeadsController extends BaseController $form_docs_name = "docs_name_" . $index_plus_one; $leads_file_primary_key = $data['leads_file_id'] ?? []; $files = $this->request->getFileMultiple($form_file_name); - $multi_file_data = $this->uploadMultiFiles($files, $data[$form_docs_name], $leads_file_primary_key); + $docs_names_from_post = $data[$form_docs_name] ?? []; + $multi_file_data = $this->uploadMultiFiles($files, $docs_names_from_post, $leads_file_primary_key); // Separate the insurer and insurer branch, handle missing or invalid data if (isset($data['insurer'][$index]) && strpos($data['insurer'][$index], '-') !== false) { @@ -950,10 +957,15 @@ class LeadsController extends BaseController $insertCount[] = $insert; $this->insertLeadStatus($insert, $value['status'], 3); - if ($value['lead_type'] == 1 && $value['status'] == 'won') { - $leadDataForClient = $this->leadsModel->find($insert); - $this->createClientWithLeadData($leadDataForClient); - } + $actual_lead_id = $value['actual_lead_id'] ?? null; + + $isType1Flow = $value['lead_type'] == 1 + || (! empty($actual_lead_id) && $actual_lead_id != 0 && $value['lead_type'] == 3); + + if ($isType1Flow && $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 @@ -978,10 +990,16 @@ class LeadsController extends BaseController { if ($this->leadsModel->where('id', $id)->set($data[0])->update()) { + // Define these FIRST before using them + $actual_lead_id = $data[0]['actual_lead_id'] ?? null; + + $isType1Flow = $data[0]['lead_type'] == 1 + || (!empty($actual_lead_id) && $actual_lead_id != 0 && $data[0]['lead_type'] == 3); + $this->insertMultiFilesData($data[0]['multi_file_data'], $id, $data[0]['lead_form_type']); $this->insertLeadStatus($id, $data[0]['status'], 3); - if ($data[0]['lead_type'] == 1 && $data[0]['status'] == 'won') { + if ($isType1Flow && $data[0]['status'] == 'won') { $leadDataForClient = $this->leadsModel->find($id); if (empty($leadDataForClient['is_client_created'])) { $this->createClientWithLeadData($leadDataForClient); @@ -1079,7 +1097,7 @@ class LeadsController extends BaseController $file_name = file_Upload_for_lead($value, $uploadFilePath, UPLOAD_EXT_LEAD_FILES); $multi_file_data[] = [ 'file_name' => $file_name, - 'docs_name' => $docs_names[$index], + 'docs_name' => $docs_names[$index] ?? '', 'id' => $primaryKey[$index] ?? "", ]; } diff --git a/app/Views/leads_list.php b/app/Views/leads_list.php index e9a09ea0..42f32f88 100644 --- a/app/Views/leads_list.php +++ b/app/Views/leads_list.php @@ -189,7 +189,7 @@