diff --git a/app/Controllers/LeadsController.php b/app/Controllers/LeadsController.php index 7f347d6f..0b1fc090 100644 --- a/app/Controllers/LeadsController.php +++ b/app/Controllers/LeadsController.php @@ -368,8 +368,10 @@ class LeadsController extends BaseController $id = $this->request->getPost('id'); $actual_lead_id = $this->request->getPost('actual_lead_id'); $actual_lead_id = ! empty($actual_lead_id) ? $actual_lead_id : null; - $postData = $this->request->getPost(); - $data = $this->prepareLeadData(); + + $this->normalizeClaimHistoryPostData(); + $postData = $this->request->getPost(); + $data = $this->prepareLeadData(); $rules = [ @@ -526,47 +528,65 @@ class LeadsController extends BaseController ]; if ((int) $this->request->getPost('claim_history') === 1) { - $rules['first_year.*'] = [ - 'rules' => 'required|regex_match[/^\d{4}-\d{4}$/]', - 'errors' => ['required' => 'Claim Year is required for all entries.', 'regex_match' => 'Year must be in format YYYY-YYYY.'], - ]; - $rules['first_policy_type_.*'] = [ - 'rules' => 'required|regex_match[/^[a-zA-Z0-9 _-]+$/]', - 'errors' => ['required' => 'Policy Type is required in Claim History.', - 'regex_match' => 'Policy Type only letters, numbers, space, hyphens and underscores are allowed', - ], - ]; - $rules['first_date_of_loss_.*'] = [ - 'rules' => 'required|regex_match[/^[0-9]{2}-[0-9]{2}-[0-9]{4}$/]', - 'errors' => ['required' => 'Date of Loss is required.', - 'regex_match' => 'Date of Loss must be inValid format.'], - ]; - $rules['first_cause_of_loss.*'] = [ - 'rules' => 'required|regex_match[/^[a-zA-Z0-9 _-]+$/]', - 'errors' => [ - 'required' => 'Cause of Loss is required.', - 'regex_match' => 'Cause of Loss only letters, numbers, space, hyphens and underscores are allowed', - ], - ]; - $rules['first_claim_amount.*'] = [ - 'rules' => 'required|numeric', - 'errors' => [ - 'required' => 'Claim Amount is required.', - 'numeric' => 'Claim Amount must be a number.', - ], - ]; - $rules['first_settled_amount.*'] = [ - 'rules' => 'required|numeric', - 'errors' => ['required' => 'Settled Amount is required.', - 'numeric' => 'Settled Amount must be a number.'], - ]; - $rules['first_claim_status.*'] = [ - 'rules' => 'required|alpha_space', - 'errors' => [ - 'required' => 'Claim Status is required.', - 'alpha_space' => 'Claim Status should only contain letters and spaces.', - ], - ]; + $nilClaimsRows = $this->resolveNilClaimRowFlags($postData); + $claimRowCount = $this->getClaimHistoryRowCount($postData, $nilClaimsRows); + + for ($claimIndex = 0; $claimIndex < $claimRowCount; $claimIndex++) { + $rules["first_year.$claimIndex"] = [ + 'rules' => 'required|regex_match[/^\d{4}-\d{4}$/]', + 'errors' => [ + 'required' => 'Claim Year is required for all entries.', + 'regex_match' => 'Year must be in format YYYY-YYYY.', + ], + ]; + + if (! empty($nilClaimsRows[$claimIndex])) { + continue; + } + + $rules["first_policy_type_.$claimIndex"] = [ + 'rules' => 'required|regex_match[/^[a-zA-Z0-9 _-]+$/]', + 'errors' => [ + 'required' => 'Policy Type is required in Claim History.', + 'regex_match' => 'Policy Type only letters, numbers, space, hyphens and underscores are allowed', + ], + ]; + $rules["first_date_of_loss_.$claimIndex"] = [ + 'rules' => 'required|regex_match[/^[0-9]{2}-[0-9]{2}-[0-9]{4}$/]', + 'errors' => [ + 'required' => 'Date of Loss is required.', + 'regex_match' => 'Date of Loss must be inValid format.', + ], + ]; + $rules["first_cause_of_loss.$claimIndex"] = [ + 'rules' => 'required|regex_match[/^[a-zA-Z0-9 _-]+$/]', + 'errors' => [ + 'required' => 'Cause of Loss is required.', + 'regex_match' => 'Cause of Loss only letters, numbers, space, hyphens and underscores are allowed', + ], + ]; + $rules["first_claim_amount.$claimIndex"] = [ + 'rules' => 'required|numeric', + 'errors' => [ + 'required' => 'Claim Amount is required.', + 'numeric' => 'Claim Amount must be a number.', + ], + ]; + $rules["first_settled_amount.$claimIndex"] = [ + 'rules' => 'required|numeric', + 'errors' => [ + 'required' => 'Settled Amount is required.', + 'numeric' => 'Settled Amount must be a number.', + ], + ]; + $rules["first_claim_status.$claimIndex"] = [ + 'rules' => 'required|alpha_space', + 'errors' => [ + 'required' => 'Claim Status is required.', + 'alpha_space' => 'Claim Status should only contain letters and spaces.', + ], + ]; + } } } @@ -576,65 +596,75 @@ class LeadsController extends BaseController $claimHistoryPolicyTypes = [1, 6, 7]; $hasClaimHistoryPolicy = count(array_intersect($postedPolicyTypeIds, $claimHistoryPolicyTypes)) > 0; $isEbClaimHistory = $leadFormType === 1 - && in_array((int) ($postData['lead_type'] ?? 0), [2, 3], true) + && in_array((int) ($postData['lead_type'] ?? 0), [1, 2, 3], true) && $hasClaimHistoryPolicy && (int) ($postData['claim_history'] ?? 0) === 1; if ($isEbClaimHistory) { - $rules['first_year.*'] = [ - 'rules' => 'required|regex_match[/^\d{4}-\d{4}$/]', - 'errors' => [ - 'required' => 'Claim Year is required for all entries.', - 'regex_match' => 'Year must be in format YYYY-YYYY.', - ], - ]; - $rules['emp_id.*'] = [ - 'rules' => 'required', - 'errors' => ['required' => 'Employee ID is required in Claim History.'], - ]; - $rules['emp_name.*'] = [ - 'rules' => 'required', - 'errors' => ['required' => 'Employee Name is required in Claim History.'], - ]; - $rules['gender.*'] = [ - 'rules' => 'required|in_list[Female,Male]', - 'errors' => [ - 'required' => 'Gender is required in Claim History.', - 'in_list' => 'Gender must be Female or Male.', - ], - ]; - $rules['designation.*'] = [ - 'rules' => 'required', - 'errors' => ['required' => 'Designation is required in Claim History.'], - ]; - $rules['sum_insured.*'] = [ - 'rules' => 'required|numeric', - 'errors' => [ - 'required' => 'Sum Insured is required in Claim History.', - 'numeric' => 'Sum Insured must be a number.', - ], - ]; - $rules['first_death_date.*'] = [ - 'rules' => 'required|regex_match[/^[0-9]{2}-([0-9]{2}|[A-Za-z]{3})-[0-9]{4}$/]', - 'errors' => [ - 'required' => 'Date of Death is required.', - 'regex_match' => 'Date of Death must be in DD-MM-YYYY or DD-MMM-YYYY format.', - ], - ]; - $rules['first_cause_of_death.*'] = [ - 'rules' => 'required|in_list[natural_death,suicide,accident,cardiac_arrest,septic_shock,heart_attack]', - 'errors' => [ - 'required' => 'Nature/Cause Of Death is required.', - 'in_list' => 'Nature/Cause Of Death is invalid.', - ], - ]; - $rules['first_claim_amount.*'] = [ - 'rules' => 'required|numeric', - 'errors' => [ - 'required' => 'Claim/Settled Amount is required.', - 'numeric' => 'Claim/Settled Amount must be a number.', - ], - ]; + $nilClaimsRows = $this->resolveNilClaimRowFlags($postData); + $claimRowCount = $this->getClaimHistoryRowCount($postData, $nilClaimsRows); + + for ($claimIndex = 0; $claimIndex < $claimRowCount; $claimIndex++) { + $rules["first_year.$claimIndex"] = [ + 'rules' => 'required|regex_match[/^\d{4}-\d{4}$/]', + 'errors' => [ + 'required' => 'Claim Year is required for all entries.', + 'regex_match' => 'Year must be in format YYYY-YYYY.', + ], + ]; + + if (! empty($nilClaimsRows[$claimIndex])) { + continue; + } + + $rules["emp_id.$claimIndex"] = [ + 'rules' => 'required', + 'errors' => ['required' => 'Employee ID is required in Claim History.'], + ]; + $rules["emp_name.$claimIndex"] = [ + 'rules' => 'required', + 'errors' => ['required' => 'Employee Name is required in Claim History.'], + ]; + $rules["gender.$claimIndex"] = [ + 'rules' => 'required|in_list[Female,Male]', + 'errors' => [ + 'required' => 'Gender is required in Claim History.', + 'in_list' => 'Gender must be Female or Male.', + ], + ]; + $rules["designation.$claimIndex"] = [ + 'rules' => 'required', + 'errors' => ['required' => 'Designation is required in Claim History.'], + ]; + $rules["sum_insured.$claimIndex"] = [ + 'rules' => 'required|numeric', + 'errors' => [ + 'required' => 'Sum Insured is required in Claim History.', + 'numeric' => 'Sum Insured must be a number.', + ], + ]; + $rules["first_death_date.$claimIndex"] = [ + 'rules' => 'required|regex_match[/^[0-9]{2}-([0-9]{2}|[A-Za-z]{3})-[0-9]{4}$/]', + 'errors' => [ + 'required' => 'Date of Death is required.', + 'regex_match' => 'Date of Death must be in DD-MM-YYYY or DD-MMM-YYYY format.', + ], + ]; + $rules["first_cause_of_death.$claimIndex"] = [ + 'rules' => 'required|in_list[natural_death,suicide,accident,cardiac_arrest,septic_shock,heart_attack]', + 'errors' => [ + 'required' => 'Nature/Cause Of Death is required.', + 'in_list' => 'Nature/Cause Of Death is invalid.', + ], + ]; + $rules["first_claim_amount.$claimIndex"] = [ + 'rules' => 'required|numeric', + 'errors' => [ + 'required' => 'Claim/Settled Amount is required.', + 'numeric' => 'Claim/Settled Amount must be a number.', + ], + ]; + } } // 1. MANUALLY VALIDATE FILES BEFORE PROCESSING @@ -2866,7 +2896,9 @@ class LeadsController extends BaseController //claim history new sheet; if ($claim_history == 1 && !empty($rfq_data['fin_years_claims'])) { - $claim_details = json_decode($rfq_data['fin_years_claims'], true) ?? []; + $claim_details = $this->sanitizeClaimDetailsForExport( + json_decode($rfq_data['fin_years_claims'], true) ?? [] + ); if (! empty($claim_details['finyear'])) { @@ -4654,6 +4686,209 @@ class LeadsController extends BaseController } } + private function normalizeClaimHistoryPostData(): void + { + $post = $this->request->getPost(); + + if ((int) ($post['claim_history'] ?? 0) !== 1) { + return; + } + + $rows = $this->getFinyearRowsFromPost($post); + + if ($rows === []) { + return; + } + + $leadFormType = (int) ($post['lead_form_type'] ?? 1); + $claimArrays = $leadFormType === 2 + ? $this->buildNonEbClaimHistoryPostArrays($rows) + : $this->buildEbClaimHistoryPostArrays($rows); + + $this->request->setGlobal('post', array_merge($post, $claimArrays)); + } + + /** + * Remove internal nil_claims flag from stored/exported claim rows. + * + * @param array $claimDetails + * + * @return array + */ + private function sanitizeClaimDetailsForExport(array $claimDetails): array + { + if (empty($claimDetails['finyear']) || ! is_array($claimDetails['finyear'])) { + return $claimDetails; + } + + $claimDetails['finyear'] = array_map(static function ($record) { + if (! is_array($record)) { + return $record; + } + + unset($record['nil_claims']); + + return $record; + }, $claimDetails['finyear']); + + return $claimDetails; + } + + /** + * @return list> + */ + private function getFinyearRowsFromPost(array $postData): array + { + $jsonPayload = $postData['finyear'] ?? $postData['fin_years_claims'] ?? null; + + if (! is_string($jsonPayload) || $jsonPayload === '') { + return []; + } + + $decoded = json_decode($jsonPayload, true); + + if (! is_array($decoded) || empty($decoded['finyear']) || ! is_array($decoded['finyear'])) { + return []; + } + + return $decoded['finyear']; + } + + /** + * @param list> $rows + * + * @return array> + */ + private function buildEbClaimHistoryPostArrays(array $rows): array + { + $arrays = [ + 'first_year' => [], + 'nil_claims' => [], + 'emp_id' => [], + 'emp_name' => [], + 'gender' => [], + 'designation' => [], + 'sum_insured' => [], + 'first_death_date' => [], + 'first_cause_of_death' => [], + 'first_claim_amount' => [], + ]; + + foreach ($rows as $row) { + $isNil = ! empty($row['nil_claims']); + + $arrays['first_year'][] = (string) ($row['year'] ?? ''); + $arrays['nil_claims'][] = $isNil ? '1' : '0'; + + if ($isNil) { + $arrays['emp_id'][] = 'Nil'; + $arrays['emp_name'][] = 'Nil'; + $arrays['gender'][] = 'Nil'; + $arrays['designation'][] = 'Nil'; + $arrays['sum_insured'][] = 'Nil'; + $arrays['first_death_date'][] = 'Nil'; + $arrays['first_cause_of_death'][] = 'Nil'; + $arrays['first_claim_amount'][] = 'Nil'; + } else { + $arrays['emp_id'][] = (string) ($row['emp_id'] ?? ''); + $arrays['emp_name'][] = (string) ($row['emp_name'] ?? ''); + $arrays['gender'][] = (string) ($row['gender'] ?? ''); + $arrays['designation'][] = (string) ($row['designation'] ?? ''); + $arrays['sum_insured'][] = (string) ($row['sum_insured'] ?? ''); + $arrays['first_death_date'][] = (string) ($row['death_date'] ?? ''); + $arrays['first_cause_of_death'][] = (string) ($row['cause_of_death'] ?? ''); + $arrays['first_claim_amount'][] = (string) ($row['settled'] ?? ($row['claim_amount'] ?? '')); + } + } + + return $arrays; + } + + /** + * @param list> $rows + * + * @return array> + */ + private function buildNonEbClaimHistoryPostArrays(array $rows): array + { + $arrays = [ + 'first_year' => [], + 'nil_claims' => [], + 'first_policy_type_' => [], + 'first_date_of_loss_' => [], + 'first_cause_of_loss' => [], + 'first_claim_amount' => [], + 'first_settled_amount' => [], + 'first_claim_status' => [], + ]; + + foreach ($rows as $row) { + $isNil = ! empty($row['nil_claims']); + + $arrays['first_year'][] = (string) ($row['year'] ?? ''); + $arrays['nil_claims'][] = $isNil ? '1' : '0'; + + if ($isNil) { + $arrays['first_policy_type_'][] = 'Nil'; + $arrays['first_date_of_loss_'][] = 'Nil'; + $arrays['first_cause_of_loss'][] = 'Nil'; + $arrays['first_claim_amount'][] = 'Nil'; + $arrays['first_settled_amount'][] = 'Nil'; + $arrays['first_claim_status'][] = 'Nil'; + } else { + $arrays['first_policy_type_'][] = (string) ($row['policy_type'] ?? ''); + $arrays['first_date_of_loss_'][] = (string) ($row['date_of_loss'] ?? ''); + $arrays['first_cause_of_loss'][] = (string) ($row['cause_of_loss'] ?? ''); + $arrays['first_claim_amount'][] = (string) ($row['claim_amount'] ?? ''); + $arrays['first_settled_amount'][] = (string) ($row['settled_amount'] ?? ''); + $arrays['first_claim_status'][] = (string) ($row['status'] ?? ''); + } + } + + return $arrays; + } + + /** + * @return array Row index => 1 when nil claims, else 0 + */ + private function resolveNilClaimRowFlags(array $postData): array + { + $flags = []; + + foreach ((array) ($postData['nil_claims'] ?? []) as $idx => $val) { + $flags[(int) $idx] = (int) $val; + } + + foreach ($this->getFinyearRowsFromPost($postData) as $idx => $row) { + if (! is_array($row)) { + continue; + } + + if (! empty($row['nil_claims'])) { + $flags[(int) $idx] = 1; + } elseif (! isset($flags[(int) $idx])) { + $flags[(int) $idx] = 0; + } + } + + return $flags; + } + + /** + * @param array $nilClaimFlags + */ + private function getClaimHistoryRowCount(array $postData, array $nilClaimFlags): int + { + $counts = [ + count((array) ($postData['first_year'] ?? [])), + count($nilClaimFlags), + ]; + + $counts[] = count($this->getFinyearRowsFromPost($postData)); + + return max(0, ...$counts); + } + public function getLastFiveFinancialYears(): array { $year = (int) date('Y'); @@ -4921,8 +5156,11 @@ class LeadsController extends BaseController $data['lead_edit_data']['multi_file_html'] = trim($html) !== '' ? $html : null; } - if (! in_array((int) $data['lead_edit_data']['lead_type'], [1, 3], true) && $data['lead_edit_data']['lead_form_type'] == 2) { - $data['lead_edit_data']['claims_details_html'] = view('rfq/claims_details_non_eb', $data['lead_edit_data']); + if (in_array((int) $data['lead_edit_data']['lead_type'], [1, 2, 3], true) && $data['lead_edit_data']['lead_form_type'] == 2) { + $data['lead_edit_data']['claims_details_html'] = view('rfq/claims_details_non_eb', [ + 'lead_edit_data' => $data['lead_edit_data'], + 'lastFiveYears' => $data['lastFiveYears'] ?? $this->getLastFiveFinancialYears(), + ]); } else { $data['lead_edit_data']['claims_details_html'] = ""; } @@ -5372,6 +5610,16 @@ class LeadsController extends BaseController { helper('excel_util_helper'); + $finyear = array_map(static function ($record) { + if (! is_array($record)) { + return $record; + } + + unset($record['nil_claims']); + + return $record; + }, $finyear); + $first = $finyear[0] ?? null; if (! is_array($first) || $first === []) { @@ -5844,8 +6092,11 @@ class LeadsController extends BaseController public function generateViewPageHtml($policy_type_id, $data = []) { - $data['insurer'] = $this->insurerBranchModel->getInsurerBranchesWithInsurerNames(); - $data['tpa'] = $this->tpaBranchModel->getTpaBranchesWithTpaNames(); + $data['insurer'] = $this->insurerBranchModel->getInsurerBranchesWithInsurerNames(); + $data['tpa'] = $this->tpaBranchModel->getTpaBranchesWithTpaNames(); + $data['lastFiveYears'] = $data['lastFiveYears'] ?? $this->getLastFiveFinancialYears(); + $data['gpaClaimType'] = $data['gpaClaimType'] ?? $this->claim_type_for_gpa; + $data['causeOfDeath'] = $data['causeOfDeath'] ?? $this->cause_of_death; $viewMap = [ 1 => 'rfq/gpa', @@ -6483,7 +6734,9 @@ class LeadsController extends BaseController if (! empty($rfq_data['fin_years_claims']) && $claim_history == 1) { - $claim_details = json_decode($rfq_data['fin_years_claims'], true) ?? []; + $claim_details = $this->sanitizeClaimDetailsForExport( + json_decode($rfq_data['fin_years_claims'], true) ?? [] + ); if (! empty($claim_details['finyear'])) { diff --git a/app/Views/leads_form.php b/app/Views/leads_form.php index b352748f..d6942deb 100644 --- a/app/Views/leads_form.php +++ b/app/Views/leads_form.php @@ -771,18 +771,7 @@ leadTypeBsedHideAndShow(lead_type, false, policy_type_id) - if (lead_type == 1) { - $('.claim-row').hide(); - } else { - $('.claim-row').show(); - if (policy_type_id == 1) { - $('.gpaClaimFileds').show(); - $('.lifeClaimFields').hide(); - } else if (policy_type_id == 6 || policy_type_id == 7) { - $('.gpaClaimFileds').hide(); - $('.lifeClaimFields').show(); - } - } + updateClaimRowVisibility(policy_type_id); if (lead_type != 1 && policy_type_id != 1 && policy_type_id != 6 && policy_type_id != 7) { // updateRenewalFields(dataIncrement); @@ -1161,11 +1150,9 @@ leadTypeBsedHideAndShow(lead_type) - if (lead_type == 1) { - $('.claim-row').hide(); - } else if (!shouldShowClaimHistorySwitch(lead_type, policy_type_id)) { - $('.claim-row').show(); + updateClaimRowVisibility(policy_type_id); + if (!shouldShowClaimHistorySwitch(lead_type, policy_type_id)) { if (policy_type_id == 1) { $('.gpaClaimFileds').show(); $('.lifeClaimFields').hide(); @@ -1775,6 +1762,11 @@ event.preventDefault(); + $('.claim-row').each(function() { + const isNil = $(this).find('.nil-claims-checkbox').prop('checked'); + $(this).find('.nil-claims-value').val(isNil ? '1' : '0'); + }); + if (typeof window.prepareLeadsFormForSubmit === 'function') { window.prepareLeadsFormForSubmit(); } @@ -1840,12 +1832,11 @@ const jsonString = JSON.stringify(salse_person_id); console.log('jsonString', jsonString); - // Append the JSON string to the FormData object formData.append('salse_person_id', jsonString); - // Convert the claim experience array to JSON const finyearJsonString = gatherClaimExperienceData(policy_type_ids); console.log('finyearJsonString', finyearJsonString); formData.append('finyear', finyearJsonString); + syncClaimHistoryFieldsToFormData(formData); let claimHistoryStatus = $("#claim_history").length > 0 && $("#claim_history").prop("checked") ? 1 : 0; formData.set('claim_history', claimHistoryStatus); @@ -2102,6 +2093,25 @@ $(".claim-row").each(function() { + let isNilClaims = $(this).find(".nil-claims-checkbox").prop("checked"); + + if (isNilClaims) { + let year = $(this).find("[name='first_year[]']").val(); + claimData.push({ + "year": year, + "emp_id": "Nil", + "emp_name": "Nil", + "gender": "Nil", + "designation": "Nil", + "sum_insured": "Nil", + "death_date": "Nil", + "cause_of_death": "Nil", + "settled": "Nil", + "nil_claims": 1, + }); + return; + } + let year = $(this).find("[name='first_year[]']").val(); let claimAmount = $(this).find("[name='first_claim_amount[]']").val(); let claimStatus = $(this).find("[name='first_claim_status[]']").val(); @@ -2125,6 +2135,7 @@ "death_date": deathDate, "cause_of_death": causeOfDeath, "settled": claimAmount, + "nil_claims": 0, }); }); @@ -2233,8 +2244,37 @@ return ['1', '6', '7'].includes(String(policyTypeId)); } + function getClaimHistoryLabel(leadType) { + return String(leadType) === '1' ? 'Mortality Claims' : 'Claims History'; + } + function shouldShowClaimHistorySwitch(leadType, policyTypeId) { - return (leadType == 2 || leadType == 3) && isClaimHistoryPolicyType(policyTypeId); + return ['1', '2', '3'].includes(String(leadType)) && isClaimHistoryPolicyType(policyTypeId); + } + + function updateClaimRowVisibility(fallbackPolicyTypeId = null) { + const leadType = $('#lead_type').val(); + let policyTypeId = fallbackPolicyTypeId; + + if (policyTypeId == null || policyTypeId === '') { + const $policySelect = $('[id^="policy_type_id_"]').first(); + policyTypeId = $policySelect.length ? $policySelect.val() : ''; + } + + if (!shouldShowClaimHistorySwitch(leadType, policyTypeId)) { + $('.claim-row').hide(); + return; + } + + if ($('#claim_history').length) { + if ($('#claim_history').prop('checked')) { + $('.claim-row').show(); + } else { + $('.claim-row').hide(); + } + } else { + $('.claim-row').show(); + } } function appendThreeYearsClaims(count) { @@ -2247,20 +2287,21 @@ let lead_type = $('#lead_type').val(); let showClaimHistorySwitch = shouldShowClaimHistorySwitch(lead_type, policy_type_id); + let claimHistoryLabel = getClaimHistoryLabel(lead_type); console.log('claimIndex from parent', claimIndex); let increment = claimIndex; let claimsFields = `${showClaimHistorySwitch && !document.querySelector('#claim_history') ? `
- +

