FEAT_RFQ_NONEB_PRE_FINAL

This commit is contained in:
Srinivas-Saravanan 2025-03-22 07:07:11 +05:30
parent b313309e00
commit 89db5cf085
6 changed files with 1267 additions and 853 deletions

View File

@ -404,6 +404,7 @@ $routes->group("leads", ["filter" => "authMVC"], function ($routes) {
$routes->group("rfq", ["filter" => "authMVC"], function ($routes) {
$routes->post("create", "LeadsController::createRFQ");
$routes->post("savePolicyInfo", "LeadsController::savePolicyInfo");
$routes->post("createQCR", "LeadsController::createQCR");
$routes->get("list/(:any)", "LeadsController::viewRFQ/$1");
$routes->get("nonEB","LeadsController::rfqNonEB");

View File

@ -28,6 +28,7 @@ use App\Models\InsurerBranchModel;
use App\Models\TPABranchModel;
use App\Models\RFQModel;
use App\Models\InsurerModel;
use App\Models\OccupancyMasterModel;
use App\Helpers\MailHelper;
use App\Helpers\ExcelMergeHelper;
@ -60,6 +61,7 @@ class LeadsController extends BaseController
protected $tpaBranchModel;
protected $RFQModel;
protected $insurerModel;
protected $occupancyModel;
//variables for storing array
protected $issuer;
@ -68,6 +70,7 @@ class LeadsController extends BaseController
protected $leadsStatus;
protected $claim_type_for_gpa;
protected $cause_of_death;
protected $buisnessType;
public function __construct()
@ -88,10 +91,12 @@ class LeadsController extends BaseController
$this->tpaBranchModel = new TPABranchModel();
$this->RFQModel = new RFQModel();
$this->insurerModel = new InsurerModel();
$this->occupancyModel = new OccupancyMasterModel();
$this->issuer = [1 => 'JIBS', 2 => 'Nhance'];
$this->clientType = [1 => 'Group', 2 => 'Individual'];
$this->leadType = [1 => 'Fresh', 2 => 'Renewal', 3 => 'Roll Over'];
$this->buisnessType = [1 => 'Industrial', 2 => 'Non Industrial'];
$this->leadsStatus = [
'queued' => 'Queued',
'qcr_sent' => 'QCR sent',
@ -113,7 +118,6 @@ class LeadsController extends BaseController
'suicide' => 'Suicide',
'accident' => 'Accident'
];
}
public function viewLeadsList()
@ -213,7 +217,6 @@ class LeadsController extends BaseController
// Separate the insurer and insurer branch, handle missing or invalid data
if (isset($data['insurer']) && strpos($data['insurer'], '-') !== false) {
list($insurer_branch_id, $insurer_id) = explode('-', $data['insurer']);
} else {
$insurer_branch_id = 0;
$insurer_id = 0;
@ -269,7 +272,6 @@ class LeadsController extends BaseController
// Separate the insurer and insurer branch, handle missing or invalid data
if (isset($data['insurer'][$index]) && strpos($data['insurer'][$index], '-') !== false) {
list($insurer_branch_id, $insurer_id) = explode('-', $data['insurer'][$index]);
} else {
$insurer_branch_id = 0;
$insurer_id = 0;
@ -578,18 +580,49 @@ class LeadsController extends BaseController
if ($data['lead_data']['lead_form_type'] == 1) {
$this->loadLayout('view_rfq.php', $data);
} else if ($data['lead_data']['lead_form_type'] == 2) {
$data['occupancy'] = $this->occupancyModel->findAll();
// dd($data['occupancy']);
$data['policies'] = json_decode($data['question_json'], true)['policies'];
$data["child_table_data"] = json_decode($data['question_json'], true)['child_table_data'];
// $data['lead_register_data'] = json_decode($data['lead_data']['custom_fields']);
// dd($data['lead_register_data']);
$data['client_type'] = $this->clientType;
$data['buisness_type'] = $this->buisnessType;
$this->loadLayout('view_rfq_non_eb', $data);
}
}
public function savePolicyInfo()
{
$data = $this->request->getPost();
$lead_id = $data['lead_id'];
$json_data = $data['registration_json'];
$existingJson = $this->RFQModel->where('is_active', 1)->where("lead_id", $lead_id)->first()['registration_json'] ?? null;
if (empty($existingJson)) {
$this->RFQModel
->where('lead_id', $lead_id)
->where('type', 1)
->where('is_active', 1)
->set('is_active', 0)
->update();
$insertData['lead_id'] = $lead_id;
$insertData['registration_json'] = json_encode($json_data);
$this->RFQModel->insert($insertData);
return $this->respond(['status' => true, "message" => "Policy Inforamtion saved"]);
} else {
return $this->respond(['status' => true, "message" => "Policy Inforamtion Already saved"]);
}
}
@ -608,12 +641,37 @@ class LeadsController extends BaseController
->set('is_active', 0)
->update();
$registrationJson = $data['registration_json'] ?? null; // Use null coalescing operator for safety
if ($registrationJson) {
// If registration_json is provided, insert the data directly
$result = $this->RFQModel->insert($data);
} else {
// If registration_json is not provided, fetch the latest registration_json from the database
$this->RFQModel->select('registration_json')
->where("lead_id", $lead_id)
->order_by('id', 'DESC') // Assuming 'id' is an auto-increment field
->limit(1);
$query = $this->RFQModel->get();
$latestRegistrationJson = $query->row()->registration_json ?? null;
if ($latestRegistrationJson) {
// If a valid registration_json is found, update the data and insert
$data['registration_json'] = $latestRegistrationJson;
$result = $this->RFQModel->insert($data);
} else {
// If no registration_json is found, insert the data as-is
$result = $this->RFQModel->insert($data);
}
}
if ($result) {
$message = "RFQ submitted successfully";
if($data['submit_type'] == 'QCR'){ $message = "QCR submitted successfully"; }
if ($data['submit_type'] == 'QCR') {
$message = "QCR submitted successfully";
}
return $this->respond(['status' => true, 'id' => $result, 'message' => $message, 'data' => $data], 200);
}
@ -1530,7 +1588,6 @@ class LeadsController extends BaseController
];
return $response;
} catch (Exception $e) {
return [
'success' => false,
@ -2047,7 +2104,6 @@ class LeadsController extends BaseController
$proposal['insurers'] = array_values($proposal['insurers']);
return $proposal;
}, $first_json['proposal_data']['over_all_column_data']);
} else {
//remove insurer as Subheaders for RFQ
@ -2085,7 +2141,6 @@ class LeadsController extends BaseController
// Ensure to reset the reference
unset($proposal);
}
return $first_json;
@ -2366,7 +2421,6 @@ class LeadsController extends BaseController
$message = str_replace("{{POLICY_YEAR}}", $policy_year, $message);
return $message;
} else {
return ''; // Return empty if no lead data found
}
@ -2525,7 +2579,6 @@ class LeadsController extends BaseController
$data['lead_edit_data']['policy_type_id'] ?? null,
$data
) ?? "";
}
if ($data['lead_edit_data']['lead_type'] != 1 && $data['lead_edit_data']['lead_form_type'] == 2) {
@ -2552,7 +2605,6 @@ class LeadsController extends BaseController
} else {
return $this->respond(['status' => false, 'code' => 400, 'message' => 'Fields not found for this policy type'], 200);
}
}
public function generateViewPageHtml($policy_type_id, $data = [])
@ -2561,13 +2613,28 @@ class LeadsController extends BaseController
$data['tpa'] = $this->tpaBranchModel->getTpaBranchesWithTpaNames();
$viewMap = [
1 => 'rfq/gpa', 6 => 'rfq/gpa', 7 => 'rfq/gpa',
2 => 'rfq/gmc', 3 => 'rfq/gmc', 4 => 'rfq/gmc', 5 => 'rfq/gmc',
22 => 'rfq/car', 23 => 'rfq/cpm', 24 => 'rfq/cyber_crime',
25 => 'rfq/do', 27 => 'rfq/eo', 49 => 'rfq/money',
19 => 'rfq/cgl', 59 => 'rfq/sfsp', 63 => 'rfq/wc',
15 => 'rfq/blu', 16 => 'rfq/bsu',
44 => 'rfq/marine', 45 => 'rfq/marine', 46 => 'rfq/marine', 47 => 'rfq/marine',
1 => 'rfq/gpa',
6 => 'rfq/gpa',
7 => 'rfq/gpa',
2 => 'rfq/gmc',
3 => 'rfq/gmc',
4 => 'rfq/gmc',
5 => 'rfq/gmc',
22 => 'rfq/car',
23 => 'rfq/cpm',
24 => 'rfq/cyber_crime',
25 => 'rfq/do',
27 => 'rfq/eo',
49 => 'rfq/money',
19 => 'rfq/cgl',
59 => 'rfq/sfsp',
63 => 'rfq/wc',
15 => 'rfq/blu',
16 => 'rfq/bsu',
44 => 'rfq/marine',
45 => 'rfq/marine',
46 => 'rfq/marine',
47 => 'rfq/marine',
50 => 'rfq/office'
];
@ -2988,7 +3055,6 @@ class LeadsController extends BaseController
$proposal['insurers'] = array_values($proposal['insurers']);
return $proposal;
}, $first_json['proposal_data']['over_all_column_data']);
} else {
//remove insurer as Subheaders for RFQ
@ -3028,7 +3094,6 @@ class LeadsController extends BaseController
// Ensure to reset the reference
unset($proposal);
}
return $first_json;

