FIX_Populated card based on policy start end date and Cd account number
This commit is contained in:
parent
47c49f2228
commit
3ea58e570c
@ -3303,6 +3303,30 @@
|
|||||||
if(res.status == true){
|
if(res.status == true){
|
||||||
// appendCDAccountNumber(res.data[0].cd_ac_no, unique_id)
|
// appendCDAccountNumber(res.data[0].cd_ac_no, unique_id)
|
||||||
appendCDAccountNumber(res.data, unique_id)
|
appendCDAccountNumber(res.data, unique_id)
|
||||||
|
|
||||||
|
|
||||||
|
let balanceDiv = document.getElementById('cd_current_balance_info_' + unique_id);
|
||||||
|
setTimeout(function(){
|
||||||
|
let dropdown_value = $('#cd_ac_no_' + unique_id).val();
|
||||||
|
|
||||||
|
console.log("dropdown_value",dropdown_value)
|
||||||
|
|
||||||
|
res.data.forEach(function(item) {
|
||||||
|
if (item.id == dropdown_value) { // match found
|
||||||
|
if (item.opening_bal !== null) {
|
||||||
|
$('#cd_current_balance_info_' + unique_id).val(item.opening_bal);
|
||||||
|
balanceDiv.innerHTML =
|
||||||
|
'<span class="text-success">' + item.opening_bal + '</span>' +
|
||||||
|
' <span class="vehicle-badge success">✓ CD balance Amount</span>';
|
||||||
|
balanceDiv.classList.add('show');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$('.card_group_34').show();
|
||||||
|
$('.card_group_37').show();
|
||||||
|
$("select[name='cd_ac_no_for_child[]']").attr('required', 'required');
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
// if(res.data[0].id){
|
// if(res.data[0].id){
|
||||||
// $('#cd_ac_pk_for_leader').val(res.data[0].id)
|
// $('#cd_ac_pk_for_leader').val(res.data[0].id)
|
||||||
// }
|
// }
|
||||||
@ -4788,32 +4812,64 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ✅ Calculate Year Difference
|
let yearDiff = calculateYearCount(startDate, endDate);
|
||||||
let yearDiff = endDate.getFullYear() - startDate.getFullYear();
|
console.log(`YDiff: ${yearDiff}`);
|
||||||
|
adjustInsurerCards(yearDiff);
|
||||||
// Adjust if end date is before anniversary
|
|
||||||
if (
|
|
||||||
endDate.getMonth() < startDate.getMonth() ||
|
|
||||||
(endDate.getMonth() === startDate.getMonth() && endDate.getDate() < startDate.getDate())
|
|
||||||
) {
|
|
||||||
yearDiff--;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('Year Difference:', yearDiff);
|
|
||||||
|
|
||||||
// Clear existing cards (optional but recommended)
|
|
||||||
// $('#allInsurerCards').empty();
|
|
||||||
// $('.insurer-card').remove();
|
|
||||||
// insurerCount = 0;
|
|
||||||
resetInsurerCards();
|
|
||||||
|
|
||||||
// Add cards equal to year difference
|
|
||||||
for (let i = 0; i < yearDiff; i++) {
|
|
||||||
addInsurerColumn();
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
function calculateYearCount(start, end) {
|
||||||
|
let startDate = new Date(start);
|
||||||
|
let endDate = new Date(end);
|
||||||
|
|
||||||
|
let years = endDate.getFullYear() - startDate.getFullYear();
|
||||||
|
|
||||||
|
// Build the anniversary date for calculated years
|
||||||
|
let anniversary = new Date(
|
||||||
|
startDate.getFullYear() + years,
|
||||||
|
startDate.getMonth(),
|
||||||
|
startDate.getDate()
|
||||||
|
);
|
||||||
|
|
||||||
|
// If end date is before anniversary → reduce 1 year
|
||||||
|
if (endDate < anniversary) {
|
||||||
|
years--;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there are extra days beyond exact year → round up
|
||||||
|
// (endDate >= anniversary)
|
||||||
|
return years + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
function adjustInsurerCards(yearDiff) {
|
||||||
|
|
||||||
|
console.log("CurrCount:", insurerCount);
|
||||||
|
|
||||||
|
if (yearDiff > insurerCount) {
|
||||||
|
// ADD missing cards
|
||||||
|
let cardsToAdd = yearDiff - insurerCount;
|
||||||
|
console.log("CaAd:", cardsToAdd);
|
||||||
|
|
||||||
|
for (let i = 0; i < cardsToAdd; i++) {
|
||||||
|
addInsurerColumn(); // your function
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (yearDiff < insurerCount) {
|
||||||
|
// REMOVE extra cards
|
||||||
|
let cardsToRemove = insurerCount - yearDiff;
|
||||||
|
console.log("CaRe:", cardsToRemove);
|
||||||
|
|
||||||
|
for (let i = 0; i < cardsToRemove; i++) {
|
||||||
|
removeInsurerCard(insurerCount); // remove last
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("UpdatedCa:", insurerCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function resetInsurerCards() {
|
function resetInsurerCards() {
|
||||||
$('#allInsurerCards').empty();
|
$('#allInsurerCards').empty();
|
||||||
insurerCount = 0;
|
insurerCount = 0;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user