Merge branch 'dev' of bitbucket.org:jubilian/nhance into dev
This commit is contained in:
commit
f1e4dade06
@ -3328,6 +3328,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)
|
||||||
// }
|
// }
|
||||||
@ -4793,52 +4817,84 @@
|
|||||||
|
|
||||||
$('#policy_end_date').on('change', function () {
|
$('#policy_end_date').on('change', function () {
|
||||||
|
|
||||||
let startDateStr = $('#policy_start_date').val();
|
let startDateStr = $('#policy_start_date').val();
|
||||||
let endDateStr = $('#policy_end_date').val();
|
let endDateStr = $('#policy_end_date').val();
|
||||||
|
|
||||||
if (!startDateStr || !endDateStr) {
|
if (!startDateStr || !endDateStr) {
|
||||||
alert('Please select both Start and End dates');
|
alert('Please select both Start and End dates');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert DD/MM/YYYY → Date object
|
// Convert DD/MM/YYYY → Date object
|
||||||
let startParts = startDateStr.split('/');
|
let startParts = startDateStr.split('/');
|
||||||
let endParts = endDateStr.split('/');
|
let endParts = endDateStr.split('/');
|
||||||
|
|
||||||
let startDate = new Date(startParts[2], startParts[1] - 1, startParts[0]);
|
let startDate = new Date(startParts[2], startParts[1] - 1, startParts[0]);
|
||||||
let endDate = new Date(endParts[2], endParts[1] - 1, endParts[0]);
|
let endDate = new Date(endParts[2], endParts[1] - 1, endParts[0]);
|
||||||
|
|
||||||
if (endDate <= startDate) {
|
if (endDate <= startDate) {
|
||||||
alert('End Date must be greater than Start Date');
|
alert('End Date must be greater than Start Date');
|
||||||
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