CHANGE_EB_FOR_CODE_MERGE

This commit is contained in:
VENKATESHWARAN 2025-10-06 09:52:49 +05:30
parent d28f5c1140
commit 7187fc89c6
8 changed files with 828 additions and 159 deletions

View File

@ -384,6 +384,8 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) {
$routes->get('getClaimDumpFileErrorData', 'TicketController::getClaimDumpFileErrorData');
$routes->get("claim_dump_excel_error/(:any)", "TicketController::getClaimDumpExcelFileErrors/$1");
$routes->get("download_claim_dump_file/(:any)", "TicketController::downloadClaimDumpFile/$1");
$routes->post('uploadMultiFileFromRfq', 'LeadsController::uploadMultiFileFromRfq');
$routes->get('downloadMemberFile/(:any)', 'LeadsController::downloadMemberFile/$1');
});
$routes->post("policy_tranction/sendInstallmentRemainderMail","PolicyTransactionController::sendInstallmentRemainderMail");
@ -692,6 +694,9 @@ $routes->group('test', function($routes) {
$routes->get('viewPDF', 'TestingController::viewPDF');
$routes->get('generate-pdf-view', 'TestingController::generatePDFWithView');
$routes->get('param/(:any)', 'TestingController::ptedfitdata/$1');
$routes->get('viewrfq', 'TestingController::viewRFQNonEb');
$routes->get('exportexcel', 'TestingController::exportExcel');
$routes->post('saverfq', 'TestingController::saverfq');
});
$routes->cli('cli/testcli', 'TestingController::testcli');

View File