` : ``}`; claimsFields += `
-
- +
+ +
+ + +
+
+ +
+
-
- +
+
-
- +
+
-
- +
+
-
- +
+
-
- +
+
-
- +
+
-
- +
+
@@ -2382,6 +2432,8 @@ if (showClaimHistorySwitch) { claimHistoryToggle(); + } else { + updateClaimRowVisibility(policy_type_id); } toggleRequiredFields(); @@ -2400,15 +2452,198 @@ } } + function isClaimRowNilClaims($row) { + return $row.find('.nil-claims-checkbox').prop('checked'); + } + + function setClaimSelectValue($select, value) { + if (!$select.length) { + return; + } + + if ($select.find('option[value="' + value + '"]').length === 0) { + $select.append($('
` - let referenceDiv = document.getElementById('appendAreaForClaim'); - referenceDiv.insertAdjacentHTML('beforeend', html); - - appendThreeYearsClaims(); - } + setupNonEbClaimDetailsSection(); // Hide loader $('.loader').fadeOut(); @@ -675,6 +668,11 @@ var pageBackButton = '" class="topbar-icon const finyearJsonString = gatherClaimExperienceData(); console.log('finyearJsonString', finyearJsonString); formData.append('fin_years_claims', finyearJsonString); + syncClaimHistoryFieldsToFormData(formData); cliam_history_status = $("#claim_history").prop("checked") ? 1 : 0; @@ -799,7 +798,7 @@ var pageBackButton = '" class="topbar-icon } - leadTypeBsedHideAndShow(value, true) + leadTypeBsedHideAndShow(value, true); $('#contact_person_summary').empty(); $('#contact_person_summary').append($('

