2615 lines
109 KiB
PHP
2615 lines
109 KiB
PHP
<style>
|
|
#allTableContainer {
|
|
max-width: 100%;
|
|
overflow-x: auto;
|
|
display: block;
|
|
}
|
|
|
|
.btn-custom {
|
|
background-color: #007bff;
|
|
color: #fff;
|
|
margin-right: 10px;
|
|
}
|
|
|
|
table {
|
|
/* border-collapse: collapse; */
|
|
margin-bottom: 20px;
|
|
/* max-width: 800px; */
|
|
/* table-layout: fixed; */
|
|
width: 1200px;
|
|
/* Set a fixed width */
|
|
table-layout: fixed;
|
|
/* Ensures equal column widths */
|
|
border-collapse: collapse;
|
|
/* Optional: Makes borders cleaner */
|
|
word-wrap: break-word;
|
|
|
|
}
|
|
|
|
|
|
|
|
th:nth-child(1),
|
|
td:nth-child(1) {
|
|
width: 110px;
|
|
/* Adjust first column width */
|
|
}
|
|
|
|
th:nth-child(2),
|
|
td:nth-child(2) {
|
|
width: 720px;
|
|
/* Adjust first column width */
|
|
}
|
|
|
|
th:nth-last-child(1),
|
|
td:nth-last-child(1) {
|
|
width: 230px;
|
|
/* Adjust last column width */
|
|
}
|
|
|
|
th,
|
|
td {
|
|
border: 1px solid #000;
|
|
padding: 8px;
|
|
}
|
|
|
|
th {
|
|
background-color: #f2f2f2 !important;
|
|
position: relative !important;
|
|
}
|
|
|
|
.three-dot-menu {
|
|
cursor: pointer;
|
|
}
|
|
|
|
.dropdown-content {
|
|
display: none;
|
|
position: absolute;
|
|
background-color: #f9f9f9;
|
|
box-shadow: 0px 8px 16px rgba(0, 0, 0, 0.2);
|
|
z-index: 1;
|
|
}
|
|
|
|
.dropdown-content button {
|
|
display: block;
|
|
width: 100%;
|
|
padding: 8px;
|
|
text-align: left;
|
|
border: none;
|
|
background: none;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.dropdown-content button:hover {
|
|
background-color: #ddd;
|
|
}
|
|
|
|
/* Dropdown container */
|
|
.simple-dropdown {
|
|
position: absolute;
|
|
background: white;
|
|
border: 1px solid #ccc;
|
|
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
|
z-index: 1000;
|
|
}
|
|
|
|
/* Individual dropdown options */
|
|
.dropdown-option {
|
|
padding: 8px 16px;
|
|
cursor: pointer;
|
|
min-width: 80px;
|
|
user-select: none;
|
|
}
|
|
|
|
/* Hover effect for options */
|
|
.dropdown-option:hover {
|
|
background-color: #f0f0f0;
|
|
}
|
|
|
|
/* Optional: Add transition for smoother hover effect */
|
|
.dropdown-option {
|
|
transition: background-color 0.2s ease;
|
|
}
|
|
|
|
/* Optional: Style the TD when it's clickable */
|
|
td[onclick] {
|
|
cursor: pointer;
|
|
}
|
|
|
|
[contenteditable="true"] {
|
|
pointer-events: auto;
|
|
/* Ensure clicking works */
|
|
}
|
|
|
|
/* Optional: Style for selected state */
|
|
.selected-option {
|
|
background-color: #f8f9fa;
|
|
}
|
|
|
|
.modal {
|
|
display: block !important;
|
|
/* Ensures visibility */
|
|
opacity: 0;
|
|
/* Initial state */
|
|
visibility: hidden;
|
|
/* Prevents flickering */
|
|
}
|
|
|
|
.modal.show {
|
|
opacity: 1;
|
|
visibility: visible;
|
|
z-index: 1050;
|
|
/* Correct z-index for Bootstrap 5 modals */
|
|
}
|
|
|
|
.modal-backdrop {
|
|
z-index: 1040 !important;
|
|
/* Ensures backdrop is below the modal */
|
|
}
|
|
|
|
.swal2-html-container {
|
|
overflow: hidden !important;
|
|
}
|
|
</style>
|
|
|
|
|
|
<div class="col-12">
|
|
<div class="card">
|
|
<div class="card-body">
|
|
|
|
<div class="row" style="margin-bottom:1rem;">
|
|
<div class="col-6" style="align-self: center;">
|
|
<h4 style="position: relative;" id="rfq_qcr_page_title"> <?= isset($page_name) ? $page_name : 'RFQ Non-EB' ?></h4>
|
|
</div>
|
|
</div>
|
|
<div class="row" style="margin-bottom:1rem;margin-left:1px">
|
|
<div class="col-md-2">
|
|
<button class="btn btn-custom" id="addProposal"> Add New Proposal</button>
|
|
</div>
|
|
<div class="col-md-2">
|
|
<button id="saveRFQ" onclick="saveRFQ()" class="btn btn-primary" id="saveRFQ">Save RFQ</button>
|
|
</div>
|
|
<div class="col-md-2">
|
|
<button onclick="openQCR()" class="btn btn-primary" id="openQCR">Proceed to QCR</button>
|
|
</div>
|
|
</div>
|
|
<input type="hidden" id="lead_id" value="<?= $lead_data['id'] ?? "" ?>" />
|
|
<div id="allTableContainer">
|
|
<div id="tablesContainer"></div>
|
|
<?php include('policyRegisterModel.php'); ?>
|
|
<!-- <div id="excessContainer"></div> -->
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
var rfq_data = <?= isset($rfq_data['json']) ? json_encode($rfq_data['json'], JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT) : '""' ?>;
|
|
rfq_data = rfq_data ? JSON.parse(rfq_data) : {}; // Convert to object if not already
|
|
|
|
var rfq_or_qcr = 1;
|
|
var policyConfig = {
|
|
1: ['Quote asked']
|
|
};
|
|
let myModal;
|
|
var over_all_column_data = {
|
|
"Proposal 1": {
|
|
"qcr": 0,
|
|
"stc": 0,
|
|
'insurers': []
|
|
}
|
|
};
|
|
const suggestions = {};
|
|
var storedData = JSON.parse(localStorage.getItem('policyData'));
|
|
var policySummary;
|
|
if (!$.isEmptyObject(storedData)) {
|
|
policySummary = addPolicySummaryTable(storedData);
|
|
}
|
|
console.log("policy summary is set :", !$.isEmptyObject(policySummary) ? "no" : "yes")
|
|
$(document).ready(function() {
|
|
myModal = new bootstrap.Modal(document.getElementById('policyRegisterModel'));
|
|
});
|
|
var tableCount = 0;
|
|
const policies = <?= json_encode($policies) ?>;
|
|
|
|
const child_table_data = <?= json_encode($child_table_data) ?>;
|
|
|
|
const policyOrder = [{
|
|
'fire': {
|
|
"priority": 1
|
|
}
|
|
},
|
|
{
|
|
'burglary': {
|
|
"priority": 2
|
|
}
|
|
},
|
|
{
|
|
'flop': {
|
|
"priority": 3
|
|
}
|
|
},
|
|
{
|
|
'all_risk': {
|
|
"priority": 4
|
|
}
|
|
},
|
|
{
|
|
'mbd': {
|
|
"priority": 5
|
|
}
|
|
},
|
|
{
|
|
'eei': {
|
|
"priority": 6
|
|
}
|
|
},
|
|
{
|
|
'fidelity': {
|
|
"priority": 7
|
|
}
|
|
},
|
|
{
|
|
'money': {
|
|
"priority": 8
|
|
}
|
|
},
|
|
{
|
|
'plate_glass': {
|
|
"priority": 9
|
|
},
|
|
},
|
|
{
|
|
'neon_sign': {
|
|
"priority": 10
|
|
}
|
|
},
|
|
{
|
|
'public_liability': {
|
|
"priority": 11
|
|
}
|
|
}
|
|
];
|
|
|
|
let selectedPolicies = new Set();
|
|
|
|
let proposalCount = 1;
|
|
console.log("Proposal count changed", proposalCount);
|
|
let quotesConfig = {
|
|
1: ['Quote asked']
|
|
}; // Stores quote columns for each proposal
|
|
|
|
// Generate a random quote code (e.g., abc123)
|
|
function generateRandomCode() {
|
|
const chars = 'abcdefghijklmnopqrstuvwxyz';
|
|
const nums = '0123456789';
|
|
return Array.from({
|
|
length: 3
|
|
}, () => chars[Math.floor(Math.random() * 26)]).join('') +
|
|
Array.from({
|
|
length: 3
|
|
}, () => nums[Math.floor(Math.random() * 10)]).join('');
|
|
}
|
|
|
|
// Add a new quote column to a specific proposal
|
|
// function addNewQuote(proposalNumber) {
|
|
// console.log("this doesnt work");
|
|
// let increaseBy = 25;
|
|
// increaseTableWidth(increaseBy)
|
|
// console.log('ADD NEW QUOTE proposalNumber' + proposalNumber);
|
|
// console.log('ADD NEW QUOTE overall quotesConfig');
|
|
// console.log(quotesConfig);
|
|
// if (!quotesConfig[proposalNumber]) {
|
|
// quotesConfig[proposalNumber] = ['Quote asked']; // Initialize with default quote
|
|
// }
|
|
// const newQuote = generateRandomCode();
|
|
// quotesConfig[proposalNumber].push(newQuote); // Add new quote to the proposal
|
|
|
|
// // Update all tables (parent and child) with the new quote column
|
|
// updateAllTables(proposalNumber, newQuote);
|
|
// // hideProposalOptionsForChild();
|
|
|
|
// }
|
|
|
|
// Update all tables with the new quote column
|
|
function updateAllTables_old(proposalNumber, newQuote) {
|
|
const tables = document.querySelectorAll('table');
|
|
tables.forEach(table => {
|
|
const headerRow1 = table.querySelector('thead tr:first-child');
|
|
const headerRow2 = table.querySelector('thead tr:last-child');
|
|
|
|
// Update proposal header colspan
|
|
const proposalHeader = headerRow1.querySelector(`th[data-proposal="${proposalNumber}"]`);
|
|
if (proposalHeader) {
|
|
proposalHeader.colSpan = quotesConfig[proposalNumber].length;
|
|
}
|
|
|
|
// Calculate the position to insert the new quote column
|
|
let insertPosition = 2; // Start after Particulars column
|
|
for (let i = 1; i < proposalNumber; i++) {
|
|
insertPosition += quotesConfig[i]?.length || 0;
|
|
}
|
|
insertPosition += quotesConfig[proposalNumber].length - 1;
|
|
let table_id = table.id ? table.id : 'parent';
|
|
console.log('insert position of ' + table.id + ' - ' + insertPosition);
|
|
// Add new quote sub-header
|
|
const newQuoteHeader = document.createElement('th');
|
|
newQuoteHeader.textContent = newQuote;
|
|
headerRow2.insertBefore(newQuoteHeader, headerRow2.children[insertPosition]);
|
|
|
|
// Add new editable cells to all rows
|
|
table.querySelectorAll('tbody tr').forEach(row => {
|
|
const newCell = document.createElement('td');
|
|
newCell.contentEditable = true; // Make cell editable
|
|
row.insertBefore(newCell, row.children[insertPosition]);
|
|
});
|
|
});
|
|
}
|
|
|
|
// Generate the table (parent or child)
|
|
|
|
// Show dropdown menu
|
|
function showDropdown(event) {
|
|
console.log("dropdown function triggered");
|
|
const dropdown = event.target.nextElementSibling;
|
|
console.log(dropdown);
|
|
dropdown.style.display = dropdown.style.display === 'block' ? 'none' : 'block';
|
|
event.stopPropagation();
|
|
}
|
|
|
|
// Remove a proposal column
|
|
function removeProposal(proposalNumber) {
|
|
|
|
console.log('removeProposal');
|
|
console.log(quotesConfig);
|
|
if (!quotesConfig[proposalNumber]) return; // If proposal doesn't exist, exit
|
|
|
|
// Remove all child columns for the proposal
|
|
const tables = document.querySelectorAll('table');
|
|
tables.forEach(table => {
|
|
const headerRow1 = table.querySelector('thead tr:first-child');
|
|
const headerRow2 = table.querySelector('thead tr:last-child');
|
|
|
|
// Find the proposal header and calculate its colspan
|
|
const proposalHeader = headerRow1.querySelector(`th[data-proposal="${proposalNumber}"]`);
|
|
if (proposalHeader) {
|
|
const colspan = parseInt(proposalHeader.getAttribute('colspan'), 10);
|
|
|
|
// Remove the proposal header
|
|
proposalHeader.remove();
|
|
|
|
// Remove corresponding sub-headers in the second header row
|
|
const subHeaders = headerRow2.querySelectorAll(`th`);
|
|
let startIndex = 2; // Start after the first two columns (checkbox and Particulars)
|
|
for (let i = 1; i < proposalNumber; i++) {
|
|
startIndex += quotesConfig[i]?.length || 1;
|
|
}
|
|
for (let i = 0; i < colspan; i++) {
|
|
headerRow2.removeChild(headerRow2.children[startIndex]);
|
|
}
|
|
|
|
// Remove corresponding cells in all rows
|
|
table.querySelectorAll('tbody tr').forEach(row => {
|
|
for (let i = 0; i < colspan; i++) {
|
|
row.removeChild(row.children[startIndex]);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
// Remove the proposal from quotesConfig
|
|
delete quotesConfig[proposalNumber];
|
|
}
|
|
|
|
// Add a new row
|
|
function addRow(event, element) {
|
|
|
|
console.log(' event ', element);
|
|
const button = event.target;
|
|
const row = button.closest('tr');
|
|
const table = row.closest('table');
|
|
const newRow = row.cloneNode(true);
|
|
console.log("old Row ", row);
|
|
// return false;
|
|
var tableID = table.id;
|
|
|
|
let nextSNO = getSNO(tableID);
|
|
// Clear input values and generate new IDs
|
|
newRow.querySelectorAll('td').forEach((td, index) => {
|
|
if (index === 0) {
|
|
console.log("Trying to set sno");
|
|
td.innerHTML = "";
|
|
td.innerHTML = `${nextSNO}`;
|
|
}
|
|
if (index !== 0 && index !== row.cells.length - 1) td.textContent = '-';
|
|
});
|
|
|
|
table.querySelector('tbody').appendChild(newRow);
|
|
updateSNO(table.id);
|
|
}
|
|
|
|
// Remove a row
|
|
function removeRow(event) {
|
|
const button = event.target;
|
|
const row = button.closest('tr');
|
|
const table = row.closest('table');
|
|
if (row && row.parentElement.children.length > 1) {
|
|
console.log("Row Removed");
|
|
row.remove();
|
|
updateSNO(table.id);
|
|
}
|
|
}
|
|
|
|
//function to hide all the 3 dot actions for the child table
|
|
function hideProposalOptionsForChild() {
|
|
// console.log('function called');
|
|
const parentTable = document.querySelector("table");
|
|
const tables = document.querySelectorAll('table');
|
|
|
|
// console.log('parentTable : ',parentTable);
|
|
tables.forEach(table => {
|
|
if (table !== parentTable) {
|
|
// Hide .three-dot-menu in all other tables
|
|
$(table).find(".three-dot-menu").hide();
|
|
// console.log("hided 3 dot menu in the table",table);
|
|
}
|
|
});
|
|
}
|
|
document.addEventListener("change", function(event) {
|
|
const checkbox = event.target;
|
|
if (checkbox.classList.contains("qcr-checkbox")) {
|
|
console.log("QCR checkbox change detected");
|
|
|
|
// Get the row containing the checkbox
|
|
const row = checkbox.closest('tr');
|
|
|
|
// Find the corresponding client-checkbox in the same row
|
|
const clientCheckbox = row.querySelector('.client-checkbox');
|
|
|
|
if (clientCheckbox) {
|
|
// Sync the client-checkbox state with the qcr-checkbox state
|
|
clientCheckbox.checked = checkbox.checked;
|
|
|
|
// Optionally, you can trigger any additional logic here
|
|
if (checkbox.checked) {
|
|
console.log("QCR checkbox is checked, client-checkbox is also checked");
|
|
} else {
|
|
console.log("QCR checkbox is unchecked, client-checkbox is also unchecked");
|
|
}
|
|
} else {
|
|
console.warn("No client-checkbox found in the same row");
|
|
}
|
|
} else if (checkbox.classList.contains("client-checkbox")) {
|
|
console.log("trying to change");
|
|
const row = checkbox.closest('tr');
|
|
const qcrCheckbox = row.querySelector('.qcr-checkbox');
|
|
|
|
if (!qcrCheckbox.checked) {
|
|
toastr.warning("QCR checkbox is not checked, preventing client-checkbox selection", "Warning");
|
|
checkbox.checked = false; // Prevent selection
|
|
}
|
|
}
|
|
})
|
|
|
|
// Add this once during initial page setup
|
|
document.getElementById('tablesContainer').addEventListener('change', function(event) {
|
|
const container = document.getElementById('tablesContainer');
|
|
const checkbox = event.target;
|
|
if (checkbox.classList.contains('sno-checkbox')) {
|
|
const rowId = checkbox.closest('tr').id;
|
|
const table = checkbox.closest('table');
|
|
if (checkbox.checked) {
|
|
const childContainer = document.createElement('div');
|
|
selectedPolicies.add(rowId);
|
|
child_table_data[rowId]?.forEach(childTable => {
|
|
if (childTable.table_type == "append") {
|
|
var tableName = childTable.table_id;
|
|
console.log("table name ", tableName);
|
|
// Handle excess table
|
|
const excessContainer = document.createElement('div');
|
|
excessContainer.setAttribute('data-parent-row', tableName);
|
|
excessContainer.setAttribute(`data-${tableName}-container`, 'true');
|
|
|
|
var result = generateExcessTable(childTable, rowId, tableName);
|
|
if (result) {
|
|
generateTable(excessContainer, true, rowId, childTable);
|
|
container.appendChild(excessContainer);
|
|
// console.log('Row id for excess table',rowId);
|
|
$("#excess .three-dot-menu").hide();
|
|
moveExcessTableLast();
|
|
}
|
|
} else {
|
|
// Handle regular table
|
|
childContainer.setAttribute('data-parent-row', rowId);
|
|
generateTable(childContainer, true, rowId, childTable);
|
|
// console.log('Row id for excess table', rowId);
|
|
$(childContainer).find(".three-dot-menu").hide();
|
|
moveExcessTableLast();
|
|
}
|
|
});
|
|
|
|
// Only append regular container if it has content
|
|
if (childContainer.hasChildNodes()) {
|
|
container.appendChild(childContainer);
|
|
}
|
|
|
|
arrangeTables();
|
|
} else {
|
|
console.log('UNCHECKED:', rowId);
|
|
selectedPolicies.delete(rowId);
|
|
// Remove regular child tables
|
|
const regularContainers = container.querySelectorAll(`div[data-parent-row="${rowId}"]:not([data-excess-container])`);
|
|
regularContainers.forEach(container => {
|
|
console.log(" contaitner ", container);
|
|
|
|
container.remove();
|
|
});
|
|
console.log("row id ", rowId);
|
|
// Handle excess table rows
|
|
const excessTable = document.getElementById('excess');
|
|
if (excessTable) {
|
|
// Remove rows associated with this checkbox
|
|
const excessRows = excessTable.querySelectorAll(`tbody tr[data-excess-row-parent="${rowId}"]`);
|
|
excessRows.forEach(row => row.remove());
|
|
|
|
// Check if excess table is empty
|
|
const remainingRows = excessTable.querySelector('tbody').children;
|
|
// console.log(remainingRows);
|
|
if (remainingRows.length === 0) {
|
|
// Remove the entire excess table container
|
|
// const excessContainer = excessTable.closest('div[data-excess-container]');
|
|
const excessContainer = $('#excess');
|
|
if (excessContainer) {
|
|
excessContainer.remove();
|
|
}
|
|
} else {
|
|
updateSNO('excess')
|
|
}
|
|
}
|
|
}
|
|
} else if (checkbox.classList.contains("qcr-checkbox")) {
|
|
console.log("QCR checkbox change detected");
|
|
|
|
// Get the row containing the checkbox
|
|
const row = checkbox.closest('tr');
|
|
|
|
// Find the corresponding client-checkbox in the same row
|
|
const clientCheckbox = row.querySelector('.client-checkbox');
|
|
|
|
if (clientCheckbox) {
|
|
// Sync the client-checkbox state with the qcr-checkbox state
|
|
clientCheckbox.checked = checkbox.checked;
|
|
|
|
// Optionally, you can trigger any additional logic here
|
|
if (checkbox.checked) {
|
|
console.log("QCR checkbox is checked, client-checkbox is also checked");
|
|
} else {
|
|
console.log("QCR checkbox is unchecked, client-checkbox is also unchecked");
|
|
}
|
|
} else {
|
|
console.warn("No client-checkbox found in the same row");
|
|
}
|
|
}
|
|
});
|
|
// Add a new proposal
|
|
document.getElementById('addProposal').addEventListener('click', () => {
|
|
console.log("proposal count before ", proposalCount);
|
|
proposalCount++;
|
|
console.log("proposal count after ", proposalCount);
|
|
|
|
quotesConfig[proposalCount] = ['Quote asked']; // Initialize with default quote
|
|
policyConfig[proposalCount] = ['Quote asked'];
|
|
const tables = document.querySelectorAll('table');
|
|
let increaseBy = 150;
|
|
increaseTableWidth(increaseBy);
|
|
|
|
// console.log('parentTable : ',parentTable);
|
|
tables.forEach(table => {
|
|
const headerRow1 = table.querySelector('thead tr:first-child');
|
|
const headerRow2 = table.querySelector('thead tr:last-child');
|
|
|
|
// Add new proposal header
|
|
const newProposalHeader = document.createElement('th');
|
|
newProposalHeader.setAttribute('data-proposal', proposalCount);
|
|
newProposalHeader.colSpan = 1;
|
|
newProposalHeader.innerHTML = `
|
|
Proposal ${proposalCount}
|
|
<span class="three-dot-menu" onclick="showDropdown(event)">⋮</span>
|
|
<div class="dropdown-content">
|
|
<button id = "isQCR" onclick = "addOrRemoveIcon(this,event)"class="qcrProposal" style="background-color: rgb(221, 221, 221);">QCR <i
|
|
class="fa fa-check-square"
|
|
style="color: green; margin-left: 8px;"></i></button>
|
|
<button id = "isSTC" class="sendClientProposal" onclick = "addOrRemoveIcon(this,event)"
|
|
style="background-color: rgb(221, 221, 221);">Send to Client <i
|
|
class="fa fa-check-square"
|
|
style="color: green; margin-left: 8px;"></i></button>
|
|
<button onclick="removeProposal(${proposalCount})">Remove Proposal</button>
|
|
<button class = "newInsurer" onclick="addNewQuote(${proposalCount})">Add New Insurer</button>
|
|
</div>
|
|
`;
|
|
headerRow1.insertBefore(newProposalHeader, headerRow1.lastElementChild);
|
|
|
|
// Add new quote sub-header
|
|
const newQuoteHeader = document.createElement('th');
|
|
newQuoteHeader.textContent = 'Quote asked';
|
|
headerRow2.insertBefore(newQuoteHeader, headerRow2.querySelector('th:last-child'));
|
|
|
|
// Add new cells to all rows
|
|
table.querySelectorAll('tbody tr').forEach(row => {
|
|
// console.log(row);
|
|
|
|
// const newCell = document.createElement('td');
|
|
const lastCell = row.querySelector('td:nth-child(3)');
|
|
const newCell = lastCell.cloneNode(true);
|
|
newCell.contentEditable = true;
|
|
newCell.onclick = () => getAnswer(table.id, row.id);
|
|
row.insertBefore(newCell, row.querySelector('td:last-child'));
|
|
});
|
|
// console.log('table ',table);
|
|
|
|
});
|
|
hideProposalOptionsForChild();
|
|
showOrHideFieldsBasedOnRFQorQCR();
|
|
});
|
|
|
|
// #################################################################################
|
|
|
|
function addNewQuote(proposalNumber) {
|
|
console.log("add new Quote start : ", quotesConfig);
|
|
const insurers = <?= json_encode($insurer); ?>;
|
|
selectInsurer(insurers).then(result => {
|
|
insurer = result.selectedInsurer;
|
|
version = result.insurerDetails;
|
|
dataId = result.dataId;
|
|
|
|
insurerName = `${insurer}${version != "" ? " v"+ version : ""}`;
|
|
|
|
let increaseBy = 100;
|
|
increaseTableWidth(increaseBy);
|
|
// console.log("Selected Insurer:", insurerName);
|
|
// console.log("Entered Version:", version);
|
|
// console.log("Entered data id:", dataId);
|
|
console.log("add new Quote : ", proposalNumber);
|
|
console.log("add new Quote : ", quotesConfig);
|
|
console.log("Add new quote insurer name : ", insurerName);
|
|
if (!quotesConfig[proposalNumber]) return;
|
|
console.log("add new quote ", quotesConfig[proposalNumber]);
|
|
if (quotesConfig[proposalNumber].includes(insurerName)) {
|
|
console.log("add new quote is duplicate");
|
|
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) {
|
|
// Handle versioning logic here for duplicate insurer
|
|
let baseInsurerName = insurer;
|
|
let count = 0;
|
|
|
|
// Count how many times this insurer appears in the current proposal
|
|
for (let i = 0; i < quotesConfig[proposalNumber].length; i++) {
|
|
if (quotesConfig[proposalNumber][i].startsWith(baseInsurerName)) {
|
|
count++;
|
|
console.log("add count ", count);
|
|
}
|
|
}
|
|
|
|
// Auto-increment version
|
|
if (version === "") {
|
|
insurerName = `${baseInsurerName} v${count + 1}`;
|
|
version = count + 1;
|
|
console.log("add inurer name ", insurerName);
|
|
} else {
|
|
// If user already specified version, append count to make it unique
|
|
insurerName = `${baseInsurerName} v${version}_${count + 1}`;
|
|
version = `${version}_${count + 1}`;
|
|
console.log("add inurer name else", insurerName);
|
|
|
|
}
|
|
var insurerDetails = {
|
|
id: dataId,
|
|
version: version,
|
|
insurerName: insurerName
|
|
}
|
|
policyConfig[proposalNumber].push(insurerDetails);
|
|
const newQuote = insurerName;
|
|
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) {
|
|
proposalHeader.colSpan = quotesConfig[proposalNumber].length;
|
|
}
|
|
|
|
}
|
|
});
|
|
} else {
|
|
var insurerDetails = {
|
|
id: dataId,
|
|
version: version,
|
|
insurerName: insurerName
|
|
}
|
|
policyConfig[proposalNumber].push(insurerDetails);
|
|
const newQuote = insurerName;
|
|
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)
|
|
proposalHeader.colSpan = quotesConfig[proposalNumber].length;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
showOrHideFieldsBasedOnRFQorQCR();
|
|
hideProposalOptionsForChild();
|
|
});
|
|
|
|
}
|
|
|
|
function changeInsurer(event, proposalNumber, currentInsurer) {
|
|
// Stop event propagation
|
|
event.stopPropagation();
|
|
console.log("insurer change function called ", quotesConfig[proposalNumber]);
|
|
if (!quotesConfig[proposalNumber]) return;
|
|
const insurers = <?= json_encode($insurer); ?>;
|
|
|
|
selectInsurer(insurers).then(result => {
|
|
let newInsurerName = result.selectedInsurer;
|
|
let newversion = result.insurerDetails;
|
|
let newdataId = result.dataId;
|
|
var insurerDetailsChange = {
|
|
id: newdataId,
|
|
version: newversion,
|
|
insurerName: newInsurerName
|
|
}
|
|
if (newversion.trim() !== '') {
|
|
newInsurerName = `${newInsurerName}-${newversion.trim()}`.replace(/\s+/g, '');
|
|
}
|
|
|
|
console.log('insurer newInsurerName', newInsurerName);
|
|
console.log('insurer newversion', newversion);
|
|
|
|
if (newInsurerName) {
|
|
// console.log("insurer inside new insurer name : ",headerRow2);
|
|
// Update all tables with the new insurer
|
|
document.querySelectorAll('table').forEach(table => {
|
|
const headerRow2 = table.querySelector('thead tr:last-child');
|
|
console.log("insurer inside ", headerRow2);
|
|
// Find the header cells that match our criteria
|
|
Array.from(headerRow2.children).forEach(th => {
|
|
// Check if this cell contains our insurer and proposal
|
|
console.log("insurer proposal number : ", proposalNumber);
|
|
console.log("insurer header proposal number : ", th);
|
|
if (th.getAttribute('data-proposal') === proposalNumber.toString()) {
|
|
// Get the first text node (the insurer name part)
|
|
let content = th.innerHTML;
|
|
console.log("insurer inside ", content);
|
|
// Only replace the exact insurer name, not any menu text
|
|
if (content.includes(currentInsurer)) {
|
|
// Create a regex to match just the insurer name
|
|
const regex = new RegExp(currentInsurer, 'g');
|
|
th.innerHTML = content.replace(regex, newInsurerName);
|
|
|
|
// Update attributes
|
|
if (th.hasAttribute('data-insurer')) {
|
|
th.setAttribute('data-insurer', newInsurerName);
|
|
}
|
|
|
|
if (newdataId && th.hasAttribute('data-id')) {
|
|
th.setAttribute('data-id', dataId);
|
|
}
|
|
|
|
// Update quote code in quotesConfig
|
|
const oldQuoteCode = th.getAttribute('data-quote');
|
|
if (oldQuoteCode) {
|
|
const quoteIndex = quotesConfig[proposalNumber].indexOf(oldQuoteCode);
|
|
if (quoteIndex !== -1) {
|
|
// Generate new quote code based on new insurer
|
|
const newQuoteCode = oldQuoteCode.replace(currentInsurer, newInsurerName);
|
|
quotesConfig[proposalNumber][quoteIndex] = newQuoteCode;
|
|
console.log("Existing policy data ", policyConfig[proposalNumber][quoteIndex]);
|
|
policyConfig[proposalNumber][quoteIndex] = insurerDetailsChange;
|
|
console.log("quote index ", quoteIndex);
|
|
console.log("changed like this ", insurerDetailsChange);
|
|
// Update data-quote attribute
|
|
th.setAttribute('data-quote', newQuoteCode);
|
|
}
|
|
}
|
|
|
|
// Find and update corresponding data cells
|
|
const colIndex = Array.from(th.parentNode.children).indexOf(th);
|
|
table.querySelectorAll(`tbody tr`).forEach(row => {
|
|
const cell = row.children[colIndex];
|
|
if (cell) {
|
|
if (cell.hasAttribute('data-insurer')) {
|
|
cell.setAttribute('data-insurer', newInsurerName);
|
|
}
|
|
if (cell.hasAttribute('data-quote')) {
|
|
const oldQuote = cell.getAttribute('data-quote');
|
|
const newQuote = oldQuote.replace(currentInsurer, newInsurerName);
|
|
cell.setAttribute('data-quote', newQuote);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
// Show success message
|
|
toastr.success("Insurer Changed", "Success");
|
|
}
|
|
});
|
|
}
|
|
|
|
function removeQuote(event, proposalNumber, quoteCode) {
|
|
event.stopPropagation();
|
|
if (!quotesConfig[proposalNumber]) return;
|
|
|
|
// Remove quote from config
|
|
const quoteIndex = quotesConfig[proposalNumber].indexOf(quoteCode);
|
|
console.log("quote index ", quoteIndex);
|
|
if (quoteIndex !== -1) {
|
|
quotesConfig[proposalNumber].splice(quoteIndex, 1);
|
|
if (quotesConfig[proposalNumber].length === 0) {
|
|
delete quotesConfig[proposalNumber];
|
|
}
|
|
}
|
|
|
|
// Remove from all tables
|
|
document.querySelectorAll('table').forEach(table => {
|
|
const headerRow1 = table.querySelector('thead tr:first-child');
|
|
const headerRow2 = table.querySelector('thead tr:last-child');
|
|
|
|
// Find and remove quote header
|
|
const targetIndex = Array.from(headerRow2.children).findIndex(th =>
|
|
th.textContent.includes(quoteCode) &&
|
|
th.getAttribute('data-proposal') === proposalNumber.toString()
|
|
);
|
|
console.log("quote target index ", targetIndex);
|
|
if (targetIndex !== -1) {
|
|
console.log("quote target index inside if", targetIndex);
|
|
// Remove from header row 2
|
|
headerRow2.removeChild(headerRow2.children[targetIndex]);
|
|
|
|
// Update proposal header colspan
|
|
const proposalHeader = headerRow1.querySelector(`th[data-proposal="${proposalNumber}"]`);
|
|
console.log("quote target index inside if proposal header", proposalHeader);
|
|
|
|
if (proposalHeader) {
|
|
const newColspan = parseInt(proposalHeader.colSpan) - 1;
|
|
console.log("Quote new colspan : ", newColspan);
|
|
if (newColspan > 0) {
|
|
proposalHeader.colSpan = newColspan;
|
|
} else {
|
|
proposalHeader.remove();
|
|
}
|
|
}
|
|
|
|
// Remove from data rows
|
|
table.querySelectorAll('tbody tr').forEach(row => {
|
|
const cellIndex = targetIndex; // No need to add 2 since we're using children array
|
|
console.log("quote target index inside if proposal header", cellIndex);
|
|
if (row.children[cellIndex]) {
|
|
row.removeChild(row.children[cellIndex]);
|
|
console.log("quote target index inside if proposal header", row);
|
|
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
function updateAllTables(proposalNumber, newQuote) {
|
|
document.querySelectorAll('table').forEach(table => {
|
|
const headerRow1 = table.querySelector('thead tr:first-child');
|
|
const headerRow2 = table.querySelector('thead tr:last-child');
|
|
const proposalHeader = headerRow1.querySelector(`th[data-proposal="${proposalNumber}"]`);
|
|
// console.log("Header Row 1 : ", headerRow1);
|
|
// console.log("Header Row 2 : ", headerRow2);
|
|
console.log("Proposal Header : ", proposalNumber);
|
|
// Create new quote header
|
|
const newQuoteHeader = document.createElement('th');
|
|
newQuoteHeader.textContent = newQuote;
|
|
newQuoteHeader.innerHTML = `
|
|
${newQuote}
|
|
<span class="three-dot-menu" onclick="showDropdown(event)">⋮</span>
|
|
<div class="dropdown-content">
|
|
<button onclick="changeInsurer(event, ${proposalNumber}, '${newQuote}')">Change Insurer</button>
|
|
<button onclick="removeQuote(event, ${proposalNumber}, '${newQuote}')">Remove Quote</button>
|
|
</div>
|
|
`;
|
|
newQuoteHeader.dataset.proposal = proposalNumber;
|
|
newQuoteHeader.dataset.quote = newQuote;
|
|
|
|
// Find insert position
|
|
let insertPosition = 2;
|
|
for (let i = 1; i < proposalNumber; i++) {
|
|
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);
|
|
// Update headers
|
|
headerRow2.insertBefore(newQuoteHeader, headerRow2.children[insertPosition]);
|
|
if (proposalHeader) proposalHeader.colSpan = quotesConfig[proposalNumber].length;
|
|
console.log("insert position insertPosition", insertPosition);
|
|
// Add new cells
|
|
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)
|
|
newCell.contentEditable = true;
|
|
newCell.onclick = () => getAnswer(table.id, row.id);
|
|
row.insertBefore(newCell, row.children[insertPosition]);
|
|
});
|
|
});
|
|
}
|
|
|
|
function generateTable(container, isChildTable = false, parentRowId = null, tableData = null) {
|
|
const table = document.createElement('table');
|
|
if (tableData) {
|
|
table.id = tableData.table_id;
|
|
};
|
|
// table_name = tableData.table_name
|
|
|
|
tableName = tableData ? tableData.table_name : "Particulars";
|
|
// console.log("table Name ",tableName);
|
|
// Header setup
|
|
const thead = document.createElement('thead');
|
|
const headerRow1 = document.createElement('tr');
|
|
headerRow1.innerHTML =
|
|
`
|
|
${isChildTable ? '<th>S.NO</th>' : '<th><input type="checkbox"></th>'}
|
|
<th>${tableName}</th>
|
|
${Object.keys(quotesConfig).map(proposal => `
|
|
<th data-proposal="${proposal}" colspan="${quotesConfig[proposal].length}">
|
|
Proposal ${proposal}
|
|
<span class="three-dot-menu" onclick="showDropdown(event)">⋮</span>
|
|
<div class="dropdown-content">
|
|
<button id = "isQCR" onclick = "addOrRemoveIcon(this,event)"class="qcrProposal" style="background-color: rgb(221, 221, 221);">QCR <i
|
|
class="fa fa-check-square"
|
|
style="color: green; margin-left: 8px;"></i></button>
|
|
<button id = "isSTC" class="sendClientProposal" onclick = "addOrRemoveIcon(this,event)"
|
|
style="background-color: rgb(221, 221, 221);">Send to Client <i
|
|
class="fa fa-check-square"
|
|
style="color: green; margin-left: 8px;"></i></button>
|
|
<button onclick="removeProposal(${proposal})">Remove Proposal</button>
|
|
<button class = "newInsurer" onclick="addNewQuote(${proposal})">Add New Insurer</button>
|
|
</div>
|
|
</th>
|
|
`).join('')}
|
|
<th>Action</th>`;
|
|
|
|
const headerRow2 = document.createElement('tr');
|
|
headerRow2.innerHTML = `
|
|
<th>-</th>
|
|
<th>-</th>
|
|
${Object.entries(quotesConfig).flatMap(([proposal, codes]) =>
|
|
codes.map(code => `
|
|
<th data-proposal="${proposal}" data-quote="${code}">
|
|
${code}
|
|
<span class="three-dot-menu" onclick="showDropdown(event)">⋮</span>
|
|
<div class="dropdown-content">
|
|
<button onclick="removeQuote(event, ${proposal}, '${code}')">Remove Quote</button>
|
|
</div>
|
|
</th>
|
|
`)
|
|
).join('')}
|
|
<th>-</th>`;
|
|
|
|
thead.append(headerRow1, headerRow2);
|
|
table.appendChild(thead);
|
|
let latestWidth = $("table").last().width();
|
|
// console.log('Latest width', latestWidth);
|
|
if (tableData) {
|
|
// console.log("table ",$(table));
|
|
$(table).width(latestWidth); // Convert to jQuery object using $(table)
|
|
// console.log('table data',tableData);
|
|
|
|
}
|
|
|
|
// Body setup
|
|
// Inside generateTable function, when creating tbody for parent table
|
|
const tbody = document.createElement('tbody');
|
|
if (!isChildTable) {
|
|
policies.forEach((policy) => {
|
|
const descriptions = policy.description;
|
|
const quoteAsked = policy.quote_asked;
|
|
const allQuotes = Object.values(quotesConfig).flat(); // Flatten all quotes
|
|
|
|
descriptions.forEach((desc, descIndex) => {
|
|
const row = document.createElement('tr');
|
|
row.id = policy.name.replace(/\s+/g, '_').toLowerCase();
|
|
|
|
// Generate cells for each quote
|
|
const quoteCells = allQuotes.map((_, index) => {
|
|
const value = quoteAsked[index] || '-'; // Use corresponding quote_asked or '-'
|
|
return `<td contenteditable="true">${value}</td>`;
|
|
}).join('');
|
|
|
|
if (descIndex === 0) {
|
|
// First row with rowspan and checkbox
|
|
row.innerHTML = `
|
|
<td rowspan="${descriptions.length}">
|
|
<input type="checkbox" class="sno-checkbox">
|
|
${policy.name}
|
|
${policy.name === 'Fire' || policy.name === 'Burglary' ?
|
|
`<br><button class = "btn btn-primary btn-sm" onclick = "getPolicyInfo()" class="policy-link" data-policy-name="${policy.name}">Register</button>` :
|
|
''}
|
|
</td>
|
|
<td contenteditable="true">${desc}</td>
|
|
${quoteCells}
|
|
<td></td>`;
|
|
} else {
|
|
// Subsequent rows without checkbox
|
|
row.innerHTML = `
|
|
<td contenteditable="true">${desc}</td>
|
|
${quoteCells}
|
|
<td></td>`;
|
|
}
|
|
|
|
tbody.appendChild(row);
|
|
});
|
|
});
|
|
} else {
|
|
const rowsData = tableData ? tableData.table_row_contents : policies;
|
|
rowsData.forEach((policy, index) => {
|
|
var row_fields = rowsData[index];
|
|
let rowID = Object.keys(row_fields)[0];
|
|
// console.log('row id ? ', rowID);
|
|
const row = document.createElement('tr');
|
|
row.id = isChildTable ? `${parentRowId}_child_${index}` : policy.name.replace(/\s+/g, '_').toLowerCase();
|
|
row.id = isChildTable ? `${rowID}` : policy.name.replace(/\s+/g, '_').toLowerCase();
|
|
|
|
// Set data attribute for excess table rows
|
|
if (tableData && tableData.table_id === 'excess') {
|
|
row.setAttribute('data-excess-row-parent', parentRowId);
|
|
// $('.three-dot-menu').hide();
|
|
}
|
|
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);
|
|
var SNO = getSNO(tableID);
|
|
if (tableData) {
|
|
suggestions[rowID] = row_fields[rowID].answer_type;
|
|
if (answer_type == 'dropdown') {
|
|
default_answers_array = row_fields[rowID].default_answer;
|
|
|
|
// createDropdown(default_answers_array);
|
|
default_value = default_answers_array[0].key;
|
|
default_answer = default_answers_array[0].display_value;
|
|
|
|
} else {
|
|
default_answers_array = row_fields[rowID].default_answer ? row_fields[rowID].default_answer : "-";
|
|
// console.log("defaultansetgoa : ",default_answers_array);
|
|
default_value = default_answers_array;
|
|
default_answer = default_answers_array;
|
|
|
|
// default_value = "-"
|
|
// console.log("debug: ",row_fields[rowID].default_answer);
|
|
}
|
|
|
|
}
|
|
|
|
row.innerHTML = `
|
|
|
|
${isChildTable
|
|
? `<td>${SNO}</td>`
|
|
: `<td rowspan = "${policy.description.length}"><input type="checkbox" class="sno-checkbox">${policy.name}${policy.name == 'Fire' || policy.name == 'Burglary'
|
|
? `<br><button class = "btn btn-primary btn-sm" onclick = "getPolicyInfo()" class="policy-link" data-policy-name="${policy.name}">Register</a>`
|
|
: ""}</td>`
|
|
}
|
|
|
|
<td contenteditable="true">${tableData ? policy_question : policy.description}</td>
|
|
${Object.values(quotesConfig).flatMap(codes =>
|
|
codes.map(() => `<td onblur="setValueForHiddenField(this,'${answer_type}')" onclick = "getAnswer('${tableID}','${rowID}')" contenteditable="true">${tableData ? (default_value === '-' ? `${default_value} <input type="hidden" value='${default_value}' />` : `${default_answer} <input type="hidden" value='${JSON.stringify(default_answers_array[0])}' />`)
|
|
: policy.quote_asked}</td>`)
|
|
).join('')}
|
|
<td>
|
|
${isChildTable ? `
|
|
<input id = "qcrCheckbox" name = "qcr" checked type="checkbox" class="qcr-checkbox"> <label for = "qcrCheckbox">QCR</label>
|
|
<input id = "stcCheckbox" name = "stc" checked type="checkbox" class="client-checkbox">Client
|
|
<button class="btn btn-primary btn-sm" onclick="addRow(event,this)">+</button>
|
|
<button class="btn btn-danger btn-sm" onclick="removeRow(event)">-</button>
|
|
` : ''}
|
|
</td>`;
|
|
tbody.appendChild(row);
|
|
});
|
|
table.appendChild(tbody);
|
|
|
|
}
|
|
table.appendChild(tbody);
|
|
container.appendChild(table);
|
|
// Checkbox functionality
|
|
if (!isChildTable) {
|
|
table.querySelectorAll('.sno-checkbox').forEach(checkbox => {
|
|
checkbox.addEventListener('change', function() {
|
|
const rowId = this.closest('tr').id;
|
|
// if (this.checked) {
|
|
// const childContainer = document.createElement('div');
|
|
// selectedPolicies.add(rowId);
|
|
// child_table_data[rowId]?.forEach(childTable => {
|
|
// if (childTable.table_type == "append") {
|
|
// var tableName = childTable.table_id;
|
|
// // Handle excess table
|
|
// const excessContainer = document.createElement('div');
|
|
// excessContainer.setAttribute('data-parent-row', tableName);
|
|
// excessContainer.setAttribute(`data-${tableName}-container`, 'true');
|
|
|
|
// var result = generateExcessTable(childTable, rowId, tableName);
|
|
// if (result) {
|
|
// generateTable(excessContainer, true, rowId, childTable);
|
|
// container.appendChild(excessContainer);
|
|
// // console.log('Row id for excess table',rowId);
|
|
// $("#excess .three-dot-menu").hide();
|
|
// moveExcessTableLast();
|
|
// }
|
|
// } else {
|
|
// // Handle regular table
|
|
// childContainer.setAttribute('data-parent-row', rowId);
|
|
// generateTable(childContainer, true, rowId, childTable);
|
|
// // console.log('Row id for excess table', rowId);
|
|
// $(childContainer).find(".three-dot-menu").hide();
|
|
// moveExcessTableLast();
|
|
// }
|
|
// });
|
|
|
|
// // Only append regular container if it has content
|
|
// if (childContainer.hasChildNodes()) {
|
|
// container.appendChild(childContainer);
|
|
// }
|
|
|
|
// arrangeTables();
|
|
// } else {
|
|
// console.log('UNCHECKED:', rowId);
|
|
// selectedPolicies.delete(rowId);
|
|
// // Remove regular child tables
|
|
// const regularContainers = container.querySelectorAll(`div[data-parent-row="${rowId}"]:not([data-excess-container])`);
|
|
// regularContainers.forEach(container => {
|
|
// console.log(" contaitner ", container);
|
|
|
|
// container.remove();
|
|
// });
|
|
// console.log("row id ", rowId);
|
|
// // Handle excess table rows
|
|
// const excessTable = document.getElementById('excess');
|
|
// if (excessTable) {
|
|
// // Remove rows associated with this checkbox
|
|
// const excessRows = excessTable.querySelectorAll(`tbody tr[data-excess-row-parent="${rowId}"]`);
|
|
// excessRows.forEach(row => row.remove());
|
|
|
|
// // Check if excess table is empty
|
|
// const remainingRows = excessTable.querySelector('tbody').children;
|
|
// // console.log(remainingRows);
|
|
// if (remainingRows.length === 0) {
|
|
// // Remove the entire excess table container
|
|
// // const excessContainer = excessTable.closest('div[data-excess-container]');
|
|
// const excessContainer = $('#excess');
|
|
// if (excessContainer) {
|
|
// excessContainer.remove();
|
|
// }
|
|
// } else {
|
|
// updateSNO('excess')
|
|
// }
|
|
// }
|
|
// }
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function generateExcessTable(tableData, parentRowId, tableName) {
|
|
var excessTable = document.getElementById(tableName);
|
|
|
|
if (excessTable) {
|
|
// If table exists, append new rows to it
|
|
const tbody = excessTable.querySelector('tbody');
|
|
// console.log("table data ",tableData);
|
|
// Add new rows from tableData
|
|
tableData.table_row_contents.forEach((rowData, index) => {
|
|
let rowID = Object.keys(rowData)[0];
|
|
var question = rowData[rowID].display_value;
|
|
|
|
const row = document.createElement('tr');
|
|
// Add data attribute to track which parent checkbox created this row
|
|
row.setAttribute('data-excess-row-parent', parentRowId);
|
|
let SNO = getSNO(tableName);
|
|
row.innerHTML = `
|
|
<td>${SNO}</td>
|
|
<td contenteditable="true">${question}</td>
|
|
${Object.values(quotesConfig).flatMap(codes =>
|
|
codes.map(() => `<td contenteditable="true">-</td>`)
|
|
).join('')}
|
|
<td>
|
|
<input id = "qcrCheckbox" name = "qcr" checked value = "1" type="checkbox" class="qcr-checkbox"> <label for = "qcrCheckbox">QCR</label>
|
|
<input name = "stc" checked value = "1" type="checkbox" class="client-checkbox">Client
|
|
<button class="btn btn-primary btn-sm" onclick="addRow(event,this)">+</button>
|
|
<button class="btn btn-danger btn-sm" onclick="removeRow(event)">-</button>
|
|
</td>`;
|
|
tbody.appendChild(row);
|
|
});
|
|
moveExcessTableLast();
|
|
return false;
|
|
} else {
|
|
return true;
|
|
}
|
|
}
|
|
// Initialize the parent table
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
// console.log("bjnglfkrg ", rfq_data.length);
|
|
const url = window.location.pathname; // Get the path (e.g., "/nhance/rfq/list/75/1")
|
|
const segments = url.split("/"); // Split by "/"
|
|
segments[segments.length - 1] = "1"; // Change the last segment
|
|
const newUrl = segments.join("/"); // Rebuild the URL
|
|
rfq_or_qcr = 1;
|
|
history.pushState(null, "", newUrl); // Change the URL without reloading
|
|
if (rfq_data.length) {
|
|
console.log("inside if conditoon");
|
|
localStorage.setItem('allTablesJsonData', JSON.stringify(rfq_data));
|
|
jsonToTables();
|
|
// generateTable(document.getElementById('tablesContainer'));
|
|
console.log("polices Length ", policies.length);
|
|
|
|
} else {
|
|
generateTable(document.getElementById('tablesContainer'));
|
|
console.log("polices Length ", policies.length);
|
|
if (policies.length == 1) {
|
|
setTimeout(() => {
|
|
$(".sno-checkbox").each(function() {
|
|
console.log("time completed function called");
|
|
$(".sno-checkbox").prop("checked", true);
|
|
this.dispatchEvent(new Event("change", {
|
|
bubbles: true
|
|
}));
|
|
});
|
|
}, 100);
|
|
}
|
|
}
|
|
|
|
showOrHideFieldsBasedOnRFQorQCR();
|
|
});
|
|
|
|
// Close dropdown when clicking outside
|
|
window.addEventListener('click', () => {
|
|
document.querySelectorAll('.dropdown-content').forEach(dropdown => {
|
|
dropdown.style.display = 'none';
|
|
});
|
|
});
|
|
|
|
function getAnswer(table_id, rowID) {
|
|
event.stopPropagation();
|
|
console.log("Function called", table_id);
|
|
var policy = table_id.split('_').slice(0, -1).join('_');
|
|
// var policy = 'policy_' + table;
|
|
console.log('policy ', rowID);
|
|
|
|
Object.entries(child_table_data).forEach(([key, value]) => {
|
|
if (key == policy) {
|
|
var table_data = value;
|
|
// console.log("table data ",table_data);
|
|
// Loop through all available table data (removing hardcoded [0])
|
|
table_data.forEach(table => {
|
|
var table_row = table['table_row_contents'];
|
|
// console.log("table Row ",table_row);
|
|
Object.entries(table_row).forEach(([key, value]) => {
|
|
var question_id = Object.keys(value)[0];
|
|
// console.log("Question ID : ",question_id," row ID : ",rowID);
|
|
if (question_id == rowID) {
|
|
let questionData = value[question_id];
|
|
console.log("question data", questionData);
|
|
if (questionData.answer_type == 'dropdown') {
|
|
|
|
var answerAndValues = questionData.answers;
|
|
createDropdown(answerAndValues);
|
|
} else {
|
|
return true;
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
function createDropdown(answerAndValues) {
|
|
// console.log(answerAndValues);
|
|
const originalTd = event.target;
|
|
const dropdown = document.createElement("div");
|
|
dropdown.classList.add("simple-dropdown");
|
|
|
|
answerAndValues.forEach(answer => {
|
|
const option = document.createElement("div");
|
|
option.classList.add("dropdown-option");
|
|
option.textContent = answer.display_value;
|
|
option.dataset.key = answer.key;
|
|
|
|
option.addEventListener("click", function(e) {
|
|
e.stopPropagation();
|
|
originalTd.innerHTML = `${this.textContent}
|
|
<input type="hidden" value='${JSON.stringify({ key: answer.key, display_value: answer.display_value })}' />`;
|
|
|
|
// originalTd.dataset.selectedKey = this.dataset.key;
|
|
dropdown.remove();
|
|
});
|
|
|
|
dropdown.appendChild(option);
|
|
});
|
|
|
|
const rect = originalTd.getBoundingClientRect();
|
|
dropdown.style.top = rect.bottom + window.scrollY + 'px';
|
|
dropdown.style.left = rect.left + window.scrollX + 'px';
|
|
|
|
const existingDropdown = document.querySelector('.simple-dropdown');
|
|
if (existingDropdown) {
|
|
existingDropdown.remove();
|
|
}
|
|
|
|
document.body.appendChild(dropdown);
|
|
|
|
document.addEventListener("click", function(e) {
|
|
if (!dropdown.contains(e.target) && e.target !== originalTd) {
|
|
dropdown.remove();
|
|
}
|
|
});
|
|
|
|
originalTd.addEventListener('click', function(e) {
|
|
e.preventDefault();
|
|
if (this.getAttribute('contenteditable') === 'true') {
|
|
// this.setAttribute('contenteditable', 'false');
|
|
}
|
|
});
|
|
}
|
|
|
|
function moveExcessTableLast() {
|
|
const excessTable = document.getElementById("excess");
|
|
const tableContentDiv = document.createElement("div");
|
|
tableContentDiv.className = 'table-content';
|
|
// const excessCollapseBar = document.querySelector('.table-collapsible-bar.Excess');
|
|
const overallContainer = document.getElementById('allTableContainer');
|
|
if (excessTable) {
|
|
// overallContainer.appendChild(excessCollapseBar); // Move it to the end of the <body>
|
|
overallContainer.appendChild(tableContentDiv);
|
|
tableContentDiv.appendChild(excessTable);
|
|
|
|
// excessCollapseBar.addEventListener('click', function() {
|
|
// this.classList.toggle('collapsed');
|
|
// tableContentDiv.classList.toggle('collapsed');
|
|
// });
|
|
// console.log("Table moved:", document.body.lastElementChild === excessTable);
|
|
} else {
|
|
// console.log("Excess table not found.");
|
|
}
|
|
}
|
|
// Global object to track SNO for each table
|
|
let tableSNOTracker = {};
|
|
|
|
function getSNO(tableID) {
|
|
if (!tableID) {
|
|
return 1;
|
|
}
|
|
|
|
// Initialize counter if not present
|
|
if (!tableSNOTracker[tableID]) {
|
|
tableSNOTracker[tableID] = 1;
|
|
} else {
|
|
tableSNOTracker[tableID]++;
|
|
}
|
|
|
|
return tableSNOTracker[tableID];
|
|
}
|
|
|
|
function updateSNO(tableID) {
|
|
console.log("Function Called Update Sno");
|
|
const table = document.getElementById(tableID);
|
|
console.log("table : ", table);
|
|
if (!table) return;
|
|
|
|
const rows = table.querySelectorAll("tbody tr");
|
|
let sno = 1; // Start numbering from 1
|
|
|
|
rows.forEach(row => {
|
|
const firstCell = row.querySelector("td:first-child"); // Get SNO cell
|
|
if (firstCell) {
|
|
firstCell.innerHTML = `<td "class="sno-checkbox"> ${sno}</td>`;
|
|
sno++; // Increment SNO for the next row
|
|
}
|
|
});
|
|
|
|
// ✅ Reset the tracker based on remaining rows
|
|
tableSNOTracker[tableID] = sno;
|
|
}
|
|
|
|
function increaseTableWidth(increaseBy) {
|
|
// console.log("function called tablewidth increase");
|
|
$("table").each(function() {
|
|
let currentWidth = ($(this).width());
|
|
// console.log('table width ', typeof(currentWidth));
|
|
let increaseTableWidth = (currentWidth + increaseBy);
|
|
// console.log(increaseTableWidth);
|
|
$(this).width(currentWidth + increaseBy);
|
|
});
|
|
}
|
|
|
|
function arrangeTables() {
|
|
// Target the container
|
|
const container = document.getElementById('tablesContainer');
|
|
if (!container) {
|
|
console.error('Error: tablesContainer not found');
|
|
return;
|
|
}
|
|
|
|
// Select divs with data-parent-row (your containers)
|
|
const divContainers = container.querySelectorAll('div[data-parent-row]');
|
|
|
|
const containerArray = Array.from(divContainers).map(div => {
|
|
const policyName = div.getAttribute('data-parent-row').toLowerCase();
|
|
const policyDetails = policyOrder.find(policy =>
|
|
Object.keys(policy)[0] === policyName
|
|
);
|
|
return {
|
|
element: div, // Work with the div, not the table
|
|
policyName: policyName,
|
|
priority: policyDetails ? policyDetails[policyName].priority : Infinity
|
|
};
|
|
});
|
|
|
|
// Filter to only selected policies
|
|
const selectedContainers = containerArray.filter(container =>
|
|
selectedPolicies.has(container.policyName)
|
|
);
|
|
// console.log('container selected ',selectedContainers);
|
|
// Sort by priority
|
|
selectedContainers.sort((a, b) => a.priority - b.priority);
|
|
|
|
// Reorder the divs in the container
|
|
selectedContainers.forEach(containerData => {
|
|
container.appendChild(containerData.element);
|
|
});
|
|
}
|
|
|
|
function setValueForHiddenField(element, answer_type) {
|
|
|
|
if (answer_type != 'dropdown') {
|
|
// console.log(element);
|
|
const hiddenInput = element.querySelector("input[type='hidden']");
|
|
const updatedText = element.textContent.trim();
|
|
var updated_Text = element.textContent.trim();
|
|
// console.log('updated text ',updated);
|
|
if (hiddenInput) {
|
|
|
|
hiddenValue = updated_Text;
|
|
|
|
// Convert it back to a JSON string and set the value
|
|
hiddenInput.value = JSON.stringify(hiddenValue);
|
|
|
|
console.log("Updated Hidden Input Value:", hiddenInput.value);
|
|
} else {
|
|
console.warn("No hidden input found inside the element.");
|
|
}
|
|
}
|
|
}
|
|
|
|
function addOrRemoveIcon(element, event) {
|
|
event.stopPropagation();
|
|
let icon = element.querySelector('.fa-check-square');
|
|
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);
|
|
}
|
|
} else {
|
|
if (!icon2) {
|
|
createIcon(client_proposal_element);
|
|
}
|
|
}
|
|
}
|
|
if (!icon) {
|
|
createIcon(element);
|
|
// console.log("checkbox added");
|
|
} else {
|
|
element.removeChild(icon);
|
|
// console.log("checkbox removed");
|
|
}
|
|
}
|
|
|
|
function createIcon(element) {
|
|
let icon = document.createElement('i');
|
|
icon.classList.add('fa', 'fa-check-square');
|
|
icon.style.color = 'green';
|
|
icon.style.marginLeft = '8px';
|
|
element.appendChild(icon);
|
|
}
|
|
|
|
document.addEventListener('click', function(e) {
|
|
if (e.target.classList.contains('policy-link')) {
|
|
const policyName = e.target.getAttribute('data-policy-name');
|
|
getPolicyInfo(policyName);
|
|
e.preventDefault();
|
|
}
|
|
});
|
|
|
|
function getPolicyInfo(policyName) {
|
|
console.log("anchor link clicked ", policyName);
|
|
|
|
if (!myModal) {
|
|
myModal = new bootstrap.Modal(document.getElementById('policyRegisterModel'));
|
|
console.log("inside if condition");
|
|
}
|
|
$('.loader').fadeIn();
|
|
$('.loader-mask').fadeIn();
|
|
myModal.show();
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
}
|
|
|
|
function addPolicySummaryTable(storedData) {
|
|
var locationCount = storedData.locations.length;
|
|
var tableRowContent = [];
|
|
|
|
// Loop through each location and generate the summary rows dynamically
|
|
for (let i = 0; i < locationCount; i++) {
|
|
let locationIndex = i + 1; // To make it 1-based instead of 0-based
|
|
|
|
tableRowContent.push({
|
|
table_type: "new",
|
|
table_id: "fire_summary_" + locationIndex,
|
|
table_editable: true,
|
|
table_name: "Risk Location " + locationIndex + "- " +
|
|
storedData.locations[i].policyRisk['occupancy'] + "- " +
|
|
storedData.locations[i].policyRisk['address1'] + " " +
|
|
storedData.locations[i].policyRisk['address2'],
|
|
"answer_type": "free-text",
|
|
table_row_contents: [{
|
|
[`fire_plantMachineries_${locationIndex}`]: {
|
|
"display_value": "Plant & Machineries and Accessories",
|
|
"answer_type": "free-text",
|
|
"default_answer": storedData.locations[i].policyRiskSplitUp?.plantAndMachinery || ""
|
|
}
|
|
},
|
|
{
|
|
[`fire_electricalFittings_${locationIndex}`]: {
|
|
"display_value": "Electronic Equipments and Accessories",
|
|
"answer_type": "free-text",
|
|
"default_answer": storedData.locations[i].policyRiskSplitUp?.electricalFittings || ""
|
|
}
|
|
},
|
|
{
|
|
[`fire_furnitureFittings_${locationIndex}`]: {
|
|
"display_value": "FFF (Furniture, Fixtures & Fittings)",
|
|
"answer_type": "free-text",
|
|
"default_answer": storedData.locations[i].policyRiskSplitUp?.furniture || ""
|
|
}
|
|
},
|
|
{
|
|
[`fire_content_${locationIndex}`]: {
|
|
"display_value": "Other Contents Related to Insured",
|
|
"answer_type": "free-text",
|
|
"default_answer": storedData.locations[i].policyRiskSplitUp?.content || ""
|
|
}
|
|
}
|
|
]
|
|
});
|
|
}
|
|
|
|
var policySummary = tableRowContent;
|
|
console.log("policy summary ", policySummary);
|
|
return policySummary;
|
|
}
|
|
|
|
async function selectInsurer(insurers) {
|
|
|
|
console.log("Async function called");
|
|
// Build the HTML for the Select2 dropdown and the input text field
|
|
const selectHTML = `
|
|
<div class="form-row">
|
|
|
|
<div class="form-group col-md-8">
|
|
<select id="insurerSelect">
|
|
<option></option> <!-- Placeholder for Select2 -->
|
|
${insurers.map(insurer => `<option data-id="${insurer.id}-${insurer.insurer_id}" value="${insurer.insurer_name}-${insurer.branch_code}">${insurer.insurer_name}-${insurer.branch_code}</option>`).join('')}
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-group col-md-4">
|
|
<input type="text" class="form-control" id="insurerDetails" placeholder="Enter Version">
|
|
</div>
|
|
|
|
</div>
|
|
`;
|
|
|
|
// Display SweetAlert with the Select2 dropdown and text input as HTML content
|
|
const result = await Swal.fire({
|
|
title: 'Select an insurer',
|
|
html: selectHTML,
|
|
showCancelButton: true,
|
|
preConfirm: () => {
|
|
|
|
const selectedInsurer = document.getElementById('insurerSelect').value;
|
|
const insurerDetails = document.getElementById('insurerDetails').value;
|
|
|
|
const insurerSelect = document.getElementById('insurerSelect');
|
|
const selectedOption = insurerSelect.options[insurerSelect.selectedIndex];
|
|
const dataId = selectedOption.getAttribute('data-id');
|
|
|
|
if (!selectedInsurer) {
|
|
Swal.showValidationMessage("You need to select an insurer :)");
|
|
}
|
|
|
|
return {
|
|
selectedInsurer,
|
|
insurerDetails,
|
|
dataId
|
|
};
|
|
},
|
|
didOpen: () => {
|
|
// Initialize Select2 on the dropdown
|
|
$('#insurerSelect').select2({
|
|
placeholder: 'Select an insurer',
|
|
dropdownParent: $(
|
|
'.swal2-popup') // Ensure Select2 is rendered inside SweetAlert
|
|
});
|
|
}
|
|
});
|
|
|
|
// Return the selected insurer and input details if confirmed
|
|
if (result.isConfirmed) {
|
|
return result.value;
|
|
}
|
|
return null; // If canceled, return null
|
|
}
|
|
|
|
function saveRFQ() {
|
|
console.log("save button clicked");
|
|
leadJson = tablesToJson();
|
|
console.log("json from function ", leadJson);
|
|
saveRFQTODB(leadJson);
|
|
}
|
|
|
|
function saveRFQTODB(tableJSON) {
|
|
|
|
var formData = {
|
|
lead_id: $("#lead_id").val(),
|
|
json: JSON.stringify(tableJSON),
|
|
submit_type: "RFQ"
|
|
}
|
|
|
|
var url = '<?= base_url('rfq/create') ?>';
|
|
$('.loader').fadeIn();
|
|
$('.loader-mask').fadeIn();
|
|
|
|
$.ajax({
|
|
url: url,
|
|
data: formData,
|
|
method: "POST",
|
|
success: function(response) {
|
|
if (response.status == true) {
|
|
toastr.success(response.message, "Success");
|
|
// window.location.reload();
|
|
} else {
|
|
toastr.error(response.message, "Error");
|
|
}
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
},
|
|
error: function(xhr, status, error) {
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
console.error(xhr.responseText);
|
|
console.error(status, error);
|
|
}
|
|
})
|
|
}
|
|
|
|
function prepareOverallData() {
|
|
const overAllData = {};
|
|
// console.log("Policy Configuration Data : ", policyConfig);
|
|
// Iterate through each proposal in quotesConfig
|
|
Object.entries(policyConfig).forEach(([proposalNumber, insurers]) => {
|
|
const proposalKey = `Proposal ${proposalNumber}`;
|
|
overAllData[proposalKey] = {
|
|
qcr: 0,
|
|
stc: 0,
|
|
insurers: []
|
|
};
|
|
|
|
// Get QCR/STC status from proposal header
|
|
const proposalHeader = document.querySelector(`th[data-proposal="${proposalNumber}"]`);
|
|
if (proposalHeader) {
|
|
const qcrSelected = proposalHeader.querySelector('.qcrProposal .fa-check-square') !== null;
|
|
const stcSelected = proposalHeader.querySelector('.sendClientProposal .fa-check-square') !== null;
|
|
overAllData[proposalKey].qcr = qcrSelected ? 1 : 0;
|
|
overAllData[proposalKey].stc = stcSelected ? 1 : 0;
|
|
}
|
|
console.log("Insurers Found", insurers);
|
|
|
|
// Get unique insurers from quotesConfig (stored during addNewQuote)
|
|
const uniqueInsurers = [];
|
|
insurers.forEach(insurer => {
|
|
if (typeof insurer === 'object' && insurer.id) { // Check if stored properly id:dataId,
|
|
|
|
uniqueInsurers.push({
|
|
ins_name: insurer.insurerName,
|
|
qcr: 1,
|
|
stc: 1,
|
|
display_name: insurer.insurerName,
|
|
id: insurer.id
|
|
});
|
|
}
|
|
});
|
|
console.log("Unique Insurers Found", uniqueInsurers);
|
|
overAllData[proposalKey].insurers = Array.from(uniqueInsurers.values());
|
|
});
|
|
console.log("overalll data created is ", overAllData);
|
|
return overAllData;
|
|
}
|
|
|
|
function getTextExcludingButton(cell) {
|
|
return Array.from(cell.childNodes)
|
|
.filter(node => node.nodeType === Node.TEXT_NODE) // Get only text nodes
|
|
.map(node => node.textContent.trim()) // Trim unnecessary spaces
|
|
.join(' ').trim();
|
|
}
|
|
|
|
function tablesToJson() {
|
|
const allTablesData = [];
|
|
// Select all tables - adjust the selector if needed (e.g., '.json-table' for specific tables)
|
|
const tables = document.querySelectorAll('table');
|
|
|
|
tables.forEach(table => {
|
|
const headers = [];
|
|
const data = [];
|
|
const tableId = table.id; // Ensure each table has a unique ID
|
|
console.log('Processing table:', tableId);
|
|
|
|
// Get parent headers and subheaders for the current table
|
|
const parentHeaders = table.querySelectorAll('thead tr:nth-child(1) th');
|
|
const subHeaders = table.querySelectorAll('thead tr:nth-child(2) th');
|
|
|
|
let headerIndex = 0;
|
|
parentHeaders.forEach(header => {
|
|
const colspan = parseInt(header.getAttribute('colspan')) || 1;
|
|
const subHeaderArray = [];
|
|
for (let i = 0; i < colspan; i++) {
|
|
subHeaderArray.push(subHeaders[headerIndex].innerText.replace('⋮', '').trim());
|
|
headerIndex++;
|
|
}
|
|
console.log("HEader : ", header.innerText.replace('⋮', '').split('\n')[0].replace(/:.*/, '').trim());
|
|
headers.push({
|
|
parentHeader: header.innerText.replace('⋮', '').split('\n')[0].replace(/:.*/, '').trim(),
|
|
subHeaders: subHeaderArray
|
|
});
|
|
});
|
|
|
|
// Process each row in the current table
|
|
const rows = table.querySelectorAll('tbody tr');
|
|
rows.forEach(row => {
|
|
const rowId = row.id;
|
|
console.log("row id : ", rowId);
|
|
console.log("Suggestions :", suggestions);
|
|
const inputType = suggestions[rowId]?.answer_type || 'text'; // Default to 'text' if undefined
|
|
const cells = row.querySelectorAll('td');
|
|
// console.log("row id going to submit us ", );
|
|
const rowData = {
|
|
SNO: cells[0] ? getTextExcludingButton(cells[0]) : '',
|
|
items: cells[1]?.innerText || '',
|
|
row_id: rowId,
|
|
data: []
|
|
};
|
|
if (tableId == "excess") {
|
|
console.log("row Trying to set : ", row);
|
|
console.log("row Trying to set : ", row.outerHTML);
|
|
rowData['parentPolicy'] = row.getAttribute("data-excess-row-parent")
|
|
}
|
|
console.log("Row data foint to submit ", rowData);
|
|
let dataIndex = 0;
|
|
headers.forEach(header => {
|
|
header.subHeaders.forEach(subHeader => {
|
|
if (dataIndex >= cells.length) return; // Prevent out-of-bound errors
|
|
const cell = cells[dataIndex];
|
|
let content;
|
|
// Handle different input types and action cells
|
|
if (inputType === "text" && header.parentHeader === 'Action') {
|
|
const qcrInput = cell.querySelector('input[name="qcr"]');
|
|
const clientInput = cell.querySelector('input[name="stc"]');
|
|
console.log("QCR INPUT : ", qcrInput);
|
|
|
|
content = {
|
|
qcr: qcrInput?.checked ? 1 : 0,
|
|
stc: clientInput?.checked ? 1 : 0
|
|
};
|
|
} else {
|
|
const input = cell.querySelector('input, select, textarea');
|
|
if (input) {
|
|
console.log("Input type:", input.type);
|
|
|
|
if (input.type === "checkbox") {
|
|
content = input.checked ? "Checked" : "Not Checked"; // Handling checkboxes
|
|
display_value = input.checked ? "Checked" : "Not Checked";
|
|
} else {
|
|
content = input.value; // Handling other input types like text, select, textarea
|
|
display_value = cell.innerText.trim();
|
|
}
|
|
} else {
|
|
content = cell.innerText.trim(); // If no input is found, use the cell's text
|
|
display_value = cell.innerText.trim();
|
|
|
|
}
|
|
}
|
|
|
|
// console.log("trying to find what this is ",cell);
|
|
rowData.data.push({
|
|
parentth: header.parentHeader,
|
|
subth: subHeader,
|
|
// value: cell.innerText,
|
|
input_value: content,
|
|
display_value: display_value,
|
|
rowspan: cell.rowSpan
|
|
});
|
|
|
|
dataIndex++;
|
|
});
|
|
});
|
|
|
|
data.push(rowData);
|
|
console.log("data gets pushed here ", data);
|
|
});
|
|
tablePolicyName = [...selectedPolicies].find(policy => tableId.startsWith(policy)) || null;
|
|
console.log(selectedPolicies);
|
|
console.log(tablePolicyName);
|
|
// Get table-specific over_all_column_data (adjust based on your data structure)
|
|
|
|
|
|
allTablesData.push({
|
|
tableId: tableId,
|
|
tablePolicy: tablePolicyName,
|
|
table_data: {
|
|
headers: headers,
|
|
data: data
|
|
},
|
|
// proposal_data: {
|
|
// over_all_column_data: tableOverAllData
|
|
// }
|
|
});
|
|
});
|
|
const tableOverAllData = prepareOverallData() || {};
|
|
allTablesData.push({
|
|
proposal_data: {
|
|
over_all_column_data: tableOverAllData
|
|
}
|
|
});
|
|
// Save all tables' data to localStorage
|
|
localStorage.setItem('allTablesJsonData', JSON.stringify(allTablesData));
|
|
console.log('All tables data saved:', allTablesData);
|
|
// toastr.success("RFQ Saved Successfully", "SUCCESS");
|
|
// If needed, reconstruct tables from JSON (implement jsonToTable accordingly)
|
|
|
|
return allTablesData;
|
|
}
|
|
|
|
function openQCR() {
|
|
const url = window.location.pathname; // Get the path (e.g., "/nhance/rfq/list/75/1")
|
|
const segments = url.split("/"); // Split by "/"
|
|
segments[segments.length - 1] = "2"; // Change the last segment
|
|
const newUrl = segments.join("/"); // Rebuild the URL
|
|
|
|
history.pushState(null, "", newUrl); // Change the URL without reloading
|
|
|
|
rfq_or_qcr = 2;
|
|
$('.loader').fadeIn();
|
|
$('.loader-mask').fadeIn();
|
|
jsonToTables();
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
hideProposalOptionsForChild();
|
|
showOrHideFieldsBasedOnRFQorQCR();
|
|
}
|
|
|
|
function setPolicyConfiguration(overAllColumnData) {
|
|
let result = {};
|
|
|
|
// Iterate over each proposal
|
|
Object.entries(overAllColumnData).forEach(([proposalKey, proposalData]) => {
|
|
// Extract proposal number from the key (ensuring it's properly extracted)
|
|
let match = proposalKey.match(/\d+/); // Extracts the number from "Proposal X"
|
|
let proposalNumber = match ? match[0] : undefined;
|
|
|
|
if (!proposalNumber) return; // Skip if extraction fails
|
|
|
|
// Initialize with "Quote asked"
|
|
result[proposalNumber] = ["Quote asked"];
|
|
|
|
// Check if insurers exist and filter those with qcr = 1
|
|
if (Array.isArray(proposalData.insurers)) {
|
|
proposalData.insurers.forEach(insurer => {
|
|
|
|
result[proposalNumber].push({
|
|
id: insurer.id,
|
|
version: "",
|
|
insurerName: insurer.display_name
|
|
});
|
|
|
|
});
|
|
}
|
|
});
|
|
|
|
return result;
|
|
}
|
|
|
|
function setQuotesConfig(overallColumnData) {
|
|
let quotesConfiguration = {}; // Stores the transformed output
|
|
let index = 1; // Keeps track of proposal index
|
|
|
|
Object.keys(overallColumnData).forEach((proposalKey) => {
|
|
let proposal = overallColumnData[proposalKey];
|
|
let insurersList = proposal.insurers.map(ins => ins.ins_name); // Extract insurer names
|
|
|
|
// Create output format: index { "Quote asked", ...insurers }
|
|
quotesConfiguration[index] = ["Quote asked", ...insurersList];
|
|
|
|
index++; // Increment index for next proposal
|
|
// proposalCount++;
|
|
});
|
|
|
|
return quotesConfiguration;
|
|
}
|
|
|
|
|
|
|
|
function jsonToTables() {
|
|
const container = document.getElementById('tablesContainer');
|
|
container.innerHTML = ''; // Clear existing content
|
|
const savedData = JSON.parse(localStorage.getItem('allTablesJsonData'));
|
|
let lastIndex = savedData.length - 1;
|
|
var proposalDataArray = savedData[lastIndex];
|
|
console.log("json to table : ", savedData);
|
|
console.log("json to table : ", proposalDataArray);
|
|
console.log("json to table : ", lastIndex);
|
|
// console.log("json to table : ",savedData[lastIndex]);
|
|
console.log("json to table : ", proposalDataArray.proposal_data);
|
|
console.log("json to table : ", proposalDataArray.proposal_data.over_all_column_data);
|
|
|
|
policyConfig = {};
|
|
|
|
policyConfig = setPolicyConfiguration(proposalDataArray.proposal_data.over_all_column_data);
|
|
console.log("policy configuration : ", policyConfig);
|
|
|
|
quotesConfig = {};
|
|
quotesConfig = setQuotesConfig(proposalDataArray.proposal_data.over_all_column_data);
|
|
console.log("quotes config ... : ", quotesConfig);
|
|
|
|
proposalCount = Object.keys(proposalDataArray.proposal_data.over_all_column_data).length;
|
|
console.log("proposal count : ", proposalCount);
|
|
console.log("proposal count quotes config ... : ", proposalDataArray.proposal_data.over_all_column_data);
|
|
|
|
let increaseBy = proposalCount * 150;
|
|
console.log("trying to find checkbox data : : : ", increaseBy);
|
|
|
|
// Group tables by policy name
|
|
const policyTables = {};
|
|
|
|
// Process each table entry
|
|
savedData.forEach((tableEntry, index) => {
|
|
// console.log("table entry : ", tableEntry);
|
|
if (!tableEntry.table_data) return; // Skip proposal data entry
|
|
|
|
const table = document.createElement('table');
|
|
if (tableEntry.tableId) table.id = tableEntry.tableId;
|
|
|
|
// Create header structure
|
|
const thead = document.createElement('thead');
|
|
const [headerRow1, headerRow2] = createHeaderRows(tableEntry.table_data.headers, proposalDataArray);
|
|
thead.append(headerRow1, headerRow2);
|
|
table.appendChild(thead);
|
|
|
|
// Create body
|
|
const tbody = document.createElement('tbody');
|
|
tableEntry.table_data.data.forEach(rowData => {
|
|
const tr = document.createElement('tr');
|
|
tr.id = rowData.row_id;
|
|
if (tableEntry.tableId === "excess" && rowData.parentPolicy) {
|
|
tr.setAttribute('data-excess-row-parent', rowData.parentPolicy);
|
|
}
|
|
|
|
// Process each cell
|
|
rowData.data.forEach((cellData, cellIndex) => {
|
|
const td = document.createElement(cellIndex === 0 ? 'td' : 'td');
|
|
|
|
// Handle RowSpan Attribute
|
|
if (cellData.rowspan && cellData.rowspan > 1) {
|
|
td.rowSpan = cellData.rowspan;
|
|
}
|
|
|
|
// Handle SNO column
|
|
if (cellIndex === 0 && tableEntry.tableId) {
|
|
td.textContent = rowData.SNO;
|
|
// td.classList.add("sno-checkboxes");
|
|
}
|
|
// Handle Action column
|
|
else if (cellData.parentth === 'Action') {
|
|
if (table.id != "") {
|
|
td.innerHTML = `
|
|
<input class = "qcr-checkbox" id = "qcrCheckbox" name="qcr" type="checkbox" ${cellData.input_value.qcr ? 'checked' : ''}> <label for = "qcrCheckbox">QCR</label>
|
|
<input class="client-checkbox" name="stc" type="checkbox" ${cellData.input_value.stc ? 'checked' : ''}>
|
|
Client
|
|
<button class="btn btn-primary btn-sm" onclick="addRow(event, this)">+</button>
|
|
<button class="btn btn-danger btn-sm" onclick="removeRowQCR(event)">-</button>
|
|
`;
|
|
} else {
|
|
td.innerHTML = "";
|
|
}
|
|
}
|
|
// Handle regular cells
|
|
else {
|
|
td.innerHTML = processCellContent(cellData.input_value, rowData,cellData.display_value);
|
|
if (cellData.parentth.startsWith("Proposal")) {
|
|
td.onclick = () => getAnswer(table.id, tr.id);
|
|
if (cellData.subth != "Quote asked") {
|
|
td.classList.add("insurer_proposal");
|
|
}
|
|
}
|
|
td.contentEditable = true;
|
|
if (cellIndex === 0) {
|
|
td.contentEditable = false;
|
|
}
|
|
}
|
|
tr.appendChild(td);
|
|
});
|
|
|
|
tbody.appendChild(tr);
|
|
});
|
|
|
|
table.appendChild(tbody);
|
|
|
|
// // Determine the policy name from the table ID
|
|
// const tableIdParts = tableEntry.tableId.split('_'); // Split table ID by underscore
|
|
// let policyName = tableIdParts[0]; // Initialize with the first part
|
|
|
|
// // Handle policy names with two words (e.g., "public_liability")
|
|
// if (tableIdParts.length > 2) {
|
|
// policyName = tableIdParts.slice(0, 2).join('_'); // Join first two parts for two-word policies
|
|
// }
|
|
selectedPolicies.add(tableEntry.tablePolicy);
|
|
let policyNameforTable = tableEntry.tablePolicy
|
|
if (!policyTables[policyNameforTable]) {
|
|
policyTables[policyNameforTable] = []; // Initialize array for this policy
|
|
}
|
|
policyTables[policyNameforTable].push(table); // Add table to the policy group
|
|
});
|
|
|
|
// Create containers for each policy and append tables
|
|
Object.entries(policyTables).forEach(([policyName, tables]) => {
|
|
const policyContainer = document.createElement('div');
|
|
policyContainer.setAttribute('data-parent-row', policyName); // Set data-parent-row to policy name
|
|
|
|
tables.forEach(table => {
|
|
policyContainer.appendChild(table); // Append all tables for this policy
|
|
});
|
|
|
|
container.appendChild(policyContainer); // Append the policy container to the main container
|
|
});
|
|
|
|
// Handle excess table separately (if it exists)
|
|
const excessTable = document.getElementById('excess');
|
|
if (excessTable) {
|
|
container.appendChild(excessTable);
|
|
}
|
|
|
|
// Restore proposal headers and icons
|
|
restoreProposalHeaders(savedData[savedData.length - 1].proposal_data.over_all_column_data);
|
|
reattachEventListeners();
|
|
hideProposalOptionsForChild();
|
|
increaseTableWidth(increaseBy);
|
|
contentNonEditableInsurerAdded(proposalDataArray.proposal_data.over_all_column_data);
|
|
}
|
|
|
|
// Helper function to create header rows
|
|
function createHeaderRows(headers, proposal_data) {
|
|
|
|
const headerRow1 = document.createElement('tr');
|
|
const headerRow2 = document.createElement('tr');
|
|
var overallColumnDataProposal = proposal_data.proposal_data.over_all_column_data;
|
|
headers.forEach(header => {
|
|
// Parent header
|
|
const th1 = document.createElement('th');
|
|
th1.textContent = header.parentHeader;
|
|
if (header.parentHeader.startsWith('Proposal')) {
|
|
var headerName = header.parentHeader;
|
|
console.log("header name : ", th1.textContent.trim());
|
|
console.log("over all column data : ", over_all_column_data)
|
|
let matchedKey = Object.keys(overallColumnDataProposal).find(key => headerName.startsWith(key));
|
|
if (matchedKey) {
|
|
console.log("something wrong : ", overallColumnDataProposal[matchedKey]);
|
|
var headerCheckBoxProperties = overallColumnDataProposal[matchedKey];
|
|
}
|
|
|
|
th1.innerHTML = `
|
|
${header.parentHeader}
|
|
<span class="three-dot-menu" >⋮</span>
|
|
<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
|
|
class="fa fa-check-square"
|
|
style="color: green; margin-left: 8px; "></i> `:"" }</button>
|
|
<button id = "isSTC" class="sendClientProposal" onclick = "addOrRemoveIcon(this,event)"
|
|
style="background-color: rgb(221, 221, 221);">Send to Client ${headerCheckBoxProperties['stc'] == 1 ? `<i
|
|
class="fa fa-check-square"
|
|
style="color: green; margin-left: 8px; "></i> `:"" }</button>
|
|
<button onclick="removeProposal(${header.parentHeader.split(' ')[1]})">Remove Proposal</button>
|
|
<button class = "newInsurer" onclick="addNewQuote(${header.parentHeader.split(' ')[1]})">Add New Insurer</button>
|
|
|
|
</div>
|
|
`;
|
|
th1.colSpan = header.subHeaders.length;
|
|
|
|
// console.log("insurer data proposal set : ",th1); // See the element's attributes in the console
|
|
|
|
}
|
|
headerRow1.appendChild(th1);
|
|
// console.log("this is the header : ", header);
|
|
// Sub headers
|
|
header.subHeaders.forEach(subHeader => {
|
|
const th2 = document.createElement('th');
|
|
if (header.parentHeader.startsWith("Proposal") && subHeader != "Quote asked") {
|
|
console.log("this is the subheader : ", subHeader);
|
|
th2.classList.add("insurer_proposal");
|
|
th2.innerHTML = `
|
|
${subHeader}
|
|
<span class="three-dot-menu">⋮</span>
|
|
<div class="dropdown-content">
|
|
<button onclick="changeInsurer(event, ${header.parentHeader.split(' ')[1]}, '${subHeader}')">Change Insurer</button>
|
|
<button onclick="removeQuote(event, ${header.parentHeader.split(' ')[1]}, '${subHeader}')">Remove Quote</button>
|
|
</div>
|
|
`;
|
|
th2.setAttribute('data-proposal', header.parentHeader.split(' ')[1]);
|
|
th1.setAttribute('data-proposal', header.parentHeader.split(' ')[1]);
|
|
console.log("header insert position ",th1.getAttribute())
|
|
|
|
} else {
|
|
th2.textContent = subHeader;
|
|
th2.setAttribute('data-proposal', header.parentHeader.split(' ')[1]);
|
|
th1.setAttribute('data-proposal', header.parentHeader.split(' ')[1]);
|
|
}
|
|
|
|
|
|
headerRow2.appendChild(th2);
|
|
});
|
|
});
|
|
|
|
return [headerRow1, headerRow2];
|
|
}
|
|
|
|
// Helper to process cell content
|
|
function processCellContent(value, cellData = null,displayValue) {
|
|
|
|
if (value.startsWith('Check') || value.startsWith('Not')) {
|
|
// 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'
|
|
? `<br><button class = "btn btn-primary btn-sm" onclick = "getPolicyInfo()" class="policy-link" data-policy-name="${cellData.SNO}">Register</a>`
|
|
: ""}`;
|
|
}
|
|
if (typeof value === 'string' && value.startsWith('{')) {
|
|
try {
|
|
const parsed = JSON.parse(value);
|
|
return `${displayValue} <input type="hidden" value='${JSON.stringify(parsed)}' />`;
|
|
} catch {
|
|
return value;
|
|
}
|
|
}
|
|
return value;
|
|
}
|
|
|
|
// Restore proposal header icons
|
|
function restoreProposalHeaders(proposalData) {
|
|
Object.entries(proposalData).forEach(([proposal, data]) => {
|
|
const proposalNumber = proposal.split(' ')[1];
|
|
const header = document.querySelector(`th[data-proposal="${proposalNumber}"]`);
|
|
// console.log("header attribute set");
|
|
|
|
if (header) {
|
|
// if (data.qcr) header.querySelector('.qcrProposal').appendChild(createCheckIcon());
|
|
// if (data.stc) header.querySelector('.sendClientProposal').appendChild(createCheckIcon());
|
|
}
|
|
});
|
|
}
|
|
|
|
// Reattach event listeners
|
|
function reattachEventListeners() {
|
|
const container = document.getElementById('tablesContainer');
|
|
|
|
|
|
// Three-dot menu handlers
|
|
document.querySelectorAll('.three-dot-menu').forEach(menu => {
|
|
menu.addEventListener('click', showDropdown);
|
|
console.log("event listener called ");
|
|
});
|
|
|
|
// Policy link handlers
|
|
document.querySelectorAll('.policy-link').forEach(link => {
|
|
link.addEventListener('click', function(e) {
|
|
getPolicyInfo(e.target.dataset.policyName);
|
|
e.preventDefault();
|
|
});
|
|
});
|
|
}
|
|
|
|
function createCheckIcon() {
|
|
const icon = document.createElement('i');
|
|
icon.className = 'fa fa-check-square';
|
|
icon.style.color = 'green';
|
|
icon.style.marginLeft = '8px';
|
|
return icon;
|
|
}
|
|
|
|
function showOrHideFieldsBasedOnRFQorQCR() {
|
|
console.log("function called rfq or qcr ", rfq_or_qcr);
|
|
|
|
if (rfq_or_qcr == 1) {
|
|
$(".newInsurer").hide();
|
|
$("#isQCR").show();
|
|
$(".qcr-checkbox").show();
|
|
$("label[for='qcrCheckbox']").show();
|
|
$("#openQCR").show();
|
|
$("input#qcrCheckbox").show();
|
|
$("#addProposal").show();
|
|
alignTableColumn();
|
|
$(".qcrProposal").show();
|
|
$("#saveRFQ").text("Save RFQ");
|
|
|
|
|
|
} else if (rfq_or_qcr == 2) {
|
|
$(".newInsurer").show();
|
|
$("#isQCR").hide();
|
|
$(".qcr-checkbox").hide();
|
|
$("label[for='qcrCheckbox']").hide();
|
|
$("input#qcrCheckbox").hide();
|
|
$("#addProposal").hide();
|
|
$(".insurer_proposal").show();
|
|
$(".qcrProposal").hide();
|
|
$("#saveRFQ").text("Save QCR");
|
|
// $(".sno-checkboxes").prop("disabled", true);
|
|
$("#openQCR").hide();
|
|
hideNonQCRRows();
|
|
hideNonQCRColumns();
|
|
disableCheckbox();
|
|
|
|
}
|
|
|
|
makeQuoteAskedColumnNonEditableorEditable();
|
|
}
|
|
|
|
function disableCheckbox() {
|
|
|
|
// Select all checkboxes with the class "sno-checkboxes"
|
|
const checkboxes = document.querySelectorAll('.sno-checkbox');
|
|
// console.log("inside disable ",checkboxes);
|
|
// Disable all selected checkboxes
|
|
checkboxes.forEach(checkbox => {
|
|
checkbox.disabled = true;
|
|
// console.log("inside disable loop",checkbox);
|
|
});
|
|
}
|
|
|
|
function hideNonQCRColumns() {
|
|
|
|
const savedData = JSON.parse(localStorage.getItem('allTablesJsonData'));
|
|
let lastIndex = savedData.length - 1;
|
|
var proposalDataArray = savedData[lastIndex];
|
|
var overallData = proposalDataArray.proposal_data.over_all_column_data;
|
|
const getProposalsWithQCRZero = (data) => {
|
|
return Object.keys(data).filter(proposal => data[proposal].qcr === 0);
|
|
};
|
|
|
|
var proposal = getProposalsWithQCRZero(overallData);
|
|
|
|
proposal.forEach(function(prop) {
|
|
hideColumn(prop);
|
|
})
|
|
|
|
}
|
|
|
|
function hideColumn(columnName) {
|
|
console.log(`Hiding column: ${columnName}`);
|
|
|
|
document.querySelectorAll("table").forEach(table => {
|
|
let headers = table.querySelectorAll("th");
|
|
let rows = table.querySelectorAll("tr");
|
|
|
|
let columnIndex = -1;
|
|
|
|
// Find the column index based on header text
|
|
headers.forEach((header, index) => {
|
|
if (header.textContent.trim().startsWith(columnName)) {
|
|
columnIndex = index;
|
|
header.style.display = "none"; // Hide header
|
|
}
|
|
});
|
|
|
|
if (columnIndex === -1) {
|
|
console.log(`Column "${columnName}" not found in any table.`);
|
|
return;
|
|
}
|
|
|
|
// Hide corresponding cells while respecting colspan & rowspan
|
|
rows.forEach(row => {
|
|
let cells = Array.from(row.children);
|
|
let cellIndex = 0;
|
|
|
|
for (let cell of cells) {
|
|
let colSpan = cell.colSpan || 1;
|
|
let rowSpan = cell.rowSpan || 1;
|
|
|
|
if (cellIndex === columnIndex) {
|
|
if (colSpan > 1) {
|
|
cell.colSpan--; // Reduce colspan instead of hiding
|
|
} else {
|
|
cell.style.display = "none"; // Hide the cell
|
|
}
|
|
}
|
|
|
|
cellIndex += colSpan; // Move to the next column index
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function hideNonQCRRows() {
|
|
console.log("hideNonQCRRows function called");
|
|
// Select all tables
|
|
document.querySelectorAll("table").forEach(table => {
|
|
|
|
console.log("Processing table:", table);
|
|
// Loop through each row in the table
|
|
table.querySelectorAll("tr").forEach(row => {
|
|
console.log("Processing row:", row);
|
|
// Find the qcr-checkbox in the current row
|
|
const qcrCheckbox = row.querySelector(".qcr-checkbox");
|
|
console.log("QCR Checkbox:", qcrCheckbox);
|
|
|
|
if (qcrCheckbox && !qcrCheckbox.checked) {
|
|
// If qcr-checkbox exists and is NOT checked, hide the row
|
|
console.log("Hiding row:", row);
|
|
row.style.display = "none"; // Uncomment this line to hide the row
|
|
updateVisisbleSNO(table.id);
|
|
} else {
|
|
// Otherwise, ensure the row is visible
|
|
console.log("Showing row:", row);
|
|
row.style.display = "";
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
function removeRowQCR(event) {
|
|
const button = event.target;
|
|
const row = button.closest('tr');
|
|
const table = row.closest('table');
|
|
if (row && row.parentElement.children.length > 1) {
|
|
console.log("Row Removed");
|
|
row.remove();
|
|
updateVisisbleSNO(table.id);
|
|
}
|
|
}
|
|
|
|
function updateVisisbleSNO(tableId) {
|
|
console.log(`Updating SNO for table: ${tableId}`);
|
|
|
|
const table = document.getElementById(tableId);
|
|
if (!table) {
|
|
console.log("Table not found!");
|
|
return;
|
|
}
|
|
|
|
let sno = 1; // Start from 1
|
|
table.querySelectorAll("tr").forEach(row => {
|
|
if (row.style.display !== "none") { // Only update visible rows
|
|
const firstCell = row.querySelector("td:first-child"); // Get SNO cell
|
|
if (firstCell) {
|
|
firstCell.innerHTML = `<td "class="sno-checkbox"> ${sno}</td>`;
|
|
sno++; // Increment SNO for the next row
|
|
}
|
|
// const snoCell = row.querySelector(".sno"); // Assuming SNO cell has class "sno"
|
|
// if (snoCell) {
|
|
// snoCell.textContent = sno++; // Assign and increment SNO
|
|
// console.log(`Updated SNO: ${snoCell.textContent}`);
|
|
// }
|
|
}
|
|
});
|
|
}
|
|
|
|
function alignTableColumn() {
|
|
$(".insurer_proposal").each(function() {
|
|
let columnIndex = $(this).index(); // Get index of the hidden column
|
|
let parentHeader = $(this).closest("table").find("tr:first-child th").filter(function() {
|
|
return $(this).attr("colspan") > 1; // Find headers with colspan > 1
|
|
});
|
|
|
|
// Reduce colspan if the hidden column belongs to this header
|
|
parentHeader.each(function() {
|
|
let colspan = parseInt($(this).attr("colspan"), 10);
|
|
if (colspan > 1) {
|
|
$(this).attr("colspan", colspan - 1);
|
|
}
|
|
});
|
|
|
|
// Hide the column
|
|
$(this).hide();
|
|
});
|
|
|
|
}
|
|
|
|
function removeOnClickFromColumnCells(cell) {
|
|
cell.removeAttr("onclick");
|
|
cell.off("click");
|
|
cell[0].onclick = null; // Remove any remaining native listeners
|
|
}
|
|
|
|
function makeQuoteAskedColumnNonEditableorEditable() {
|
|
$("table").each(function() {
|
|
var table = $(this);
|
|
var subHeaderRow = table.find("tr:nth-child(2)"); // Assuming second row is the sub-header
|
|
|
|
var targetColumnIndexes = [];
|
|
// var targetColumnIndex = -1; // Stores the correct column index
|
|
var colIndexTracker = []; // Maps visual column index to actual index
|
|
var visualIndex = 0; // Tracks the visual column position considering rowspan/colspan
|
|
|
|
// Step 1: Find the "Quote asked" column index
|
|
subHeaderRow.children("th, td").each(function(actualIndex) {
|
|
colIndexTracker[visualIndex] = actualIndex;
|
|
|
|
if ($(this).text().trim() === "Quote asked") {
|
|
targetColumnIndexes.push(visualIndex);
|
|
}
|
|
|
|
visualIndex += parseInt($(this).attr("colspan") || 1, 10);
|
|
});
|
|
|
|
if (targetColumnIndexes === 0) return; // If "Quote asked" column is not found, exit
|
|
|
|
// Step 2: Make all cells in the found column non-editable, considering rowspan
|
|
var rowSpans = {}; // Keeps track of rowspans per column
|
|
table.find("tr").each(function() {
|
|
var row = $(this);
|
|
var currentVisualIndex = 0;
|
|
|
|
row.children("td, th").each(function(actualIndex) {
|
|
while (rowSpans[currentVisualIndex]) {
|
|
currentVisualIndex++; // Skip previous row-spanned columns
|
|
}
|
|
|
|
var cell = $(this);
|
|
var actualColIndex = colIndexTracker[currentVisualIndex];
|
|
|
|
if (targetColumnIndexes.includes(colIndexTracker[currentVisualIndex])) {
|
|
|
|
if (rfq_or_qcr == 2) {
|
|
cell.attr("contenteditable", "false");
|
|
removeOnClickFromColumnCells(cell);
|
|
} else if (rfq_or_qcr == 1) {
|
|
// cell.attr("contenteditable", "true");
|
|
}
|
|
|
|
}
|
|
|
|
var rowspan = parseInt(cell.attr("rowspan") || 1, 10);
|
|
if (rowspan > 1) {
|
|
for (var i = 0; i < rowspan; i++) {
|
|
rowSpans[currentVisualIndex] = (rowSpans[currentVisualIndex] || 0) + 1;
|
|
}
|
|
}
|
|
|
|
currentVisualIndex++;
|
|
});
|
|
|
|
// Step 3: Reduce rowspan count for next row processing
|
|
Object.keys(rowSpans).forEach(function(key) {
|
|
if (rowSpans[key] > 0) {
|
|
rowSpans[key]--;
|
|
}
|
|
});
|
|
});
|
|
});
|
|
}
|
|
|
|
function contentNonEditableInsurerAdded(overallcolumnData) {
|
|
let insNames = [];
|
|
|
|
Object.entries(overallcolumnData).forEach(([proposalKey, proposalValue]) => {
|
|
if (proposalValue.insurers.length > 0) {
|
|
insNames.push(proposalKey); // Push proposal key if insurers are present
|
|
}
|
|
});
|
|
|
|
console.log("overall column Data : ", insNames);
|
|
$("table").each(function() {
|
|
var table = $(this);
|
|
var mainHeaderRow = table.find("tr:first-child"); // First row as main header
|
|
|
|
var targetColumnIndexes = new Set();
|
|
var colIndexTracker = [];
|
|
var visualIndex = 0;
|
|
|
|
// Step 1: Find columns where the header matches `insNames`
|
|
mainHeaderRow.children("th, td").each(function(actualIndex) {
|
|
colIndexTracker[visualIndex] = actualIndex;
|
|
|
|
var cellText = $(this).text().trim();
|
|
// console.log("order : ",cellText);
|
|
if (insNames.some(ins => cellText.startsWith(ins))) {
|
|
targetColumnIndexes.add(visualIndex);
|
|
}
|
|
|
|
visualIndex += parseInt($(this).attr("colspan") || 1, 10);
|
|
});
|
|
// console.log("order fro header : ",targetColumnIndexes);
|
|
if (targetColumnIndexes.size === 0) return; // If no matching column is found, exit
|
|
|
|
var rowSpans = {};
|
|
|
|
// Step 2: Iterate through rows and set cells as non-editable
|
|
table.find("tr").each(function() {
|
|
var row = $(this);
|
|
var currentVisualIndex = 0;
|
|
|
|
row.children("td, th").each(function(actualIndex) {
|
|
while (rowSpans[currentVisualIndex]) {
|
|
currentVisualIndex++; // Skip row-spanned columns
|
|
}
|
|
|
|
var cell = $(this);
|
|
var actualColIndex = colIndexTracker[currentVisualIndex];
|
|
var cellColspan = parseInt(cell.attr("colspan") || 1, 10);
|
|
var cellRowspan = parseInt(cell.attr("rowspan") || 1, 10);
|
|
// console.log("order actualcol index : ",actualColIndex);
|
|
if (targetColumnIndexes.has(actualColIndex)) {
|
|
// console.log("inside if conditon order");
|
|
cell.attr("contenteditable", "false");
|
|
removeOnClickFromColumnCells(cell);
|
|
}
|
|
|
|
// Track rowspan
|
|
if (cellRowspan > 1) {
|
|
for (var i = 0; i < cellColspan; i++) {
|
|
rowSpans[currentVisualIndex + i] = (rowSpans[currentVisualIndex + i] || 0) + (cellRowspan - 1);
|
|
}
|
|
}
|
|
|
|
currentVisualIndex += cellColspan;
|
|
});
|
|
|
|
// Reduce rowspan count for the next row
|
|
Object.keys(rowSpans).forEach(function(key) {
|
|
if (rowSpans[key] > 0) {
|
|
rowSpans[key]--;
|
|
}
|
|
});
|
|
});
|
|
});
|
|
|
|
}
|
|
</script>
|