diff --git a/app/Controllers/LeadsController.php b/app/Controllers/LeadsController.php index 67c5c1da..32beb07c 100644 --- a/app/Controllers/LeadsController.php +++ b/app/Controllers/LeadsController.php @@ -362,13 +362,13 @@ class LeadsController extends BaseController // $premium_date = null; // } - if (!empty($data['source_policy_start_date'])) { + if (!empty($data['source_policy_start_date']) && $data['lead_type'] == 2) { $data['source_policy_start_date'] = change_date_format($data['source_policy_start_date'], 'd/m/Y', 'Y-m-d'); } else { $data['source_policy_start_date'] = null; } - if (!empty($data['source_policy_end_date'])) { + if (!empty($data['source_policy_end_date']) && $data['lead_type'] == 2) { $data['source_policy_end_date'] = change_date_format($data['source_policy_end_date'], 'd/m/Y', 'Y-m-d'); } else { $data['source_policy_end_date'] = null; @@ -938,7 +938,7 @@ class LeadsController extends BaseController foreach ($original as $key => $value) { // Match only keys that look like 'Proposal X' - if (preg_match('/^Proposal\s+\d+$/', $key)) { + if (preg_match('/^(Proposal\s+\d+|Existing Renewal|Existing Rollover)$/', $key)) { // Get the insurer entry (not 'Quote Asked') foreach ($value as $subKey => $subVal) { if ($subKey !== 'Quote Asked' && isset($subVal['Total'])) { @@ -998,7 +998,7 @@ class LeadsController extends BaseController // Collect proposal keys that match the pattern "Proposal X" foreach ($premiumProposals as $key) { - if (preg_match('/^Proposal\s+\d+$/', $key) && isset($data['proposal_data']['over_all_column_data'][$key])) { + if (preg_match('/^(Proposal\s+\d+|Existing Renewal|Existing Rollover)$/', $key) && isset($data['proposal_data']['over_all_column_data'][$key])) { $filteredProposals[$key] = $data['proposal_data']['over_all_column_data'][$key]; } } @@ -1044,8 +1044,12 @@ class LeadsController extends BaseController } // print_rr($reorderedHeaders); die; + $proposel_count = 1; foreach ($reorderedHeaders as $key => &$value) { - $value['parentHeader'] = 'Proposal ' . ($key + 1); + if(!in_array($value['parentHeader'], ["Existing Renewal", "Existing Rollover"])){ + $value['parentHeader'] = 'Proposal ' . $proposel_count; + $proposel_count++; + } } unset($value); @@ -1085,11 +1089,15 @@ class LeadsController extends BaseController foreach ($reorderedProposalData as $key => &$value) { if ($dubParTh == $value['parentth']) { - $value['parentth'] = 'Proposal ' . ($increament); + if(!in_array($value['parentth'], ["Existing Renewal", "Existing Rollover"])){ + $value['parentth'] = 'Proposal ' . ($increament); + } } else { $dubParTh = $value['parentth']; - $increament = $increament + 1; - $value['parentth'] = 'Proposal ' . ($increament); + if(!in_array($value['parentth'], ["Existing Renewal", "Existing Rollover"])){ + $increament = $increament + 1; + $value['parentth'] = 'Proposal ' . ($increament); + } } } unset($value); @@ -1328,7 +1336,7 @@ class LeadsController extends BaseController $sheet->getStyle("A{$rowNumber}")->applyFromArray([ 'font' => [ 'bold' => true, - 'size' => 20 + 'size' => 23 ], 'alignment' => [ 'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER, @@ -1384,8 +1392,8 @@ class LeadsController extends BaseController // // Set column width based on max content length (adjusted for padding) $sheet->getColumnDimension('A')->setWidth($maxWidthA * 1.2); - $sheet->getColumnDimension('B')->setWidth($maxWidthA * 1.5); - $sheet->getColumnDimension('C')->setWidth($maxWidthB * 1.6); + // $sheet->getColumnDimension('B')->setWidth($maxWidthA * 1.5); + $sheet->getColumnDimension('C')->setWidth(35); // $rowNumber += 2; @@ -1440,12 +1448,17 @@ class LeadsController extends BaseController } $columnLetter = 'A'; + $header_actual_count = 0; foreach ($headers as $header) { // Kint::dump($header); if (in_array($header['parentHeader'], ['Item Key', 'Action'])) { continue; } + + if (!in_array($header['parentHeader'], ['Item Key', 'Action', 'Sno', 'Particulars'])) { + $header_actual_count++; + } if ($header['parentHeader'] === 'Sno') { $header['parentHeader'] = 'S.No.'; @@ -1453,7 +1466,7 @@ class LeadsController extends BaseController } if ($header['parentHeader'] === 'Particulars') { - $sheet->getColumnDimension('B')->setWidth(50); + $sheet->getColumnDimension('B')->setWidth(35); } $startColumn = $columnLetter; // Start of the current header range @@ -1512,6 +1525,13 @@ class LeadsController extends BaseController $length++; } } + + if($header_actual_count == 1 && $type == 1){ + $sheet->getColumnDimension('B')->setWidth(80); + }else{ + $sheet->getColumnDimension('B')->setWidth(35); + } + // die(); // Apply border to the header range @@ -1665,8 +1685,8 @@ class LeadsController extends BaseController ]); } - $sheet->getColumnDimension($columnLetter_img)->setWidth(40); - $sheet->getRowDimension(1)->setRowHeight(40); // Adjust as needed + $sheet->getColumnDimension($columnLetter_img)->setWidth(35); + $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 @@ -1681,7 +1701,7 @@ class LeadsController extends BaseController $offsetX = $offsetX + 97; // dd($length); if ($length >= 4) { - $offsetX = 50; + $offsetX = 65; } else if ($length == 3) { $offsetX = 65; } diff --git a/app/Views/leads_form.php b/app/Views/leads_form.php index 33020b90..d4314b6b 100644 --- a/app/Views/leads_form.php +++ b/app/Views/leads_form.php @@ -552,7 +552,7 @@ }) //------------------------------ GET DATA ( EDIT, BRANCH, POLICY ) --------------------------------------------------------------------------- - //view and edit Lead data function + //view and edit Lead data function ( NOT IN USE DON'T DELETE ) function getLeadsDataForEdit(input) { $('.loader').fadeIn(); @@ -608,9 +608,9 @@ $('.lifeClaimFields').show(); } else { - updateRenewalFields(dataIncrement); - let incurred_claim_date_id = 'incurred_claim_date_' + dataIncrement; - // let premium_date_id = 'premium_date_' + dataIncrement; + // updateRenewalFields(dataIncrement); + // let incurred_claim_date_id = 'incurred_claim_date_' + dataIncrement; + let incurred_claim_date_id = 'incurred_claim_date'; var incurred_claim_datepicker = flatpickr("#" + incurred_claim_date_id, { dateFormat: "d/m/Y", @@ -976,10 +976,12 @@ $('.lifeClaimFields').show(); } else { - updateRenewalFields(dataIncrement); - let incurred_claim_date_id = 'incurred_claim_date_' + dataIncrement; - // let premium_date_id = 'premium_date_' + dataIncrement; - + if(lead_type == 1){ + updateRenewalFields(dataIncrement); + } + + // let incurred_claim_date_id = 'incurred_claim_date_' + dataIncrement; + let incurred_claim_date_id = 'incurred_claim_date'; var incurred_claim_datepicker = flatpickr("#" + incurred_claim_date_id, { dateFormat: "d/m/Y", allowInput: false, @@ -1007,11 +1009,6 @@ } }); - // var premium_date_datepicker = flatpickr("#" + premium_date_id, { - // dateFormat: "d/m/Y", - // allowInput: false - // }); - $('#proposed_insurer_' + dataIncrement).select2(); $('#proposed_tpa_' + dataIncrement).select2(); @@ -1181,14 +1178,14 @@ $('#source_policy_id').on('change', function() { let client_policy_id = $(this).val(); - console.log('increment given', increment) + console.log('increment given', increment); getPolicyData(client_policy_id, increment); }) if (check == 1) { let client_policy_id = $('#source_policy_id').val(); if (client_policy_id) { - getPolicyData(client_policy_id, increment) + getPolicyData(client_policy_id, increment); } } @@ -1354,23 +1351,29 @@ console.log('Lead Type:', lead_type); let increment = input.id.split('_').pop(); // Extract increment - if(lead_type != 1){ - increment = "1"; + if(lead_type == 1){ + return; } + let input_id = input.id; console.log('--- calculatePolicyMetrics called ---'); - console.log('Input ID:', input.id); + console.log('Input ID:', input_id); console.log('Increment:', increment); let sourcePolicyDateVal = $('#source_policy_start_date').val()?.trim(); - let policyStartDateVal = $('#policy_start_date').val()?.trim(); + let policyStartDateVal = $('#policy_start_date').val()?.trim() || $('#policy_start_date_1').val()?.trim(); + let policyStartDateInput = null; - if (sourcePolicyDateVal) { + if (sourcePolicyDateVal && lead_type == 2) { policyStartDateInput = $('#source_policy_start_date'); console.log('Using Source Policy Start Date:', sourcePolicyDateVal); } else if (policyStartDateVal) { - policyStartDateInput = $('#policy_start_date'); + if(input_id == "policy_start_date_1"){ + policyStartDateInput = $('#policy_start_date_1'); + }else{ + policyStartDateInput = $('#policy_start_date'); + } console.log('Using Policy Start Date:', policyStartDateVal); } else { toastr.warning('Policy start date or Date of Commencement is empty. Please fill in the date field.', "WARNING.. !"); @@ -1383,7 +1386,7 @@ console.log('Policy Start Date Input:', policyStartDateInput.val()); let policyStartDate = flatpickr.parseDate(policyStartDateInput.val(), "d/m/Y"); - let incurredClaimDate = flatpickr.parseDate($("#incurred_claim_date_" + increment).val(), "d/m/Y"); + let incurredClaimDate = flatpickr.parseDate($("#incurred_claim_date").val(), "d/m/Y"); console.log('Parsed Policy Start Date:', policyStartDate); console.log('Parsed Incurred Claim Date:', incurredClaimDate); @@ -1395,28 +1398,28 @@ let daysDiff = Math.ceil(timeDiff / (1000 * 60 * 60 * 24) + 1); console.log('Policy Run Days:', daysDiff); - $('#policy_run_days_' + increment).val(daysDiff); + $('#policy_run_days').val(daysDiff); } - let paid_claims = Number($('#paid_claims_' + increment).val()) || 0; - let outstanding_claims = Number($('#outstanding_claims_' + increment).val()) || 0; + let paid_claims = Number($('#paid_claims').val()) || 0; + let outstanding_claims = Number($('#outstanding_claims').val()) || 0; console.log('Paid Claims:', paid_claims); console.log('Outstanding Claims:', outstanding_claims); let incurred_claims = paid_claims + outstanding_claims; console.log('Incurred Claims:', incurred_claims); - $('#incurred_claims_' + increment).val(incurred_claims); + $('#incurred_claims').val(incurred_claims); - let policy_run_days = Number($('#policy_run_days_' + increment).val()) || 0; + let policy_run_days = Number($('#policy_run_days').val()) || 0; console.log('Policy Run Days (Final):', policy_run_days); let annualised_claims = policy_run_days > 0 ? (incurred_claims / policy_run_days) * 365 : 0; let annualised_claims_roundoff = Math.round(annualised_claims); console.log('Annualised Claims:', annualised_claims); console.log('Annualised Claims (Rounded):', annualised_claims_roundoff); - $('#annualised_claims_' + increment).val(annualised_claims_roundoff); + $('#annualised_claims').val(annualised_claims_roundoff); - let premium_as_on_date = Number($('#premium_date_' + increment).val()) || 0; + let premium_as_on_date = Number($('#premium_date').val()) || 0; console.log('Premium as on Date:', premium_as_on_date); let incurred_claim_ratio = (annualised_claims > 0 && premium_as_on_date > 0) @@ -1425,19 +1428,19 @@ let incurred_claim_ratio_roundoff = isFinite(incurred_claim_ratio) ? Math.round(incurred_claim_ratio) : 0; console.log('Incurred Claim Ratio:', incurred_claim_ratio); console.log('Incurred Claim Ratio (Rounded):', incurred_claim_ratio_roundoff); - $('#incurred_claims_ratio_' + increment).val(incurred_claim_ratio_roundoff); + $('#incurred_claims_ratio').val(incurred_claim_ratio_roundoff); let earned_premium = premium_as_on_date > 0 ? (premium_as_on_date / 365) * 364 : 0; let earned_premium_roundoff = Math.round(earned_premium); console.log('Earned Premium:', earned_premium); console.log('Earned Premium (Rounded):', earned_premium_roundoff); - $('#earned_premium_' + increment).val(earned_premium_roundoff); + $('#earned_premium').val(earned_premium_roundoff); let earnedClaimsRatio = earned_premium > 0 ? annualised_claims / earned_premium : 0; let earnedClaimsRatioRounded = Math.round(earnedClaimsRatio); console.log('Earned Claims Ratio:', earnedClaimsRatio); console.log('Earned Claims Ratio (Rounded):', earnedClaimsRatioRounded); - $('#earned_claims_ratio_' + increment).val(earnedClaimsRatioRounded); + $('#earned_claims_ratio').val(earnedClaimsRatioRounded); console.log('--- End of calculatePolicyMetrics ---\n'); } @@ -1593,6 +1596,78 @@ removeExtraForms(); } + $('#contact_person_summary').empty(); + $('#contact_person_summary').append($('', { + value: "", + text: "Select a Contact" + })); + + $("#gst").val(""); + $("#branch_name").val(""); + $("#branch_code").val(""); + $("#contact_person_name").val(""); + $("#contact_person_mobile").val(""); + $("#contact_person_email").val(""); + + + // Fresh fields + $("#client_type").prop("selectedIndex", 0); + $("#entity_type_id").prop("selectedIndex", 0); + $("#client_name").val(""); + $("#client_short_name").val(""); + + // Renewal fields + $("#client_id").prop("selectedIndex", 0); + $("#client_branch_id").prop("selectedIndex", 0); + $("#source_policy_id").empty(); + $('#source_policy_id').append($('', { + value: "", + text: "Select a Policy" + })); + $("#pan").val(""); + + $('#policy_type_id_1').prop("selectedIndex", 0) + $('#insurer_1').prop("selectedIndex", 0) + $('#tpa_1').prop("selectedIndex", 0); + $('#policy_start_date').val(""); + $('#policy_end_date').val(""); + $("#appendArea_1").empty(); + + // $('#source_policy_start_date').val(""); + // $('#source_policy_end_date').val(""); + // $('#incurred_claims_date').val(""); + // $('#paid_claims').val(""); + // $('#outstanding_claims').val(""); + // $('#incurred_claims').val(""); + // $('#policy_run_days').val(""); + // $('#premium_at_inception').val(""); + // $('#premium_date').val(""); + // $('#earned_premium').val(""); + // $('#annualised_claims').val(""); + // $('#incurred_claims_ratio').val(""); + // $('#earned_claims_ratio').val(""); + + let incurred_claim_date_id = 'incurred_claim_date'; + if ($('#' + incurred_claim_date_id).length) { + flatpickr("#" + incurred_claim_date_id, { + dateFormat: "d/m/Y", + allowInput: false, + onChange: function (selectedDates) { + try { + let increment = this.input.id.split('_').pop(); + let policyStartDate = $("#source_policy_start_date"); + if (policyStartDate.val()) { + calculatePolicyRunDays(increment); + } + } catch (error) { + console.error('Error in incurred_claim_datepicker:', error); + } + } + }); + } else { + console.warn(`Incurred claim date field #${incurred_claim_date_id} not found.`); + } + }) function insurerChange(input, unique_id) { diff --git a/app/Views/leads_form_handler.php b/app/Views/leads_form_handler.php index 06d51e8f..c53a4b9c 100644 --- a/app/Views/leads_form_handler.php +++ b/app/Views/leads_form_handler.php @@ -593,9 +593,8 @@ if (isset($selected_lead_type)) { $('.lifeClaimFields').show(); } else { // updateRenewalFields(dataIncrement); - - let incurred_claim_date_id = 'incurred_claim_date_' + dataIncrement; - // let premium_date_id = 'premium_date_' + dataIncrement; + // let incurred_claim_date_id = 'incurred_claim_date_' + dataIncrement; + let incurred_claim_date_id = 'incurred_claim_date'; if ($('#' + incurred_claim_date_id).length) { flatpickr("#" + incurred_claim_date_id, { @@ -617,15 +616,6 @@ if (isset($selected_lead_type)) { console.warn(`Incurred claim date field #${incurred_claim_date_id} not found.`); } - // if ($('#' + premium_date_id).length) { - // flatpickr("#" + premium_date_id, { - // dateFormat: "d/m/Y", - // allowInput: false - // }); - // } else { - // console.warn(`Premium date field #${premium_date_id} not found.`); - // } - // console.log($('#proposed_insurer_' + dataIncrement).length); $('#proposed_insurer_' + dataIncrement).select2(); $('#proposed_tpa_' + dataIncrement).select2(); diff --git a/app/Views/rfq/gmc.php b/app/Views/rfq/gmc.php index 876839d5..f8982fce 100644 --- a/app/Views/rfq/gmc.php +++ b/app/Views/rfq/gmc.php @@ -1,6 +1,6 @@ - + @@ -132,21 +132,21 @@ No of Employees at Inception * + class="text-danger"> No of Dependents at Inception * + class="text-danger"> Total Lives at Inception * + class="text-danger"> @@ -156,20 +156,20 @@ - No of Employees at Expiry * + No of Employees at Expiry No of Dependents at Expiry * + class="text-danger"> - Total Lives at Expiry * + Total Lives at Expiry @@ -180,21 +180,21 @@ No of Employees at Renewal * + class="text-danger"> No of Dependents at Renewal * + class="text-danger"> Total Lives at Renewal * + class="text-danger">