${sectionTitle}

`; + + referenceDiv.insertAdjacentHTML('beforeend', html); + appendThreeYearsClaims(); + updateNonEbClaimRowVisibility(leadType); + } + + function leadTypeBsedHideAndShow(value, resetValues = false, skipClaimSetup = false) { var actual_lead_id = $('#actual_lead_id').val(); if (value == 1 || value == 3) { $('.btnDiv').show(); - $('.claim-row').hide(); + + if (!skipClaimSetup && shouldShowNonEbClaimHistory(value)) { + setupNonEbClaimDetailsSection(value); + } else if (!shouldShowNonEbClaimHistory(value)) { + $('#appendAreaForClaim').empty(); + $('.claim-row').hide(); + } $('.emp_title_text').text('No of Employees') @@ -950,7 +1008,10 @@ var pageBackButton = '" class="topbar-icon var increment = 1; + function isClaimRowNilClaims($row) { + return $row.find('.nil-claims-checkbox').prop('checked'); + } + + function setClaimSelectValue($select, value) { + if (!$select.length) { + return; + } + + if ($select.find('option[value="' + value + '"]').length === 0) { + $select.append($(' -
- +
+
+
- + + +
+ + +
+
+ +
+
-
- +
+
-
- +
+
-
- +
+
-
- +
+
-
- +
+
@@ -1241,7 +1459,10 @@ var pageBackButton = '" class="topbar-icon let claimData = []; + if ($("#claim_history").length > 0 && !$("#claim_history").prop("checked")) { + return JSON.stringify({ + "finyear": claimData + }); + } + $(".claim-row").each(function() { + let isNilClaims = $(this).find(".nil-claims-checkbox").prop("checked"); + + if (isNilClaims) { + let year = $(this).find("[name='first_year[]']").val(); + claimData.push({ + "year": year, + "policy_type": "Nil", + "date_of_loss": "Nil", + "claim_amount": "Nil", + "settled_amount": "Nil", + "cause_of_loss": "Nil", + "status": "Nil", + "nil_claims": 1, + }); + return; + } + let year = $(this).find("[name='first_year[]']").val(); let policyType = $(this).find("[name='first_policy_type_[]']").val(); let dateOfLoss = $(this).find("[name='first_date_of_loss_[]']").val(); @@ -1292,6 +1536,7 @@ var pageBackButton = '" class="topbar-icon function claimHistoryToggle() { cliam_history_status = $("#claim_history").prop("checked") ? 1 : 0; - // alert(cliam_history_status); + if (cliam_history_status == 1) { if ($(".claim-row").length > 0) { - // Rows already exist, just show them - $(".claim-row").show(); + $(".claim-row").show(); } else { - // No rows yet, so create them appendThreeYearsClaims(); } - $(".claim-input").attr("required", true); - } else { + $(".claim-row").each(function() { + const $row = $(this); + $row.find('[name="first_year[]"]').prop("required", true); + + if (!isClaimRowNilClaims($row)) { + $row.find(".claim-input").not('[name="first_year[]"]').prop("required", true); + } + }); + } else { $(".claim-row").hide(); - $(".claim-input").removeAttr("required"); // Required Attributes Remove - $(".claim-input").val(""); // Value Reset + $(".claim-row").each(function() { + const $row = $(this); + $row.find('.nil-claims-checkbox').prop('checked', false); + $row.find('.nil-claims-value').val('0'); + $row.removeClass('claim-row-nil'); + $row.find('.claim-required-star').show(); + }); + $(".claim-input").removeAttr("required").prop('disabled', false).val(""); $(".claim-input").each(function() { - $(this).parsley().reset(); // Validation Reset + if ($(this).hasClass('select2-hidden-accessible')) { + $(this).val(null).trigger('change'); + } + if ($(this).parsley) { + $(this).parsley().reset(); + } }); } - } $('#exixting_client').change(function () { @@ -1476,5 +1736,12 @@ var pageBackButton = ' \ No newline at end of file diff --git a/app/Views/rfq/claims_details_non_eb.php b/app/Views/rfq/claims_details_non_eb.php index 8f565ee0..3141be9b 100644 --- a/app/Views/rfq/claims_details_non_eb.php +++ b/app/Views/rfq/claims_details_non_eb.php @@ -1,55 +1,85 @@ - '', 'claim_amount' => '', 'status' => '', 'claim_type' => '', 'cause_of_death' => '', 'death_date' => ''] ]; += 4) ? $year : $year - 1; + $lastFiveYears = []; + + for ($i = 0; $i < 6; $i++) { + $startYear = $currentFYStart - $i; + $lastFiveYears[] = "{$startYear}-" . ($startYear + 1); + } + } + + $claims = ! empty($lead_edit_data['fin_years_claims_array']) + ? $lead_edit_data['fin_years_claims_array'] + : [['year' => '', 'claim_amount' => '', 'status' => '', 'policy_type' => '', 'date_of_loss' => '', 'cause_of_loss' => '']]; + $leadType = (int) ($lead_edit_data['lead_type'] ?? 0); + $showClaimsSection = in_array($leadType, [1, 2, 3], true); + $claimHistoryLabel = $leadType === 1 ? 'Mortality Claims' : 'Claims History'; ?> +
- /> - + /> +

$value) { ?> + foreach ($claims as $key => $value) { + $isNilClaimRow = ! empty($value['nil_claims']); + ?> -
-
- - $year"; - } ?> + $selected = ($year == $value['year']) ? 'selected' : ''; + echo ""; + } ?>
+
- - + + +
+ > + +
-
- - + +
+ + >
-
- - +
+ + >
-
- - +
+ + >
-
- - +
+ + >
-
- - +
+ + > +
+
+ + >
@@ -59,5 +89,24 @@
- - \ No newline at end of file + + + + diff --git a/app/Views/rfq/gpa.php b/app/Views/rfq/gpa.php index 7fe37fb4..21029eaa 100644 --- a/app/Views/rfq/gpa.php +++ b/app/Views/rfq/gpa.php @@ -42,16 +42,35 @@ = 4) ? $year : $year - 1; + $lastFiveYears = []; + + for ($i = 0; $i < 6; $i++) { + $startYear = $currentFYStart - $i; + $lastFiveYears[] = "{$startYear}-" . ($startYear + 1); + } + } + + if (! isset($causeOfDeath) || ! is_array($causeOfDeath)) { + $causeOfDeath = []; + } + $savedClaims = !empty($lead_edit_data['fin_years_claims_array']) ? $lead_edit_data['fin_years_claims_array'] : []; $isClaimHistoryChecked = (isset($lead_edit_data['claim_history']) && (int) $lead_edit_data['claim_history'] === 1) || !empty($savedClaims); $showClaimHistorySwitch = isset($lead_edit_data['lead_type'], $lead_edit_data['policy_type_id']) - && in_array((int) $lead_edit_data['lead_type'], [2, 3], true) + && in_array((int) $lead_edit_data['lead_type'], [1, 2, 3], true) && in_array((int) $lead_edit_data['policy_type_id'], [1, 6, 7], true); + $claimHistoryLabel = (isset($lead_edit_data['lead_type']) && (int) $lead_edit_data['lead_type'] === 1) + ? 'Mortality Claims' + : 'Claims History'; ?>
> - +

@@ -59,13 +78,15 @@ $claims = !empty($savedClaims) ? $savedClaims : [ ['year' => '', 'claim_amount' => '', 'status' => '', 'claim_type' => '', 'cause_of_death' => '', 'death_date' => ''] ]; - foreach ($claims as $key => $value) { ?> + foreach ($claims as $key => $value) { + $isNilClaimRow = !empty($value['nil_claims']); + ?> -
+
-
- -
- - + + +
+ > + +
+
+ +
+ + >
-
- - +
+ + >
-
- - > - + + + +
-
- - +
+ + >
-
- - +
+ + >
-
- - +
+ + >
-
- - > $death_value) { $selected = ($cause == $value['cause_of_death']) ? 'selected' : ''; echo ""; } ?> + + +
-
- - +
+ + >