@@ -1422,15 +1407,15 @@ class LeadsController extends BaseController
In case of any query, please feel free to contact us.
Thank You!
Best regards,
-
+
{{LOGGED_USER_NAME}}
Mobile: {{LOGGED_USER_MOBILE}}
-
+
';
- }else{
+ } else {
return '
Dear Sir,
Greetings From Nhance India!
@@ -1439,12 +1424,12 @@ class LeadsController extends BaseController
In case of any query, please feel free to contact us.
Thank You!
Best regards,
-
+
{{LOGGED_USER_NAME}}
Mobile: {{LOGGED_USER_MOBILE}}
-
+
';
}
@@ -1463,7 +1448,7 @@ class LeadsController extends BaseController
$data = $this->request->getPost();
- $lead_id = $data['lead_id'];
+ $lead_id = $data['lead_id'];
$json_data = $data['registration_json'];
$existingJson = $this->RFQModel->where('is_active', 1)->where("lead_id", $lead_id)->first()['registration_json'] ?? null;
@@ -1476,10 +1461,9 @@ class LeadsController extends BaseController
->set('is_active', 0)
->update();
- $insertData['lead_id'] = $lead_id;
+ $insertData['lead_id'] = $lead_id;
$insertData['registration_json'] = json_encode($json_data);
-
$this->RFQModel->insert($insertData);
return $this->respond(['status' => true, "message" => "Policy Inforamtion saved"]);
@@ -1491,26 +1475,26 @@ class LeadsController extends BaseController
public function createRFQ()
{
- $data = $this->request->getPost();
+ $data = $this->request->getPost();
$lead_id = $data['lead_id'] ?? null;
- if (!$lead_id) {
+ if (! $lead_id) {
return $this->respond(['status' => false, 'message' => 'Opportunity ID is required'], 400);
}
$rfq_created = $this->RFQModel->where('lead_id', $lead_id)->where('is_active', 1)->countAllResults();
$qcr_created = false;
- $inputJson = json_decode($data['json'], true);
- if (isset($inputJson['premium_data']) && !empty($inputJson['premium_data'])) {
- $sortedJson = $this->reorderProposalsByInsurerTotal($inputJson);
+ $inputJson = json_decode($data['json'], true);
+ if (isset($inputJson['premium_data']) && ! empty($inputJson['premium_data'])) {
+ $sortedJson = $this->reorderProposalsByInsurerTotal($inputJson);
$data['json'] = json_encode($sortedJson);
- $qcr_created = true;
+ $qcr_created = true;
}
$quote_received_insurer = [];
if (($data['submit_type'] ?? "") === 'QCR') {
- $inputJson = json_decode($data['json'], true);
+ $inputJson = json_decode($data['json'], true);
$proposal_data = $inputJson['proposal_data'] ?? array_pop($inputJson);
if (isset($proposal_data['over_all_column_data'])) {
@@ -1519,11 +1503,11 @@ class LeadsController extends BaseController
$this->myLogger->logme("error", "insurer id : " . json_encode($proposel_count));
foreach ($proposel_count as $key => $value) {
- if (!empty($value['insurers'])) {
+ if (! empty($value['insurers'])) {
$qcr_created = true;
foreach ($value['insurers'] as $insurer => $id) {
- if (!empty($id['id'])) {
+ if (! empty($id['id'])) {
$quote_received_insurer[] = $id['id'];
}
}
@@ -1536,13 +1520,13 @@ class LeadsController extends BaseController
$data['type'] = 1;
//update the quote received insurer data to the lead
- if(count($quote_received_insurer) != 0){
+ if (count($quote_received_insurer) != 0) {
$this->leadsModel->update($lead_id, ['quote_received_insurer' => json_encode($quote_received_insurer ?? [])]);
$this->myLogger->logme("error", "quote_received_insurer data updated in the lead: " . json_encode($quote_received_insurer));
}
// Deactivate existing RFQs for this lead and type
- if (!isset($data['rfq_primaryKey']) && empty($data['rfq_primaryKey'])) {
+ if (! isset($data['rfq_primaryKey']) && empty($data['rfq_primaryKey'])) {
$this->RFQModel
->where('lead_id', $lead_id)
->where('type', 1)
@@ -1560,16 +1544,16 @@ class LeadsController extends BaseController
->orderBy('id', 'DESC')
->first();
- if (!empty($latest['registration_json'])) {
+ if (! empty($latest['registration_json'])) {
$data['registration_json'] = $latest['registration_json'];
}
}
// print_r($data); die;
// $data['json'] = "";
- if (isset($data['rfq_primaryKey']) && !empty($data['rfq_primaryKey'])) {
+ if (isset($data['rfq_primaryKey']) && ! empty($data['rfq_primaryKey'])) {
$this->RFQModel->update($data['rfq_primaryKey'], $data);
- $insertId = $data['rfq_primaryKey'];
+ $insertId = $data['rfq_primaryKey'];
$affectedRows = db_connect()->affectedRows();
} else {
// Insert new RFQ
@@ -1592,28 +1576,28 @@ class LeadsController extends BaseController
$message = ($data['submit_type'] ?? '') == 'QCR' ? 'QCR saved successfully' : 'RFQ saved successfully';
return $this->respond([
- 'status' => true,
- 'id' => $insertId,
- 'message' => $message,
- 'data' => $data,
+ 'status' => true,
+ 'id' => $insertId,
+ 'message' => $message,
+ 'data' => $data,
'affectedRows' => $affectedRows ?? null,
], 200);
}
$message = ($data['submit_type'] ?? '') == 'QCR' ? 'Failed to save QCR' : 'Failed to save RFQ';
return $this->respond([
- 'status' => false,
- 'id' => null,
+ 'status' => false,
+ 'id' => null,
'message' => $message,
- 'data' => $data
+ 'data' => $data,
], 200);
}
public function createQCR()
{
- $data = $this->request->getPost();
- $lead_id = $data['lead_id'];
+ $data = $this->request->getPost();
+ $lead_id = $data['lead_id'];
$data['type'] = 2;
$this->RFQModel
@@ -1632,15 +1616,16 @@ class LeadsController extends BaseController
return $this->respond(['status' => false, 'id' => $result, 'message' => "Failed to create QCR", 'data' => $data], 200);
}
-
public function reorderProposalsByInsurerTotal(array $data): array
{
- if (!isset($data['premium_data']['data'])) return $data;
+ if (! isset($data['premium_data']['data'])) {
+ return $data;
+ }
- $original = $data['premium_data']['data'];
- $proposals = [];
- $others = [];
+ $original = $data['premium_data']['data'];
+ $proposals = [];
+ $others = [];
$emptyKeyData = [];
foreach ($original as $key => $value) {
@@ -1677,7 +1662,7 @@ class LeadsController extends BaseController
// Add Quote Asked back at the top
$proposal = array_merge(['Quote Asked' => $quoteAsked], $proposal);
}
-
+
// Sort proposals by their insurer's total
uasort($proposals, function ($a, $b) {
$totalA = 0;
@@ -1702,29 +1687,29 @@ class LeadsController extends BaseController
// Merge back the sorted proposals into the full structure
$data['premium_data']['data'] = array_merge($others, $proposals, $emptyKeyData);
- $data = $this->reorderProposalDataByPremiumOrder($data);
+ $data = $this->reorderProposalDataByPremiumOrder($data);
return $data;
}
private function reorderProposalDataByPremiumOrder(array $data): array
{
- if (!isset($data['premium_data']['data'], $data['proposal_data']['over_all_column_data'])) {
+ if (! isset($data['premium_data']['data'], $data['proposal_data']['over_all_column_data'])) {
return $data;
}
- $porposalData = $data['premium_data']['data'];
- $premiumProposals = array_keys($data['premium_data']['data']);
+ $porposalData = $data['premium_data']['data'];
+ $premiumProposals = array_keys($data['premium_data']['data']);
$filteredProposals = [];
//Reorder the Insurer based on the Premium data insurer
foreach ($porposalData as $key => $value) {
- if(in_array($key, ['Particulars', ""])){
+ if (in_array($key, ['Particulars', ""])) {
continue;
}
// Ensure the premium data is an array and not empty
- if (!is_array($value) || empty($value)) {
+ if (! is_array($value) || empty($value)) {
continue;
}
@@ -1741,7 +1726,7 @@ class LeadsController extends BaseController
// });
// Step 2: Reorder proposal insurers based on premium order
- usort($data['proposal_data']['over_all_column_data'][$key]['insurers'], function($a, $b) use ($premiumOrder) {
+ usort($data['proposal_data']['over_all_column_data'][$key]['insurers'], function ($a, $b) use ($premiumOrder) {
$posA = array_search($a['display_name'] ?? '', $premiumOrder);
$posB = array_search($b['display_name'] ?? '', $premiumOrder);
@@ -1764,21 +1749,21 @@ class LeadsController extends BaseController
// dd($premiumProposals, $filteredProposals);
$data['proposal_data']['over_all_column_data'] = $filteredProposals;
- $data = $this->reorderProposalInHeaderAndData($data);
+ $data = $this->reorderProposalInHeaderAndData($data);
return $data;
}
private function reorderProposalInHeaderAndData(array $data): array
{
- $tableData = $data['table_data'];
+ $tableData = $data['table_data'];
$sortedProposalOrder = $data['proposal_data']['over_all_column_data'];
- $headers = $tableData['headers'] ?? [];
- $dataRows = $tableData['data'] ?? [];
+ $headers = $tableData['headers'] ?? [];
+ $dataRows = $tableData['data'] ?? [];
// Step 1: Separate static and proposal headers
- $staticHeaders = [];
+ $staticHeaders = [];
$proposalHeaders = [];
- $actionHeader = [];
+ $actionHeader = [];
foreach ($headers as $header) {
if (in_array($header['parentHeader'], array_keys($sortedProposalOrder))) {
$proposalHeaders[$header['parentHeader']] = $header;
@@ -1795,10 +1780,10 @@ class LeadsController extends BaseController
foreach ($sortedProposalOrder as $proposalKey => $proposalData) {
// Skip if insurers or subHeaders are missing
if (
- !isset($proposalData['insurers']) ||
- !is_array($proposalData['insurers']) ||
- !isset($proposalHeaders[$proposalKey]['subHeaders']) ||
- !is_array($proposalHeaders[$proposalKey]['subHeaders'])
+ ! isset($proposalData['insurers']) ||
+ ! is_array($proposalData['insurers']) ||
+ ! isset($proposalHeaders[$proposalKey]['subHeaders']) ||
+ ! is_array($proposalHeaders[$proposalKey]['subHeaders'])
) {
continue;
}
@@ -1808,7 +1793,7 @@ class LeadsController extends BaseController
// Add insurers in the sorted order
foreach ($proposalData['insurers'] as $insurer) {
- if(in_array($insurer['display_name'], $proposalHeaders[$proposalKey]['subHeaders'])){
+ if (in_array($insurer['display_name'], $proposalHeaders[$proposalKey]['subHeaders'])) {
$newSubHeaders[] = $insurer['display_name'];
}
}
@@ -1830,7 +1815,7 @@ class LeadsController extends BaseController
// print_rr($reorderedHeaders); die;
$proposel_count = 1;
foreach ($reorderedHeaders as $key => &$value) {
- if(!in_array($value['parentHeader'], ["Existing Renewal", "Existing Rollover"])){
+ if (! in_array($value['parentHeader'], ["Existing Renewal", "Existing Rollover"])) {
$value['parentHeader'] = 'Proposal ' . $proposel_count;
$proposel_count++;
}
@@ -1839,12 +1824,12 @@ class LeadsController extends BaseController
//merge the all headers
$reorderedHeaders = array_merge($staticHeaders, $reorderedHeaders, $actionHeader);
-
+
// Step 3: Reorder each row's `data` by matching parentth
foreach ($dataRows as $dataRowIndex => &$row) {
- $staticData = [];
+ $staticData = [];
$proposalData = [];
- $actionData = [];
+ $actionData = [];
foreach ($row['data'] as $entry) {
if (in_array($entry['parentth'], array_keys($sortedProposalOrder))) {
@@ -1867,18 +1852,18 @@ class LeadsController extends BaseController
}
}
- $dubParTh = "";
+ $dubParTh = "";
$increament = 0;
foreach ($reorderedProposalData as $key => &$value) {
if ($dubParTh == $value['parentth']) {
- if(!in_array($value['parentth'], ["Existing Renewal", "Existing Rollover"])){
+ if (! in_array($value['parentth'], ["Existing Renewal", "Existing Rollover"])) {
$value['parentth'] = 'Proposal ' . ($increament);
}
} else {
$dubParTh = $value['parentth'];
- if(!in_array($value['parentth'], ["Existing Renewal", "Existing Rollover"])){
- $increament = $increament + 1;
+ if (! in_array($value['parentth'], ["Existing Renewal", "Existing Rollover"])) {
+ $increament = $increament + 1;
$value['parentth'] = 'Proposal ' . ($increament);
}
}
@@ -1888,19 +1873,18 @@ class LeadsController extends BaseController
//Reorder the Row Data based on the Insurer
$reorderedProposalData = $this->reorderProposalRowData($reorderedProposalData, $proposalHeaders);
-
// print_rr($reorderedProposalData); die;
$row['data'] = array_merge($staticData, $reorderedProposalData, $actionData);
}
$data['table_data']['headers'] = $reorderedHeaders;
- $data['table_data']['data'] = $dataRows;
+ $data['table_data']['data'] = $dataRows;
- $renumberedArray = $this->renumberProposalKeys($data['proposal_data']['over_all_column_data']);
- $updatedDataSet = $this->renumberProposalKeys($data['premium_data']['data']);
- $data['proposal_data']['over_all_column_data'] = !empty($renumberedArray) ? $renumberedArray : $data['proposal_data']['over_all_column_data'];
- $data['premium_data']['data'] = !empty($updatedDataSet) ? $updatedDataSet : $data['premium_data']['data'];
+ $renumberedArray = $this->renumberProposalKeys($data['proposal_data']['over_all_column_data']);
+ $updatedDataSet = $this->renumberProposalKeys($data['premium_data']['data']);
+ $data['proposal_data']['over_all_column_data'] = ! empty($renumberedArray) ? $renumberedArray : $data['proposal_data']['over_all_column_data'];
+ $data['premium_data']['data'] = ! empty($updatedDataSet) ? $updatedDataSet : $data['premium_data']['data'];
return $data;
}
@@ -1912,7 +1896,7 @@ class LeadsController extends BaseController
// Group rows by parentth
$groupedRows = [];
foreach ($proposalRowData as $row) {
- if (!isset($row['parentth'])) {
+ if (! isset($row['parentth'])) {
continue; // skip invalid rows
}
$groupedRows[$row['parentth']][] = $row;
@@ -1921,15 +1905,15 @@ class LeadsController extends BaseController
// Reorder each group's rows based on header subHeaders
foreach ($proposalHeaderData as $proposalKey => $headerInfo) {
if (
- !isset($groupedRows[$proposalKey]) ||
- !isset($headerInfo['subHeaders']) ||
- !is_array($headerInfo['subHeaders'])
+ ! isset($groupedRows[$proposalKey]) ||
+ ! isset($headerInfo['subHeaders']) ||
+ ! is_array($headerInfo['subHeaders'])
) {
continue;
}
$order = $headerInfo['subHeaders'];
- $rows = $groupedRows[$proposalKey];
+ $rows = $groupedRows[$proposalKey];
// Sort whole rows according to subth position in $order
usort($rows, function ($a, $b) use ($order) {
@@ -1945,12 +1929,12 @@ class LeadsController extends BaseController
private function renumberProposalKeys(array $input): array
{
- $result = [];
+ $result = [];
$counter = 1;
foreach ($input as $key => $value) {
if (strpos($key, 'Proposal') === 0) {
- $newKey = 'Proposal ' . $counter++;
+ $newKey = 'Proposal ' . $counter++;
$result[$newKey] = $value;
} else {
$result[$key] = $value;
@@ -1964,7 +1948,7 @@ class LeadsController extends BaseController
{
$id = $this->request->getGet('id');
// print_r($id); die;
- if (!empty($id)) {
+ if (! empty($id)) {
$this->leadInstallmentPaymentDetails->whereIn('id', $id)->set(['is_active' => 0])->update();
} else {
return $this->respond(['status' => false, 'message' => 'Could not be removed.'], 200);
@@ -1972,9 +1956,9 @@ class LeadsController extends BaseController
if ($this->request->getGet('lead_id')) {
$lead_id = $this->request->getGet('lead_id');
- $data = [
+ $data = [
'no_of_installment' => 0,
- 'is_installment' => 0
+ 'is_installment' => 0,
];
$this->leadsModel->where('id', $lead_id)->set($data)->update();
}
@@ -1984,7 +1968,6 @@ class LeadsController extends BaseController
//-----RFQ and QCR EXPORT------------------------------------------------------------------------------------------------
-
//export main route function
public function exportQCRandRFQ($lead_id, $type, $lead_form_type)
{
@@ -2015,7 +1998,7 @@ class LeadsController extends BaseController
if ($lead_file_path) {
$filePaths = [
['file_path' => $temp_file_path, 'sheets' => []],
- ['file_path' => $lead_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);
@@ -2049,15 +2032,15 @@ class LeadsController extends BaseController
public function constructExcelToSaveTemp($lead_id, $type, $propsal_and_insurer = null)
{
helper('excel_util_helper');
- $rfq_data = $this->RFQModel->getRFQTableDataWithLeadIDAndType($lead_id, $type);
+ $rfq_data = $this->RFQModel->getRFQTableDataWithLeadIDAndType($lead_id, $type);
$is_placement = false;
- $length = 0;
+ $length = 0;
// dd($rfq_data, $lead_id, $type, $propsal_and_insurer);
// print_r($propsal_and_insurer); die;
// print_r($is_placement); die;
- $data = json_decode($rfq_data['json'], true);
+ $data = json_decode($rfq_data['json'], true);
$sheetName = 'Worksheet';
if ($type == 2) {
$sheetName = 'QCR';
@@ -2065,51 +2048,51 @@ class LeadsController extends BaseController
$data = $this->convertJsonForQCR($data, $type);
if ($propsal_and_insurer !== null) {
list($proposal_key, $insurer_key) = explode('-', $propsal_and_insurer, 2);
- $data = $this->transformProposelData($data, $proposal_key, $insurer_key);
- $is_placement = true;
- $sheetName = 'Placement';
+ $data = $this->transformProposelData($data, $proposal_key, $insurer_key);
+ $is_placement = true;
+ $sheetName = 'Placement';
}
} else if ($type == 1) {
$sheetName = 'RFQ';
- $data = $this->convertJsonForQCR($data, $type);
+ $data = $this->convertJsonForQCR($data, $type);
} // dd($data);
if ($rfq_data['lead_type'] == 1) {
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']] ?? "",
+ 'Insured' => $rfq_data['client_name'],
+ 'Policy Type' => $this->leadType[$rfq_data['lead_type']] ?? "",
- 'No of Employees' => $rfq_data['incept_emp_count'],
- 'No of Dependents' => $rfq_data['incept_dept_count'],
- 'Total Lives' => $rfq_data['incept_no_of_lives'],
+ '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 ' => !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",
+ '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'],
];
} else if (in_array($rfq_data['policy_type_id'], [1, 6, 7])) {
$lead_data = [
- 'Insured' => $rfq_data['client_name'],
+ 'Insured' => $rfq_data['client_name'],
'No of Employees at Inception' => $rfq_data['incept_emp_count'],
// 'Total Sum Insured at Inception ' => $rfq_data['total_si_at_incept'],
- '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",
+ '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']] ?? "",
+ 'Policy Type' => $this->leadType[$rfq_data['lead_type']] ?? "",
];
}
-
+
} else {
if (in_array($rfq_data['policy_type_id'], [2, 3, 4, 5])) {
- if($is_placement == true){
+ if ($is_placement == true) {
$lead_data = [
- 'Insured' => $rfq_data['client_name'],
- 'Policy Type' => $this->leadType[$rfq_data['lead_type']] ?? "",
+ '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'],
@@ -2119,13 +2102,13 @@ class LeadsController extends BaseController
// '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 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'],
+ 'Total Lives at Renewal ' => $rfq_data['renewal_no_of_lives'],
- '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'] ?? " - ",
+ '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']),
@@ -2136,52 +2119,52 @@ class LeadsController extends BaseController
// 'Incurred Claims Ratio' => $rfq_data['incurred_claims_ratio'] . " %",
// 'Earned Claims Ratio' => $rfq_data['earned_claims_ratio'] . " %",
];
- }else{
+ } else {
$lead_data = [
- 'Insured' => $rfq_data['client_name'],
- 'Policy Type' => $this->leadType[$rfq_data['lead_type']] ?? "",
+ 'Insured' => $rfq_data['client_name'],
+ 'Policy Type' => $this->leadType[$rfq_data['lead_type']] ?? "",
- 'No of Employees at Inception' => $is_placement ? '-' : $rfq_data['incept_emp_count'],
- 'No of Dependents at Inception' => $is_placement ? '-' : $rfq_data['incept_dept_count'],
- 'Total Lives at Inception ' => $is_placement ? '-' : $rfq_data['incept_no_of_lives'],
+ 'No of Employees at Inception' => $is_placement ? '-' : $rfq_data['incept_emp_count'],
+ 'No of Dependents at Inception' => $is_placement ? '-' : $rfq_data['incept_dept_count'],
+ 'Total Lives at Inception ' => $is_placement ? '-' : $rfq_data['incept_no_of_lives'],
- 'No of Employees at Expiry' => $is_placement ? '-' : $rfq_data['exp_emp_count'],
- 'No of Dependents at Expiry' => $is_placement ? '-' : $rfq_data['exp_dept_count'],
- 'Total Lives at Expiry ' => $is_placement ? '-' : $rfq_data['exp_no_of_lives'],
+ 'No of Employees at Expiry' => $is_placement ? '-' : $rfq_data['exp_emp_count'],
+ 'No of Dependents at Expiry' => $is_placement ? '-' : $rfq_data['exp_dept_count'],
+ 'Total Lives at Expiry ' => $is_placement ? '-' : $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'],
+ '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 ' => !empty($rfq_data['policy_start_date']) && !empty($rfq_data['policy_end_date'])
+ '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'] ?? " - ",
+ 'Insurer' => $rfq_data['insurer_name'] ?? " - ",
+ 'TPA' => $rfq_data['tpa_name'] ?? " - ",
- 'Policy Run Days' => $is_placement ? '-' : $rfq_data['policy_run_days'],
- 'Inception Premium' => $is_placement ? '-' : formatIndianCurrency($rfq_data['premium_at_inception']),
- 'Premium as on (' . date('d-m-Y', strtotime($rfq_data['incurred_claims_date'])) . ')' => $is_placement ? '-' : formatIndianCurrency($rfq_data['premium_date']),
- 'Earned Premium' => $is_placement ? '-' : formatIndianCurrency(intval($rfq_data['earned_premium'])),
+ 'Policy Run Days' => $is_placement ? '-' : $rfq_data['policy_run_days'],
+ 'Inception Premium' => $is_placement ? '-' : formatIndianCurrency($rfq_data['premium_at_inception']),
+ 'Premium as on (' . date('d-m-Y', strtotime($rfq_data['incurred_claims_date'])) . ')' => $is_placement ? '-' : formatIndianCurrency($rfq_data['premium_date']),
+ 'Earned Premium' => $is_placement ? '-' : formatIndianCurrency(intval($rfq_data['earned_premium'])),
'Incurred Claims as on (' . date('d-m-Y', strtotime($rfq_data['incurred_claims_date'])) . ')' => $is_placement ? '-' : formatIndianCurrency($rfq_data['incurred_claims']),
- 'Annualised Claims' => $is_placement ? '-' : formatIndianCurrency(intval($rfq_data['annualised_claims'])),
- 'Incurred Claims Ratio' => $is_placement ? '-' : $rfq_data['incurred_claims_ratio'] . " %",
- 'Earned Claims Ratio' => $is_placement ? '-' : $rfq_data['earned_claims_ratio'] . " %",
+ 'Annualised Claims' => $is_placement ? '-' : formatIndianCurrency(intval($rfq_data['annualised_claims'])),
+ 'Incurred Claims Ratio' => $is_placement ? '-' : $rfq_data['incurred_claims_ratio'] . " %",
+ 'Earned Claims Ratio' => $is_placement ? '-' : $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 Sum Insured at Inception' => $rfq_data['total_si_at_incept'],
- 'Premium at inception' => $rfq_data['premium_at_incept'],
- '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",
- 'Policy Type' => $this->leadType[$rfq_data['lead_type']] ?? "",
- 'Existing Insurer' => $rfq_data['insurer_name'],
- 'No of Employees at Renewal' => $rfq_data['renewal_emp_count'],
- 'Total Sum Insured at Renewal' => $rfq_data['total_si_at_renewal'],
+ 'Insured' => $rfq_data['client_name'],
+ 'No of Employees at Inception' => $rfq_data['incept_emp_count'],
+ 'Total Sum Insured at Inception' => $rfq_data['total_si_at_incept'],
+ 'Premium at inception' => $rfq_data['premium_at_incept'],
+ '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",
+ 'Policy Type' => $this->leadType[$rfq_data['lead_type']] ?? "",
+ 'Existing Insurer' => $rfq_data['insurer_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'] ?? " - ",
@@ -2191,12 +2174,10 @@ class LeadsController extends BaseController
}
// print_r($lead_data); die;
-
$spreadsheet = new Spreadsheet();
- $sheet = $spreadsheet->getActiveSheet();
+ $sheet = $spreadsheet->getActiveSheet();
$sheet->setTitle($sheetName);
-
// Start with lead_data at the top
$rowNumber = 1;
@@ -2204,13 +2185,13 @@ class LeadsController extends BaseController
// $sheet->mergeCells($mergeRange1);
$sheet->setCellValue("A{$rowNumber}", "Nhance India Insurance Broking Pvt Ltd");
$sheet->getStyle("A{$rowNumber}")->applyFromArray([
- 'font' => [
+ 'font' => [
'bold' => true,
- 'size' => 23
+ 'size' => 23,
],
'alignment' => [
'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER,
- 'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER,
+ 'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER,
],
]);
@@ -2271,22 +2252,22 @@ class LeadsController extends BaseController
$sheet->setCellValue("A{$rowNumber}", "Details of Coverage");
$sheet->getStyle("A{$rowNumber}")->applyFromArray([
- 'font' => [
+ 'font' => [
'bold' => true,
],
- 'fill' => [
- 'fillType' => Fill::FILL_SOLID,
+ 'fill' => [
+ 'fillType' => Fill::FILL_SOLID,
'startColor' => ['rgb' => 'ADD8E6'],
],
'borders' => [
'allBorders' => [
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
- 'color' => ['argb' => 'FF000000'], // Black color
+ 'color' => ['argb' => 'FF000000'], // Black color
],
],
]);
- if($type == 2){
+ if ($type == 2) {
$subheader_count = array_sum(
array_map(
fn($header) => count(array_filter(
@@ -2296,7 +2277,7 @@ class LeadsController extends BaseController
$data['table_data']['headers']
)
);
- }else{
+ } else {
$subheader_count = array_sum(array_map(fn($header) => count($header['subHeaders']), $data['table_data']['headers']));
}
@@ -2305,7 +2286,7 @@ class LeadsController extends BaseController
}
$headerCount = count($data['table_data']['headers']);
- $lastColumn = Coordinate::stringFromColumnIndex($subheader_count);
+ $lastColumn = Coordinate::stringFromColumnIndex($subheader_count);
// dd( $headerCount, $lastColumn);
// Merge cells from A to the last column
@@ -2315,14 +2296,14 @@ class LeadsController extends BaseController
'borders' => [
'allBorders' => [
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
- 'color' => ['argb' => 'FF000000'], // Black color
+ 'color' => ['argb' => 'FF000000'], // Black color
],
],
]);
$sheet->mergeCells($mergeRange);
$rowNumber_for_remove_quote_asked = $rowNumber;
- $rowNumber = $rowNumber + 1;
+ $rowNumber = $rowNumber + 1;
if ($type == 2) {
$subHeaderRow = $rowNumber + 1;
@@ -2331,13 +2312,13 @@ class LeadsController extends BaseController
$subHeaderRow = $rowNumber + 1;
}
- $columnLetter = 'A';
+ $columnLetter = 'A';
$header_actual_count = 0;
- $headerIndex = 0;
+ $headerIndex = 0;
foreach ($headers as $header) {
// Kint::dump($header);
- if($is_placement == true){
+ if ($is_placement == true) {
//for placement proposal only
$nxt_ro = $rowNumber + 1;
$sheet->mergeCells("C{$rowNumber}:C{$nxt_ro}");
@@ -2346,13 +2327,13 @@ class LeadsController extends BaseController
if (in_array($header['parentHeader'], ['Item Key', 'Action'])) {
continue;
}
-
- if (!in_array($header['parentHeader'], ['Item Key', 'Action', 'Sno', 'Particulars'])) {
+
+ if (! in_array($header['parentHeader'], ['Item Key', 'Action', 'Sno', 'Particulars'])) {
$header_actual_count++;
- //Quote asked not showed in the QCR excel so some proposel has only one Quote Asked, So that case avoid the proposel name
+ //Quote asked not showed in the QCR excel so some proposel has only one Quote Asked, So that case avoid the proposel name
$subHeaderCount = count($header['subHeaders'] ?? []) ?? 0;
- if($subHeaderCount <= 1 && $type == 2 && $is_placement == false){
+ if ($subHeaderCount <= 1 && $type == 2 && $is_placement == false) {
// print_rr($header);
continue;
}
@@ -2376,33 +2357,33 @@ class LeadsController extends BaseController
}
$startColumn = $columnLetter; // Start of the current header range
- if($type == 2){
- $subHeaderCount = count(array_filter($header['subHeaders'], function($subHeader) {
+ if ($type == 2) {
+ $subHeaderCount = count(array_filter($header['subHeaders'], function ($subHeader) {
return $subHeader !== "Quote Asked";
}));
- }else{
+ } else {
$subHeaderCount = count($header['subHeaders']); // Number of subheaders for this parent header
}
// Set parent header value
- if ($is_placement == true && !in_array($header['parentHeader'], ['Particulars', 'S.No.'])) {
+ if ($is_placement == true && ! in_array($header['parentHeader'], ['Particulars', 'S.No.'])) {
$sheet->setCellValue("{$startColumn}{$rowNumber}", "Terms");
} else {
- if(in_array($header['parentHeader'], ["Existing Renewal", "Existing Rollover"])){
+ if (in_array($header['parentHeader'], ["Existing Renewal", "Existing Rollover"])) {
$sheet->setCellValue("{$startColumn}{$rowNumber}", "Existing Terms");
- }else if(in_array($header['parentHeader'], ["Particulars", "S.No."])){
+ } else if (in_array($header['parentHeader'], ["Particulars", "S.No."])) {
$sheet->setCellValue("{$startColumn}{$rowNumber}", $header['parentHeader']);
- }else{
+ } else {
$headerIndex = $headerIndex + 1;
$sheet->setCellValue("{$startColumn}{$rowNumber}", "Proposal Terms " . $headerIndex);
}
}
-
+
$sheet->getStyle("{$startColumn}{$rowNumber}")->applyFromArray([
- 'font' => ['bold' => true],
+ 'font' => ['bold' => true],
'alignment' => [
'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER,
- 'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER,
+ 'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER,
],
]);
@@ -2417,7 +2398,7 @@ class LeadsController extends BaseController
// Add subheaders
foreach ($header['subHeaders'] as $subHeader) {
- if($type == 2 && in_array($subHeader, ['Quote Asked'])){
+ if ($type == 2 && in_array($subHeader, ['Quote Asked'])) {
continue;
}
@@ -2433,23 +2414,23 @@ class LeadsController extends BaseController
if ($is_placement == false) {
$sheet->getStyle("{$columnLetter}{$subHeaderRow}")->applyFromArray([
- 'font' => ['bold' => true],
+ 'font' => ['bold' => true],
'alignment' => [
'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER,
- 'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER,
+ 'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER,
],
]);
}
$columnLetter++; // Move to the next column for subheaders
- // Kint::dump($subHeader);
+ // Kint::dump($subHeader);
$length++;
}
}
-
- if($header_actual_count == 1 && $type == 1){
+
+ if ($header_actual_count == 1 && $type == 1) {
$sheet->getColumnDimension('B')->setWidth(80);
- }else{
+ } else {
$sheet->getColumnDimension('B')->setWidth(35);
}
@@ -2460,13 +2441,13 @@ class LeadsController extends BaseController
'borders' => [
'allBorders' => [
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
- 'color' => ['argb' => 'FF000000'], // Black color
+ 'color' => ['argb' => 'FF000000'], // Black color
],
],
]);
- // Increase row height for headers and subheaders
- $sheet->getRowDimension($rowNumber)->setRowHeight(25); // Header row height
+ // Increase row height for headers and subheaders
+ $sheet->getRowDimension($rowNumber)->setRowHeight(25); // Header row height
$sheet->getRowDimension($subHeaderRow)->setRowHeight(20); // Subheader row height
if ($is_placement == true) {
@@ -2476,8 +2457,8 @@ class LeadsController extends BaseController
}
// dd($rowNumber);
- $column_data = $data['table_data']['data'];
- $serial_no = 1;
+ $column_data = $data['table_data']['data'];
+ $serial_no = 1;
$maxColumnWidths = [];
// Add table data rows
@@ -2488,7 +2469,7 @@ class LeadsController extends BaseController
continue;
}
- if($type == 2 && in_array($cellData['subth'], ['Quote Asked'])){
+ if ($type == 2 && in_array($cellData['subth'], ['Quote Asked'])) {
continue;
}
@@ -2505,26 +2486,26 @@ class LeadsController extends BaseController
}
$prevColumn2 = $this->getPreviousColumn($columnLetter);
- $dataRange = "A" . ($subHeaderRow + 1) . ":" . "{$prevColumn2}" . ($rowNumber - 1);
+ $dataRange = "A" . ($subHeaderRow + 1) . ":" . "{$prevColumn2}" . ($rowNumber - 1);
$sheet->getStyle($dataRange)->applyFromArray([
'borders' => [
'allBorders' => [
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
- 'color' => ['argb' => 'FF000000'], // Black color
+ 'color' => ['argb' => 'FF000000'], // Black color
],
],
]);
- //premium data
+ //premium data
if ($type == 2) {
- if($is_placement == true){$columnLetterForPremium = "B";}else{$columnLetterForPremium = "B";}
+ if ($is_placement == true) {$columnLetterForPremium = "B";} else { $columnLetterForPremium = "B";}
$rowNumber += 2;
// Add premium data
// dd($data);
// $labelArray = ["Premium", "GST (%)", "GST Amount (₹)", "Total"];
- $labelArray = ["Premium", "GST Amount (₹)", "Total"];
+ $labelArray = ["Premium", "GST Amount (₹)", "Total"];
$premiumData = $data['premium_data']['data'];
// dd($premiumData);
// $premium = [$labelArray[0]];
@@ -2533,24 +2514,24 @@ class LeadsController extends BaseController
// $total = [$labelArray[2]];
// if($is_placement == true){
- $premium[] = $labelArray[0];
- $gstAmt[] = $labelArray[1];
- $total[] = $labelArray[2];
+ $premium[] = $labelArray[0];
+ $gstAmt[] = $labelArray[1];
+ $total[] = $labelArray[2];
// }
foreach ($premiumData as $proposal => $insurers) {
if ($proposal != 'Particulars') {
foreach ($insurers as $insurer => $values) {
- if($insurer == 'Quote Asked'){
+ if ($insurer == 'Quote Asked') {
// $premium[] = count($insurers ?? []) > 1 ? $labelArray[0] : "";
// $gst[] = "";
// $gstAmt[] = count($insurers ?? []) > 1 ? $labelArray[1] : "";
// $total[] = count($insurers ?? []) > 1 ? $labelArray[2] : "";
- }else{
+ } else {
$premium[] = formatIndianCurrency($values[$labelArray[0]]);
// $gst[] = $values[$labelArray[1]];
$gstAmt[] = formatIndianCurrency($values[$labelArray[1]]);
- $total[] = formatIndianCurrency($values[$labelArray[2]]);
+ $total[] = formatIndianCurrency($values[$labelArray[2]]);
}
}
}
@@ -2563,7 +2544,7 @@ class LeadsController extends BaseController
foreach ($rowData as $key => $value) {
$sheet->setCellValue("{$columnLetter}{$rowNumber}", $value);
if (in_array($value, $labelArray)) {
- $sheet->getStyle("{$columnLetter}{$rowNumber}")->applyFromArray(['font' => ['bold' => true,],]);
+ $sheet->getStyle("{$columnLetter}{$rowNumber}")->applyFromArray(['font' => ['bold' => true]]);
}
$columnLetter++;
}
@@ -2583,7 +2564,7 @@ class LeadsController extends BaseController
'borders' => [
'allBorders' => [
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
- 'color' => ['argb' => 'FF000000'], // Black color
+ 'color' => ['argb' => 'FF000000'], // Black color
],
],
]);
@@ -2601,7 +2582,7 @@ class LeadsController extends BaseController
}
$company_name = $this->getPreviousColumn($columnLetter_img);
- $mergeRange1 = "A1:{$company_name}1";
+ $mergeRange1 = "A1:{$company_name}1";
$sheet->mergeCells($mergeRange1);
$rowCount = count($lead_data);
@@ -2612,7 +2593,7 @@ class LeadsController extends BaseController
'borders' => [
'allBorders' => [
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
- 'color' => ['argb' => 'FF000000'], // Black color
+ 'color' => ['argb' => 'FF000000'], // Black color
],
],
]);
@@ -2622,13 +2603,13 @@ class LeadsController extends BaseController
$sheet->getRowDimension(1)->setRowHeight(50); // Adjust as needed
$drawing = new Drawing();
- $path = ROOTPATH . "public/assets/images/Nhance-Logo-Final.png"; // Use FCPATH for server path
+ $path = ROOTPATH . "public/assets/images/Nhance-Logo-Final.png"; // Use FCPATH for server path
$drawing->setPath($path);
$drawing->setCoordinates("{$columnLetter_img}1"); // Set position in column B
- $drawing->setHeight(35); // Adjust image
+ $drawing->setHeight(35); // Adjust image
$offsetX = 35;
$drawing->setOffsetX($offsetX); // Adjust horizontal offset
- $drawing->setOffsetY(10); // Adjust vertical offset
+ $drawing->setOffsetY(10); // Adjust vertical offset
$drawing->setWorksheet($sheet);
//end
@@ -2650,53 +2631,53 @@ class LeadsController extends BaseController
if ($matches) {
$startColumn = $matches[1]; // A
- $startRow = $matches[2]; // 1
- $endColumn = $matches[3]; // G
- $endRow = $matches[4]; // 75
+ $startRow = $matches[2]; // 1
+ $endColumn = $matches[3]; // G
+ $endRow = $matches[4]; // 75
// Convert column letter to index, reduce by 1, and convert back
$endColumnIndex = Coordinate::columnIndexFromString($endColumn) - 1;
- $newEndColumn = Coordinate::stringFromColumnIndex($endColumnIndex);
+ $newEndColumn = Coordinate::stringFromColumnIndex($endColumnIndex);
// Generate the new range (e.g., "A1:F75" instead of "A1:G75")
$newDataRange = "{$startColumn}{$startRow}:{$newEndColumn}{$endRow}";
// $sheet->getStyle($newDataRange)->getBorders()->getAllBorders()->setBorderStyle(Border::BORDER_THIN);
}
- $lastRow = count($lead_data) + 1;
+ $lastRow = count($lead_data) + 1;
$leadRange = "A1:{$columnLetter_img}{$lastRow}";
$sheet->getStyle($leadRange)->applyFromArray([
'borders' => [
'allBorders' => [
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
- 'color' => ['argb' => 'FF000000'], // Black color
+ 'color' => ['argb' => 'FF000000'], // Black color
],
],
]);
// Set filename
- $string = ($type == 2) ? ($is_placement == true ? 'Placement' : 'QCR') : 'RFQ';
+ $string = ($type == 2) ? ($is_placement == true ? 'Placement' : 'QCR') : 'RFQ';
$current_year = date('Y');
- $next_year = $current_year + 1;
- $policy_year = "$current_year-$next_year";
+ $next_year = $current_year + 1;
+ $policy_year = "$current_year-$next_year";
- if (!empty($rfq_data['policy_end_date'])) {
+ if (! empty($rfq_data['policy_end_date'])) {
- $policy_expiry = strtotime($rfq_data['policy_end_date']);
+ $policy_expiry = strtotime($rfq_data['policy_end_date']);
$formatted_policy = date("d-m-Y", $policy_expiry);
- $filename = "{$rfq_data['client_name']}_{$rfq_data['policy_type']}_{$string}_" . $policy_year . '(Due On ' . $formatted_policy . ')' . '.xlsx';
+ $filename = "{$rfq_data['client_name']}_{$rfq_data['policy_type']}_{$string}_" . $policy_year . '(Due On ' . $formatted_policy . ')' . '.xlsx';
} else {
- $filename = "{$rfq_data['client_name']}_{$rfq_data['policy_type']}_{$string}_" . $policy_year . '_' . '.xlsx';
+ $filename = "{$rfq_data['client_name']}_{$rfq_data['policy_type']}_{$string}_" . $policy_year . '_' . '.xlsx';
}
//claim history new sheet;
- if (!empty($rfq_data['fin_years_claims'])) {
+ if (! empty($rfq_data['fin_years_claims'])) {
$claim_details = json_decode($rfq_data['fin_years_claims'], true) ?? [];
- if (!empty($claim_details['finyear'])) {
+ if (! empty($claim_details['finyear'])) {
// Get headers dynamically
$headers = array_map(function ($key) {
@@ -2709,9 +2690,9 @@ class LeadsController extends BaseController
$sheet = $spreadsheet->getActiveSheet();
// Set headers
- $sheet->fromArray($headers, NULL, 'A1');
+ $sheet->fromArray($headers, null, 'A1');
- // Apply background color and bold style to headers
+ // Apply background color and bold style to headers
$headerCellRange = 'A1:' . chr(64 + count($headers)) . '1'; // e.g., A1:G1
$sheet->getStyle($headerCellRange)->getFont()->setBold(true);
@@ -2725,8 +2706,8 @@ class LeadsController extends BaseController
foreach ($claim_details['finyear'] as $record) {
$col = 'A';
foreach ($record as $array_key => $value) {
- $label = ucwords(str_replace('_', ' ', ($value ?? "")));
- if(in_array($array_key, ['sum_insured', 'claim_amount', 'settled'])){
+ $label = ucwords(str_replace('_', ' ', ($value ?? "")));
+ if (in_array($array_key, ['sum_insured', 'claim_amount', 'settled'])) {
$label = formatIndianCurrency(intval($label));
}
$sheet->setCellValue($col . $row, $label);
@@ -2753,24 +2734,24 @@ class LeadsController extends BaseController
// $sheet->getStyle("A2:{$maxColLetter}{$row}")->getAlignment()->setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER);
$maxColLetter = chr(64 + count($headers));
- $dataRange = "A1:{$maxColLetter}" . ($row - 1);
+ $dataRange = "A1:{$maxColLetter}" . ($row - 1);
$sheet->getStyle($dataRange)->getAlignment()
->setWrapText(true)
->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER)
->setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER);
- // Optional: Make row height auto (helps when wrap text is on)
- for ($i = 2; $i < $row; $i++) {
- $sheet->getRowDimension($i)->setRowHeight(-1);
- }
+ // Optional: Make row height auto (helps when wrap text is on)
+ for ($i = 2; $i < $row; $i++) {
+ $sheet->getRowDimension($i)->setRowHeight(-1);
+ }
- }
- }
+ }
+ }
// Save to temporary location
$uploadFilePath = WRITEPATH . 'tmp/' . $filename;
- $writer = new Xlsx($spreadsheet);
+ $writer = new Xlsx($spreadsheet);
$writer->save($uploadFilePath);
return [
@@ -2792,21 +2773,21 @@ class LeadsController extends BaseController
public function calculateMembersDemography($params, $returnType = null)
{
- $lead_id = $params['lead_id'];
- $lead_data = $this->leadsModel->find((int)$lead_id);
+ $lead_id = $params['lead_id'];
+ $lead_data = $this->leadsModel->find((int) $lead_id);
$file_name_with_path = WRITEPATH . "/uploads/lead_files/" . $lead_data['file_name'];
- if (!$lead_data) {
+ if (! $lead_data) {
return ['status' => 'failed', 'message' => 'Opportunity data not found'];
}
- try{
+ try {
if ($lead_data['file_name']) {
// $file_name_with_path = WRITEPATH . "/uploads/lead_files/NonPrintableCharacters.xlsx";
//check physical file
- if (!file_exists($file_name_with_path)) {
- //file not found update status and reason
+ if (! file_exists($file_name_with_path)) {
+ //file not found update status and reason
$message = "Lead Physcial file not found";
// echo $message;
$this->myLogger->logme('error', ($message . ' for file ' . $file_name_with_path));
@@ -2816,28 +2797,27 @@ class LeadsController extends BaseController
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($file_name_with_path);
//get members data
- $members_sheet = $spreadsheet->getSheet(0);
+ $members_sheet = $spreadsheet->getSheet(0);
$highestRowAndColumn = $members_sheet->getHighestRowAndColumn();
// dd($highestRowAndColumn);
$uncleaned_members = $members_sheet->rangeToArray('A1:' . $highestRowAndColumn['column'] . $highestRowAndColumn['row']);
- $members = ExcelSanitizeHelper::sanitizeArrayData($uncleaned_members);
+ $members = ExcelSanitizeHelper::sanitizeArrayData($uncleaned_members);
//get age band data
- $age_band_sheet = $spreadsheet->getSheet(1);
+ $age_band_sheet = $spreadsheet->getSheet(1);
$highestRowAndColumn = $age_band_sheet->getHighestRowAndColumn();
- $age_band_data = $age_band_sheet->rangeToArray('A1:' . $highestRowAndColumn['column'] . $highestRowAndColumn['row']);
+ $age_band_data = $age_band_sheet->rangeToArray('A1:' . $highestRowAndColumn['column'] . $highestRowAndColumn['row']);
-
- //check age or dob column
+ //check age or dob column
$members_heading = $members[0];
- $available_col = null;
- $col_index = null;
+ $available_col = null;
+ $col_index = null;
if (in_array('age', array_map('strtolower', $members_heading))) {
$available_col = 'age';
- $col_index = array_search('age', array_map('strtolower', $members_heading));
+ $col_index = array_search('age', array_map('strtolower', $members_heading));
} elseif (in_array('dob', array_map('strtolower', $members_heading))) {
$available_col = 'dob';
- $col_index = array_search('dob', array_map('strtolower', $members_heading));
+ $col_index = array_search('dob', array_map('strtolower', $members_heading));
}
if ($available_col == null) {
@@ -2853,12 +2833,11 @@ class LeadsController extends BaseController
}
//for this to view the demography in the RFQ and QCR page to using internal
- if($returnType == "internal"){
+ if ($returnType == "internal") {
return ['data' => $classifiers];
// print_rr($classifiers); die;
}
-
try {
$result = $this->generateClassifierSpreadsheet($classifiers, WRITEPATH . 'uploads/lead_files/');
if ($result['success']) {
@@ -2868,9 +2847,9 @@ class LeadsController extends BaseController
echo "Filename: " . $result['filename'] . "\n";
$filePaths = [
['file_path' => WRITEPATH . 'uploads/lead_files/' . $lead_data['file_name'], 'sheets' => [0, 1]],
- ['file_path' => WRITEPATH . '/uploads/lead_files/' . $result['filename'], 'sheets' => []],
+ ['file_path' => WRITEPATH . '/uploads/lead_files/' . $result['filename'], 'sheets' => []],
];
- $outputPath = WRITEPATH . 'uploads/lead_files/' . $lead_data['file_name'];
+ $outputPath = WRITEPATH . 'uploads/lead_files/' . $lead_data['file_name'];
$result_merge = ExcelMergeHelper::mergeExcelFiles($filePaths, $outputPath);
if ($result_merge) {
// Call the delete function after the file is successfully created
@@ -2891,8 +2870,8 @@ class LeadsController extends BaseController
$this->myLogger->logme('error', (' no file found ' . $file_name_with_path));
return ['status' => 'failed', 'message' => 'no file found'];
}
-
- }catch(Exception $e){
+
+ } catch (Exception $e) {
$this->myLogger->logme("error", "Exception: " . $e->getMessage() . " --- Line: " . $e->getLine() . " --- Trace: " . $e->getTraceAsString());
return ['status' => 'fail', 'error' => "File not found / Wrong file"];
}
@@ -2902,10 +2881,10 @@ class LeadsController extends BaseController
{
$first_loop = 0;
// $col_index_si = array_search('si enhancement', array_map('strtolower', $members_heading));
- $col_index_si = array_search('si', array_map('strtolower', $members_heading));
+ $col_index_si = array_search('si', array_map('strtolower', $members_heading));
$col_index_relationship = array_search('relationship', array_map('strtolower', $members_heading));
- $relations = [];
- $si_amt = ['general']; // Initialize with 'general' as per first loop condition
+ $relations = [];
+ $si_amt = ['general']; // Initialize with 'general' as per first loop condition
// First pass - collect unique relations and SI amounts
foreach ($members as $member) {
@@ -2917,11 +2896,11 @@ class LeadsController extends BaseController
continue;
}
- if (!in_array($member[$col_index_relationship], $relations) && $member[$col_index_relationship] != null) {
+ if (! in_array($member[$col_index_relationship], $relations) && $member[$col_index_relationship] != null) {
$relations[] = $member[$col_index_relationship];
}
- if (!in_array($member[$col_index_si], $si_amt) && $member[$col_index_si] != null) {
+ if (! in_array($member[$col_index_si], $si_amt) && $member[$col_index_si] != null) {
$si_amt[] = $member[$col_index_si];
}
}
@@ -2960,14 +2939,15 @@ class LeadsController extends BaseController
// Get age
$age = $this->getAge($available_col, $member, $col_index);
-
- $relation = $member[$col_index_relationship];
+ $relation = $member[$col_index_relationship];
$member_si = $member[$col_index_si];
// Find the correct age band (only once per member)
$found_band = false;
foreach ($age_band_data as $age_bands) {
- if ($found_band) break;
+ if ($found_band) {
+ break;
+ }
foreach ($age_bands as $age_band) {
//get Min and Max Age
@@ -3010,21 +2990,21 @@ class LeadsController extends BaseController
public function generateClassifierSpreadsheet($classifiers, $outputDir = 'exports')
{
- if (!file_exists($outputDir)) {
- if (!mkdir($outputDir, 0755, true)) {
+ if (! file_exists($outputDir)) {
+ if (! mkdir($outputDir, 0755, true)) {
throw new Exception("Failed to create directory: $outputDir");
}
}
// Check if directory is writable
- if (!is_writable($outputDir)) {
+ if (! is_writable($outputDir)) {
throw new Exception("Directory is not writable: $outputDir");
}
// Generate unique filename
$timestamp = date('Y-m-d_His');
- $filename = "member_classification_{$timestamp}.xlsx";
- $filepath = $outputDir . DIRECTORY_SEPARATOR . $filename;
+ $filename = "member_classification_{$timestamp}.xlsx";
+ $filepath = $outputDir . DIRECTORY_SEPARATOR . $filename;
// Check if file already exists (shouldn't happen with timestamp, but just in case)
if (file_exists($filepath)) {
@@ -3037,12 +3017,12 @@ class LeadsController extends BaseController
}
$spreadsheet = new Spreadsheet();
- $sheet = $spreadsheet->getActiveSheet();
+ $sheet = $spreadsheet->getActiveSheet();
$sheet->setTitle('Demography_Data');
// Get all age bands
$age_bands = array_keys(reset($classifiers['general']));
- array_pop($age_bands); // Remove 'Grand Total'
+ array_pop($age_bands); // Remove 'Grand Total'
$age_bands[] = 'Grand Total'; // Add it back at the end
$currentRow = 5; // Start from row 5 to match the example
@@ -3054,7 +3034,7 @@ class LeadsController extends BaseController
// Style section header
$sheet->getStyle('B' . $currentRow)->applyFromArray([
- 'font' => ['bold' => true, 'size' => 14],
+ 'font' => ['bold' => true, 'size' => 14],
'alignment' => ['horizontal' => Alignment::HORIZONTAL_CENTER],
]);
@@ -3069,14 +3049,14 @@ class LeadsController extends BaseController
}
// Style headers
- $lastCol = chr(ord('B') + count($age_bands));
+ $lastCol = chr(ord('B') + count($age_bands));
$headerRange = 'B' . $currentRow . ':' . $lastCol . $currentRow;
$sheet->getStyle($headerRange)->applyFromArray([
- 'font' => ['bold' => true],
- 'borders' => [
+ 'font' => ['bold' => true],
+ 'borders' => [
'allBorders' => [
'borderStyle' => Border::BORDER_THIN,
- 'color' => ['rgb' => '000000'],
+ 'color' => ['rgb' => '000000'],
],
],
'alignment' => [
@@ -3100,10 +3080,10 @@ class LeadsController extends BaseController
// Style data row
$dataRange = 'B' . $currentRow . ':' . $lastCol . $currentRow;
$sheet->getStyle($dataRange)->applyFromArray([
- 'borders' => [
+ 'borders' => [
'allBorders' => [
'borderStyle' => Border::BORDER_THIN,
- 'color' => ['rgb' => '000000'],
+ 'color' => ['rgb' => '000000'],
],
],
'alignment' => [
@@ -3126,15 +3106,15 @@ class LeadsController extends BaseController
// Style Grand Total row
$totalRange = 'B' . $currentRow . ':' . $lastCol . $currentRow;
$sheet->getStyle($totalRange)->applyFromArray([
- 'font' => ['bold' => true],
- 'borders' => [
+ 'font' => ['bold' => true],
+ 'borders' => [
'allBorders' => [
'borderStyle' => Border::BORDER_THIN,
- 'color' => ['rgb' => '000000'],
+ 'color' => ['rgb' => '000000'],
],
],
- 'fill' => [
- 'fillType' => Fill::FILL_SOLID,
+ 'fill' => [
+ 'fillType' => Fill::FILL_SOLID,
'startColor' => ['rgb' => 'F2F2F2'],
],
'alignment' => [
@@ -3162,23 +3142,23 @@ class LeadsController extends BaseController
$writer->save($filepath);
// Verify file was created successfully
- if (!file_exists($filepath)) {
+ if (! file_exists($filepath)) {
throw new Exception("Failed to create file: $filepath");
}
// Return the file info after creation
$response = [
- 'success' => true,
+ 'success' => true,
'filepath' => $filepath,
'filename' => $filename,
- 'fullpath' => realpath($filepath)
+ 'fullpath' => realpath($filepath),
];
return $response;
} catch (Exception $e) {
return [
'success' => false,
- 'error' => $e->getMessage()
+ 'error' => $e->getMessage(),
];
}
}
@@ -3191,18 +3171,18 @@ class LeadsController extends BaseController
unlink($filePath); // Delete the file
return [
'success' => true,
- 'message' => "File deleted successfully"
+ 'message' => "File deleted successfully",
];
} else {
return [
'success' => false,
- 'message' => "File does not exist"
+ 'message' => "File does not exist",
];
}
} catch (Exception $e) {
return [
'success' => false,
- 'error' => $e->getMessage()
+ 'error' => $e->getMessage(),
];
}
}
@@ -3216,7 +3196,7 @@ class LeadsController extends BaseController
if ($dob == 'DOB') {
return;
}
- $dobDate = \DateTime::createFromFormat('d-M-Y', $dob);
+ $dobDate = \DateTime::createFromFormat('d-M-Y', $dob);
$currentDate = new \DateTime();
if ($dobDate == false) {
$this->myLogger->logme('error', $dob . 'is not valid');
@@ -3232,18 +3212,17 @@ class LeadsController extends BaseController
$age_band = trim($age_band);
// Parse age range
if (strpos($age_band, '-') === false) {
- $min_age = (int)filter_var($age_band, FILTER_SANITIZE_NUMBER_INT);
+ $min_age = (int) filter_var($age_band, FILTER_SANITIZE_NUMBER_INT);
$max_age = PHP_INT_MAX;
} else {
- $parts = explode("-", $age_band);
- $min_age = (int)$parts[0];
- $max_age = (int)$parts[1];
+ $parts = explode("-", $age_band);
+ $min_age = (int) $parts[0];
+ $max_age = (int) $parts[1];
}
- return array($min_age, $max_age);
+ return [$min_age, $max_age];
}
-
//this funciton for send mail to insurer and client with either RFQ/QCR
public function sendMailWithAttachement()
{
@@ -3254,33 +3233,33 @@ class LeadsController extends BaseController
// print_r($params); die;
- $lead_id = (int)$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
+ $lead_id = (int) $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'];
+ $mail_content = $params['mail_content'];
+ $mail_subject = $params['subject'];
$attachment_file_ids = $params['selected_attachment_files'];
$from_mail = getenv('email.fromEmail');
if (in_array($recipient_type, ['placement', 'insurer', 'internal'])) {
- $from_mail = "im@nhanceindia.in";
+ $from_mail = getenv('LEAD_INSURER_FROM_MAIL_ID');
} else if (in_array($recipient_type, ['client'])) {
- $from_mail = "bs@nhanceindia.in";
+ $from_mail = getenv('LEAD_CLIENT_FROM_MAIL_ID');
}
- $type = "";
+ $type = "";
$insurer_ids = null;
if (in_array($recipient_type, ['placement'])) {
$type = "placement";
} else if (in_array($recipient_type, ['insurer'])) {
- $type = "insurer";
+ $type = "insurer";
$insurer_ids = json_decode($params['insurer_ids'] ?? "", true) ?? [];
- }else if (in_array($recipient_type, ['internal'])) {
+ } else if (in_array($recipient_type, ['internal'])) {
$type = "internal";
- }else if (in_array($recipient_type, ['client'])) {
+ } else if (in_array($recipient_type, ['client'])) {
$type = "client";
}
@@ -3288,32 +3267,32 @@ class LeadsController extends BaseController
if ($recipient_type === 'placement') {
- $lead_data = $this->leadsModel->find((int)$lead_id);
+ $lead_data = $this->leadsModel->find((int) $lead_id);
$data = [];
- if (!empty($params['policy_start_date'])) {
+ if (! empty($params['policy_start_date'])) {
$converted_start = change_date_format($params['policy_start_date']); // converts to Y-m-d
if ($converted_start !== $lead_data['policy_start_date']) {
$data['policy_start_date'] = $converted_start;
}
}
- if (!empty($params['policy_end_date'])) {
+ if (! empty($params['policy_end_date'])) {
$converted_end = change_date_format($params['policy_end_date']); // converts to Y-m-d
if ($converted_end !== $lead_data['policy_end_date']) {
$data['policy_end_date'] = $converted_end;
}
}
- if (!empty($data)) {
+ if (! empty($data)) {
$this->leadsModel->update($lead_id, $data);
}
}
$result_data = [];
// dd($recipient_mail);
- if ($recipient_type == 'insurer' && (!is_array($recipient_mail) || count($recipient_mail) == 0)) {
+ if ($recipient_type == 'insurer' && (! is_array($recipient_mail) || count($recipient_mail) == 0)) {
return $this->respond(['status' => 'failed', 'code' => 400, 'data' => '', 'messgae' => 'Recipient mail not found ! '], 200);
}
// dd();
@@ -3328,16 +3307,15 @@ class LeadsController extends BaseController
// log_message('error', 'Lead Data' . json_encode($lead_data));
// print_r($lead_data ); die;
- $cc_mails = [];
+ $cc_mails = [];
$bcc_mails = [];
//get CC Mails
if ($recipient_type == 'internal' || $recipient_type == 'insurer' || $recipient_type == 'client') {
- $cc_data = isset($params['cc']) ? $params['cc'] : "";
+ $cc_data = isset($params['cc']) ? $params['cc'] : "";
$param_cc_mail = json_decode($cc_data, true);
-
if (isset($param_cc_mail) && is_array($param_cc_mail) && count($param_cc_mail) > 0) {
// Fetch user data where ID is in the param_cc_mail array
$userData = $this->userModel
@@ -3362,13 +3340,20 @@ class LeadsController extends BaseController
// return $this->respond(['status' => 'failed','code' => 400,'data' => '','message' => 'CC mail not found!'], 200);
}
} else if ($recipient_type == 'placement') {
- $cc_mails = isset($params['cc']) ? json_decode($params['cc'], true) : "";
+
+ if(isset($params['cc']) && !empty($params['cc'])) {
+ if(is_array($params['cc'])) {
+ $cc_mails = $params['cc'];
+ } else {
+ $cc_mails = json_decode($params['cc'], true);
+ }
+ }
}
//get BCC Mails
if ($recipient_type == 'insurer' || $recipient_type == 'client') {
- $bcc_data = isset($params['bcc']) ? $params['bcc'] : "";
+ $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) {
@@ -3406,7 +3391,8 @@ class LeadsController extends BaseController
//get file path to attach
if ($lead_data["lead_form_type"] == 2) {
- $file_info = $this->constructNonEbExcelToSaveTemp($lead_id, ($file_type == 'rfq' ? 1 : 2), $propsal_and_insurer);
+ // For Non-EB, download RFQ/QCR file from Google Sheet (if configured)
+ $file_info = $this->downloadFileFromGoogleSheet($lead_data);
} else {
$file_info = $this->constructExcelToSaveTemp($lead_id, ($file_type == 'rfq' ? 1 : 2), $propsal_and_insurer);
}
@@ -3420,10 +3406,10 @@ class LeadsController extends BaseController
if ($lead_file_path) {
$filePaths = [
['file_path' => $temp_file_path, 'sheets' => []],
- ['file_path' => $lead_file_path, 'sheets' => []]
+ ['file_path' => $lead_file_path, 'sheets' => []],
];
- $outputPath = dirname($temp_file_path) . '/' . $temp_file_name;
- $result = ExcelMergeHelper::mergeExcelFiles($filePaths, $outputPath);
+ $outputPath = dirname($temp_file_path) . '/' . $temp_file_name;
+ $result = ExcelMergeHelper::mergeExcelFiles($filePaths, $outputPath);
// print_rr($result);
}
} else {
@@ -3441,21 +3427,24 @@ class LeadsController extends BaseController
$file_name = basename($result);
// Attacments part
- $attachments = [['fileName' => $file_name, 'filePath' => $file_path]];
+ $attachments = [['fileName' => $file_name, 'filePath' => $file_path]];
$other_attachments = $this->handleMultiFileAttachments($attachment_file_ids, $lead_id);
- $attachments = array_merge($attachments, $other_attachments);
+ $attachments = array_merge($attachments, $other_attachments);
// print_r($attachments); die;
//get recipient address
if ($recipient_type == 'insurer' || $recipient_type == 'placement') {
-
+
+ if(!is_array($recipient_mail)) {
+ $recipient_mail = [$recipient_mail];
+ }
$recipient_data = $this->levelContactModel
->where(['contact_type' => 'insurer', 'is_active' => 1])
->whereIn('id', $recipient_mail)
->findAll();
} else if ($recipient_type == 'client') {
- $mailIDS = explode(',', $params['contact_mail']);
+ $mailIDS = explode(',', $params['contact_mail']);
$recipient_data = [];
foreach ($mailIDS as $mail) {
$recipient_data[] = ['name' => $lead_data['contact_person_name'], 'email' => $mail];
@@ -3470,12 +3459,12 @@ class LeadsController extends BaseController
$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.