@@ -667,6 +667,8 @@
$('#submitData').text('Save RFQ');
$('#submitMail').text('Send Insurer Mail');
+ $('#submitPlacement').hide();
+ document.getElementById("second_table")?.remove();
if(data){
$('#submitQCRData').show();
@@ -674,16 +676,15 @@
$('#submitQCRData').hide();
$('#submitMail').hide();
$('#submitExcel').hide();
-x }
-
- $('#submitPlacement').hide();
-
- if(jsonDataForHide){
- $('#second_table').hide();
- }else{
- document.getElementById("second_table")?.remove();
+ $('#submitInternalMail').hide();
}
+ // if(jsonDataForHide){
+ // $('#second_table').hide();
+ // }else{
+ // document.getElementById("second_table")?.remove();
+ // }
+
}else{
$('#submitData').text('Save QCR');
@@ -1029,8 +1030,36 @@ function addSuggestionsToTable() {
console.log(' addSuggestionsToTable suggestions ', suggestions);
console.log(' addSuggestionsToTable suggestions type', typeof suggestions);
+ let leadType = = isset($lead_data) && isset($lead_data['lead_type']) ? $lead_data['lead_type'] : 1; ?>;
+ console.log('leadType', leadType);
+
+ let renewal_or_rollover = "Proposal 1";
+ if(leadType == 2){
+ renewal_or_rollover = "Existing Renewal"
+ }else if(leadType == 3){
+ renewal_or_rollover = "Existing Rollover"
+ }
+
+ $('#first_proposel_title').html(`
+ ${renewal_or_rollover}
+
+
+
+
+ `);
if (policy_terms && RFQ_or_QCR == 1) {
+
+
let special_condition_count = 0;
if (policy_terms['special_condition_label']) {
@@ -1074,7 +1103,9 @@ function addSuggestionsToTable() {
const columnCount = $("#rfqTable thead tr th").length;
console.log('columnCount' + columnCount);
+
for (let i = 3; i < columnCount - 6; i++) {
+
const editableCell = newRow.insertCell(i);
editableCell.setAttribute('contenteditable', 'true');
editableCell.classList.add('editablecolumns');
@@ -1093,6 +1124,7 @@ function addSuggestionsToTable() {
editableCell.textContent = '';
inputBox.value = '';
}
+
} else if (policy_terms[key] == 0) {
if (details.answers[1]) {
editableCell.textContent = details.answers[1].display_value || '';
@@ -1116,14 +1148,30 @@ function addSuggestionsToTable() {
if (key.startsWith('special_condition')) {
- if(policy_terms['special_condition_label']){
- editableCell.textContent = policy_terms['special_condition_label'][special_condition_index] + ' - ' + policy_terms['special_condition_input'][special_condition_index];
- inputBox.value = policy_terms['special_condition_label'][special_condition_index] + '--' + policy_terms['special_condition_input'][special_condition_index];
- special_condition_index++
+ if(policy_terms.hasOwnProperty('special_condition_label')){
+
+ if(policy_terms['special_condition_label'] != "" && Array.isArray(policy_terms['special_condition_label'])){
+ editableCell.textContent = policy_terms['special_condition_label'][special_condition_index] + ' - ' + policy_terms['special_condition_input'][special_condition_index];
+ inputBox.value = policy_terms['special_condition_label'][special_condition_index] + '--' + policy_terms['special_condition_input'][special_condition_index];
+ special_condition_index++
+ }else{
+ editableCell.textContent = ""
+ inputBox.value = "";
+ special_condition_index++
+ }
+
}else{
- editableCell.textContent = policy_terms['gpa_special_condition_label'][special_condition_index] + ' - ' + policy_terms['gpa_special_condition_input'][special_condition_index];
- inputBox.value = policy_terms['gpa_special_condition_label'][special_condition_index] + '--' + policy_terms['gpa_special_condition_input'][special_condition_index];
- special_condition_index++
+
+
+ if(policy_terms['gpa_special_condition_label'] != "" && Array.isArray(policy_terms['gpa_special_condition_label'])){
+ editableCell.textContent = policy_terms['gpa_special_condition_label'][special_condition_index] + ' - ' + policy_terms['gpa_special_condition_input'][special_condition_index];
+ inputBox.value = policy_terms['gpa_special_condition_label'][special_condition_index] + '--' + policy_terms['gpa_special_condition_input'][special_condition_index];
+ special_condition_index++
+ }else{
+ editableCell.textContent = ""
+ inputBox.value = "";
+ special_condition_index++
+ }
}
}
@@ -1216,9 +1264,11 @@ addQuoteButton.addEventListener('click', function() {
const secondLastCellValue = headerRow.cells[lastCellIndex - 1].textContent.trim();
// Split the second last cell's value and get the last part
- const lastPart = secondLastCellValue.split(" ")[1]?.trim();
+ const lastPart = secondLastCellValue?.split(" ")[1]?.trim() ?? "0";
+
+ // Check if lastPart is a valid number; if not, default to 0
+ const proposalNumber = isNaN(Number(lastPart)) ? 0 : Number(lastPart);
- const proposalNumber = Number(lastPart);
console.log("proposalNumber:", proposalNumber);
@@ -1336,6 +1386,7 @@ function showSuggestions(input) {
function showAnswersSuggestions(input) {
console.log(input.parentElement.id);
+ console.log(input);
//return;
var questionItem = input.parentElement.id;
@@ -1451,11 +1502,16 @@ document.addEventListener('click', function(e) {
}
if (e.target.classList.contains('editablecolumns')) {
+
// console.log(e.target.innerText);
// if(e.target.innerText == '')
// {
- showAnswersSuggestions(e.target);
+ // showAnswersSuggestions(e.target);
// }
+
+ if (e.target.isContentEditable) {
+ showAnswersSuggestions(e.target);
+ }
}
//hide currently showing any three dotted menu
@@ -4136,8 +4192,6 @@ function jsonToTable(json) {
// Add subheaders, hiding those under "Item Key"
header.subHeaders.forEach((subHeader, index) => {
-
-
const subTh = document.createElement('th');
// Hide if parent header is "Item Key"
@@ -4294,15 +4348,28 @@ function jsonToTable(json) {
td.innerText = dataEntry.value || '';
if(!["Sno", "Item Key", "Particulars", "Action"].includes(dataEntry.parentth)){
- insurerCountForDisableQuoteAsked = proposels[dataEntry.parentth]['insurers'].length
+ const insurers = proposels[dataEntry?.parentth]?.insurers;
+ insurerCountForDisableQuoteAsked = insurers?.length ?? 0;
}
- if(dataEntry.subth === "Quote Asked" && insurerCountForDisableQuoteAsked > 0){
- td.contentEditable = false;
- td.classList.add('readonly-select');
+ if(RFQ_or_QCR == 1){
+ //if the page is RFQ than check the insurer after disable the quote asked
+ if(dataEntry.subth === "Quote Asked" && insurerCountForDisableQuoteAsked > 0){
+ td.contentEditable = false;
+ td.classList.add('readonly-select');
+ }else{
+ td.contentEditable = true;
+ td.classList.add('editablecolumns');
+ }
}else{
- td.contentEditable = true;
- td.classList.add('editablecolumns');
+ //if the page is QCR than disable the quote asked default
+ if(dataEntry.subth === "Quote Asked"){
+ td.contentEditable = false;
+ td.classList.add('readonly-select');
+ }else{
+ td.contentEditable = true;
+ td.classList.add('editablecolumns');
+ }
}
// end of hide QUOTE ASKED if insurer exist
@@ -4366,11 +4433,12 @@ function jsonToTable(json) {
hideQCR()
isFormDataModified = false;
- // if(RFQ_or_QCR == 2){
+ if(RFQ_or_QCR == 2){
populateTable(json)
- // }
+ }
}
+//Premium Calculation child table
function populateTable(json) {
console.log(json);
@@ -4382,6 +4450,7 @@ function populateTable(json) {
const headerRow1 = document.createElement("tr");
const headerRow2 = document.createElement("tr");
+ var proposels = json.proposal_data.over_all_column_data;
// Iterate over the headers to create thead
json.table_data.headers.forEach(header => {
@@ -4415,6 +4484,14 @@ function populateTable(json) {
th.setAttribute("rowspan", 2); // No subheaders, span both rows
}
+ if (RFQ_or_QCR == 2) {
+ if (proposels[header.parentHeader] && proposels[header.parentHeader].qcr !== undefined) {
+ if (proposels[header.parentHeader].qcr == 0 || proposels[header.parentHeader].qcr == false) {
+ th.classList.add('hidden');
+ }
+ }
+ }
+
headerRow1.appendChild(th);
// Create and append subheaders to the second row
@@ -4433,6 +4510,15 @@ function populateTable(json) {
if(header.parentHeader != "Particulars" && header.parentHeader !== 'Sno'){
subTh.style.backgroundColor = randomColor;
}
+
+ //for QCR hidden fields
+ if(RFQ_or_QCR == 2){
+ if (proposels[header.parentHeader] && proposels[header.parentHeader].qcr !== undefined) {
+ if(proposels[header.parentHeader].qcr == 0 || proposels[header.parentHeader].qcr == false){
+ subTh.classList.add('hidden')
+ }
+ }
+ }
headerRow2.appendChild(subTh);
});
@@ -4473,12 +4559,28 @@ function populateTable(json) {
// if(value != '-'){
const td = document.createElement("td");
- td.setAttribute("contenteditable", "true");
- // td.classList.add('editablecolumnsforcalc')
+
+ if(label == "Total") {
+ console.log();
+ td.setAttribute("contenteditable", false);
+ td.classList.add('readonly-select')
+ }else{
+ td.setAttribute("contenteditable", "true");
+ }
+
td.classList.add(
'editablecolumnsforcalc',
label.toLowerCase().replace(/\s+/g, '').replace(/[%₹()]/g, '')
);
+
+ if(RFQ_or_QCR == 2){
+ if (proposels[header.parentHeader] && proposels[header.parentHeader].qcr !== undefined) {
+ if(proposels[header.parentHeader].qcr == 0 || proposels[header.parentHeader].qcr == false){
+ td.classList.add('hidden')
+ }
+ }
+ }
+
// td.id = `${label.toLowerCase()}`;
td.textContent = json.premium_data?.data?.[header.parentHeader]?.[value]?.[label] || "";
tr.appendChild(td);
@@ -4588,12 +4690,12 @@ function generateJSONFromTable() {
function addInsurerDataForPremiumTable(event, insurerName, proposal_name) {
- console.log('########################################################################')
+ console.log('##################### ADD INSURER ###################################################')
const closestTh = event.target.closest('th');
let colIndex = closestTh.cellIndex;
console.log('column index of second table', colIndex);
- colIndex = colIndex -2
+ colIndex = colIndex -1
console.log('column index of second table', colIndex);
let rfqTable = document.getElementById('rfqTable_for_calc');
@@ -4613,8 +4715,10 @@ function addInsurerDataForPremiumTable(event, insurerName, proposal_name) {
// Determine the position for inserting the column
let insertPosition = totalColspan; // Default to inserting at the end of the current insurer's columns
+ const rowLabels = ["Premium", "GST (%)", "GST Amount (₹)", "Total"];
// Add a new column to each row
+ let labelIncrement = 0
for (let i = 1; i < rfqTable.rows.length; i++) {
if (i === 1) {
const newHeaderCell = document.createElement('th');
@@ -4623,13 +4727,27 @@ function addInsurerDataForPremiumTable(event, insurerName, proposal_name) {
rfqTable.rows[i].insertBefore(newHeaderCell, rfqTable.rows[i].cells[insertPosition]);
} else {
const newCell = rfqTable.rows[i].insertCell(insertPosition);
- newCell.setAttribute('contenteditable', 'true');
+
+ if(rowLabels[labelIncrement] == "Total") {
+ console.log();
+ newCell.setAttribute("contenteditable", false);
+ newCell.classList.add('readonly-select')
+ }else{
+ newCell.setAttribute("contenteditable", "true");
+ }
+ newCell.classList.add(
+ 'editablecolumnsforcalc',
+ rowLabels[labelIncrement].toLowerCase().replace(/\s+/g, '').replace(/[%₹()]/g, '')
+ );
+
// newCell.classList.add('editablecolumns');
newCell.innerHTML = rfqTable.rows[i].cells[columnIndextoCopyData].innerHTML;
- newCell.style.backgroundColor = parentTh.style.backgroundColor;
+ // newCell.style.backgroundColor = parentTh.style.backgroundColor;
+ labelIncrement++
}
}
+ labelIncrement = 0
isFormDataModified = true; // if any value changeing in the table to set true
console.log('########################################################################')
@@ -4638,13 +4756,15 @@ function addInsurerDataForPremiumTable(event, insurerName, proposal_name) {
function copyInsurerDataForPremiumTable(event, insurerName){
+ console.log('########## COPPY INSURER ##############')
+
const thPosition = getThPosition(event);
let parentThIndex = null;
const closestTh = event.target.closest('th');
let colIndex = closestTh.cellIndex;
console.log('colIndex', colIndex);
- colIndex = colIndex - 2;
+ colIndex = colIndex - 1;
let columnText = closestTh.innerText;
let proposal_name = columnText.split('⋮')[0].trim();
let rfqTable = document.getElementById('rfqTable_for_calc');
@@ -4696,6 +4816,8 @@ function copyInsurerDataForPremiumTable(event, insurerName){
// add colspan of current th
let parentTh = rfqTable.querySelector('thead tr th:nth-child(' + (parentThIndex + 1) + ')');
parentTh.colSpan += 1;
+
+ let labelIncrement = 0;
// Add a new column to each row
for (let i = 1; i < rfqTable.rows.length; i++) {
@@ -4711,19 +4833,34 @@ function copyInsurerDataForPremiumTable(event, insurerName){
} else {
const newCell = rfqTable.rows[i].insertCell(totalColspan);
- newCell.setAttribute('contenteditable', 'true');
+
+ if(rowLabels[labelIncrement] == "Total") {
+ console.log();
+ newCell.setAttribute("contenteditable", false);
+ newCell.classList.add('readonly-select')
+ }else{
+ newCell.setAttribute("contenteditable", "true");
+ }
+ newCell.classList.add(
+ 'editablecolumnsforcalc',
+ rowLabels[labelIncrement].toLowerCase().replace(/\s+/g, '').replace(/[%₹()]/g, '')
+ );
+
+ // newCell.setAttribute('contenteditable', 'true');
newCell.innerHTML = rfqTable.rows[i].cells[colIndex].innerHTML;
- newCell.style.backgroundColor = parentTh.style.backgroundColor;
+ // newCell.style.backgroundColor = parentTh.style.backgroundColor;
+ labelIncrement++
}
}
+ labelIncrement = 0
}
function changeInsurerForPremiumTable(event, newInsurerName, secondRowIndex) {
const table = document.getElementById('rfqTable_for_calc');
const headerRows = table.querySelectorAll('thead tr');
- secondRowIndex = secondRowIndex - 2
+ secondRowIndex = secondRowIndex - 1
const secondRow = headerRows[1];
const thElements = secondRow.querySelectorAll('th');
const closestTh = thElements[secondRowIndex];
@@ -4755,7 +4892,7 @@ function removeInsurerFromPremiumTable(event, secondRowIndex) {
console.log('insurerName', insurerName);
// let subThIndex = closestTh.cellIndex;
// console.log('subThIndex', subThIndex);
- subThIndex = secondRowIndex - 2
+ subThIndex = secondRowIndex - 1
console.log('subThIndex', subThIndex);
// Get the sub TH from the second header row
@@ -4806,7 +4943,7 @@ function removeInsurerFromPremiumTable(event, secondRowIndex) {
function removeProposalForPremiumTable(secondRowIndex) {
- let colIndex = secondRowIndex - 2;
+ let colIndex = secondRowIndex - 1;
console.log('colIndex', colIndex);
const rfqPremiumTable = document.getElementById('rfqTable_for_calc');
@@ -4919,6 +5056,14 @@ function autoCaluculationForPremiumChildTable(input) {
const row = input.closest('tr');
console.log('row', row);
+ const hasPremiumClass = input.classList.contains('premium');
+ const hasGstClass = input.classList.contains('gst');
+ const hasGstAmtClass = input.classList.contains('gstamount');
+
+ console.log('hasPremiumClass', hasPremiumClass);
+ console.log('hasGstClass', hasGstClass);
+
+
// Find the index of the input td
const tdIndex = Array.from(row.children).indexOf(input);
console.log('tdIndex', tdIndex);
@@ -4930,22 +5075,43 @@ function autoCaluculationForPremiumChildTable(input) {
// Extract values from the corresponding cells in each row
const premium = Number(rows[0].children[tdIndex]?.textContent.trim()) || 0;
const gst = Number(rows[1].children[tdIndex]?.textContent.trim()) || 0;
+ const gstAmt = Number(rows[2].children[tdIndex]?.textContent.trim()) || 0;
console.log('premium', premium);
console.log('gst', gst);
+
// Calculate GST Amount and Total
- const gstAmount = (premium * gst) / 100;
- const total = premium + gstAmount;
+ if(hasPremiumClass || hasGstClass){
- console.log('Calculated GST Amount:', gstAmount.toFixed(2));
- console.log('Calculated Total Amount:', total.toFixed(2));
+ const gstAmount = (premium * gst) / 100;
+ const total = premium + gstAmount;
- // Update GST Amount row
- rows[2].children[tdIndex].textContent = gstAmount.toFixed(2);
+ console.log('Calculated GST Amount:', gstAmount.toFixed(2));
+ console.log('Calculated Total Amount:', total.toFixed(2));
- // Update Total row
- rows[3].children[tdIndex].textContent = total.toFixed(2);
+ // Update GST Amount row
+ rows[2].children[tdIndex].textContent = gstAmount.toFixed(2);
+
+ // Update Total row
+ rows[3].children[tdIndex].textContent = total.toFixed(2);
+
+ }else if (hasGstAmtClass){
+
+ // Calculate GST percentage based on GST amount and premium
+ const gstPercent = premium > 0 ? (gstAmt / premium) * 100 : 0;
+ const total = premium + gstAmt;
+
+ console.log('Calculated GST Percentage:', gstPercent.toFixed(2));
+ console.log('Calculated Total Amount:', total.toFixed(2));
+
+ // Update GST row with calculated GST percentage
+ rows[1].children[tdIndex].textContent = gstPercent.toFixed(2);
+
+ // Update Total row
+ rows[3].children[tdIndex].textContent = total.toFixed(2);
+
+ }
}
@@ -5101,7 +5267,7 @@ function autoCaluculationForPremiumChildTable(input) {
const table = document.getElementById('rfqTable');
let premium_data = '';
- if(jsonDataForHide){
+ if(RFQ_or_QCR == 2){
premium_data = generateJSONFromTable();
console.log('save premium data', premium_data);
}