FIX_CHANGE_INSURER_NOT_CHECK_DUB_INS : RV

This commit is contained in:
VENKATESHWARAN 2025-06-17 14:44:44 +05:30
parent 0f88ddc117
commit 0f305ab8dc

View File

@ -2560,6 +2560,15 @@ function popInsurerInArray(proposal_name, insurerName) {
function changeInsurer(event) {
console.log('change insure event', event);
let proposal_name = getParentHeaderTh(event);
console.log('proposel Name', proposal_name)
if(proposal_name == null || proposal_name == ""){
toastr.warning("Could not change the insurer", "WARNING")
return;
}
// let newInsurerName = prompt("Enter New insurer name:");
const insurers = <?= json_encode($insurer); ?>;
@ -2577,6 +2586,43 @@ function changeInsurer(event) {
console.log('newInsurerName', newInsurerName)
console.log('newversion', newversion)
const closestTh = event.target.closest('th');
let oldInsurerName = closestTh.innerText.split('⋮')[0].trim();
console.log(oldInsurerName + ' - ' + newInsurerName);
if (!checkExistingInsurer(proposal_name, newInsurerName) && oldInsurerName != newInsurerName) {
Swal.fire({
title: "Insurer Dublicate Found?",
text: "Do you want version control!",
icon: "warning",
showCancelButton: true,
confirmButtonColor: "#3085d6",
cancelButtonColor: "#d33",
confirmButtonText: "Yes, Procced!"
}).then((result) => {
if (result.isConfirmed) {
let modifiedInsurerName = constructInsurerNameWithVersion(proposal_name, newInsurerName);
console.log('modifiedInsurerName', modifiedInsurerName);
changeInsurerData(event, modifiedInsurerName, dataId)
}else{
return false;
}
});
}else{
changeInsurerData(event, newInsurerName)
}
});
}
function changeInsurerData(event, newInsurerName, dataId){
if (newInsurerName) {
const closestTh = event.target.closest('th');
@ -2644,10 +2690,60 @@ function changeInsurer(event) {
console.log('insurer name not replaced in golbal variable');
}else{
toastr.warning("Could not change the insurer", "WARNING")
return;
}
});
}
function getParentHeaderTh(event) {
const currentTh = event.target.closest('th');
if (!currentTh) return;
const colIndex = currentTh.cellIndex;
// Get all header rows
const thead = currentTh.closest('thead');
const headerRows = thead.querySelectorAll('tr');
if (headerRows.length < 2) return; // need at least 2 header rows
const secondRowThs = headerRows[1].querySelectorAll('th');
const firstRowThs = headerRows[0].querySelectorAll('th');
// Step 1: Find actual column span index of clicked th in 2nd row
let actualColIndex = 0;
for (let i = 0; i < secondRowThs.length; i++) {
const th = secondRowThs[i];
const colspan = parseInt(th.getAttribute('colspan')) || 1;
if (th === currentTh) break;
actualColIndex += colspan;
}
// Step 2: Match it with first row <th>s
let colSpanCounter = 0;
for (let i = 0; i < firstRowThs.length; i++) {
const th = firstRowThs[i];
const colspan = parseInt(th.getAttribute('colspan')) || 1;
if (actualColIndex >= colSpanCounter && actualColIndex < colSpanCounter + colspan) {
let proposelName = th.innerText.split('⋮')[0].trim();
console.log("Parent TH Proposel innerText:", proposelName);
console.log("Parent TH Proposel textContent:", th.textContent.trim());
return proposelName;
}
colSpanCounter += colspan;
}
console.log("Parent header not found");
return null;
}
function changeState(event) {
console.log('changeState Function called')