diff --git a/app/Views/policy_transaction_inception_form_2.php b/app/Views/policy_transaction_inception_form_2.php
index dfd6a662..a1db7f44 100644
--- a/app/Views/policy_transaction_inception_form_2.php
+++ b/app/Views/policy_transaction_inception_form_2.php
@@ -3328,6 +3328,30 @@
if(res.status == true){
// appendCDAccountNumber(res.data[0].cd_ac_no, 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 =
+ '' + item.opening_bal + '' +
+ ' ✓ CD balance Amount';
+ 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){
// $('#cd_ac_pk_for_leader').val(res.data[0].id)
// }
@@ -4792,53 +4816,85 @@
$('#policy_end_date').on('change', function () {
-
- let startDateStr = $('#policy_start_date').val();
- let endDateStr = $('#policy_end_date').val();
- if (!startDateStr || !endDateStr) {
- alert('Please select both Start and End dates');
- return;
- }
+ let startDateStr = $('#policy_start_date').val();
+ let endDateStr = $('#policy_end_date').val();
- // Convert DD/MM/YYYY → Date object
- let startParts = startDateStr.split('/');
- let endParts = endDateStr.split('/');
+ if (!startDateStr || !endDateStr) {
+ alert('Please select both Start and End dates');
+ return;
+ }
- let startDate = new Date(startParts[2], startParts[1] - 1, startParts[0]);
- let endDate = new Date(endParts[2], endParts[1] - 1, endParts[0]);
+ // Convert DD/MM/YYYY → Date object
+ let startParts = startDateStr.split('/');
+ let endParts = endDateStr.split('/');
- if (endDate <= startDate) {
- alert('End Date must be greater than Start Date');
- return;
- }
+ let startDate = new Date(startParts[2], startParts[1] - 1, startParts[0]);
+ let endDate = new Date(endParts[2], endParts[1] - 1, endParts[0]);
- // ✅ Calculate Year Difference
- let yearDiff = endDate.getFullYear() - startDate.getFullYear();
+ if (endDate <= startDate) {
+ alert('End Date must be greater than Start Date');
+ return;
+ }
- // 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();
- }
+ let yearDiff = calculateYearCount(startDate, endDate);
+ console.log(`YDiff: ${yearDiff}`);
+ adjustInsurerCards(yearDiff);
});
+
+ 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() {
$('#allInsurerCards').empty();
insurerCount = 0;