nhance-enrollment/app/Views/leads_form.php

1571 lines
69 KiB
PHP
Executable File

<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>
.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>
//SELECT2 document ready function
$(document).ready(function() {
getURLParamsForReport()
addHTMLInput()
setTimeout(function() {
$("textarea.select2-search__field").attr('rows', '1');
$("textarea.select2-search__field").css('resize', 'none');
}, 1000)
$('#insurer').select2();
$('#tpa').select2();
$('#proposed_insurer').select2();
$('#proposed_tpa').select2();
})
//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) {
$('.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();
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);
$('#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)
.change();
$('#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').val(res.data.policy_type_id).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);
claimExperience[0].finyear.forEach((data, index) => {
const year = document.querySelector(`#${["first", "second", "third"][index]}_year_${increment}`);
const claimAmount = document.querySelector(`#${["first", "second", "third"][index]}_claim_amount_${increment}`);
const claimStatus = document.querySelector(`#${["first", "second", "third"][index]}_claim_status_${increment}`);
const causeOfDeath = document.querySelector(`#${["first", "second", "third"][index]}_casue_of_death_${increment}`);
const deathDate = document.querySelector(`#${["first", "second", "third"][index]}_death_date_${increment}`);
if (year) year.value = data.year;
if (claimAmount) claimAmount.value = data.claim_amount;
if (claimStatus) claimStatus.value = data.status;
if (causeOfDeath) causeOfDeath.value = data.cause_of_death;
if (deathDate) deathDate.value = data.death_date;
});
}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);
$('.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) {
console.log('client_policy_id', client_policy_id);
console.log('increment_count', increment_count);
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++) {
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}`;
// Update fields with response data
$(`#policy_type_id_${i}`).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');
}
} 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}`).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}`).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}`).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 addHTMLInput(check) {
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 freashDiv';
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';
// 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}" name="policy_type_id[]" onchange="showGpaColumns(this)" 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="policy_start_date_${increment}">Date of Commencement <span class="text-danger"></span></label>
<input type="text" class="form-control policy_start_date" id="policy_start_date_${increment}" name="policy_start_date[]" placeholder="Enter DOC">
</div>
<div class="form-group col-md-3">
<label for="policy_end_date_${increment}">Date of Expiry <span class="text-danger"></span></label>
<input type="text" class="form-control policy_end_date" id="policy_end_date_${increment}" 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)">
</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 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>
`;
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);
//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();
$('#proposed_insurer_'+ increment).select2();
$('#proposed_tpa_'+ increment).select2();
$('#policy_type_id_'+ increment).select2();
// Initialize date pickers
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
});
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);
}
}
});
var premium_date_datepicker = flatpickr("#premium_date_" + increment, {
dateFormat: "d/m/Y",
allowInput: false
});
$('#source_policy_id').on('change', function(){
let client_policy_id = $(this).val();
console.log('client_policy_id', client_policy_id)
getPolicyData(client_policy_id, increment)
})
if(check == 1){
let client_policy_id = $('#source_policy_id').val();
if(client_policy_id){
getPolicyData(client_policy_id, increment)
}
}
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);
// Prevent division by zero in annualised claims calculation
let annualised_claims = policy_run_days > 0 ? incurred_claims / policy_run_days * 365 : 0;
console.log('annualised_claims', annualised_claims);
$('#annualised_claims_' + increment).val(annualised_claims);
// ------------------------------------------------------------------------------------------
// Prevent division by zero in incurred claim ratio calculation
let incurred_claim_ratio = annualised_claims > 0 ? incurred_claims / annualised_claims : 0;
console.log('incurred_claim_ratio', incurred_claim_ratio);
$('#incurred_claims_ratio_' + increment).val(incurred_claim_ratio);
// ------------------------------------------------------------------------------------------
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;
console.log('earned_claims_ratio', earned_claims_ratio);
$('#earned_claims_ratio_' + increment).val(earned_claims_ratio);
}
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);
// Set the calculated value with two decimal places
$('#earned_premium_' + increment).val(earned_premium.toFixed(2));
}
//---------------------------------------------------------------------------------------------------------
$("#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]);
console.log(formData);
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();
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) {
$('#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 {
$('#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()
$('.emp_title').text('No of Employees')
$('.depnd_title').text('No of Dependents')
$('.total_title').text('Total Lives')
$('.gpa_div_elements').show();
}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();
}
}
})
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() {
// Initialize an empty array for the claim experience data
let claimExperience = [];
// Loop through the rows and extract data for each year
$('input[name="first_year[]"]').each(function(index) {
// Extract values for the first, second, and third year claims
const firstYear = $(this).val();
const firstClaimAmount = $(`input[name="first_claim_amount[]"]`).eq(index).val();
const firstClaimStatus = $(`input[name="first_claim_status[]"]`).eq(index).val();
const firstCauseOfDeath = $(`input[name="first_casue_of_death[]"]`).eq(index).val() || null;
const firstDeathDate = $(`input[name="first_death_date[]"]`).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;
// 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
},
{
"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
}
]
});
});
return JSON.stringify(claimExperience);
}
function showGpaColumns(input){
let policy_type_id = $(input).val()
let increment = input.id.split("_").pop();
if(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')
$('.total_title').text('Total Sum Insured at Inception')
}else{
$('.gpa_hide_div_'+increment).show();
}
}
//-----------------------------------------------------------------------------------------------------------
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
}
</script>