View File

@ -0,0 +1,22 @@
<?php
namespace App\Models;
use CodeIgniter\Model;
class OccupancyMasterModel extends Model
{
protected $table = 'occupancy_master';
protected $allowedFields = [
'id',
'iib_code',
'section',
'description',
'iib_loss_rate',
'created_by',
'created_at',
'is_active'
];
}

View File

@ -17,6 +17,7 @@ class RFQModel extends Model
'type',
'lead_id',
'json',
"registration_json",
'created_at',
'created_by',
'updated_at',

File diff suppressed because it is too large Load Diff

View File

@ -403,11 +403,18 @@
}
};
var suggestions = {};
var storedData = JSON.parse(localStorage.getItem('policyData'));
var policySummary;
if (!$.isEmptyObject(storedData)) {
policySummary = addPolicySummaryTable(storedData);
var policyInformationData = <?= isset($rfq_data['registration_json']) ? json_encode($rfq_data['registration_json'], JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT) : '""' ?>;
var storedData = {};
console.log("stored data : ", typeof(policyInformationData))
if (policyInformationData.length) {
localStorage.setItem('policyData', (policyInformationData));
storedData = policyInformationData;
}
var policySummary = [];
console.log("policy summary is set :", !$.isEmptyObject(policySummary) ? "no" : "yes")
$(document).ready(function() {
myModal = new bootstrap.Modal(document.getElementById('policyRegisterModel'));
@ -482,37 +489,7 @@
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) {
@ -722,6 +699,7 @@
// console.log('Row id for excess table',rowId);
$("#excess .three-dot-menu").hide();
moveExcessTableLast();
}
} else {
// Handle regular table
@ -729,6 +707,9 @@
generateTable(childContainer, true, rowId, childTable);
// console.log('Row id for excess table', rowId);
$(childContainer).find(".three-dot-menu").hide();
// alert(`${rowId.toUpperCase()}_register`);
$(`#${rowId.toUpperCase()}_register`).prop("disabled", false);
moveExcessTableLast();
}
});
@ -738,7 +719,10 @@
container.appendChild(childContainer);
}
arrangeTables();
alignTableColumn();
} else {
console.log('UNCHECKED:', rowId);
selectedPolicies.delete(rowId);
@ -747,6 +731,7 @@
regularContainers.forEach(container => {
console.log(" contaitner ", container);
$(`#${rowId.toUpperCase()}_register`).prop("disabled", true);
container.remove();
});
console.log("row id ", rowId);
@ -1134,6 +1119,10 @@
${newQuote}
<span class="three-dot-menu" onclick="showDropdown(event)">&#8942;</span>
<div class="dropdown-content">
<button id = "isInsurerSTC" class="sendInsurerClientProposal" onclick = "addOrRemoveIconInsurer(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="changeInsurer(event, ${proposalNumber}, '${newQuote}')">Change Insurer</button>
<button onclick="removeQuote(event, ${proposalNumber}, '${newQuote}')">Remove Quote</button>
</div>
@ -1183,7 +1172,7 @@
const headerRow1 = document.createElement('tr');
headerRow1.innerHTML =
`
${isChildTable ? '<th>S.NO</th>' : '<th><input type="checkbox"></th>'}
${isChildTable ? '<th>S.NO</th>' : '<th>Policy</th>'}
<th>${tableName}</th>
${Object.keys(quotesConfig).map(proposal => `
<th data-proposal="${proposal}" colspan="${quotesConfig[proposal].length}">
@ -1210,13 +1199,15 @@
<th>-</th>
${Object.entries(quotesConfig).flatMap(([proposal, codes]) =>
codes.map(code => `
<th data-proposal="${proposal}" data-quote="${code}">
<th data-proposal="${proposal}" data-quote="${code}"
class="${code !== 'Quote asked' ? 'insurer_proposal' : ''}">
${code}
<span class="three-dot-menu" onclick="showDropdown(event)">&#8942;</span>
<div class="dropdown-content">
<button onclick="removeQuote(event, ${proposal}, '${code}')">Remove Quote</button>
</div>
</th>
`)
).join('')}
<th>-</th>`;
@ -1258,7 +1249,7 @@
<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>` :
`<br><button id = '${policy.name.toUpperCase()}_register' class = "btn btn-primary btn-sm" onclick = "getPolicyInfo('${policy.name}')" class="policy-link" data-policy-name="${policy.name}" disabled>Register</button>` :
''}
</td>
<td contenteditable="true">${desc}</td>
@ -1299,13 +1290,14 @@
suggestions[rowID] = row_fields[rowID].answer_type;
if (answer_type == 'dropdown') {
default_answers_array = row_fields[rowID].default_answer;
console.log("default ans array : ", typeof(default_answers_array))
// 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("default ans array else: ", default_answers_array)
// console.log("defaultansetgoa : ",default_answers_array);
default_value = default_answers_array;
default_answer = default_answers_array;
@ -1321,15 +1313,43 @@
${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>`
? `<br><button id = '${policy.name.toUpperCase()}_register' class = "btn btn-primary btn-sm" onclick = "getPolicyInfo('${policy.name}')" class="policy-link" data-policy-name="${policy.name}" disabled>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>`)
codes.map((_, colIndex) => {
// Get the subheader (assuming it's the second <tr> inside <thead>)
let subHeaderTh = document.querySelector(`thead tr:nth-child(2) th:nth-child(${colIndex + 1})`);
let subHeaderText = subHeaderTh ? subHeaderTh.textContent.trim() : '';
// Check if subheader is NOT "Quote asked"
let className = subHeaderText !== "Quote asked" && subHeaderText != "-" ? "insurer_proposal" : "";
let defaultJsonString = typeof default_answers_array == "object" ? JSON.stringify(default_answers_array[0]) : String(default_answers_array);
// console.log("defaultJsonString", defaultJsonString);
// console.log("defaultJsonString type", typeof defaultJsonString);
// console.log("defaultJsonString string", String(defaultJsonString));
return `<td class="${className}" 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='${defaultJsonString}' />`
)
: policy.quote_asked
}
</td>`;
})
).join('')}
<td>
${isChildTable ? `
<input id = "qcrCheckbox" name = "qcr" checked type="checkbox" class="qcr-checkbox"> <label for = "qcrCheckbox">QCR</label>
@ -1474,6 +1494,23 @@
console.log("inside if conditoon");
localStorage.setItem('allTablesJsonData', JSON.stringify(rfq_data));
jsonToTables();
if (!$.isEmptyObject(storedData)) {
console.log("DATA FROM DB : ", JSON.parse(storedData));
let data = JSON.parse(storedData);
Object.keys(data).forEach(key => {
policySummary[key] = addPolicySummaryTable(data[key], key);
prependTable(policySummary[key],key);
});
// console.log("policy summary : ",child_table_data[key])
console.log("generate policy summary : ", policySummary);
}
// generateTable(document.getElementById('tablesContainer'));
// console.log("polices Length ", policies.length);
@ -1783,18 +1820,37 @@
function getPolicyInfo(policyName) {
console.log("anchor link clicked ", policyName);
if (!myModal) {
myModal = new bootstrap.Modal(document.getElementById('policyRegisterModel'));
console.log("inside if condition");
}
var leadID = $("#lead_id").val();
$("#policyName").val(policyName);
$("#leadID").val(leadID);
$("#multilocation_type_div").hide();
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
// Add 'show active' to the 'product-selection' tab
$("#policy_register_forms .tab-pane.show.active").removeClass("active show");
// Add 'show active' to the 'product-selection' tab
$("#product-selection").addClass("active show");
hideAndShowBurglary();
storedPolicyData = JSON.parse(localStorage.getItem('policyData'));
if (!$.isEmptyObject(storedPolicyData)) {
// alert("not empty");
prepareDataForEdit(storedPolicyData);
}
myModal.show();
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
}
function addPolicySummaryTable(storedData) {
function addPolicySummaryTable(storedData, policyName) {
// alert(policyName);
var locationCount = storedData.locations.length;
var tableRowContent = [];
@ -1804,7 +1860,7 @@
tableRowContent.push({
table_type: "new",
table_id: "fire_summary_" + locationIndex,
table_id: `${policyName}_summary_` + locationIndex,
table_editable: true,
table_name: "Risk Location " + locationIndex + "- " +
storedData.locations[i].policyRisk['occupancy'] + "- " +
@ -1914,15 +1970,17 @@
console.log("save button clicked");
leadJson = tablesToJson();
console.log("json from function ", leadJson);
saveRFQTODB(leadJson);
var policyJson = localStorage.getItem("policyData") ?? null;
saveRFQTODB(leadJson, policyJson);
}
function saveRFQTODB(tableJSON) {
function saveRFQTODB(tableJSON, policyJson) {
var formData = {
lead_id: $("#lead_id").val(),
json: JSON.stringify(tableJSON),
submit_type: "RFQ"
submit_type: "RFQ",
registration_json: policyJson
}
var url = '<?= base_url('rfq/create') ?>';
@ -1935,6 +1993,8 @@
method: "POST",
success: function(response) {
if (response.status == true) {
localStorage.removeItem('policyData');
toastr.success(response.message, "Success");
// window.location.reload();
} else {
@ -1942,7 +2002,7 @@
}
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
// window.location.reload();
window.location.reload();
},
error: function(xhr, status, error) {
$('.loader').fadeOut();
@ -1955,8 +2015,6 @@
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] = {
@ -1965,7 +2023,6 @@
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;
@ -1975,13 +2032,25 @@
}
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,
if (typeof insurer === 'object' && insurer.id) {
let stcInsurerSelected = false;
const insurerHeaders = document.querySelectorAll(`th[data-quote="${insurer.insurerName}"]`);
insurerHeaders.forEach(header => {
const headerProposalCount = header.getAttribute("data-proposal");
if (headerProposalCount == proposalNumber) {
console.log("Found the subheader we are searching");
if (header.querySelector('.sendInsurerClientProposal .fa-check-square') !== null) {
stcInsurerSelected = true;
}
console.log("STC selected for insurer:", stcInsurerSelected);
}
});
uniqueInsurers.push({
ins_name: insurer.insurerName,
qcr: 1,
stc: rfq_or_qcr == 1 ? 1 : stcInsurerSelected ? 1 : 0,
display_name: insurer.insurerName,
id: insurer.id
});
@ -1994,6 +2063,7 @@
return overAllData;
}
function getTextExcludingButton(cell) {
return Array.from(cell.childNodes)
.filter(node => node.nodeType === Node.TEXT_NODE) // Get only text nodes
@ -2039,7 +2109,7 @@
const headerHTML = header.innerHTML;
const headerText = headerHTML.replace(/<span class="three-dot-menu"[\s\S]*?<\/div>/g, '').trim();
console.log("processing sub header array : ", subHeaderArray);
console.log("HEader : ", headerText);
console.log("HEader : ", header.innerText == " " ? header.innerText.trim() : headerText);
headers.push({
// parentHeader: header.innerText.replace('⋮', '').split('\n')[0].replace(/:.*/, '').trim(),
parentHeader: headerText,
@ -2242,6 +2312,17 @@
// child_table_data[rowData.rowID]
}
function getTotalCount(proposalDataArray) {
let proposals = proposalDataArray.proposal_data.over_all_column_data;
let proposalCount = Object.keys(proposals).length; // Count proposals
let insurerCount = Object.values(proposals).reduce((sum, proposal) => {
return sum + (proposal.insurers ? proposal.insurers.length : 0);
}, 0); // Count insurers across all proposals
return proposalCount + insurerCount;
}
function jsonToTables() {
@ -2270,7 +2351,15 @@
console.log("proposal count : ", proposalCount);
console.log("proposal count quotes config ... : ", proposalDataArray.proposal_data.over_all_column_data);
var totalCount = getTotalCount(proposalDataArray);
let increaseBy = proposalCount * 150;
if (rfq_or_qcr == 1) {
console.log("inside if ")
increaseBy = proposalCount * 150;
} else if (rfq_or_qcr == 2) {
increaseBy = totalCount * 150;
}
console.log("trying to find checkbox data : : : ", increaseBy);
@ -2400,6 +2489,7 @@
const headerRow1 = document.createElement('tr');
const headerRow2 = document.createElement('tr');
var overallColumnDataProposal = proposal_data.proposal_data.over_all_column_data;
var matchedKey = "";
headers.forEach(header => {
// Parent header
const th1 = document.createElement('th');
@ -2408,7 +2498,7 @@
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));
matchedKey = Object.keys(overallColumnDataProposal).find(key => headerName.startsWith(key));
if (matchedKey) {
console.log("something wrong : ", overallColumnDataProposal[matchedKey]);
var headerCheckBoxProperties = overallColumnDataProposal[matchedKey];
@ -2441,14 +2531,22 @@
header.subHeaders.forEach(subHeader => {
const th2 = document.createElement('th');
if (header.parentHeader.startsWith("Proposal")) {
var insurers = overallColumnDataProposal[matchedKey].insurers;
const matchedInsurer = insurers.find(ins => ins.ins_name == subHeader);
if (subHeader != "Quote asked") {
console.log("trying to find something : ", matchedInsurer.stc);
console.log("this is the subheader : ", subHeader);
th2.classList.add("insurer_proposal");
th2.innerHTML = `
${subHeader}
<span class="three-dot-menu">&#8942;</span>
<div class="dropdown-content">
<button id = "isInsurerSTC" class="sendInsurerClientProposal" onclick = "addOrRemoveIconInsurer(this,event)"
style="background-color: rgb(221, 221, 221);">Send to Client ${matchedInsurer.stc == 1 ? `<i
class="fa fa-check-square"
style="color: green; margin-left: 8px; "></i>`: ""} </button>
<button onclick="changeInsurer(event, ${header.parentHeader.split(' ')[1]}, '${subHeader}')">Change Insurer</button>
<button onclick="removeQuote(event, ${header.parentHeader.split(' ')[1]}, '${subHeader}')">Remove Quote</button>
</div>
@ -2487,7 +2585,7 @@
}
// 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>`
? `<br><button id = '${cellData.SNO.toUpperCase()}_register' class = "btn btn-primary btn-sm" onclick = "getPolicyInfo('${cellData.SNO}')" class="policy-link" data-policy-name="${cellData.SNO}" ${value == "Checked" ? "" :"disabled"} >Register</a>`
: ""}`;
}
if (typeof value === 'string' && value.startsWith('{')) {
@ -2913,11 +3011,53 @@
});
});
}
function prependTable(policyJson,policyName) {
// alert("hi");
console.log("table to prepened : ", policyJson);
let parentDiv = document.querySelector(`div[data-parent-row=${policyName}]`);
// let newTable = document.createElement("table");
if (parentDiv){
let tables = Array.from(parentDiv.querySelectorAll("table"));
tables.forEach(table => {
if (table.id.includes("summary")) {
table.remove(); // Move summary table to the top
}
});
policyJson.slice().reverse().forEach(childTable => {
generateTable(parentDiv, true, policyName, childTable);
});
moveSummaryTableToTop(policyName);
}
}
function moveSummaryTableToTop(policyName) {
let parentDiv = document.querySelector(`div[data-parent-row="${policyName}"]`);
if (!parentDiv) return; // Exit if no such div exists
let tables = Array.from(parentDiv.querySelectorAll("table"));
tables.forEach(table => {
if (table.id.includes("summary")) {
parentDiv.prepend(table); // Move summary table to the top
}
});
}
</script>
<!-- Export Excel and Mail Script -->
<script>
var proposalDataForDropDown = {};
const editorConfig = {
@ -2989,10 +3129,10 @@
if (placementLeadData) {
placementLeadData = JSON.parse(placementLeadData);
let txt = 'The data has already been sent to the insurer '
+ placementLeadData.insurer_name
+ ' and the proposal is '
+ placementLeadData.proposel_name + '.';
let txt = 'The data has already been sent to the insurer ' +
placementLeadData.insurer_name +
' and the proposal is ' +
placementLeadData.proposel_name + '.';
$('#alert_msg').text(txt);
} else {
$('#alert_msg').text('');
@ -3594,4 +3734,24 @@
$("textarea.select2-search__field").css('resize', 'none');
})
function addOrRemoveIconInsurer(element, event) {
event.stopPropagation(); // Prevent event bubbling
// Find the button inside the dropdown (or use `element` directly)
const stcButton = element.closest('.dropdown-content') ?
element.closest('.dropdown-content').querySelector('.sendInsurerClientProposal') :
element;
// Check if the icon already exists
let icon = stcButton.querySelector("i.fa-check-square");
if (icon) {
// Remove the icon if it already exists
icon.remove();
} else {
// Create and append the check icon
createIcon(stcButton);
}
}
</script>