FIX_CHANGE_INSURER_NOT_CHECK_DUB_INS : RV
This commit is contained in:
parent
0f88ddc117
commit
0f305ab8dc
@ -2560,6 +2560,15 @@ function popInsurerInArray(proposal_name, insurerName) {
|
|||||||
|
|
||||||
function changeInsurer(event) {
|
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:");
|
// let newInsurerName = prompt("Enter New insurer name:");
|
||||||
const insurers = <?= json_encode($insurer); ?>;
|
const insurers = <?= json_encode($insurer); ?>;
|
||||||
@ -2577,77 +2586,164 @@ function changeInsurer(event) {
|
|||||||
console.log('newInsurerName', newInsurerName)
|
console.log('newInsurerName', newInsurerName)
|
||||||
console.log('newversion', newversion)
|
console.log('newversion', newversion)
|
||||||
|
|
||||||
if (newInsurerName) {
|
const closestTh = event.target.closest('th');
|
||||||
|
let oldInsurerName = closestTh.innerText.split('⋮')[0].trim();
|
||||||
|
console.log(oldInsurerName + ' - ' + newInsurerName);
|
||||||
|
|
||||||
const closestTh = event.target.closest('th');
|
|
||||||
let oldInsurerName = closestTh.innerText.split('⋮')[0].trim();
|
if (!checkExistingInsurer(proposal_name, newInsurerName) && oldInsurerName != newInsurerName) {
|
||||||
let subThIndex = closestTh.cellIndex;
|
|
||||||
console.log(oldInsurerName + ' - ' + newInsurerName);
|
Swal.fire({
|
||||||
// Iterate over child nodes to find the text node containing "Myname"
|
title: "Insurer Dublicate Found?",
|
||||||
closestTh.childNodes.forEach(node => {
|
text: "Do you want version control!",
|
||||||
if (node.nodeType === Node.TEXT_NODE && node.textContent.includes(oldInsurerName)) {
|
icon: "warning",
|
||||||
// Replace the old name with the new name
|
showCancelButton: true,
|
||||||
node.textContent = node.textContent.replace(oldInsurerName, newInsurerName);
|
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;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
//find parent th index then it's text content
|
|
||||||
|
|
||||||
|
|
||||||
// Get the sub TH from the second header row
|
|
||||||
const table = document.getElementById('rfqTable');
|
|
||||||
const headerRows = table.querySelectorAll('thead tr');
|
|
||||||
const subTh = headerRows[1].children[subThIndex];
|
|
||||||
|
|
||||||
let accumulatedColspan = 0;
|
|
||||||
let parentTh = null;
|
|
||||||
const firstHeaderRow = headerRows[0];
|
|
||||||
// Find the parent TH for the specified sub TH index
|
|
||||||
for (let i = 0; i < firstHeaderRow.children.length; i++) {
|
|
||||||
const currentParentTh = firstHeaderRow.children[i];
|
|
||||||
const currentColspan = parseInt(currentParentTh.getAttribute('colspan')) || 1;
|
|
||||||
|
|
||||||
accumulatedColspan += currentColspan;
|
|
||||||
|
|
||||||
if (subThIndex < accumulatedColspan) {
|
|
||||||
parentTh = currentParentTh;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
changeInsurerForPremiumTable(event, newInsurerName, subThIndex)
|
|
||||||
|
|
||||||
let proposal_name = parentTh.innerText.split('⋮')[0].trim();
|
|
||||||
|
|
||||||
if (over_all_column_data[proposal_name]) {
|
|
||||||
// let tempInsurerList = over_all_column_data[proposal_name].insurers;
|
|
||||||
// console.log(tempInsurerList);
|
|
||||||
// if(!tempInsurerList.length) { return true; }
|
|
||||||
//replace the old insurer with the new insuren in global array
|
|
||||||
over_all_column_data[proposal_name].insurers.forEach(item => {
|
|
||||||
if (item.display_name === oldInsurerName) {
|
|
||||||
item.display_name = newInsurerName; // Replace with new name
|
|
||||||
item.ins_name = newInsurerName.split('-')[0].trim(); // Replace with new name
|
|
||||||
item.id = dataId
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// console.log(tempInsurerList);
|
|
||||||
// over_all_column_data[proposal_name].insurers = tempInsurerList;
|
|
||||||
console.log('insurer name replaced in golbal variable');
|
|
||||||
console.log(over_all_column_data[proposal_name].insurers);
|
|
||||||
// over_all_column_data[proposal_name].insurers = tempInsurerList
|
|
||||||
|
|
||||||
isFormDataModified = true; // if any value changeing in the table to set true
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('insurer name not replaced in golbal variable');
|
|
||||||
|
|
||||||
|
|
||||||
|
}else{
|
||||||
|
changeInsurerData(event, newInsurerName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function changeInsurerData(event, newInsurerName, dataId){
|
||||||
|
|
||||||
|
if (newInsurerName) {
|
||||||
|
|
||||||
|
const closestTh = event.target.closest('th');
|
||||||
|
let oldInsurerName = closestTh.innerText.split('⋮')[0].trim();
|
||||||
|
let subThIndex = closestTh.cellIndex;
|
||||||
|
console.log(oldInsurerName + ' - ' + newInsurerName);
|
||||||
|
// Iterate over child nodes to find the text node containing "Myname"
|
||||||
|
closestTh.childNodes.forEach(node => {
|
||||||
|
if (node.nodeType === Node.TEXT_NODE && node.textContent.includes(oldInsurerName)) {
|
||||||
|
// Replace the old name with the new name
|
||||||
|
node.textContent = node.textContent.replace(oldInsurerName, newInsurerName);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
//find parent th index then it's text content
|
||||||
|
|
||||||
|
|
||||||
|
// Get the sub TH from the second header row
|
||||||
|
const table = document.getElementById('rfqTable');
|
||||||
|
const headerRows = table.querySelectorAll('thead tr');
|
||||||
|
const subTh = headerRows[1].children[subThIndex];
|
||||||
|
|
||||||
|
let accumulatedColspan = 0;
|
||||||
|
let parentTh = null;
|
||||||
|
const firstHeaderRow = headerRows[0];
|
||||||
|
// Find the parent TH for the specified sub TH index
|
||||||
|
for (let i = 0; i < firstHeaderRow.children.length; i++) {
|
||||||
|
const currentParentTh = firstHeaderRow.children[i];
|
||||||
|
const currentColspan = parseInt(currentParentTh.getAttribute('colspan')) || 1;
|
||||||
|
|
||||||
|
accumulatedColspan += currentColspan;
|
||||||
|
|
||||||
|
if (subThIndex < accumulatedColspan) {
|
||||||
|
parentTh = currentParentTh;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
changeInsurerForPremiumTable(event, newInsurerName, subThIndex)
|
||||||
|
|
||||||
|
let proposal_name = parentTh.innerText.split('⋮')[0].trim();
|
||||||
|
|
||||||
|
if (over_all_column_data[proposal_name]) {
|
||||||
|
// let tempInsurerList = over_all_column_data[proposal_name].insurers;
|
||||||
|
// console.log(tempInsurerList);
|
||||||
|
// if(!tempInsurerList.length) { return true; }
|
||||||
|
//replace the old insurer with the new insuren in global array
|
||||||
|
over_all_column_data[proposal_name].insurers.forEach(item => {
|
||||||
|
if (item.display_name === oldInsurerName) {
|
||||||
|
item.display_name = newInsurerName; // Replace with new name
|
||||||
|
item.ins_name = newInsurerName.split('-')[0].trim(); // Replace with new name
|
||||||
|
item.id = dataId
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// console.log(tempInsurerList);
|
||||||
|
// over_all_column_data[proposal_name].insurers = tempInsurerList;
|
||||||
|
console.log('insurer name replaced in golbal variable');
|
||||||
|
console.log(over_all_column_data[proposal_name].insurers);
|
||||||
|
// over_all_column_data[proposal_name].insurers = tempInsurerList
|
||||||
|
|
||||||
|
isFormDataModified = true; // if any value changeing in the table to set true
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
function changeState(event) {
|
||||||
|
|
||||||
console.log('changeState Function called')
|
console.log('changeState Function called')
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user