This commit is contained in:
sanjeev.p 2026-04-17 14:25:55 +05:30
parent f19c1b9627
commit a59e19d425
3 changed files with 33 additions and 14 deletions

View File

@ -659,8 +659,14 @@ class LeadsController extends BaseController
$request_data = $this->request->getPost(); $request_data = $this->request->getPost();
$data = sanitizeInputArrayAdvanced($request_data); $data = sanitizeInputArrayAdvanced($request_data);
$data['client_type'] = 1; $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(); $client_data = $this->clientModel->where('id', $data['client_id'])->where('is_active', 1)->first();
$data['client_name'] = $client_data['client_name']; $data['client_name'] = $client_data['client_name'];
$data['client_short_name'] = $client_data['short_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; $form_docs_name = "docs_name_" . $index_plus_one;
$leads_file_primary_key = $data['leads_file_id'] ?? []; $leads_file_primary_key = $data['leads_file_id'] ?? [];
$files = $this->request->getFileMultiple($form_file_name); $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 // Separate the insurer and insurer branch, handle missing or invalid data
if (isset($data['insurer'][$index]) && strpos($data['insurer'][$index], '-') !== false) { if (isset($data['insurer'][$index]) && strpos($data['insurer'][$index], '-') !== false) {
@ -950,7 +957,12 @@ class LeadsController extends BaseController
$insertCount[] = $insert; $insertCount[] = $insert;
$this->insertLeadStatus($insert, $value['status'], 3); $this->insertLeadStatus($insert, $value['status'], 3);
if ($value['lead_type'] == 1 && $value['status'] == 'won') { $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); $leadDataForClient = $this->leadsModel->find($insert);
$this->createClientWithLeadData($leadDataForClient); $this->createClientWithLeadData($leadDataForClient);
} }
@ -978,10 +990,16 @@ class LeadsController extends BaseController
{ {
if ($this->leadsModel->where('id', $id)->set($data[0])->update()) { 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->insertMultiFilesData($data[0]['multi_file_data'], $id, $data[0]['lead_form_type']);
$this->insertLeadStatus($id, $data[0]['status'], 3); $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); $leadDataForClient = $this->leadsModel->find($id);
if (empty($leadDataForClient['is_client_created'])) { if (empty($leadDataForClient['is_client_created'])) {
$this->createClientWithLeadData($leadDataForClient); $this->createClientWithLeadData($leadDataForClient);
@ -1079,7 +1097,7 @@ class LeadsController extends BaseController
$file_name = file_Upload_for_lead($value, $uploadFilePath, UPLOAD_EXT_LEAD_FILES); $file_name = file_Upload_for_lead($value, $uploadFilePath, UPLOAD_EXT_LEAD_FILES);
$multi_file_data[] = [ $multi_file_data[] = [
'file_name' => $file_name, 'file_name' => $file_name,
'docs_name' => $docs_names[$index], 'docs_name' => $docs_names[$index] ?? '',
'id' => $primaryKey[$index] ?? "", 'id' => $primaryKey[$index] ?? "",
]; ];
} }

View File

@ -189,7 +189,7 @@
</a> </a>
<div class="dropdown-menu dropdown-menu-right"> <div class="dropdown-menu dropdown-menu-right">
<?php $isNonEb = isset($row['lead_form_type']) && (int) $row['lead_form_type'] === 2; ?> <?php $isNonEb = isset($row['lead_form_type']) && (int) $row['lead_form_type'] === 2; ?>
<a class="dropdown-item btnEdit" data-id="<?php echo $row['id']; ?>" data-ft="<?php echo $row['lead_form_type']; ?>" onclick="getLeadsDataForEdit('<?php echo htmlspecialchars($row['id'], ENT_QUOTES) ?>', '<?php echo htmlspecialchars($row['lead_form_type'], ENT_QUOTES) ?>')"> <a class="dropdown-item btnEdit" data-id="<?php echo $row['id']; ?>" data-ft="<?php echo $row['lead_form_type']; ?>" onclick="getLeadsDataForEdit('<?php echo htmlspecialchars($row['id'], ENT_QUOTES) ?>', '<?php echo htmlspecialchars($row['lead_form_type'], ENT_QUOTES) ?>', '<?php echo htmlspecialchars($row['actual_lead_id'] ?? 0, ENT_QUOTES) ?>')">
<i class="mdi mdi-pencil mr-2 text-muted font-18 vertical-middle"></i>Edit <i class="mdi mdi-pencil mr-2 text-muted font-18 vertical-middle"></i>Edit
</a> </a>
<?php if ($isNonEb) {?> <?php if ($isNonEb) {?>
@ -820,11 +820,12 @@
} }
function getLeadsDataForEdit(lead_id, lead_form_type){ function getLeadsDataForEdit(lead_id, lead_form_type, actual_lead_id = 0){
console.log('lead_id', lead_id); console.log('lead_id', lead_id);
console.log('lead_form_type', lead_form_type); console.log('lead_form_type', lead_form_type);
let actual_lead_id = 0; // Hardcoded to 0 since this is an edit operation console.log('actual_lead_id', actual_lead_id);
// let actual_lead_id = 0; // Hardcoded to 0 since this is an edit operation
//Here After Edit URL: /type / actual_lead_id (0) / lead_id //Here After Edit URL: /type / actual_lead_id (0) / lead_id
let url = '<?php echo base_url('/util/getLeadNonEB/') ?>' + lead_form_type + '/' + actual_lead_id + '/' + lead_id; let url = '<?php echo base_url('/util/getLeadNonEB/') ?>' + lead_form_type + '/' + actual_lead_id + '/' + lead_id;
// old URL // old URL