diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 0c5f0d0c..45619181 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -352,6 +352,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/Chatbot/EcardDownloadConversation.php b/app/Controllers/Chatbot/EcardDownloadConversation.php index b0cb78ae..84617af1 100644 --- a/app/Controllers/Chatbot/EcardDownloadConversation.php +++ b/app/Controllers/Chatbot/EcardDownloadConversation.php @@ -17,6 +17,8 @@ class EcardDownloadConversation extends Conversation protected function showEcardMenu() { + log_message('error', ('showEcardMenu function called')); + $chat_session_info = get_chatbot_session_info(); $policy_list = ChatbotHelper::getListOfPolicies($chat_session_info); $buttons = []; diff --git a/app/Controllers/Chatbot/MainMenuConversation.php b/app/Controllers/Chatbot/MainMenuConversation.php index 87d9a4ef..875ecba4 100644 --- a/app/Controllers/Chatbot/MainMenuConversation.php +++ b/app/Controllers/Chatbot/MainMenuConversation.php @@ -46,9 +46,14 @@ class MainMenuConversation extends Conversation $this->bot->reply($message); } + log_message('error', ('user_reponse before: ' . $user_reponse)); + + if (!$answer->isInteractiveMessageReply()) { $user_reponse = null; } + + // Get just the existing path array $path = $this->bot->userStorage()->get('path') ?? []; @@ -60,6 +65,9 @@ class MainMenuConversation extends Conversation 'path' => $path ]); + log_message('error', ('user_reponse : ' . $user_reponse)); + + switch ($user_reponse) { case "ecard_download": diff --git a/app/Controllers/Chatbot/NetworkHospitalConversation.php b/app/Controllers/Chatbot/NetworkHospitalConversation.php index 2e59f896..4a1e991c 100644 --- a/app/Controllers/Chatbot/NetworkHospitalConversation.php +++ b/app/Controllers/Chatbot/NetworkHospitalConversation.php @@ -59,7 +59,10 @@ class NetworkHospitalConversation extends Conversation $this->bot->userStorage()->save([ 'path' => $path ]); + log_message('error', ('user_reponse : ' . $answer->getValue())); + switch ($answer->getValue()) { + case is_string($answer->getValue()) && is_array(explode('#',$answer->getValue())) && count((explode('#',$answer->getValue()))) == 2: $client_poilicy_id = explode('#',$answer->getValue())[1]; diff --git a/app/Controllers/Chatbot/policyConversation.php b/app/Controllers/Chatbot/policyConversation.php index 04c8d9a5..f2fe91c1 100644 --- a/app/Controllers/Chatbot/policyConversation.php +++ b/app/Controllers/Chatbot/policyConversation.php @@ -46,6 +46,9 @@ class policyConversation extends Conversation if (!$answer->isInteractiveMessageReply()) { $user_reponse = null; } + + log_message('error', ('user_reponse : ' . $answer->getValue())); + $path = $this->bot->userStorage()->get('path'); array_push($path, $answer->getValue() diff --git a/app/Controllers/ChatbotControllerNew.php b/app/Controllers/ChatbotControllerNew.php index 610f2bda..2f6ca404 100644 --- a/app/Controllers/ChatbotControllerNew.php +++ b/app/Controllers/ChatbotControllerNew.php @@ -89,7 +89,7 @@ class ChatbotControllerNew extends BaseController $user = $this->botman->getUser(); $id = $user->getId(); - // $this->myLogger->logme('error', ('TEST' . $id)); + $this->myLogger->logme('error', ('TEST' . $id)); $this->session->set('CHATBOT_RANDOM_USER_ID', $id); } @@ -128,14 +128,14 @@ class ChatbotControllerNew extends BaseController $this->botman->listen(); } - private function registerHandlers() - { - // Handling Policy and Claims - $this->botman->hears('group:policy:{option}', [\App\Controllers\Chatbot\PolicyHandler::class, 'handle']); - $this->botman->hears('group:claim:{option}', [\App\Libraries\Chatbot\ClaimHandler::class, 'handle']); + // private function registerHandlers() + // { + // // Handling Policy and Claims + // $this->botman->hears('group:policy:{option}', [\App\Controllers\Chatbot\PolicyHandler::class, 'handle']); + // $this->botman->hears('group:claim:{option}', [\App\Libraries\Chatbot\ClaimHandler::class, 'handle']); - } + // } public function chatbot() { diff --git a/app/Controllers/LeadsController.php b/app/Controllers/LeadsController.php index 1c5e9f80..02134611 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); @@ -1801,7 +1891,7 @@ class LeadsController extends BaseController ['file_path' => $temp_file_path, 'sheets' => []], ['file_path' => $lead_file_path, 'sheets' => []] ]; - $outputPath = dirname($temp_file_path) . '/' . 'merged_' . $temp_file_name; + $outputPath = dirname($temp_file_path) . '/' . $temp_file_name; $result = ExcelMergeHelper::mergeExcelFiles($filePaths, $outputPath); // print_rr($result); } @@ -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/Helpers/ExcelMergeHelper.php b/app/Helpers/ExcelMergeHelper.php index 36306692..405c4762 100644 --- a/app/Helpers/ExcelMergeHelper.php +++ b/app/Helpers/ExcelMergeHelper.php @@ -17,10 +17,13 @@ class ExcelMergeHelper { { try { log_message('debug', 'Attempting merge with original file order'); + // echo "Attempting merge with original file order\n"; return self::processFiles($filePaths, $outputPath); } catch (Exception $e) { log_message('error', 'First attempt failed: ' . $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine()); + // echo "First attempt failed: " . $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine() . "\n"; log_message('debug', 'Retrying with reversed file order'); + // echo "Retrying with reversed file order\n"; // Reverse the file order and try again $reversedFiles = array_reverse($filePaths); @@ -29,6 +32,7 @@ class ExcelMergeHelper { return self::processFiles($reversedFiles, $outputPath); } catch (Exception $e2) { log_message('error', 'Both attempts failed. Last error: ' . $e2->getMessage() . ' in ' . $e2->getFile() . ' on line ' . $e2->getLine()); + // echo "Both attempts failed. Last error: " . $e2->getMessage() . ' in ' . $e2->getFile() . ' on line ' . $e2->getLine() . "\n"; return null; } } @@ -45,7 +49,9 @@ class ExcelMergeHelper { private static function processFiles(array $filePaths, string $outputPath): string { log_message('debug', 'Starting Excel merge process'); + // echo "Starting Excel merge process\n"; log_message('debug', 'Files to process: ' . json_encode($filePaths)); + // echo "Files to process: " . json_encode($filePaths) . "\n"; if (empty($filePaths)) { throw new Exception("No files provided to merge"); @@ -66,6 +72,7 @@ class ExcelMergeHelper { // Save the merged file log_message('debug', "Saving merged file to: {$outputPath}"); + // echo "Saving merged file to: {$outputPath}\n"; $writer = IOFactory::createWriter($mergedSpreadsheet, 'Xlsx'); $writer->setPreCalculateFormulas(false); $writer->save($outputPath); @@ -76,6 +83,7 @@ class ExcelMergeHelper { gc_collect_cycles(); log_message('debug', 'Excel merge process completed successfully'); + // echo "Excel merge process completed successfully\n"; return $outputPath; } @@ -87,15 +95,17 @@ class ExcelMergeHelper { * @param int|null $index * @throws Exception */ - private static function processSingleFile(array $fileInfo, Spreadsheet $mergedSpreadsheet, int $index = null) + private static function processSingleFile(array $fileInfo, Spreadsheet $mergedSpreadsheet, ?int $index = null) { if (!isset($fileInfo['file_path']) || !file_exists($fileInfo['file_path'])) { $path = $fileInfo['file_path'] ?? 'undefined'; log_message('error', "File " . ($index ?? 'base') . ": Invalid or missing file path: {$path}"); + // echo "File " . ($index ?? 'base') . ": Invalid or missing file path: {$path}\n"; return; } log_message('debug', "Processing file " . ($index ?? 'base') . ": " . $fileInfo['file_path']); + // echo "Processing file " . ($index ?? 'base') . ": " . $fileInfo['file_path'] . "\n"; try { // Load the source spreadsheet @@ -105,6 +115,7 @@ class ExcelMergeHelper { $worksheets = $sourceSpreadsheet->getAllSheets(); $totalSheets = count($worksheets); log_message('debug', "Total sheets in file: " . $totalSheets); + // echo "Total sheets in file: " . $totalSheets . "\n"; $sheetsToMerge = $fileInfo['sheets'] ?? []; @@ -114,26 +125,30 @@ class ExcelMergeHelper { try { $sheetName = $worksheet->getTitle(); log_message('debug', "Processing sheet: {$sheetName}"); + // echo "Processing sheet: {$sheetName}\n"; // Generate unique sheet name before cloning $newName = $sheetName; $counter = 1; while (in_array($newName, $mergedSpreadsheet->getSheetNames())) { - $newName = $sheetName . "_" . $counter++; + // $newName = $sheetName . "_" . $counter++; log_message('debug', "Sheet name already exists. Trying new name: {$newName}"); + // echo "Sheet name already exists. Trying new name: {$newName}\n"; } // Clone the worksheet and set the new name - $clonedSheet = clone $worksheet; - $clonedSheet->setTitle($newName); + // $clonedSheet = clone $worksheet; + // $clonedSheet->setTitle($newName); // Add as external sheet - $mergedSpreadsheet->addExternalSheet($clonedSheet); + $mergedSpreadsheet->addExternalSheet($worksheet); log_message('debug', "Successfully added sheet: {$newName}"); + // echo "Successfully added sheet: {$newName}\n"; } catch (Exception $e) { log_message('error', "Error processing sheet {$sheetName} as new name {$newName}: " . $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine()); + // echo "Error processing sheet {$sheetName} as new name {$newName}: " . $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine() . "\n"; } } } @@ -145,6 +160,7 @@ class ExcelMergeHelper { } catch (Exception $e) { log_message('error', "Error processing file {$fileInfo['file_path']}: " . $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine()); + // echo "Error processing file {$fileInfo['file_path']}: " . $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine() . "\n"; } } } \ No newline at end of file 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) @@ -1064,7 +1062,7 @@ console.log('incurredClaimDate', incurredClaimDate) if (policyStartDate && incurredClaimDate) { - var timeDiff = incurredClaimDate - policyStartDate; // Time difference in milliseconds + var timeDiff = (policyStartDate - incurredClaimDate) + 1; // Time difference in milliseconds console.log('timeDiff', timeDiff); var daysDiff = Math.ceil(timeDiff / (1000 * 60 * 60 * 24)); // Convert to days and add 1 console.log('daysDiff', daysDiff); @@ -1145,6 +1143,69 @@ $('#earned_premium_' + increment).val(earned_premium_roundoff); } + $(document).on("input", "#incept_emp_count, #incept_dept_count, #renewal_emp_count, #renewal_dept_count, #exp_emp_count, #exp_dept_count", function() { + calculateTotalLives(this); + }); + + function calculateTotalLives(input) { + + var lead_type = $('#lead_type').val(); + + if (lead_type == 1) { + + let formRow = input.closest('.form-row'); + + if (formRow) { + // Get the employee count and dependent count within the same row + let empCountInput = formRow.querySelector('[name="incept_emp_count[]"]'); + let depCountInput = formRow.querySelector('[name="incept_dept_count[]"]'); + let totalLivesInput = formRow.querySelector('[name="incept_no_of_lives[]"]'); + + // Parse the input values as integers, defaulting to 0 if empty + let empCount = empCountInput ? parseInt(empCountInput.value) || 0 : 0; + let depCount = depCountInput ? parseInt(depCountInput.value) || 0 : 0; + + // Calculate total lives + let totalLives = empCount + depCount; + + // Set the total lives input value + if (totalLivesInput) { + totalLivesInput.value = totalLives; + } + } + + + } else { + console.log("Function Called"); + + if (input.id === "incept_emp_count" || input.id === "incept_dept_count") { + var incept_emp_count = parseInt($("#incept_emp_count").val()) || 0; + var incept_dept_count = parseInt($("#incept_dept_count").val()) || 0; + + var totalCount = incept_emp_count + incept_dept_count; + $("#incept_no_of_lives").val(totalCount); + + } else if (input.id === "renewal_emp_count" || input.id === "renewal_dept_count") { + var renewal_emp_count = parseInt($("#renewal_emp_count").val()) || 0; + var renewal_dept_count = parseInt($("#renewal_dept_count").val()) || 0; + + var totalCount = renewal_emp_count + renewal_dept_count; + $("#renewal_no_of_lives").val(totalCount); + + } else { + var exp_emp_count = parseInt($("#exp_emp_count").val()) || 0; + var exp_dept_count = parseInt($("#exp_dept_count").val()) || 0; + + var totalCount = exp_emp_count + exp_dept_count; + $("#exp_no_of_lives").val(totalCount); + } + } + + + } + + + //------------------------ FORM SUBMIT --------------------------------------------------------------------------------- $("#leads_form_id").submit(function(event) { @@ -1540,4 +1601,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/gmc.php b/app/Views/rfq/gmc.php index 09d28d3e..9c99df08 100644 --- a/app/Views/rfq/gmc.php +++ b/app/Views/rfq/gmc.php @@ -116,14 +116,14 @@ + placeholder="Enter Lives" required oninput="calculateTotalLives(this)">
+ placeholder="Enter Lives" required oninput="calculateTotalLives(this)">
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 = '';