CHANGE_OPPORTUITIES_CLAIM_HISTORY_SHOW_FOR_FRESH

This commit is contained in:
VENKATESHWARAN 2026-05-22 14:46:19 +05:30
parent 69160d8c52
commit 7fb8bac17f
7 changed files with 1139 additions and 265 deletions

View File

@ -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<string, mixed> $claimDetails
*
* @return array<string, mixed>
*/
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<array<string, mixed>>
*/
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<array<string, mixed>> $rows
*
* @return array<string, list<string>>
*/
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<array<string, mixed>> $rows
*
* @return array<string, list<string>>
*/
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<int, int> 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<int, int> $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'])) {

View File

@ -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') ? `<div class="custom-control custom-switch">
<input type="checkbox" onchange="claimHistoryToggle()" class="custom-control-input" id="claim_history" name="claim_history" checked>
<label class="custom-control-label" for="claim_history">Claims History</label>
<label class="custom-control-label" for="claim_history">${claimHistoryLabel}</label>
</div><br>` : ``}`;
claimsFields += `
<div class="row claim-row">
<div class="form-group col-md-2">
<label for="first_year_${increment}">Year<span class="text-danger">*</span></label>
<div class="form-group col-md-2 claim-year-group">
<label for="first_year_${increment}">Year<span class="text-danger claim-required-star">*</span></label>
<select class="form-control first_year_ claim-input" id="first_year_${increment}" name="first_year[]">
<option value="">Select Year</option>
<?php foreach ($lastFiveYears as $year) {
@ -2270,18 +2311,27 @@
</div>
<div class="form-group col-md-2">
<label for="emp_id_${increment}">Emp ID<span class="text-danger">*</span></label>
<label>Nil Claims</label>
<input type="hidden" class="nil-claims-value" name="nil_claims[]" value="0">
<div class="custom-control custom-checkbox" style="padding-top: 8px;">
<input type="checkbox" class="custom-control-input nil-claims-checkbox" id="nil_claims_${increment}" onchange="nilClaimsToggle(this)">
<label class="custom-control-label" for="nil_claims_${increment}">Nil Claims</label>
</div>
</div>
<div class="form-group col-md-2 claim-field-group">
<label for="emp_id_${increment}">Emp ID<span class="text-danger claim-required-star">*</span></label>
<input type="text" class="form-control claim-input" id="emp_id_${increment}" name="emp_id[]">
</div>
<div class="form-group col-md-2">
<label for="emp_name_${increment}">Employee Name<span class="text-danger">*</span></label>
<div class="form-group col-md-2 claim-field-group">
<label for="emp_name_${increment}">Employee Name<span class="text-danger claim-required-star">*</span></label>
<input type="text" class="form-control claim-input" id="emp_name_${increment}" name="emp_name[]">
</div>
<div class="form-group col-md-2">
<label for="gender_${increment}">Gender<span class="text-danger">*</span></label>
<div class="form-group col-md-2 claim-field-group">
<label for="gender_${increment}">Gender<span class="text-danger claim-required-star">*</span></label>
<select class="form-control claim-input" id="gender_${increment}" name="gender[]">
<option value="">Select Gender</option>
<option value="Female">Female</option>
@ -2289,26 +2339,26 @@
</select>
</div>
<div class="form-group col-md-2">
<label for="designation_${increment}">Designation <span class="text-danger">*</span></label>
<div class="form-group col-md-2 claim-field-group">
<label for="designation_${increment}">Designation <span class="text-danger claim-required-star">*</span></label>
<input type="text" class="form-control claim-input" id="designation_${increment}" name="designation[]">
</div>
<div class="form-group col-md-2">
<label for="sum_insured_${increment}">Sum Insured <span class="text-danger">*</span></label>
<div class="form-group col-md-2 claim-field-group">
<label for="sum_insured_${increment}">Sum Insured <span class="text-danger claim-required-star">*</span></label>
<input type="text" class="form-control claim-input" id="sum_insured_${increment}" name="sum_insured[]">
</div>
<div class="form-group col-md-2">
<label for="first_death_date_${increment}">Date of Death<span class="text-danger">*</span></label>
<div class="form-group col-md-2 claim-field-group">
<label for="first_death_date_${increment}">Date of Death<span class="text-danger claim-required-star">*</span></label>
<div class="input-icon">
<input type="text" class="form-control death_date flatpickr-date claim-input" id="first_death_date_${increment}" name="first_death_date[]" autocomplete="off">
<i class="mdi mdi-calendar-blank-outline additional-icon"></i>
</div>
</div>
<div class="form-group col-md-2">
<label for="first_cause_of_death_${increment}">Nature/Cause Of Death <span class="text-danger">*</span></label>
<div class="form-group col-md-2 claim-field-group">
<label for="first_cause_of_death_${increment}">Nature/Cause Of Death <span class="text-danger claim-required-star">*</span></label>
<select class="form-control claim-input" id="first_cause_of_death_${increment}" name="first_cause_of_death[]">
<option value="">Select Cause of Death</option>
<?php foreach ($causeOfDeath as $cause => $death_value) {
@ -2317,8 +2367,8 @@
</select>
</div>
<div class="form-group col-md-2">
<label for="first_claim_amount_${increment}">Claim/Settled Amount<span class="text-danger">*</span></label>
<div class="form-group col-md-2 claim-field-group">
<label for="first_claim_amount_${increment}">Claim/Settled Amount<span class="text-danger claim-required-star">*</span></label>
<input type="text" class="form-control claim-input" id="first_claim_amount_${increment}" name="first_claim_amount[]">
</div>
@ -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($('<option>', { value: value, text: value }));
}
$select.val(value);
if ($select.hasClass('select2-hidden-accessible')) {
$select.trigger('change');
}
}
function resetClaimYearField($yearField) {
if (!$yearField.length) {
return;
}
$yearField.find('option[value="Nil"]').remove();
if ($yearField.val() === 'Nil') {
$yearField.val('').trigger('change');
}
}
function nilClaimsToggle(checkbox) {
const $row = $(checkbox).closest('.claim-row');
const isNil = $(checkbox).prop('checked');
const $yearField = $row.find('[name="first_year[]"]');
resetClaimYearField($yearField);
$row.find('.nil-claims-value').val(isNil ? '1' : '0');
$row.toggleClass('claim-row-nil', isNil);
$row.find('.claim-field-group .claim-required-star').toggle(!isNil);
$row.find('.claim-input').not('[name="first_year[]"]').each(function() {
const $field = $(this);
if (isNil) {
if ($field.is('select')) {
setClaimSelectValue($field, 'Nil');
} else {
$field.val('Nil');
}
$field.prop('disabled', true).removeAttr('required');
if ($field.hasClass('select2-hidden-accessible')) {
$field.next('.select2-container').addClass('select2-container--disabled');
}
if ($field.parsley) {
$field.parsley().reset();
}
} else {
$field.prop('disabled', false);
if ($field.hasClass('select2-hidden-accessible')) {
$field.next('.select2-container').removeClass('select2-container--disabled');
}
if ($field.is('select')) {
$field.find('option[value="Nil"]').remove();
$field.val('').trigger('change');
} else {
$field.val('');
}
}
});
const claimHistoryOn = !$('#claim_history').length || $('#claim_history').prop('checked');
if (claimHistoryOn) {
$yearField.prop('required', true).prop('disabled', false);
if ($yearField.hasClass('select2-hidden-accessible')) {
$yearField.next('.select2-container').removeClass('select2-container--disabled');
}
if (!isNil) {
$row.find('.claim-input').not('[name="first_year[]"]').prop('required', true);
}
}
toggleRequiredFields();
if (typeof window.refreshLeadsFormValidation === 'function') {
window.refreshLeadsFormValidation();
}
}
function initNilClaimsRows() {
$('.claim-row .nil-claims-checkbox:checked').each(function() {
nilClaimsToggle(this);
});
}
function syncClaimHistoryFieldsToFormData(formData) {
const $rows = $('.claim-row');
if (!$rows.length) {
return;
}
const isEbRow = $rows.first().find('[name="emp_id[]"]').length > 0;
const fieldNames = isEbRow
? ['first_year[]', 'nil_claims[]', 'emp_id[]', 'emp_name[]', 'gender[]', 'designation[]', 'sum_insured[]', 'first_death_date[]', 'first_cause_of_death[]', 'first_claim_amount[]']
: ['first_year[]', 'nil_claims[]', 'first_policy_type_[]', 'first_date_of_loss_[]', 'first_cause_of_loss[]', 'first_claim_amount[]', 'first_settled_amount[]', 'first_claim_status[]'];
fieldNames.forEach(function(name) {
if (typeof formData.delete === 'function') {
formData.delete(name);
}
});
$rows.each(function() {
const $row = $(this);
const isNil = $row.find('.nil-claims-checkbox').prop('checked');
$row.find('.nil-claims-value').val(isNil ? '1' : '0');
formData.append('first_year[]', $row.find('[name="first_year[]"]').val() || '');
formData.append('nil_claims[]', isNil ? '1' : '0');
if (isEbRow) {
if (isNil) {
formData.append('emp_id[]', 'Nil');
formData.append('emp_name[]', 'Nil');
formData.append('gender[]', 'Nil');
formData.append('designation[]', 'Nil');
formData.append('sum_insured[]', 'Nil');
formData.append('first_death_date[]', 'Nil');
formData.append('first_cause_of_death[]', 'Nil');
formData.append('first_claim_amount[]', 'Nil');
} else {
formData.append('emp_id[]', $row.find('[name="emp_id[]"]').val() || '');
formData.append('emp_name[]', $row.find('[name="emp_name[]"]').val() || '');
formData.append('gender[]', $row.find('[name="gender[]"]').val() || '');
formData.append('designation[]', $row.find('[name="designation[]"]').val() || '');
formData.append('sum_insured[]', $row.find('[name="sum_insured[]"]').val() || '');
formData.append('first_death_date[]', $row.find('[name="first_death_date[]"]').val() || '');
formData.append('first_cause_of_death[]', $row.find('[name="first_cause_of_death[]"]').val() || '');
formData.append('first_claim_amount[]', $row.find('[name="first_claim_amount[]"]').val() || '');
}
} else if (isNil) {
formData.append('first_policy_type_[]', 'Nil');
formData.append('first_date_of_loss_[]', 'Nil');
formData.append('first_cause_of_loss[]', 'Nil');
formData.append('first_claim_amount[]', 'Nil');
formData.append('first_settled_amount[]', 'Nil');
formData.append('first_claim_status[]', 'Nil');
} else {
formData.append('first_policy_type_[]', $row.find('[name="first_policy_type_[]"]').val() || '');
formData.append('first_date_of_loss_[]', $row.find('[name="first_date_of_loss_[]"]').val() || '');
formData.append('first_cause_of_loss[]', $row.find('[name="first_cause_of_loss[]"]').val() || '');
formData.append('first_claim_amount[]', $row.find('[name="first_claim_amount[]"]').val() || '');
formData.append('first_settled_amount[]', $row.find('[name="first_settled_amount[]"]').val() || '');
formData.append('first_claim_status[]', $row.find('[name="first_claim_status[]"]').val() || '');
}
});
}
function claimHistoryToggle() {
let claimHistoryStatus = $("#claim_history").prop("checked") ? 1 : 0;
if (claimHistoryStatus == 1) {
$(".claim-row").show();
$(".claim-input").attr("required", true);
$(".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").val("");
$(".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() {
if ($(this).hasClass('select2-hidden-accessible')) {
$(this).val(null).trigger('change');
@ -2445,7 +2680,7 @@
if (value == 1) {
$('.btnDiv').show();
$('.claim-row').hide();
updateClaimRowVisibility(fallbackPolicyTypeId);
$('.emp_title_text').text('No of Employees')
$('.depnd_title_text').text('No of Dependents')
@ -2534,7 +2769,7 @@
} else {
$('.btnDiv').hide();
$('.claim-row').show();
updateClaimRowVisibility(fallbackPolicyTypeId);
$('.emp_title_text').text('No of Employees at Inception')
$('.depnd_title_text').text(' No of Dependents at Inception')
@ -2609,23 +2844,22 @@
function toggleRequiredFields() {
try {
const claimHistoryOn = !$('#claim_history').length || $('#claim_history').prop('checked');
$('.claim-row').each(function() {
var isRowHidden = $(this).css('display') === 'none';
var isNilClaims = isClaimRowNilClaims($(this));
$(this).find('.form-group').each(function() {
var input = $(this).find('input, select');
$(this).find('.claim-year-group .claim-input').prop('required', claimHistoryOn && !isRowHidden);
if (input.attr('name') === "gender[]") {
return;
}
$(this).find('.claim-field-group').each(function() {
var input = $(this).find('input.claim-input, select.claim-input');
if (input.length === 0) {
console.warn('No input/select fields found in:', this);
return;
}
// Remove required if row is hidden, otherwise check field visibility
input.prop('required', !isRowHidden && $(this).css('display') !== 'none');
input.prop('required', claimHistoryOn && !isRowHidden && !isNilClaims && $(this).css('display') !== 'none');
});
});
} catch (error) {

View File

@ -846,12 +846,22 @@ if (isset($selected_lead_type)) {
claimHistoryToggle();
}
if (typeof initNilClaimsRows === 'function') {
initNilClaimsRows();
}
if (typeof updateClaimRowVisibility === 'function') {
updateClaimRowVisibility(policy_type_id);
}
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
if (lead_type == 1 || lead_type == 3) {
if (lead_type == 1 || !shouldShowClaimHistorySwitch(lead_type, policy_type_id)) {
if (typeof updateClaimRowVisibility === 'function') {
updateClaimRowVisibility(policy_type_id);
} else if (!shouldShowClaimHistorySwitch(lead_type, policy_type_id)) {
$('.claim-row').hide();
}
@ -948,6 +958,14 @@ if (isset($selected_lead_type)) {
claimHistoryToggle();
}
if (typeof initNilClaimsRows === 'function') {
initNilClaimsRows();
}
if (typeof updateClaimRowVisibility === 'function') {
updateClaimRowVisibility(policy_type_id);
}
if(lead_type == 3){
let incurred_claim_date_id = 'incurred_claim_date';
@ -1121,7 +1139,7 @@ if (isset($selected_lead_type)) {
let policy_type_id = data.policy_type_id || null;
let lead_type = data.lead_type || null;
leadTypeBsedHideAndShow(lead_type);
$('#lead_type').val(lead_type || '');
const isExistingClient = data.client_id !== undefined
&& data.client_id !== null
@ -1192,7 +1210,6 @@ if (isset($selected_lead_type)) {
$('#leads_primarykey').val(data.id || '');
$('#actual_lead_id').val(data.actual_lead_id || 0);
$('#policy_start_date').val(data.policy_end_date || '');
$('#lead_type').val(data.lead_type || '');
$('#issuer').val(data.issuer || '');
$('#client_type').val(data.client_type || '');
$('#client_name').val(data.client_name || '');
@ -1253,9 +1270,23 @@ if (isset($selected_lead_type)) {
selecSalsePerson(data.salse_person_id);
}
leadTypeBsedHideAndShow(lead_type, false, Boolean(data.claims_details_html));
let referenceDiv = document.getElementById('appendAreaForClaim');
referenceDiv.innerHTML = '';
referenceDiv.insertAdjacentHTML('beforeend', data.claims_details_html);
referenceDiv.insertAdjacentHTML('beforeend', data.claims_details_html || '');
if (typeof initNilClaimsRows === 'function') {
initNilClaimsRows();
}
if (typeof updateNonEbClaimRowVisibility === 'function') {
updateNonEbClaimRowVisibility(lead_type);
} else if (typeof updateClaimRowVisibility === 'function') {
updateClaimRowVisibility(data.policy_type_id);
} else if (!data.claims_details_html && typeof setupNonEbClaimDetailsSection === 'function' && shouldShowNonEbClaimHistory(lead_type)) {
setupNonEbClaimDetailsSection(lead_type);
}
console.log("wdesfgefwregfefwregffeegf",data.lead_type);
var lead_type_value = data.lead_type;

View File

@ -647,14 +647,7 @@ var pageBackButton = '<a href="<?= base_url('leads/list') ?>" class="topbar-icon
console.log(response.message, 'WARNING');
}
if (lead_type != 1 && lead_type != 3) {
let html = `<hr><div class="form-row"> <div class="form-group col-md-3"><h4> Claim Details </h4></div></div>`
let referenceDiv = document.getElementById('appendAreaForClaim');
referenceDiv.insertAdjacentHTML('beforeend', html);
appendThreeYearsClaims();
}
setupNonEbClaimDetailsSection();
// Hide loader
$('.loader').fadeOut();
@ -675,6 +668,11 @@ var pageBackButton = '<a href="<?= base_url('leads/list') ?>" class="topbar-icon
event.preventDefault();
$('.claim-row').each(function() {
const isNil = $(this).find('.nil-claims-checkbox').prop('checked');
$(this).find('.nil-claims-value').val(isNil ? '1' : '0');
});
var isValid = $('#leads_non_eb_form_id').parsley().validate();
console.log('isValid', isValid)
@ -728,6 +726,7 @@ var pageBackButton = '<a href="<?= base_url('leads/list') ?>" 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 = '<a href="<?= base_url('leads/list') ?>" class="topbar-icon
});
$('#lead_type').change(function() {
let value = $(this).val()
let value = $(this).val();
// alert(value);
if (value == 1 || value == 3) {
// alert("Function Called");
@ -840,7 +839,7 @@ var pageBackButton = '<a href="<?= base_url('leads/list') ?>" class="topbar-icon
}
leadTypeBsedHideAndShow(value, true)
leadTypeBsedHideAndShow(value, true);
$('#contact_person_summary').empty();
$('#contact_person_summary').append($('<option>', {
@ -906,13 +905,72 @@ var pageBackButton = '<a href="<?= base_url('leads/list') ?>" class="topbar-icon
})
function leadTypeBsedHideAndShow(value, resetValues = false) {
function getClaimHistoryLabel(leadType) {
return String(leadType) === '1' ? 'Mortality Claims' : 'Claims History';
}
function getClaimDetailsSectionTitle(leadType) {
return String(leadType) === '1' ? 'Mortality Claims' : 'Claim Details';
}
function shouldShowNonEbClaimHistory(leadType) {
return ['1', '2', '3'].includes(String(leadType));
}
function updateNonEbClaimRowVisibility(leadTypeOverride) {
const leadType = leadTypeOverride ?? $('#lead_type').val();
if (!shouldShowNonEbClaimHistory(leadType)) {
$('.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 setupNonEbClaimDetailsSection(leadTypeOverride) {
const leadType = leadTypeOverride ?? $('#lead_type').val();
const referenceDiv = document.getElementById('appendAreaForClaim');
if (!referenceDiv) {
return;
}
referenceDiv.innerHTML = '';
if (!shouldShowNonEbClaimHistory(leadType)) {
return;
}
const sectionTitle = getClaimDetailsSectionTitle(leadType);
const html = `<hr><div class="form-row claim-details-section-header"><div class="form-group col-md-3"><h4>${sectionTitle}</h4></div></div>`;
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 = '<a href="<?= base_url('leads/list') ?>" class="topbar-icon
} else {
$('.btnDiv').hide();
$('.claim-row').show();
if (!skipClaimSetup && shouldShowNonEbClaimHistory(value)) {
setupNonEbClaimDetailsSection(value);
}
$('.emp_title_text').text('No of Employees at Inception')
$('.depnd_title_text').text(' No of Dependents at Inception')
@ -1178,11 +1239,158 @@ var pageBackButton = '<a href="<?= base_url('leads/list') ?>" 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($('<option>', { value: value, text: value }));
}
$select.val(value);
if ($select.hasClass('select2-hidden-accessible')) {
$select.trigger('change');
}
}
function resetClaimYearField($yearField) {
if (!$yearField.length) {
return;
}
$yearField.find('option[value="Nil"]').remove();
if ($yearField.val() === 'Nil') {
$yearField.val('').trigger('change');
}
}
function nilClaimsToggle(checkbox) {
const $row = $(checkbox).closest('.claim-row');
const isNil = $(checkbox).prop('checked');
const $yearField = $row.find('[name="first_year[]"]');
resetClaimYearField($yearField);
$row.find('.nil-claims-value').val(isNil ? '1' : '0');
$row.toggleClass('claim-row-nil', isNil);
$row.find('.claim-field-group .claim-required-star').toggle(!isNil);
$row.find('.claim-input').not('[name="first_year[]"]').each(function() {
const $field = $(this);
if (isNil) {
if ($field.is('select')) {
setClaimSelectValue($field, 'Nil');
} else {
$field.val('Nil');
}
$field.prop('disabled', true).removeAttr('required');
if ($field.hasClass('select2-hidden-accessible')) {
$field.next('.select2-container').addClass('select2-container--disabled');
}
if ($field.parsley) {
$field.parsley().reset();
}
} else {
$field.prop('disabled', false);
if ($field.hasClass('select2-hidden-accessible')) {
$field.next('.select2-container').removeClass('select2-container--disabled');
}
if ($field.is('select')) {
$field.find('option[value="Nil"]').remove();
$field.val('').trigger('change');
} else {
$field.val('');
}
}
});
const claimHistoryOn = !$('#claim_history').length || $('#claim_history').prop('checked');
if (claimHistoryOn) {
$yearField.prop('required', true).prop('disabled', false);
if ($yearField.hasClass('select2-hidden-accessible')) {
$yearField.next('.select2-container').removeClass('select2-container--disabled');
}
if (!isNil) {
$row.find('.claim-input').not('[name="first_year[]"]').prop('required', true);
}
}
if (typeof window.refreshLeadsFormValidation === 'function') {
window.refreshLeadsFormValidation();
}
}
function initNilClaimsRows() {
$('.claim-row .nil-claims-checkbox:checked').each(function() {
nilClaimsToggle(this);
});
}
function syncClaimHistoryFieldsToFormData(formData) {
const $rows = $('.claim-row');
if (!$rows.length) {
return;
}
const fieldNames = ['first_year[]', 'nil_claims[]', 'first_policy_type_[]', 'first_date_of_loss_[]', 'first_cause_of_loss[]', 'first_claim_amount[]', 'first_settled_amount[]', 'first_claim_status[]'];
fieldNames.forEach(function(name) {
if (typeof formData.delete === 'function') {
formData.delete(name);
}
});
$rows.each(function() {
const $row = $(this);
const isNil = $row.find('.nil-claims-checkbox').prop('checked');
$row.find('.nil-claims-value').val(isNil ? '1' : '0');
formData.append('first_year[]', $row.find('[name="first_year[]"]').val() || '');
formData.append('nil_claims[]', isNil ? '1' : '0');
if (isNil) {
formData.append('first_policy_type_[]', 'Nil');
formData.append('first_date_of_loss_[]', 'Nil');
formData.append('first_cause_of_loss[]', 'Nil');
formData.append('first_claim_amount[]', 'Nil');
formData.append('first_settled_amount[]', 'Nil');
formData.append('first_claim_status[]', 'Nil');
} else {
formData.append('first_policy_type_[]', $row.find('[name="first_policy_type_[]"]').val() || '');
formData.append('first_date_of_loss_[]', $row.find('[name="first_date_of_loss_[]"]').val() || '');
formData.append('first_cause_of_loss[]', $row.find('[name="first_cause_of_loss[]"]').val() || '');
formData.append('first_claim_amount[]', $row.find('[name="first_claim_amount[]"]').val() || '');
formData.append('first_settled_amount[]', $row.find('[name="first_settled_amount[]"]').val() || '');
formData.append('first_claim_status[]', $row.find('[name="first_claim_status[]"]').val() || '');
}
});
}
function appendThreeYearsClaims() {
const leadType = $('#lead_type').val();
const claimHistoryLabel = getClaimHistoryLabel(leadType);
let claimsFields = `${!document.querySelector('#claim_history') ? `<div class="custom-control custom-switch">
<input type="checkbox" onchange="claimHistoryToggle()" class="custom-control-input" id="claim_history" name="claim_history" checked />
<label class="custom-control-label" for="claim_history">Claims History</label>
<label class="custom-control-label" for="claim_history">${claimHistoryLabel}</label>
</div><br>`: ``}`
claimsFields += `
@ -1190,8 +1398,8 @@ var pageBackButton = '<a href="<?= base_url('leads/list') ?>" class="topbar-icon
<div id = "claimHistoryRow" class="row claim-row">
<div class="form-group col-md-2">
<label for="first_year_${increment}">Year<span class="text-danger">*</span></label>
<div class="form-group col-md-2 claim-year-group">
<label for="first_year_${increment}">Year<span class="text-danger claim-required-star">*</span></label>
<select class="form-control claim-input first_year_" id="first_year_${increment}" name="first_year[]">
<option value="">Select Year</option>
<?php foreach ($lastFiveYears as $year) {
@ -1199,28 +1407,38 @@ var pageBackButton = '<a href="<?= base_url('leads/list') ?>" class="topbar-icon
} ?>
</select>
</div>
<div class="form-group col-md-2">
<label for="first_policy_type_${increment}">Policy Type<span class="text-danger">*</span></label>
<label>Nil Claims</label>
<input type="hidden" class="nil-claims-value" name="nil_claims[]" value="0">
<div class="custom-control custom-checkbox" style="padding-top: 8px;">
<input type="checkbox" class="custom-control-input nil-claims-checkbox" id="nil_claims_${increment}" onchange="nilClaimsToggle(this)">
<label class="custom-control-label" for="nil_claims_${increment}">Nil Claims</label>
</div>
</div>
<div class="form-group col-md-2 claim-field-group">
<label for="first_policy_type_${increment}">Policy Type<span class="text-danger claim-required-star">*</span></label>
<input type="text" class="form-control claim-input" id="first_policy_type_${increment}" name="first_policy_type_[]">
</div>
<div class="form-group col-md-2">
<label for="first_date_of_loss_${increment}">Date of Loss<span class="text-danger">*</span></label>
<div class="form-group col-md-2 claim-field-group">
<label for="first_date_of_loss_${increment}">Date of Loss<span class="text-danger claim-required-star">*</span></label>
<input type="text" class="form-control loss_date claim-input" id="first_date_of_loss_${increment}" name="first_date_of_loss_[]">
</div>
<div class="form-group col-md-2">
<label for="first_cause_of_death_${increment}">Cause Of Loss <span class="text-danger">*</span></label>
<div class="form-group col-md-2 claim-field-group">
<label for="first_cause_of_loss_${increment}">Cause Of Loss <span class="text-danger claim-required-star">*</span></label>
<input type="text" class="form-control claim-input" id="first_cause_of_loss_${increment}" name="first_cause_of_loss[]">
</div>
<div class="form-group col-md-2">
<label for="first_claim_amount_${increment}">Claim Amount<span class="text-danger">*</span></label>
<div class="form-group col-md-2 claim-field-group">
<label for="first_claim_amount_${increment}">Claim Amount<span class="text-danger claim-required-star">*</span></label>
<input type="text" class="form-control claim-input" id="first_claim_amount_${increment}" name="first_claim_amount[]">
</div>
<div class="form-group col-md-2">
<label for="first_claim_amount_${increment}">Settled Amount<span class="text-danger">*</span></label>
<div class="form-group col-md-2 claim-field-group">
<label for="first_settled_amount_${increment}">Settled Amount<span class="text-danger claim-required-star">*</span></label>
<input type="text" class="form-control claim-input" id="first_settled_amount_${increment}" name="first_settled_amount[]">
</div>
<div class="form-group col-md-2">
<label for="first_claim_status_${increment}">Claim Status<span class="text-danger">*</span></label>
<div class="form-group col-md-2 claim-field-group">
<label for="first_claim_status_${increment}">Claim Status<span class="text-danger claim-required-star">*</span></label>
<input type="text" class="form-control claim-input" id="first_claim_status_${increment}" name="first_claim_status[]">
</div>
<div class="form-group col-md-2">
@ -1241,7 +1459,10 @@ var pageBackButton = '<a href="<?= base_url('leads/list') ?>" class="topbar-icon
let lastRow = $(".claim-row").last();
if (isChecked) {
lastRow.show();
lastRow.find(".claim-input").attr("required", true);
lastRow.find('[name="first_year[]"]').prop("required", true);
if (!isClaimRowNilClaims(lastRow)) {
lastRow.find(".claim-input").not('[name="first_year[]"]').prop("required", true);
}
} else {
lastRow.hide();
lastRow.find(".claim-input").removeAttr("required");
@ -1274,8 +1495,31 @@ var pageBackButton = '<a href="<?= base_url('leads/list') ?>" 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 = '<a href="<?= base_url('leads/list') ?>" class="topbar-icon
"settled_amount": settledAmount,
"cause_of_loss": causeOfLoss,
"status": claimStatus,
"nil_claims": 0,
});
});
@ -1309,26 +1554,41 @@ var pageBackButton = '<a href="<?= base_url('leads/list') ?>" 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 = '<a href="<?= base_url('leads/list') ?>" class="topbar-icon
$('#lost_reason').val("");
$('#lost_reason').removeAttr('required');
}
const initialLeadType = $('#lead_type').val();
const isEditLead = String($('#actual_lead_id').val() || '0') !== '0';
if (initialLeadType && !isEditLead) {
leadTypeBsedHideAndShow(initialLeadType, false);
}
});
</script>

