nhance/app/Views/leads_form.php

2110 lines
99 KiB
PHP

<style>
.readonly-color {
background-color: #e0e0e0;
/* Darker background */
color: #666;
/* Darker text color */
}
.readonly-select {
pointer-events: none;
background-color: #f0f0f0;
color: #666;
}
</style>
<style>
hr.solid {
border-top: 3px solid #bbb;
}
.select2-hidden-accessible+.select2-container .select2-dropdown {
display: none !important;
}
.select2-container .select2-selection--multiple .select2-selection__choice {
color: #000000;
}
.select2-selection__choice {
background-color: #0a8794 !important;
color: white !important;
font-weight: bold;
}
.select2-selection__choice__remove {
color: white !important;
margin-right: 5px;
}
</style>
<div class="row" id="leads_form" style="display:none;">
<div class="col-12">
<div class="card">
<div class="card-body">
<div class="row" style="margin-bottom:1rem;">
<div class="col-6" style="align-self: center;">
<h4 id="page_title" style="position: relative;">Add Lead</h4>
</div>
<div class="col-3" style="text-align: right; position: relative; left: 211px;">
<!-- <button class="btn btn-primary waves-effect waves-light" onclick="fileupload(this)">file upload</button> -->
</div>
<div class="col-1" style="text-align: right; position: relative; left: 193px;">
<a href="<?= base_url('leads/list') ?>" type="button" id="btnAdd"
class="btn btn-primary waves-effect waves-light">Back</a>
</div>
</div>
<form role="form" class="parsley-examples" method="post" id="leads_form_id"
enctype="multipart/form-data">
<input type="hidden" name="id" id="leads_primarykey">
<div class="form-row">
<div class="form-group col-md-3">
<label for="lead_type">Lead Type<span class="text-danger">*</span></label>
<select class="form-control" id="lead_type" name="lead_type" required>
<option value="">Select Lead Type</option>
<?php
if (isset($lead_type) && count($lead_type)) {
foreach ($lead_type as $key => $value) {
if ($key == 1) {
echo "<option value=" . $key . " selected>" . $value . "</option>";
} else {
echo "<option value=" . $key . ">" . $value . "</option>";
}
}
}
?>
</select>
</div>
<div class="form-group col-md-3">
<label for="issuer">Issuer<span class="text-danger">*</span></label>
<select class="form-control" id="issuer" name="issuer" required>
<option value="">Select Issuer</option>
<?php
if (isset($issuer) && count($issuer)) {
foreach ($issuer as $key => $value) {
echo "<option value=" . $key . ">" . $value . "</option>";
}
}
?>
</select>
</div>
</div>
<hr>
<!-- client row -->
<div class="form-row" id="freshDiv">
<div class="form-group col-md-3">
<label for="client_type">Client Type<span class="text-danger">*</span></label>
<select class="form-control" id="client_type" name="client_type" required>
<option value="">Select Client type</option>
<?php
if (isset($client_type) && count($client_type)) {
foreach ($client_type as $key => $value) {
echo "<option value='" . $key . "' >" . $value . "</option>";
}
}
?>
</select>
</div>
<div class="form-group col-md-3">
<label for="entity_type_id">Entity Type<span class="text-danger">*</span></label>
<select class="form-control" id="entity_type_id" name="entity_type_id" required>
<option value="" selected>Select Entity</option>
<?php
if (isset($entity) && count($entity)) {
foreach ($entity as $key => $value) {
echo "<option value=" . $value['id'] . ">" . $value['name'] . "</option>";
}
}
?>
</select>
</div>
<div class="form-group col-md-3">
<label for="client_name">Client Name<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="client_name" name="client_name"
placeholder="Enter Client Name" required>
</div>
<div class="form-group col-md-3">
<label for="client_short_name">Client Short Name<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="client_short_name" name="client_short_name"
placeholder="Enter Client Short Name" required>
</div>
</div>
<div class="form-row" id="renewalDiv" style="display: none;">
<div class="form-group col-md-3">
<label for="client_id">Client<span class="text-danger">*</span></label>
<select class="form-control" id="client_id" name="client_id">
<option value="">Select Client</option>
</select>
</div>
<div class="form-group col-md-3">
<label for="client_branch_id">Branch<span class="text-danger">*</span></label>
<select class="form-control" id="client_branch_id" name="client_branch_id"
onchange="getBranchData(this)">
<option value="">Select Branch</option>
</select>
</div>
<div class="form-group col-md-3">
<label for="source_policy_id"> Source Policy <span id="base_danger"
class="text-danger">*</span></label>
<select class="form-control" id="source_policy_id" name="source_policy_id">
<option value="" selected>Select Source Policy</option>
</select>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-3">
<label for="pan">PAN<span class="text-danger"></span></label>
<input type="text" class="form-control" id="pan" placeholder="Enter PAN Number" data-parsley-error-message="Invalid PAN Number. Example: ABCDE1234F" name="pan" data-parsley-trigger="change" data-parsley-pattern="^[A-Z]{5}[0-9]{4}[A-Z]$">
</div>
</div>
<!-- end client row -->
<hr>
<!-- branch row-->
<div class="form-row">
<div class="form-group col-md-3">
<label for="gst">GST<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="gst" placeholder="Enter GST Number"
data-parsley-error-message="Invalid GST Number. Example: 12ABCDE1234F5Z6" name="gst"
data-parsley-trigger="change"
data-parsley-pattern="^\d{2}[A-Z]{5}\d{4}[A-Z]{1}[A-Z\d]{1}[Z]{1}[A-Z\d]{1}$" required>
</div>
<div class="form-group col-md-3">
<label for="client_branch">Branch Name<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="branch_name" name="branch_name"
placeholder="Enter Branch Name" required>
</div>
<div class="form-group col-md-3">
<label for="client_branch">Branch Code<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="branch_code" name="branch_code"
placeholder="Enter Branch Code" required>
</div>
<div class="form-group col-md-3">
<label for="client_branch">Contact Person Name<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="contact_person_name" name="contact_person_name"
placeholder="Enter Contact Name" required>
</div>
<div class="form-group col-md-3">
<label for="contact_person_mobile">Contact Person Mobile<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="contact_person_mobile" name="contact_person_mobile"
placeholder="Enter Contact Mobile" required>
</div>
<div class="form-group col-md-3">
<label for="contact_person_email">Contact Person Email<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="contact_person_email" name="contact_person_email"
placeholder="Enter Contact Email" required>
</div>
</div>
<!-- policy row -->
<div id="dynamic-form-container"></div>
<hr>
<!-- other row -->
<div class="form-row">
<div class="form-group col-md-3">
<label for="salse_person_id">Sales Person<span class="text-danger">*</span></label>
<select class="form-control" id="salse_person_id" name="salse_person_id" multiple required>
<option value="">Select Sales Person</option>
<?php if (isset($salse_team)) { ?>
<?php foreach ($salse_team as $value) { ?>
<option value="<?= $value['id']; ?>">
<?= $value['first_name']; ?>
</option>
<?php } ?>
<?php } ?>
</select>
</div>
<div class="form-group col-md-3">
<label for="status"> Status <span id="base_danger" class="text-danger">*</span></label>
<select class="form-control" id="lead_status" name="status" required>
<option value="" selected>Select Status</option>
<?php
if (isset($lead_status) && count($lead_status)) {
foreach ($lead_status as $key => $value) {
if ($key == 'queued') {
echo "<option value=" . $key . " selected>" . $value . "</option>";
} else {
echo "<option value=" . $key . ">" . $value . "</option>";
}
}
}
?>
</select>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-12">
<label for="notes">Note</label>
<textarea class="form-control" id="notes" name="notes" rows="4"></textarea>
</div>
</div>
<div class="form-group text-right m-b-0" id="submitButton">
<button type="submit" class="btn btn-primary waves-effect waves-light mr-1"
id="btnSubmit">Submit</button>
</div>
</form>
</div>
</div>
</div>
</div><!-- end form row -->
<script>
let claimIndex = 1;
setTimeout(() => {
var policyStart = $(".policy_start_date");
var policyEnd = $(".policy_end_date");
if (policyStart.length === 0 || policyEnd.length === 0) {
console.log("Elements still not found after delay.");
return;
}
console.log("Elements found, setting IDs...");
var lead_type = $('#lead_type').val();
var increment = 1;
var start_date_id = lead_type == "1" ? `policy_start_date_${increment}` : "policy_start_date";
var end_date_id = lead_type == "1" ? `policy_end_date_${increment}` : "policy_end_date";
policyStart.attr("id", start_date_id);
$("label[for='policy_start_date'], label[for^='policy_start_date_']").attr("for", start_date_id);
policyEnd.attr("id", end_date_id);
$("label[for='policy_end_date'], label[for^='policy_end_date_']").attr("for", end_date_id);
}, 3000);
</script>
<script>
let edit_function_Called = 0;
//SELECT2 document ready function
$(document).ready(function() {
$("#lead_type").change(function() {
$("input, select").removeClass("readonly-select");
$("input, select").removeAttr("readonly");
// 5.3'+increment);
var lead_type = $(this).val();
var increment = 1; // Example increment value (modify as needed)
var start_date_id = lead_type == "1" ? `policy_start_date_${increment}` : "policy_start_date";
var end_date_id = lead_type == "1" ? `policy_end_date_${increment}` : "policy_end_date";
$(".policy_start_date").attr("id", start_date_id);
// $("label[for]").attr("for", start_date_id);
$(".policy_end_date").attr("id", end_date_id);
// $("label[for]").attr("for", end_date_id);
// $('#leads_form_id')[0].reset();
// console.log("Updated ID:", newId);
if (lead_type == 1) {
var policy_start_datePicker = flatpickr("#policy_start_date_" + increment, {
dateFormat: "d/m/Y",
allowInput: false,
onChange: function(selectedDates) {
var policy_end_date = new Date(selectedDates[0]);
policy_end_date.setFullYear(policy_end_date.getFullYear() + 1);
policy_end_date.setDate(policy_end_date.getDate() - 1); // Set end date to last day of selected year
policy_end_datePicker.setDate(policy_end_date);
console.log('this object', this);
console.log('id of this element:', this.element);
console.log('id of this element:', this.element.id);
let increment = this.element.id.split('_').pop();
console.log(increment); // Outputs: 1
console.log('increment', increment);
console.log('policy_start_datePicker selectedDates', selectedDates);
console.log('policy_start_datePicker incurred_claim_date_', $("#incurred_claim_date_" + increment).val());
// Recalculate policy_run_days if incurred claim date is already selected
if ($("#incurred_claim_date_" + increment).val()) {
console.log('policy_start_datePicker selectedDates', selectedDates);
calculatePolicyRunDays(increment);
}
}
});
}
var policy_end_datePicker = flatpickr("#policy_end_date_" + increment, {
dateFormat: "d/m/Y",
allowInput: false
});
});
console.log('increment count for insurer and tpa ',increment);
$('#insurer_'+increment).select2();
$('#tpa_'+increment).select2();
addHTMLInput();
// var lead_type = $("#lead_type").val();
// if (lead_type == 1) {
// var policy_start_datePicker = flatpickr("#policy_start_date_" + increment, {
// dateFormat: "d/m/Y",
// allowInput: false,
// onChange: function(selectedDates) {
// var policy_end_date = new Date(selectedDates[0]);
// policy_end_date.setFullYear(policy_end_date.getFullYear() + 1);
// policy_end_date.setDate(policy_end_date.getDate() - 1); // Set end date to last day of selected year
// policy_end_datePicker.setDate(policy_end_date);
// console.log('this object', this);
// console.log('id of this element:', this.element);
// console.log('id of this element:', this.element.id);
// let increment = this.element.id.split('_').pop();
// console.log(increment); // Outputs: 1
// console.log('increment', increment);
// console.log('policy_start_datePicker selectedDates', selectedDates);
// console.log('policy_start_datePicker incurred_claim_date_', $("#incurred_claim_date_" + increment).val());
// // Recalculate policy_run_days if incurred claim date is already selected
// if ($("#incurred_claim_date_" + increment).val()) {
// console.log('policy_start_datePicker selectedDates', selectedDates);
// calculatePolicyRunDays(increment);
// }
// }
// });
// }
// var policy_end_datePicker = flatpickr("#policy_end_date_" + increment, {
// dateFormat: "d/m/Y",
// allowInput: false
// });
// getURLParamsForReport()
setTimeout(function() {
$("textarea.select2-search__field").attr('rows', '1');
$("textarea.select2-search__field").css('resize', 'none');
}, 1000)
$('.first_year_').select2();
$("[id*='first_year']").select2();
$("[id*='claim_type']").select2();
$("[id*='first_casue_of_death_']").select2();
$('#insurer_'+increment).select2();
$('#tpa_'+increment).select2();
$('#proposed_insurer').select2();
$('#proposed_tpa').select2();
// $('#source_policy_id').on('change', function() {
// alert();
// let client_policy_id = $(this).val();
// console.log('client_policy_id', client_policy_id)
// getPolicyData(client_policy_id, increment)
// })
})
//DATE document ready function
// $(document).ready(function(){
// var today = new Date();
// var policy_start_date = flatpickr(".policy_start_date", {
// dateFormat: "d/m/Y",
// // defaultDate: today,
// allowInput: false,
// onChange: function(selectedDates, dateStr, instance) {
// var policy_end_date = new Date(selectedDates[0]);
// policy_end_date.setFullYear(policy_end_date.getFullYear() + 1);
// policy_end_date.setDate(policy_end_date.getDate() - 1); // Set end date to last day of selected year
// policy_end_datePicker.setDate(policy_end_date);
// }
// });
// // Calculate the end date (today + 1 year)
// // var closeDate = new Date(today);
// // closeDate.setFullYear(closeDate.getFullYear() + 1);
// // closeDate.setDate(closeDate.getDate() - 1); // Set end date to last day of next year
// var policy_end_datePicker = flatpickr(".policy_end_date", {
// dateFormat: "d/m/Y",
// // defaultDate: closeDate,
// allowInput: false
// });
// })
//---------------------------------------------------------------------------------------------------------
//view and edit Lead data function
function getLeadsDataForEdit(input) {
edit_function_Called += 1;
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
$('#leads_form_id')[0].reset();
var id = input;
console.log('Selected Leads:', id);
$.ajax({
url: '<?= base_url("leads/list/") ?>' + id,
type: "GET",
dataType: 'json',
success: function(res) {
$('.btnDiv').hide();
// $('.btnDiv1').hide();
console.log('getLeadsDataForEdit', res);
if (res.status == true) {
hide_list_show_add();
var page_title = 'Edit Lead';
$('#page_title').text(page_title);
$('#leads_primarykey').val(res.data.id);
console.log('policy start date : ' + res.data.policy_end_date);
$('#policy_start_date').val(res.data.policy_end_date);
$('#lead_type').val(res.data.lead_type);
$('#issuer').val(res.data.issuer);
$('#client_type').val(res.data.client_type);
$('#client_name').val(res.data.client_name);
$('#client_short_name').val(res.data.client_short_name);
$('#entity_type_id').val(res.data.entity_type_id);
$('#lead_status').val(res.data.status);
$('#notes').val(res.data.notes);
setTimeout(function() {
$('#client_id').val(res.data.client_id).change();
setTimeout(function() {
$('#client_branch_id').val(res.data.client_branch_id).change();
setTimeout(function() {
$('#source_policy_id').val(res.data.source_policy_id);
$('#pan').val(res.data.pan);
$('#gst').val(res.data.gst);
$('#branch_name').val(res.data.branch_name);
$('#branch_code').val(res.data.branch_code);
$('#contact_person_name').val(res.data.contact_person_name);
$('#contact_person_mobile').val(res.data.contact_person_mobile);
$('#contact_person_email').val(res.data.contact_person_email);
// $('#policy_type_id_1_'+random_number).val(res.data.policy_type_id).trigger('change');
$('select[id^="policy_type_id_1_"]').val(res.data.policy_type_id).trigger('change');
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
}, 1000)
}, 1000);
}, 1000);
var insurer = res.data.insurer_branch_id + '-' + res.data.insurer_id;
var tpa = res.data.tpa_branch_id + '-' + res.data.tpa_id;
var proposed_insurer = res.data.proposed_insurer_branch_id + '-' + res.data.proposed_insurer_id;
var proposed_tpa = res.data.proposed_tpa_branch_id + '-' + res.data.proposed_tpa_id;
$('#insurer_1').val(insurer).select2();
$('#tpa_1').val(tpa).select2();
$('#proposed_insurer_1').val(proposed_insurer).select2();
$('#proposed_tpa_1').val(proposed_tpa).select2();
$('#policy_start_date_1').val(res.data.policy_start_date);
$('#policy_end_date_1').val(res.data.policy_end_date);
$('#no_of_lives').val(res.data.no_of_lives);
$('#location').val(res.data.location);
let increment = 1;
// Other fields, set dynamically based on increment
$('#renewal_emp_count_' + increment).val(res.data.renewal_emp_count);
$('#renewal_dept_count_' + increment).val(res.data.renewal_dept_count);
$('#renewal_no_of_lives_' + increment).val(res.data.renewal_no_of_lives);
$('#incept_emp_count_' + increment).val(res.data.incept_emp_count);
$('#incept_dept_count_' + increment).val(res.data.incept_dept_count);
$('#incept_no_of_lives_' + increment).val(res.data.incept_no_of_lives);
$('#exp_emp_count_' + increment).val(res.data.exp_emp_count);
$('#exp_dept_count_' + increment).val(res.data.exp_dept_count);
$('#exp_no_of_lives_' + increment).val(res.data.exp_no_of_lives);
$('#incurred_claim_date_' + increment).val(res.data.incurred_claims_date);
$('#paid_claims_' + increment).val(res.data.paid_claims);
$('#outstanding_claims_' + increment).val(res.data.outstanding_claims);
$('#policy_run_days_' + increment).val(res.data.policy_run_days);
$('#premium_at_inception_' + increment).val(res.data.premium_at_inception);
$('#premium_date_' + increment).val(res.data.premium_date);
$('#earned_premium_' + increment).val(res.data.earned_premium);
$('#annualised_claims_' + increment).val(res.data.annualised_claims);
$('#incurred_claims_ratio_' + increment).val(res.data.incurred_claims_ratio);
$('#earned_claims_ratio_' + increment).val(res.data.earned_claims_ratio);
$('#incurred_claims_' + increment).val(res.data.incurred_claims);
$('#file_name_display').text('Upload File Name : ' + res.data.file_name);
// $('#file_name').val(res.data.file_name);
$('#total_si_at_incept_' + increment).val(res.data.total_si_at_incept);
$('#total_si_at_renewal_' + increment).val(res.data.total_si_at_renewal);
if (res.data.salse_person_id) {
selecSalsePerson(res.data.salse_person_id);
}
if (res.data.lead_type == 2) {
$('#renewalDiv').find('select, input').attr('required', 'required');
$('#freshDiv').find('select, input').removeAttr('required');
$('#renewalDiv').show();
$('#freshDiv').hide();
$('.proposed_div').show().find('select, input').attr('required', 'required');
$('#policy_end_date, #policy_start_date, #claim').removeAttr('required');
// $('.freashDiv').show()
$('.renewalDiv').hide()
$('.emp_title').text('No of Employees at Inception')
$('.depnd_title').text(' No of Dependents at Inception')
$('.total_title').text('Total Lives at Inception')
} else {
$('#renewalDiv').find('select, input').removeAttr('required');
$('#freshDiv').find('select, input').attr('required', 'required');
$('#renewalDiv').hide();
$('#freshDiv').show();
$('.proposed_div').hide().find('select, input').removeAttr('required');
if (res.data.lead_type == 1) {
$('.freashDiv').hide()
$('.renewalDiv').show()
$('.emp_title').text('No of Employees')
$('.depnd_title').text('No of Dependents')
$('.total_title').text('Total Lives')
} else {
// $('.freashDiv').show()
$('.renewalDiv').hide()
$('.emp_title').text('No of Employees at Inception')
$('.depnd_title').text(' No of Dependents at Inception')
$('.total_title').text('Total Lives at Inception')
}
}
if (res.data.policy_type_id != 2) {
$('.gpa_hide_div_' + increment).hide();
$('.gpa_show_div_' + increment).show();
$('.gpa_div_elements_' + increment).show();
$('.emp_title').text('No of Employees at Inception');
let claimExperience = JSON.parse(res.data.fin_years_claims);
// console.table(claimExperience);
let id = $('[id^="policy_type_id_1_"]').attr('id');
let random_number = id.match(/\d+$/)[0]; // Gets the numbers at the end
// return false;
console.log("below is the data", claimExperience);
var policy = res.data.policy_type_id;
$('#appendArea').empty();
console.log('length', claimExperience.length);
// $('policy_type_id_1_'+random_number).change(function (){
for (var i = 0; i < claimExperience.length; i++) {
console.log('loop count ',i);
appendThreeYearsClaims(random_number,policy);
}
// });
claimExperience.forEach((finyearObj, finyearIndex) => {
// Using finyearIndex + 1 instead of index + 1
let rowIndex = finyearIndex + 1;
finyearObj.finyear.forEach((data) => {
console.log('data', data);
let yearField = $(`#first_year_${rowIndex}_${policy}_${random_number}`);
let claimAmountField = $(`#first_claim_amount_${rowIndex}_${policy}_${random_number}`);
let claimStatusField = $(`#first_claim_status_${rowIndex}_${policy}_${random_number}`);
let causeOfDeathField = $(`#first_casue_of_death_${rowIndex}_${policy}_${random_number}`);
let deathDateField = $(`#first_death_date_${rowIndex}_${policy}_${random_number}`);
let claimType = $(`#claim_type_${rowIndex}_${policy}_${random_number}`);
console.log('rowIndex trying to find', rowIndex);
console.log('policy trying to find', policy);
console.log('random number trying to find', random_number);
console.log('year field',yearField);
if (yearField.length) {
yearField.val(data.year || '').trigger('change');
// Or if using Select2:
// yearField.select2('val', data.year || '');
}
if (claimAmountField.length) claimAmountField.val(data.claim_amount || '');
if (claimStatusField.length) claimStatusField.val(data.status || '');
if (causeOfDeathField.length) {
causeOfDeathField.val(data.cause_of_death || '').trigger('change');
}
if (deathDateField.length) deathDateField.val(data.death_date || '');
if (claimType.length) {
claimType.val(data.claim_type || '').trigger('change');
}
});
});
} else {
$('.gpa_hide_div_' + increment).show();
}
} else {
console.log('No data found');
}
},
error: function(xhr, status, error) {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
console.error(xhr.responseText);
console.error(status, error);
}
});
}
//client branch data
function getBranchData(input) {
var client_branch_id = $(input).val();
if (client_branch_id) {
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
$.ajax({
url: '<?php echo base_url('util/get_client_branch_data/'); ?>' + client_branch_id,
type: "GET",
dataType: 'json',
success: function(res) {
console.log('getBranchData response', res);
if (res.status == true) {
$('#gst').val(res.data.gst);
$('#pan').val(res.data.pan);
$('#branch_name').val(res.data.branch_name);
$('#branch_code').val(res.data.branch_code);
$('#contact_person_name').val(res?.contact?.name || '');
$('#contact_person_mobile').val(res?.contact?.mobile || '');
$('#contact_person_email').val(res?.contact?.email || '');
$('#pan').prop('readOnly', true);
$('#gst').prop('readOnly', true);
$('#branch_name').prop('readOnly', true);
$('#branch_code').prop('readOnly', true);
$('#contact_person_name').prop('readOnly', true);
$('#contact_person_mobile').prop('readOnly', true);
$('#contact_person_email').prop('readOnly', true);
// $('#policy_type_id_1').prop('readOnly', true);
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
} else {
$('#gst').val('');
$('#pan').val('');
$('#branch_name').val('');
$('#branch_code').val('');
$('#contact_person_name').val('');
$('#contact_person_mobile').val('');
$('#contact_person_email').val('');
console.log(res.message, 'warning');
}
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
}
});
}
}
// Client Policy Data
function getPolicyData(client_policy_id, increment_count, random_id) {
console.log('client_policy_id', client_policy_id);
console.log('increment_count', increment);
if (client_policy_id) {
// Show loader
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
$.ajax({
url: '<?php echo base_url('client/policy/list/'); ?>' + client_policy_id,
type: "GET",
dataType: 'json',
success: function(res) {
console.log('getPolicyData response:', res);
if (res.status === true && res.data) {
for (let i = 1; i <= increment_count; i++) {
$(`#policy_type_id_${i}_${random_id}`).removeClass('readonly-select ').select2();
$(`#insurer_${i}`).removeClass('readonly-select ').select2();
$(`#tpa_${i}`).removeClass('readonly-select ').select2();
console.log('Updating fields for row:', i);
const insurer = `${res.data.insurer_branch_id}-${res.data.insurer_id}`;
const tpa = `${res.data.tpa_branch_id}-${res.data.tpa_id}`;
console.log('policy data', res);
// Update fields with response data
$(`#policy_type_id_${i}_${random_id}`).val(res.data.policy_type_id).trigger('change');
$(`#insurer_${i}`).val(insurer).trigger('change');
$(`#tpa_${i}`).val(tpa).trigger('change');
$(`#proposed_insurer_${i}`).val(insurer).trigger('change');
$(`#proposed_tpa_${i}`).val(tpa).trigger('change');
$('#policy_start_date').val(res.new_start_date);
$('#policy_end_date').val(res.end_date);
console.log($(`#policy_type_id_${i}_${random_id}`));
console.log($(`#insurer_${i}`));
console.log($(`#tpa_${i}`));
$("#policy_end_date").prop('readOnly', true);
$("#policy_start_date").prop("readOnly", true);
$(`#policy_type_id_${i}_${random_id}`).addClass('readonly-select ').select2('destroy');
$(`#insurer_${i}`).addClass('readonly-select ').select2('destroy');
$(`#tpa_${i}`).addClass('readonly-select ').select2('destroy');
$(`#proposed_insurer_${i}`).addClass('readonly-select ').select2('destroy');
$(`#proposed_tpa_${i}`).addClass('readonly-select ').select2('destroy');
}
} else {
console.warn('Invalid response:', res.message || 'Unknown error');
// Reset fields if response is invalid
for (let i = 1; i <= increment_count; i++) {
$(`#policy_type_id_${i}_${random_id}`).val('').trigger('change');
$(`#insurer_${i}`).val('').trigger('change');
$(`#tpa_${i}`).val('').trigger('change');
$(`#proposed_insurer_${i}`).val('').trigger('change');
$(`#proposed_tpa_${i}`).val('').trigger('change');
}
}
// Hide loader
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
},
error: function(xhr, status, error) {
console.error('AJAX Error:', xhr.responseText || error);
// Reset fields on error
for (let i = 1; i <= increment_count; i++) {
$(`#policy_type_id_${i}_${random_id}`).val('').trigger('change');
$(`#insurer_${i}`).val('').trigger('change');
$(`#tpa_${i}`).val('').trigger('change');
$(`#proposed_insurer_${i}`).val('').trigger('change');
$(`#proposed_tpa_${i}`).val('').trigger('change');
}
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
}
});
} else {
console.warn('Client policy ID is required.');
// Reset fields if no client policy ID is provided
for (let i = 1; i <= increment_count; i++) {
$(`#policy_type_id_${i}_${random_id}`).val('').trigger('change');
$(`#insurer_${i}`).val('').trigger('change');
$(`#tpa_${i}`).val('').trigger('change');
$(`#proposed_insurer_${i}`).val('').trigger('change');
$(`#proposed_tpa_${i}`).val('').trigger('change');
}
}
}
// Salse team user list data
function selecSalsePerson(salse_person_ids) {
salse_person_ids = JSON.parse(salse_person_ids);
// Loop through each insurer-branch combination
$.each(salse_person_ids, function(index, value) {
// Use value in the format 'branch_id-insurer_id'
$('#salse_person_id option').each(function() {
if ($(this).val() === value) {
$(this).prop('selected', true); // Select the matching option
}
});
});
// Trigger change for plugins (like Select2)
$('#salse_person_id').trigger('change');
}
//---------------------------------------------------------------------------------------------------------
var increment = 1;
function generateRandomNumber() {
let randomNumber = Math.floor(Math.random() * 90)
return randomNumber;
}
function addHTMLInput(check = null) {
random = generateRandomNumber();
console.log('random for div', random)
const container = document.getElementById('dynamic-form-container');
const newRow = document.createElement('div');
newRow.className = 'form-row dynamic-form-row';
const newRow2 = document.createElement('div');
newRow2.className = 'form-row dynamic-form-row freashDiv2';
const newRow3 = document.createElement('div');
newRow3.className = 'form-row dynamic-form-row';
const newRow4 = document.createElement('div');
newRow4.className = 'form-row dynamic-form-row freashDiv';
const newRow5 = document.createElement('div');
newRow5.className = 'form-row dynamic-form-row';
const newRow7 = document.createElement('div');
newRow7.className = 'form-row dynamic-form-row';
const newRow8 = document.createElement('div');
newRow8.className = 'form-row dynamic-form-row';
const newRow6 = document.createElement('div');
newRow6.className = `form-row dynamic-form-row gpa_div_elements_${increment}`;
newRow6.style.display = 'none';
const newRow9 = document.createElement('div');
newRow9.className = `form-row dynamic-form-row gpa_div_elements_${increment}`;
newRow9.style.display = 'none';
const newRow10 = document.createElement('div');
newRow10.className = `form-row dynamic-form-row gpa_div_elements_${increment}`;
newRow10.style.display = 'none';
const newRow11 = document.createElement('div');
newRow11.className = `form-row dynamic-form-row gpa_div_elements_${increment}`;
newRow11.style.display = 'none';
const emptyDiv = document.createElement("div");
emptyDiv.className = "form-row dynamic-form-row emptyDiv"; // Optional clas
// Add an <hr> element
const hrElement = document.createElement('hr');
container.appendChild(hrElement);
// Main div
newRow.innerHTML += `
<div class="form-group col-md-3">
<label for="policy_type_id">Policy Type <span class="text-danger">*</span></label>
<select class="form-control" id="policy_type_id_${increment}_${random}" name="policy_type_id[]" onchange="showGpaColumns(this,${random})" required>
<option value="">Select Policy Type</option>
<?php
if (isset($policy_type) && count($policy_type)) {
foreach ($policy_type as $value) {
echo "<option value='" . $value['id'] . "'>" .
$value['policy_type'] .
"</option>";
}
}
?>
</select>
</div>
<div class="form-group col-md-3 proposed_div">
<label for="insurer">Insurer <span class="text-danger"></span></label>
<select class="form-control" id="insurer_${increment}" name="insurer[]" onchange="insurerChange(this, ${increment})">
<option value="">Select Insurer</option>
<?php if (isset($insurer)) { ?>
<?php foreach ($insurer as $value) { ?>
<option value="<?= $value['id'] . '-' . $value['insurer_id'] ?>">
<?= $value['insurer_name'] . '-' . $value['branch_code'] ?>
</option>
<?php } ?>
<?php } ?>
</select>
</div>
<div class="form-group col-md-3 proposed_div">
<label for="tpa">TPA <span class="text-danger"></span></label>
<select class="form-control" id="tpa_${increment}" name="tpa[]" onchange="tpaChange(this, ${increment})">
<option value="">Select TPA</option>
<?php if (isset($tpa)) { ?>
<?php foreach ($tpa as $value) { ?>
<option value="<?= $value['id'] . '-' . $value['tpa_id'] ?>">
<?= $value['tpa_short_name'] . '-' . $value['branch_code'] ?>
</option>
<?php } ?>
<?php } ?>
</select>
</div>
<div class="form-group col-md-3">
<label for="">Date of Commencement <span class="text-danger"></span></label>
<input type="text" class="form-control policy_start_date" id="" name="policy_start_date[]" placeholder="Enter DOC">
</div>
<div class="form-group col-md-3">
<label for="">Date of Expiry <span class="text-danger"></span></label>
<input type="text" class="form-control policy_end_date" id="" name="policy_end_date[]" placeholder="Enter DOE">
</div>
`;
// Incured claim div
newRow8.innerHTML += `
<div class="form-group col-md-3 freashDiv" style="display: none;">
<label for="incurred_claim_date_${increment}">Incurred Claim Date<span class="text-danger"></span></label>
<input type="text" class="form-control incurred_claim" id="incurred_claim_date_${increment}" name="incurred_claim_date[]" placeholder="Enter DOE">
</div>
<div class="form-group col-md-3 freashDiv" style="display: none;">
<label for="paid_claims_${increment}">Paid Claims<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="paid_claims_${increment}" name="paid_claims[]" placeholder="Enter Paid Claims" oninput="incurredClaimSum(this)">
</div>
<div class="form-group col-md-3 freashDiv" style="display: none;">
<label for="outstanding_claims_${increment}">Outstanding Claims<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="outstanding_claims_${increment}" name="outstanding_claims[]" placeholder="Enter Outstanding Claims" oninput="incurredClaimSum(this)">
</div>
<div class="form-group col-md-3 freashDiv" style="display: none;">
<label for="incurred_claims_${increment}">Incurred Claim<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="incurred_claims_${increment}" name="incurred_claims[]" placeholder="Enter Incurred Claim" oninput="incurredClaimSum(this)">
</div>
<div class="form-group col-md-3 freashDiv" style="display: none;">
<label for="policy_run_days_${increment}">Policy Run Days<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="policy_run_days_${increment}" name="policy_run_days[]" placeholder="Enter Policy Run Days" oninput="earnedPremiumCalc(this)" onkeyup="incurredClaimSum(this)">
</div>
<div class="form-group col-md-3 freashDiv" style="display: none;">
<label for="premium_at_inception_${increment}">Premium Paid at Inception<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="premium_at_inception_${increment}" name="premium_at_inception[]" placeholder="Enter Premium Paid" oninput="earnedPremiumCalc(this)">
</div>
<div class="form-group col-md-3 freashDiv" style="display: none;">
<label for="premium_date_${increment}">Premium Date<span class="text-danger"></span></label>
<input type="text" class="form-control" id="premium_date_${increment}" name="premium_date[]" placeholder="Enter Premium Date">
</div>
<div class="form-group col-md-3 freashDiv" style="display: none;">
<label for="earned_premium_${increment}">Earned Premium<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="earned_premium_${increment}" name="earned_premium[]" placeholder="Enter Earned Premium" oninput="incurredClaimSum(this)">
</div>
<div class="form-group col-md-3 freashDiv" style="display: none;">
<label for="annualised_claims_${increment}">Annualised Claims<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="annualised_claims_${increment}" name="annualised_claims[]" placeholder="Enter Annualised Claims" >
</div>
<div class="form-group col-md-3 freashDiv" style="display: none;">
<label for="incurred_claims_ratio_${increment}">Incurred Claims Ratio<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="incurred_claims_ratio_${increment}" name="incurred_claims_ratio[]" placeholder="Enter Incurred Claims Ratio" >
</div>
<div class="form-group col-md-3 freashDiv" style="display: none;">
<label for="earned_claims_ratio_${increment}">Earned Claims Ratio<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="earned_claims_ratio_${increment}" name="earned_claims_ratio[]" placeholder="Enter Earned Claims Ratio" >
</div>
<div class="form-group col-md-3 freashDiv">
<label for="location">Location <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="location" name="location[]" placeholder="Enter Location" >
</div>
<div class="form-group col-md-3 proposed_div" style="display: none;">
<label for="proposed_insurer">Proposed Insurer <span class="text-danger"></span></label>
<select class="form-control" id="proposed_insurer_${increment}" name="proposed_insurer[]">
<option value="">Select Insurer</option>
<?php if (isset($insurer)) { ?>
<?php foreach ($insurer as $value) { ?>
<option value="<?= $value['id'] . '-' . $value['insurer_id'] ?>">
<?= $value['insurer_name'] . '-' . $value['branch_code'] ?>
</option>
<?php } ?>
<?php } ?>
</select>
</div>
<div class="form-group col-md-3 proposed_div" style="display: none;">
<label for="proposed_tpa">Proposed TPA <span class="text-danger"></span></label>
<select class="form-control" id="proposed_tpa_${increment}" name="proposed_tpa[]">
<option value="">Select TPA</option>
<?php if (isset($tpa)) { ?>
<?php foreach ($tpa as $value) { ?>
<option value="<?= $value['id'] . '-' . $value['tpa_id'] ?>">
<?= $value['tpa_short_name'] . '-' . $value['branch_code'] ?>
</option>
<?php } ?>
<?php } ?>
</select>
</div>
`;
//renewal div
newRow2.innerHTML += `
<div class="form-group col-md-3">
<label for="renewal_emp_count_${increment}"> No of Employees at Renewal <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="renewal_emp_count_${increment}" name="renewal_emp_count[]" placeholder="Enter Lives" >
</div>
<div class="form-group col-md-3 gpa_hide_div_${increment}" style="display:none;">
<label for="renewal_dept_count_${increment}"> No of Dependents at Renewal <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="renewal_dept_count_${increment}" name="renewal_dept_count[]" placeholder="Enter Lives" >
</div>
<div class="form-group col-md-3 gpa_hide_div_${increment}" style="display:none;">
<label for="renewal_no_of_lives_${increment}"> Total Lives at Renewal <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="renewal_no_of_lives_${increment}" name="renewal_no_of_lives[]" placeholder="Enter Lives" >
</div>
<div class="form-group col-md-3 gpa_show_div_${increment}" style="display:none;">
<label for="total_si_at_renewal_${increment}"> Total Sum Insured at Renewal <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="total_si_at_renewal_${increment}" name="total_si_at_renewal[]" placeholder="Enter Lives" >
</div>
`;
//inception div
newRow3.innerHTML += `
<div class="form-group col-md-3">
<label for="incept_emp_count_${increment}" class="emp_title"> No of Employees at Inception <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="incept_emp_count_${increment}" name="incept_emp_count[]" placeholder="Enter Lives" >
</div>
<div class="form-group col-md-3 gpa_hide_div_${increment}" style="display:none;">
<label for="incept_dept_count_${increment}" class="depnd_title"> No of Dependents at Inception <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="incept_dept_count_${increment}" name="incept_dept_count[]" placeholder="Enter Lives" >
</div>
<div class="form-group col-md-3 gpa_hide_div_${increment}" style="display:none;">
<label for="incept_no_of_lives_${increment}" class="total_title"> Total Lives at Inception <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="incept_no_of_lives_${increment}" name="incept_no_of_lives[]" placeholder="Enter Lives" >
</div>
<div class="form-group col-md-3 gpa_show_div_${increment}" style="display:none;">
<label for="total_si_at_incept_${increment}" class="total_title"> Total Sum Insured at Inception <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="total_si_at_incept_${increment}" name="total_si_at_incept[]" placeholder="Enter Lives" >
</div>
`;
//expiry div
newRow4.innerHTML += `
<div class="form-group col-md-3">
<label for="exp_emp_count_${increment}"> No of Employees at Expiry <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="exp_emp_count_${increment}" name="exp_emp_count[]" placeholder="Enter Lives" >
</div>
<div class="form-group col-md-3">
<label for="exp_dept_count_${increment}"> No of Dependents at Expiry <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="exp_dept_count_${increment}" name="exp_dept_count[]" placeholder="Enter Lives" >
</div>
<div class="form-group col-md-3">
<label for="exp_no_of_lives_${increment}"> Total Lives at Expiry <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="exp_no_of_lives_${increment}" name="exp_no_of_lives[]" placeholder="Enter Lives" >
</div>
`;
//file upload div
newRow7.innerHTML += `
<div class="form-group col-md-3">
<label for="file_upload">File Upload<span class="text-danger">*</span></label>
<input type="file" class="form-control" id="file_name_${increment}" name="file_name[]" accept=".xls,.xlsx">
<span class="text-danger" id="file_name_display"></span>
</div>
`;
newRow9.innerHTML += `<div class="form-group col-md-3"><h5>Claims Experience for last 3 Years </h5></div>`;
//Last 3 years claims expirence div
// newRow6.innerHTML += `
// <div class="form-group col-md-3">
// <label for="first_year_${increment}">Year<span class="text-danger">*</span></label>
// <input type="text" class="form-control" id="first_year_${increment}" name="first_year[]">
// </div>
// <div class="form-group col-md-3">
// <label for="first_claim_amount_${increment}">Claim Amount / Settled Amount<span class="text-danger">*</span></label>
// <input type="text" class="form-control" id="first_claim_amount_${increment}" name="first_claim_amount[]">
// </div>
// <div class="form-group col-md-3">
// <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[]">
// </div>
// <div class="form-group col-md-3">
// <label for="first_casue_of_death_${increment}">Nature / Casue Of Death <span class="text-danger">*</span></label>
// <input type="text" class="form-control" id="first_casue_of_death_${increment}" name="first_casue_of_death[]">
// </div>
// <div class="form-group col-md-3">
// <label for="first_death_date_${increment}">Date of Death<span class="text-danger">*</span></label>
// <input type="text" class="form-control" id="first_death_date_${increment}" name="first_death_date[]">
// </div>
// `;
// //Last 3 years claims expirence div
// newRow10.innerHTML += `
// <div class="form-group col-md-3">
// <label for="second_year_${increment}">Year<span class="text-danger">*</span></label>
// <input type="text" class="form-control" id="second_year_${increment}" name="second_year[]">
// </div>
// <div class="form-group col-md-3">
// <label for="second_claim_amount_${increment}">Claim Amount / Settled Amount<span class="text-danger">*</span></label>
// <input type="text" class="form-control" id="second_claim_amount_${increment}" name="second_claim_amount[]">
// </div>
// <div class="form-group col-md-3">
// <label for="second_claim_status_${increment}">Claim Status<span class="text-danger">*</span></label>
// <input type="text" class="form-control" id="second_claim_status_${increment}" name="second_claim_status[]">
// </div>
// <div class="form-group col-md-3">
// <label for="second_casue_of_death_${increment}">Nature / Casue Of Death <span class="text-danger">*</span></label>
// <input type="text" class="form-control" id="second_casue_of_death_${increment}" name="second_casue_of_death[]">
// </div>
// <div class="form-group col-md-3">
// <label for="second_death_date_${increment}">Date of Death<span class="text-danger">*</span></label>
// <input type="text" class="form-control" id="second_death_date_${increment}" name="second_death_date[]">
// </div>
// `;
// //Last 3 years claims expirence div
// newRow11.innerHTML += `
// <div class="form-group col-md-3">
// <label for="third_year_${increment}">Year<span class="text-danger">*</span></label>
// <input type="text" class="form-control" id="third_year_${increment}" name="third_year[]">
// </div>
// <div class="form-group col-md-3">
// <label for="third_claim_amount_${increment}">Claim Amount / Settled Amount<span class="text-danger">*</span></label>
// <input type="text" class="form-control" id="third_claim_amount_${increment}" name="third_claim_amount[]">
// </div>
// <div class="form-group col-md-3">
// <label for="third_claim_status_${increment}">Claim Status<span class="text-danger">*</span></label>
// <input type="text" class="form-control" id="third_claim_status_${increment}" name="third_claim_status[]">
// </div>
// <div class="form-group col-md-3">
// <label for="third_casue_of_death_${increment}">Nature / Casue Of Death <span class="text-danger">*</span></label>
// <input type="text" class="form-control" id="third_casue_of_death_${increment}" name="third_casue_of_death[]">
// </div>
// <div class="form-group col-md-3">
// <label for="third_death_date_${increment}">Date of Death<span class="text-danger">*</span></label>
// <input type="text" class="form-control" id="third_death_date_${increment}" name="third_death_date[]">
// </div>
// `;
//button div
// newRow5.innerHTML += `
// <div class="form-group col-md-12 btnDiv1" style="position: relative;top: 28px;float: right;text-align: end;">
// <a class="btn btn-danger waves-effect waves-light" onclick="removeClaim(this)">x</a>
// <a class="btn btn-primary waves-effect waves-light mr-1" onclick="appendThreeYearsClaims()">+</a>
// </div>
// <div class="form-group col-md-12 btnDiv" style="position: relative;top: 28px;float: right;text-align: end;">
// <a class="btn btn-danger waves-effect waves-light" onclick="removeHTMLInput(this)">x</a>
// <a class="btn btn-primary waves-effect waves-light mr-1" onclick="addHTMLInput(1)">+</a>
// </div>
// `;
newRow5.innerHTML += `
<div class="form-group col-md-12 btnDiv" style="position: relative;top: 28px;float: right;text-align: end;">
<a class="btn btn-danger waves-effect waves-light" onclick="removeHTMLInput(this)">x</a>
<a class="btn btn-primary waves-effect waves-light mr-1" onclick="addHTMLInput(1)">+</a>
</div>
`;
emptyDiv.innerHTML += `<div id="appendArea_${random}" class = "form-group col-md-12 appendArea"></div>`;
container.appendChild(newRow);
container.appendChild(newRow8);
const hrElement2 = document.createElement('hr');
container.appendChild(hrElement2);
//inception div
container.appendChild(newRow3);
//renewal div
container.appendChild(newRow2);
//expiry div
container.appendChild(newRow4);
const hrElement3 = document.createElement('hr');
hrElement3.className = "gpa_div_elements"; // Set class to hrElement3
container.appendChild(hrElement3); // Append hrElement3 to container
container.appendChild(newRow9);
//Last 3 years claims expirence div
// container.appendChild(newRow6);
// container.appendChild(newRow10);
// container.appendChild(newRow11);
// appendThreeYearsClaims(random, 1);
console.log('div from addhtml',emptyDiv);
container.appendChild(emptyDiv);
//file upload div
container.appendChild(newRow7);
//button div
container.appendChild(newRow5);
var lead_type = $('#lead_type').val();
if (lead_type == 2) {
// $('.proposed_div').show().find('select, input').attr('required', 'required');
$('.proposed_div').show();
// $('.freashDiv').show()
$('.renewalDiv').hide()
$('.emp_title').text('No of Employees at Inception')
$('.depnd_title').text(' No of Dependents at Inception')
$('.total_title').text('Total Lives at Inception')
$('.gpa_div_elements').show();
} else {
// $('.proposed_div').hide().find('select, input').removeAttr('required');
$('.proposed_div').hide()
$('.gpa_div_elements').hide();
if (lead_type == 1) {
$('.freashDiv').hide()
$('.renewalDiv').show()
$('.emp_title').text('No of Employees')
$('.depnd_title').text('No of Dependents')
$('.total_title').text('Total Lives')
} else {
// $('.freashDiv').show()
$('.renewalDiv').hide()
$('.emp_title').text('No of Employees at Inception')
$('.depnd_title').text(' No of Dependents at Inception')
$('.total_title').text('Total Lives at Inception')
$('.gpa_div_elements').show();
}
}
// Scroll the newly added select into view and focus on it
// const newPolicyTypeSelect = document.getElementById(`policy_type_id_${increment}`);
// newPolicyTypeSelect.scrollIntoView({
// behavior: 'smooth',
// block: 'end'
// });
// newPolicyTypeSelect.focus();
$('#insurer_' + increment).select2();
$('#tpa_' + increment).select2();
console.log('tpa ',$('#tpa_'+increment));
$('#proposed_insurer_' + increment).select2();
$('#proposed_tpa_' + increment).select2();
$('#policy_type_id_' + increment + '_' + random).select2();
console.log('policy _type div',$('#policy_type_id_' + increment + '_' + random));
lead_type = $('#lead_type').val();
console.log('increment date', increment);
console.log($("#policy_start_date_" + increment));
var start_date_id = lead_type == "1" ? `policy_start_date_${increment}` : "policy_start_date";
var end_date_id = lead_type == "1" ? `policy_end_date_${increment}` : "policy_end_date";
$(".policy_start_date").attr("id", start_date_id);
// $("label[for]").attr("for", start_date_id);
$(".policy_end_date").attr("id", end_date_id);
// 1'+increment);
// Initialize date pickers
if (lead_type == 1) {
var policy_start_datePicker = flatpickr("#policy_start_date_" + increment, {
dateFormat: "d/m/Y",
allowInput: false,
onChange: function(selectedDates) {
var policy_end_date = new Date(selectedDates[0]);
policy_end_date.setFullYear(policy_end_date.getFullYear() + 1);
policy_end_date.setDate(policy_end_date.getDate() - 1); // Set end date to last day of selected year
policy_end_datePicker.setDate(policy_end_date);
console.log('this object', this);
console.log('id of this element:', this.element);
console.log('id of this element:', this.element.id);
let increment = this.element.id.split('_').pop();
console.log(increment); // Outputs: 1
console.log('increment', increment);
console.log('policy_start_datePicker selectedDates', selectedDates);
console.log('policy_start_datePicker incurred_claim_date_', $("#incurred_claim_date_" + increment).val());
// Recalculate policy_run_days if incurred claim date is already selected
if ($("#incurred_claim_date_" + increment).val()) {
console.log('policy_start_datePicker selectedDates', selectedDates);
calculatePolicyRunDays(increment);
}
}
});
} // 2'+increment);
var policy_end_datePicker = flatpickr("#policy_end_date_" + increment, {
dateFormat: "d/m/Y",
allowInput: false
});
var incurred_claim_datepicker = flatpickr("#incurred_claim_date_" + increment, {
dateFormat: "d/m/Y",
allowInput: false,
onChange: function(selectedDates) {
console.log('Flatpickr instance:', this);
console.log('ID of this element:', this.input.id);
// Extract the increment value from the element's ID
let increment = this.input.id.split('_').pop();
console.log('Extracted increment:', increment);
console.log('Selected Dates:', selectedDates);
console.log('Policy Start Date:', $("#policy_start_date_" + increment).val());
// Recalculate policy_run_days if policy start date is already selected
if ($("#policy_start_date_" + increment).val()) {
calculatePolicyRunDays(increment);
}
}
});
// 3'+increment);
var premium_date_datepicker = flatpickr("#premium_date_" + increment, {
dateFormat: "d/m/Y",
allowInput: false
});
// 4'+increment);
$('#source_policy_id').on('change', function() {
// 5'+increment);
let client_policy_id = $(this).val();
console.log('increment given', increment)
getPolicyData(client_policy_id, increment, random);
})
if (check == 1) {
let client_policy_id = $('#source_policy_id').val();
if (client_policy_id) {
getPolicyData(client_policy_id, increment, random)
}
}
increment++; // Increment after adding the input
}
function removeHTMLInput(element) {
const container = document.getElementById('dynamic-form-container');
const rows = container.querySelectorAll('.dynamic-form-row');
if (rows.length > 1) {
const row = element.closest('.dynamic-form-row');
const hrElement = row.previousElementSibling; // Get the <hr> before the row
console.log(hrElement);
console.log(hrElement.tagName);
if (hrElement && hrElement.tagName === 'HR') { // Check if it's an <hr> element
hrElement.remove(); // Remove the <hr>
}
row.remove();
}
}
function calculatePolicyRunDays(increment) {
console.log('calculatePolicyRunDays function called');
console.log('increment', increment);
var policyStartDate = flatpickr.parseDate($("#policy_start_date_" + increment).val(), "d/m/Y");
var incurredClaimDate = flatpickr.parseDate($("#incurred_claim_date_" + increment).val(), "d/m/Y");
console.log('policyStartDate', policyStartDate)
console.log('incurredClaimDate', incurredClaimDate)
if (policyStartDate && incurredClaimDate) {
var timeDiff = incurredClaimDate - policyStartDate; // Time difference in milliseconds
console.log('timeDiff', timeDiff);
var daysDiff = Math.ceil(timeDiff / (1000 * 60 * 60 * 24)); // Convert to days and add 1
console.log('daysDiff', daysDiff);
$("#policy_run_days_" + increment).val(daysDiff); // Set value in the policy_run_days_ input
}
}
function incurredClaimSum(input) {
let increment = input.id.split('_').pop(); // Extract the increment part
console.log('increment', increment);
// Retrieve and convert the values to numbers, fallback to 0 if empty or invalid
let paid_claims = Number($('#paid_claims_' + increment).val()) || 0;
console.log('paid_claims', paid_claims);
let outstanding_claims = Number($('#outstanding_claims_' + increment).val()) || 0;
console.log('outstanding_claims', outstanding_claims);
// Calculate the incurred claim
let incurred_claims = paid_claims + outstanding_claims;
console.log('incurred_claims', incurred_claims);
// Set the calculated value
$('#incurred_claims_' + increment).val(incurred_claims);
// ------------------------------------------------------------------------------------------
let policy_run_days = Number($('#policy_run_days_' + increment).val()) || 0;
console.log('policy_run_days', policy_run_days);
console.log('incurred claims ' + incurred_claims);
// Prevent division by zero in annualised claims calculation
let annualised_claims = policy_run_days > 0 ? incurred_claims / policy_run_days * 365 : 0;
let annualised_claims_roundoff = Math.round(annualised_claims);
console.log('annualised_claims', annualised_claims_roundoff);
$('#annualised_claims_' + increment).val(annualised_claims_roundoff);
// ------------------------------------------------------------------------------------------
// Prevent division by zero in incurred claim ratio calculation
let incurred_claim_ratio = annualised_claims > 0 ? incurred_claims / annualised_claims : 0;
let incurred_claim_ratio_roundoff = Math.round(incurred_claim_ratio);
console.log('incurred_claim_ratio', incurred_claim_ratio_roundoff);
$('#incurred_claims_ratio_' + increment).val(incurred_claim_ratio_roundoff);
// ------------------------------------------------------------------------------------------
let earned_premium = Number($('#earned_premium_' + increment).val()) || 0;
console.log('earned_premium', earned_premium);
// Prevent division by zero in earned claims ratio calculation
let earned_claims_ratio = earned_premium > 0 ? incurred_claims / earned_premium : 0;
let earned_claims_ration_roundoff = Math.round(earned_claims_ratio);
console.log('earned_claims_ratio', earned_claims_ratio);
$('#earned_claims_ratio_' + increment).val(earned_claims_ration_roundoff);
}
function earnedPremiumCalc(input) {
let increment = input.id.split('_').pop(); // Extract the increment part
console.log('increment', increment);
// Retrieve and convert the values to numbers, fallback to 0 if empty or invalid
let premium_at_inception = Number($('#premium_at_inception_' + increment).val()) || 0;
console.log('premium_at_inception', premium_at_inception);
let policy_run_days = Number($('#policy_run_days_' + increment).val()) || 0;
console.log('policy_run_days', policy_run_days);
// Prevent division by zero and calculate earned premium
let earned_premium = policy_run_days > 0 ? premium_at_inception / policy_run_days : 0;
console.log('earned_premium', earned_premium);
let earned_premium_roundoff = Math.round(earned_premium);
// Set the calculated value with two decimal places
$('#earned_premium_' + increment).val(earned_premium_roundoff);
}
//---------------------------------------------------------------------------------------------------------
$("#leads_form_id").submit(function(event) {
event.preventDefault();
var isValid = $('#leads_form_id').parsley().validate();
if (!isValid) {
$('#leads_form_id').find('input, select, textarea').each(function() {
if ($(this).parsley().isValid() === false && !$(this).val()) {
console.log('Empty field ID:', this.id);
}
});
console.log('Form is Empty', 'Warning');
return;
}
var salse_person_id = $("#salse_person_id").val();
console.log('salse_person_id : ', salse_person_id);
form_action = '<?= base_url('leads/create') ?>';
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
var formData = new FormData($('#leads_form_id')[0]);
var policy_type_ids = formData.getAll('policy_type_id[]');
console.table(policy_type_ids);
console.log('form policy ',policy_type_ids);
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);
$.ajax({
data: formData,
url: form_action,
type: "POST",
dataType: 'json',
processData: false,
contentType: false,
success: function(res) {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
console.log('inception_form_response', res)
if (res.status == true) {
toastr.success(res.message, 'Success');
window.location.href = '<?= base_url('leads/list') ?>';
} else {
toastr.error(res.message, 'Error');
}
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
}
});
});
//-----------------------------------------------------------------------------------------------------------
$('#lead_type').change(function() {
let value = $(this).val()
if (value == 2) {
// // 5.2'+increment);
$('.btnDiv').hide();
// $('.btnDiv1').hide();
$('#renewalDiv').find('select, input').attr('required', 'required');
$('#freshDiv').find('select, input').removeAttr('required');
$('#renewalDiv').show();
$('.proposed_div').show().find('select, input').attr('required', 'required');
$('#policy_end_date').removeAttr('required');
$('#policy_start_date').removeAttr('required');
$('#claims').removeAttr('required');
$('#freshDiv').hide();
$('.freashDiv').show()
$('.renewalDiv').hide()
$('.gpa_div_elements').show();
$('#gst').val('');
$('#pan').val('');
$('#branch_name').val('');
$('#branch_code').val('');
$('#contact_person_name').val('');
$('#contact_person_mobile').val('');
$('#contact_person_email').val('');
$('.emp_title').text('No of Employees at Inception')
$('.depnd_title').text(' No of Dependents at Inception')
$('.total_title').text('Total Lives at Inception')
} else {
$('.btnDiv').show();
$('.btnDiv1').show();
$('#renewalDiv').find('select, input').removeAttr('required');
$('#freshDiv').find('select, input').attr('required', 'required');
$('#renewalDiv').hide();
$('.proposed_div').hide().find('select, input').removeAttr('required');
$('#freshDiv').show();
$('#gst').val('');
$('#pan').val('');
$('#branch_name').val('');
$('#branch_code').val('');
$('#contact_person_name').val('');
$('#contact_person_mobile').val('');
$('#contact_person_email').val('');
$('#client_type').val('');
$('#client_name').val('');
$('#client_short_name').val('');
$('#entity_type_id').val('');
if (value == 1) {
$('.freashDiv').hide()
$('.renewalDiv').show()
$('.btnDiv').show();
$('.btnDiv1').show();
$('.emp_title').text('No of Employees')
$('.depnd_title').text('No of Dependents')
$('.total_title').text('Total Lives')
$('.gpa_div_elements').show();
} else {
$('.btnDiv').hide();
// $('.freashDiv').show()
$('.renewalDiv').hide()
$('.emp_title').text('No of Employees at Inception')
$('.depnd_title').text(' No of Dependents at Inception')
$('.total_title').text('Total Lives at Inception')
$('.gpa_div_elements').show();
}
}
})
function insurerChange(input, unique_id) {
var lead_type = $('#lead_type').val()
if (lead_type == 2) {
var val = $(input).val();
$('#proposed_insurer_' + unique_id).val(val).select2();
}
}
function tpaChange(input, unique_id) {
var lead_type = $('#lead_type').val()
if (lead_type == 2) {
var val = $(input).val();
$('#proposed_tpa_' + unique_id).val(val).select2();
}
}
//-----------------------------------------------------------------------------------------------------------
function sumOfLives(input) {
}
function gatherClaimExperienceData(policy_id) {
// console.log('policy id', policy_id);
// Initialize an empty array for the claim experience data
let claimExperience = [];
for (let i = 0;i<policy_id.length;i++){
// Loop through the rows and extract data for each year
$(`[name="first_year[]"][id*='_${policy_id[i]}_']`).each(function(index) {
// Extract values for the first, second, and third year claims
console.log('index ', index);
const firstYear = $(`[name="first_year[]"][id*='_${policy_id[i]}_']`).eq(index).val();
const firstClaimAmount = $(`input[name="first_claim_amount[]"][id*='_${policy_id[i]}_']`).eq(index).val();
const firstClaimStatus = $(`input[name="first_claim_status[]"][id*='_${policy_id[i]}_']`).eq(index).val();
const firstCauseOfDeath = $(`[name="first_casue_of_death[]"][id*='_${policy_id[i]}_']`).eq(index).val() || null;
const firstDeathDate = $(`input[name="first_death_date[]"][id*='_${policy_id[i]}_']`).eq(index).val() || null;
const claimType = $(`[name="claim_type[]"][id*='_${policy_id[i]}_']`).eq(index).val() || null;
// const firstYear = $(`input[name="first_year[]"][id*='_${policy_id[i]}_']`).eq(index).val();
// const firstClaimAmount = $(`input[name="first_claim_amount[]"][id*='_${policy_id[i]}_']`).eq(index).val();
// const firstClaimStatus = $(`input[name="first_claim_status[]"][id*='_${policy_id[i]}_']`).eq(index).val();
// const firstCauseOfDeath = $(`[name="first_casue_of_death[]"][id*='_${policy_id[i]}_']`).eq(index).val() || null;
// const firstDeathDate = $(`input[name="first_death_date[]"][id*='_${policy_id[i]}_']`).eq(index).val() || null;
// const claimType = $(`[name="claim_type[]"][id*='_${policy_id[i]}_']`).eq(index).val() || null;
// const secondYear = $(`input[name="second_year[]"]`).eq(index).val();
// const secondClaimAmount = $(`input[name="second_claim_amount[]"]`).eq(index).val();
// const secondClaimStatus = $(`input[name="second_claim_status[]"]`).eq(index).val();
// const secondCauseOfDeath = $(`input[name="second_casue_of_death[]"]`).eq(index).val() || null;
// const secondDeathDate = $(`input[name="second_death_date[]"]`).eq(index).val() || null;
// const thirdYear = $(`input[name="third_year[]"]`).eq(index).val();
// const thirdClaimAmount = $(`input[name="third_claim_amount[]"]`).eq(index).val();
// const thirdClaimStatus = $(`input[name="third_claim_status[]"]`).eq(index).val();
// const thirdCauseOfDeath = $(`input[name="third_casue_of_death[]"]`).eq(index).val() || null;
// const thirdDeathDate = $(`input[name="third_death_date[]"]`).eq(index).val() || null;
// console.log(firstYear);
// Push each year's data into the array
claimExperience.push({
"finyear": [{
"year": firstYear,
"claim_amount": firstClaimAmount,
"status": firstClaimStatus,
"cause_of_death": firstCauseOfDeath,
"death_date": firstDeathDate,
'claim_type': claimType,
'policy_type':policy_id[i]
}
// {
// "year": secondYear,
// "claim_amount": secondClaimAmount,
// "status": secondClaimStatus,
// "cause_of_death": secondCauseOfDeath,
// "death_date": secondDeathDate
// },
// {
// "year": thirdYear,
// "claim_amount": thirdClaimAmount,
// "status": thirdClaimStatus,
// "cause_of_death": thirdCauseOfDeath,
// "death_date": thirdDeathDate
// }
]
});
});
}
console.log('claim experience', claimExperience);
return JSON.stringify(claimExperience);
}
// function gatherClaimExperienceData(policy_ids) {
// // Initialize an empty array for the claim experience data
// let claimExperience = [];
// // Process each policy ID
// for (let i = 0; i < policy_ids.length; i++) {
// let policyId = policy_ids[i];
// // Find all first year fields that contain this policy_id in their name
// $(`[name*='_${policyId}_']`).filter('[name*="first_year"]').each(function() {
// // Get the name attribute
// const nameAttr = $(this).attr('name');
// // Extract the suffix pattern that includes increment, policy_id, and random_id
// // This should match: first_year_${increment}_${policy_id}_${random_id}
// const suffixMatch = nameAttr.match(/first_year_(.+)/);
// if (!suffixMatch) return; // Skip if pattern doesn't match
// const suffix = suffixMatch[1];
// const firstYear = $(this).val();
// // Use the extracted suffix to find related fields
// const firstClaimAmount = $(`[name="first_claim_amount_${suffix}"]`).val();
// const firstClaimStatus = $(`[name="first_claim_status_${suffix}"]`).val();
// const firstCauseOfDeath = $(`[name="first_casue_of_death_${suffix}"]`).val() || null;
// const firstDeathDate = $(`[name="first_death_date_${suffix}"]`).val() || null;
// const claimType = $(`[name="claim_type_${suffix}"]`).val() || null;
// // Only add if we have valid data
// if (firstYear) {
// claimExperience.push({
// "policy_id": policyId,
// "finyear": [{
// "year": firstYear,
// "claim_amount": firstClaimAmount,
// "status": firstClaimStatus,
// "cause_of_death": firstCauseOfDeath,
// "death_date": firstDeathDate,
// 'claim_type': claimType
// }]
// });
// }
// });
// }
// console.log('claim experience', claimExperience);
// return JSON.stringify(claimExperience);
// }
function showGpaColumns(input, random_id) {
let policy_type_id = $(input).val()
let increment = input.id.split("_")[3];
let lead_type = $('#lead_type').val();
if (policy_type_id != 2) {
// $('.gpa_hide_div_' + increment).hide();
$('.freashDiv').hide()
$('.freashDiv2').show();
$('.gpa_hide_div_' + increment).hide();
$('.gpa_show_div_' + increment).show();
$('.gpa_div_elements_' + increment).show();
$('.emp_title').text('No of Employees at Inception')
$('.total_title').text('Total Sum Insured at Inception')
$(`[id$='_${random_id}']`)
.filter("[id^='first_death_date_'], [id^='first_casue_of_death_']")
.closest(".form-group")
.hide();
$(`[id$='_${random_id}']`)
.filter("[id^='claim_type_']")
.closest(".form-group")
.hide();
$('#renewal_emp_count_'+increment).show();
if (policy_type_id == 6 || policy_type_id == 7) {
$(`[id$='_${random_id}']`)
.filter("[id^='first_death_date_'], [id^='first_casue_of_death_']")
.closest(".form-group")
.show();
}
if (policy_type_id == 1) {
$(`[id$='_${random_id}']`)
.filter("[id^='claim_type_']")
.closest(".form-group")
.show();
}
console.log('policy type id ', policy_type_id);
}
console.log('policy type id ', policy_type_id);
if (policy_type_id == 2) {
console.log('increment', increment);
console.log($('.gpa_div_elements_' + increment));
$('.gpa_div_elements_' + increment).hide();
$('#appendArea_' + random_id).hide();
// $('#tpa_1').hide();
// $("label[for='tpa']").hide();
console.log('Lead Type is ' + lead_type);
if (lead_type != 1) {
$('.freashDiv').show();
}
$('.gpa_hide_div_' + increment).show();
}
$('.gpa_div_elements_'+increment).empty;
console.log('edit function called : ',edit_function_Called);
if (edit_function_Called == 0){
$('#appendArea_'+random_id).empty();
appendThreeYearsClaims(random_id);
}else{
edit_function_Called = 0
}
}
//-----------------------------------------------------------------------------------------------------------
// function getURLParamsForReport() {
// const params = new URLSearchParams(window.location.search);
// const lead_id = params.get('lead_id') ?? 0;
// if (lead_id != 0) {
// hide_list_show_add();
// setTimeout(() =>
// getLeadsDataForEdit(lead_id),
// 1500); // Reduced timeout
// } else {
// show_list_hide_add();
// }
// console.log('lead_id', lead_id); // Retain the log if necessary
// }
// $('.policy_type_id').change(function() {
// console.log("policy type changed");
// var policy_type_id = $(this).val();
// if (policy_type_id == 2) {
// $('.freashDiv').show();
// } else {
// $('.freashDiv').hide(); // Optional: Hide when `policy_type_id` is not 2
// }});
function appendThreeYearsClaims(random_id, policy = null) {
console.log('calimIndex from parent', claimIndex);
increment = claimIndex;
const container = document.getElementById('dynamic-form-container');
const newDivElement = document.createElement('div');
var policy_type_id = $(`[id$='_${random_id}']`)
.filter("[id^='policy_type_id_']")
.val();
console.log
if (policy_type_id == '' || policy_type_id == null){
policy_type_id = policy;
console.log('policy id changed');
}
newDivElement.innerHTML = `
<div class="form-group col-md-2">
<label for="first_year_${increment}_${policy_type_id}_${random_id}">Year<span class="text-danger">*</span></label>
<select class="form-control first_year_" id="first_year_${increment}_${policy_type_id}_${random_id}" name="first_year[]">
<option value="">Select Year</option>
<?php
foreach ($lastFiveYears as $year) {
echo "<option value='$year'>$year</option>";
}
?>
</select>
</div>
<div class="form-group col-md-2">
<label for="first_claim_amount_${increment}_${policy_type_id}_${random_id}">Claim / Settled Amount<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="first_claim_amount_${increment}_${policy_type_id}_${random_id}" name="first_claim_amount[]">
</div>
<div class="form-group col-md-2">
<label for="first_claim_status_${increment}_${policy_type_id}_${random_id}">Claim Status<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="first_claim_status_${increment}_${policy_type_id}_${random_id}" name="first_claim_status[]">
</div>
<div class="form-group col-md-2">
<label for="first_casue_of_death_${increment}_${policy_type_id}_${random_id}">Nature / Casue Of Death <span class="text-danger">*</span></label>
<select class="form-control" id="first_casue_of_death_${increment}_${policy_type_id}_${random_id}" name="first_casue_of_death[]">
<option value="">Select Cause of Death</option>
<?php
foreach ($causeOfDeath as $cause => $death_value) {
echo "<option value='$cause'>$death_value</option>";
}
?>
</select> </div>
<div class="form-group col-md-2">
<label for="first_death_date_${increment}_${policy_type_id}_${random_id}">Date of Death<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="first_death_date_${increment}_${policy_type_id}_${random_id}" name="first_death_date[]">
</div>
<div class="form-group col-md-2">
<label for="claim_type_${increment}_${policy_type_id}_${random_id}">Claim Type<span class="text-danger">*</span></label>
<select class="form-control" id="claim_type_${increment}_${policy_type_id}_${random_id}" name="claim_type[]">
<option value="">Select Claim Type</option>
<?php
foreach ($gpaClaimType as $claimType => $claim_value) {
echo "<option value='$claimType'>$claim_value</option>";
}
?>
</select>
</div>
<div class="form-group col-md-2">
<div class="form-group col-md-12 btnDiv1" style="position: relative;top: 28px;float: right;text-align: end;">
<a class="btn btn-danger waves-effect waves-light" onclick="removeClaim(this)">x</a>
<a id = "addRow" class="btn btn-primary waves-effect waves-light mr-1" onclick="appendThreeYearsClaims(${random_id})">+</a>
</div>
</div>
`;
console.log('passed random id', random_id);
newDivElement.className = `form-row dynamic-form-row gpa_div_elements_${increment}`;
referenceDiv = document.getElementById('appendArea_' + random_id);
console.log("random id is ",random_id);
// console.log(referenceDiv);
// if (claimIndex == 1 || check == 1) {
// console.log('Inside if condition');
// container.appendChild(newDivElement);
// } else {
// console.log("inside else");
referenceDiv.append(newDivElement);
console.log('rowIndex trying to set', increment);
console.log('policy trying to set', policy_type_id);
console.log('random number trying to set', random_id);
// }
// var policy_type_id = $('#policy_type_id_').val();
console.log('dynamic policy type id', policy_type_id);
// $(".gpa_div_elements").append(html); // Append to container
$(`[id$='_${random_id}']`)
.filter("[id^='first_death_date_'], [id^='first_casue_of_death_']")
.closest(".form-group")
.hide();
$(`[id$='_${random_id}']`)
.filter("[id^='claim_type_']")
.closest(".form-group")
.hide();
if (policy_type_id == 6 || policy_type_id == 7) {
$(`[id$='_${random_id}']`)
.filter("[id^='first_death_date_'], [id^='first_casue_of_death_']")
.closest(".form-group")
.show();
}
if (policy_type_id == 1) {
$(`[id$='_${random_id}']`)
.filter("[id^='claim_type_']")
.closest(".form-group")
.show();
}
console.log("claim index " + claimIndex);
claimIndex++;
console.log(" after claim index " + claimIndex);
$("[id*='first_year']").select2();
$("[id*='claim_type']").select2();
$("[id*='first_casue_of_death_']").select2();
}
function removeClaim(btn) {
const container = document.getElementById('dynamic-form-container');
const rows = container.querySelectorAll('.form-row');
if (rows.length > 1) {
const row = btn.closest('.form-row'); // Use `btn` instead of `element`
row.remove();
}
};
// function removeRequiredFields(formId) {
// const form = document.getElementById(formId);
// if (!form) {
// console.warn("Form not found!");
// return;
// }
// const requiredFields = form.querySelectorAll("[required]");
// requiredFields.forEach(field => field.removeAttribute("required"));
// }
</script>