524 lines
19 KiB
PHP
524 lines
19 KiB
PHP
<style>
|
|
.table th,
|
|
.table td {
|
|
padding: 8px;
|
|
}
|
|
|
|
table.dataTable tbody td {
|
|
padding: 4px 4px !important;
|
|
}
|
|
|
|
.col-12 {
|
|
max-width: 98% !important;
|
|
}
|
|
|
|
.dataTables_filter {
|
|
position: absolute;
|
|
}
|
|
|
|
.highlight {
|
|
border: 2px solid red;
|
|
background-color: #ffe6e6;
|
|
}
|
|
|
|
.column-header {
|
|
margin-right: 10px;
|
|
}
|
|
|
|
.form-section {
|
|
border: 1px solid #ccc;
|
|
padding: 15px;
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
.row-box {
|
|
border: 1px solid #ccc;
|
|
padding: 10px;
|
|
margin-bottom: 10px;
|
|
}
|
|
|
|
|
|
.custom-dropdown-menu {
|
|
display: none;
|
|
position: absolute;
|
|
background-color: #ffffff !important;
|
|
border: 1px solid rgba(0, 0, 0, 0.15);
|
|
border-radius: 0.25rem;
|
|
padding: 0.5rem 0;
|
|
min-width: 10rem;
|
|
z-index: 9999;
|
|
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
|
}
|
|
|
|
.custom-dropdown-menu .dropdown-item {
|
|
display: block !important;
|
|
width: 100% !important;
|
|
padding: 0.5rem 1rem !important;
|
|
color: #212529 !important;
|
|
text-decoration: none !important;
|
|
background-color: transparent !important;
|
|
}
|
|
|
|
.custom-dropdown-menu .dropdown-item:hover {
|
|
background-color: #f8f9fa !important;
|
|
color: #16181b !important;
|
|
cursor: pointer !important;
|
|
}
|
|
</style>
|
|
|
|
<?php
|
|
|
|
if (isset($selected_lead_type)) {
|
|
if ($selected_lead_type == 1) {
|
|
include('leads_form.php');
|
|
} else {
|
|
include('leads_non_eb.php');
|
|
}
|
|
}
|
|
|
|
?>
|
|
|
|
|
|
<script>
|
|
var client_list = ''; // local variable for storing the client branch list
|
|
var branch_list = ''; // local variable for storing the client branch list
|
|
var policy_list = ''; // local variable for storing the client policy list
|
|
|
|
|
|
// select2 document ready
|
|
$(document).ready(function() {
|
|
|
|
getClientAndBranchAndPolicy()
|
|
|
|
$('#client_id').select2();
|
|
$('#client_branch_id').select2();
|
|
$('#salse_person_id').select2({
|
|
placeholder: "Select Salse Person",
|
|
});
|
|
|
|
$('#policy_type_id').select2();
|
|
|
|
$("textarea.select2-search__field").attr('rows', '1');
|
|
$("textarea.select2-search__field").css('resize', 'none');
|
|
|
|
})
|
|
|
|
//--------------------------------------------------------------------------------------------------------
|
|
|
|
function hide_list_show_add() {
|
|
$('#leads_list').hide()
|
|
$('#lead_filter_div').hide()
|
|
$('#leads_form').show()
|
|
}
|
|
|
|
function show_list_hide_add() {
|
|
$('#leads_list').show()
|
|
$('#lead_filter_div').show()
|
|
$('#leads_form').hide()
|
|
}
|
|
|
|
function getClientAndBranchAndPolicy() {
|
|
|
|
console.log('getClientAndBranchAndPolicy function called')
|
|
|
|
$.ajax({
|
|
url: '<?= base_url("/util/getClientAndBranchAndPolicy") ?>',
|
|
type: "GET",
|
|
dataType: 'json',
|
|
success: function(res) {
|
|
|
|
console.log('getClientAndBranchAndPolicy', res);
|
|
if (res.status == true) {
|
|
client_list = res.client_data;
|
|
branch_list = res.branch_data;
|
|
policy_list = res.policy_data;
|
|
appendClients(res.client_data);
|
|
} else {
|
|
console.log('No data found');
|
|
}
|
|
|
|
},
|
|
error: function(xhr, status, error) {
|
|
console.error(xhr.responseText);
|
|
console.error(status, error);
|
|
}
|
|
});
|
|
}
|
|
|
|
function appendClients(data) {
|
|
$('#client_id').empty();
|
|
|
|
$('#client_id').append($('<option>', {
|
|
value: '',
|
|
text: 'Select Client'
|
|
}));
|
|
|
|
$.each(data, function(index, item) {
|
|
var option = $('<option>', {
|
|
value: item.id,
|
|
text: item.client_name,
|
|
'data-cn': item.client_name,
|
|
'data-ct': item.client_type,
|
|
class: (item.client_type == 1) ? 'group' : (item.client_type == 2) ? 'individual' : ''
|
|
});
|
|
|
|
$('#client_id').append(option);
|
|
});
|
|
|
|
}
|
|
|
|
function appendBranch(data) {
|
|
|
|
$('#client_branch_id').empty();
|
|
|
|
$('#client_branch_id').append($('<option>', {
|
|
value: '',
|
|
text: 'Select Branch'
|
|
}));
|
|
|
|
$.each(data, function(index, item) {
|
|
|
|
var option = $('<option>', {
|
|
value: item.id,
|
|
text: item.branch_name
|
|
});
|
|
$('#client_branch_id').append(option);
|
|
});
|
|
}
|
|
|
|
function appendRenewalPolicies(data) {
|
|
console.log('appendRenewalPolicies', data);
|
|
|
|
$('#source_policy_id').empty();
|
|
|
|
$('#source_policy_id').append($('<option>', {
|
|
value: '',
|
|
text: 'Select Policy',
|
|
}));
|
|
|
|
$.each(data, function(index, item) {
|
|
|
|
var option = $('<option>', {
|
|
value: item.id,
|
|
text: item.policy_type + '-' + item.policy_no,
|
|
});
|
|
|
|
$('#source_policy_id').append(option);
|
|
});
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------------
|
|
|
|
$(document).ready(function() {
|
|
|
|
$('#client_id').change(function() {
|
|
|
|
let client_id = $(this).val();
|
|
console.log("client_id", client_id)
|
|
let client_type = $('#client_id option:selected').data('ct');
|
|
|
|
if (branch_list[client_id] != '' && branch_list[client_id] != null && client_id != '') {
|
|
console.log('branch_list', branch_list[client_id]);
|
|
let data = branch_list[client_id];
|
|
appendBranch(data);
|
|
} else {
|
|
toastr.warning("No Branch Found for the selected Client", 'Warning');
|
|
}
|
|
|
|
})
|
|
|
|
$('#client_branch_id').change(function() {
|
|
|
|
let client_branch_id = $(this).val();
|
|
|
|
if (policy_list[client_branch_id] != '' && policy_list[client_branch_id] != null &&
|
|
client_branch_id != '' && client_branch_id != null) {
|
|
console.log('policy_list', policy_list[client_branch_id]);
|
|
let data = policy_list[client_branch_id];
|
|
appendRenewalPolicies(data);
|
|
} else {
|
|
$('#source_policy_id').empty();
|
|
toastr.warning("No Policies Found for the selected Branch", 'Warning');
|
|
}
|
|
|
|
})
|
|
});
|
|
|
|
//--------------------------------------------------------------------------------------------------------
|
|
|
|
// 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');
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
<?php if (isset($lead_edit_data)) { ?>
|
|
<script>
|
|
|
|
setTimeout(function(){
|
|
handleEbAndNonEbEdit(
|
|
<?= json_encode($lead_edit_data, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP) ?>);
|
|
}, 1000)
|
|
|
|
function handleEbAndNonEbEdit(data){
|
|
if(data.lead_form_type == 1){
|
|
dynamicLeadsDataForEdit(data)
|
|
}else{
|
|
dynamicNonEbLeadsDataForEdit(data)
|
|
}
|
|
}
|
|
|
|
function dynamicLeadsDataForEdit(data) {
|
|
try {
|
|
console.log('########### THIS IS EB LEAD ###############')
|
|
|
|
console.log('Received data:', data);
|
|
let dataIncrement = 1;
|
|
|
|
if (!data || typeof data !== 'object') {
|
|
console.error('Invalid data received for editing.');
|
|
return;
|
|
}
|
|
|
|
$('.btnDiv').hide();
|
|
$('#appendArea_' + dataIncrement).empty();
|
|
|
|
if (data.html) {
|
|
$('#appendArea_' + dataIncrement).append(data.html);
|
|
} else {
|
|
console.warn('HTML content missing in data.');
|
|
}
|
|
|
|
let policy_type_id = data.policy_type_id || null;
|
|
let lead_type = data.lead_type || null;
|
|
|
|
if ([1, 6, 7].includes(policy_type_id)) {
|
|
let newId = 'appendAreaForClaim_' + dataIncrement;
|
|
$('#appendAreaForClaim').attr('id', newId);
|
|
}
|
|
|
|
leadTypeBsedHideAndShow(lead_type);
|
|
|
|
if (lead_type == 1) {
|
|
$('.claim-row').hide();
|
|
} else {
|
|
$('.claim-row').show();
|
|
if (policy_type_id == 1) {
|
|
$('.gpaClaimFileds').show();
|
|
$('.lifeClaimFields').hide();
|
|
} else if (policy_type_id === 6 || policy_type_id === 7) {
|
|
$('.gpaClaimFileds').hide();
|
|
$('.lifeClaimFields').show();
|
|
} else {
|
|
updateRenewalFields(dataIncrement);
|
|
|
|
let incurred_claim_date_id = 'incurred_claim_date_' + dataIncrement;
|
|
let premium_date_id = 'premium_date_' + dataIncrement;
|
|
|
|
if ($('#' + incurred_claim_date_id).length) {
|
|
flatpickr("#" + incurred_claim_date_id, {
|
|
dateFormat: "d/m/Y",
|
|
allowInput: false,
|
|
onChange: function (selectedDates) {
|
|
try {
|
|
let increment = this.input.id.split('_').pop();
|
|
let policyStartDate = $("#policy_start_date_" + increment).length
|
|
? $("#policy_start_date_" + increment)
|
|
: $("#policy_start_date");
|
|
|
|
if (policyStartDate.val()) {
|
|
calculatePolicyRunDays(increment);
|
|
}
|
|
} catch (error) {
|
|
console.error('Error in incurred_claim_datepicker:', error);
|
|
}
|
|
}
|
|
});
|
|
} else {
|
|
console.warn(`Incurred claim date field #${incurred_claim_date_id} not found.`);
|
|
}
|
|
|
|
if ($('#' + premium_date_id).length) {
|
|
flatpickr("#" + premium_date_id, {
|
|
dateFormat: "d/m/Y",
|
|
allowInput: false
|
|
});
|
|
} else {
|
|
console.warn(`Premium date field #${premium_date_id} not found.`);
|
|
}
|
|
|
|
$('#proposed_insurer_' + dataIncrement).select2();
|
|
$('#proposed_tpa_' + dataIncrement).select2();
|
|
}
|
|
}
|
|
|
|
hide_list_show_add();
|
|
|
|
$('#page_title').text('Edit Lead');
|
|
$('#leads_primarykey').val(data.id || '');
|
|
$('#policy_start_date').val(data.policy_end_date || '');
|
|
$('#lead_type').val(data.lead_type || '');
|
|
$('#issuer').val(data.issuer || '');
|
|
$('#client_type').val(data.client_type || '');
|
|
$('#client_name').val(data.client_name || '');
|
|
$('#client_short_name').val(data.client_short_name || '');
|
|
$('#entity_type_id').val(data.entity_type_id || '');
|
|
$('#lead_status').val(data.status || '');
|
|
$('#notes').val(data.notes || '');
|
|
|
|
setTimeout(() => {
|
|
$('#client_id').val(data.client_id || '').change();
|
|
setTimeout(() => {
|
|
$('#client_branch_id').val(data.client_branch_id || '').change();
|
|
setTimeout(() => {
|
|
$('#source_policy_id').val(data.source_policy_id || '');
|
|
$('#pan').val(data.pan || '');
|
|
$('#gst').val(data.gst || '');
|
|
$('#branch_name').val(data.branch_name || '');
|
|
$('#branch_code').val(data.branch_code || '');
|
|
$('#contact_person_name').val(data.contact_person_name || '');
|
|
$('#contact_person_mobile').val(data.contact_person_mobile || '');
|
|
$('#contact_person_email').val(data.contact_person_email || '');
|
|
$('#policy_type_id_1').val(data.policy_type_id || '').select2();
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
}, 1000);
|
|
}, 1000);
|
|
}, 1000);
|
|
|
|
let insurer = (data.insurer_branch_id && data.insurer_id)
|
|
? `${data.insurer_branch_id}-${data.insurer_id}`
|
|
: '';
|
|
let tpa = (data.tpa_branch_id && data.tpa_id)
|
|
? `${data.tpa_branch_id}-${data.tpa_id}`
|
|
: '';
|
|
|
|
let proposed_insurer = (data.proposed_insurer_branch_id && data.proposed_insurer_id)
|
|
? `${data.proposed_insurer_branch_id}-${data.proposed_insurer_id}`
|
|
: '';
|
|
let proposed_tpa = (data.proposed_tpa_branch_id && data.proposed_tpa_id)
|
|
? `${data.proposed_tpa_branch_id}-${data.proposed_tpa_id}`
|
|
: '';
|
|
|
|
$('#insurer_1').val(insurer).select2();
|
|
$('#tpa_1').val(tpa).select2();
|
|
$('#policy_start_date_1').val(data.policy_start_date || '');
|
|
$('#policy_end_date_1').val(data.policy_end_date || '');
|
|
$('#file_name_display').text(`Upload File Name : ${data.file_name || 'N/A'}`);
|
|
|
|
if (data.salse_person_id) {
|
|
selecSalsePerson(data.salse_person_id);
|
|
}
|
|
} catch (error) {
|
|
console.error('Error in dynamicLeadsDataForEdit function:', error);
|
|
}
|
|
}
|
|
|
|
function dynamicNonEbLeadsDataForEdit(data) {
|
|
try {
|
|
console.log('########### THIS IS NON EB LEAD ###############')
|
|
console.log('Received data:', data);
|
|
let dataIncrement = 1;
|
|
|
|
if (!data || typeof data !== 'object') {
|
|
console.error('Invalid data received for editing.');
|
|
return;
|
|
}
|
|
|
|
$('#appendArea').empty();
|
|
|
|
if (data.html) {
|
|
$('#appendArea').append(data.html);
|
|
} else {
|
|
console.warn('HTML content missing in data.');
|
|
}
|
|
|
|
let policy_type_id = data.policy_type_id || null;
|
|
let lead_type = data.lead_type || null;
|
|
|
|
leadTypeBsedHideAndShow(lead_type);
|
|
|
|
|
|
$('#page_title').text('Edit Lead');
|
|
$('#leads_primarykey').val(data.id || '');
|
|
$('#policy_start_date').val(data.policy_end_date || '');
|
|
$('#lead_type').val(data.lead_type || '');
|
|
$('#issuer').val(data.issuer || '');
|
|
$('#client_type').val(data.client_type || '');
|
|
$('#client_name').val(data.client_name || '');
|
|
$('#client_short_name').val(data.client_short_name || '');
|
|
$('#entity_type_id').val(data.entity_type_id || '');
|
|
$('#lead_status').val(data.status || '');
|
|
$('#notes').val(data.notes || '');
|
|
|
|
setTimeout(() => {
|
|
$('#client_id').val(data.client_id || '').change();
|
|
setTimeout(() => {
|
|
$('#client_branch_id').val(data.client_branch_id || '').change();
|
|
setTimeout(() => {
|
|
$('#source_policy_id').val(data.source_policy_id || '');
|
|
$('#pan').val(data.pan || '');
|
|
$('#gst').val(data.gst || '');
|
|
$('#branch_name').val(data.branch_name || '');
|
|
$('#branch_code').val(data.branch_code || '');
|
|
$('#contact_person_name').val(data.contact_person_name || '');
|
|
$('#contact_person_mobile').val(data.contact_person_mobile || '');
|
|
$('#contact_person_email').val(data.contact_person_email || '');
|
|
$('#policy_type_id').val(data.policy_type_id || '').select2();
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
}, 1000);
|
|
}, 1000);
|
|
}, 2000);
|
|
|
|
let insurer = (data.insurer_branch_id && data.insurer_id)
|
|
? `${data.insurer_branch_id}-${data.insurer_id}`
|
|
: '';
|
|
let tpa = (data.tpa_branch_id && data.tpa_id)
|
|
? `${data.tpa_branch_id}-${data.tpa_id}`
|
|
: '';
|
|
|
|
let proposed_insurer = (data.proposed_insurer_branch_id && data.proposed_insurer_id)
|
|
? `${data.proposed_insurer_branch_id}-${data.proposed_insurer_id}`
|
|
: '';
|
|
let proposed_tpa = (data.proposed_tpa_branch_id && data.proposed_tpa_id)
|
|
? `${data.proposed_tpa_branch_id}-${data.proposed_tpa_id}`
|
|
: '';
|
|
|
|
$('#insurer').val(insurer).select2();
|
|
$('#tpa').val(tpa).select2();
|
|
$('#policy_start_date').val(data.policy_start_date || '');
|
|
$('#policy_end_date').val(data.policy_end_date || '');
|
|
$('#file_name_display').text(`Upload File Name : ${data.file_name || 'N/A'}`);
|
|
|
|
if (data.salse_person_id) {
|
|
selecSalsePerson(data.salse_person_id);
|
|
}
|
|
|
|
let referenceDiv = document.getElementById('appendAreaForClaim');
|
|
referenceDiv.innerHTML = '';
|
|
referenceDiv.insertAdjacentHTML('beforeend', data.claims_details_html);
|
|
|
|
} catch (error) {
|
|
console.error('Error in dynamicLeadsDataForEdit function:', error);
|
|
}
|
|
}
|
|
|
|
</script>
|
|
<?php } ?>
|