View File

@ -1,55 +1,85 @@
<?php if(isset($lead_edit_data)) {
$claims = !empty($lead_edit_data['fin_years_claims_array']) ? $lead_edit_data['fin_years_claims_array'] : [ ['year' => '', 'claim_amount' => '', 'status' => '', 'claim_type' => '', 'cause_of_death' => '', 'death_date' => ''] ];
<?php if (isset($lead_edit_data)) {
if (! isset($lastFiveYears) || ! is_array($lastFiveYears)) {
$year = (int) date('Y');
$month = (int) date('m');
$currentFYStart = ($month >= 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';
?>
<?php if ($showClaimsSection) { ?>
<div class="custom-control custom-switch">
<input type="checkbox" onchange="claimHistoryToggle()" class="custom-control-input" id="claim_history" name="claim_history" <?= $lead_edit_data['claim_history'] == 1 ? "checked" : "" ?> />
<label class="custom-control-label" for="claim_history">Claims History</label>
<input type="checkbox" onchange="claimHistoryToggle()" class="custom-control-input" id="claim_history" name="claim_history" <?= $lead_edit_data['claim_history'] == 1 ? 'checked' : '' ?> />
<label class="custom-control-label" for="claim_history"><?= $claimHistoryLabel ?></label>
</div><br>
<?php
if ($lead_edit_data['claim_history'] == 1) {
foreach ($claims as $key => $value) { ?>
foreach ($claims as $key => $value) {
$isNilClaimRow = ! empty($value['nil_claims']);
?>
<div class="row claim-row">
<div class="form-group col-md-2">
<label for="first_year">Year<span class="text-danger">*</span></label>
<select class="form-control first_year_" id="first_year" name="first_year[]">
<div class="row claim-row<?= $isNilClaimRow ? ' claim-row-nil' : '' ?>">
<div class="form-group col-md-2 claim-year-group">
<label for="first_year_<?= $key ?>">Year<span class="text-danger claim-required-star">*</span></label>
<select class="form-control first_year_ claim-input" id="first_year_<?= $key ?>" name="first_year[]">
<option value="">Select Year</option>
<?php foreach ($lastFiveYears as $year) {
$selected = ($year == $value['year']) ? 'selected' : '';
echo "<option value='$year' $selected>$year</option>";
} ?>
$selected = ($year == $value['year']) ? 'selected' : '';
echo "<option value='$year' $selected>$year</option>";
} ?>
</select>
</div>
<div class="form-group col-md-2">
<label for="first_policy_type_${increment}">Policy Type<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="first_policy_type_${increment}" name="first_policy_type_[]"
value="<?= htmlspecialchars($value['policy_type']) ?>">
<label>Nil Claims</label>
<input type="hidden" class="nil-claims-value" name="nil_claims[]" value="<?= $isNilClaimRow ? '1' : '0' ?>">
<div class="custom-control custom-checkbox" style="padding-top: 8px;">
<input type="checkbox" class="custom-control-input nil-claims-checkbox" id="nil_claims_<?= $key ?>" onchange="nilClaimsToggle(this)"<?= $isNilClaimRow ? ' checked' : '' ?>>
<label class="custom-control-label" for="nil_claims_<?= $key ?>">Nil Claims</label>
</div>
</div>
<div class="form-group col-md-2">
<label for="first_date_of_loss_${increment}">Date of Loss<span class="text-danger">*</span></label>
<input type="text" class="form-control loss_date" id="first_date_of_loss_${increment}" name="first_date_of_loss_[]"
value="<?= htmlspecialchars($value['date_of_loss']) ?>">
<div class="form-group col-md-2 claim-field-group">
<label for="first_policy_type_<?= $key ?>">Policy Type<span class="text-danger claim-required-star"<?= $isNilClaimRow ? ' style="display:none;"' : '' ?>>*</span></label>
<input type="text" class="form-control claim-input" id="first_policy_type_<?= $key ?>" name="first_policy_type_[]"
value="<?= htmlspecialchars($value['policy_type'] ?? '') ?>"<?= $isNilClaimRow ? ' disabled' : '' ?>>
</div>
<div class="form-group col-md-2">
<label for="first_cause_of_death_${increment}">Cause Of Loss <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="first_cause_of_loss_${increment}" name="first_cause_of_loss[]"
value="<?= htmlspecialchars($value['cause_of_loss']) ?>">
<div class="form-group col-md-2 claim-field-group">
<label for="first_date_of_loss_<?= $key ?>">Date of Loss<span class="text-danger claim-required-star"<?= $isNilClaimRow ? ' style="display:none;"' : '' ?>>*</span></label>
<input type="text" class="form-control loss_date claim-input" id="first_date_of_loss_<?= $key ?>" name="first_date_of_loss_[]"
value="<?= htmlspecialchars($value['date_of_loss'] ?? '') ?>"<?= $isNilClaimRow ? ' disabled' : '' ?>>
</div>
<div class="form-group col-md-2">
<label for="first_claim_amount_${increment}">Claim Amount<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="first_claim_amount_${increment}" name="first_claim_amount[]"
value="<?= htmlspecialchars($value['claim_amount']) ?>">
<div class="form-group col-md-2 claim-field-group">
<label for="first_cause_of_loss_<?= $key ?>">Cause Of Loss <span class="text-danger claim-required-star"<?= $isNilClaimRow ? ' style="display:none;"' : '' ?>>*</span></label>
<input type="text" class="form-control claim-input" id="first_cause_of_loss_<?= $key ?>" name="first_cause_of_loss[]"
value="<?= htmlspecialchars($value['cause_of_loss'] ?? '') ?>"<?= $isNilClaimRow ? ' disabled' : '' ?>>
</div>
<div class="form-group col-md-2">
<label for="first_claim_amount_${increment}">Settled Amount<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="first_settled_amount_${increment}" name="first_settled_amount[]"
value="<?= htmlspecialchars($value['settled_amount']) ?>">
<div class="form-group col-md-2 claim-field-group">
<label for="first_claim_amount_<?= $key ?>">Claim Amount<span class="text-danger claim-required-star"<?= $isNilClaimRow ? ' style="display:none;"' : '' ?>>*</span></label>
<input type="text" class="form-control claim-input" id="first_claim_amount_<?= $key ?>" name="first_claim_amount[]"
value="<?= htmlspecialchars($value['claim_amount'] ?? '') ?>"<?= $isNilClaimRow ? ' disabled' : '' ?>>
</div>
<div class="form-group col-md-2">
<label for="first_claim_status_${increment}">Claim Status<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="first_claim_status_${increment}" name="first_claim_status[]"
value="<?= htmlspecialchars($value['status']) ?>">
<div class="form-group col-md-2 claim-field-group">
<label for="first_settled_amount_<?= $key ?>">Settled Amount<span class="text-danger claim-required-star"<?= $isNilClaimRow ? ' style="display:none;"' : '' ?>>*</span></label>
<input type="text" class="form-control claim-input" id="first_settled_amount_<?= $key ?>" name="first_settled_amount[]"
value="<?= htmlspecialchars($value['settled_amount'] ?? '') ?>"<?= $isNilClaimRow ? ' disabled' : '' ?>>
</div>
<div class="form-group col-md-2 claim-field-group">
<label for="first_claim_status_<?= $key ?>">Claim Status<span class="text-danger claim-required-star"<?= $isNilClaimRow ? ' style="display:none;"' : '' ?>>*</span></label>
<input type="text" class="form-control claim-input" id="first_claim_status_<?= $key ?>" name="first_claim_status[]"
value="<?= htmlspecialchars($value['status'] ?? '') ?>"<?= $isNilClaimRow ? ' disabled' : '' ?>>
</div>
<div class="form-group col-md-2">
<div class="" style="position: relative; top: 28px; float: right; text-align: end;">
@ -59,5 +89,24 @@
</div>
</div>
<?php } } ?>
<?php } ?>
<?php
}
}
?>
<script>
$(".loss_date").each(function () {
flatpickr(this, {
dateFormat: "d-m-Y",
});
});
if (typeof initNilClaimsRows === 'function') {
initNilClaimsRows();
}
if (typeof updateNonEbClaimRowVisibility === 'function') {
updateNonEbClaimRowVisibility();
}
</script>
<?php } ?>
<?php } ?>

