From 076f40499bfe43952173de81ef59560de17889f7 Mon Sep 17 00:00:00 2001 From: Srinivas-Saravanan Date: Thu, 20 Mar 2025 08:51:02 +0530 Subject: [PATCH] FIX_QCR_AND_STC_SRI --- app/Controllers/LeadsController.php | 3 +- app/Views/policyRegisterModel.php | 88 +++++--- app/Views/view_rfq_non_eb.php | 305 ++++++++++++++++++---------- 3 files changed, 263 insertions(+), 133 deletions(-) diff --git a/app/Controllers/LeadsController.php b/app/Controllers/LeadsController.php index 3205553c..2cba662f 100644 --- a/app/Controllers/LeadsController.php +++ b/app/Controllers/LeadsController.php @@ -583,7 +583,8 @@ class LeadsController extends BaseController $data['policies'] = json_decode($data['question_json'], true)['policies']; $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; $this->loadLayout('view_rfq_non_eb', $data); diff --git a/app/Views/policyRegisterModel.php b/app/Views/policyRegisterModel.php index 9e440904..06d63a47 100644 --- a/app/Views/policyRegisterModel.php +++ b/app/Views/policyRegisterModel.php @@ -32,11 +32,11 @@
-
-
- +
+
+ +
-
@@ -64,7 +64,7 @@
-
- +
@@ -123,8 +123,11 @@
-
- +
+
@@ -159,7 +162,7 @@
- @@ -179,7 +182,7 @@
- @@ -264,11 +267,11 @@
\ No newline at end of file diff --git a/app/Views/view_rfq_non_eb.php b/app/Views/view_rfq_non_eb.php index b89cefeb..ff7b3881 100644 --- a/app/Views/view_rfq_non_eb.php +++ b/app/Views/view_rfq_non_eb.php @@ -198,7 +198,7 @@ 'insurers': [] } }; - const suggestions = {}; + var suggestions = {}; var storedData = JSON.parse(localStorage.getItem('policyData')); var policySummary; if (!$.isEmptyObject(storedData)) { @@ -398,6 +398,8 @@ // Remove the proposal from quotesConfig delete quotesConfig[proposalNumber]; + + delete policyConfig[proposalNumber]; } // Add a new row @@ -720,7 +722,7 @@ quotesConfig[proposalNumber].push(newQuote); console.log("add Quotes config", quotesConfig); updateAllTables(proposalNumber, insurerName); - + var proposalName = `Proposal ${proposalNumber}`; const proposalHeader = document.querySelector(`th[data-proposal="${proposalNumber}"]`); if (proposalHeader) { @@ -740,11 +742,11 @@ quotesConfig[proposalNumber].push(newQuote); console.log("add Quotes config", quotesConfig); updateAllTables(proposalNumber, insurerName); - + var proposalName = `Proposal ${proposalNumber}`; const proposalHeader = document.querySelector(`th[data-proposal="${proposalNumber}"]`); if (proposalHeader) { - console.log("Proposal heade length : ",quotesConfig[proposalNumber].length) + console.log("Proposal heade length : ", quotesConfig[proposalNumber].length) proposalHeader.colSpan = quotesConfig[proposalNumber].length; } } @@ -862,8 +864,10 @@ console.log("quote index ", quoteIndex); if (quoteIndex !== -1) { quotesConfig[proposalNumber].splice(quoteIndex, 1); + policyConfig[proposalNumber].splice(quoteIndex, 1); if (quotesConfig[proposalNumber].length === 0) { delete quotesConfig[proposalNumber]; + delete policyConfig[proposalNumber]; } } @@ -939,11 +943,11 @@ insertPosition += quotesConfig[i]?.length || 0; } insertPosition += quotesConfig[proposalNumber].length - 1; - console.log("Header insert position : ",insertPosition); - console.log("Header insert position : ",newQuoteHeader.outerHTML); - console.log("Header insert position : ",headerRow2.children[insertPosition].outerHTML); - console.log("Header insert position : ",quotesConfig[proposalNumber].length); - console.log("Header insert position : ",proposalHeader); + console.log("Header insert position : ", insertPosition); + console.log("Header insert position : ", newQuoteHeader.outerHTML); + console.log("Header insert position : ", headerRow2.children[insertPosition].outerHTML); + console.log("Header insert position : ", quotesConfig[proposalNumber].length); + console.log("Header insert position : ", proposalHeader); // Update headers headerRow2.insertBefore(newQuoteHeader, headerRow2.children[insertPosition]); if (proposalHeader) proposalHeader.colSpan = quotesConfig[proposalNumber].length; @@ -952,8 +956,8 @@ table.querySelectorAll('tbody tr').forEach(row => { const lastCell = row.querySelector(`td:nth-child(${insertPosition})`); const newCell = lastCell.cloneNode(true); - console.log("Header insert position lasr cell: ",lastCell.outerHTML) - console.log("Header insert position new cell: ",newCell.outerHTML) + console.log("Header insert position lasr cell: ", lastCell.outerHTML) + console.log("Header insert position new cell: ", newCell.outerHTML) newCell.contentEditable = true; newCell.onclick = () => getAnswer(table.id, row.id); row.insertBefore(newCell, row.children[insertPosition]); @@ -1085,7 +1089,7 @@ var policy_question = row_fields[rowID].display_value; var answer_type = row_fields[rowID].answer_type; var tableID = tableData?.table_id ?? null; - // console.log('table id ', tableID); + console.log('row fields : ', row_fields); var SNO = getSNO(tableID); if (tableData) { suggestions[rowID] = row_fields[rowID].answer_type; @@ -1267,7 +1271,7 @@ localStorage.setItem('allTablesJsonData', JSON.stringify(rfq_data)); jsonToTables(); // generateTable(document.getElementById('tablesContainer')); - console.log("polices Length ", policies.length); + // console.log("polices Length ", policies.length); } else { generateTable(document.getElementById('tablesContainer')); @@ -1511,27 +1515,49 @@ function addOrRemoveIcon(element, event) { 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')) { - var client_proposal_element = document.querySelector('.sendClientProposal'); - var icon2 = client_proposal_element.querySelector('.fa-check-square'); - if (icon) { - if (icon2) { - client_proposal_element.removeChild(icon2); + if (!qcrIcon) { + // QCR being checked: add icon to both + createIcon(qcrButton); + if (!stcIcon) { + createIcon(stcButton); } } else { - if (!icon2) { - createIcon(client_proposal_element); + // QCR being unchecked: remove icon from both + qcrButton.removeChild(qcrIcon); + if (stcIcon) { + stcButton.removeChild(stcIcon); } } } - if (!icon) { - createIcon(element); - // console.log("checkbox added"); - } else { - element.removeChild(icon); - // console.log("checkbox removed"); + // If clicked on Send to Client button + else if (element.classList.contains('sendClientProposal')) { + if (!stcIcon) { + // STC being checked: must ensure QCR is checked first + if (!qcrIcon) { + 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) { @@ -1712,6 +1738,7 @@ } $('.loader').fadeOut(); $('.loader-mask').delay(350).fadeOut('slow'); + // window.location.reload(); }, error: function(xhr, status, error) { $('.loader').fadeOut(); @@ -1751,8 +1778,6 @@ uniqueInsurers.push({ ins_name: insurer.insurerName, - qcr: 1, - stc: 1, display_name: insurer.insurerName, id: insurer.id }); @@ -1789,17 +1814,34 @@ let headerIndex = 0; 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 = []; + console.log("processing save function header : ", header); + // console.log("processing save colspn : ",colspan); for (let i = 0; i < colspan; i++) { - subHeaderArray.push(subHeaders[headerIndex].innerText.replace('⋮', '').trim()); + const subheaderHTML = subHeaders[headerIndex].innerHTML; + const subheaderText = subheaderHTML.replace(//g, '').trim(); + subHeaderArray.push(subheaderText); 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(//g, '').trim(); + console.log("processing sub header array : ", subHeaderArray); + console.log("HEader : ", headerText); headers.push({ - parentHeader: header.innerText.replace('⋮', '').split('\n')[0].replace(/:.*/, '').trim(), + // parentHeader: header.innerText.replace('⋮', '').split('\n')[0].replace(/:.*/, '').trim(), + parentHeader: headerText, subHeaders: subHeaderArray }); + console.log("processing sub header array : ", headers); }); // Process each row in the current table @@ -1846,14 +1888,15 @@ if (input.type === "checkbox") { content = input.checked ? "Checked" : "Not Checked"; // Handling checkboxes - display_value = input.checked ? "Checked" : "Not Checked"; + display_content = input.checked ? "Checked" : "Not Checked"; } else { 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 { 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, // value: cell.innerText, input_value: content, - display_value: display_value, + display_content: display_content, rowspan: cell.rowSpan }); @@ -1873,7 +1916,7 @@ }); 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; console.log(selectedPolicies); @@ -1975,6 +2018,24 @@ 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() { @@ -2006,6 +2067,9 @@ let increaseBy = proposalCount * 150; console.log("trying to find checkbox data : : : ", increaseBy); + + suggestions = {}; + // Group tables by policy name const policyTables = {}; @@ -2062,7 +2126,7 @@ } // Handle regular cells 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")) { td.onclick = () => getAnswer(table.id, tr.id); if (cellData.subth != "Quote asked") { @@ -2148,7 +2212,7 @@ ${header.parentHeader} - `; + `; + } else { + th2.textContent = subHeader; + } + + th2.setAttribute('data-proposal', header.parentHeader.split(' ')[1]); + th2.setAttribute("data-quote", subHeader); th1.setAttribute('data-proposal', header.parentHeader.split(' ')[1]); - console.log("header insert position ",th1.getAttribute()) + // console.log("header insert position ",th1.getAttribute()) } else { th2.textContent = subHeader; @@ -2200,9 +2272,13 @@ } // 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 == "Checked") { + addSuggestion(cellData); + } // console.log("insude the function value ", value); return ` ${cellData.SNO} ${cellData.SNO == 'Fire' || cellData.SNO == 'Burglary' ? `