diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 0059a7a1..4f3f4223 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -348,6 +348,7 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) { $routes->get('getTheEmpDataForClaimSearchByMobile/(:any)', 'ClientController::getTheEmpDataForClaimSearchByMobile/$1'); $routes->get('getLeadNonEB/(:any)', 'LeadsController::getLeadNonEB/$1'); $routes->get('getPolicyTypeFields', 'LeadsController::getPolicyTypeFields'); + $routes->get('removeMultiFile', 'LeadsController::removeMultiFile'); }); $routes->group("policy_tranction", ["filter" => "authMVC"], function ($routes) { diff --git a/app/Controllers/LeadsController.php b/app/Controllers/LeadsController.php index 1c5e9f80..9c35bc48 100644 --- a/app/Controllers/LeadsController.php +++ b/app/Controllers/LeadsController.php @@ -29,6 +29,7 @@ use App\Models\TPABranchModel; use App\Models\RFQModel; use App\Models\InsurerModel; use App\Models\OccupancyMasterModel; +use App\Models\LeadFilesModel; use App\Helpers\MailHelper; use App\Helpers\ExcelMergeHelper; @@ -62,6 +63,7 @@ class LeadsController extends BaseController protected $RFQModel; protected $insurerModel; protected $occupancyModel; + protected $leadFilesModel; //variables for storing array protected $issuer; @@ -92,6 +94,7 @@ class LeadsController extends BaseController $this->RFQModel = new RFQModel(); $this->insurerModel = new InsurerModel(); $this->occupancyModel = new OccupancyMasterModel(); + $this->leadFilesModel = new LeadFilesModel(); $this->issuer = [1 => 'JIBS', 2 => 'Nhance']; $this->clientType = [1 => 'Group', 2 => 'Individual']; @@ -206,13 +209,12 @@ class LeadsController extends BaseController private function prepareSingleLeadData($data) { // print_r($data); die; - $uploadFilePath = WRITEPATH . 'uploads/lead_files/'; - - // Get all uploaded files for 'file_name[]' - $files = $this->request->getFileMultiple('file_name'); - - // print_r($files); die; - + $index_plus_one = 1; + $form_file_name = "file_name_".$index_plus_one; + $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); // Separate the insurer and insurer branch, handle missing or invalid data if (isset($data['insurer']) && strpos($data['insurer'], '-') !== false) { @@ -249,7 +251,9 @@ class LeadsController extends BaseController $data['policy_end_date'] = null; } - $data['file_name'] = file_Upload($files, $uploadFilePath); + // $data['file_name'] = file_Upload($files, $uploadFilePath); + $data['multi_file_data']= $multi_file_data ?? null; + $processcedData[] = $data; // print_r($data);die(); @@ -260,15 +264,16 @@ class LeadsController extends BaseController { // print_r($data); die; $processedData = []; - $uploadFilePath = WRITEPATH . 'uploads/lead_files/'; - - // Get all uploaded files for 'file_name[]' - $files = $this->request->getFileMultiple('file_name'); - - // print_r($files); die; foreach ($data['policy_type_id'] as $index => $value) { + $index_plus_one = $index + 1; + $form_file_name = "file_name_".$index_plus_one; + $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); + // Separate the insurer and insurer branch, handle missing or invalid data if (isset($data['insurer'][$index]) && strpos($data['insurer'][$index], '-') !== false) { list($insurer_branch_id, $insurer_id) = explode('-', $data['insurer'][$index]); @@ -324,7 +329,7 @@ class LeadsController extends BaseController $premium_date = null; } - $file_name = file_Upload($files[$index], $uploadFilePath); + // $file_name = file_Upload($files[$index], $uploadFilePath); $last_3_years_claims = $data['finyear']; @@ -387,7 +392,8 @@ class LeadsController extends BaseController 'total_si_at_renewal' => $data['total_si_at_renewal'][$index] ?? 0, 'fin_years_claims' => $last_3_years_claims, - 'file_name' => $file_name, + // 'file_name' => $file_name, + 'multi_file_data' => $multi_file_data ?? null, 'status' => $data['status'] ?? null, 'notes' => $data['notes'] ?? null, @@ -405,6 +411,11 @@ class LeadsController extends BaseController $insertCount = []; foreach ($data as $value) { $insert = $this->leadsModel->insert($value); + + if ($insert) { + $this->insertMultiFilesData($value['multi_file_data'], $insert); + } + $insertCount[] = $insert; $this->insertLeadStatus($insert, $value['status'], 3); @@ -427,13 +438,15 @@ class LeadsController extends BaseController private function updateOldLead($id, $data) { if ($this->leadsModel->where('id', $id)->set($data[0])->update()) { + + $this->insertMultiFilesData($data[0]['multi_file_data'], $id); $this->insertLeadStatus($id, $data[0]['status'], 3); return $this->respond(['status' => true, 'lead_id' => $id, 'message' => "Lead updated successfully", 'data' => $data], 200); } return $this->respond(['status' => false, 'lead_id' => $id, 'message' => "Failed to update Lead", 'data' => $data], 200); } - // Get the Single Lead data for edit + // Get the Single Lead data for edit uisng ajax ( do not delete) public function getLeadDataForEdit($id) { @@ -472,6 +485,8 @@ class LeadsController extends BaseController $data['premium_date'] = null; } + $data['multi_file_data'] = $this->leadFilesModel->where('lead_id', $id)->first() ?? null; + $data['lastFiveYears'] = $this->getLastFiveFinancialYears(); $data['gpaClaimType'] = $this->claim_type_for_gpa; $data['causeOfDeath'] = $this->cause_of_death; @@ -485,6 +500,8 @@ class LeadsController extends BaseController $data['html'] = $this->generateViewPageHtml($data['policy_type_id'], $data) ?? ""; + // print_r($data); die; + if ($data) { return $this->respond(['status' => true, 'data' => $data], 200); } else { @@ -503,6 +520,77 @@ class LeadsController extends BaseController $this->policyTransactionStatusModel->insert($statusData); } + public function uploadMultiFiles($files, $docs_names, $primaryKey) + { + $uploadFilePath = WRITEPATH . 'uploads/lead_files/'; + + $multi_file_data = []; + foreach ($files as $index => $value) { + $file_name = file_Upload($value, $uploadFilePath); + $multi_file_data[] = [ + 'file_name' => $file_name, + 'docs_name' => $docs_names[$index], + 'id' => $primaryKey[$index] ?? "", + ]; + } + + return $multi_file_data; + } + + public function insertMultiFilesData($data, $lead_id) + { + // print_r($data); die; + + if(!empty($data)){ + foreach ($data as $key => $value) { + + if(!empty($value['id'])){ + + $lead_file_data = [ + 'lead_id' => $lead_id, + 'docs_name' => $value['docs_name'], + ]; + + if(!empty($value['file_name'])) { + $lead_file_data['file_name'] = $value['file_name']; + } + + $this->leadFilesModel->where('id', $value['id'])->set($lead_file_data)->update(); + + }else{ + + $lead_file_data = [ + 'lead_id' => $lead_id, + 'docs_name' => $value['docs_name'], + 'file_name' => $value['file_name'], + ]; + $this->leadFilesModel->insert($lead_file_data); + } + + if($key == 0 && !empty($value['file_name'])) { + $this->leadsModel->where('id', $lead_id)->set('file_name', $value['file_name'])->update(); + } + } + } + + return true; + } + + public function removeMultiFile() + { + $id = $this->request->getGet('lead_file_id'); + if(!empty($id)){ + $this->leadFilesModel->where('id', $id)->set(['is_active' => 0])->update(); + return $this->respond(['status' => true, 'message' => 'File removed successfully'], 200); + }else{ + return $this->respond(['status' => false, 'message' => 'File could not be removed.'], 200); + } + } + + public function updateLeadTableFields() + { + + } //--------RFQ----------------------------------------------------------------------------------------------- @@ -575,8 +663,11 @@ class LeadsController extends BaseController $data['mail_content'] = $this->transformMailContent($lead_data, $mail_content, $data['page_name']); $data['subject'] = $this->transformMailContent($lead_data, $subject, $data['page_name']); + $data['multi_file_data'] = $this->leadFilesModel->where('lead_id', $id)->where('is_active', 1)->findAll() ?? null; + $data['attachment_html'] = view('rfq/attachment_files', $data) ?? ""; + + // dd($data); - if ($data['lead_data']['lead_form_type'] == 1) { $this->loadLayout('view_rfq.php', $data); @@ -635,7 +726,6 @@ class LeadsController extends BaseController } } - public function createRFQ() { $data = $this->request->getPost(); @@ -691,7 +781,6 @@ class LeadsController extends BaseController ], 200); } - public function createQCR() { @@ -1693,6 +1782,7 @@ class LeadsController extends BaseController $propsal_and_insurer = isset($params['proposal_insurer']) ? $params['proposal_insurer'] : null; $mail_content = $params['mail_content']; $mail_subject = $params['subject']; + $attachment_file_ids = $params['selected_attachment_files']; $result_data = []; // dd($recipient_mail); @@ -1817,7 +1907,12 @@ class LeadsController extends BaseController $file_path = $result; $file_name = basename($result); + + // Attacments part $attachments = [['fileName' => $file_name, 'filePath' => $file_path]]; + $other_attachments = $this->handleMultiFileAttachments($attachment_file_ids, $lead_id); + $attachments = array_merge($attachments, $other_attachments); + // print_r($attachments); die; //get recipient address if ($recipient_type == 'insurer' || $recipient_type == 'placement') { @@ -2579,6 +2674,7 @@ class LeadsController extends BaseController $this->loadLayout('view_rfq_non_eb'); } + // get lead data for edit bot EB and NON-EB public function getLeadNonEB($type, $id = null) { // Set basic data @@ -2606,9 +2702,15 @@ class LeadsController extends BaseController ->where('user_profiles.is_active', 1) ->findAll(); + + if (!empty($id)) { + $data['lead_edit_data'] = $this->leadsModel->where('id', $id)->first() ?? []; + $data['lead_edit_data']['multi_file_data'] = $this->leadFilesModel->where('lead_id', $id)->where('is_active', 1)->findAll() ?? null; + $data['lead_edit_data']['lead_file_count'] = count($data['lead_edit_data']['multi_file_data']); + // Decode and merge custom fields if present $custom_fields_data = !empty($data['lead_edit_data']['custom_fields']) ? json_decode($data['lead_edit_data']['custom_fields'], true) @@ -2633,6 +2735,8 @@ class LeadsController extends BaseController $data['lead_edit_data']['policy_type_id'] ?? null, $data ) ?? ""; + + $data['lead_edit_data']['multi_file_html'] = view('rfq/multi_files', $data) ?? ""; } if ($data['lead_edit_data']['lead_type'] != 1 && $data['lead_edit_data']['lead_form_type'] == 2) { @@ -3477,19 +3581,34 @@ class LeadsController extends BaseController return $data; } - // function getPreviousColumn($columnLetter) - // { - // $colIndex = Coordinate::columnIndexFromString($columnLetter); - // if ($colIndex > 1) { - // $colIndex--; - // } - // return Coordinate::stringFromColumnIndex($colIndex); - // } - - function getPreviousColumn($columnLetter, $decrement = 1) { + public function getPreviousColumn($columnLetter, $decrement = 1) + { $colIndex = Coordinate::columnIndexFromString($columnLetter); $colIndex = max(1, $colIndex - $decrement); // ensure column index doesn't go below 1 return Coordinate::stringFromColumnIndex($colIndex); } + public function handleMultiFileAttachments($json_string, $lead_id) + { + $attachments = []; + + if (!empty($json_string)) { + $fileIds = json_decode($json_string, true); + $lead_file_path = WRITEPATH . 'uploads/lead_files/'; + + foreach ($fileIds as $id) { + $lead_file = $this->leadFilesModel->where('lead_id', $lead_id)->where('id', $id)->where('is_active', 1)->first(); + + if ($lead_file) { + $attachments[] = [ + 'fileName' => $lead_file['file_name'], + 'filePath' => $lead_file_path . $lead_file['file_name'] + ]; + } + } + } + + return $attachments; + } + } diff --git a/app/Models/LeadFilesModel.php b/app/Models/LeadFilesModel.php new file mode 100644 index 00000000..37db8e16 --- /dev/null +++ b/app/Models/LeadFilesModel.php @@ -0,0 +1,55 @@ + -
- - - -
- +
+
x + @@ -931,6 +927,8 @@ container.appendChild(newRow); + //append mutli file html + addFileField(increment); var lead_type = $('#lead_type').val(); leadTypeBsedHideAndShow(lead_type) @@ -1540,4 +1538,8 @@ } }); } + + //----------------------------------------------------------------------------------------------------------- + + \ No newline at end of file diff --git a/app/Views/leads_form_handler.php b/app/Views/leads_form_handler.php index 93a82b96..30bb0d02 100644 --- a/app/Views/leads_form_handler.php +++ b/app/Views/leads_form_handler.php @@ -86,6 +86,8 @@ if (isset($selected_lead_type)) { var temp_client_id = 0; var temp_branch_id = 0; var selected_lead_form_type = ; + var fileIndex = 1; // Initialize index + // select2 document ready $(document).ready(function() { @@ -327,6 +329,122 @@ if (isset($selected_lead_type)) { } + // -------------------------------------------------------------------------------------------------------- + + function addFileField(increment) { + + console.log('addFileField function called'); + + const container = document.getElementById(`multiFileAppendArea_${increment}`); + if (!container) return; + + const div = document.createElement("div"); + div.className = "form-row d-flex align-items-end"; + div.setAttribute("id", `fileField_${fileIndex}`); + + let isFirstField = container.childElementCount === 0; // Check if it's the first field + let placeholder = isFirstField ? 'First file must be Demography.' : ''; + let accept = isFirstField ? '.xls,.xlsx' : ''; + + div.innerHTML = ` +
+ + +
+
+ + +
+
+ + +
+ `; + container.appendChild(div); + fileIndex++; + } + + function removeFileField(index, lead_file_id = null) { + + if(index == 1){ + toastr.warning("You can't remove the first file field", 'WARNING'); + return false; + } + + if(lead_file_id != null) { + + Swal.fire({ + title: "Do you want to remove this file?", + // text: "Do you want Save this!", + icon: "warning", + showCancelButton: true, + confirmButtonColor: "#3085d6", + cancelButtonColor: "#d33", + confirmButtonText: "Yes, Procced!" + }).then((result) => { + + if (result.isConfirmed) { + + let url = ''; + + let requestData = { + lead_file_id: lead_file_id + }; + + $('.loader').fadeIn(); + $('.loader-mask').fadeIn(); + + // Send AJAX request + sendAjaxRequestForGlobal(url, 'GET', requestData, function(response) { + console.log('Data fetched successfully:', response); + + if (response.status == true) { + toastr.success(response.message, 'SUCCESS'); + + //remove the file field + const field = document.getElementById(`fileField_${index}`); + if(index != 1){ + if (field) field.remove(); + } + + } else { + toastr.error(response.message, 'WARNING'); + } + + $('.loader').fadeOut(); + $('.loader-mask').delay(350).fadeOut('slow'); + + }, function(xhr, status, error) { + $('.loader').fadeOut(); + $('.loader-mask').delay(350).fadeOut('slow'); + console.error('Error fetching data:', error); + console.error(xhr.responseText); + toastr.error('An error occurred while checking the CD amount.', 'ERROR'); + }); + + }else{ + return false; + } + + }); + + }else{ + const field = document.getElementById(`fileField_${index}`); + if(index != 1){ + if (field) field.remove(); + } + } + + } + + function showFileName(input, index) { + if (input.files.length > 0) { + document.getElementById(`file_name_display_${index}`).textContent = input.files[0].name; + } else { + document.getElementById(`file_name_display_${index}`).textContent = "No file chosen"; + } + } + @@ -337,7 +455,7 @@ if (isset($selected_lead_type)) { setTimeout(function(){ handleEbAndNonEbEdit( ); - }, 1000) + }, 2000) function handleEbAndNonEbEdit(data){ if(data.lead_form_type == 1){ @@ -353,6 +471,7 @@ if (isset($selected_lead_type)) { console.log('Received data:', data); let dataIncrement = 1; + fileIndex = data.lead_file_count + 1; if (!data || typeof data !== 'object') { console.error('Invalid data received for editing.'); @@ -361,6 +480,7 @@ if (isset($selected_lead_type)) { $('.btnDiv').hide(); $('#appendArea_' + dataIncrement).empty(); + $('#multiFileAppendArea_' + dataIncrement).empty(); if (data.html) { $('#appendArea_' + dataIncrement).append(data.html); @@ -368,6 +488,15 @@ if (isset($selected_lead_type)) { console.warn('HTML content missing in data.'); } + if (data.multi_file_html) { + console.log(data.multi_file_html); + setTimeout(function(){ + $('#multiFileAppendArea_' + dataIncrement).append(data.multi_file_html); + }, 2000) + } else { + console.warn('MULTI FILE HTML content missing in data.'); + } + let policy_type_id = data.policy_type_id || null; let lead_type = data.lead_type || null; @@ -498,6 +627,7 @@ if (isset($selected_lead_type)) { console.log('########### THIS IS NON EB LEAD ###############') console.log('Received data:', data); let dataIncrement = 1; + fileIndex = data.lead_file_count + 1; if (!data || typeof data !== 'object') { console.error('Invalid data received for editing.'); @@ -505,6 +635,8 @@ if (isset($selected_lead_type)) { } $('#appendArea').empty(); + $('#multiFileAppendArea_' + dataIncrement).empty(); + if (data.html) { $('#appendArea').append(data.html); @@ -512,6 +644,15 @@ if (isset($selected_lead_type)) { console.warn('HTML content missing in data.'); } + if (data.multi_file_html) { + console.log(data.multi_file_html); + setTimeout(function(){ + $('#multiFileAppendArea_' + dataIncrement).append(data.multi_file_html); + }, 2000) + } else { + console.warn('MULTI FILE HTML content missing in data.'); + } + let policy_type_id = data.policy_type_id || null; let lead_type = data.lead_type || null; diff --git a/app/Views/leads_non_eb.php b/app/Views/leads_non_eb.php index 1ee910fa..fef3f394 100644 --- a/app/Views/leads_non_eb.php +++ b/app/Views/leads_non_eb.php @@ -290,14 +290,18 @@ hr.solid {
+
+ +
+
-
+
@@ -370,6 +374,8 @@ $(document).ready(function(){ dateFormat: "d/m/Y", allowInput: false }); + + addFileField(1); }) function getPolicyTypeFields(input) { diff --git a/app/Views/rfq/attachment_files.php b/app/Views/rfq/attachment_files.php new file mode 100644 index 00000000..711fbe84 --- /dev/null +++ b/app/Views/rfq/attachment_files.php @@ -0,0 +1,14 @@ + +
+ + +
+ + + +
+ +
+ diff --git a/app/Views/rfq/multi_files.php b/app/Views/rfq/multi_files.php new file mode 100644 index 00000000..a071172b --- /dev/null +++ b/app/Views/rfq/multi_files.php @@ -0,0 +1,50 @@ + + + $value) { + $isFirstField = ($index === 0); // First file must be Demography + $placeholder = $isFirstField ? 'First file must be Demography.' : ''; + $accept = $isFirstField ? '.xls,.xlsx' : ''; + $index = $index + 1; +?> + +
+ + + + +
+ + +
+ + +
+ + + +
+ + + +
+ + +
+
+ + \ No newline at end of file diff --git a/app/Views/view_rfq.php b/app/Views/view_rfq.php index 3922cdf6..950e9b45 100644 --- a/app/Views/view_rfq.php +++ b/app/Views/view_rfq.php @@ -373,6 +373,16 @@
+ +
+

Attachments Files

+
+ +
+
+ +
+
@@ -394,47 +404,58 @@ -
+ +
+

Attachments Files

+
+ +
+
+ +
+
+ +
+
@@ -535,6 +556,16 @@
+
+

Attachments Files

+
+ +
+
+ +
+
+
@@ -557,6 +588,7 @@ var premium_data_check = false; var user_role_id = ; var jsonDataForHide = null; + var multi_file_data = []; const editorConfig = { buttons: [ @@ -595,7 +627,8 @@ console.log('Type:', type); let titile_client_name = ""; - + multi_file_data = ; + appendMultiFileData(multi_file_data) RFQ_or_QCR = type; var type_for_url = 1; @@ -3452,6 +3485,11 @@ function constructURL_ForInsurerAndClientMailSend() { bcc = bcc.map(Number); bcc = JSON.stringify(bcc); + var selectedFiles = []; + $('#insurer_or_clinet_mail_attachment .multi_file_attachment:checked').each(function () { + selectedFiles.push($(this).val()); + }); + // Prepare FormData object var formData = new FormData(); formData.append('lead_id', lead_id); @@ -3459,6 +3497,8 @@ function constructURL_ForInsurerAndClientMailSend() { formData.append('subject', subject); formData.append('cc', cc); formData.append('bcc', bcc); + formData.append('selected_attachment_files', JSON.stringify(selectedFiles)); + if (RFQ_or_QCR == 2) { formData.append('file_type', 'qcr'); @@ -3493,6 +3533,11 @@ function constructURL_ForInternalMailSend() { // Determine file type var file_type = RFQ_or_QCR == 2 ? 'qcr' : 'rfq'; + var selectedFiles = []; + $('#internal_mail_attachment .multi_file_attachment:checked').each(function () { + selectedFiles.push($(this).val()); + }); + // Create FormData var formData = new FormData(); formData.append('lead_id', lead_id); @@ -3503,6 +3548,7 @@ function constructURL_ForInternalMailSend() { formData.append('subject', subject); formData.append('mail_content', mail_content); formData.append('recipient_mail', ''); // Empty value as per logic + formData.append('selected_attachment_files', JSON.stringify(selectedFiles)); ajaxRequest(formData) @@ -3528,6 +3574,11 @@ function constructURL_ForPlacementMailSend() { to = to.split(',').map(email => email.trim()); cc = cc.map(Number); // or split if it's a string: `cc.split(',').map(email => email.trim())` + var selectedFiles = []; + $('#placement_mail_attachment .multi_file_attachment:checked').each(function () { + selectedFiles.push($(this).val()); + }); + // Prepare FormData var formData = new FormData(); formData.append('lead_id', lead_id); @@ -3544,6 +3595,8 @@ function constructURL_ForPlacementMailSend() { formData.append('total_amount', total_amount); formData.append('cd_amount', cd_amount); formData.append('mail_content', mail_content); + formData.append('selected_attachment_files', JSON.stringify(selectedFiles)); + ajaxRequest(formData); @@ -5157,6 +5210,11 @@ function autoCaluculationForPremiumChildTable(input) { } +function appendMultiFileData(data) { + + console.log('appendMultiFileData function called'); + console.log(data) +} diff --git a/app/Views/view_rfq_non_eb.php b/app/Views/view_rfq_non_eb.php index 6a182769..5f9aba17 100644 --- a/app/Views/view_rfq_non_eb.php +++ b/app/Views/view_rfq_non_eb.php @@ -309,11 +309,22 @@
+
+

Attachments Files

+
+ +
+
+ +
+
+
@@ -475,6 +496,16 @@
+
+

Attachments Files

+
+ +
+
+ +
+
+
@@ -4550,6 +4581,11 @@ bcc = bcc.map(Number); bcc = JSON.stringify(bcc); + var selectedFiles = []; + $('#insurer_or_clinet_mail_attachment .multi_file_attachment:checked').each(function () { + selectedFiles.push($(this).val()); + }); + // Prepare FormData object var formData = new FormData(); formData.append('lead_id', lead_id); @@ -4557,6 +4593,8 @@ formData.append('subject', subject); formData.append('cc', cc); formData.append('bcc', bcc); + formData.append('selected_attachment_files', JSON.stringify(selectedFiles)); + if (rfq_or_qcr == 2) { formData.append('file_type', 'qcr'); @@ -4591,6 +4629,12 @@ // Determine file type var file_type = rfq_or_qcr == 2 ? 'qcr' : 'rfq'; + var selectedFiles = []; + $('#internal_mail_attachment .multi_file_attachment:checked').each(function () { + selectedFiles.push($(this).val()); + }); + + // Create FormData var formData = new FormData(); formData.append('lead_id', lead_id); @@ -4601,6 +4645,8 @@ formData.append('subject', subject); formData.append('mail_content', mail_content); formData.append('recipient_mail', ''); // Empty value as per logic + formData.append('selected_attachment_files', JSON.stringify(selectedFiles)); + ajaxRequest(formData) @@ -4626,6 +4672,13 @@ to = to.split(',').map(email => email.trim()); cc = cc.map(Number); // or split if it's a string: `cc.split(',').map(email => email.trim())` + + var selectedFiles = []; + $('#placement_mail_attachment .multi_file_attachment:checked').each(function () { + selectedFiles.push($(this).val()); + }); + + // Prepare FormData var formData = new FormData(); formData.append('lead_id', lead_id); @@ -4642,11 +4695,14 @@ formData.append('total_amount', total_amount); formData.append('cd_amount', cd_amount); formData.append('mail_content', mail_content); + formData.append('selected_attachment_files', JSON.stringify(selectedFiles)); + ajaxRequest(formData); } + function ajaxRequest(formData) { var apiURL = '';