@ -528,7 +528,7 @@ class LeadsController extends BaseController
return $this->respond(['status' => false, 'lead_id' => $id, 'message' => "Failed to update Lead", 'data' => $data], 200);
}
// Get the Single Lead data for edit uisng ajax ( do not delete)
// Get the Single Lead data for edit uisng ajax (do not delete)
public function getLeadDataForEdit($id)
{
@ -603,7 +603,7 @@ class LeadsController extends BaseController
}
public function uploadMultiFiles($files, $docs_names, $primaryKey)
{
{
$uploadFilePath = WRITEPATH . 'uploads/lead_files/';
$multi_file_data = [];
@ -696,63 +696,287 @@ class LeadsController extends BaseController
//--------RFQ-----------------------------------------------------------------------------------------------
// public function viewRFQ($id, $type = 1)
// {
// $data['rfq_data'] = $this->RFQModel
// ->where('lead_id', $id)
// // ->where('type', $type)
// ->where('is_active', 1)
// ->orderBy('id', 'desc')
// ->first();
// // dd($data);
// $data['rfq_count'] = $this->RFQModel
// ->where('lead_id', $id)
// // ->where('type', 1)
// ->where('is_active', 1)
// ->countAllResults();
// $data['qcr_count'] = $this->RFQModel
// ->where('lead_id', $id)
// ->where('type', 2)
// ->where('is_active', 1)
// ->countAllResults();
// // dd(count($data['rfq_data']));
// $data['lead_id'] = $id;
// $lead_data = $this->leadsModel
// ->select('
// leads.*,
// policy_type.question_json,
// policy_type.policy_type,
// policy_type.long_name,
// user_profiles.email as created_person_email
// ')
// ->join('policy_type', 'leads.policy_type_id = policy_type.id')
// ->join('user_profiles', 'leads.created_by = user_profiles.id', 'left')
// ->where('leads.id', $id)
// ->where('leads.is_active', 1)
// ->first();
// // dd($lead_data);
// if ($lead_data['lead_type'] != 1) {
// $client_policy_data = $this->clientPolicyModel->where('is_active', 1)->where('id', $lead_data['source_policy_id'])->first();
// if (isset($client_policy_data)) {
// $data['policy_terms'] = $client_policy_data['policy_terms'];
// }
// }
// $data['question_json'] = $lead_data['question_json'];
// $data['page_name'] = $type == 2 ? 'QCR' : 'RFQ';
// $data['insurer'] = $this->insurerBranchModel->getInsurerBranchesWithInsurerNames();
// $data['userList'] = $this->userModel->getUserListForRFQ();
// $data['exclusiveUserList'] = $this->userModel->getexclusiveUserListForRFQ();
// $data['lead_data'] = $lead_data;
// $data['tpa_list'] = $this->tpaBranchModel->getTpaBranchesWithTpaNames();
// $data['account_manager'] = $this->userModel->where('is_active', 1)->where('role', 3)->findAll();
// $mail_content = '
// <p>Dear Sir,</p>
// <p>Greetings From Nhance India!</p>
// <p>Please find attached the {{RFQ_OR_QCR}} for <strong>{{POLICY_TYPE}}</strong> policy pertaining to <strong>{{CLIENT_NAME}}</strong>.</p>
// <p>Kindly request you to share the competitive quotes at the earliest.</p>
// <p>In case of any query, please feel free to contact us.</p>
// <p>Thank You!</p><br>
// <p>Best regards,</p>
// <div style=\"margin: 0; padding: 0; line-height: 1.2;\">
// <div>{{LOGGED_USER_NAME}}</div>
// <div>Mobile: {{LOGGED_USER_MOBILE}}</div>
// </div>
// <img src="{{LOGO_PATH}}" alt="Nhance Logo" width="100" style="margin-top:10px;">
// ';
// if ($data['lead_data']['policy_end_date'] != null) {
// $subject = "{{CLIENT_NAME}} _ {{POLICY_TYPE}} _ {{RFQ_OR_QCR}} _ {{POLICY_YEAR}} {{POLICY_END_DATE}}";
// } else {
// $subject = "{{CLIENT_NAME}} _ {{POLICY_TYPE}} _ {{RFQ_OR_QCR}} _ {{POLICY_YEAR}}";
// }
// if ($lead_data['policy_type_id'] == 1) {
// $data['totalSumAssured'] = $this->handleMemberDataGPATotalSumInsurerFromExcel(['lead_id' => $id]);
// } else {
// $data['totalSumAssured'] = [];
// }
// $data['mail_content'] = $this->transformMailContent($lead_data, $mail_content, $data['page_name']);
// $data['subject'] = $this->transformMailContent($lead_data, $subject, $data['page_name']);
// $data['placement_mail_content'] = $this->transformMailContent($lead_data, $mail_content, 'Placement');
// $data['placement_subject'] = $this->transformMailContent($lead_data, $subject, 'Placement');
// $data['multi_file_data'] = $this->leadFilesModel->where('lead_id', $id)->where('is_active', 1)->findAll() ?? null;
// $installment_data['installments'] = $this->leadInstallmentPaymentDetails->where('lead_id', $id)->where('is_active', 1)->findAll() ?? null;
// $data['lead_data']['installment_data'] = view('rfq/installment_fields', $installment_data) ?? null;
// $data['attachment_html'] = view('rfq/attachment_files', $data) ?? "";
// $data['user_team'] = $this->userModel->select("ut.team_id")->join("user_teams ut", "ut.user_id = user_profiles.id and ut.is_active = 1")->where("user_profiles.is_active", 1)->first()['team_id'];
// $data['multi_file_data_html'] = $this->renderFileFields($data['multi_file_data']);
// // dd($data);
// if ($data['lead_data']['lead_form_type'] == 1) {
// $data['demogrphy_html_data'] = $this->generateDemographyDataTable(['lead_id' => $id]);
// $this->loadLayout('view_rfq.php', $data);
// } else if ($data['lead_data']['lead_form_type'] == 2) {
// $data['occupancy'] = $this->occupancyModel->findAll();
// // dd($data['occupancy']);
// if ($lead_data['lead_type'] != 1 && $data['rfq_count'] == 0) {
// $client_policy_data = $this->clientPolicyModel->where('is_active', 1)->where('id', $lead_data['source_policy_id'])->first();
// if (isset($client_policy_data)) {
// $data['rfq_data']['json'] = $client_policy_data['placement_json'];
// }
// }
// if (!empty($data['question_json'])) {
// $data['policies'] = json_decode($data['question_json'], true)['policies'];
// $data["child_table_data"] = json_decode($data['question_json'], true)['child_table_data'];
// }
// $data['product'] = $this->leadsModel->select("policy_type.policy_type")->join('policy_type', 'leads.policy_type_id = policy_type.id')->where('leads.id', $id)->first()['policy_type'];
// // $data['lead_register_data'] = json_decode($data['lead_data']['custom_fields']);
// // dd($data['lead_register_data']);
// // $data['entity_type'] = $this->kycEntityTypeModel->where('is_active', 1)->findAll();
// $data['buisness_type'] = $this->buisnessType;
// // dd($data);
// $data['client_type'] = $this->clientType;
// $this->loadLayout('view_rfq_non_eb', $data);
// }
// }
public function viewRFQ($id, $type = 1)
{
// 1. Combine RFQ queries into a single query
$rfqStats = $this->RFQModel
->select('
COUNT(*) as total_count,
SUM(CASE WHEN type != 2 THEN 1 ELSE 0 END) as rfq_count,
SUM(CASE WHEN type = 2 THEN 1 ELSE 0 END) as qcr_count
')
->where('lead_id', $id)
->where('is_active', 1)
->first();
$data['rfq_count'] = $rfqStats['rfq_count'] ?? 0;
$data['qcr_count'] = $rfqStats['qcr_count'] ?? 0;
// 2. Get RFQ data separately (only if needed)
$data['rfq_data'] = $this->RFQModel
->where('lead_id', $id)
// ->where('type', $type)
->where('is_active', 1)
->orderBy('id', 'desc')
->first();
// dd($data);
$data['rfq_count'] = $this->RFQModel
->where('lead_id', $id)
// ->where('type', 1)
->where('is_active', 1)
->countAllResults();
$data['qcr_count'] = $this->RFQModel
->where('lead_id', $id)
->where('type', 2)
->where('is_active', 1)
->countAllResults();
// dd(count($data['rfq_data']));
$data['lead_id'] = $id;
// 3. Optimize lead data query with specific field selection
$lead_data = $this->leadsModel
->select('
leads.*,
policy_type.question_json,
policy_type.policy_type,
policy_type.long_name,
user_profiles.email as created_person_email
')
leads.id, leads.policy_type_id, leads.lead_type, leads.source_policy_id,
leads.policy_end_date, leads.lead_form_type, leads.created_by, leads.client_name,
policy_type.question_json, policy_type.policy_type, policy_type.long_name,
user_profiles.email as created_person_email
')
->join('policy_type', 'leads.policy_type_id = policy_type.id')
->join('user_profiles', 'leads.created_by = user_profiles.id', 'left')
->where('leads.id', $id)
->where('leads.is_active', 1)
->first();
// dd($lead_data);
if (!$lead_data) {
// Handle case where lead doesn't exist
throw new \Exception('Lead not found');
}
// 4. Conditional query - only fetch if needed
if ($lead_data['lead_type'] != 1) {
$client_policy_data = $this->clientPolicyModel->where('is_active', 1)->where('id', $lead_data['source_policy_id'])->first();
if (isset($client_policy_data)) {
$client_policy_data = $this->clientPolicyModel
->select('policy_terms, placement_json')
->where('is_active', 1)
->where('id', $lead_data['source_policy_id'])
->first();
if ($client_policy_data) {
$data['policy_terms'] = $client_policy_data['policy_terms'];
// Store for later use in lead_form_type == 2 condition
if ($lead_data['lead_form_type'] == 2 && $data['rfq_count'] == 0) {
$data['rfq_data']['json'] = $client_policy_data['placement_json'];
}
}
}
// 5. Cache decoded JSON to avoid multiple decodes
$question_json_decoded = !empty($lead_data['question_json'])
? json_decode($lead_data['question_json'], true)
: null;
$data['question_json'] = $lead_data['question_json'];
$data['page_name'] = $type == 2 ? 'QCR' : 'RFQ';
$data['lead_data'] = $lead_data;
// 6. Parallel/batch data fetching for independent queries
$data['insurer'] = $this->insurerBranchModel->getInsurerBranchesWithInsurerNames();
$data['userList'] = $this->userModel->getUserListForRFQ();
$data['exclusiveUserList'] = $this->userModel->getexclusiveUserListForRFQ();
$data['lead_data'] = $lead_data;
$data['tpa_list'] = $this->tpaBranchModel->getTpaBranchesWithTpaNames();
$data['account_manager'] = $this->userModel
->where('is_active', 1)
->where('role', 3)
->findAll();
$mail_content = '
// 7. Define mail templates as constants or config
$mail_content = $this->getMailTemplate();
$subject = $this->getSubjectTemplate($lead_data);
// 8. Pre-calculate sum assured only for GPA
$data['totalSumAssured'] = ($lead_data['policy_type_id'] == 1) ? $this->handleMemberDataGPATotalSumInsurerFromExcel(['lead_id' => $id]) : [];
// 9. Transform mail content once
$data['mail_content'] = $this->transformMailContent($lead_data, $mail_content, $data['page_name']);
$data['subject'] = $this->transformMailContent($lead_data, $subject, $data['page_name']);
$data['placement_mail_content'] = $this->transformMailContent($lead_data, $mail_content, 'Placement');
$data['placement_subject'] = $this->transformMailContent($lead_data, $subject, 'Placement');
// 10. Combine related queries
$data['multi_file_data'] = $this->leadFilesModel
->where('lead_id', $id)
->where('is_active', 1)
->findAll();
$installment_data['installments'] = $this->leadInstallmentPaymentDetails
->where('lead_id', $id)
->where('is_active', 1)
->findAll();
// 11. Generate views efficiently
$data['lead_data']['installment_data'] = !empty($installment_data['installments'])
? view('rfq/installment_fields', $installment_data)
: null;
$data['attachment_html'] = view('rfq/attachment_files', $data);
$user_team = $this->userModel
->select("ut.team_id")
->join("user_teams ut", "ut.user_id = user_profiles.id and ut.is_active = 1")
->where("user_profiles.is_active", 1)
->first();
$data['user_team'] = $user_team['team_id'] ?? null;
$data['multi_file_data_html'] = $this->renderFileFields($data['multi_file_data']);
// 12. Conditional rendering based on lead_form_type
if ($lead_data['lead_form_type'] == 1) {
$data['demogrphy_html_data'] = $this->generateDemographyDataTable(['lead_id' => $id]);
$this->loadLayout('view_rfq.php', $data);
} else if ($lead_data['lead_form_type'] == 2) {
$data['occupancy'] = $this->occupancyModel->findAll();
// Use cached decoded JSON
if ($question_json_decoded) {
$data['policies'] = $question_json_decoded['policies'] ?? [];
$data["child_table_data"] = $question_json_decoded['child_table_data'] ?? [];
}
$data['product'] = $lead_data['policy_type'];
$data['buisness_type'] = $this->buisnessType;
$data['client_type'] = $this->clientType;
$this->loadLayout('view_rfq_non_eb', $data);
}
}
// 13. Extract mail template to separate method for reusability
private function getMailTemplate()
{
return '
<p>Dear Sir,</p>
<p>Greetings From Nhance India!</p>
<p>Please find attached the {{RFQ_OR_QCR}} for <strong>{{POLICY_TYPE}}</strong> policy pertaining to <strong>{{CLIENT_NAME}}</strong>.</p>
@ -761,70 +985,21 @@ class LeadsController extends BaseController
<p>Thank You!</p><br>
<p>Best regards,</p>
<div style=\"margin: 0; padding: 0; line-height: 1.2;\">
<div style="margin: 0; padding: 0; line-height: 1.2;">
<div>{{LOGGED_USER_NAME}}</div>
<div>Mobile: {{LOGGED_USER_MOBILE}}</div>
</div>
<img src="{{LOGO_PATH}}" alt="Nhance Logo" width="100" style="margin-top:10px;">
<img src="{{LOGO_PATH}}" alt="Nhance Logo" width="100" style="margin-top:10px;">
';
}
if ($data['lead_data']['policy_end_date'] != null) {
$subject = "{{CLIENT_NAME}} _ {{POLICY_TYPE}} _ {{RFQ_OR_QCR}} _ {{POLICY_YEAR}} {{POLICY_END_DATE}}";
} else {
$subject = "{{CLIENT_NAME}} _ {{POLICY_TYPE}} _ {{RFQ_OR_QCR}} _ {{POLICY_YEAR}}";
}
if ($lead_data['policy_type_id'] == 1) {
$data['totalSumAssured'] = $this->handleMemberDataGPATotalSumInsurerFromExcel(['lead_id' => $id]);
} else {
$data['totalSumAssured'] = [];
}
$data['mail_content'] = $this->transformMailContent($lead_data, $mail_content, $data['page_name']);
$data['subject'] = $this->transformMailContent($lead_data, $subject, $data['page_name']);
$data['placement_mail_content'] = $this->transformMailContent($lead_data, $mail_content, 'Placement');
$data['placement_subject'] = $this->transformMailContent($lead_data, $subject, 'Placement');
$data['multi_file_data'] = $this->leadFilesModel->where('lead_id', $id)->where('is_active', 1)->findAll() ?? null;
$installment_data['installments'] = $this->leadInstallmentPaymentDetails->where('lead_id', $id)->where('is_active', 1)->findAll() ?? null;
$data['lead_data']['installment_data'] = view('rfq/installment_fields', $installment_data) ?? null;
$data['attachment_html'] = view('rfq/attachment_files', $data) ?? "";
$data['user_team'] = $this->userModel->select("ut.team_id")->join("user_teams ut", "ut.user_id = user_profiles.id and ut.is_active = 1")->where("user_profiles.is_active", 1)->first()['team_id'];
// dd($data);
if ($data['lead_data']['lead_form_type'] == 1) {
$data['demogrphy_html_data'] = $this->generateDemographyDataTable(['lead_id' => $id]);
$this->loadLayout('view_rfq.php', $data);
} else if ($data['lead_data']['lead_form_type'] == 2) {
$data['occupancy'] = $this->occupancyModel->findAll();
// dd($data['occupancy']);
if ($lead_data['lead_type'] != 1 && $data['rfq_count'] == 0) {
$client_policy_data = $this->clientPolicyModel->where('is_active', 1)->where('id', $lead_data['source_policy_id'])->first();
if (isset($client_policy_data)) {
$data['rfq_data']['json'] = $client_policy_data['placement_json'];
}
}
if (!empty($data['question_json'])) {
$data['policies'] = json_decode($data['question_json'], true)['policies'];
$data["child_table_data"] = json_decode($data['question_json'], true)['child_table_data'];
}
$data['product'] = $this->leadsModel->select("policy_type.policy_type")->join('policy_type', 'leads.policy_type_id = policy_type.id')->where('leads.id', $id)->first()['policy_type'];
// $data['lead_register_data'] = json_decode($data['lead_data']['custom_fields']);
// dd($data['lead_register_data']);
// $data['entity_type'] = $this->kycEntityTypeModel->where('is_active', 1)->findAll();
$data['buisness_type'] = $this->buisnessType;
// dd($data);
$data['client_type'] = $this->clientType;
$this->loadLayout('view_rfq_non_eb', $data);
}
// 14. Extract subject template to separate method
private function getSubjectTemplate($lead_data)
{
return $lead_data['policy_end_date'] != null
? "{{CLIENT_NAME}} _ {{POLICY_TYPE}} _ {{RFQ_OR_QCR}} _ {{POLICY_YEAR}} {{POLICY_END_DATE}}"
: "{{CLIENT_NAME}} _ {{POLICY_TYPE}} _ {{RFQ_OR_QCR}} _ {{POLICY_YEAR}}";
}
public function savePolicyInfo()
@ -1452,20 +1627,22 @@ class LeadsController extends BaseController
'Policy Type' => $this->leadType[$rfq_data['lead_type']] ?? "",
];
}
} else {
if (in_array($rfq_data['policy_type_id'], [2, 3, 4, 5])) {
$lead_data = [
'Insured' => $rfq_data['client_name'],
'Policy Type' => $this->leadType[$rfq_data['lead_type']] ?? "",
'No of Employees at Inception' => $rfq_data['incept_emp_count'],
'No of Dependents at Inception' => $rfq_data['incept_dept_count'],
'Total Lives at Inception ' => $rfq_data['incept_no_of_lives'],
// 'No of Employees at Inception' => $rfq_data['incept_emp_count'],
// 'No of Dependents at Inception' => $rfq_data['incept_dept_count'],
// 'Total Lives at Inception ' => $rfq_data['incept_no_of_lives'],
'No of Employees at Expiry' => $rfq_data['exp_emp_count'],
'No of Dependents at Expiry' => $rfq_data['exp_dept_count'],
'Total Lives at Expiry ' => $rfq_data['exp_no_of_lives'],
// 'No of Employees at Expiry' => $rfq_data['exp_emp_count'],
// 'No of Dependents at Expiry' => $rfq_data['exp_dept_count'],
// 'Total Lives at Expiry ' => $rfq_data['exp_no_of_lives'],
'No of Employees at Renewal' => $rfq_data['renewal_emp_count'],
'No of Dependents at Renewal' => $rfq_data['renewal_dept_count'],
@ -1474,30 +1651,32 @@ class LeadsController extends BaseController
'Period of Insurance ' => !empty($rfq_data['policy_start_date']) && !empty($rfq_data['policy_end_date']) ? date('d-m-Y', strtotime($rfq_data['policy_start_date'])) . ' to ' . date('d-m-Y', strtotime($rfq_data['policy_end_date'])) : "To be decided",
'Insurer' => $rfq_data['insurer_name'] ?? " - ",
'TPA' => $rfq_data['tpa_name'] ?? " - ",
'Policy Run Days' => $rfq_data['policy_run_days'],
'Inception Premium' => formatIndianCurrency($rfq_data['premium_at_inception']),
'Premium as on (' . date('d-m-Y', strtotime($rfq_data['incurred_claims_date'])) . ')' => formatIndianCurrency($rfq_data['premium_date']),
'Earned Premium' => formatIndianCurrency(intval($rfq_data['earned_premium'])),
'Incurred Claims as on (' . date('d-m-Y', strtotime($rfq_data['incurred_claims_date'])) . ')' => formatIndianCurrency($rfq_data['incurred_claims']),
'Annualised Claims' => formatIndianCurrency(intval($rfq_data['annualised_claims'])),
'Incurred Claims Ratio' => $rfq_data['incurred_claims_ratio'] . " %",
'Earned Claims Ratio' => $rfq_data['earned_claims_ratio'] . " %",
// 'Policy Run Days' => $rfq_data['policy_run_days'],
// 'Inception Premium' => formatIndianCurrency($rfq_data['premium_at_inception']),
// 'Premium as on (' . date('d-m-Y', strtotime($rfq_data['incurred_claims_date'])) . ')' => formatIndianCurrency($rfq_data['premium_date']),
// 'Earned Premium' => formatIndianCurrency(intval($rfq_data['earned_premium'])),
// 'Incurred Claims as on (' . date('d-m-Y', strtotime($rfq_data['incurred_claims_date'])) . ')' => formatIndianCurrency($rfq_data['incurred_claims']),
// 'Annualised Claims' => formatIndianCurrency(intval($rfq_data['annualised_claims'])),
// 'Incurred Claims Ratio' => $rfq_data['incurred_claims_ratio'] . " %",
// 'Earned Claims Ratio' => $rfq_data['earned_claims_ratio'] . " %",
];
} else if (in_array($rfq_data['policy_type_id'], [1, 6, 7])) {
$lead_data = [
'Insured' => $rfq_data['client_name'],
'No of Employees at Inception' => $rfq_data['incept_emp_count'],
'Total Lives at Inception' => $rfq_data['total_lives_at_incept'],
'Total Sum Insured at Inception' => $rfq_data['total_si_at_incept'],
'Premium at inception' => $rfq_data['premium_at_incept'],
'No of Employees at Renewal' => $rfq_data['renewal_emp_count'],
'Total Sum Insured at Renewal ' => $rfq_data['total_si_at_renewal'],
'Policy Period' => !empty($rfq_data['policy_start_date']) && !empty($rfq_data['policy_end_date']) ? date('d-m-Y', strtotime($rfq_data['policy_start_date'])) . ' to ' . date('d-m-Y', strtotime($rfq_data['policy_end_date'])) : "To be decided",
// 'Insurer' => $rfq_data['insurer_name'] ?? " - ",
// 'TPA' => $rfq_data['tpa_name'] ?? " - ",
'Policy Type' => $this->leadType[$rfq_data['lead_type']] ?? "",
'Existing Insurer' => $rfq_data['insurer_name'],
// 'TPA ' => $rfq_data['tpa_name'],
'No of Employees at Renewal' => $rfq_data['renewal_emp_count'],
'Total Sum Insured at Renewal' => $rfq_data['total_si_at_renewal'],
'Claims Experience for last 3 years' => "Mentioned in Claims sheet",
// 'Insurer' => $rfq_data['insurer_name'] ?? " - ",
// 'TPA' => $rfq_data['tpa_name'] ?? " - ",
// 'Total Lives at Inception' => $rfq_data['total_lives_at_incept'],
];
}
}
@ -2825,6 +3004,22 @@ class LeadsController extends BaseController
}
}
if($recipient_type == 'placement' && isset($params['acm_email']) && !empty($params['acm_email'])){
$common['mail_type'] = "internal acm";
$acm_mail_content = '
<p>Dear Sir,</p>
<p>The placement for the <strong>{{POLICY_TYPE}}</strong> policy pertaining to <strong>{{CLIENT_NAME}}</strong> has been successfully won.</p>
<p>Please proceed with the next steps accordingly.</p>
<p>Thank You!</p><br>
<p>Best regards,</p>
<img src="{{LOGO_PATH}}" alt="Nhance Logo" width="100" style="margin-top:10px;">
';
$acm_mail_content = $this->transformMailContent($lead_data, $acm_mail_content, $data['page_name'] = 'QCR');
$res = MailHelper::send_email(['from_mail' => $from_mail, 'mail' => $params['acm_email'], 'subject' => $subject, 'message' => $acm_mail_content, 'attachments' => $attachments, 'common' => $common]);
}
$is_placement = false;
if ($recipient_type == 'placement') {
@ -2850,8 +3045,16 @@ class LeadsController extends BaseController
'cd_amount' => $params['cd_amount'] ?? null,
'no_of_installment' => $params['no_of_installment'] ?? null,
'is_installment' => $params['is_installment'] ?? null,
'is_installment' => $params['is_installment'] ?? null,
'acm_id' => $params['acm_pk'] ?? null,
];
if(isset($params['tpa_id']) && !empty($params['tpa_id'])){
list($tpaBranchId, $tpaId) = explode('-', $params['tpa_id']);
$data['tpa_branch_id'] = $tpaBranchId;
$data['tpa_id'] = $tpaId;
}
$this->leadsModel->where('id', $lead_id)->set($data)->update();
if (isset($params['installments']) && !empty($params['installments'])) {
@ -3639,7 +3842,7 @@ class LeadsController extends BaseController
$this->loadLayout('view_rfq_non_eb');
}
// get lead data for edit bot EB and NON-EB
// get lead data for edit both EB and NON-EB
public function getLeadNonEB($type, $id = null)
{
// Set basic data
@ -4899,7 +5102,7 @@ class LeadsController extends BaseController
$lower_headers = array_map('strtolower', $members_heading);
foreach ($lower_headers as $index => $header) {
if (preg_match('/^sa\s*-\s*option\s*\d*$/i', $header)) {
if (preg_match('/^(sa\s*-\s*option|proposed\s+sum\s+insured)\s+\d+$/i', $header)) {
$column_name = $members_heading[$index];
$sum = 0;
@ -5166,5 +5369,182 @@ class LeadsController extends BaseController
return ['status' => true, "data" => $reminder_sended_lead];
}
public function uploadMultiFileFromRfq()
{
try {
$this->myLogger->logme('error', "uploadMultiFileFromRfq START");
$this->myLogger->logme('error', "Files received: " . json_encode($this->request->getPost() ?? []));
$lead_id = $this->request->getPost('lead_id');
$lead_form_type = $this->request->getPost('lead_form_type');
$leads_file_primary_key = $this->request->getPost('leads_file_id') ?? [];
$docs_name = $this->request->getPost('docs_name') ?? [];
$files = $this->request->getFileMultiple('file_name');
if (empty($files) || empty($docs_name)) {
$this->myLogger->logme('error', "No files or document names provided");
return $this->respond([
'status' => false,
'code' => 400,
'message' => 'No files or document names provided'
], 400);
}
// Upload process
$multi_file_data = $this->uploadMultiFiles($files, $docs_name, $leads_file_primary_key) ?? [];
$this->myLogger->logme('error', "uploadMultiFiles result: " . json_encode($multi_file_data ?? []));
if (!empty($multi_file_data)) {
$this->insertMultiFilesData($multi_file_data, $lead_id, $lead_form_type);
$this->myLogger->logme('error', "Files inserted successfully into DB");
// update lead file name if change
if(isset($multi_file_data[0]['file_name']) && !empty($multi_file_data[0]['file_name'])){
$this->leadsModel->where('id', $lead_id)->set('file_name', $multi_file_data[0]['file_name'])->update();
}
} else {
$this->myLogger->logme('error', "uploadMultiFiles returned empty");
}
// Get the updated lead file data
$lead_file_data = $this->leadFilesModel
->where('is_active', 1)
->where('lead_id', $lead_id)
->findAll();
$this->myLogger->logme('error', "Fetched " . count($lead_file_data) . " lead file records");
$document_data = $this->renderFileFields($lead_file_data);
$attch_data['multi_file_data'] = $lead_file_data;
$attachment_html = view('rfq/attachment_files', $attch_data) ?? "";
$this->myLogger->logme('error', "uploadMultiFileFromRfq END");
return $this->respond([
'status' => true,
'code' => 200,
'message' => "File uploaded Successfully",
'document_data' => $document_data,
'attachment_html' => $attachment_html,
], 200);
} catch (\Throwable $e) {
$errorDetails = [
'error_message' => $e->getMessage(),
'file' => $e->getFile(),
'line' => $e->getLine(),
'stack_trace' => $e->getTraceAsString(),
];
// Catch any error/exception and log with trace
$this->myLogger->logme('error', "Exception in uploadMultiFileFromRfq: " . json_encode($errorDetails));
return $this->respond([
'status' => false,
'code' => 500,
'message' => "File upload failed: " . $e->getMessage(),
'errorDetails' => $errorDetails,
], 500);
}
}
function renderFileFields($multi_file_data = [])
{
$uploadFilePath = WRITEPATH . 'uploads/lead_files/';
$html = '';
// If data exists (edit mode)
if (!empty($multi_file_data)) {
foreach ($multi_file_data as $index => $value) {
$sample_dwn_link = '&nbsp;[ <a href="' . base_url("util/downloadMemberFile/") . $value['file_name'] . '" data-toggle="tooltip" data-placement="top" title="Download Member List" target="_blank">Download</a> ]';
$isFirstField = ($index === 0);
$placeholder = $isFirstField ? 'First file must be Demography.' : '';
$first_file_name = $isFirstField ? 'Member List' : '';
$member_data_link = $isFirstField ? $sample_dwn_link : '';
$read_only = $isFirstField ? 'readonly' : '';
$accept = $isFirstField ? '.xls,.xlsx' : '';
$displayIndex = $index + 1;
$html .= '
<div class="form-row d-flex align-items-end" id="fileField_' . $displayIndex . '">
<input type="hidden" name="leads_file_id[]" value="' . htmlspecialchars($value['id']) . '" id="file_id_' . $displayIndex . '">
<div class="form-group col-md-5">
<label>Document Name</label>
<input type="text" class="form-control" name="docs_name[]"
placeholder="' . $placeholder . '"
value="' . htmlspecialchars(!empty($first_file_name) ? $first_file_name : $value['docs_name']) . '" id="docs_name_' . $displayIndex . '" '.$read_only.'>
</div>
<div class="form-group col-md-5">
<label>
File Upload<br>
<small id="file_name_display_' . $displayIndex . '" class="text-muted">' .
(!empty($value['file_name']) ? htmlspecialchars($value['file_name']) : 'No file chosen') .
'</small> '.$member_data_link.'
</label>
<input type="file" class="form-control" id="file_name_' . $displayIndex . '"
name="file_name[]" accept="' . $accept . '"
onchange="showFileName(this, ' . $displayIndex . ')">
</div>
<div class="col-md-2" style="position: relative; bottom: 16px;">
<button type="button" class="btn btn-danger" onclick="removeFileField(' . $displayIndex . ', ' . htmlspecialchars($value['id']) . ')">x</button>
<button type="button" class="btn btn-primary" onclick="addFileField()">+</button>
</div>
</div>';
}
} else {
// Default (add mode)
$html .= '
<div class="form-row d-flex align-items-end" id="fileField_1">
<input type="hidden" name="leads_file_id[]" value="">
<div class="form-group col-md-5">
<label>Document Name</label>
<input type="text" class="form-control" name="docs_name[]"
placeholder="First file must be Demography." id="docs_name_1">
</div>
<div class="form-group col-md-5">
<label>
File Upload<br>
<small id="file_name_display_1" class="text-muted">No file chosen</small>
</label>
<input type="file" class="form-control" id="file_name_1"
name="file_name[]" accept=".xls,.xlsx" onchange="showFileName(this, 1)">
</div>
<div class="col-md-2" style="position: relative; bottom: 16px;">
<button type="button" class="btn btn-danger" onclick="removeFileField(1, \'\')">x</button>
<button type="button" class="btn btn-primary" onclick="addFileField()">+</button>
</div>
</div>';
}
return $html;
}
public function downloadMemberFile($fileName)
{
$filePath = WRITEPATH . 'uploads/lead_files/' . $fileName;
if (!file_exists($filePath)) {
$data['message'] = 'The Physical File Not Found';
echo view('errors/404', $data);
}
// force download
return $this->response->download($filePath, null);
}
}

View File

@ -1241,7 +1241,8 @@ class PolicyTransactionController extends BaseController
$issue_type = $this->policyTransactionModel
->where('action_type', 'inception')
->where('client_id', $this->request->getPost('client_id'))
->where('client_policy_id', $this->request->getPost('client_policy_id'))
// ->where('client_policy_id', $this->request->getPost('client_policy_id'))
->where('id', $this->request->getPost('client_policy_id'))
->where('policy_transaction.is_active', 1)
->first();
@ -3054,9 +3055,28 @@ class PolicyTransactionController extends BaseController
$clientIds = array_column($clients, 'id');
$policies = $this->clientPolicyModel
// $policies = $this->clientPolicyModel
// ->select("
// client_policy.*,
// policy_type.policy_type,
// policy_type.ebp,
// policy_type.etp,
// policy_type.iep,
// policy_type.itp,
// policy_type.bap,
// policy_type.allocg,
// DATE_FORMAT(client_policy.policy_start_date, '%d/%m/%Y') as policy_start_date,
// DATE_FORMAT(client_policy.policy_end_date, '%d/%m/%Y') as policy_end_date
// ")
// ->join('policy_type', 'policy_type.id = client_policy.policy_type_id')
// ->join('policy_transaction pt', 'pt.client_policy_id = client_policy.id and pt.action_type = "inception" and pt.is_active = 1 and pt.client_policy_id is not null')
// ->whereIn('client_policy.client_id', $clientIds)
// ->where('client_policy.is_active', 1)
// ->findAll();
$policies = $this->policyTransactionModel
->select("
client_policy.*,
policy_transaction.*,
policy_type.policy_type,
policy_type.ebp,
policy_type.etp,
@ -3064,14 +3084,14 @@ class PolicyTransactionController extends BaseController
policy_type.itp,
policy_type.bap,
policy_type.allocg,
DATE_FORMAT(client_policy.policy_start_date, '%d/%m/%Y') as policy_start_date,
DATE_FORMAT(client_policy.policy_end_date, '%d/%m/%Y') as policy_end_date
DATE_FORMAT(policy_transaction.policy_start_date, '%d/%m/%Y') as policy_start_date,
DATE_FORMAT(policy_transaction.policy_end_date, '%d/%m/%Y') as policy_end_date
")
->join('policy_type', 'policy_type.id = client_policy.policy_type_id')
->join('policy_transaction pt', 'pt.client_policy_id = client_policy.id and pt.action_type = "inception" and pt.is_active = 1 and pt.client_policy_id is not null')
->whereIn('client_policy.client_id', $clientIds)
->where('client_policy.is_active', 1)
->findAll();
->join('policy_type', 'policy_type.id = policy_transaction.policy_type_id')
->whereIn('policy_transaction.client_id', $clientIds)
->where('policy_transaction.is_active', 1)
->where('policy_transaction.action_type', "inception")
->findAll();
foreach ($policies as $policy) {
$policyList[$policy['client_branch_id']][] = $policy;

View File

@ -1460,7 +1460,7 @@
<?php } ?>
<!-- Masters -->
<?php if (get_role_id() == 1 || get_role_id() == 5) { ?>
<?php if (get_role_id() == 1 || get_role_id() == 5 || get_role_id() == 4) { ?>
<li>
<a href="#sidebarDashboards" data-toggle="collapse" class=" img-inactive-not-working">
@ -1470,27 +1470,39 @@
</a>
<div class="collapse" id="sidebarDashboards">
<ul class="nav-second-level">
<li>
<a href="<?= base_url('/master/insurer/list') ?>">Insurer</a>
</li>
<li>
<a href="<?= base_url('/master/tpa/list') ?>">TPA</a>
</li>
<li>
<a href="<?= base_url('/master/kyc/list') ?>">KYC</a>
</li>
<li>
<a href="<?= base_url('/master/policy/list') ?>">Policy</a>
</li>
<li>
<a href="<?= base_url('/master/cash_deposite/list') ?>">CD Master</a>
</li>
<li>
<a href="<?= base_url('/master/vehicle/list') ?>">Vehicle Master</a>
</li>
<li>
<a href="<?= base_url('/user/list') ?>"> Users </a>
</li>
<?php if (get_role_id() == 1 || get_role_id() == 5 || ( get_role_id() == 4 && (in_array(BUSINESS_SUPPORT_TEAM_ID, user_team()) || in_array(SALES_TEAM_ID, user_team())))) { ?>
<li>
<a href="<?= base_url('/master/insurer/list') ?>">Insurer</a>
</li>
<?php } ?>
<?php if (get_role_id() == 1 || get_role_id() == 5) { ?>
<li>
<a href="<?= base_url('/master/tpa/list') ?>">TPA</a>
</li>
<li>
<a href="<?= base_url('/master/kyc/list') ?>">KYC</a>
</li>
<li>
<a href="<?= base_url('/master/policy/list') ?>">Policy</a>
</li>
<li>
<a href="<?= base_url('/master/cash_deposite/list') ?>">CD Master</a>
</li>
<li>
<a href="<?= base_url('/master/vehicle/list') ?>">Vehicle Master</a>
</li>
<li>
<a href="<?= base_url('/user/list') ?>"> Users </a>
</li>
<?php } ?>
</ul>
</div>
</li>

View File

@ -238,17 +238,19 @@ if (isset($selected_lead_type)) {
}));
$.each(data, function(index, item) {
var option = $('<option>', {
value: item.id,
text: item.client_name,
'data-cn': item.client_name,
'data-csn': item.short_name,
'data-ct': item.client_type,
'data-cet': item.entity_type_id,
class: (item.client_type == 1) ? 'group' : (item.client_type == 2) ? 'individual' : ''
});
if(item.client_type == 1){
var option = $('<option>', {
value: item.id,
text: item.client_name,
'data-cn': item.client_name,
'data-csn': item.short_name,
'data-ct': item.client_type,
'data-cet': item.entity_type_id,
class: (item.client_type == 1) ? 'group' : (item.client_type == 2) ? 'individual' : ''
});
$('#client_id').append(option);
$('#client_id').append(option);
}
});
}

View File

@ -339,6 +339,7 @@
<?php } ?>
<button id="submitPlacement" class="btn btn-primary" onclick="checkTheTableDataChanged(6)">Placement</button>
<button id="viewDemography" class="btn btn-primary" onclick="viewDemography()">Demography</button>
<button id="viewDocs" class="btn btn-primary" onclick="viewDocs()">Docs</button>
<input type="hidden" id="lead_id" name="lead_id" value="<?= isset($lead_id) ? $lead_id : '' ?>">
<input type="hidden" id="rfq_primaryKey" name="rfq_primaryKey" value="<?= isset($rfq_data['id']) ? $rfq_data['id'] : '' ?>">
<input type="hidden" id="qcr_count" value="<?= isset($qcr_count) ? $qcr_count : 0 ?>">
@ -492,7 +493,7 @@
<hr>
<div class="form-group" id="insurer_or_clinet_mail_attachment">
<div class="form-row" >
<div class="form-row attachmet_row">
<?php echo isset($attachment_html) && !empty($attachment_html) ? $attachment_html : ''; ?>
</div>
</div>
@ -565,7 +566,7 @@
<hr>
<div class="form-group" id="internal_mail_attachment">
<div class="form-row" >
<div class="form-row attachmet_row">
<?php echo isset($attachment_html) && !empty($attachment_html) ? $attachment_html : ''; ?>
</div>
</div>
@ -600,6 +601,22 @@
<div class="form-row">
<div class="form-group col-md-3">
<label for="tpa">TPA <span class="text-danger"></span></label>
<select class="form-control" id="tpa_id" name="tpa">
<option value="">Select TPA</option>
<?php if (isset($tpa_list)) {
$tpa_id = isset($lead_data['tpa_id']) ? $lead_data['tpa_id'] : "";
$tpa_branch_id = isset($lead_data['tpa_branch_id']) ? $lead_data['tpa_branch_id'] : "";
foreach ($tpa_list as $value) { ?>
<option value="<?= $value['id'] . '-' . $value['tpa_id'] ?>"
<?= ($tpa_id == $value['tpa_id'] && $tpa_branch_id == $value['id']) ? 'selected' : '' ?>>
<?= $value['tpa_short_name'] . '-' . $value['branch_code'] ?>
</option>
<?php } } ?>
</select>
</div>
<div class="form-group col-md-3">
<label for="policy_start_date">Policy Start Date</label>
<input type="text" class="form-control" id="policy_start_date" name="policy_start_date" placeholder="DD/MM/YYY" value="<?= isset($lead_data['policy_start_date']) ? date('d-m-Y', strtotime($lead_data['policy_start_date'])) : "" ?>">
@ -617,15 +634,15 @@
<div class="form-group col-md-3">
<label for="is_cd_switch">CD Entry</label>
<input id="is_cd_switch" type="checkbox" name = "is_cd" value = "1" data-toggle="toggle" data-on="With CD" data-off="Without CD" data-onstyle="info" data-offstyle="primary" data-style="border" data-width="218" <?= isset($lead_data['is_cd']) && $lead_data['is_cd'] != 1 ? '' : 'checked' ?>>
<input id="is_cd_switch" type="checkbox" name = "is_cd" value = "1" data-toggle="toggle" data-on="With CD" data-off="Without CD" data-onstyle="info" data-offstyle="primary" data-style="border" data-width="219" <?= isset($lead_data['is_cd']) && $lead_data['is_cd'] != 1 ? '' : 'checked' ?>>
</div>
<div class="form-group col-md-3">
<label for="premium_amount">Premium Amount</label>
<label for="premium_amount">Pre Amount include GST</label>
<input type="text" class="form-control" id="premium_amount" name="premium_amount" placeholder="Enter Premium Amount" value="<?= isset($lead_data['premium_amount']) ? $lead_data['premium_amount'] : "" ?>">
</div>
<?php if (isset($lead_data['is_cd']) && $lead_data['is_cd'] == 1 || !isset($lead_data['is_cd'])) { ?>
<?php if (isset($lead_data['is_cd']) && $lead_data['is_cd'] == 1 || !isset($lead_data['is_cd']) || $lead_data['is_cd'] == null) { ?>
<div class="form-group col-md-3">
<label for="cd_amount">CD Amount</label>
@ -706,6 +723,22 @@
</select>
</div>
<div class="form-group col-md-6">
<label for="acm_id">Account Manager</label>
<select class="form-control" id="acm_id" name="acm_id" required>
<option value="">Select Account Manager Mail</option>
<?php if (isset($account_manager)) { ?>
<?= $acm_id = isset($lead_data['acm_id']) ? $lead_data['acm_id'] : ""; ?>
<?php foreach ($account_manager as $user) { ?>
<option value="<?= $user['email'];?>" data-id="<?= $user['id'] ?>"
<?= ($acm_id == $user['id']) ? 'selected' : '' ?>>
<?= $user['first_name'].' - '.$user['email'];?>
</option>
<?php } ?>
<?php } ?>
</select>
</div>
<div class="form-group col-md-12">
<label for="subject">Subject</label>
<input type="text" class="form-control" id="placement_subject" name="placement_subject" value="<?= isset($placement_subject) ? $placement_subject : " " ?>" placeholder="Enter Subject">
@ -727,7 +760,7 @@
<hr>
<div class="form-group" id="placement_mail_attachment">
<div class="form-row" >
<div class="form-row attachmet_row" >
<?php echo isset($attachment_html) && !empty($attachment_html) ? $attachment_html : ''; ?>
</div>
</div>
@ -741,7 +774,7 @@
</div>
</div><!-- /.modal -->
<!-- Modal content for View Demography Mail -->
<!-- Modal content for View Demography Modal -->
<div class="modal fade" id="view_demography_modal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
aria-hidden="false">
<div class="modal-dialog modal-full-width">
@ -765,6 +798,31 @@
</div>
</div><!-- /.modal -->
<!-- Modal content for Other Docs Upload Modal -->
<div class="modal fade" id="other_docs_upload_modal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
aria-hidden="false">
<div class="modal-dialog modal-full-width">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="docsCenterModalLabel">Documents</h4>
<button type="button" id="close_btn" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<form id="multiFileForm" enctype="multipart/form-data">
<input type="hidden" name="lead_id" value="<?= isset($lead_id) ? $lead_id : '' ?>">
<input type="hidden" name="lead_form_type" value="1">
<div id="multiFileAppendArea">
<?php echo isset($multi_file_data_html) && !empty($multi_file_data_html) ? $multi_file_data_html : ''; ?>
</div>
<div class="form-group text-right m-b-0 mt-3">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
</div><!-- /.modal-content -->
</div>
</div><!-- /.modal -->
<script>
var isFormDataModified = false;
@ -948,6 +1006,8 @@
placeholder: 'Select CC Mail',
});
$('#acm_id').select2();
$('#proposals').select2({
placeholder: 'Select proposal',
});
@ -1031,6 +1091,11 @@ $(document).ready(function () {
} else {
console.log("Lead status is 'won', submitData will not be called");
}
<?php if (!isset($multi_file_data_html) || empty($multi_file_data_html)) : ?>
addFileField();
<?php endif; ?>
});
function startInterval() {
@ -3964,8 +4029,10 @@ function constructURL_ForPlacementMailSend() {
let insurer_and_branch = $('#proposals').val();
let cc = $('#placement_cc').val();
let no_of_installment = $('#no_of_installment').val();
let tpa_id = $('#tpa_id').val();
let acm_email = $('#acm_id').val();
let acm_pk = $('#acm_id option:selected').data('id');
let is_installment = $("#is_installment_switch").is(":checked") ? 1 : 0;
console.log("cc1", cc);
// Process `to` field
to = to.split(',').map(email => email.trim());
@ -4025,6 +4092,9 @@ function constructURL_ForPlacementMailSend() {
formData.append('installments', JSON.stringify(data));
formData.append('no_of_installment', no_of_installment);
formData.append('is_installment', is_installment);
formData.append('tpa_id', tpa_id);
formData.append('acm_email', acm_email);
formData.append('acm_pk', acm_pk);
ajaxRequest(formData);
@ -6805,6 +6875,12 @@ function appendMultiFileData(data) {
const myModal = new bootstrap.Modal(document.getElementById('view_demography_modal'));
myModal.show();
}
function viewDocs(){
// Show the modal
const myModal = new bootstrap.Modal(document.getElementById('other_docs_upload_modal'));
myModal.show();
}
</script>
@ -6819,4 +6895,178 @@ function appendMultiFileData(data) {
}, 2000);
}
</script>
<script>
let fileIndex = 1;
function addFileField() {
console.log('addFileField function called');
const container = document.getElementById('multiFileAppendArea');
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' : '';
if(isFirstField == 1){
placeholder = '';
accept = '';
}
let sample_dwn_link = "";
if(isFirstField == 1){
sample_dwn_link = '&nbsp;[ <a href="<?= base_url("util/download-excel/member_data"); ?>" id="excel_download" data-toggle="tooltip" data-placement="top" title="Download Sample Excel">Sample Excel</a> ]';
}
div.innerHTML = `
<div class="form-group col-md-5">
<label>Document Name ${sample_dwn_link}<span class="text-danger"></span></label>
<input type="text" class="form-control" name="docs_name[]" placeholder="${placeholder}">
</div>
<div class="form-group col-md-5">
<label>File Upload<span class="text-danger"></span></label>
<input type="file" class="form-control" id="file_name_${fileIndex}" name="file_name[]" accept="${accept}">
</div>
<div class="col-md-2" style="position: relative; bottom: 16px;">
<button type="button" class="btn btn-danger" onclick="removeFileField(${fileIndex})">x</button>
<button type="button" class="btn btn-primary" onclick="addFileField()">+</button>
</div>
`;
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 = '<?= base_url('util/removeMultiFile') ?>';
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";
}
}
// Submit form
$("#multiFileForm").on("submit", function (e) {
e.preventDefault();
let formData = new FormData(this);
// Show loader
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
$.ajax({
url: "<?= base_url('util/uploadMultiFileFromRfq'); ?>",
type: "POST",
data: formData,
contentType: false,
processData: false,
success: function (res) {
console.log('uploadMultiFileFromRfq reponse', res);
if(res.status == true){
toastr.success(res.message, 'SUCCESS');
$('#multiFileAppendArea').empty();
$('.attachmet_row').empty();
$('#multiFileAppendArea').append(res.document_data);
$('.attachmet_row').html(res.attachment_html);
}else{
toastr.warning(res.message, 'WARNING');
}
// Hide loader
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
$('.close').click();
},
error: function (xhr) {
console.error("Upload error:", xhr.responseText);
}
});
});
</script>

Binary file not shown.