diff --git a/app/Config/Routes.php b/app/Config/Routes.php
index 655da7e1..45f70e25 100755
--- a/app/Config/Routes.php
+++ b/app/Config/Routes.php
@@ -330,6 +330,7 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) {
$routes->get('getCoShareStatementDetails/(:any)', 'PolicyTransactionController::getCoShareStatementDetails/$1');
$routes->get('getClientPolicyDataBasedOnClientAndInsuer', 'PolicyTransactionController::getClientPolicyDataBasedOnClientAndInsuer');
$routes->get('checkCDAmountForBasePremium', 'PolicyTransactionController::checkCDAmountForBasePremium');
+ $routes->get('transformMailContent', 'LeadsController::transformMailContent');
});
$routes->group("policy_tranction", ["filter" => "authMVC"], function ($routes) {
@@ -377,6 +378,7 @@ $routes->group("leads", ["filter" => "authMVC"], function ($routes) {
$routes->post("create", "LeadsController::createLead");
$routes->get("list/(:any)", "LeadsController::getLeadDataForEdit/$1");
$routes->get("sendMail", "LeadsController::sendMailWithAttachement");
+ $routes->post("sendMail", "LeadsController::sendMailWithAttachement");
$routes->get("exportQCRandRFQ/(:any)", "LeadsController::exportQCRandRFQ/$1");
$routes->get("featchLeadDataAndInsertClient/(:any)", "LeadsController::featchLeadDataAndInsertClient/$1");
$routes->get("featchClientPolicyFromLead/(:any)", "LeadsController::featchClientPolicyFromLead/$1");
diff --git a/app/Controllers/EmpDataServiceController.php b/app/Controllers/EmpDataServiceController.php
index 78baac0b..5c79e589 100755
--- a/app/Controllers/EmpDataServiceController.php
+++ b/app/Controllers/EmpDataServiceController.php
@@ -205,9 +205,6 @@ class EmpDataServiceController extends BaseController
// Log the export file name
$this->myLogger->logme('error', 'Inception export file name : {data}', ['data' => $export_data['file_name']]);
- // remove existing batch file anf batch list data every time export
- $this->removeOldExportInfoFromBatchFile($export_data);
-
// default excel header information
$excel_header_columns = [
[
@@ -258,7 +255,7 @@ class EmpDataServiceController extends BaseController
[
'column_index' => 7,
'column_name' => 'DATE OF COVERAGE',
- 'db_column_name' => 'date_coverage'
+ 'db_column_name' => 'date_of_coverage'
],
[
'column_index' => 8,
@@ -368,7 +365,7 @@ class EmpDataServiceController extends BaseController
[
'column_index' => 7,
'column_name' => 'DATE OF COVERAGE',
- 'db_column_name' => 'date_coverage'
+ 'db_column_name' => 'date_of_coverage'
],
[
'column_index' => 8,
@@ -428,14 +425,35 @@ class EmpDataServiceController extends BaseController
];
}else{
// get excel export format structure array
- $template_json = $this->clientPolicyModel
- ->select('insurer_excel_export_template.jsoncolumns')
- ->join('insurer_excel_export_template', 'insurer_excel_export_template.insurer_id = client_policy.insurer_id and insurer_excel_export_template.policy_type_id = client_policy.policy_type_id')
- ->where('client_policy.id', $export_data['client_policy_id'])
- ->where('insurer_excel_export_template.event_name', $export_data['event_type'])
- ->where('insurer_excel_export_template.is_active', 1) //Live issue changes 17-10-2024
- ->where('insurer_excel_export_template.type_name', $export_data['actions'])
- ->first();
+ // $template_json = $this->clientPolicyModel
+ // ->select('insurer_excel_export_template.jsoncolumns')
+ // ->join('insurer_excel_export_template', 'insurer_excel_export_template.insurer_id = client_policy.insurer_id and insurer_excel_export_template.policy_type_id = client_policy.policy_type_id')
+ // ->where('client_policy.id', $export_data['client_policy_id'])
+ // ->where('insurer_excel_export_template.event_name', $export_data['event_type'])
+ // ->where('insurer_excel_export_template.is_active', 1) //Live issue changes 17-10-2024
+ // ->where('insurer_excel_export_template.type_name', $export_data['actions'])
+ // ->first();
+
+ $sql = "
+ SELECT `insurer_excel_export_template`.`jsoncolumns`
+ FROM `client_policy`
+ JOIN `insurer_excel_export_template`
+ ON `insurer_excel_export_template`.`insurer_id` = `client_policy`.`insurer_id`
+ AND `insurer_excel_export_template`.`policy_type_id` =
+ CASE
+ WHEN `client_policy`.`policy_type_id` IN (2, 3, 4, 5) THEN 2
+ ELSE `client_policy`.`policy_type_id`
+ END
+ WHERE `client_policy`.`id` = '".$export_data['client_policy_id']."'
+ AND `insurer_excel_export_template`.`event_name` = '".$export_data['event_type']."'
+ AND `insurer_excel_export_template`.`is_active` = 1
+ AND `insurer_excel_export_template`.`type_name` = '".$export_data['actions']."'
+ LIMIT 1";
+
+ $query = db_connect()->query($sql);
+ $template_json = $query->getRowArray();
+
+ // dd(db_connect()->getLastQuery());
if(!empty($template_json) && $template_json != null){
$excel_header_columns = json_decode($template_json['jsoncolumns'], true);
@@ -444,6 +462,10 @@ class EmpDataServiceController extends BaseController
}
}
+ // remove existing batch file anf batch list data every time export
+ $this->removeOldExportInfoFromBatchFile($export_data);
+
+ //convert the excel data based on the insurer
$excel_data_info = generate_insurer_based_excel($excel_header_columns, $objects);
// Generate Excel file
@@ -1343,7 +1365,7 @@ class EmpDataServiceController extends BaseController
// employees.gender AS emp_gender,
// employee_polices.pre_existing_alignments,
// employee_polices.basic_cover_si,
- // employee_polices.date_coverage,
+ // employee_polices.date_of_coverage,
// TIMESTAMPDIFF(YEAR, employees.dob, CURDATE()) AS emp_age,
// employees.relationship AS emp_relationship,
// employees.change_event AS change_event,
@@ -1954,12 +1976,14 @@ class EmpDataServiceController extends BaseController
->where("employees.is_active", 1)
->where("employees.emp_status", "active")
->where("emp_endorsement.actions", "c")
+ ->where("emp_endorsement.is_active", 1)
+ ->where("emp_endorsement.status !=", "truncated")
->where("(emp_endorsement.endorsement_id IS NULL OR emp_endorsement.endorsement_id = '')")
->findAll();
- // dd($endorsement_data, $excel_data);
+ dd($endorsement_data, $excel_data);
if ($endorsement_data == null || empty($endorsement_data)) {
@@ -2253,6 +2277,8 @@ class EmpDataServiceController extends BaseController
->where('employee_polices.status', 'active')
->where('employees.is_active', 1)
->where('employees.emp_status', 'active')
+ ->where("emp_endorsement.is_active", 1)
+ ->where("emp_endorsement.status !=", "truncated")
->first();
if (isset($result['id']) && $result['id'] !== null) {
diff --git a/app/Controllers/LeadsController.php b/app/Controllers/LeadsController.php
index b8d47cce..ea15cb12 100644
--- a/app/Controllers/LeadsController.php
+++ b/app/Controllers/LeadsController.php
@@ -32,6 +32,9 @@ use App\Helpers\ExcelMergeHelper;
use Google\Service\CloudSearch\PushItem;
use Kint;
+use App\Controllers\Jobs;
+use App\Controllers\JobWorker;
+
class LeadsController extends BaseController
{
@@ -98,7 +101,7 @@ class LeadsController extends BaseController
{
// $d = $this->constructExcelToSaveTemp(24, 1, $propsal_and_insurer = null);
- $job_details = new Jobs();
+ // $job_details = new Jobs();
// $r = Jobs::addJob(['job_name' => 'calculateMembersDemography', 'payload' => ['lead_id' => 24]]);
// $d = $this->calculateMembersDemography(['lead_id' => 24]);
//$this->mergeQuoteExcelFileWithMembersListExcelFile(24, 1, $propsal_and_insurer = null);
@@ -323,6 +326,12 @@ class LeadsController extends BaseController
$insert = $this->leadsModel->insert($value);
$insertCount[] = $insert;
$this->insertLeadStatus($insert, $value['status'], 3);
+
+ //for this push the job to the calculateMembersDemography() function
+ $job_details = new Jobs();
+ $r = Jobs::addJob(['job_name' => 'calculateMembersDemography', 'payload' => [
+ 'lead_id' => $insert,
+ ]]);
}
if (count($insertCount) > 0) {
@@ -423,11 +432,13 @@ class LeadsController extends BaseController
}
$data['question_json'] = $lead_data['question_json'];
- $data['page_name'] = isset($data['rfq_data']['type']) && $data['rfq_data']['type'] == 2 ? 'QCR' : 'RFQ';
+ $data['page_name'] = $type == 2 ? 'QCR' : 'RFQ';
$data['insurer'] = $this->insurerBranchModel->getInsurerBranchesWithInsurerNames();
$data['userList'] = $this->userModel->getUserListForRFQ();
$data['lead_data'] = $lead_data;
+ $data['mail_content'] = $this->transformMailContent($id);
+
// dd($data);
$this->loadLayout('view_rfq.php', $data);
}
@@ -449,7 +460,10 @@ class LeadsController extends BaseController
$result = $this->RFQModel->insert($data);
if ($result) {
- return $this->respond(['status' => true, 'id' => $result, 'message' => 'RFQ created successfully', 'data' => $data], 200);
+
+ $message = "RFQ submitted successfully";
+ if($data['submit_type'] == 'QCR'){ $message = "QCR submitted successfully"; }
+ return $this->respond(['status' => true, 'id' => $result, 'message' => $message, 'data' => $data], 200);
}
return $this->respond(['status' => false, 'id' => $result, 'message' => "Failed to create RFQ", 'data' => $data], 200);
@@ -492,6 +506,29 @@ class LeadsController extends BaseController
public function exportExcelForQCRandRFQ($lead_id, $type)
{
$filepath = $this->constructExcelToSaveTemp($lead_id, $type);
+ $lead_data = $this->RFQModel->getRFQTableDataWithLeadIDAndType($lead_id, $type);
+ // dd($filepath);
+
+ //Excel merging part
+ if ($lead_data['file_name'] != null && $lead_data['file_name'] != '') {
+
+ $temp_file_path = $filepath['filePath'];
+ $temp_file_name = $filepath['fileName'];
+ $lead_file_path = WRITEPATH . 'uploads/lead_files/' . $lead_data['file_name'];
+
+ // dd($lead_data, $temp_file_path, $temp_file_name, $lead_file_path);
+
+ if ($lead_file_path) {
+ $filePaths = [
+ ['file_path' => $temp_file_path, 'sheets' => []],
+ ['file_path' => $lead_file_path, 'sheets' => []]
+ ];
+ // $outputPath = dirname($temp_file_path) . '/' . 'merged_' . $temp_file_name;
+ $result = ExcelMergeHelper::mergeExcelFiles($filePaths, $temp_file_path);
+ // print_rr($result);
+ }
+ }
+
$filepath = $filepath['filePath'];
if (file_exists($filepath)) {
@@ -522,11 +559,51 @@ class LeadsController extends BaseController
// dd($rfq_data, $lead_id, $type, $propsal_and_insurer);
// print_r($propsal_and_insurer); die;
- $lead_data = [
- 'Insured' => $rfq_data['client_name'],
- 'Insurer' => $rfq_data['insurer_name'] . ' - ' . $rfq_data['insurer_branch_name'],
- 'TPA' => $rfq_data['tpa_name'] . ' - ' . $rfq_data['tpa_branch_name'],
- ];
+ if($rfq_data['lead_type'] == 1){
+
+ $lead_data = [
+
+ 'Insured' => $rfq_data['client_name'],
+ 'Policy Status' => $rfq_data['status'],
+
+ 'No of Employees' => $rfq_data['incept_emp_count'],
+ 'No of Dependents' => $rfq_data['incept_dept_count'],
+ 'Total Lives' => $rfq_data['incept_no_of_lives'],
+
+ 'Period of Insurance ' => date('d/m/Y', strtotime($rfq_data['policy_start_date'])).' to '. date('d/m/Y', strtotime($rfq_data['policy_end_date'])),
+ 'Policy Run Days' => $rfq_data['policy_run_days'],
+ ];
+
+ }else{
+
+ $lead_data = [
+
+ 'Insured' => $rfq_data['client_name'],
+ 'Policy Status' => $rfq_data['status'],
+
+ '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 Renewal' => $rfq_data['renewal_emp_count'],
+ 'No of Dependents at Renewal' => $rfq_data['renewal_dept_count'],
+ 'Total Lives at Renewal ' => $rfq_data['renewal_no_of_lives'],
+
+ 'Period of Insurance ' => date('d/m/Y', strtotime($rfq_data['policy_start_date'])).' to '. date('d/m/Y', strtotime($rfq_data['policy_end_date'])),
+ 'Policy Run Days' => $rfq_data['policy_run_days'],
+ 'Inception Premium' => $rfq_data['premium_at_inception'],
+ 'Premium as on (Date - DD MM YYYY should be entered based on the claims dump report)' => $rfq_data['premium_date'],
+ 'Earned Premium' => $rfq_data['earned_premium'],
+ 'Incurred Claims as on (Date - DD MM YYYY should be entered based on the claims dump report)' => $rfq_data['incurred_claims_date'],
+ 'Annualised Claims' => $rfq_data['annualised_claims'],
+ 'Incurred Claims Ratio' => $rfq_data['incurred_claims_ratio'],
+ 'Earned Claims Ratio' => $rfq_data['earned_claims_ratio'],
+ ];
+ }
$data = json_decode($rfq_data['json'], true);
@@ -538,6 +615,7 @@ class LeadsController extends BaseController
}
}else if($type == 1){
$data = $this->convertJsonForQCR($data, $type);
+ // dd($data);
}
$spreadsheet = new Spreadsheet();
@@ -1135,14 +1213,18 @@ class LeadsController extends BaseController
helper('excel_util_helper');
helper('MailHelper');
helper('ExcelMergeHelper');
- $params = $this->request->getGet();
+ $params = $this->request->getPost();
+
// print_r($params); die;
+
$lead_id = $params['lead_id'];
$file_type = $params['file_type']; //rfq or qcr
$recipient_type = $params['recipient_type']; //insurer or client or internal or placement
$recipient_mail = $params['recipient_mail']; // - only primary key of contacts
$recipient_mail = json_decode($params['recipient_mail'], true); // - only primary key of contacts
$propsal_and_insurer = isset($params['proposal_insurer']) ? $params['proposal_insurer'] : null;
+ $mail_content = $params['mail_content'];
+ $mail_subject = $params['subject'];
$result_data = [];
// dd($recipient_mail);
@@ -1161,9 +1243,10 @@ class LeadsController extends BaseController
// print_r($lead_data ); die;
$cc_mails = [];
+ $bcc_mails = [];
//get CC Mails
- if ($recipient_type == 'internal' || $recipient_type == 'placement') {
+ if ($recipient_type == 'internal' || $recipient_type == 'placement' || $recipient_type == 'insurer' || $recipient_type == 'client') {
$cc_data = isset($params['cc']) ? $params['cc'] : "";
$param_cc_mail = json_decode($cc_data, true);
@@ -1193,6 +1276,37 @@ class LeadsController extends BaseController
}
}
+ //get BCC Mails
+ if ($recipient_type == 'insurer' || $recipient_type == 'client') {
+
+ $bcc_data = isset($params['bcc']) ? $params['bcc'] : "";
+ $param_bcc_mail = json_decode($bcc_data, true);
+
+ if (isset($param_bcc_mail) && is_array($param_bcc_mail) && count($param_bcc_mail) > 0) {
+ // Fetch user data where ID is in the param_cc_mail array
+ $userData = $this->userModel
+ ->where('is_active', 1)
+ ->whereIn('id', $param_bcc_mail)
+ ->findAll();
+
+ // print_r($userData); die;
+
+ // Extract emails from the fetched user data
+ $bcc_mails = array_column($userData, 'email');
+
+ // print_r(json_encode($cc_mails)); die;
+
+ // If no emails were found, return an error response
+ // if (empty($cc_mails)) {
+ // return $this->respond(['status' => 'failed','code' => 400,'data' => '','message' => 'No valid CC mail addresses found!'], 200);
+ // }
+
+ } else {
+ // Handle case where param_cc_mail is not valid
+ // return $this->respond(['status' => 'failed','code' => 400,'data' => '','message' => 'CC mail not found!'], 200);
+ }
+ }
+
if ($recipient_type == 'client' && ($lead_data['contact_person_email'] == '' || $lead_data['contact_person_email'] == null)) {
return $this->respond(['status' => 'failed', 'code' => 400, 'data' => '', 'messgae' => 'Recipient mail not found ! '], 200);
}
@@ -1248,6 +1362,18 @@ class LeadsController extends BaseController
$subject = $file_type == 'rfq' ? 'Request for Quotation from ' . $lead_data['client_name'] . ' for ' . $lead_data['policy_type'] : 'Quotation Comparison Report for ' . $lead_data['policy_type'];
$original_message = '
Request for Quotation (RFQ)
Dear {{RECIPIENT_NAME}},
We are reaching out to request a quotation for the following insurance coverage. Please review the details below and provide your quote at your earliest convenience.
RFQ Details
Client name
{{CLIENT_NAME}}
Coverage Type
{{POLICY_LONG_NAME}}
Policy Start Date
{{POLICY_START_DATE}}
Policy Duration
{{DURATION}}
Please note: Additional terms and details are included in the attachment for your reference.
Please feel free to reach out if you require any further information to prepare the quote. We look forward to receiving your proposal.
';
+ //for mail content
+ if(!empty($mail_content)){
+ $original_message = $mail_content;
+ }
+
+ //for mail subject
+ if(!empty($mail_subject)){
+ $subject = $mail_subject;
+ }
+
+ // print_r($subject); die;
+
if ($recipient_data) {
foreach ($recipient_data as $recipient) {
@@ -1260,7 +1386,7 @@ class LeadsController extends BaseController
// print_rr($message);calculate_days_bw_dates
- $res = MailHelper::send_email(['mail' => $recipient['email'], 'cc' => $cc_mails, 'subject' => $subject, 'message' => $message, 'attachments' => $attachments, 'reply_to' => $reply_to]);
+ $res = MailHelper::send_email(['mail' => $recipient['email'], 'cc' => $cc_mails, 'subject' => $subject, 'message' => $message, 'attachments' => $attachments, 'reply_to' => $reply_to, 'bcc' => $bcc_mails]);
// !dd($res);
$result_data[] = ['mail' => $recipient['email'], 'status' => $res];
}
@@ -1434,83 +1560,126 @@ class LeadsController extends BaseController
public function convertJsonForQCR($json, $type)
{
if ($json) {
+
// Deep copy of JSON
$first_json = json_decode(json_encode($json), true);
-
// dd($first_json);
- // Column-wise Check: Remove headers and relevant data if qcr == 0
- foreach ($json['proposal_data']['over_all_column_data'] as $proposalKey => $proposalData) {
+ if($type == 2){
- if ($proposalData['stc'] == 0 || $proposalData['stc'] === false) {
- // Remove matching parentHeader in headers
- foreach ($first_json['table_data']['headers'] as $index => $header) {
- if ($header['parentHeader'] === $proposalKey) {
- unset($first_json['table_data']['headers'][$index]);
- }
- }
+ // Column-wise Check: Remove headers and relevant data if qcr == 0
+ foreach ($json['proposal_data']['over_all_column_data'] as $proposalKey => $proposalData) {
- // Remove data entries with matching parentth
- foreach ($first_json['table_data']['data'] as &$item) {
- $item['data'] = array_values(array_filter($item['data'], function ($entry) use ($proposalKey) {
- return $entry['parentth'] !== $proposalKey;
- }));
- }
+ if (($proposalData['qcr'] == 0 || $proposalData['qcr'] === false) || ($proposalData['stc'] == 0 || $proposalData['stc'] === false)) {
- // Remove proposalKey from over_all_column_data
- unset($first_json['proposal_data']['over_all_column_data'][$proposalKey]);
-
- if($type == 2){
- // Remove proposalKey from premium_data
- unset($first_json['premium_data']['data'][$proposalKey]);
- }
- }
-
- // Insurer Check: Remove subHeaders and relevant data for insurers with qcr == 0
- foreach ($proposalData['insurers'] as $insurerIndex => $insurer) {
- if ($insurer['stc'] === 0 || $insurer['stc'] === false) {
- foreach ($first_json['table_data']['headers'] as &$header) {
- if (isset($header['subHeaders'])) {
- $header['subHeaders'] = array_values(array_filter($header['subHeaders'], function ($sub) use ($insurer) {
- return $sub !== $insurer['display_name'];
- }));
+ // Remove matching parentHeader in headers
+ foreach ($first_json['table_data']['headers'] as $index => $header) {
+ if ($header['parentHeader'] === $proposalKey) {
+ unset($first_json['table_data']['headers'][$index]);
}
}
-
+ // Remove data entries with matching parentth
foreach ($first_json['table_data']['data'] as &$item) {
- $item['data'] = array_values(array_filter($item['data'], function ($entry) use ($insurer) {
- return $entry['subth'] !== $insurer['display_name'];
+ $item['data'] = array_values(array_filter($item['data'], function ($entry) use ($proposalKey) {
+ return $entry['parentth'] !== $proposalKey;
}));
}
- // Remove insurer from proposal's insurers array
- unset($first_json['proposal_data']['over_all_column_data'][$proposalKey]['insurers'][$insurerIndex]);
-
+ // Remove proposalKey from over_all_column_data
+ unset($first_json['proposal_data']['over_all_column_data'][$proposalKey]);
+
if($type == 2){
- unset($first_json['premium_data']['data'][$proposalKey][$insurer['display_name']]);
+ // Remove proposalKey from premium_data
+ unset($first_json['premium_data']['data'][$proposalKey]);
+ }
+ }
+
+ // Insurer Check: Remove subHeaders and relevant data for insurers with qcr == 0
+ foreach ($proposalData['insurers'] as $insurerIndex => $insurer) {
+ if (($insurer['qcr'] === 0 || $insurer['qcr'] === false) || ($insurer['stc'] === 0 || $insurer['stc'] === false) ) {
+ foreach ($first_json['table_data']['headers'] as &$header) {
+ if (isset($header['subHeaders'])) {
+ $header['subHeaders'] = array_values(array_filter($header['subHeaders'], function ($sub) use ($insurer) {
+ return $sub !== $insurer['display_name'];
+ }));
+ }
+ }
+
+
+ foreach ($first_json['table_data']['data'] as &$item) {
+ $item['data'] = array_values(array_filter($item['data'], function ($entry) use ($insurer) {
+ return $entry['subth'] !== $insurer['display_name'];
+ }));
+ }
+
+ // Remove insurer from proposal's insurers array
+ unset($first_json['proposal_data']['over_all_column_data'][$proposalKey]['insurers'][$insurerIndex]);
+
+ if($type == 2){
+ unset($first_json['premium_data']['data'][$proposalKey][$insurer['display_name']]);
+ }
}
}
}
- }
- // Row-wise Check: Remove rows if qcr == 0 for actions
- foreach ($first_json['table_data']['data'] as $rowKey => $rowData) {
- foreach ($rowData['data'] as $data) {
- if ($data['parentth'] === "Action" && isset($data['input_value']['stc']) && $data['input_value']['stc'] == 0) {
- unset($first_json['table_data']['data'][$rowKey]);
- break;
+ // Row-wise Check: Remove rows if qcr == 0 for actions
+ foreach ($first_json['table_data']['data'] as $rowKey => $rowData) {
+ foreach ($rowData['data'] as $data) {
+ if ($data['parentth'] === "Action" && (isset($data['input_value']['qcr']) && $data['input_value']['qcr'] == 0) || (isset($data['input_value']['stc']) && $data['input_value']['stc'] == 0)) {
+ unset($first_json['table_data']['data'][$rowKey]);
+ break;
+ }
}
}
- }
- // Reindex arrays to maintain proper structure
- $first_json['table_data']['headers'] = array_values($first_json['table_data']['headers']);
- $first_json['table_data']['data'] = array_values($first_json['table_data']['data']);
- $first_json['proposal_data']['over_all_column_data'] = array_map(function ($proposal) {
- $proposal['insurers'] = array_values($proposal['insurers']);
- return $proposal;
- }, $first_json['proposal_data']['over_all_column_data']);
+ // Reindex arrays to maintain proper structure
+ $first_json['table_data']['headers'] = array_values($first_json['table_data']['headers']);
+ $first_json['table_data']['data'] = array_values($first_json['table_data']['data']);
+ $first_json['proposal_data']['over_all_column_data'] = array_map(function ($proposal) {
+ $proposal['insurers'] = array_values($proposal['insurers']);
+ return $proposal;
+ }, $first_json['proposal_data']['over_all_column_data']);
+
+ }else{
+
+ //remove insurer as Subheaders for RFQ
+ foreach ($first_json['table_data']['headers'] as &$header) {
+ $header['subHeaders'] = array_filter($header['subHeaders'], function ($subHeader) {
+ return in_array($subHeader, ['Quote Asked', '-']);
+ });
+ }
+
+ //Remove insurer Row wise data for RFQ
+ foreach ($first_json['table_data']['data'] as &$row) {
+
+ // Filter the inner data array
+ $row['data'] = array_filter(
+ $row['data'],
+ function ($item) {
+ return in_array($item['subth'], ['Quote Asked', '-']);
+ }
+ );
+
+ $row['data'] = array_values($row['data']);
+ }
+
+ // Ensure to unset the reference after the loop
+ unset($row);
+
+
+ // Remove insurers from Proposal Data key for RFQ
+ foreach ($first_json['proposal_data']['over_all_column_data'] as $key => &$proposal) {
+ if (isset($proposal['insurers'])) {
+ // Set the insurers array to empty
+ $proposal['insurers'] = [];
+ }
+ }
+
+ // Ensure to reset the reference
+ unset($proposal);
+
+ }
return $first_json;
}
@@ -1850,8 +2019,54 @@ class LeadsController extends BaseController
//------------------------------------------------------------------------------------------------
- public function transformMailContent()
- {
+ public function transformMailContent($lead_id)
+ {
+ helper('excel_util_helper');
+ // $params = $this->request->getGet();
+ // print_r($params); die;
+ // $lead_id = $params['lead_id'];
+ // $file_type = $params['file_type']; //rfq or qcr
+ // $recipient_type = $params['recipient_type']; //insurer or client or internal or placement
+ // $recipient_mail = $params['recipient_mail']; // - only primary key of contacts
+ // $propsal_and_insurer = isset($params['proposal_insurer']) ? $params['proposal_insurer'] : null;
+
+ // if ($recipient_type == 'insurer' && empty($recipient_mail)) {
+ // return $this->respond(['status' => 'failed', 'code' => 400, 'data' => '', 'messgae' => 'Recipient mail not found ! '], 200);
+ // }
+
+ //gather lead info
+ $lead_data = $this->leadsModel
+ ->select('leads.*,policy_type.long_name,policy_type.policy_type,user_profiles.email as created_person_email')
+ ->join('policy_type', 'leads.policy_type_id = policy_type.id', 'left')
+ ->join('user_profiles', 'leads.created_by = user_profiles.id', 'left')
+ ->where('leads.id', $lead_id)
+ ->first();
+
+ // dd($lead_data);
+
+ if($lead_data){
+
+ $recipient_data = ['name' => "Team"];
+ $original_message = '
Request for Quotation (RFQ)
Dear {{RECIPIENT_NAME}},
We are reaching out to request a quotation for the following insurance coverage. Please review the details below and provide your quote at your earliest convenience.
RFQ Details
Client name
{{CLIENT_NAME}}
Coverage Type
{{POLICY_LONG_NAME}}
Policy Start Date
{{POLICY_START_DATE}}
Policy Duration
{{DURATION}}
Please note: Additional terms and details are included in the attachment for your reference.
Please feel free to reach out if you require any further information to prepare the quote. We look forward to receiving your proposal.