FIX_QCR_AND_STC_SRI

This commit is contained in:
Srinivas-Saravanan 2025-03-20 08:51:02 +05:30
parent 45eeef869b
commit 076f40499b
3 changed files with 263 additions and 133 deletions

View File

@ -583,7 +583,8 @@ class LeadsController extends BaseController
$data['policies'] = json_decode($data['question_json'], true)['policies']; $data['policies'] = json_decode($data['question_json'], true)['policies'];
$data["child_table_data"] = json_decode($data['question_json'], true)['child_table_data']; $data["child_table_data"] = json_decode($data['question_json'], true)['child_table_data'];
// dd($data); // $data['lead_register_data'] = json_decode($data['lead_data']['custom_fields']);
// dd($data['lead_register_data']);
$data['client_type'] = $this->clientType; $data['client_type'] = $this->clientType;
$this->loadLayout('view_rfq_non_eb', $data); $this->loadLayout('view_rfq_non_eb', $data);

View File

@ -32,11 +32,11 @@
<!-- Product selection Tab --> <!-- Product selection Tab -->
<div class="tab-pane fade show active" id="product-selection"> <div class="tab-pane fade show active" id="product-selection">
<form id="productSelectionForm" class="parsley-examples" enctype="multipart/form-data"> <form id="productSelectionForm" class="parsley-examples" enctype="multipart/form-data">
<div class="row"> <div class="row">
<div class="form-group col-md-3"> <div class="form-group col-md-3">
<button type="button" class="btn btn-primary" id="getDataFromLead" onclick="assignLeadData()">Get Data From Lead</button> <button type="button" class="btn btn-primary" id="getDataFromLead" onclick="assignLeadData()">Get Data From Lead</button>
</div>
</div> </div>
</div>
<div class="row"> <div class="row">
<div class="form-group col-md-3"> <div class="form-group col-md-3">
<label>Select Buisness Type<span class="text-danger">*</span></label> <label>Select Buisness Type<span class="text-danger">*</span></label>
@ -64,7 +64,7 @@
<div class="row"> <div class="row">
<div class="form-group col-md-3"> <div class="form-group col-md-3">
<label for="client_type">Client Type<span class="text-danger">*</span></label> <label for="client_type">Client Type<span class="text-danger">*</span></label>
<select class="form-control" id="client_type" name="client_type" > <select class="form-control" id="client_type" name="client_type">
<option value="">Select Client type</option> <option value="">Select Client type</option>
<?php <?php
if (isset($client_type) && count($client_type)) { if (isset($client_type) && count($client_type)) {
@ -77,7 +77,7 @@
</div> </div>
<div class="form-group col-md-3"> <div class="form-group col-md-3">
<label for="buisnessNature">Nature of Buisness</label> <label for="buisnessNature">Nature of Buisness</label>
<input type="text" class="form-control" id="buisnessNature"/> <input type="text" class="form-control" id="buisnessNature" />
</div> </div>
</div> </div>
@ -123,8 +123,11 @@
<label for="pan_number">PAN Number</label> <label for="pan_number">PAN Number</label>
<input type="text" id="pan_number" name="pan_number" class="form-control" /> <input type="text" id="pan_number" name="pan_number" class="form-control" />
</div> </div>
<div class="form-group col-md-3"> <div class="form-group col-md-3" style="
<input type="checkbox" id="dataFromLead" name="dataFromLead" class="form-check-input" /> padding-left: 40px;
padding-top: 34px;
">
<input onclick="checkandassignLeadData()" type="checkbox" id="dataFromLead" name="dataFromLead" class="form-check-input" />
<label for="dataFromLead">Get Data From Leads</label> <label for="dataFromLead">Get Data From Leads</label>
</div> </div>
</div> </div>
@ -159,7 +162,7 @@
</div> </div>
<div class="form-group col-md-3"> <div class="form-group col-md-3">
<label for="policy_term">Policy Term<span class="text-danger">*</span></label> <label for="policy_term">Policy Term<span class="text-danger">*</span></label>
<select id="policy_term" name="policy_term" class="form-control" > <select id="policy_term" name="policy_term" class="form-control">
<option value="">Select</option> <option value="">Select</option>
<option value="1_month">1 Months</option> <option value="1_month">1 Months</option>
<option value="2_month">2 Months</option> <option value="2_month">2 Months</option>
@ -179,7 +182,7 @@
</div> </div>
<div id="locationNoDIV" class="form-group col-md-3"> <div id="locationNoDIV" class="form-group col-md-3">
<label for="location_no">No of location<span class="text-danger">*</span></label> <label for="location_no">No of location<span class="text-danger">*</span></label>
<select id="location_no" name="location_no" class="form-control" > <select id="location_no" name="location_no" class="form-control">
<option value="1">1</option> <option value="1">1</option>
<option value="2">2</option> <option value="2">2</option>
<option value="3">3</option> <option value="3">3</option>
@ -264,11 +267,11 @@
</div> </div>
</div> </div>
<script> <script>
var storedData = JSON.parse(localStorage.getItem('policyData')); var storedPolicyData = JSON.parse(localStorage.getItem('policyData'));
$(document).ready(function() { $(document).ready(function() {
// console.log("Stored date Found : ",storedData.length); // console.log("Stored date Found : ",storedPolicyData.length);
if (!$.isEmptyObject(storedData)) { if (!$.isEmptyObject(storedPolicyData)) {
prepareDataForEdit(storedData); prepareDataForEdit(storedPolicyData);
} else { } else {
console.log("inside else trying to open product sleection tab"); console.log("inside else trying to open product sleection tab");
// const productSelectionTab = new bootstrap.Tab(document.getElementById); // const productSelectionTab = new bootstrap.Tab(document.getElementById);
@ -346,7 +349,7 @@
var policyRiskSplitUpData = {}; var policyRiskSplitUpData = {};
$(document).ready(function() { $(document).ready(function() {
if ($.isEmptyObject(storedData)) { if ($.isEmptyObject(storedPolicyData)) {
$('#multilocation_type_div').hide(); $('#multilocation_type_div').hide();
} }
// When a business-type checkbox changes, handle exclusive selection // When a business-type checkbox changes, handle exclusive selection
@ -546,6 +549,7 @@
if (e.target.id === 'policy-details-tab') { if (e.target.id === 'policy-details-tab') {
if (Object.keys(productSelectionData).length > 0) { if (Object.keys(productSelectionData).length > 0) {
$("#policy-details").show(); $("#policy-details").show();
// validatePolicyBasedOnProductSelection(); // validatePolicyBasedOnProductSelection();
} else { } else {
$("#policy-details").hide(); $("#policy-details").hide();
@ -1061,9 +1065,9 @@
console.log("Policy data saved to local storage. : ", policyData); console.log("Policy data saved to local storage. : ", policyData);
} }
function loadPolicyDataBack(storedData) { function loadPolicyDataBack(storedPolicyData) {
if (storedData) { if (storedPolicyData) {
var parsedData = storedData; var parsedData = storedPolicyData;
// Assign back to original variables // Assign back to original variables
productSelectionData = parsedData.productSelection; productSelectionData = parsedData.productSelection;
@ -1086,6 +1090,7 @@
function prepareDataForEdit(data) { function prepareDataForEdit(data) {
// alert("something wrong");
loadPolicyDataBack(data); loadPolicyDataBack(data);
// Populate Product Selection // Populate Product Selection
$('#singleProduct').prop('checked', data.productSelection.singleProduct === 'on'); $('#singleProduct').prop('checked', data.productSelection.singleProduct === 'on');
@ -1163,11 +1168,48 @@
} }
function assignLeadData(){ function checkandassignLeadData() {
const lead_data = '<?= json_encode($lead_data['custom_fields']) ?>';
var checkedStatus = $("#dataFromLead").is(":checked") ? true : false;
if (lead_data){
console.log("Lead Data : ",lead_data); if (checkedStatus) {
assignLeadData();
}
}
function assignLeadData() {
const lead_data = <?= json_encode(json_decode($lead_data['custom_fields'])) ?>;
var client_type = <?= isset($lead_data['client_type']) ? $lead_data
['client_type'] : "" ?>;
var mobile = <?= isset($lead_data['client_type']) ? $lead_data
['client_type'] : "" ?>;
var email = <?= isset($lead_data['client_type']) ? $lead_data
['client_type'] : "" ?>;
var panNo = <?= isset($lead_data['client_type']) ? $lead_data
['client_type'] : "" ?>;
console.log("client_type : ".client_type);
if (lead_data) {
// lead_data = JSON.parse(lead_data);
console.log("Lead Data : ", typeof(lead_data));
if (lead_data.risk_location == "Single") {
console.log("single ");
$("#singleProduct").prop("checked", true).trigger("change");
} else {
$("#multipleProduct").prop("checked", true).trigger("change");
if (lead_data.risk_location == "multi_with_floter") {
$("#multilocation_type").val("multiFloater").trigger("change");
} else {
$("#multilocation_type").val("multiLocation").trigger("change");
}
}
$("#client_type").val(client_type).trigger("change");
$("#address1").val(lead_data.address);
} }
} }
</script> </script>

View File

@ -198,7 +198,7 @@
'insurers': [] 'insurers': []
} }
}; };
const suggestions = {}; var suggestions = {};
var storedData = JSON.parse(localStorage.getItem('policyData')); var storedData = JSON.parse(localStorage.getItem('policyData'));
var policySummary; var policySummary;
if (!$.isEmptyObject(storedData)) { if (!$.isEmptyObject(storedData)) {
@ -398,6 +398,8 @@
// Remove the proposal from quotesConfig // Remove the proposal from quotesConfig
delete quotesConfig[proposalNumber]; delete quotesConfig[proposalNumber];
delete policyConfig[proposalNumber];
} }
// Add a new row // Add a new row
@ -720,7 +722,7 @@
quotesConfig[proposalNumber].push(newQuote); quotesConfig[proposalNumber].push(newQuote);
console.log("add Quotes config", quotesConfig); console.log("add Quotes config", quotesConfig);
updateAllTables(proposalNumber, insurerName); updateAllTables(proposalNumber, insurerName);
var proposalName = `Proposal ${proposalNumber}`; var proposalName = `Proposal ${proposalNumber}`;
const proposalHeader = document.querySelector(`th[data-proposal="${proposalNumber}"]`); const proposalHeader = document.querySelector(`th[data-proposal="${proposalNumber}"]`);
if (proposalHeader) { if (proposalHeader) {
@ -740,11 +742,11 @@
quotesConfig[proposalNumber].push(newQuote); quotesConfig[proposalNumber].push(newQuote);
console.log("add Quotes config", quotesConfig); console.log("add Quotes config", quotesConfig);
updateAllTables(proposalNumber, insurerName); updateAllTables(proposalNumber, insurerName);
var proposalName = `Proposal ${proposalNumber}`; var proposalName = `Proposal ${proposalNumber}`;
const proposalHeader = document.querySelector(`th[data-proposal="${proposalNumber}"]`); const proposalHeader = document.querySelector(`th[data-proposal="${proposalNumber}"]`);
if (proposalHeader) { if (proposalHeader) {
console.log("Proposal heade length : ",quotesConfig[proposalNumber].length) console.log("Proposal heade length : ", quotesConfig[proposalNumber].length)
proposalHeader.colSpan = quotesConfig[proposalNumber].length; proposalHeader.colSpan = quotesConfig[proposalNumber].length;
} }
} }
@ -862,8 +864,10 @@
console.log("quote index ", quoteIndex); console.log("quote index ", quoteIndex);
if (quoteIndex !== -1) { if (quoteIndex !== -1) {
quotesConfig[proposalNumber].splice(quoteIndex, 1); quotesConfig[proposalNumber].splice(quoteIndex, 1);
policyConfig[proposalNumber].splice(quoteIndex, 1);
if (quotesConfig[proposalNumber].length === 0) { if (quotesConfig[proposalNumber].length === 0) {
delete quotesConfig[proposalNumber]; delete quotesConfig[proposalNumber];
delete policyConfig[proposalNumber];
} }
} }
@ -939,11 +943,11 @@
insertPosition += quotesConfig[i]?.length || 0; insertPosition += quotesConfig[i]?.length || 0;
} }
insertPosition += quotesConfig[proposalNumber].length - 1; insertPosition += quotesConfig[proposalNumber].length - 1;
console.log("Header insert position : ",insertPosition); console.log("Header insert position : ", insertPosition);
console.log("Header insert position : ",newQuoteHeader.outerHTML); console.log("Header insert position : ", newQuoteHeader.outerHTML);
console.log("Header insert position : ",headerRow2.children[insertPosition].outerHTML); console.log("Header insert position : ", headerRow2.children[insertPosition].outerHTML);
console.log("Header insert position : ",quotesConfig[proposalNumber].length); console.log("Header insert position : ", quotesConfig[proposalNumber].length);
console.log("Header insert position : ",proposalHeader); console.log("Header insert position : ", proposalHeader);
// Update headers // Update headers
headerRow2.insertBefore(newQuoteHeader, headerRow2.children[insertPosition]); headerRow2.insertBefore(newQuoteHeader, headerRow2.children[insertPosition]);
if (proposalHeader) proposalHeader.colSpan = quotesConfig[proposalNumber].length; if (proposalHeader) proposalHeader.colSpan = quotesConfig[proposalNumber].length;
@ -952,8 +956,8 @@
table.querySelectorAll('tbody tr').forEach(row => { table.querySelectorAll('tbody tr').forEach(row => {
const lastCell = row.querySelector(`td:nth-child(${insertPosition})`); const lastCell = row.querySelector(`td:nth-child(${insertPosition})`);
const newCell = lastCell.cloneNode(true); const newCell = lastCell.cloneNode(true);
console.log("Header insert position lasr cell: ",lastCell.outerHTML) console.log("Header insert position lasr cell: ", lastCell.outerHTML)
console.log("Header insert position new cell: ",newCell.outerHTML) console.log("Header insert position new cell: ", newCell.outerHTML)
newCell.contentEditable = true; newCell.contentEditable = true;
newCell.onclick = () => getAnswer(table.id, row.id); newCell.onclick = () => getAnswer(table.id, row.id);
row.insertBefore(newCell, row.children[insertPosition]); row.insertBefore(newCell, row.children[insertPosition]);
@ -1085,7 +1089,7 @@
var policy_question = row_fields[rowID].display_value; var policy_question = row_fields[rowID].display_value;
var answer_type = row_fields[rowID].answer_type; var answer_type = row_fields[rowID].answer_type;
var tableID = tableData?.table_id ?? null; var tableID = tableData?.table_id ?? null;
// console.log('table id ', tableID); console.log('row fields : ', row_fields);
var SNO = getSNO(tableID); var SNO = getSNO(tableID);
if (tableData) { if (tableData) {
suggestions[rowID] = row_fields[rowID].answer_type; suggestions[rowID] = row_fields[rowID].answer_type;
@ -1267,7 +1271,7 @@
localStorage.setItem('allTablesJsonData', JSON.stringify(rfq_data)); localStorage.setItem('allTablesJsonData', JSON.stringify(rfq_data));
jsonToTables(); jsonToTables();
// generateTable(document.getElementById('tablesContainer')); // generateTable(document.getElementById('tablesContainer'));
console.log("polices Length ", policies.length); // console.log("polices Length ", policies.length);
} else { } else {
generateTable(document.getElementById('tablesContainer')); generateTable(document.getElementById('tablesContainer'));
@ -1511,27 +1515,49 @@
function addOrRemoveIcon(element, event) { function addOrRemoveIcon(element, event) {
event.stopPropagation(); event.stopPropagation();
let icon = element.querySelector('.fa-check-square');
// Get the parent dropdown to access both buttons reliably
const dropdown = element.closest('.dropdown-content');
const qcrButton = dropdown.querySelector('.qcrProposal');
const stcButton = dropdown.querySelector('.sendClientProposal');
// Get current icons
let qcrIcon = qcrButton.querySelector('.fa-check-square');
let stcIcon = stcButton.querySelector('.fa-check-square');
// If clicked on QCR button
if (element.classList.contains('qcrProposal')) { if (element.classList.contains('qcrProposal')) {
var client_proposal_element = document.querySelector('.sendClientProposal'); if (!qcrIcon) {
var icon2 = client_proposal_element.querySelector('.fa-check-square'); // QCR being checked: add icon to both
if (icon) { createIcon(qcrButton);
if (icon2) { if (!stcIcon) {
client_proposal_element.removeChild(icon2); createIcon(stcButton);
} }
} else { } else {
if (!icon2) { // QCR being unchecked: remove icon from both
createIcon(client_proposal_element); qcrButton.removeChild(qcrIcon);
if (stcIcon) {
stcButton.removeChild(stcIcon);
} }
} }
} }
if (!icon) { // If clicked on Send to Client button
createIcon(element); else if (element.classList.contains('sendClientProposal')) {
// console.log("checkbox added"); if (!stcIcon) {
} else { // STC being checked: must ensure QCR is checked first
element.removeChild(icon); if (!qcrIcon) {
// console.log("checkbox removed"); createIcon(qcrButton); // Ensure QCR is checked
}
createIcon(stcButton);
} else {
// STC being unchecked: only remove STC icon
stcButton.removeChild(stcIcon);
// QCR remains unchanged
}
} }
// Update your data model or save state if needed
// updateHeaderCheckBoxProperties();
} }
function createIcon(element) { function createIcon(element) {
@ -1712,6 +1738,7 @@
} }
$('.loader').fadeOut(); $('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow'); $('.loader-mask').delay(350).fadeOut('slow');
// window.location.reload();
}, },
error: function(xhr, status, error) { error: function(xhr, status, error) {
$('.loader').fadeOut(); $('.loader').fadeOut();
@ -1751,8 +1778,6 @@
uniqueInsurers.push({ uniqueInsurers.push({
ins_name: insurer.insurerName, ins_name: insurer.insurerName,
qcr: 1,
stc: 1,
display_name: insurer.insurerName, display_name: insurer.insurerName,
id: insurer.id id: insurer.id
}); });
@ -1789,17 +1814,34 @@
let headerIndex = 0; let headerIndex = 0;
parentHeaders.forEach(header => { parentHeaders.forEach(header => {
const colspan = parseInt(header.getAttribute('colspan')) || 1; console.log("Found header ", header);
if (header.innerText.trim().startsWith("Proposal")) {
var policyNumber = header.getAttribute("data-proposal");
var colspan = parseInt(quotesConfig[policyNumber].length);
console.log("Found header true colspan : ", colspan);
} else {
var colspan = parseInt(header.getAttribute('colspan')) || 1;
}
const subHeaderArray = []; const subHeaderArray = [];
console.log("processing save function header : ", header);
// console.log("processing save colspn : ",colspan);
for (let i = 0; i < colspan; i++) { for (let i = 0; i < colspan; i++) {
subHeaderArray.push(subHeaders[headerIndex].innerText.replace('⋮', '').trim()); const subheaderHTML = subHeaders[headerIndex].innerHTML;
const subheaderText = subheaderHTML.replace(/<span class="three-dot-menu"[\s\S]*?<\/div>/g, '').trim();
subHeaderArray.push(subheaderText);
headerIndex++; headerIndex++;
} }
console.log("HEader : ", header.innerText.replace('⋮', '').split('\n')[0].replace(/:.*/, '').trim()); console.log("inside save colspn : ", colspan);
const headerHTML = header.innerHTML;
const headerText = headerHTML.replace(/<span class="three-dot-menu"[\s\S]*?<\/div>/g, '').trim();
console.log("processing sub header array : ", subHeaderArray);
console.log("HEader : ", headerText);
headers.push({ headers.push({
parentHeader: header.innerText.replace('⋮', '').split('\n')[0].replace(/:.*/, '').trim(), // parentHeader: header.innerText.replace('⋮', '').split('\n')[0].replace(/:.*/, '').trim(),
parentHeader: headerText,
subHeaders: subHeaderArray subHeaders: subHeaderArray
}); });
console.log("processing sub header array : ", headers);
}); });
// Process each row in the current table // Process each row in the current table
@ -1846,14 +1888,15 @@
if (input.type === "checkbox") { if (input.type === "checkbox") {
content = input.checked ? "Checked" : "Not Checked"; // Handling checkboxes content = input.checked ? "Checked" : "Not Checked"; // Handling checkboxes
display_value = input.checked ? "Checked" : "Not Checked"; display_content = input.checked ? "Checked" : "Not Checked";
} else { } else {
content = input.value; // Handling other input types like text, select, textarea content = input.value; // Handling other input types like text, select, textarea
display_value = cell.innerText.trim(); display_content = cell.innerText.trim();
console.log("processing sub header array : ", content);
} }
} else { } else {
content = cell.innerText.trim(); // If no input is found, use the cell's text content = cell.innerText.trim(); // If no input is found, use the cell's text
display_value = cell.innerText.trim(); display_content = cell.innerText.trim();
} }
} }
@ -1864,7 +1907,7 @@
subth: subHeader, subth: subHeader,
// value: cell.innerText, // value: cell.innerText,
input_value: content, input_value: content,
display_value: display_value, display_content: display_content,
rowspan: cell.rowSpan rowspan: cell.rowSpan
}); });
@ -1873,7 +1916,7 @@
}); });
data.push(rowData); data.push(rowData);
console.log("data gets pushed here ", data); // console.log("processing sub header array : ",content);
}); });
tablePolicyName = [...selectedPolicies].find(policy => tableId.startsWith(policy)) || null; tablePolicyName = [...selectedPolicies].find(policy => tableId.startsWith(policy)) || null;
console.log(selectedPolicies); console.log(selectedPolicies);
@ -1975,6 +2018,24 @@
return quotesConfiguration; return quotesConfiguration;
} }
function addSuggestion(rowData) {
console.log("child table data ", rowData);
console.log("child table data ", rowData.row_id);
console.log("child table data ", child_table_data[rowData.row_id]);
var table_data = child_table_data[rowData.row_id];
table_data.forEach(table => {
table.table_row_contents.forEach(row => {
const key = Object.keys(row)[0]; // Get the first key in the row object
const answerType = row[key].answer_type; // Get the answer_type
suggestions[key] = answerType; // Store in suggestions object
});
});
console.log("child table data ", suggestions);
// child_table_data[rowData.rowID]
}
function jsonToTables() { function jsonToTables() {
@ -2006,6 +2067,9 @@
let increaseBy = proposalCount * 150; let increaseBy = proposalCount * 150;
console.log("trying to find checkbox data : : : ", increaseBy); console.log("trying to find checkbox data : : : ", increaseBy);
suggestions = {};
// Group tables by policy name // Group tables by policy name
const policyTables = {}; const policyTables = {};
@ -2062,7 +2126,7 @@
} }
// Handle regular cells // Handle regular cells
else { else {
td.innerHTML = processCellContent(cellData.input_value, rowData,cellData.display_value); td.innerHTML = processCellContent(cellData.input_value, rowData, cellData.display_content);
if (cellData.parentth.startsWith("Proposal")) { if (cellData.parentth.startsWith("Proposal")) {
td.onclick = () => getAnswer(table.id, tr.id); td.onclick = () => getAnswer(table.id, tr.id);
if (cellData.subth != "Quote asked") { if (cellData.subth != "Quote asked") {
@ -2148,7 +2212,7 @@
${header.parentHeader} ${header.parentHeader}
<span class="three-dot-menu" >&#8942;</span> <span class="three-dot-menu" >&#8942;</span>
<div class="dropdown-content"> <div class="dropdown-content">
<button id = "isQCR" onclick = "addOrRemoveIcon(this,event)"class="qcrProposal" style="background-color: rgb(221, 221, 221);">QCR ${headerCheckBoxProperties['qcr'] == 1 ? `<i <button id = "isQCR" onclick = "addOrRemoveIcon(this,event)" class="qcrProposal" style="background-color: rgb(221, 221, 221);">QCR ${headerCheckBoxProperties['qcr'] == 1 ? `<i
class="fa fa-check-square" class="fa fa-check-square"
style="color: green; margin-left: 8px; "></i> `:"" }</button> style="color: green; margin-left: 8px; "></i> `:"" }</button>
<button id = "isSTC" class="sendClientProposal" onclick = "addOrRemoveIcon(this,event)" <button id = "isSTC" class="sendClientProposal" onclick = "addOrRemoveIcon(this,event)"
@ -2170,20 +2234,28 @@
// Sub headers // Sub headers
header.subHeaders.forEach(subHeader => { header.subHeaders.forEach(subHeader => {
const th2 = document.createElement('th'); const th2 = document.createElement('th');
if (header.parentHeader.startsWith("Proposal") && subHeader != "Quote asked") { if (header.parentHeader.startsWith("Proposal")) {
console.log("this is the subheader : ", subHeader);
th2.classList.add("insurer_proposal"); if (subHeader != "Quote asked") {
th2.innerHTML = ` console.log("this is the subheader : ", subHeader);
th2.classList.add("insurer_proposal");
th2.innerHTML = `
${subHeader} ${subHeader}
<span class="three-dot-menu">&#8942;</span> <span class="three-dot-menu">&#8942;</span>
<div class="dropdown-content"> <div class="dropdown-content">
<button onclick="changeInsurer(event, ${header.parentHeader.split(' ')[1]}, '${subHeader}')">Change Insurer</button> <button onclick="changeInsurer(event, ${header.parentHeader.split(' ')[1]}, '${subHeader}')">Change Insurer</button>
<button onclick="removeQuote(event, ${header.parentHeader.split(' ')[1]}, '${subHeader}')">Remove Quote</button> <button onclick="removeQuote(event, ${header.parentHeader.split(' ')[1]}, '${subHeader}')">Remove Quote</button>
</div> </div>
`; `;
} else {
th2.textContent = subHeader;
}
th2.setAttribute('data-proposal', header.parentHeader.split(' ')[1]); th2.setAttribute('data-proposal', header.parentHeader.split(' ')[1]);
th2.setAttribute("data-quote", subHeader);
th1.setAttribute('data-proposal', header.parentHeader.split(' ')[1]); th1.setAttribute('data-proposal', header.parentHeader.split(' ')[1]);
console.log("header insert position ",th1.getAttribute()) // console.log("header insert position ",th1.getAttribute())
} else { } else {
th2.textContent = subHeader; th2.textContent = subHeader;
@ -2200,9 +2272,13 @@
} }
// Helper to process cell content // Helper to process cell content
function processCellContent(value, cellData = null,displayValue) { function processCellContent(value, cellData = null, displayValue) {
if (value.startsWith('Check') || value.startsWith('Not')) { if (value.startsWith('Check') || value.startsWith('Not')) {
if (value == "Checked") {
addSuggestion(cellData);
}
// console.log("insude the function value ", value); // console.log("insude the function value ", value);
return `<input type="checkbox" ${value == "Checked" ? "checked" :""} class = "sno-checkbox" /> ${cellData.SNO} ${cellData.SNO == 'Fire' || cellData.SNO == 'Burglary' return `<input type="checkbox" ${value == "Checked" ? "checked" :""} class = "sno-checkbox" /> ${cellData.SNO} ${cellData.SNO == 'Fire' || cellData.SNO == 'Burglary'
? `<br><button class = "btn btn-primary btn-sm" onclick = "getPolicyInfo()" class="policy-link" data-policy-name="${cellData.SNO}">Register</a>` ? `<br><button class = "btn btn-primary btn-sm" onclick = "getPolicyInfo()" class="policy-link" data-policy-name="${cellData.SNO}">Register</a>`
@ -2241,7 +2317,7 @@
// Three-dot menu handlers // Three-dot menu handlers
document.querySelectorAll('.three-dot-menu').forEach(menu => { document.querySelectorAll('.three-dot-menu').forEach(menu => {
menu.addEventListener('click', showDropdown); menu.addEventListener('click', showDropdown);
console.log("event listener called "); // console.log("event listener called ");
}); });
// Policy link handlers // Policy link handlers
@ -2321,8 +2397,9 @@
}; };
var proposal = getProposalsWithQCRZero(overallData); var proposal = getProposalsWithQCRZero(overallData);
console.log("column to hide : ", proposal);
proposal.forEach(function(prop) { proposal.forEach(function(prop) {
console.log("column prop : ", prop);
hideColumn(prop); hideColumn(prop);
}) })
@ -2332,51 +2409,50 @@
console.log(`Hiding column: ${columnName}`); console.log(`Hiding column: ${columnName}`);
document.querySelectorAll("table").forEach(table => { document.querySelectorAll("table").forEach(table => {
let headers = table.querySelectorAll("th"); // 1. Find the main proposal header in the first header row
let rows = table.querySelectorAll("tr"); const mainHeaderRow = table.querySelector('thead tr:first-child');
let proposalHeader = null;
let proposalColspan = 1;
let startColumnIndex = -1;
let columnIndex = -1; // Find the header matching the columnName and its position
Array.from(mainHeaderRow.children).forEach((th, index) => {
// Find the column index based on header text if (th.textContent.trim().startsWith(columnName)) {
headers.forEach((header, index) => { proposalHeader = th;
if (header.textContent.trim().startsWith(columnName)) { proposalColspan = parseInt(th.getAttribute('colspan')) || 1;
columnIndex = index; startColumnIndex = index; // Starting index of the proposal header
header.style.display = "none"; // Hide header return;
} }
}); });
if (columnIndex === -1) { if (!proposalHeader) {
console.log(`Column "${columnName}" not found in any table.`); console.log(`Column "${columnName}" not found.`);
return; return;
} }
// Hide corresponding cells while respecting colspan & rowspan // 2. Hide the main proposal header
rows.forEach(row => { proposalHeader.style.display = "none";
let cells = Array.from(row.children);
let cellIndex = 0;
for (let cell of cells) { // 3. Find and hide all subheaders under this proposal
let colSpan = cell.colSpan || 1; const subHeaderRow = table.querySelector('thead tr:last-child');
let rowSpan = cell.rowSpan || 1; const subHeaders = Array.from(subHeaderRow.children);
if (cellIndex === columnIndex) { // Calculate range of subheaders to hide (same colspan as proposal header)
if (colSpan > 1) { const endColumnIndex = startColumnIndex + proposalColspan - 1;
cell.colSpan--; // Reduce colspan instead of hiding for (let i = startColumnIndex; i <= endColumnIndex; i++) {
} else { if (subHeaders[i]) subHeaders[i].style.display = "none";
cell.style.display = "none"; // Hide the cell }
}
}
cellIndex += colSpan; // Move to the next column index // 4. Hide corresponding cells in all data rows
table.querySelectorAll('tbody tr').forEach(row => {
const cells = Array.from(row.children);
for (let i = startColumnIndex; i <= endColumnIndex; i++) {
if (cells[i]) cells[i].style.display = "none";
} }
}); });
}); });
} }
function hideNonQCRRows() { function hideNonQCRRows() {
console.log("hideNonQCRRows function called"); console.log("hideNonQCRRows function called");
// Select all tables // Select all tables
@ -2538,78 +2614,89 @@
function contentNonEditableInsurerAdded(overallcolumnData) { function contentNonEditableInsurerAdded(overallcolumnData) {
let insNames = []; let insNames = [];
Object.entries(overallcolumnData).forEach(([proposalKey, proposalValue]) => { Object.entries(overallcolumnData).forEach(([proposalKey, proposalValue]) => {
if (proposalValue.insurers.length > 0) { if (proposalValue.insurers.length > 0) {
insNames.push(proposalKey); // Push proposal key if insurers are present insNames.push(proposalKey); // Push proposal key if insurers are present
} }
}); });
console.log("overall column Data : ", insNames); console.log("Insurer names to make non-editable:", insNames);
$("table").each(function() { $("table").each(function() {
var table = $(this); var table = $(this);
var mainHeaderRow = table.find("tr:first-child"); // First row as main header var mainHeaderRow = table.find("tr:first-child"); // First row as main header
var targetColumnIndexes = new Set(); var targetColumnIndexes = new Set();
var colIndexTracker = [];
// Step 1: Create a mapping of visual index to column header text
var headerMapping = [];
var visualIndex = 0; var visualIndex = 0;
// Step 1: Find columns where the header matches `insNames` mainHeaderRow.children("th, td").each(function() {
mainHeaderRow.children("th, td").each(function(actualIndex) {
colIndexTracker[visualIndex] = actualIndex;
var cellText = $(this).text().trim(); var cellText = $(this).text().trim();
// console.log("order : ",cellText); var colspan = parseInt($(this).attr("colspan") || 1, 10);
if (insNames.some(ins => cellText.startsWith(ins))) {
targetColumnIndexes.add(visualIndex); // Store the header text at this visual index
for (var i = 0; i < colspan; i++) {
headerMapping[visualIndex + i] = cellText;
} }
visualIndex += parseInt($(this).attr("colspan") || 1, 10); // Check if this column matches any insurer name
if (insNames.some(ins => cellText.startsWith(ins))) {
for (var i = 0; i < colspan; i++) {
targetColumnIndexes.add(visualIndex + i);
}
}
visualIndex += colspan;
}); });
// console.log("order fro header : ",targetColumnIndexes);
console.log("Target column indexes:", Array.from(targetColumnIndexes));
if (targetColumnIndexes.size === 0) return; // If no matching column is found, exit if (targetColumnIndexes.size === 0) return; // If no matching column is found, exit
var rowSpans = {}; var rowSpans = {};
// Step 2: Iterate through rows and set cells as non-editable // Step 2: Iterate through rows and set cells as non-editable
table.find("tr").each(function() { table.find("tr").each(function(rowIndex) {
var row = $(this); var row = $(this);
var currentVisualIndex = 0; var currentVisualIndex = 0;
row.children("td, th").each(function(actualIndex) { row.children("td, th").each(function() {
while (rowSpans[currentVisualIndex]) { // Skip cells that are covered by rowspans from previous rows
currentVisualIndex++; // Skip row-spanned columns while (rowSpans[currentVisualIndex] > 0) {
rowSpans[currentVisualIndex]--;
currentVisualIndex++;
} }
var cell = $(this); var cell = $(this);
var actualColIndex = colIndexTracker[currentVisualIndex];
var cellColspan = parseInt(cell.attr("colspan") || 1, 10); var cellColspan = parseInt(cell.attr("colspan") || 1, 10);
var cellRowspan = parseInt(cell.attr("rowspan") || 1, 10); var cellRowspan = parseInt(cell.attr("rowspan") || 1, 10);
// console.log("order actualcol index : ",actualColIndex);
if (targetColumnIndexes.has(actualColIndex)) { // Check if any of the columns this cell spans are in our target set
// console.log("inside if conditon order"); let makeNonEditable = false;
for (let i = 0; i < cellColspan; i++) {
if (targetColumnIndexes.has(currentVisualIndex + i)) {
makeNonEditable = true;
break;
}
}
if (makeNonEditable) {
cell.attr("contenteditable", "false"); cell.attr("contenteditable", "false");
removeOnClickFromColumnCells(cell); removeOnClickFromColumnCells(cell);
} }
// Track rowspan // Track rowspan for future rows
if (cellRowspan > 1) { if (cellRowspan > 1) {
for (var i = 0; i < cellColspan; i++) { for (var i = 0; i < cellColspan; i++) {
rowSpans[currentVisualIndex + i] = (rowSpans[currentVisualIndex + i] || 0) + (cellRowspan - 1); rowSpans[currentVisualIndex + i] = (rowSpans[currentVisualIndex + i] || 0) + (cellRowspan - 1);
} }
} }
// Move to the next visual position
currentVisualIndex += cellColspan; currentVisualIndex += cellColspan;
}); });
// Reduce rowspan count for the next row
Object.keys(rowSpans).forEach(function(key) {
if (rowSpans[key] > 0) {
rowSpans[key]--;
}
});
}); });
}); });
} }
</script> </script>