diff --git a/app/Controllers/LeadsController.php b/app/Controllers/LeadsController.php index 4f59c8ae..b6f5f35f 100644 --- a/app/Controllers/LeadsController.php +++ b/app/Controllers/LeadsController.php @@ -447,7 +447,7 @@ class LeadsController extends BaseController ], ]; - if (isset($postData['lead_type']) && $postData['lead_type'] == 1) { + if (isset($postData['lead_type']) && in_array((int) $postData['lead_type'], [1, 3], true)) { $rules['entity_type_id'] = [ 'rules' => 'required', @@ -659,14 +659,7 @@ 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 - - $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 + if (! in_array((int) $data['lead_type'], [1, 3], true)) { $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']; @@ -957,15 +950,10 @@ class LeadsController extends BaseController $insertCount[] = $insert; $this->insertLeadStatus($insert, $value['status'], 3); - $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 (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 @@ -990,16 +978,10 @@ 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 ($isType1Flow && $data[0]['status'] == 'won') { + 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); @@ -1420,7 +1402,7 @@ class LeadsController extends BaseController } // 4. Conditional query - only fetch if needed - if ($lead_data['lead_type'] != 1) { + if (! in_array((int) $lead_data['lead_type'], [1, 3], true)) { $client_policy_data = $this->clientPolicyModel ->select('policy_terms, placement_json') ->where('is_active', 1) @@ -2183,7 +2165,7 @@ class LeadsController extends BaseController } // dd($data); $lead_data = []; - if ($rfq_data['lead_type'] == 1) { + if (in_array((int) $rfq_data['lead_type'], [1, 3], true)) { if (in_array($rfq_data['policy_type_id'], [2, 3, 4, 5])) { $lead_data = [ @@ -4860,7 +4842,7 @@ class LeadsController extends BaseController $data['lead_edit_data']['multi_file_html'] = trim($html) !== '' ? $html : null; } - if ($data['lead_edit_data']['lead_type'] != 1 && $data['lead_edit_data']['lead_form_type'] == 2) { + if (! in_array((int) $data['lead_edit_data']['lead_type'], [1, 3], true) && $data['lead_edit_data']['lead_form_type'] == 2) { $data['lead_edit_data']['claims_details_html'] = view('rfq/claims_details_non_eb', $data['lead_edit_data']); } else { $data['lead_edit_data']['claims_details_html'] = ""; diff --git a/app/Views/leads_form.php b/app/Views/leads_form.php index d0745283..af7fbeff 100644 --- a/app/Views/leads_form.php +++ b/app/Views/leads_form.php @@ -541,8 +541,8 @@ var lead_type = $(this).val(); var increment = 1; // Example increment value (modify as needed) - var start_date_id = lead_type == "1" ? `policy_start_date_${increment}` : "policy_start_date"; - var end_date_id = lead_type == "1" ? `policy_end_date_${increment}` : "policy_end_date"; + var start_date_id = (lead_type == "1" || lead_type == "3") ? `policy_start_date_${increment}` : "policy_start_date"; + var end_date_id = (lead_type == "1" || lead_type == "3") ? `policy_end_date_${increment}` : "policy_end_date"; $(".policy_start_date").attr("id", start_date_id); // $("label[for]").attr("for", start_date_id); @@ -553,7 +553,7 @@ // $('#leads_form_id')[0].reset(); // console.log("Updated ID:", newId); - if (lead_type == 1) { + if (lead_type == 1 || lead_type == 3) { var policy_start_datePicker = flatpickr("#policy_start_date_" + increment, { dateFormat: "d/m/Y", @@ -585,32 +585,7 @@ // } } }); - } else if (lead_type == 3) { - - if ($('#client_id option[value="add_client"]').length === 0) { - $('#client_id').prepend($('