View File

@ -42,16 +42,35 @@
<?php if(isset($lead_edit_data)) { ?>
<?php
if (! isset($lastFiveYears) || ! is_array($lastFiveYears)) {
$year = (int) date('Y');
$month = (int) date('m');
$currentFYStart = ($month >= 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';
?>
<?php if ($showClaimHistorySwitch) { ?>
<div class="custom-control custom-switch">
<input type="checkbox" onchange="claimHistoryToggle()" class="custom-control-input" id="claim_history" name="claim_history" <?= $isClaimHistoryChecked ? 'checked' : '' ?>>
<label class="custom-control-label" for="claim_history">Claims History</label>
<label class="custom-control-label" for="claim_history"><?= $claimHistoryLabel ?></label>
</div><br>
<?php } ?>
<div class="form-row" id="appendAreaForClaim_1">
@ -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']);
?>
<div class="row claim-row">
<div class="row claim-row<?= $isNilClaimRow ? ' claim-row-nil' : '' ?>">
<div class="form-group col-md-2">
<label for="first_year">Year<span class="text-danger">*</span></label>
<select class="form-control first_year_ claim-input" id="first_year" name="first_year[]">
<div class="form-group col-md-2 claim-year-group">
<label for="first_year_<?= $key ?>">Year<span class="text-danger claim-required-star">*</span></label>
<select class="form-control first_year_ claim-input" id="first_year_<?= $key ?>" name="first_year[]">
<option value="">Select Year</option>
<?php foreach ($lastFiveYears as $year) {
$selected = ($year == $value['year']) ? 'selected' : '';
@ -75,54 +96,69 @@
</div>
<div class="form-group col-md-2">
<label for="emp_id">Emp ID<span class="text-danger">*</span></label>
<input type="text" class="form-control claim-input" id="emp_id" name="emp_id[]" value="<?= htmlspecialchars(isset($value['emp_id']) ? $value['emp_id'] : '-' ) ?>">
<label>Nil Claims</label>
<input type="hidden" class="nil-claims-value" name="nil_claims[]" value="<?= $isNilClaimRow ? '1' : '0' ?>">
<div class="custom-control custom-checkbox" style="padding-top: 8px;">
<input type="checkbox" class="custom-control-input nil-claims-checkbox" id="nil_claims_<?= $key ?>" onchange="nilClaimsToggle(this)"<?= $isNilClaimRow ? ' checked' : '' ?>>
<label class="custom-control-label" for="nil_claims_<?= $key ?>">Nil Claims</label>
</div>
</div>
<div class="form-group col-md-2 claim-field-group">
<label for="emp_id_<?= $key ?>">Emp ID<span class="text-danger claim-required-star"<?= $isNilClaimRow ? ' style="display:none;"' : '' ?>>*</span></label>
<input type="text" class="form-control claim-input" id="emp_id_<?= $key ?>" name="emp_id[]" value="<?= htmlspecialchars(isset($value['emp_id']) ? $value['emp_id'] : '-' ) ?>"<?= $isNilClaimRow ? ' disabled' : '' ?>>
</div>
<div class="form-group col-md-2">
<label for="emp_name">Employee Name<span class="text-danger">*</span></label>
<input type="text" class="form-control claim-input" id="emp_name" name="emp_name[]" value="<?= htmlspecialchars(isset($value['emp_name']) ? $value['emp_name'] : '-' ) ?>">
<div class="form-group col-md-2 claim-field-group">
<label for="emp_name_<?= $key ?>">Employee Name<span class="text-danger claim-required-star"<?= $isNilClaimRow ? ' style="display:none;"' : '' ?>>*</span></label>
<input type="text" class="form-control claim-input" id="emp_name_<?= $key ?>" name="emp_name[]" value="<?= htmlspecialchars(isset($value['emp_name']) ? $value['emp_name'] : '-' ) ?>"<?= $isNilClaimRow ? ' disabled' : '' ?>>
</div>
<div class="form-group col-md-2">
<label for="gender">Gender<span class="text-danger">*</span></label>
<select class="form-control claim-input" id="gender" name="gender[]">
<div class="form-group col-md-2 claim-field-group">
<label for="gender_<?= $key ?>">Gender<span class="text-danger claim-required-star"<?= $isNilClaimRow ? ' style="display:none;"' : '' ?>>*</span></label>
<select class="form-control claim-input" id="gender_<?= $key ?>" name="gender[]"<?= $isNilClaimRow ? ' disabled' : '' ?>>
<option value="">Select Gender</option>
<option value="Female" <?= (isset($value['gender']) && $value['gender'] == 'Female') ? 'selected' : '' ?>>Female</option>
<option value="Male" <?= (isset($value['gender']) && $value['gender'] == 'Male') ? 'selected' : '' ?>>Male</option>
<option value="Male" <?= (isset($value['gender']) && $value['gender'] == 'Male') ? 'selected' : '' ?>>Male</option>
<?php if ($isNilClaimRow) { ?>
<option value="Nil" selected>Nil</option>
<?php } ?>
</select>
</div>
<div class="form-group col-md-2">
<label for="designation">Designation <span class="text-danger">*</span></label>
<input type="text" class="form-control claim-input" id="designation" name="designation[]" value="<?= htmlspecialchars(isset($value['designation']) ? $value['designation'] : '-' ) ?>">
<div class="form-group col-md-2 claim-field-group">
<label for="designation_<?= $key ?>">Designation <span class="text-danger claim-required-star"<?= $isNilClaimRow ? ' style="display:none;"' : '' ?>>*</span></label>
<input type="text" class="form-control claim-input" id="designation_<?= $key ?>" name="designation[]" value="<?= htmlspecialchars(isset($value['designation']) ? $value['designation'] : '-' ) ?>"<?= $isNilClaimRow ? ' disabled' : '' ?>>
</div>
<div class="form-group col-md-2">
<label for="sum_insured">Sum Insured <span class="text-danger">*</span></label>
<input type="text" class="form-control claim-input" id="sum_insured" name="sum_insured[]" value="<?= htmlspecialchars(isset($value['sum_insured']) ? $value['sum_insured'] : '-' ) ?>">
<div class="form-group col-md-2 claim-field-group">
<label for="sum_insured_<?= $key ?>">Sum Insured <span class="text-danger claim-required-star"<?= $isNilClaimRow ? ' style="display:none;"' : '' ?>>*</span></label>
<input type="text" class="form-control claim-input" id="sum_insured_<?= $key ?>" name="sum_insured[]" value="<?= htmlspecialchars(isset($value['sum_insured']) ? $value['sum_insured'] : '-' ) ?>"<?= $isNilClaimRow ? ' disabled' : '' ?>>
</div>
<div class="form-group col-md-2">
<label for="first_death_date">Date of Death<span class="text-danger">*</span></label>
<input type="text" class="form-control flatpickr-date claim-input" id="first_death_date" name="first_death_date[]" value="<?= htmlspecialchars($value['death_date']) ?>" autocomplete="off">
<div class="form-group col-md-2 claim-field-group">
<label for="first_death_date_<?= $key ?>">Date of Death<span class="text-danger claim-required-star"<?= $isNilClaimRow ? ' style="display:none;"' : '' ?>>*</span></label>
<input type="text" class="form-control flatpickr-date claim-input" id="first_death_date_<?= $key ?>" name="first_death_date[]" value="<?= htmlspecialchars($value['death_date'] ?? '') ?>" autocomplete="off"<?= $isNilClaimRow ? ' disabled' : '' ?>>
</div>
<div class="form-group col-md-2">
<label for="first_cause_of_death">Nature/Cause Of Death <span class="text-danger">*</span></label>
<select class="form-control claim-input" id="first_cause_of_death" name="first_cause_of_death[]">
<div class="form-group col-md-2 claim-field-group">
<label for="first_cause_of_death_<?= $key ?>">Nature/Cause Of Death <span class="text-danger claim-required-star"<?= $isNilClaimRow ? ' style="display:none;"' : '' ?>>*</span></label>
<select class="form-control claim-input" id="first_cause_of_death_<?= $key ?>" name="first_cause_of_death[]"<?= $isNilClaimRow ? ' disabled' : '' ?>>
<option value="">Select Cause of Death</option>
<?php foreach ($causeOfDeath as $cause => $death_value) {
$selected = ($cause == $value['cause_of_death']) ? 'selected' : '';
echo "<option value='$cause' $selected>$death_value</option>";
} ?>
<?php if ($isNilClaimRow) { ?>
<option value="Nil" selected>Nil</option>
<?php } ?>
</select>
</div>
<div class="form-group col-md-2">
<label for="first_claim_amount">Claim/Settled Amount<span class="text-danger">*</span></label>
<input type="text" class="form-control claim-input" id="first_claim_amount" name="first_claim_amount[]" value="<?= htmlspecialchars(isset($value['claim_amount']) ? $value['claim_amount'] : ( isset($value['settled']) ? $value['settled'] : '-' )) ?>">
<div class="form-group col-md-2 claim-field-group">
<label for="first_claim_amount_<?= $key ?>">Claim/Settled Amount<span class="text-danger claim-required-star"<?= $isNilClaimRow ? ' style="display:none;"' : '' ?>>*</span></label>
<input type="text" class="form-control claim-input" id="first_claim_amount_<?= $key ?>" name="first_claim_amount[]" value="<?= htmlspecialchars(isset($value['claim_amount']) ? $value['claim_amount'] : ( isset($value['settled']) ? $value['settled'] : '-' )) ?>"<?= $isNilClaimRow ? ' disabled' : '' ?>>
</div>
<!-- <div class="form-group col-md-2">
@ -165,5 +201,9 @@ flatpickr('.flatpickr-date', {
maxDate: 'today', // Optional: disable future dates
});
if (typeof initNilClaimsRows === 'function') {
initNilClaimsRows();
}
</script>

View File

@ -269,12 +269,12 @@ table.dataTable tbody td {
<td style="display: none;"><?php echo $row['insurer_name']; ?></td>
<td style="display: none;"><?php echo $row['tpa_name']; ?></td>
<td style="display: none;"><?php echo $row['policy_no']; ?></td>
<td style="display: none;"><?php echo isset($priorityType[$row['priority'] ?? 0]) ? $priorityType[$row['priority'] ?? 0] : ''; ?></td>
<td style="display: none;"><?php echo ($priorityType ?? [])[$row['priority'] ?? 0] ?? ''; ?></td>
<td style="display: none;"><?php echo $row['relationship']; ?></td>
<td style="display: none;"><?php echo $row['emp_mobile']; ?></td>
<td style="display: none;"><?php echo $row['emp_mail']; ?></td>
<td style="display: none;"><?php echo $row['emp_personal_mail']; ?></td>
<td style="display: none;"><?php echo isset($modeOFIntimate[$row['mode_of_intimation'] ?? '']) ? $modeOFIntimate[$row['mode_of_intimation']] : ''; ?></td>
<td style="display: none;"><?php echo ($modeOFIntimate ?? [])[$row['mode_of_intimation'] ?? ''] ?? ''; ?></td>
<td style="display: none;">
<?php
$typeId = $row['ticket_type_id'] ?? 0;