FIX_LEADS_FORM_HANDLE_EDIT
This commit is contained in:
parent
df9795bc48
commit
68c3d72741
@ -292,6 +292,7 @@ if (isset($selected_lead_type)) {
|
||||
} else {
|
||||
$('#source_policy_id').empty();
|
||||
|
||||
// let lead_type = data.lead_type || null;
|
||||
if (temp_branch_id == 0) {
|
||||
console.log("Step 1: temp_branch_id is 0 - No Policies Found for the selected branch");
|
||||
console.log('second client_branch_id', client_branch_id);
|
||||
@ -301,11 +302,17 @@ if (isset($selected_lead_type)) {
|
||||
} else {
|
||||
console.log("Step 3: v exists - Assigning temp_branch_id = client_branch_id");
|
||||
temp_branch_id = client_id;
|
||||
toastr.warning("No Policies Found for the selected Branch", 'Warning');
|
||||
if (lead_type != 3) {
|
||||
|
||||
toastr.warning("No Policies Found for the selected Branch", 'Warning');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.log("Step 4: temp_branch_id is not 0 - Showing warning");
|
||||
toastr.warning("No Policies Found for the selected Branch", 'Warning');
|
||||
if (lead_type != 3) {
|
||||
|
||||
toastr.warning("No Policies Found for the selected Branch", 'Warning');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -485,6 +492,8 @@ if (isset($selected_lead_type)) {
|
||||
<?php if (isset($lead_edit_data)) { ?>
|
||||
<script>
|
||||
|
||||
var lead_type = "";
|
||||
|
||||
$(document).ready(async function () {
|
||||
|
||||
$('.loader').fadeIn();
|
||||
@ -502,6 +511,7 @@ if (isset($selected_lead_type)) {
|
||||
});
|
||||
|
||||
function handleEbAndNonEbEdit(data){
|
||||
lead_type = data.lead_type || null;
|
||||
if(data.lead_form_type == 1){
|
||||
dynamicLeadsDataForEdit(data)
|
||||
}else{
|
||||
@ -610,38 +620,39 @@ if (isset($selected_lead_type)) {
|
||||
}
|
||||
}
|
||||
|
||||
if (lead_type == 3) {
|
||||
// if (lead_type == 3) {
|
||||
|
||||
$('#client_id').prepend($('<option>', {
|
||||
value: 'add_client',
|
||||
text: '+ Add Client'
|
||||
}));
|
||||
// $('#client_id').prepend($('<option>', {
|
||||
// value: 'add_client',
|
||||
// text: '+ Add Client'
|
||||
// }));
|
||||
|
||||
console.log("trying to remove required ");
|
||||
$("#source_policy_id").prop("required",false);
|
||||
$("#source_policy_id").closest("div") .find("label .text-danger").remove();
|
||||
// console.log("trying to remove required ");
|
||||
// $("#source_policy_id").prop("required",false);
|
||||
// $("#source_policy_id").closest("div") .find("label .text-danger").remove();
|
||||
|
||||
|
||||
} else if (lead_type != 3) {
|
||||
$("#source_policy_id").prop("required",true);
|
||||
$("#source_policy_id").prop("required", true);
|
||||
// } else if (lead_type != 3) {
|
||||
// $("#source_policy_id").prop("required",true);
|
||||
// $("#source_policy_id").prop("required", true);
|
||||
|
||||
// Check if the asterisk doesn't already exist, then add it
|
||||
let $label = $("#source_policy_id")
|
||||
.closest("div")
|
||||
.find("label");
|
||||
// // Check if the asterisk doesn't already exist, then add it
|
||||
// let $label = $("#source_policy_id")
|
||||
// .closest("div")
|
||||
// .find("label");
|
||||
|
||||
if ($label.find(".text-danger").length === 0) {
|
||||
$label.append(' <span class="text-danger">*</span>');
|
||||
}
|
||||
// if ($label.find(".text-danger").length === 0) {
|
||||
// $label.append(' <span class="text-danger">*</span>');
|
||||
// }
|
||||
|
||||
var addOption = $('#client_id option[value="add_client"]');
|
||||
if (addOption.length > 0) {
|
||||
addOption.remove();
|
||||
}
|
||||
// var addOption = $('#client_id option[value="add_client"]');
|
||||
// if (addOption.length > 0) {
|
||||
// addOption.remove();
|
||||
// }
|
||||
|
||||
// console.log("rying to remove required and option removed from client")
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
hide_list_show_add();
|
||||
|
||||
@ -657,27 +668,33 @@ if (isset($selected_lead_type)) {
|
||||
$('#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 || '');
|
||||
$('#source_policy_end_date').val(data.source_policy_end_date || '');
|
||||
$('#source_policy_start_date').val(data.source_policy_start_date || '');
|
||||
$('#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);
|
||||
}, 5000);
|
||||
// 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 || '');
|
||||
// $('#source_policy_end_date').val(data.source_policy_end_date || '');
|
||||
// $('#source_policy_start_date').val(data.source_policy_start_date || '');
|
||||
// $('#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);
|
||||
// }, 5000);
|
||||
|
||||
// setTimeout(() => {
|
||||
populateForm(data);
|
||||
|
||||
// },5000);
|
||||
|
||||
|
||||
let insurer = (data.insurer_branch_id && data.insurer_id)
|
||||
? `${data.insurer_branch_id}-${data.insurer_id}`
|
||||
@ -732,10 +749,10 @@ if (isset($selected_lead_type)) {
|
||||
}
|
||||
|
||||
if (data.multi_file_html) {
|
||||
console.log(data.multi_file_html);
|
||||
// console.log(data.multi_file_html);
|
||||
setTimeout(function(){
|
||||
$('#multiFileAppendArea_' + dataIncrement).append(data.multi_file_html);
|
||||
}, 2000)
|
||||
}, 1000)
|
||||
} else {
|
||||
console.warn('MULTI FILE HTML content missing in data.');
|
||||
}
|
||||
@ -764,30 +781,33 @@ if (isset($selected_lead_type)) {
|
||||
$('#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');
|
||||
$(".loss_date").each(function () {
|
||||
flatpickr(this, {
|
||||
dateFormat: "d-m-Y",
|
||||
});
|
||||
});
|
||||
}, 1000);
|
||||
}, 1000);
|
||||
}, 2000);
|
||||
// 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');
|
||||
// $(".loss_date").each(function () {
|
||||
// flatpickr(this, {
|
||||
// dateFormat: "d-m-Y",
|
||||
// });
|
||||
// });
|
||||
// }, 1000);
|
||||
// }, 1000);
|
||||
// }, 2000);
|
||||
|
||||
populateForm(data);
|
||||
|
||||
|
||||
let insurer = (data.insurer_branch_id && data.insurer_id)
|
||||
? `${data.insurer_branch_id}-${data.insurer_id}`
|
||||
@ -819,8 +839,35 @@ if (isset($selected_lead_type)) {
|
||||
|
||||
console.log("wdesfgefwregfefwregffeegf",data.lead_type);
|
||||
var lead_type_value = data.lead_type;
|
||||
// alert(lead_type);
|
||||
if (lead_type_value == 3) {
|
||||
|
||||
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error in dynamicLeadsDataForEdit function:', error);
|
||||
}
|
||||
}
|
||||
|
||||
function waitForDropdownValue(selector, value, callback, retries = 20) {
|
||||
const trySet = () => {
|
||||
const $el = $(selector);
|
||||
if ($el.find(`option[value="${value}"]`).length > 0) {
|
||||
$el.val(value).trigger('change');
|
||||
callback();
|
||||
} else if (retries > 0) {
|
||||
setTimeout(() => trySet(selector, value, callback, retries - 1), 300);
|
||||
} else {
|
||||
console.warn(`Value ${value} not found for ${selector}`);
|
||||
callback(); // Proceed anyway to avoid hanging
|
||||
}
|
||||
};
|
||||
trySet();
|
||||
}
|
||||
|
||||
function populateForm(data) {
|
||||
|
||||
let lead_type = data.lead_type || null;
|
||||
waitForDropdownValue('#client_id', data.client_id || '', () => {
|
||||
if (lead_type == 3) {
|
||||
|
||||
$('#client_id').prepend($('<option>', {
|
||||
value: 'add_client',
|
||||
@ -832,7 +879,7 @@ if (isset($selected_lead_type)) {
|
||||
$("#source_policy_id").closest("div") .find("label .text-danger").remove();
|
||||
|
||||
|
||||
} else if (lead_type_value != 3) {
|
||||
} else if (lead_type != 3) {
|
||||
$("#source_policy_id").prop("required",true);
|
||||
$("#source_policy_id").prop("required", true);
|
||||
|
||||
@ -850,13 +897,36 @@ if (isset($selected_lead_type)) {
|
||||
addOption.remove();
|
||||
}
|
||||
|
||||
console.log("rying to remove required and option removed from client")
|
||||
|
||||
}
|
||||
waitForDropdownValue('#client_branch_id', data.client_branch_id || '', () => {
|
||||
// Fill other fields once both dropdowns are ready
|
||||
$('#source_policy_id').val(data.source_policy_id || '');
|
||||
$('#source_policy_end_date').val(data.source_policy_end_date || '');
|
||||
$('#source_policy_start_date').val(data.source_policy_start_date || '');
|
||||
$('#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();
|
||||
$('#policy_type_id_1').val(data.policy_type_id || '').select2();
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error in dynamicLeadsDataForEdit function:', error);
|
||||
}
|
||||
$('.loader').fadeOut();
|
||||
$('.loader-mask').delay(350).fadeOut('slow');
|
||||
$(".loss_date").each(function () {
|
||||
flatpickr(this, {
|
||||
dateFormat: "d-m-Y",
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
<?php } ?>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user