4346 lines
176 KiB
PHP
4346 lines
176 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;
|
||
}
|
||
|
||
.select2-selection__choice {
|
||
background-color: #0a8794 !important;
|
||
color: white !important;
|
||
font-weight: bold;
|
||
}
|
||
|
||
.select2-selection__choice__remove {
|
||
color: white !important;
|
||
margin-right: 5px;
|
||
}
|
||
</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 id="rfq_qcr_page_title">
|
||
<?= isset($page_name) ? htmlspecialchars($page_name, ENT_QUOTES, 'UTF-8') : 'RFQ Non-EB' ?>
|
||
</h4>
|
||
</div>
|
||
|
||
<div class="col-2" id="status_change" style="text-align: right; position: relative; top: 56px; left: 386px;">
|
||
<a onclick="checkTheTableDataChanged(1)" class="btn btn-primary">Back</a>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="row" style="margin-bottom: 1rem;margin-left: 0px;">
|
||
<button class="btn btn-custom rfqbtn" id="addProposal" style="margin-right: 10px;">Add New Proposal</button>
|
||
<button id="saveRFQ" onclick="saveRFQ()" class="btn btn-primary" style="margin-right: 10px;">Save RFQ</button>
|
||
<button id="openQCR" onclick="openQCR()" class="btn btn-primary rfqbtn" style="margin-right: 20px;">Proceed to QCR</button>
|
||
<a id="submitExcel" onclick="checkTheTableDataChanged(2)" class="btn btn-primary" style="margin-right: 10px;">Export Excel</a>
|
||
<button id="submitInternalMail" class="btn btn-primary" style="margin-right: 10px;" onclick="checkTheTableDataChanged(4)">Send Internal Mail</button>
|
||
<button id="submitMail" class="btn btn-primary" style="margin-right: 10px;" onclick="checkTheTableDataChanged(3)">Send Insurer Mail</button>
|
||
<button id="submitPlacement" class="btn btn-primary qcrbtn" onclick="checkTheTableDataChanged(6)">Placement</button>
|
||
</div>
|
||
|
||
|
||
<input type="hidden" id="lead_id" value="<?= htmlspecialchars($lead_data['id'] ?? "", ENT_QUOTES, 'UTF-8') ?>" />
|
||
|
||
<div id="allTableContainer">
|
||
<div id="tablesContainer"></div>
|
||
<?php include('policyRegisterModel.php'); ?>
|
||
<!-- <div id="excessContainer"></div> -->
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Modal content for Send Insurer and Client Mail -->
|
||
<div class="modal fade" id="list_model" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
|
||
aria-hidden="false">
|
||
<div class="modal-dialog modal-full-width">
|
||
<div class="modal-content">
|
||
<div class="modal-header">
|
||
<h4 class="modal-title" id="myCenterModalLabel"></h4>
|
||
<button type="button" id="close_btn" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||
</div>
|
||
<div class="modal-body">
|
||
<div class="form-group">
|
||
<div class="form-row" id="input_for_row">
|
||
</div>
|
||
</div>
|
||
|
||
<div class="form-group text-right m-b-0" id="hide_smbt_btn">
|
||
<button type="submit" class="btn btn-primary" onclick="constructURL(1)">Send Mail</button>
|
||
</div>
|
||
</div>
|
||
</div><!-- /.modal-content -->
|
||
</div>
|
||
</div><!-- /.modal -->
|
||
|
||
<!-- Modal content for Send Internal Mail -->
|
||
<div class="modal fade" id="internal_mail_modal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
|
||
aria-hidden="false">
|
||
<div class="modal-dialog modal-full-width">
|
||
<div class="modal-content">
|
||
<div class="modal-header">
|
||
<h4 class="modal-title" id="internal_mail_modal_label">Send Internal Mail</h4>
|
||
<button type="button" id="close_btn" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||
</div>
|
||
<div class="modal-body">
|
||
|
||
<div class="form-group">
|
||
|
||
<div class="form-row">
|
||
<div class="form-group col-md-4">
|
||
<label for="to">To </label>
|
||
<select class="form-control" id="to" name="to" required>
|
||
<?php if (isset($userList)) { ?>
|
||
<?php foreach ($userList as $user) { ?>
|
||
<option value="<?= $user['email'];?>">
|
||
<?= $user['first_name'].' - '.$user['email'];?>
|
||
</option>
|
||
<?php } ?>
|
||
<?php } ?>
|
||
</select>
|
||
</div>
|
||
|
||
<div class="form-group col-md-4">
|
||
<label for="cc">CC </label>
|
||
<select class="form-control" id="cc" name="cc" required multiple>
|
||
<?php if (isset($userList)) { ?>
|
||
<?php foreach ($userList as $user) { ?>
|
||
<option value="<?= $user['id'];?>">
|
||
<?= $user['first_name'].' - '.$user['email'];?>
|
||
</option>
|
||
<?php } ?>
|
||
<?php } ?>
|
||
</select>
|
||
</div>
|
||
|
||
<div class="form-group col-md-12">
|
||
<label for="subject">Subject</label>
|
||
<input id="subject" type="text" class="form-control" name="subject" value="<?= isset($subject) ? $subject : " " ?>">
|
||
</div>
|
||
|
||
<div class="form-group col-md-12">
|
||
<label for="internal_mail_content">Mail Content</label>
|
||
<textarea id="internal_mail_content" class="form-control" name="internal_mail_content" rows="3"><?= isset($mail_content) ? $mail_content : " " ?></textarea>
|
||
</div>
|
||
</div>
|
||
|
||
</div>
|
||
<br>
|
||
<div class="form-group text-right m-b-0" id="hide_smbt_btn">
|
||
<button type="submit" class="btn btn-primary" onclick="constructURL(2)">Send Mail</button>
|
||
</div>
|
||
</div>
|
||
</div><!-- /.modal-content -->
|
||
</div>
|
||
</div><!-- /.modal -->
|
||
|
||
<!-- Modal content for Send Placement Mail -->
|
||
<div class="modal fade" id="placement_mail_modal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
|
||
aria-hidden="false">
|
||
<div class="modal-dialog modal-full-width">
|
||
<div class="modal-content">
|
||
<div class="modal-header">
|
||
<h4 class="modal-title" id="myCenterModalLabel">Placement</h4>
|
||
<button type="button" id="close_btn" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||
</div>
|
||
<div class="modal-body">
|
||
|
||
<div class="form-group">
|
||
|
||
<!-- For display perpose placement alredy submited text display -->
|
||
<div class="form-group col-md-12">
|
||
<label><span id="alert_msg"class="text-danger"></span></label>
|
||
</div>
|
||
|
||
<div class="form-row">
|
||
|
||
<div class="form-group col-md-3">
|
||
<label for="utr_no">UTR No.</label>
|
||
<input type="text" class="form-control" id="utr_no" name="utr_no" placeholder="Enter UTR No.">
|
||
</div>
|
||
|
||
<div class="form-group col-md-3">
|
||
<label for="placement_date">Placement Date</label>
|
||
<input type="text" class="form-control" id="placement_date" name="placement_date" placeholder="DD/MM/YYY">
|
||
</div>
|
||
|
||
<div class="form-group col-md-3">
|
||
<label for="premium_amount">Premium Amount</label>
|
||
<input type="text" class="form-control" id="premium_amount" name="premium_amount" placeholder="Enter Premium Amount">
|
||
</div>
|
||
|
||
<div class="form-group col-md-3">
|
||
<label for="total_amount">Total Amount</label>
|
||
<input type="text" class="form-control" id="total_amount" name="total_amount" placeholder="Enter Total Amount">
|
||
</div>
|
||
|
||
<div class="form-group col-md-3">
|
||
<label for="cd_amount">CD Amount</label>
|
||
<input type="text" class="form-control" id="cd_amount" name="cd_amount" placeholder="Enter CD Amount">
|
||
</div>
|
||
|
||
</div>
|
||
<hr>
|
||
<div class="form-row">
|
||
|
||
<div class="form-group col-md-6">
|
||
<label for="proposals"> Proposals/Insurer <span id="base_danger"class="text-danger">*</span></label>
|
||
<select class="form-control" id="proposals"name="proposals" onchange="getInsurerBranchContacts(this)" required>
|
||
<option value="" >Select Proposals</option>
|
||
</select>
|
||
</div>
|
||
|
||
<div class="form-group col-md-6">
|
||
<label for="placement_to"> To <span id="base_danger"class="text-danger">*</span></label>
|
||
<select class="form-control" id="placement_to" name="placement_to" required>
|
||
<option value="" >Select To Mail</option>
|
||
</select>
|
||
</div>
|
||
|
||
<div class="form-group col-md-6">
|
||
<label for="placement_cc">CC </label>
|
||
<select class="form-control" id="placement_cc" name="placement_cc" required multiple>
|
||
<?php if (isset($userList)) { ?>
|
||
<?php foreach ($userList as $user) { ?>
|
||
<option value="<?= $user['id'];?>">
|
||
<?= $user['first_name'].' - '.$user['email'];?>
|
||
</option>
|
||
<?php } ?>
|
||
<?php } ?>
|
||
</select>
|
||
</div>
|
||
|
||
<div class="form-group col-md-12">
|
||
<label for="subject">Subject</label>
|
||
<input type="text" class="form-control" id="placement_subject" name="placement_subject" value="<?= isset($subject) ? $subject : " " ?>" placeholder="Enter Subject">
|
||
</div>
|
||
|
||
</div>
|
||
<hr>
|
||
<div class="form-row">
|
||
<div class="form-group col-md-12">
|
||
<label for="mail_content">Mail Content</label>
|
||
<textarea id="placement_mail_content" class="form-control" name="placement_mail_content" rows="3"><?= isset($mail_content) ? $mail_content : " " ?></textarea>
|
||
</div>
|
||
</div>
|
||
|
||
</div>
|
||
|
||
<div class="form-group text-right m-b-0" id="hide_smbt_btn">
|
||
<button type="submit" class="btn btn-primary" onclick="constructURL(3)">Send Mail</button>
|
||
</div>
|
||
|
||
</div>
|
||
</div><!-- /.modal-content -->
|
||
</div>
|
||
</div><!-- /.modal -->
|
||
|
||
<script>
|
||
var rfq_data = <?= isset($rfq_data['json']) ? $rfq_data['json'] : null ?>;
|
||
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 = [
|
||
|
||
{
|
||
name: "Fire",
|
||
description: ["All Buildings and civil structures including Super Structure, plinth & foundation, other Civil Structures, Roads, gates, pavements,internal Pathways, stone works, stone arts etc., Street Lights, Landscaping, Play Area, Culvert, drainage, retaining walls, etc. Compound Wall including utility, admin block, security office and all other similar structures pertaining to insured within the premises, Kutcha Constructions, Temporary Sheds, parking Sheds, Shelters, Civil Structure / bed for DG set / Genset, Interlocking Pathways, LVP Pathway Widening, Roads including internal roads, Mini Conference, Swimming pool, rest areas, shelters, Kitchen-Exhaust System Work, Red Earth for Garden, Arch Wall , Retaining Wall, Boundry,compound walls, Water, Vetrified Tiles, Capital Additions related to Building. All other civil structures related to insured at the covered premises."],
|
||
quote_asked: ["100"]
|
||
},
|
||
{
|
||
name: "Burglary",
|
||
description: ["Contents, AC & Accessories, FFF, P & M & Accessories, Electronic Equipments & Assessories, Electrical Items & Fittings, Plumbing Items, Structural Products, Structures, Leasehold Work including Civil Works, Interiors Temporary Structures including Sheds and Containers, Interiors, Plate Glass, Workstations, Office Equipments, Consumables, Goods held in commission / Trust, Trading Goods, Other contents / Items related to Insured's trade, Other Contets related to Insured's Trdae"],
|
||
quote_asked: ["1000"]
|
||
},
|
||
{
|
||
name: "Flop",
|
||
description: ["Loss of Gross Profit due to peril covered in the Standard Fire & Special Perils Policy."],
|
||
quote_asked: ["10,000,000"]
|
||
},
|
||
{
|
||
name: "All Risk",
|
||
description: ["Laptops, Notebooks Computers, Tablets, Mobile Phones & Cameras, projectors, and other portable equipments."],
|
||
quote_asked: ["900"]
|
||
},
|
||
{
|
||
name: "MBD",
|
||
description: ["Plant & Machinieries including and not limited to DG Set, Lifts, Refrigerator, Cooler, Air Condiitoner, Pump, Water Dispenser, Freezer, Oven, Motor, Transformer, etc. and other P&M related to Insured "],
|
||
quote_asked: ["100"]
|
||
},
|
||
{
|
||
name: "EEI",
|
||
description: ["Various electronic Items including and not limited to Computer, Printer, CCTV, Telephone Instruments, Control System, Router, Switches, BMS System, DVD Player, Music Systems, Scanner, Photo Copier and Electronic Lock System, and other electronic items."],
|
||
quote_asked: ["0"]
|
||
},
|
||
{
|
||
name: "Fidelity",
|
||
description: ["Dishonest acts / Fraudulent Act of employees", "No Of Employees", "Per Person Limit", "Third Party Fidelity Cover"],
|
||
quote_asked: ["10000000", "100", "2500000", "2500000"]
|
||
},
|
||
{
|
||
name: "Money",
|
||
description: ["Money in transit", "Money in Safe", "Money in Counter", "Annual Transit"],
|
||
quote_asked: ["10000000", "10000000", "10000000", "10000000"]
|
||
},
|
||
{
|
||
name: "Plate Glass",
|
||
description: ["Glass items, including frames and fititngs "],
|
||
quote_asked: ["10055"]
|
||
},
|
||
{
|
||
name: "Neon Sign",
|
||
description: ["Neon Tubes, Frame, Electrical Components, Glass Panels, Lettering and Graphics"],
|
||
quote_asked: ["102220"]
|
||
},
|
||
{
|
||
name: "Public Liability",
|
||
description: ["As per Public Liability including extensions such as Lift Liability & Food & Beverage: AOA : AOY - 1:4", "AOA:AOY"],
|
||
quote_asked: ["1000000", "1:1 / 1:2 / 1:4"]
|
||
},
|
||
|
||
];
|
||
|
||
const child_table_data = {
|
||
|
||
"fire": [
|
||
...(!$.isEmptyObject(policySummary) ? policySummary : []),
|
||
{
|
||
table_type: "new",
|
||
table_id: "fire_addOnCoverage",
|
||
table_editable: true,
|
||
table_name: "Fire Inbuilt Coverage",
|
||
table_row_contents: [{
|
||
"fire_designated_property_clause": {
|
||
"display_value": "Designated Property Clause",
|
||
"answer_type": 'dropdown',
|
||
"default_answer": [{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}],
|
||
"answers": [{
|
||
"key": "1",
|
||
"display_value": "Agreed"
|
||
},
|
||
{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}
|
||
]
|
||
},
|
||
},
|
||
{
|
||
"fire_bank_clause": {
|
||
"display_value": "Agreed Bank Clause",
|
||
"answer_type": 'dropdown',
|
||
"default_answer": [{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}],
|
||
"answers": [{
|
||
"key": "1",
|
||
"display_value": "Agreed"
|
||
},
|
||
{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}
|
||
]
|
||
},
|
||
},
|
||
{
|
||
"fire_reinstatement_value": {
|
||
"display_value": "Reinstatement Value Clause",
|
||
"answer_type": 'dropdown',
|
||
"default_answer": [{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}],
|
||
"answers": [{
|
||
"key": "1",
|
||
"display_value": "Agreed"
|
||
},
|
||
{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}
|
||
]
|
||
}
|
||
}
|
||
]
|
||
},
|
||
|
||
{
|
||
table_type: "new",
|
||
table_id: "fire_coverage",
|
||
table_editable: true,
|
||
table_name: "Fire Additional Coverage",
|
||
table_row_contents: [{
|
||
"fire_allied_perls": {
|
||
"display_value": "Fire and Allied Perils, Including STFI ",
|
||
"answer_type": 'free-text'
|
||
},
|
||
},
|
||
{
|
||
"fire_removal_debres": {
|
||
"display_value": "Costs for Removal of debris upto 2 % of the claim amount ",
|
||
"answer_type": 'free-text'
|
||
},
|
||
},
|
||
{
|
||
"fire_alteration_extension ": {
|
||
"display_value": "Additions, alterations or extensions upto 15% of the Sum Insured for that item (excluding stocks)",
|
||
"answer_type": 'free-text'
|
||
},
|
||
},
|
||
{
|
||
"fire_temp_removal_stocks": {
|
||
"display_value": "Temporary removal of stocks upto 10% of value",
|
||
"answer_type": 'free-text'
|
||
},
|
||
},
|
||
{
|
||
"fire_start_up_expense": {
|
||
"display_value": "Start-Up Expenses upto 5 Lakhs",
|
||
"answer_type": 'free-text'
|
||
}
|
||
}
|
||
]
|
||
},
|
||
{
|
||
table_type: "append",
|
||
table_name: "Excess",
|
||
table_id: "excess",
|
||
table_editable: true,
|
||
table_row_contents: [{
|
||
'policy_fire_excess': {
|
||
"display_value": "Policy Fire",
|
||
"answer_type": 'free-text'
|
||
}
|
||
}]
|
||
}
|
||
],
|
||
"burglary": [{
|
||
table_type: "new",
|
||
table_name: "Burglary Additional Coverage",
|
||
table_id: "burglary_addOnCoverage",
|
||
table_editable: true,
|
||
table_row_contents: [{
|
||
"burglary_loss_limit": {
|
||
"display_value": "First Loss Limit ",
|
||
"answer_type": 'dropdown',
|
||
"default_answer": [{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}],
|
||
"answers": [{
|
||
"key": "1",
|
||
"display_value": "Agreed"
|
||
},
|
||
{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}
|
||
]
|
||
},
|
||
},
|
||
{
|
||
"burglary_theft_rmsd": {
|
||
"display_value": "Theft & RSMD",
|
||
"answer_type": 'dropdown',
|
||
"default_answer": [{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}],
|
||
"answers": [{
|
||
"key": "1",
|
||
"display_value": "Agreed"
|
||
},
|
||
{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}
|
||
],
|
||
},
|
||
},
|
||
{
|
||
"burglary_waiver_FIR": {
|
||
"display_value": " Waiver of FIR, NTC and Final Investigation reports",
|
||
"answer_type": 'dropdown',
|
||
"default_answer": [{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}],
|
||
"answers": [{
|
||
"key": "1",
|
||
"display_value": "Agreed"
|
||
},
|
||
{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}
|
||
]
|
||
},
|
||
}
|
||
]
|
||
},
|
||
|
||
{
|
||
table_type: "append",
|
||
table_name: "Excess",
|
||
table_editable: true,
|
||
table_id: "excess",
|
||
table_row_contents: [{
|
||
"burglary_excess": {
|
||
"display_value": "Policy Burglary",
|
||
"answer_type": 'free-text'
|
||
}
|
||
}]
|
||
}
|
||
],
|
||
"flop": [{
|
||
table_type: "new",
|
||
table_name: "Flop Coverage",
|
||
table_id: "flop_coverage",
|
||
table_editable: true,
|
||
table_row_contents: [{
|
||
"flop_coverage_si": {
|
||
"display_value": "Sum Insured",
|
||
"answer_type": 'free-text',
|
||
}
|
||
},
|
||
{
|
||
"flop_indemnity_period": {
|
||
"display_value": "Indemnity Period",
|
||
"answer_type": 'free-text',
|
||
}
|
||
},
|
||
{
|
||
"flop_indemnification": {
|
||
"display_value": "Basis of Sum Insured / Indemnification ",
|
||
"answer_type": 'free-text',
|
||
|
||
}
|
||
},
|
||
|
||
]
|
||
},
|
||
{
|
||
table_type: "new",
|
||
table_name: "Flop Add on Coverage",
|
||
table_id: "flop_AddOnCoverage",
|
||
table_editable: true,
|
||
table_row_contents: [{
|
||
"flop_earthquake": {
|
||
"display_value": "Earthquake",
|
||
"answer_type": 'free-text',
|
||
}
|
||
},
|
||
{
|
||
"flop_stfi": {
|
||
"display_value": "STFI (Storm, Tempest, Flood and Innundation)",
|
||
"answer_type": 'free-text',
|
||
}
|
||
},
|
||
{
|
||
"flop_terrorism": {
|
||
"display_value": "Terrorism",
|
||
"answer_type": 'free-text',
|
||
|
||
}
|
||
},
|
||
|
||
]
|
||
},
|
||
{
|
||
table_type: "append",
|
||
table_name: "Excess",
|
||
table_id: "excess",
|
||
table_editable: true,
|
||
table_row_contents: [{
|
||
"money_excess": {
|
||
"display_value": "Policy Flop ",
|
||
"answer_type": 'free-text'
|
||
}
|
||
}]
|
||
}
|
||
],
|
||
|
||
"all_risk": [{
|
||
table_type: "new",
|
||
table_name: "All Risk Additional Coverage",
|
||
table_id: "all_risk_addOnCoverage",
|
||
table_editable: true,
|
||
table_row_contents: [{
|
||
"all_risk_rsmd": {
|
||
"display_value": "RSMD",
|
||
"answer_type": 'dropdown',
|
||
"default_answer": [{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}],
|
||
"answers": [{
|
||
"key": "1",
|
||
"display_value": "Agreed"
|
||
},
|
||
{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}
|
||
]
|
||
}
|
||
},
|
||
{
|
||
"all_risk_terrorism": {
|
||
"display_value": "Terrorism",
|
||
"answer_type": 'dropdown',
|
||
"default_answer": [{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}],
|
||
"answers": [{
|
||
"key": "1",
|
||
"display_value": "Agreed"
|
||
},
|
||
{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}
|
||
]
|
||
}
|
||
},
|
||
{
|
||
"all_risk_reistatement": {
|
||
"display_value": "Reinstatement value clause",
|
||
"answer_type": 'dropdown',
|
||
"default_answer": [{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}],
|
||
"answers": [{
|
||
"key": "1",
|
||
"display_value": "Agreed"
|
||
},
|
||
{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}
|
||
]
|
||
}
|
||
}
|
||
]
|
||
},
|
||
{
|
||
table_type: "append",
|
||
table_name: "Excess",
|
||
table_id: "excess",
|
||
table_editable: true,
|
||
table_row_contents: [{
|
||
"money_excess": {
|
||
"display_value": "Policy All Risk ",
|
||
"answer_type": 'free-text'
|
||
}
|
||
}]
|
||
}
|
||
],
|
||
"mbd": [{
|
||
table_type: "new",
|
||
table_name: "MBD Additional Coverage",
|
||
table_id: "mbd_addOnCoverage",
|
||
table_editable: true,
|
||
table_row_contents: [{
|
||
"mbd_accidental_breakdown": {
|
||
"display_value": "Accidental / Mechanical breakdown",
|
||
"answer_type": 'dropdown',
|
||
"default_answer": [{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}],
|
||
"answers": [{
|
||
"key": "1",
|
||
"display_value": "Agreed"
|
||
},
|
||
{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}
|
||
]
|
||
}
|
||
},
|
||
{
|
||
"mbd_terrorism_express_freight": {
|
||
"display_value": "Express Freight",
|
||
"answer_type": 'dropdown',
|
||
"default_answer": [{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}],
|
||
"answers": [{
|
||
"key": "1",
|
||
"display_value": "Agreed"
|
||
},
|
||
{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}
|
||
]
|
||
}
|
||
},
|
||
{
|
||
"mbd_reistatement_air_freight": {
|
||
"display_value": "Air Freight",
|
||
"answer_type": 'dropdown',
|
||
"default_answer": [{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}],
|
||
"answers": [{
|
||
"key": "1",
|
||
"display_value": "Agreed"
|
||
},
|
||
{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}
|
||
]
|
||
}
|
||
}
|
||
]
|
||
}],
|
||
|
||
"eei": [{
|
||
table_type: "new",
|
||
table_name: "EEI Additional Coverage",
|
||
table_id: "eei_addOnCoverage",
|
||
table_editable: true,
|
||
table_row_contents: [{
|
||
"eei_electronic_equipment": {
|
||
"display_value": "As per Electronic Equipment Policy including STFI, EQ, Terrorism",
|
||
"answer_type": 'dropdown',
|
||
"default_answer": [{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}],
|
||
"answers": [{
|
||
"key": "1",
|
||
"display_value": "Agreed"
|
||
},
|
||
{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}
|
||
]
|
||
}
|
||
},
|
||
{
|
||
"eei_accidental_breakdown": {
|
||
"display_value": "Accidental / Electrical Breakdown",
|
||
"answer_type": 'dropdown',
|
||
"default_answer": [{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}],
|
||
"answers": [{
|
||
"key": "1",
|
||
"display_value": "Agreed"
|
||
},
|
||
{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}
|
||
]
|
||
}
|
||
},
|
||
{
|
||
"eei_electrical_damage": {
|
||
"display_value": "Damage to electronic equipment incl. systems software, cost of external data media, cost of reconstruction of data",
|
||
"answer_type": 'dropdown',
|
||
"default_answer": [{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}],
|
||
"answers": [{
|
||
"key": "1",
|
||
"display_value": "Agreed"
|
||
},
|
||
{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}
|
||
]
|
||
}
|
||
}
|
||
]
|
||
}],
|
||
"fidelity": [{
|
||
table_type: "new",
|
||
table_name: "Fidelity Additional Coverage",
|
||
table_id: "fidelity_addOnCoverage",
|
||
table_editable: true,
|
||
table_row_contents: [{
|
||
"fidelity_any1_person": {
|
||
"display_value": "Any One Person",
|
||
"answer_type": 'dropdown',
|
||
"default_answer": [{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}],
|
||
"answers": [{
|
||
"key": "1",
|
||
"display_value": "Agreed"
|
||
},
|
||
{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}
|
||
]
|
||
}
|
||
},
|
||
{
|
||
"fidelity_contract_employee": {
|
||
"display_value": " Including contract Employees",
|
||
"answer_type": 'dropdown',
|
||
"default_answer": [{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}],
|
||
"answers": [{
|
||
"key": "1",
|
||
"display_value": "Agreed"
|
||
},
|
||
{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}
|
||
]
|
||
}
|
||
},
|
||
{
|
||
"fidelity_unnamed_bias": {
|
||
"display_value": "Un-named Basis",
|
||
"answer_type": 'dropdown',
|
||
"default_answer": [{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}],
|
||
"answers": [{
|
||
"key": "1",
|
||
"display_value": "Agreed"
|
||
},
|
||
{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}
|
||
]
|
||
}
|
||
}
|
||
]
|
||
}],
|
||
"money": [{
|
||
table_type: "new",
|
||
table_name: "Money Additional Coverage",
|
||
table_id: "money_addOnCoverage",
|
||
table_editable: true,
|
||
table_row_contents: [{
|
||
"money_rsmd": {
|
||
"display_value": "RSMD",
|
||
"answer_type": 'dropdown',
|
||
"default_answer": [{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}],
|
||
"answers": [{
|
||
"key": "1",
|
||
"display_value": "Agreed"
|
||
},
|
||
{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}
|
||
]
|
||
}
|
||
},
|
||
{
|
||
"money_terrorism": {
|
||
"display_value": "Terrorism",
|
||
"answer_type": 'free-text'
|
||
}
|
||
},
|
||
{
|
||
"money_by_vehicle": {
|
||
"display_value": " Cash by Public Transport/Vehicle",
|
||
"answer_type": 'free-text'
|
||
}
|
||
},
|
||
{
|
||
"money_by_two_wheeler": {
|
||
"display_value": "Cash by Two Wheeler",
|
||
"answer_type": 'free-text'
|
||
}
|
||
},
|
||
|
||
]
|
||
},
|
||
{
|
||
table_type: "append",
|
||
table_name: "Excess",
|
||
table_id: "excess",
|
||
table_editable: true,
|
||
table_row_contents: [{
|
||
"money_excess": {
|
||
"display_value": "Policy Money ",
|
||
"answer_type": 'free-text'
|
||
}
|
||
}]
|
||
}
|
||
],
|
||
"plate_glass": [{
|
||
table_type: "new",
|
||
table_name: "Plate Glass Coverage",
|
||
table_id: "plate_glass_addOnCoverage",
|
||
table_editable: true,
|
||
table_row_contents: [{
|
||
"plate_glass_accidental_damage": {
|
||
"display_value": "Accidental Damage",
|
||
"answer_type": 'dropdown',
|
||
"default_answer": [{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}],
|
||
"answers": [{
|
||
"key": "1",
|
||
"display_value": "Agreed"
|
||
},
|
||
{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}
|
||
]
|
||
}
|
||
},
|
||
{
|
||
"plate_glass_rsmd": {
|
||
"display_value": "RSMD",
|
||
"answer_type": 'dropdown',
|
||
"default_answer": [{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}],
|
||
"answers": [{
|
||
"key": "1",
|
||
"display_value": "Agreed"
|
||
},
|
||
{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}
|
||
]
|
||
}
|
||
},
|
||
{
|
||
"plate_glass_waiver_of_survey": {
|
||
"display_value": "Waiver of Survey upto INR 2 Lacs",
|
||
"answer_type": 'dropdown',
|
||
"default_answer": [{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}],
|
||
"answers": [{
|
||
"key": "1",
|
||
"display_value": "Agreed"
|
||
},
|
||
{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}
|
||
]
|
||
}
|
||
}
|
||
|
||
]
|
||
},
|
||
|
||
{
|
||
table_type: "append",
|
||
table_name: "Excess",
|
||
table_id: "excess",
|
||
table_editable: true,
|
||
table_row_contents: [{
|
||
"plate_glass_excess": {
|
||
"display_value": "Policy Plate Glass ",
|
||
"answer_type": 'free-text'
|
||
}
|
||
}]
|
||
}
|
||
],
|
||
"neon_sign": [{
|
||
table_type: "new",
|
||
table_name: "Neon Sign Coverage",
|
||
table_id: "neon_sign_addOnCoverage",
|
||
table_editable: true,
|
||
table_row_contents: [{
|
||
"neon_sign_accidental": {
|
||
"display_value": "Accidental/Physical/Electronic Damage",
|
||
"answer_type": 'dropdown',
|
||
"default_answer": [{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}],
|
||
"answers": [{
|
||
"key": "1",
|
||
"display_value": "Agreed"
|
||
},
|
||
{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}
|
||
]
|
||
}
|
||
},
|
||
{
|
||
"neon_sign_rsmd": {
|
||
"display_value": "RSMD",
|
||
"answer_type": 'dropdown',
|
||
"default_answer": [{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}],
|
||
"answers": [{
|
||
"key": "1",
|
||
"display_value": "Agreed"
|
||
},
|
||
{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}
|
||
]
|
||
}
|
||
},
|
||
{
|
||
"neon_sign_waiver": {
|
||
"display_value": "Waiver of Survey upto INR 2 Lacs",
|
||
"answer_type": 'dropdown',
|
||
"default_answer": [{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}],
|
||
"answers": [{
|
||
"key": "1",
|
||
"display_value": "Agreed"
|
||
},
|
||
{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}
|
||
]
|
||
}
|
||
},
|
||
]
|
||
},
|
||
|
||
{
|
||
table_type: "append",
|
||
table_name: "Excess",
|
||
table_id: "excess",
|
||
table_editable: true,
|
||
table_row_contents: [{
|
||
"neon_sign_excess": {
|
||
"display_value": "Policy Neon",
|
||
"answer_type": 'free-text'
|
||
}
|
||
}]
|
||
}
|
||
],
|
||
"public_liability": [{
|
||
table_type: "new",
|
||
table_name: "Public Liability Coverage",
|
||
table_id: "public_liability_addOnCoverage",
|
||
table_editable: true,
|
||
table_row_contents: [{
|
||
"public_liability_aog": {
|
||
"display_value": "AOG Perils Extention",
|
||
"answer_type": 'dropdown',
|
||
"default_answer": [{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}],
|
||
"answers": [{
|
||
"key": "1",
|
||
"display_value": "Agreed"
|
||
},
|
||
{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}
|
||
]
|
||
}
|
||
},
|
||
{
|
||
"public_liability_3rdparty": {
|
||
"display_value": "Third Party Includes visitors",
|
||
"answer_type": 'dropdown',
|
||
"default_answer": [{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}],
|
||
"answers": [{
|
||
"key": "1",
|
||
"display_value": "Agreed"
|
||
},
|
||
{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}
|
||
]
|
||
}
|
||
},
|
||
{
|
||
"public_liability_owners": {
|
||
"display_value": "Owners / Tenants occupying the premises",
|
||
"answer_type": 'dropdown',
|
||
"default_answer": [{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}],
|
||
"answers": [{
|
||
"key": "1",
|
||
"display_value": "Agreed"
|
||
},
|
||
{
|
||
"key": "0",
|
||
"display_value": "Not Agreed"
|
||
}
|
||
]
|
||
}
|
||
},
|
||
|
||
|
||
]
|
||
}],
|
||
|
||
};
|
||
|
||
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);
|
||
hideProposalOptionsForChild();
|
||
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);
|
||
hideProposalOptionsForChild();
|
||
var proposalName = `Proposal ${proposalNumber}`;
|
||
const proposalHeader = document.querySelector(`th[data-proposal="${proposalNumber}"]`);
|
||
if (proposalHeader) {
|
||
proposalHeader.colSpan = quotesConfig[proposalNumber].length;
|
||
}
|
||
}
|
||
|
||
|
||
|
||
showOrHideFieldsBasedOnRFQorQCR();
|
||
});
|
||
|
||
}
|
||
|
||
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;
|
||
|
||
// 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);
|
||
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[0];
|
||
default_answer = default_answers_array[0];
|
||
|
||
// 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'));
|
||
} else {
|
||
generateTable(document.getElementById('tablesContainer'));
|
||
}
|
||
|
||
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
|
||
} else {
|
||
content = input.value; // Handling other input types like text, select, textarea
|
||
}
|
||
} else {
|
||
content = cell.innerText.trim(); // If no input is found, use the cell's text
|
||
|
||
}
|
||
}
|
||
// console.log("trying to find what this is ",cell);
|
||
rowData.data.push({
|
||
parentth: header.parentHeader,
|
||
subth: subHeader,
|
||
// value: cell.innerText,
|
||
input_value: content,
|
||
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
|
||
|
||
console.log('newUrl', newUrl)
|
||
|
||
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];
|
||
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);
|
||
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]);
|
||
|
||
} else {
|
||
th2.textContent = subHeader;
|
||
}
|
||
|
||
|
||
headerRow2.appendChild(th2);
|
||
});
|
||
});
|
||
|
||
return [headerRow1, headerRow2];
|
||
}
|
||
|
||
// Helper to process cell content
|
||
function processCellContent(value, cellData = null) {
|
||
|
||
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 `${parsed.display_value} <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");
|
||
$("#submitMail").text("Send Insurer Mail");
|
||
$(".rfqbtn").show();
|
||
$(".qcrbtn").hide();
|
||
$("#saveRFQ").css("margin-right", "10px");
|
||
|
||
} 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");
|
||
$("#submitMail").text("Send Client Mail");
|
||
// $(".sno-checkboxes").prop("disabled", true);
|
||
$("#openQCR").hide();
|
||
hideNonQCRRows();
|
||
hideNonQCRColumns();
|
||
disableCheckbox();
|
||
|
||
$(".rfqbtn").hide();
|
||
$(".qcrbtn").show();
|
||
$("#saveRFQ").css("margin-right", "20px");
|
||
|
||
}
|
||
|
||
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>
|
||
|
||
<!-- Export Excel and Mail Script -->
|
||
<script>
|
||
|
||
var proposalDataForDropDown = {};
|
||
|
||
const editorConfig = {
|
||
buttons: [
|
||
"bold",
|
||
"italic",
|
||
"strikethrough",
|
||
"|",
|
||
"superscript",
|
||
"subscript",
|
||
"|",
|
||
"align",
|
||
"fontsize",
|
||
"|",
|
||
"source" // Add the "source" button for editing HTML
|
||
],
|
||
fontsize: ["8px", "10px", "12px", "14px", "16px", "18px", "20px", "22px", "24px"], // Font sizes in pixels
|
||
showPlaceholder: false,
|
||
toolbarButtonSize: "small",
|
||
toolbarAdaptive: false,
|
||
saveHeightInStorage: true,
|
||
minHeight: 400,
|
||
height: 400, // Optional fixed height
|
||
defaultMode: "1", // Start in WYSIWYG mode
|
||
enableDragAndDropFileToEditor: true, // Allow file uploads via drag and drop
|
||
placeholder: "Start typing here...", // Optional placeholder text
|
||
};
|
||
|
||
$(document).ready(function(){
|
||
|
||
const path = window.location.pathname; // Get the current URL path
|
||
const segments = path.split('/'); // Split the path into segments
|
||
const lead_id = segments[segments.length - 2]; // Get the second last segment (15)
|
||
const rfq_type = segments[segments.length - 1]; // Get the last segment (2)
|
||
|
||
console.log('Lead ID:', lead_id);
|
||
console.log('Type:', rfq_type);
|
||
|
||
let excel_url = '<?= base_url('leads/exportQCRandRFQ/') ?>' + lead_id + '/' + rfq_type + '/' + 2
|
||
console.log(excel_url, excel_url);
|
||
|
||
$('#submitExcel').attr('data-url', excel_url);
|
||
|
||
$('#cc').select2({
|
||
placeholder: 'Select CC Mail',
|
||
});
|
||
|
||
$('#placement_cc').select2({
|
||
placeholder: 'Select CC Mail',
|
||
});
|
||
|
||
$('#proposals').select2({
|
||
placeholder: 'Select To proposal',
|
||
});
|
||
|
||
$('#placement_to').select2({
|
||
placeholder: 'Select To Mail',
|
||
});
|
||
|
||
$('#to').select2({
|
||
placeholder: 'Select To Mail',
|
||
});
|
||
|
||
$("textarea.select2-search__field").attr('rows', '1');
|
||
$("textarea.select2-search__field").css('resize', 'none');
|
||
|
||
let placementLeadData = <?= isset($lead_data) && isset($lead_data['proposel_data']) ? json_encode($lead_data['proposel_data']) : 'null'; ?>;
|
||
// console.log('placementLeadData', placementLeadData);
|
||
|
||
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 + '.';
|
||
$('#alert_msg').text(txt);
|
||
} else {
|
||
$('#alert_msg').text('');
|
||
console.log('placementLeadData is null or undefined.');
|
||
}
|
||
|
||
|
||
// Initialize the Jodit editor
|
||
const editor = Jodit.make("#placement_mail_content", editorConfig);
|
||
|
||
const editor2 = Jodit.make("#internal_mail_content", editorConfig);
|
||
|
||
var placement_date_datePicker = flatpickr("#placement_date", {
|
||
dateFormat: "d/m/Y",
|
||
allowInput: false,
|
||
});
|
||
|
||
|
||
})
|
||
|
||
function checkTheTableDataChanged(redirect_type){
|
||
|
||
|
||
if(redirect_type == 1){
|
||
//BACK BUTTON
|
||
window.location.href="<?= base_url("leads/list")?>"
|
||
|
||
}else if(redirect_type == 2){
|
||
//EXCEL EXPORT
|
||
let url = $('#submitExcel').data('url');
|
||
window.location.href = url;
|
||
|
||
}else if(redirect_type == 3){
|
||
//INSURER OR CLIENT MAIL SEND
|
||
showModal(1);
|
||
|
||
}else if(redirect_type == 4){
|
||
//INTERNAL MAIL SEND
|
||
showModal(2);
|
||
|
||
}else if(redirect_type == 5){
|
||
//PROCCED TO QCR
|
||
// submitQCRData();
|
||
let lead_id = $('#lead_id').val();
|
||
let url = '<?= base_url('rfq/list/') ?>' + lead_id + '/' + 2;
|
||
window.location.href = url;
|
||
|
||
}else if(redirect_type == 6){
|
||
//INTERNAL MAIL SEND
|
||
showModal(3);
|
||
|
||
}
|
||
}
|
||
|
||
function showModal(mail_type) {
|
||
|
||
if(mail_type == 1){
|
||
|
||
insurerAndClientMailPopUp()
|
||
|
||
}else if(mail_type == 2){
|
||
|
||
var myModal = new bootstrap.Modal(document.getElementById('internal_mail_modal'));
|
||
myModal.show();
|
||
|
||
// getMailContent('internal_mail_content');
|
||
|
||
}else if(mail_type == 3){
|
||
|
||
placementMailPopUp()
|
||
// getMailContent('placement_mail_content');
|
||
|
||
}
|
||
|
||
}
|
||
|
||
function insurerAndClientMailPopUp(){
|
||
|
||
var url = '';
|
||
var lead_id = $('#lead_id').val();
|
||
|
||
if (rfq_or_qcr == 2) {
|
||
$('#myCenterModalLabel').text('Client contact to send mail')
|
||
url = '<?= base_url('leads/list/') ?>' + lead_id;
|
||
} else {
|
||
$('#myCenterModalLabel').text('Choose insurer to send mail')
|
||
url = '<?= base_url('util/getLevelContects') ?>'
|
||
}
|
||
|
||
ajaxRequestForGetMailData(url);
|
||
|
||
var myModal = new bootstrap.Modal(document.getElementById('list_model'));
|
||
myModal.show();
|
||
}
|
||
|
||
function placementMailPopUp() {
|
||
|
||
console.log(proposalDataForDropDown);
|
||
|
||
const selectElement = document.getElementById('proposals');
|
||
|
||
// Clear existing options
|
||
selectElement.innerHTML = '<option value="">Select Proposals</option>';
|
||
|
||
// Loop through the proposal data and append options
|
||
for (const [proposalKey, proposalValue] of Object.entries(proposalDataForDropDown.over_all_column_data)) {
|
||
proposalValue.insurers.forEach(insurer => {
|
||
const option = document.createElement('option');
|
||
option.value = insurer.id;
|
||
option.setAttribute("data-id", `${proposalKey}-${insurer.display_name}`);
|
||
option.textContent = `${proposalKey} - ${insurer.display_name}`;
|
||
selectElement.appendChild(option);
|
||
});
|
||
}
|
||
|
||
// Show the modal
|
||
const myModal = new bootstrap.Modal(document.getElementById('placement_mail_modal'));
|
||
myModal.show();
|
||
}
|
||
|
||
function ajaxRequestForGetMailData(url) {
|
||
|
||
console.log(url);
|
||
|
||
$('.loader').fadeIn();
|
||
$('.loader-mask').fadeIn();
|
||
|
||
$.ajax({
|
||
url: url,
|
||
type: "GET",
|
||
dataType: 'json',
|
||
success: function(res) {
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
appendInput(res.data)
|
||
},
|
||
error: function(xhr, status, error) {
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
console.error(xhr.responseText);
|
||
console.error(status, error);
|
||
}
|
||
});
|
||
}
|
||
|
||
function appendInput(data) {
|
||
|
||
console.log(data);
|
||
var lead_id = $('#lead_id').val();
|
||
$('#input_for_row').empty();
|
||
let html = '';
|
||
|
||
if (rfq_or_qcr == 2) {
|
||
|
||
const url = '<?= base_url('leads/list') ?>?lead_id=' + lead_id;
|
||
|
||
html += `
|
||
<div class="form-group col-md-4">
|
||
<label for="contact_mail">Client Contact Mail</label>
|
||
<input value="${data.contact_person_email || ''}" type="text" id="contact_mail" class="form-control" placeholder="Contact Mail" readonly>
|
||
</div>
|
||
`;
|
||
|
||
if (!data.contact_person_email) {
|
||
html += `
|
||
<div class="form-group col-md-4">
|
||
<a href="${url}">Click here to update mail ID</a>
|
||
</div>
|
||
`;
|
||
}
|
||
|
||
if(user_role_id == 1 || user_role_id == 5){
|
||
|
||
html += `
|
||
|
||
<div class="form-group col-md-4">
|
||
<label for="client_cc">CC </label>
|
||
<select class="form-control" id="client_cc" name="client_cc" required multiple>
|
||
<?php if (isset($userList)) { ?>
|
||
<?php foreach ($userList as $user) { ?>
|
||
<option value="<?= $user['id'];?>">
|
||
<?= $user['first_name'].' - '.$user['email'];?>
|
||
</option>
|
||
<?php } ?>
|
||
<?php } ?>
|
||
</select>
|
||
</div>
|
||
|
||
<div class="form-group col-md-4">
|
||
<label for="client_bcc">BCC </label>
|
||
<select class="form-control" id="client_bcc" name="client_bcc" required multiple>
|
||
<?php if (isset($userList)) { ?>
|
||
<?php foreach ($userList as $user) { ?>
|
||
<option value="<?= $user['id'];?>">
|
||
<?= $user['first_name'].' - '.$user['email'];?>
|
||
</option>
|
||
<?php } ?>
|
||
<?php } ?>
|
||
</select>
|
||
</div>
|
||
`;
|
||
|
||
}
|
||
|
||
html += `
|
||
<div class="form-group col-md-12">
|
||
<label for="mail_subject">Subject</label>
|
||
<input type="text" id="mail_subject" class="form-control" value="'<?= isset($subject) ? $subject : " " ?>'" placeholder="Subject">
|
||
</div>
|
||
`;
|
||
|
||
} else {
|
||
// Assuming `data.contacts` is an array of contact objects within the main data object
|
||
const contacts = data || {};
|
||
|
||
html = `
|
||
<div class="form-group col-md-4">
|
||
<label for="insurerContact">Insurers</label>
|
||
<select id="insurerContact" class="form-control" name="insurerContact[]" multiple>
|
||
<option></option>
|
||
`;
|
||
|
||
// Loop through each contact property within the `contacts` object
|
||
for (const id in contacts) {
|
||
const contact = contacts[id];
|
||
html += `
|
||
<option value="${contact.id}">${contact.insurer_name} - ${contact.branch_code} - ${contact.contact_person_name} - ${contact.contact_person_email}</option>
|
||
`;
|
||
}
|
||
|
||
html += `
|
||
</select>
|
||
</div>
|
||
`;
|
||
|
||
html += `
|
||
|
||
<div class="form-group col-md-4">
|
||
<label for="client_cc">CC </label>
|
||
<select class="form-control" id="client_cc" name="client_cc" required multiple>
|
||
<?php if (isset($userList)) { ?>
|
||
<?php foreach ($userList as $user) { ?>
|
||
<option value="<?= $user['id'];?>">
|
||
<?= $user['first_name'].' - '.$user['email'];?>
|
||
</option>
|
||
<?php } ?>
|
||
<?php } ?>
|
||
</select>
|
||
</div>
|
||
|
||
<div class="form-group col-md-4">
|
||
<label for="client_bcc">BCC </label>
|
||
<select class="form-control" id="client_bcc" name="client_bcc" required multiple>
|
||
<?php if (isset($userList)) { ?>
|
||
<?php foreach ($userList as $user) { ?>
|
||
<option value="<?= $user['id'];?>">
|
||
<?= $user['first_name'].' - '.$user['email'];?>
|
||
</option>
|
||
<?php } ?>
|
||
<?php } ?>
|
||
</select>
|
||
</div>
|
||
`;
|
||
|
||
html += `
|
||
<div class="form-group col-md-12">
|
||
<label for="mail_subject">Subject</label>
|
||
<input value="<?= isset($subject) ? $subject : " " ?>" type="text" id="mail_subject" class="form-control" placeholder="Subject">
|
||
</div>
|
||
`;
|
||
|
||
}
|
||
|
||
html += `
|
||
<div class="form-group col-md-12">
|
||
<label for="insurer_and_client_mail_content">Mail Content</label>
|
||
<textarea id="insurer_and_client_mail_content" class="form-control" name="insurer_and_client_mail_content" rows="3"><?= isset($mail_content) ? $mail_content : " " ?></textarea>
|
||
</div>
|
||
`;
|
||
|
||
$('#input_for_row').append(html);
|
||
|
||
// Initialize select2 for the dropdown if insurerContact is present
|
||
if ($('#insurerContact').length) {
|
||
|
||
$('#insurerContact').select2({
|
||
placeholder: 'Select an Insurer',
|
||
});
|
||
|
||
$("textarea.select2-search__field").attr('rows', '1');
|
||
$("textarea.select2-search__field").css('resize', 'none');
|
||
}
|
||
|
||
// Initialize select2 for the dropdown if Client is present
|
||
if ($('#client_cc').length) {
|
||
|
||
$('#client_cc').select2({
|
||
placeholder: 'Select an CC',
|
||
});
|
||
|
||
$('#client_bcc').select2({
|
||
placeholder: 'Select an BCC',
|
||
});
|
||
|
||
$("textarea.select2-search__field").attr('rows', '1');
|
||
$("textarea.select2-search__field").css('resize', 'none');
|
||
}
|
||
|
||
// Initialize the Jodit editor
|
||
const editor = Jodit.make("#insurer_and_client_mail_content", editorConfig);
|
||
|
||
// getMailContent('insurer_and_client_mail_content');
|
||
|
||
}
|
||
|
||
function constructURL(url_type) {
|
||
|
||
if(url_type == 1){
|
||
constructURL_ForInsurerAndClientMailSend()
|
||
}else if(url_type == 2){
|
||
constructURL_ForInternalMailSend()
|
||
}else if(url_type == 3){
|
||
|
||
Swal.fire({
|
||
title: "Do you want to place the proposal data?",
|
||
// text: "Do you want Save this!",
|
||
icon: "warning",
|
||
showCancelButton: true,
|
||
confirmButtonColor: "#3085d6",
|
||
cancelButtonColor: "#d33",
|
||
confirmButtonText: "Yes, Procced!"
|
||
}).then((result) => {
|
||
if (result.isConfirmed) {
|
||
constructURL_ForPlacementMailSend()
|
||
}else{
|
||
return false;
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
// Insurer and Client Mail
|
||
function constructURL_ForInsurerAndClientMailSend() {
|
||
|
||
var lead_id = $('#lead_id').val();
|
||
var mail_content = $('#insurer_and_client_mail_content').val();
|
||
var subject = $('#mail_subject').val();
|
||
var bcc = $('#client_bcc').val();
|
||
var cc = $('#client_cc').val();
|
||
|
||
console.log('lead_id', lead_id)
|
||
console.log('subject', subject)
|
||
console.log('mail_content', mail_content)
|
||
console.log('bcc', bcc)
|
||
console.log('cc', cc)
|
||
|
||
// Convert cc to JSON string
|
||
cc = cc.map(Number);
|
||
cc = JSON.stringify(cc);
|
||
|
||
// Convert bcc to JSON string
|
||
bcc = bcc.map(Number);
|
||
bcc = JSON.stringify(bcc);
|
||
|
||
// Prepare FormData object
|
||
var formData = new FormData();
|
||
formData.append('lead_id', lead_id);
|
||
formData.append('mail_content', mail_content);
|
||
formData.append('subject', subject);
|
||
formData.append('cc', cc);
|
||
formData.append('bcc', bcc);
|
||
|
||
if (rfq_or_qcr == 2) {
|
||
formData.append('file_type', 'qcr');
|
||
formData.append('recipient_type', 'client');
|
||
formData.append('recipient_mail', '');
|
||
} else {
|
||
var insurerContact = $('#insurerContact').val();
|
||
insurerContact = insurerContact.map(Number);
|
||
formData.append('file_type', 'rfq');
|
||
formData.append('recipient_type', 'insurer');
|
||
formData.append('recipient_mail', JSON.stringify(insurerContact));
|
||
}
|
||
|
||
ajaxRequest(formData)
|
||
console.log('formData', formData)
|
||
|
||
}
|
||
|
||
//Internal Mail
|
||
function constructURL_ForInternalMailSend() {
|
||
|
||
var lead_id = $('#lead_id').val();
|
||
let to = $('#to').val();
|
||
let mail_content = $('#internal_mail_content').val();
|
||
let subject = $('#subject').val();
|
||
let cc = $('#cc').val();
|
||
|
||
// Convert cc to JSON string
|
||
cc = cc.map(Number);
|
||
cc = JSON.stringify(cc);
|
||
|
||
// Determine file type
|
||
var file_type = rfq_or_qcr == 2 ? 'qcr' : 'rfq';
|
||
|
||
// Create FormData
|
||
var formData = new FormData();
|
||
formData.append('lead_id', lead_id);
|
||
formData.append('file_type', file_type);
|
||
formData.append('recipient_type', 'internal');
|
||
formData.append('to', to);
|
||
formData.append('cc', cc);
|
||
formData.append('subject', subject);
|
||
formData.append('mail_content', mail_content);
|
||
formData.append('recipient_mail', ''); // Empty value as per logic
|
||
|
||
ajaxRequest(formData)
|
||
|
||
}
|
||
|
||
//placement mail
|
||
function constructURL_ForPlacementMailSend() {
|
||
|
||
var lead_id = $('#lead_id').val();
|
||
let to = $('#placement_to').val();
|
||
let placement_date = $('#placement_date').val();
|
||
let utr_no = $('#utr_no').val();
|
||
let premium_amount = $('#premium_amount').val();
|
||
let total_amount = $('#total_amount').val();
|
||
let cd_amount = $('#cd_amount').val();
|
||
let subject = $('#placement_subject').val();
|
||
let mail_content = $('#placement_mail_content').val();
|
||
let proposal_insurer = $('#proposals option:selected').data('id');
|
||
let insurer_and_branch = $('#proposals').val();
|
||
let cc = $('#placement_cc').val();
|
||
|
||
// Process `to` field
|
||
to = to.split(',').map(email => email.trim());
|
||
cc = cc.map(Number); // or split if it's a string: `cc.split(',').map(email => email.trim())`
|
||
|
||
// Prepare FormData
|
||
var formData = new FormData();
|
||
formData.append('lead_id', lead_id);
|
||
formData.append('file_type', rfq_or_qcr == 2 ? 'qcr' : 'rfq');
|
||
formData.append('recipient_type', 'placement');
|
||
formData.append('recipient_mail', JSON.stringify(to));
|
||
formData.append('cc', JSON.stringify(cc));
|
||
formData.append('subject', subject);
|
||
formData.append('proposal_insurer', proposal_insurer);
|
||
formData.append('insurer_and_branch', insurer_and_branch);
|
||
formData.append('placement_date', placement_date);
|
||
formData.append('utr_no', utr_no);
|
||
formData.append('premium_amount', premium_amount);
|
||
formData.append('total_amount', total_amount);
|
||
formData.append('cd_amount', cd_amount);
|
||
formData.append('mail_content', mail_content);
|
||
|
||
ajaxRequest(formData);
|
||
|
||
}
|
||
|
||
function ajaxRequest(formData) {
|
||
|
||
var apiURL = '<?= base_url('leads/sendMail') ?>';
|
||
console.log(apiURL);
|
||
|
||
$('.loader').fadeIn();
|
||
$('.loader-mask').fadeIn();
|
||
|
||
$.ajax({
|
||
url: apiURL,
|
||
type: "POST",
|
||
data: formData,
|
||
processData: false, // Required for FormData
|
||
contentType: false, // Required for FormData
|
||
dataType: 'json',
|
||
success: function(res) {
|
||
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
|
||
console.log(res);
|
||
if (res.status == 'success' && res.code == 200) {
|
||
toastr.success('Mail send Successfully', 'SUCCESS')
|
||
} else {
|
||
if (res.messgae) {
|
||
toastr.error(res.messgae, 'ERROR')
|
||
} else {
|
||
toastr.error('Mail send failed', 'ERROR')
|
||
}
|
||
}
|
||
|
||
$('.close').click()
|
||
},
|
||
error: function(xhr, status, error) {
|
||
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
|
||
console.error(xhr.responseText);
|
||
console.error(status, error);
|
||
}
|
||
});
|
||
|
||
$('#to').select2({
|
||
placeholder: 'Select To Mail',
|
||
});
|
||
$('#cc').val('').select2({
|
||
placeholder : 'select CC Mail'
|
||
});
|
||
// $('#subject').val('');
|
||
$('#proposals').val('');
|
||
$('#placement_to').val('').select2({
|
||
placeholder : 'select To Mail'
|
||
});
|
||
$('#placement_cc').val('').select2({
|
||
placeholder : 'select CC Mail'
|
||
});
|
||
$('#placement_subject').val('');
|
||
|
||
$("textarea.select2-search__field").attr('rows', '1');
|
||
$("textarea.select2-search__field").css('resize', 'none');
|
||
}
|
||
|
||
function objectToQueryString(obj) {
|
||
return Object.keys(obj).map(key => `${encodeURIComponent(key)}=${encodeURIComponent(obj[key])}`).join('&');
|
||
}
|
||
|
||
function getInsurerBranchContacts(input){
|
||
|
||
let insurer_and_branch = $(input).val();
|
||
console.log('insurer_and_branch', insurer_and_branch);
|
||
|
||
$('.loader').fadeIn();
|
||
$('.loader-mask').fadeIn();
|
||
|
||
$.ajax({
|
||
url: '<?= base_url('util/getInsurerBranchContacts/') ?>' + insurer_and_branch,
|
||
type: "GET",
|
||
dataType: 'json',
|
||
success: function(res) {
|
||
console.log(res)
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
if(res.status == false){
|
||
toastr.warning(res.message, 'WARNING')
|
||
}else{
|
||
appendInsurerContact(res.data)
|
||
}
|
||
},
|
||
error: function(xhr, status, error) {
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
console.error(xhr.responseText);
|
||
console.error(status, error);
|
||
}
|
||
});
|
||
}
|
||
|
||
function appendInsurerContact(data) {
|
||
|
||
console.log(data)
|
||
|
||
$('#placement_to').empty();
|
||
$('#placement_to').append($('<option>', {
|
||
value: '',
|
||
text: 'Select'
|
||
}));
|
||
|
||
$.each(data, function(index, item) {
|
||
var option = $('<option>', {
|
||
value: item.id,
|
||
text: item.contact_person_email
|
||
});
|
||
$('#placement_to').append(option);
|
||
});
|
||
}
|
||
|
||
$('.close').click(function(){
|
||
|
||
$('#to').select2({
|
||
placeholder: 'Select To Mail',
|
||
});
|
||
|
||
$('#cc').val('').select2({
|
||
placeholder : 'select CC Mail'
|
||
});
|
||
// $('#subject').val('');
|
||
$('#proposals').val('');
|
||
$('#placement_to').val('').select2({
|
||
placeholder : 'select To Mail'
|
||
});
|
||
$('#placement_cc').val('').select2({
|
||
placeholder : 'select CC Mail'
|
||
});
|
||
$('#placement_subject').val('');
|
||
|
||
$("textarea.select2-search__field").attr('rows', '1');
|
||
$("textarea.select2-search__field").css('resize', 'none');
|
||
})
|
||
|
||
</script>
|