6728 lines
255 KiB
PHP
6728 lines
255 KiB
PHP
<style>
|
||
/* Custom CSS */
|
||
body {
|
||
background-color: #f4f4f4;
|
||
color: #333;
|
||
/* padding: 20px; */
|
||
font-size: small;
|
||
}
|
||
|
||
.table-container {
|
||
overflow-x: auto;
|
||
/* margin-top: 20px; */
|
||
}
|
||
|
||
.table {
|
||
min-width: 100%;
|
||
table-layout: auto;
|
||
}
|
||
|
||
.table th,
|
||
.table td {
|
||
vertical-align: middle;
|
||
text-align: center;
|
||
text-wrap: pretty;
|
||
}
|
||
|
||
.table th,
|
||
.table td {
|
||
padding: 4px;
|
||
}
|
||
|
||
/* .table th[contenteditable],
|
||
.table td[contenteditable] {
|
||
border: 1px solid #007bff;
|
||
outline: none;
|
||
} */
|
||
|
||
#rfqTable th:nth-child(-n+3),
|
||
#rfqTable td:nth-child(-n+3) {
|
||
border: none;
|
||
}
|
||
|
||
#rfqTable th:nth-child(-n+3),
|
||
#rfqTable td:nth-child(-n+3) {
|
||
border: 2px solid #007bff;
|
||
}
|
||
|
||
#rfqTable th:nth-child(n+4),
|
||
#rfqTable td:nth-child(n+4) {
|
||
border: 2px solid #007bff;
|
||
outline: none;
|
||
}
|
||
|
||
#rfqTable thead th {
|
||
border-bottom: none !important;
|
||
}
|
||
|
||
/* Apply border to all columns */
|
||
#rfqTable_for_calc th,
|
||
#rfqTable_for_calc td {
|
||
border: 2px solid #007bff;
|
||
|
||
}
|
||
|
||
/* Remove border from first 2 and last column */
|
||
#rfqTable_for_calc th:nth-child(-n+2),
|
||
#rfqTable_for_calc td:nth-child(-n+2),
|
||
#rfqTable_for_calc th:last-child,
|
||
#rfqTable_for_calc td:last-child {
|
||
border: none;
|
||
}
|
||
|
||
.table th,
|
||
.table td {
|
||
min-width: 150px;
|
||
}
|
||
|
||
.table th.sno,
|
||
.table td.sno {
|
||
width: 10px;
|
||
background-color: #bfe0e2;
|
||
}
|
||
|
||
.table th.action,
|
||
.table td.action {
|
||
width: 200px;
|
||
}
|
||
|
||
.table th.sticky,
|
||
.table td.sticky {
|
||
position: sticky;
|
||
left: 0;
|
||
background-color: #bfe0e2;
|
||
z-index: 2;
|
||
width: 10px;
|
||
}
|
||
|
||
.suggestion-box {
|
||
border: 1px solid #ddd;
|
||
max-height: auto;
|
||
overflow-y: auto;
|
||
position: absolute;
|
||
background: #fff;
|
||
z-index: 100;
|
||
display: none;
|
||
width: auto;
|
||
background-color: #ff9999;
|
||
min-width: 80px !important;
|
||
text-align: center;
|
||
}
|
||
|
||
.suggestion-box ul {
|
||
list-style: none;
|
||
padding: 3px;
|
||
margin: 0;
|
||
list-style-type: square;
|
||
}
|
||
|
||
.suggestion-box ul li {
|
||
padding: 5px;
|
||
cursor: pointer;
|
||
|
||
}
|
||
|
||
.suggestion-box ul li:hover {
|
||
background-color: black;
|
||
color: #fff;
|
||
}
|
||
|
||
.btn-custom {
|
||
background-color: #007bff;
|
||
color: #fff;
|
||
margin-right: 10px;
|
||
}
|
||
|
||
.hidden {
|
||
display: none;
|
||
}
|
||
|
||
/* Style for the vertical three-dot menu */
|
||
.dropbtn {
|
||
background: none;
|
||
border: none;
|
||
font-size: 18px;
|
||
cursor: pointer;
|
||
}
|
||
|
||
.dropdown-content {
|
||
display: none;
|
||
position: absolute;
|
||
background-color: #f1f1f1;
|
||
min-width: 160px;
|
||
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
|
||
z-index: 1;
|
||
}
|
||
|
||
.dropdown-content a {
|
||
color: black;
|
||
padding: 12px 16px;
|
||
text-decoration: none;
|
||
display: block;
|
||
}
|
||
|
||
.dropdown-content a:hover {
|
||
background-color: #ddd;
|
||
}
|
||
|
||
/* .dropdown:hover .dropdown-content {
|
||
display: block;
|
||
}*/
|
||
|
||
.dialog {
|
||
display: none;
|
||
position: fixed;
|
||
left: 50%;
|
||
top: 50%;
|
||
transform: translate(-50%, -50%);
|
||
border: 1px solid #ccc;
|
||
background-color: #fff;
|
||
padding: 20px;
|
||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
||
z-index: 1000;
|
||
width: 300px;
|
||
}
|
||
|
||
.dialog-header {
|
||
font-size: 18px;
|
||
margin-bottom: 10px;
|
||
}
|
||
|
||
.dialog-content {
|
||
margin-bottom: 15px;
|
||
}
|
||
|
||
.dialog-footer {
|
||
text-align: right;
|
||
}
|
||
|
||
.dialog button {
|
||
padding: 5px 10px;
|
||
}
|
||
|
||
.hidden {
|
||
display: none;
|
||
}
|
||
|
||
.swal2-html-container {
|
||
overflow: hidden !important;
|
||
}
|
||
|
||
.bold {
|
||
font-weight: bold;
|
||
color: red;
|
||
}
|
||
|
||
.select2-selection__choice {
|
||
background-color: #0a8794 !important;
|
||
color: white !important;
|
||
font-weight: bold;
|
||
}
|
||
|
||
.select2-selection__choice__remove {
|
||
color: white !important;
|
||
margin-right: 5px;
|
||
}
|
||
|
||
.readonly-select {
|
||
pointer-events: none;
|
||
background-color: #f0f0f0;
|
||
color: #666;
|
||
}
|
||
|
||
/* table th.action,
|
||
table th.disableborder,
|
||
table td.action,
|
||
table td.disableborder {
|
||
border: none !important;
|
||
} */
|
||
|
||
.no-border {
|
||
border: none !important;
|
||
}
|
||
|
||
.save-indicator {
|
||
position: absolute;
|
||
top: 10px;
|
||
right: 10px;
|
||
background: #28a745;
|
||
color: white;
|
||
padding: 2px 8px;
|
||
border-radius: 10px;
|
||
font-size: 11px;
|
||
opacity: 0;
|
||
transition: opacity 0.3s;
|
||
}
|
||
|
||
.save-indicator.show {
|
||
opacity: 1;
|
||
}
|
||
|
||
</style>
|
||
|
||
<div class="row" id="inception_list">
|
||
<div class="col-12">
|
||
<div class="card">
|
||
<div class="card-body">
|
||
|
||
<div class="row" style="margin-bottom:1rem;">
|
||
<div class="col-6" style="align-self: center;">
|
||
<h4 style="position: relative;" id="rfq_qcr_page_title"> <?= isset($page_name) ? $page_name : 'RFQ' ?></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>
|
||
|
||
<button id="addQuote" class="btn btn-custom">Add New Proposal</button>
|
||
<button id="submitData" class="btn btn-primary">Save RFQ</button>
|
||
<?php if (in_array(get_role_id(), [1,2,5]) || in_array(BUSINESS_SUPPORT_TEAM_ID, user_team())) { ?>
|
||
<button id="submitQCRData" onclick="checkTheTableDataChanged(5)" class="btn btn-primary">Procced to QCR</button>
|
||
<?php } ?>
|
||
<a id="submitExcel" onclick="checkTheTableDataChanged(2)" class="btn btn-primary" id>Export Excel</a>
|
||
<button id="submitInternalMail" class="btn btn-primary" onclick="checkTheTableDataChanged(4)">Send Internal Mail</button>
|
||
<?php if (in_array(get_role_id(), [1,5]) || in_array(BUSINESS_SUPPORT_TEAM_ID, user_team()) || in_array(MANAGEMENT_TEAM_ID, user_team())) { ?>
|
||
<button id="submitMail" class="btn btn-primary"
|
||
onclick="checkTheTableDataChanged(3)">Send Insurer Mail</button>
|
||
<?php } ?>
|
||
<button id="submitPlacement" class="btn btn-primary" onclick="checkTheTableDataChanged(6)">Placement</button>
|
||
<input type="hidden" id="lead_id" name="lead_id" value="<?= isset($lead_id) ? $lead_id : '' ?>">
|
||
<input type="hidden" id="rfq_primaryKey" name="rfq_primaryKey" value="<?= isset($rfq_data['id']) ? $rfq_data['id'] : '' ?>">
|
||
<input type="hidden" id="qcr_count" value="<?= isset($qcr_count) ? $qcr_count : 0 ?>">
|
||
<!-- <button id="openDialogBtn">Open Dialog</button> -->
|
||
|
||
<div class="save-indicator" id="saveIndicator">Saved</div>
|
||
<div class="table-container" id="first_table">
|
||
<table id="rfqTable" class="table table-bordered mt-3">
|
||
<thead>
|
||
<tr>
|
||
<th class="sticky no-border" style="border-right: 2px solid rgb(0, 123, 255) !important; border-left: 2px solid rgb(0, 123, 255) !important; border-top: 2px solid rgb(0, 123, 255) !important; min-width: 72px !important;"><span class="key_name" style="display: none;">Sno</span><span class="display_name">S.No.</span></th>
|
||
<th class="hidden no-border" style="border-right: 2px solid rgb(0, 123, 255) !important;">Item Key</th>
|
||
<th class="sticky no-border" style="border-top: 2px solid rgb(0, 123, 255) !important; border-right: 2px solid rgb(0, 123, 255) !important;">Particulars</th>
|
||
<th contenteditable="false" id="first_proposel_title" ><span class="key_name" style="display: none;">Proposal 1</span><span class="display_name">Proposal Coverage 1</span>
|
||
<span class="dropdown" onclick="showThreeDottedMenu(event)">
|
||
<button class="dropbtn">⋮</button>
|
||
<div class="dropdown-content">
|
||
<a href="#" class="addInsurer">Add Insurer</a>
|
||
<a href="#" class="qcrProposal"
|
||
style="background-color: rgb(221, 221, 221);">QCR <i
|
||
class="fa fa-check-square"
|
||
style="color: green; margin-left: 8px;"></i></a>
|
||
<a href="#" class="sendClientProposal"
|
||
style="background-color: rgb(221, 221, 221);">Send to Client <i
|
||
class="fa fa-check-square"
|
||
style="color: green; margin-left: 8px;"></i></a>
|
||
<a href="#" class="removeProposal">Remove</a>
|
||
</div>
|
||
</span>
|
||
</th>
|
||
<th class="action no-border" style="border-right: 2px solid rgb(0, 123, 255) !important; border-left: 2px solid rgb(0, 123, 255) !important; border-top: 2px solid rgb(0, 123, 255) !important;">Action</th>
|
||
</tr>
|
||
<tr>
|
||
<th class="sticky no-border" style="color: rgb(191, 224, 226); border-right: 2px solid rgb(0, 123, 255) !important; border-left: 2px solid rgb(0, 123, 255) !important; min-width: 72px !important;"> - </th>
|
||
<th class="hidden no-border" style="color: #bfe0e2; border-right: 2px solid rgb(0, 123, 255) !important;"> - </th>
|
||
<th class="sticky no-border" style="color: rgb(191, 224, 226); border-bottom: 2px solid rgb(0, 123, 255) !important; border-right: 2px solid rgb(0, 123, 255) !important;"> - </th>
|
||
<th colspan="X" style="background-color: inherit;"><span class="key_name" style="display: none;">Quote Asked</span><span class="display_name">Quote Asked</span></th>
|
||
<th class="action no-border" style="color: rgb(255, 255, 255); border-right: 2px solid rgb(0, 123, 255) !important; border-left: 2px solid rgb(0, 123, 255) !important;"> - </th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td class="sno" style="min-width: 72px !important;">1</td>
|
||
<td class="hidden"></td>
|
||
<td contenteditable="true" class="particulars sticky"></td>
|
||
<td contenteditable="true" class="editablecolumns"></td>
|
||
<td class="action">
|
||
<input type="checkbox" name="qcr" onchange="setRowWiseQCRandSTCDatachange(this)"> <span class="qcr_check_box_title">QCR</span>
|
||
<input type="checkbox" name="client" onchange="setRowWiseQCRandSTCDatachange(this)"> Client
|
||
<button class="btn btn-danger btn-sm removeRow">−</button>
|
||
<button id="addRow" onclick="addRow(event)"
|
||
class="btn btn-primary btn-sm">+</button>
|
||
</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
|
||
<!-- <button id="getjson" class="btn btn-primary" onclick="generateJSONFromTable()">getjson</button> -->
|
||
|
||
<div class="table-container" id="second_table" style="display: none;">
|
||
<table id="rfqTable_for_calc" class="table table-bordered mt-3">
|
||
</table>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div><!-- end col -->
|
||
</div>
|
||
<!-- end table row -->
|
||
|
||
<div id="second"></div>
|
||
|
||
<!-- Suggestion Box -->
|
||
<div id="suggestionBox" class="suggestion-box">
|
||
<div class="text-right" style="padding-right: 10px;">
|
||
<i class="fa fa-times remove-icon" aria-hidden="true" style="color: black;text-align: right;"
|
||
onclick="hideSuggestionBox()"></i>
|
||
</div>
|
||
<ul id="suggestionList"></ul>
|
||
<!-- <br>
|
||
<div class="text-center p-2"> -->
|
||
<!-- <button id="addNewItem" class="btn btn-primary btn-sm" style="background-color: black;">Add New Item</button></div> -->
|
||
</div>
|
||
|
||
<!-- familiy floater dialog -->
|
||
<div class="dialog" id="familyFloaterDialog">
|
||
<div class="dialog-header">Family Members <i class="fa fa-times remove-icon" id="closeDialogBtn" aria-hidden="true"
|
||
style="color: black;text-align: right;margin-left: 99px;"></i></div>
|
||
<div class="dialog-content">
|
||
<label>
|
||
<input type="checkbox" id="family_self" checked>
|
||
Self
|
||
</label><br>
|
||
<label>
|
||
<input type="checkbox" id="family_spouse">
|
||
Spouse
|
||
</label><br>
|
||
<label for="children">Children:</label>
|
||
<select class="form-control" id="family_children">
|
||
<option value="0">0</option>
|
||
<option value="1">1</option>
|
||
<option value="2">2</option>
|
||
<option value="3">3</option>
|
||
<option value="4">4</option>
|
||
</select><br>
|
||
<label for="otherMembers">Other Members:</label>
|
||
<select class="form-control" id="family_other_members" onchange="setEldersCount(this)">
|
||
<option value="0">Select</option>
|
||
<option data-value="1" value="oneparent">Only one parent (Either Father / Mother)</option>
|
||
<option data-value="2" value="twoparent">Only two parents (Father+Mother)</option>
|
||
<option data-value="1" value="onepil">Only one parent in law (Either MIL / FIL)</option>
|
||
<option data-value="2" value="twopil">Only two parents in law (FIL + MIL)</option>
|
||
<option data-value="2" value="either_par_pil">Parents or PIL (Any two of Father, Mother, MIl, FIL)</option>
|
||
<option data-value="2" value="any_two">Either Parents or PIL (Parents or Parents In Law)</option>
|
||
<option data-value="4" value="all">Parents + PIL (Father + Mother + MIL + FIL)</option>
|
||
</select><br>
|
||
<label for="eldersCount">Elders Count:</label>
|
||
<input class="form-control" type="text" id="family_elders_count" readonly>
|
||
<input type="text" id="familiy_dialog_row_index" style="display: none;" readonly>
|
||
<input type="text" id="familiy_dialog_column_index" style="display: none;" readonly>
|
||
</div>
|
||
<div class="dialog-footer">
|
||
<button class="btn btn-primary btn-sm" id="savefamiliy" onclick="saveFamilyMembersDetails()">save</button>
|
||
</div>
|
||
</div>
|
||
<!-- familiy floater dialog end -->
|
||
|
||
<!-- 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>
|
||
|
||
<br>
|
||
<h4>Attachments Files</h4>
|
||
<hr>
|
||
|
||
<div class="form-group" id="insurer_or_clinet_mail_attachment">
|
||
<div class="form-row" >
|
||
<?php echo isset($attachment_html) && !empty($attachment_html) ? $attachment_html : ''; ?>
|
||
</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($page_name == "RFQ") { $exclusiveUserList = $userList; } ?>
|
||
<?php if (isset($exclusiveUserList)) { ?>
|
||
<?php foreach ($exclusiveUserList as $user) { ?>
|
||
<?php if ($page_name == "RFQ" || in_array($user['role'],[1,5]) || in_array($user['team_id'],[6,7])) { ?>
|
||
<option value="<?= $user['id'];?>">
|
||
<?= $user['first_name'].' - '.$user['email'];?>
|
||
</option>
|
||
<?php } ?>
|
||
<?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>
|
||
<h4>Attachments Files</h4>
|
||
<hr>
|
||
|
||
<div class="form-group" id="internal_mail_attachment">
|
||
<div class="form-row" >
|
||
<?php echo isset($attachment_html) && !empty($attachment_html) ? $attachment_html : ''; ?>
|
||
</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="policy_start_date">Policy Start Date</label>
|
||
<input type="text" class="form-control" id="policy_start_date" name="policy_start_date" placeholder="DD/MM/YYY" value="<?= isset($lead_data['policy_start_date']) ? date('d-m-Y', strtotime($lead_data['policy_start_date'])) : "" ?>">
|
||
</div>
|
||
|
||
<div class="form-group col-md-3">
|
||
<label for="policy_end_date">Policy End Date</label>
|
||
<input type="text" class="form-control" id="policy_end_date" name="policy_end_date" placeholder="DD/MM/YYY" value="<?= isset($lead_data['policy_end_date']) ? date('d-m-Y', strtotime($lead_data['policy_end_date'])) : "" ?>">
|
||
</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" value="<?= isset($lead_data['placement_date']) ? date('d-m-Y', strtotime($lead_data['placement_date'])) : "" ?>">
|
||
</div>
|
||
|
||
<div class="form-group col-md-3">
|
||
<label for="is_cd_switch">CD Entry</label>
|
||
<input id="is_cd_switch" type="checkbox" name = "is_cd" value = "1" data-toggle="toggle" data-on="With CD" data-off="Without CD" data-onstyle="info" data-offstyle="dark" data-style="border" data-width="218" <?= isset($lead_data['is_cd']) && $lead_data['is_cd'] != 1 ? '' : 'checked' ?>>
|
||
</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" value="<?= isset($lead_data['premium_amount']) ? $lead_data['premium_amount'] : "" ?>">
|
||
</div>
|
||
|
||
<?php if (isset($lead_data['is_cd']) && $lead_data['is_cd'] == 1 || !isset($lead_data['is_cd'])) { ?>
|
||
|
||
<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" value="<?= isset($lead_data['cd_amount']) ? $lead_data['cd_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" value="<?= isset($lead_data['cd_amount']) ? $lead_data['cd_amount'] : "" ?>">
|
||
</div>
|
||
|
||
<?php } ?>
|
||
|
||
<div class="form-group col-md-3">
|
||
<label for="is_installment_switch">Installment </label>
|
||
<input id="is_installment_switch" type="checkbox" name = "is_installment" value = "1" data-toggle="toggle" data-on="With Installments" data-off="Without Installments" data-onstyle="info" data-offstyle="dark" data-style="border" data-width="218" <?= isset($lead_data['is_installment']) && $lead_data['is_installment'] == 1 ? 'checked' : '' ?>>
|
||
</div>
|
||
|
||
<div class="form-group col-md-3" style="<?= (!empty($lead_data['is_installment']) && $lead_data['is_installment'] == 1) ? 'display: block;' : 'display: none;' ?>">
|
||
<label for="no_of_installment">No of Installments</label>
|
||
<input type="text" class="form-control" id="no_of_installment" name="no_of_installment"
|
||
value="<?= isset($lead_data['no_of_installment']) ? $lead_data['no_of_installment'] : 1 ?>">
|
||
</div>
|
||
</div>
|
||
<div class="row" id="not_installment">
|
||
|
||
<?php if (isset($lead_data['is_installment']) && $lead_data['is_installment'] == 0 || !isset($lead_data['is_installment'])) { ?>
|
||
<div class="form-group col-md-3">
|
||
<label for="payment_date">Payment Date</label>
|
||
<input type="text" class="form-control payment_date" id="payment_date" name="payment_date" placeholder="DD/MM/YYY" value="<?= isset($lead_data['payment_date']) ? date('d-m-Y', strtotime($lead_data['payment_date'])) : "" ?>">
|
||
</div>
|
||
|
||
<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." value="<?= isset($lead_data['utr_no']) ? $lead_data['utr_no'] : "" ?>">
|
||
</div>
|
||
|
||
<?php } ?>
|
||
</div>
|
||
|
||
<!-- </div> -->
|
||
|
||
<hr>
|
||
<div id="installment_form_row">
|
||
<?= isset($lead_data['is_installment']) && $lead_data['is_installment'] == 1 && isset($lead_data['installment_data']) && !empty($lead_data['installment_data']) ? $lead_data['installment_data'] : '' ?>
|
||
</div>
|
||
<hr>
|
||
|
||
<div class="form-row">
|
||
|
||
<div class="form-group col-md-6">
|
||
<label for="proposals"> Proposal(s) / Insurer(s) <span id="base_danger"class="text-danger">*</span></label>
|
||
<select class="form-control" id="proposals"name="proposals" onchange="getInsurerBranchContacts(this)" required>
|
||
<option value="" >Select a Proposal</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($page_name == "RFQ") { $exclusiveUserList = $userList; } ?>
|
||
<?php if (isset($exclusiveUserList)) { ?>
|
||
>
|
||
<?php foreach ($exclusiveUserList as $user) { ?>
|
||
<?php if ($page_name == "RFQ" || in_array($user['role'],[1,5]) || in_array($user['team_id'],[6,7])) { ?>
|
||
<option value="<?= $user['email'];?>">
|
||
<?= $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($placement_subject) ? $placement_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($placement_mail_content) ? $placement_mail_content : " " ?></textarea>
|
||
</div>
|
||
</div>
|
||
|
||
</div>
|
||
|
||
<br>
|
||
<h4>Attachments Files</h4>
|
||
<hr>
|
||
|
||
<div class="form-group" id="placement_mail_attachment">
|
||
<div class="form-row" >
|
||
<?php echo isset($attachment_html) && !empty($attachment_html) ? $attachment_html : ''; ?>
|
||
</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 isFormDataModified = false;
|
||
|
||
var suggestionKeys = []; // Local variable to store keys
|
||
var suggestions = {};
|
||
var RFQ_or_QCR = 0; //check this variable current page is RFQ(1) or QCR(2)
|
||
var insurer_count = 0
|
||
var proposalDataForDropDown = {};
|
||
var policy_terms = {};
|
||
var premium_data_check = false;
|
||
var user_role_id = <?= get_role_id(); ?>;
|
||
var jsonDataForHide = null;
|
||
var multi_file_data = [];
|
||
var totalSumAssuredData = [];
|
||
var snoColumnWidth = "72px";
|
||
var borderPixel = "2px solid #007bff";
|
||
|
||
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 type = segments[segments.length - 1]; // Get the last segment (2)
|
||
|
||
console.log('Lead ID:', lead_id);
|
||
console.log('Type:', type);
|
||
|
||
let titile_client_name = "<?= isset($lead_data) ? $lead_data['client_name'] : '' ?>";
|
||
multi_file_data = <?= isset($multi_file_data) ? json_encode($multi_file_data) : '[]' ?>;
|
||
appendMultiFileData(multi_file_data)
|
||
RFQ_or_QCR = type;
|
||
|
||
var type_for_url = 1;
|
||
if (type == 2) {
|
||
type_for_url = 2
|
||
$('#submitData').hide();
|
||
$('#submitQCRData').text('Save');
|
||
$('#rfq_qcr_page_title').text('QCR - ' + titile_client_name)
|
||
} else {
|
||
$('#submitData').show();
|
||
$('#submitQCRData').text('Proceed to QCR');
|
||
$('#rfq_qcr_page_title').text('RFQ - ' + titile_client_name)
|
||
}
|
||
|
||
let excel_url = '<?= base_url('leads/exportQCRandRFQ/') ?>' + lead_id + '/' + type_for_url + '/' + 1
|
||
$('#submitExcel').attr('data-url', excel_url);
|
||
|
||
// let mail_url = '<?= base_url('leads/exportQCRandRFQ/') ?>' + lead_id + '/' + type_for_url + '/' + 'mail'
|
||
// $('#submitMail').attr('data-url', mail_url);
|
||
|
||
console.log('RFQ_or_QCR:', RFQ_or_QCR);
|
||
|
||
});
|
||
|
||
$(document).ready(function() {
|
||
|
||
// Ensure that $rfq_data is properly encoded and check for null/undefined
|
||
let data = <?= isset($rfq_data) ? json_encode($rfq_data['json']) : 'null' ?>;
|
||
let rfq_count = <?= isset($rfq_count) ? $rfq_count : 0 ?>;
|
||
console.log('rfq_count', rfq_count);
|
||
let qcr_count = <?= isset($qcr_count) ? $qcr_count : 0 ?>;
|
||
let question_json = <?= isset($question_json) ? json_encode($question_json) : 'null' ?>;
|
||
let policy_terms_json = <?= isset($policy_terms) ? json_encode($policy_terms) : 'null' ?>;
|
||
totalSumAssuredData = <?= isset($totalSumAssured) ? json_encode($totalSumAssured) : '[]' ?>;
|
||
console.log('totalSumAssuredData', totalSumAssuredData);
|
||
console.log('totalSumAssuredData.type', typeof totalSumAssuredData);
|
||
// console.log('policy_terms_json', policy_terms_json);
|
||
|
||
data = JSON.parse(data);
|
||
suggestions = JSON.parse(question_json);
|
||
policy_terms = JSON.parse(policy_terms_json);
|
||
|
||
jsonDataForHide = data?.premium_data ?? null;
|
||
console.log("data", data);
|
||
if(data){
|
||
proposalDataForDropDown = data.proposal_data;
|
||
if(!data.premium_data){
|
||
premium_data_check = true;
|
||
}
|
||
}
|
||
|
||
console.log('policy_terms', policy_terms);
|
||
console.log('JSON DATA', data);
|
||
console.log('suggestions data', suggestions);
|
||
// console.log(data.proposal_data.over_all_column_data['Proposal 1']['insurers']);
|
||
// console.log('insurer_count', insurer_count);
|
||
|
||
|
||
// Check if data is valid (not null or undefined) and is an object
|
||
if (data && typeof data === 'object') {
|
||
let insurer_count = data.proposal_data.over_all_column_data['Proposal 1']?.insurers?.length || 0;
|
||
jsonToTable(data);
|
||
} else {
|
||
addSuggestionsToTable();
|
||
attachEventListeners();
|
||
}
|
||
|
||
// if (rfq_count == 0) {
|
||
|
||
// $('#submitQCRData').hide();
|
||
// $('#submitExcel').hide();
|
||
// $('#submitMail').hide();
|
||
// $('#submitInternalMail').hide();
|
||
|
||
// } else {
|
||
|
||
// $('#submitQCRData').show();
|
||
// $('#submitExcel').show();
|
||
// $('#submitMail').show();
|
||
// $('#submitInternalMail').show();
|
||
// }
|
||
|
||
if(RFQ_or_QCR == 1){
|
||
|
||
$('#submitData').text('Save RFQ');
|
||
$('#submitMail').text('Send Insurer Mail');
|
||
$('#submitPlacement').hide();
|
||
document.getElementById("second_table")?.remove();
|
||
|
||
if(data){
|
||
$('#submitQCRData').show();
|
||
}else{
|
||
$('#submitQCRData').hide();
|
||
$('#submitMail').hide();
|
||
$('#submitExcel').hide();
|
||
$('#submitInternalMail').hide();
|
||
}
|
||
|
||
// if(jsonDataForHide){
|
||
// $('#second_table').hide();
|
||
// }else{
|
||
// document.getElementById("second_table")?.remove();
|
||
// }
|
||
|
||
}else{
|
||
|
||
$('#submitData').text('Save QCR');
|
||
$('#submitMail').text('Send Client Mail');
|
||
$('#submitData').show();
|
||
$('#second_table').show();
|
||
$('#submitPlacement').show();
|
||
$('#submitQCRData').hide();
|
||
}
|
||
|
||
if(RFQ_or_QCR == 1 && insurer_count > 0){
|
||
$('#submitMail').hide();
|
||
}
|
||
|
||
$('#cc').select2({
|
||
placeholder: 'Select CC Mail',
|
||
});
|
||
|
||
$('#placement_cc').select2({
|
||
placeholder: 'Select CC Mail',
|
||
});
|
||
|
||
$('#proposals').select2({
|
||
placeholder: 'Select 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.');
|
||
}
|
||
|
||
});
|
||
|
||
//JoDit editor
|
||
$(document).ready(function(){
|
||
|
||
// 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,
|
||
});
|
||
|
||
var payment_date_datePicker = flatpickr("#payment_date", {
|
||
dateFormat: "d-m-Y",
|
||
allowInput: false,
|
||
});
|
||
|
||
var policy_start_date_datePicker = flatpickr("#policy_start_date", {
|
||
dateFormat: "d-m-Y",
|
||
allowInput: false,
|
||
});
|
||
|
||
var policy_end_date_datePicker = flatpickr("#policy_end_date", {
|
||
dateFormat: "d-m-Y",
|
||
allowInput: false,
|
||
});
|
||
|
||
|
||
})
|
||
|
||
</script>
|
||
|
||
<script>
|
||
|
||
let intervalId;
|
||
|
||
$(document).ready(function () {
|
||
console.log("Document ready");
|
||
|
||
let lead_status = '<?= isset($lead_data['status']) ? $lead_data['status'] : '' ?>';
|
||
console.log('Lead status retrieved:', lead_status);
|
||
|
||
if (lead_status != "won") {
|
||
console.log("Lead status is not 'won', setting interval for submitData");
|
||
|
||
startInterval();
|
||
} else {
|
||
console.log("Lead status is 'won', submitData will not be called");
|
||
}
|
||
});
|
||
|
||
function startInterval() {
|
||
intervalId = setInterval(function () {
|
||
console.log("Calling submitData(1) at 20-second interval");
|
||
submitData(1);
|
||
}, 20000);
|
||
}
|
||
|
||
|
||
|
||
const openDialogBtn = document.getElementById('openDialogBtn');
|
||
const closeDialogBtn = document.getElementById('closeDialogBtn');
|
||
|
||
// const familyFloaterDialog = document.getElementById('familyFloaterDialog');
|
||
|
||
// openDialogBtn.onclick = function() {
|
||
// familyFloaterDialog.style.display = 'block';
|
||
// };
|
||
|
||
// familyFloaterDialog.onclick = function() {
|
||
// myDialog.style.display = 'none';
|
||
// };
|
||
$('.remove-icon').on('click', function() {
|
||
$('#familyFloaterDialog').css('display', 'none');
|
||
});
|
||
|
||
var currentThrdottedMenu = '';
|
||
var proposal_colum_count = 1;
|
||
|
||
var over_all_column_data = {
|
||
"Proposal 1": {
|
||
"qcr": 1,
|
||
"stc": 1,
|
||
'insurers': []
|
||
}
|
||
};
|
||
document.addEventListener('DOMContentLoaded', function () {
|
||
const textarea = document.getElementById('placement_mail_content');
|
||
const textarea2 = document.getElementById("placement_subject");
|
||
|
||
if (textarea) {
|
||
let content = textarea.value;
|
||
if (content.includes('QCR')) {
|
||
textarea.value = content.replace(/QCR/g, 'Placement');
|
||
}
|
||
}
|
||
|
||
if (textarea2){
|
||
let content = textarea2.value;
|
||
if (content.includes('QCR')) {
|
||
textarea2.value = content.replace(/QCR/g, 'Placement');
|
||
}
|
||
}
|
||
});
|
||
|
||
// document.addEventListener("DOMContentLoaded", function () {
|
||
const rfqTable = document.getElementById('rfqTable');
|
||
const addQuoteButton = document.getElementById('addQuote');
|
||
const submitButton = document.getElementById('submitData');
|
||
const suggestionBox = document.getElementById('suggestionBox');
|
||
const suggestionList = document.getElementById('suggestionList');
|
||
|
||
function showFamilyFloaterDialogBox(target) {
|
||
|
||
const familyFloaterDialog = document.getElementById('familyFloaterDialog');
|
||
if (familyFloaterDialog.style.display == 'block') {
|
||
familyFloaterDialog.style.display = 'none';
|
||
}
|
||
familyFloaterDialog.style.display = 'block';
|
||
console.log('showFamilyFloaterDialogBox');
|
||
let currentTD = getCellIndices(target);
|
||
console.log(currentTD);
|
||
|
||
//set current cell row, column in modal as hidden value
|
||
$('#familiy_dialog_row_index').val(currentTD.rowIndex);
|
||
$('#familiy_dialog_column_index').val(currentTD.columnIndex);
|
||
// alert(currentColumnIndex)
|
||
let parentId = target.parentElement.id
|
||
// alert(parentId);
|
||
let hiddenInput = target.querySelector('input[type="hidden"]');
|
||
// alert(hiddenInput);
|
||
let inputValue = hiddenInput ? hiddenInput.value : null;
|
||
// console.log('hidden input value');
|
||
console.log(inputValue);
|
||
if (inputValue !== null && inputValue !== '') {
|
||
//get stored familiy composition json if any in hidden input and display it
|
||
inputValue = JSON.parse(inputValue);
|
||
console.log('from hidden value');
|
||
console.log(inputValue);
|
||
|
||
setFamilyDialogValues(inputValue);
|
||
// return true;
|
||
}
|
||
|
||
// setCellInnerHTMLByCellIndex('rfqTable', currentTD.rowIndex, (currentTD.columnIndex), '<b>TEST</b>');
|
||
}
|
||
|
||
function saveFamilyMembersDetails() {
|
||
|
||
var rowIndex = $('#familiy_dialog_row_index').val();
|
||
var columnIndex = $('#familiy_dialog_column_index').val();
|
||
console.log('Incoming Cell Index');
|
||
console.log(rowIndex + '-' + columnIndex);
|
||
|
||
let self = $('#family_self').prop('checked') ? 1 : 0;
|
||
let spouse = $('#family_spouse').prop('checked') ? 1 : 0;
|
||
var children = $('#family_children').val();
|
||
var elders = $('#family_other_members').val();
|
||
var elders_count = $('#family_elders_count').val();
|
||
|
||
console.log('Current Family Modal Values');
|
||
console.log('self' + '-' + self);
|
||
console.log('spouse' + '-' + spouse);
|
||
console.log('children' + '-' + children);
|
||
console.log('elders' + '-' + elders);
|
||
console.log('elders_count' + '-' + elders_count);
|
||
|
||
var display_value = createFamilyDisplayString({
|
||
'self': self,
|
||
'spouse': spouse,
|
||
'children': children,
|
||
'family_other_members': elders,
|
||
'elders_count': elders_count
|
||
});
|
||
|
||
var hidden_value = createFamilyJSONString({
|
||
'self': self,
|
||
'spouse': spouse,
|
||
'children': children,
|
||
'family_other_members': elders,
|
||
'elders_count': elders_count
|
||
});
|
||
console.log('display string');
|
||
console.log(display_value);
|
||
|
||
console.log('JSON string');
|
||
console.log(hidden_value);
|
||
// input.innerText = '';
|
||
//hidden text box for store choosed answers object
|
||
// const hiddenInputBox = document.createElement('input');
|
||
// hiddenInputBox.type = 'hidden';
|
||
// hiddenInputBox.value = hidden_value;
|
||
|
||
let combinedContent = `<input type="hidden" value='${hidden_value}'>` + display_value;
|
||
setCellInnerHTMLByCellIndex('rfqTable', rowIndex, columnIndex, combinedContent);
|
||
resetFamiliyDialogModalValues();
|
||
$('#familyFloaterDialog').hide();
|
||
// input.appendChild(hiddenInputBox);
|
||
// // alert(input.innerText);
|
||
// input.appendChild(document.createTextNode(details.display_value));
|
||
// // input.innerHTML += details.display_value;
|
||
// // const row = input.closest('tr');
|
||
// // row.id = display_value;
|
||
// // row.querySelector('.hidden').innerText = display_value;
|
||
// hideSuggestionBox();
|
||
// handleChildQuestions(input);
|
||
}
|
||
|
||
function resetFamiliyDialogModalValues() {
|
||
$('#familiy_dialog_row_index').val('');
|
||
$('#familiy_dialog_column_index').val('');
|
||
// $('#family_self').val('');
|
||
$('#family_self').prop('checked', true); // Checks the checkbox
|
||
|
||
// $('#family_spouse').val('');
|
||
$('#family_spouse').prop('checked', false); // Checks the checkbox
|
||
$('#family_children').val(0)
|
||
$('#family_other_members').val('0');
|
||
$('#family_elders_count').val(0);
|
||
}
|
||
|
||
function createFamilyDisplayString(familyArray) {
|
||
|
||
let displayString = [];
|
||
|
||
// Add 'self' if the value is 1 (true)
|
||
if (familyArray['self']) {
|
||
displayString.push('Self');
|
||
}
|
||
|
||
// Add 'spouse' if the value is 1 (true)
|
||
if (familyArray['spouse']) {
|
||
displayString.push('Spouse');
|
||
}
|
||
|
||
// Add 'children(count)' if count > 0
|
||
if (familyArray['children'] > 0) {
|
||
displayString.push(`Children(${familyArray['children']})`);
|
||
}
|
||
|
||
// Handle family_other_members values
|
||
let familyOtherMembersMap = {
|
||
'oneparent': 'One Parent',
|
||
'twoparent': 'Two Parents',
|
||
'onepil': 'One Parent-in-law',
|
||
'twopil': 'Two Parents-in-law',
|
||
'either_par_pil': 'Either Two Parents or Two Parents-in-law',
|
||
'any_two': 'Any Two Parents or Parents-in-law',
|
||
'all': 'All Four Parents/Parents-in-law'
|
||
};
|
||
|
||
if (familyArray['family_other_members'] && familyOtherMembersMap[familyArray['family_other_members']]) {
|
||
displayString.push(familyOtherMembersMap[familyArray['family_other_members']]);
|
||
}
|
||
|
||
// Join the array with ' + ' to create the final display string
|
||
return displayString.join(' + ');
|
||
}
|
||
|
||
function createFamilyJSONString(familyArray) {
|
||
let result = {
|
||
"self": familyArray['self'] || 0,
|
||
"spouse": familyArray['spouse'] || 0,
|
||
"childrens": familyArray['children'] || 0,
|
||
"parents": 0,
|
||
"parents-in-law": 0,
|
||
"either-parents-pil": 0,
|
||
"elders_count": familyArray['elders_count'] || "0"
|
||
};
|
||
|
||
// Process the family_other_members values to set parents and parents-in-law
|
||
switch (familyArray['family_other_members']) {
|
||
case 'oneparent':
|
||
result['parents'] = 1;
|
||
result['elders_count'] = 1;
|
||
break;
|
||
case 'twoparent':
|
||
result['parents'] = 2;
|
||
result['elders_count'] = 2;
|
||
break;
|
||
case 'onepil':
|
||
result['parents-in-law'] = 1;
|
||
result['elders_count'] = 1;
|
||
break;
|
||
case 'twopil':
|
||
result['parents-in-law'] = 2;
|
||
result['elders_count'] = 2;
|
||
break;
|
||
case 'either_par_pil':
|
||
result['either-parents-pil'] = 1;
|
||
result['elders_count'] = 2;
|
||
break;
|
||
case 'any_two':
|
||
result['either-parents-pil'] = 2;
|
||
result['elders_count'] = 2;
|
||
break;
|
||
case 'all':
|
||
result['parents'] = 2;
|
||
result['parents-in-law'] = 2;
|
||
result['elders_count'] = 4;
|
||
break;
|
||
}
|
||
|
||
// Convert the result object to a JSON string
|
||
return JSON.stringify(result);
|
||
}
|
||
|
||
function setFamilyDialogValues(familyData) {
|
||
// Set Self checkbox
|
||
$('#family_self').prop('checked', familyData.self === 1);
|
||
|
||
// Set Spouse checkbox
|
||
$('#family_spouse').prop('checked', familyData.spouse === 1);
|
||
|
||
// Set Children select
|
||
$('#family_children').val(familyData.childrens);
|
||
|
||
// Determine which value to select for family other members (parents, parents-in-law)
|
||
if (familyData.parents === 1) {
|
||
$('#family_other_members').val('oneparent');
|
||
} else if (familyData.parents === 2) {
|
||
$('#family_other_members').val('twoparent');
|
||
} else if (familyData["parents-in-law"] === 1) {
|
||
$('#family_other_members').val('onepil');
|
||
} else if (familyData["parents-in-law"] === 2) {
|
||
$('#family_other_members').val('twopil');
|
||
} else if (familyData["either-parents-pil"] === 1) {
|
||
$('#family_other_members').val('either_par_pil');
|
||
} else if (familyData["either-parents-pil"] === 2) {
|
||
$('#family_other_members').val('any_two');
|
||
} else if (familyData["either-parents-pil"] === 3) {
|
||
$('#family_other_members').val('all');
|
||
}
|
||
|
||
// Set Elders Count (readonly input)
|
||
$('#family_elders_count').val(familyData.elders_count);
|
||
}
|
||
|
||
function addSuggestionsToTable() {
|
||
|
||
var tbody = $("#rfqTable tbody");
|
||
|
||
tbody.empty(); // Clear any existing rows in the tbody
|
||
// return;
|
||
if (suggestions) {
|
||
|
||
console.log(' addSuggestionsToTable suggestions ', suggestions);
|
||
console.log(' addSuggestionsToTable suggestions type', typeof suggestions);
|
||
console.log(' over_all_column_data', over_all_column_data);
|
||
let leadType = <?= isset($lead_data) && isset($lead_data['lead_type']) ? $lead_data['lead_type'] : 1; ?>;
|
||
console.log('leadType', leadType);
|
||
|
||
let renewal_or_rollover = "Proposal 1";
|
||
let renewal_or_rollover_display_name = "Proposal Coverage 1";
|
||
if (leadType == 2) {
|
||
renewal_or_rollover = "Existing Renewal";
|
||
renewal_or_rollover_display_name = "Existing Coverage";
|
||
} else if (leadType == 3) {
|
||
renewal_or_rollover = "Existing Rollover";
|
||
renewal_or_rollover_display_name = "Existing Coverage";
|
||
}
|
||
|
||
over_all_column_data = {
|
||
[renewal_or_rollover]: {
|
||
"qcr": 1,
|
||
"stc": 1,
|
||
"insurers": []
|
||
}
|
||
};
|
||
|
||
console.log('renewal_or_rollover', renewal_or_rollover);
|
||
console.log(' over_all_column_data', over_all_column_data);
|
||
|
||
|
||
$('#first_proposel_title').html(`
|
||
<span class="key_name" style="display: none;">${renewal_or_rollover}</span><span class="display_name">${renewal_or_rollover_display_name}</span>
|
||
<span class="dropdown" onclick="showThreeDottedMenu(event)">
|
||
<button class="dropbtn">⋮</button>
|
||
<div class="dropdown-content">
|
||
<a href="#" class="addInsurer">Add Insurer</a>
|
||
<a href="#" class="qcrProposal" style="background-color: rgb(221, 221, 221);">
|
||
QCR <i class="fa fa-check-square" style="color: green; margin-left: 8px;"></i>
|
||
</a>
|
||
<a href="#" class="sendClientProposal" style="background-color: rgb(221, 221, 221);">
|
||
Send to Client <i class="fa fa-check-square" style="color: green; margin-left: 8px;"></i>
|
||
</a>
|
||
<a href="#" class="removeProposal">Remove</a>
|
||
</div>
|
||
</span>
|
||
`);
|
||
|
||
if (policy_terms && RFQ_or_QCR == 1) {
|
||
|
||
|
||
let special_condition_count = 0;
|
||
|
||
if (policy_terms['special_condition_label']) {
|
||
special_condition_count += policy_terms['special_condition_label'].length;
|
||
}
|
||
|
||
if (policy_terms['gpa_special_condition_label']) {
|
||
special_condition_count += policy_terms['gpa_special_condition_label'].length;
|
||
}
|
||
|
||
console.log(special_condition_count);
|
||
|
||
for (let i = 1; i < special_condition_count; i++) {
|
||
suggestions[`special_condition_${i + 1}`] = {
|
||
"display_values": `Special condition ${i + 1}`,
|
||
"answers": [],
|
||
"type": "text",
|
||
"object_value": 0
|
||
};
|
||
}
|
||
}
|
||
|
||
let special_condition_index = 0;
|
||
for (const [key, details] of Object.entries(suggestions)) {
|
||
|
||
const newRow = tbody[0].insertRow();
|
||
newRow.setAttribute('id', key); // Set the row ID to the suggestion key
|
||
|
||
const snoCell = newRow.insertCell(0);
|
||
snoCell.classList.add('sno');
|
||
snoCell.innerText = tbody[0].rows.length;
|
||
snoCell.style.setProperty('min-width', snoColumnWidth, 'important');
|
||
|
||
const hiddenCell = newRow.insertCell(1);
|
||
hiddenCell.classList.add('hidden');
|
||
hiddenCell.innerText = key;
|
||
|
||
const particularsCell = newRow.insertCell(2);
|
||
particularsCell.setAttribute('contenteditable', 'true');
|
||
particularsCell.classList.add('particulars', 'sticky');
|
||
particularsCell.innerText = details.display_values;
|
||
|
||
const columnCount = $("#rfqTable thead tr th").length;
|
||
// console.log('columnCount' + columnCount);
|
||
|
||
for (let i = 3; i < columnCount - 6; i++) {
|
||
|
||
const editableCell = newRow.insertCell(i);
|
||
editableCell.setAttribute('contenteditable', 'true');
|
||
editableCell.classList.add('editablecolumns');
|
||
const inputBox = document.createElement('input');
|
||
inputBox.type = 'hidden';
|
||
|
||
//add default values for default proposal for both hidden valuse as well as cell textContent
|
||
if(policy_terms && RFQ_or_QCR == 1){
|
||
|
||
if (policy_terms[key] == 1) {
|
||
|
||
if (details.answers[0]) {
|
||
editableCell.textContent = details.answers[0].display_value || '';
|
||
inputBox.value = JSON.stringify(details.answers[0]);
|
||
} else {
|
||
editableCell.textContent = '';
|
||
inputBox.value = '';
|
||
}
|
||
|
||
} else if (policy_terms[key] == 0) {
|
||
if (details.answers[1]) {
|
||
editableCell.textContent = details.answers[1].display_value || '';
|
||
inputBox.value = JSON.stringify(details.answers[1]);
|
||
} else {
|
||
editableCell.textContent = '';
|
||
inputBox.value = '';
|
||
}
|
||
} else if (policy_terms[key]) {
|
||
editableCell.textContent = policy_terms[key];
|
||
inputBox.value = JSON.stringify(policy_terms[key]);
|
||
} else {
|
||
editableCell.textContent = '';
|
||
inputBox.value = '';
|
||
}
|
||
|
||
if(key == 'family_composition'){
|
||
editableCell.textContent = createFamilyDisplayStringPolicyTerms(policy_terms['family_floaters']);
|
||
inputBox.value = JSON.stringify(policy_terms['family_floaters']);
|
||
}
|
||
|
||
if (key.startsWith('special_condition')) {
|
||
|
||
if(policy_terms.hasOwnProperty('special_condition_label')){
|
||
|
||
if(policy_terms['special_condition_label'] != "" && Array.isArray(policy_terms['special_condition_label'])){
|
||
editableCell.textContent = policy_terms['special_condition_label'][special_condition_index] + ' - ' + policy_terms['special_condition_input'][special_condition_index];
|
||
inputBox.value = policy_terms['special_condition_label'][special_condition_index] + '--' + policy_terms['special_condition_input'][special_condition_index];
|
||
special_condition_index++
|
||
}else{
|
||
editableCell.textContent = ""
|
||
inputBox.value = "";
|
||
special_condition_index++
|
||
}
|
||
|
||
}else{
|
||
|
||
|
||
if(policy_terms['gpa_special_condition_label'] != "" && Array.isArray(policy_terms['gpa_special_condition_label'])){
|
||
editableCell.textContent = policy_terms['gpa_special_condition_label'][special_condition_index] + ' - ' + policy_terms['gpa_special_condition_input'][special_condition_index];
|
||
inputBox.value = policy_terms['gpa_special_condition_label'][special_condition_index] + '--' + policy_terms['gpa_special_condition_input'][special_condition_index];
|
||
special_condition_index++
|
||
}else{
|
||
editableCell.textContent = ""
|
||
inputBox.value = "";
|
||
special_condition_index++
|
||
}
|
||
}
|
||
}
|
||
|
||
}else{
|
||
|
||
if (details.answers.length != 0) {
|
||
inputBox.value = JSON.stringify(details.answers[0]);
|
||
editableCell.textContent = (details.answers[0].display_value);
|
||
}
|
||
}
|
||
|
||
editableCell.appendChild(inputBox);
|
||
// Additional handling can be added here for 'answers' or 'type'
|
||
}
|
||
|
||
const actionCell = newRow.insertCell(-1);
|
||
actionCell.classList.add('action');
|
||
actionCell.innerHTML =
|
||
'<input type="checkbox" name="qcr" onchange="setRowWiseQCRandSTCDatachange(this)" checked> <span class="qcr_check_box_title">QCR</span> <input type="checkbox" name="client" onchange="setRowWiseQCRandSTCDatachange(this)" checked> Client <button class="btn btn-danger btn-sm removeRow">−</button> ';
|
||
suggestionKeys.push(key);
|
||
}
|
||
}
|
||
|
||
moveAddRowButton();
|
||
hideQCR();
|
||
isFormDataModified = false;
|
||
processTotalSumInsured(totalSumAssuredData)
|
||
|
||
}
|
||
|
||
function processTotalSumInsured(data) {
|
||
let values = [];
|
||
|
||
if (Array.isArray(data)) {
|
||
data.forEach((value, index) => {
|
||
console.log('total - value', value);
|
||
if (index !== 0) {
|
||
$('#addQuote').click();
|
||
}
|
||
});
|
||
values = data
|
||
} else if (typeof data === 'object' && data !== null) {
|
||
$.each(data, function(key, value) {
|
||
console.log('total - value', value);
|
||
if (key != 0) {
|
||
$('#addQuote').click();
|
||
}
|
||
});
|
||
values = Object.values(data)
|
||
} else {
|
||
console.log("Data is not iterable.");
|
||
return;
|
||
}
|
||
|
||
// Set values in td.editablecolumns in order
|
||
$('#totalSumInsured .editablecolumns').each(function(index) {
|
||
if (values[index] !== undefined) {
|
||
$(this).text(values[index]);
|
||
}
|
||
});
|
||
}
|
||
|
||
|
||
// Function to move add row button to last row
|
||
function moveAddRowButton() {
|
||
|
||
// console.log('table', rfqTable)
|
||
const lastRow = rfqTable.rows[rfqTable.rows.length - 1];
|
||
const actionCell = lastRow.querySelector('.action');
|
||
|
||
if (actionCell && !actionCell.querySelector('#addRow')) {
|
||
actionCell.innerHTML += ' <button id="addRow" class="btn btn-primary btn-sm">+</button>';
|
||
document.getElementById('addRow').addEventListener('click', addRow);
|
||
}
|
||
|
||
// const actionCell = lastRow.cells[lastRow.cells.length - 1];
|
||
// actionCell.innerHTML =
|
||
// '<input type="checkbox" name="qcr"> QCR <input type="checkbox" name="client"> Client <button class="btn btn-danger btn-sm removeRow">−</button> <button id="addRow" class="btn btn-primary btn-sm">+</button>';
|
||
// document.getElementById('addRow').addEventListener('click', addRow);
|
||
|
||
// const lastRow = rows[rows.length - 1];
|
||
|
||
}
|
||
|
||
// Event listener to handle row removal
|
||
rfqTable.addEventListener('click', function(e) {
|
||
|
||
if (e.target.classList.contains('removeRow')) {
|
||
Swal.fire({
|
||
title: 'Are you sure?',
|
||
text: "Do you want to remove the row?",
|
||
icon: 'warning',
|
||
showCancelButton: true,
|
||
confirmButtonColor: '#d33',
|
||
cancelButtonColor: '#3085d6',
|
||
confirmButtonText: 'Yes, remove it!',
|
||
cancelButtonText: 'Cancel'
|
||
}).then((result) => {
|
||
if (result.isConfirmed) {
|
||
const row = e.target.closest('tr'); // Get the row to be removed
|
||
const rowKey = row.getAttribute('id');
|
||
|
||
console.log(suggestionKeys);
|
||
// Remove the key from suggestionKeys
|
||
suggestionKeys = suggestionKeys.filter(key => key !== rowKey);
|
||
row.remove();
|
||
console.log(suggestionKeys);
|
||
updateRowNumbers(); // Update row numbers
|
||
moveAddRowButton(); // Move the add row button to the last row
|
||
realignSpecialConditions();
|
||
|
||
isFormDataModified = true; // if any value changeing in the table to set true
|
||
}
|
||
})
|
||
|
||
|
||
}
|
||
|
||
});
|
||
|
||
// Function to add new columns
|
||
addQuoteButton.addEventListener('click', function() {
|
||
|
||
const headerRow = rfqTable.rows[0];
|
||
console.log('headerRow');
|
||
const secondHeaderRow = rfqTable.rows[1];
|
||
console.log(secondHeaderRow);
|
||
// alert('FH - ' + headerRow.cells.length + ' : SH - ' + secondHeaderRow.cells.length);
|
||
const newQuoteHeader = document.createElement('th');
|
||
newQuoteHeader.colspan = 1;
|
||
newQuoteHeader.setAttribute('data-colspan', 1)
|
||
|
||
const quoteCount = headerRow.cells.length - 4;
|
||
console.log('quoteCount', quoteCount);
|
||
console.log('quoteCount headerRow.cells', headerRow.cells);
|
||
|
||
const lastCellIndex = headerRow.cells.length - 1;
|
||
console.log('lastCellIndex : ', lastCellIndex);
|
||
|
||
// const secondLastCellValue = headerRow.cells[lastCellIndex - 1].textContent.trim();
|
||
let secondLastCellValue = headerRow.cells[lastCellIndex - 1];
|
||
console.log('SecondLastCellValue Instance : ', secondLastCellValue);
|
||
|
||
secondLastCellValue = (secondLastCellValue.querySelector('.key_name')?.innerText || '').trim();
|
||
console.log('SecondLastCellValue Text: ', secondLastCellValue);
|
||
|
||
// Split the second last cell's value and get the last part
|
||
const lastPart = secondLastCellValue?.split(" ")[1]?.trim() ?? "0";
|
||
console.log('lastPart : ', lastPart);
|
||
|
||
// Check if lastPart is a valid number; if not, default to 0
|
||
const proposalNumber = isNaN(Number(lastPart)) ? 0 : Number(lastPart);
|
||
console.log("proposalNumber:", proposalNumber);
|
||
|
||
proposal_colum_count = proposalNumber + 1;
|
||
console.log("proposal_colum_count:", proposal_colum_count);
|
||
|
||
// proposal_colum_count = proposal_colum_count + 1;
|
||
let new_proposal_name = `Proposal ${proposal_colum_count}`;
|
||
let new_proposal_name_display_name = "Proposal Coverage " + (proposal_colum_count);
|
||
|
||
newQuoteHeader.innerHTML = `
|
||
<span class="key_name" style="display: none;">${new_proposal_name}</span><span class="display_name">${new_proposal_name_display_name}</span>
|
||
<span class="dropdown" onclick="showThreeDottedMenu(event)">
|
||
<button class="dropbtn">⋮</button>
|
||
<div class="dropdown-content">
|
||
<!-- <a href="#" class="addInsurer">Add Insurer</a> -->
|
||
<a href="#" class="qcrProposal" style="background-color: rgb(221, 221, 221);">QCR <i class="fa fa-check-square" style="color: green; margin-left: 8px;"></i></a>
|
||
<a href="#" class="sendClientProposal" style="background-color: rgb(221, 221, 221);">Send to Client <i class="fa fa-check-square" style="color: green; margin-left: 8px;"></i></a>
|
||
<a href="#" class="removeProposal">Remove</a>
|
||
</div>
|
||
</span>`;
|
||
newQuoteHeader.setAttribute('contenteditable', 'false');
|
||
headerRow.insertBefore(newQuoteHeader, headerRow.cells[headerRow.cells.length - 1]);
|
||
// Generate random light background color
|
||
let randomColor = 'hsl(' + Math.random() * 360 + ', 100%, 93%)';
|
||
newQuoteHeader.style.backgroundColor = randomColor;
|
||
|
||
|
||
console.log('rows - ' + rfqTable.rows.length);
|
||
// Add a new column to each row
|
||
for (let i = 1; i < rfqTable.rows.length; i++) {
|
||
|
||
// console.log(rfqTable.rows[i]);
|
||
// console.log('fourth cell html', rfqTable.rows[i].cells[3]);
|
||
// console.log('fourth cell innerText', rfqTable.rows[i].cells[3].innerText);
|
||
|
||
if (i == 1) {
|
||
// Create a new <th> element
|
||
const newHeaderCell = document.createElement('th');
|
||
// newHeaderCell.innerHTML = ` Quote Asked `;
|
||
let subHeaderKeyName = "Quote Asked";
|
||
let subHeaderDisplayName = "Quote Asked";
|
||
newHeaderCell.innerHTML = `<span class="key_name" style="display: none;">${subHeaderKeyName}</span><span class="display_name">${subHeaderDisplayName}</span>`;
|
||
newHeaderCell.style.backgroundColor = randomColor;
|
||
// Insert the <th> element at the desired position
|
||
rfqTable.rows[i].insertBefore(newHeaderCell, rfqTable.rows[i].cells[secondHeaderRow.cells.length - 1]);
|
||
|
||
} else {
|
||
const newCell = rfqTable.rows[i].insertCell(secondHeaderRow.cells.length - 2);
|
||
newCell.setAttribute('contenteditable', 'true');
|
||
newCell.classList.add('editablecolumns');
|
||
newCell.innerHTML = rfqTable.rows[i].cells[3].innerHTML;
|
||
newCell.style.backgroundColor = randomColor;
|
||
}
|
||
|
||
}
|
||
attachEventListeners();
|
||
//add new proposal in gobal array
|
||
var new_proposal_array = {}
|
||
over_all_column_data[new_proposal_name] = {
|
||
"qcr": 1,
|
||
"stc": 1,
|
||
'insurers': []
|
||
};
|
||
|
||
isFormDataModified = true; // if any value changeing in the table to set true
|
||
|
||
console.log(over_all_column_data);
|
||
});
|
||
|
||
// Function to handle suggestion box
|
||
function showSuggestions(input) {
|
||
|
||
suggestionList.innerHTML = '';
|
||
const value = input.innerText.trim().toLowerCase();
|
||
const rowID = event.target.parentNode.id;
|
||
// const filteredSuggestions = Object.entries(suggestions);.filter(([key, details]) =>
|
||
// details.display_values.toLowerCase().includes(value)
|
||
// );
|
||
|
||
filteredSuggestions = Object.entries(suggestions);
|
||
filteredSuggestions.forEach(([key, details]) => {
|
||
const li = document.createElement('li');
|
||
li.innerText = details.display_values;
|
||
li.dataset.key = key;
|
||
suggestionList.appendChild(li);
|
||
li.addEventListener('click', function() {
|
||
// alert(value+' - '+key);
|
||
if ((rowID == "" || rowID != key) && suggestionKeys.includes(key) && key !=
|
||
'special_condition') {
|
||
alert('Duplicate entry detected');
|
||
return false; // Prevent adding duplicate
|
||
}
|
||
|
||
input.innerText = details.display_values;
|
||
const row = input.closest('tr');
|
||
row.id = key;
|
||
row.querySelector('.hidden').innerText = key;
|
||
suggestionKeys.push(key);
|
||
hideSuggestionBox();
|
||
realignSpecialConditions();
|
||
|
||
// Optionally handle 'answers' and 'type' here
|
||
// e.g., populate other cells based on details.answers and details.type
|
||
});
|
||
});
|
||
|
||
if (filteredSuggestions.length > 0) {
|
||
|
||
suggestionBox.style.display = 'block';
|
||
const rect = input.getBoundingClientRect();
|
||
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
|
||
const scrollLeft = window.pageXOffset || document.documentElement.scrollLeft;
|
||
suggestionBox.style.top = (rect.bottom + scrollTop) + 'px';
|
||
suggestionBox.style.left = (rect.left + scrollLeft) + 'px';
|
||
|
||
} else {
|
||
hideSuggestionBox();
|
||
}
|
||
}
|
||
|
||
// Function to handle answers suggestion box
|
||
function showAnswersSuggestions(input) {
|
||
console.log(input.parentElement.id);
|
||
console.log(input);
|
||
//return;
|
||
var questionItem = input.parentElement.id;
|
||
|
||
if (questionItem == 'family_composition') {
|
||
showFamilyFloaterDialogBox(input);
|
||
return;
|
||
}
|
||
if (questionItem.startsWith('special_condition')) {
|
||
return;
|
||
}
|
||
var questionAnswers = suggestions[questionItem]['answers'];
|
||
var questionType = suggestions[questionItem]['type'];
|
||
// console.log(questionItem);
|
||
// console.log(questionAnswers);
|
||
// console.log(questionType);
|
||
if (questionType == 'text') {
|
||
return;
|
||
}
|
||
|
||
suggestionList.innerHTML = '';
|
||
// const value = input.innerText.trim().toLowerCase();
|
||
// alert(value);
|
||
// const filteredSuggestions = questionAnswers.filter((details) => {
|
||
// // console.log(key);
|
||
// // console.log(details.display_value);
|
||
// return details.display_value.toLowerCase().includes(value)
|
||
// });
|
||
|
||
// console.log(filteredSuggestions);
|
||
// if (filteredSuggestions.length === 0) {
|
||
const filteredSuggestions = questionAnswers;
|
||
// }
|
||
//return;
|
||
|
||
filteredSuggestions.forEach((details) => {
|
||
console.log('building each answers');
|
||
const li = document.createElement('li');
|
||
li.innerText = details.display_value;
|
||
li.dataset.key = details.display_value;
|
||
suggestionList.appendChild(li);
|
||
li.addEventListener('click', function() {
|
||
|
||
input.innerText = '';
|
||
//hidden text box for store choosed answers object
|
||
const hiddenInputBox = document.createElement('input');
|
||
hiddenInputBox.type = 'hidden';
|
||
hiddenInputBox.value = JSON.stringify(details);
|
||
|
||
input.appendChild(hiddenInputBox);
|
||
// alert(input.innerText);
|
||
input.appendChild(document.createTextNode(details.display_value));
|
||
// input.innerHTML += details.display_value;
|
||
// const row = input.closest('tr');
|
||
// row.id = display_value;
|
||
// row.querySelector('.hidden').innerText = display_value;
|
||
hideSuggestionBox();
|
||
handleChildQuestions(input);
|
||
checkCellValueAndHighlight();
|
||
|
||
// Optionally handle 'answers' and 'type' here
|
||
// e.g., populate other cells based on details.answers and details.type
|
||
});
|
||
});
|
||
|
||
if (filteredSuggestions.length > 0) {
|
||
console.log('display suggestion box');
|
||
console.log(input.getBoundingClientRect().bottom + '-' + input.getBoundingClientRect().left);
|
||
suggestionBox.style.display = 'block';
|
||
const rect = input.getBoundingClientRect();
|
||
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
|
||
const scrollLeft = window.pageXOffset || document.documentElement.scrollLeft;
|
||
suggestionBox.style.top = (rect.bottom + scrollTop) + 'px';
|
||
suggestionBox.style.left = (rect.left + scrollLeft) + 'px';
|
||
|
||
// suggestionBox.style.top = '500px';
|
||
// suggestionBox.style.left = '900px';
|
||
} else {
|
||
console.log('hide suggestion box');
|
||
hideSuggestionBox();
|
||
}
|
||
}
|
||
|
||
document.addEventListener('input', function(e) {
|
||
if (e.target.classList.contains('particulars')) {
|
||
console.log(' show suggestions eventlistener ')
|
||
showSuggestions(e.target);
|
||
}
|
||
|
||
if (e.target.classList.contains('editablecolumns')) {
|
||
showAnswersSuggestions(e.target);
|
||
checkCellValueAndHighlight();
|
||
}
|
||
});
|
||
|
||
document.getElementById('rfqTable').addEventListener('focusout', function(e) {
|
||
// Ensure the event target is a td element
|
||
if (e.target && e.target.tagName === 'TD' && e.target.classList.contains('editablecolumns')) {
|
||
// validateCellContent(e.target);
|
||
}
|
||
if (e.target && e.target.tagName === 'TD' && e.target.classList.contains('particulars')) {
|
||
validateQuestionCellContent(e.target);
|
||
}
|
||
});
|
||
|
||
document.addEventListener('click', function(e) {
|
||
|
||
if (!e.target.closest('.suggestion-box') && !e.target.classList.contains('particulars')) {
|
||
suggestionBox.style.display = 'none';
|
||
}
|
||
|
||
if (e.target.classList.contains('particulars')) {
|
||
showSuggestions(e.target);
|
||
}
|
||
|
||
if (e.target.classList.contains('editablecolumns')) {
|
||
|
||
// console.log(e.target.innerText);
|
||
// if(e.target.innerText == '')
|
||
// {
|
||
// showAnswersSuggestions(e.target);
|
||
// }
|
||
|
||
if (e.target.isContentEditable) {
|
||
showAnswersSuggestions(e.target);
|
||
}
|
||
}
|
||
|
||
//hide currently showing any three dotted menu
|
||
if (currentThrdottedMenu != '') {
|
||
// console.log('currentThrdottedMenu hide called');
|
||
// Toggle the display property
|
||
if (currentThrdottedMenu.style.display === 'block') {
|
||
// console.log('currentThrdottedMenu hidden');
|
||
currentThrdottedMenu.style.display = 'none'; // Hide if it's already shown
|
||
currentThrdottedMenu = '';
|
||
} else {
|
||
currentThrdottedMenu.style.display = 'block'; // Show if it's hidden
|
||
}
|
||
}
|
||
});
|
||
|
||
function hideSuggestionBox() {
|
||
suggestionBox.style.display = 'none';
|
||
}
|
||
|
||
function addRow(e) {
|
||
|
||
let columnCount = rfqTable.rows[1].cells.length;
|
||
const newRow = rfqTable.insertRow();
|
||
|
||
const snoCell = newRow.insertCell(0);
|
||
snoCell.classList.add('sno');
|
||
snoCell.innerText = rfqTable.rows.length - 1;
|
||
|
||
const hiddenCell = newRow.insertCell(1);
|
||
hiddenCell.classList.add('hidden'); // Hidden column for item key
|
||
|
||
const particularsCell = newRow.insertCell(2);
|
||
particularsCell.setAttribute('contenteditable', 'true');
|
||
particularsCell.classList.add('particulars', 'sticky');
|
||
|
||
for (let i = 3; i < columnCount - 1; i++) {
|
||
const editableCell = newRow.insertCell(i);
|
||
editableCell.setAttribute('contenteditable', 'true');
|
||
editableCell.classList.add('editablecolumns');
|
||
}
|
||
|
||
const actionCell = newRow.insertCell();
|
||
actionCell.classList.add('action');
|
||
actionCell.innerHTML =
|
||
'<input type="checkbox" name="qcr" onchange="setRowWiseQCRandSTCDatachange(this)" checked> <span class="qcr_check_box_title">QCR</span> <input type="checkbox" name="client" onchange="setRowWiseQCRandSTCDatachange(this)" checked> Client <button class="btn btn-danger btn-sm removeRow">−</button> <button class="btn btn-primary btn-sm" onclick="addRow(event)">+</button>';
|
||
|
||
e.target.remove();
|
||
updateRowNumbers();
|
||
realignSpecialConditions();
|
||
|
||
isFormDataModified = true; // if any value changeing in the table to set true
|
||
}
|
||
|
||
// Function to update row numbers
|
||
function updateRowNumbers() {
|
||
|
||
// console.log('updateRowNumbers function called')
|
||
|
||
// const rows = rfqTable.tBodies[0].rows;
|
||
// console.log('rows', rows);
|
||
|
||
// for (let i = 0; i < rows.length; i++) {
|
||
// rows[i].cells[0].innerText = i + 1;
|
||
// }
|
||
|
||
const rows = rfqTable.tBodies[0].rows;
|
||
// console.log('rows', rows);
|
||
|
||
for (let i = 0, rowNumber = 1; i < rows.length; i++) {
|
||
const row = rows[i];
|
||
// Check if the row has the 'hidden' class
|
||
if (!row.classList.contains('hidden')) {
|
||
row.cells[0].innerText = rowNumber; // Set the row number
|
||
rowNumber++; // Increment row number only for visible rows
|
||
}
|
||
}
|
||
|
||
|
||
}
|
||
|
||
function realignSpecialConditions() {
|
||
// Get the table by ID
|
||
const table = document.getElementById('rfqTable');
|
||
if (!table) return;
|
||
|
||
// Initialize a counter for special conditions
|
||
let specialConditionCount = 1;
|
||
|
||
// Loop through each row in the table
|
||
const rows = table.getElementsByTagName('tr');
|
||
for (let i = 0; i < rows.length; i++) {
|
||
const row = rows[i];
|
||
const rowId = row.id; // Get the row ID
|
||
|
||
// Check if the row ID starts with "special_condition"
|
||
if (rowId.startsWith('special_condition')) {
|
||
// Update the row ID to special_condition_1, special_condition_2, etc.
|
||
const newId = `special_condition_${specialConditionCount}`;
|
||
row.id = newId;
|
||
|
||
// Update the inner text of the hidden cell (index 1)
|
||
const hiddenCell = row.getElementsByTagName('td')[1];
|
||
hiddenCell.innerText = newId;
|
||
|
||
// Update the inner text of the visible cell (index 0)
|
||
const visibleCell = row.getElementsByTagName('td')[2];
|
||
visibleCell.innerText = `Special condition ${specialConditionCount}`;
|
||
|
||
// Increment the special condition counter
|
||
specialConditionCount++;
|
||
}
|
||
}
|
||
}
|
||
|
||
function attachEventListeners() {
|
||
// Detach existing listeners before attaching new ones
|
||
detachDynamicEventListeners();
|
||
|
||
// Attach listeners to all elements with the class 'addInsurer'
|
||
document.querySelectorAll('.addInsurer').forEach(function(element) {
|
||
element.addEventListener('click', addInsurer);
|
||
});
|
||
|
||
document.querySelectorAll('.removeProposal').forEach(function(element) {
|
||
element.addEventListener('click', removeProposal);
|
||
});
|
||
|
||
document.querySelectorAll('.removeInsurer').forEach(function(element) {
|
||
element.addEventListener('click', removeInsurer);
|
||
});
|
||
|
||
document.querySelectorAll('.changeInsurer').forEach(function(element) {
|
||
element.addEventListener('click', changeInsurer);
|
||
});
|
||
|
||
document.querySelectorAll('.qcrProposal').forEach(function(element) {
|
||
element.addEventListener('click', changeState);
|
||
});
|
||
document.querySelectorAll('.sendClientProposal').forEach(function(element) {
|
||
element.addEventListener('click', changeState);
|
||
});
|
||
|
||
document.querySelectorAll('.qcrInsurer').forEach(function(element) {
|
||
element.addEventListener('click', changeState);
|
||
});
|
||
document.querySelectorAll('.sendClientInsurer').forEach(function(element) {
|
||
element.addEventListener('click', changeState);
|
||
});
|
||
|
||
document.querySelectorAll('.copyInsurerNext').forEach(function(element) {
|
||
element.addEventListener('click', dupInsurer);
|
||
});
|
||
document.querySelectorAll('.copyInsurerLast').forEach(function(element) {
|
||
element.addEventListener('click', dupInsurer);
|
||
});
|
||
// document.querySelectorAll('.editablecolumns').forEach(function(element) {
|
||
// element.addEventListener('input', showAnswersSuggestions(element));
|
||
// });
|
||
}
|
||
|
||
function detachDynamicEventListeners() {
|
||
|
||
document.querySelectorAll('.addInsurer').forEach(function(element) {
|
||
element.removeEventListener('click', addInsurer);
|
||
});
|
||
|
||
document.querySelectorAll('.changeInsurer').forEach(function(element) {
|
||
element.removeEventListener('click', changeInsurer);
|
||
});
|
||
|
||
document.querySelectorAll('.qcrProposal').forEach(function(element) {
|
||
element.removeEventListener('click', changeState);
|
||
});
|
||
document.querySelectorAll('.sendClientProposal').forEach(function(element) {
|
||
element.removeEventListener('click', changeState);
|
||
});
|
||
|
||
document.querySelectorAll('.qcrInsurer').forEach(function(element) {
|
||
element.removeEventListener('click', changeState);
|
||
});
|
||
document.querySelectorAll('.sendClientInsurer').forEach(function(element) {
|
||
element.removeEventListener('click', changeState);
|
||
});
|
||
|
||
document.querySelectorAll('.copyInsurerNext').forEach(function(element) {
|
||
element.removeEventListener('click', dupInsurer);
|
||
});
|
||
|
||
document.querySelectorAll('.copyInsurerLast').forEach(function(element) {
|
||
element.removeEventListener('click', dupInsurer);
|
||
});
|
||
|
||
// document.querySelectorAll('.editablecolumns').forEach(function(element) {
|
||
// element.removeEventListener('input', showAnswersSuggestions);
|
||
// });
|
||
}
|
||
|
||
//----------------------------------------------------------------------------------------------------------
|
||
|
||
function addInsurer(event) {
|
||
|
||
const insurers = <?= json_encode($insurer); ?>;
|
||
|
||
selectInsurer(insurers).then(result => {
|
||
|
||
insurerName = result.selectedInsurer;
|
||
version = result.insurerDetails;
|
||
dataId = result.dataId;
|
||
|
||
if (version.trim() !== '') {
|
||
insurerName = `${insurerName}-${version.trim()}`.replace(/\s+/g, '');
|
||
}
|
||
|
||
console.log('insurerName', insurerName)
|
||
console.log('version', version)
|
||
|
||
if (insurerName) {
|
||
|
||
const closestTh = event.target.closest('th');
|
||
console.log("closestTh", closestTh);
|
||
|
||
let colIndex = closestTh.cellIndex;
|
||
console.log("colIndex", colIndex);
|
||
|
||
let columnText = closestTh.innerText;
|
||
console.log("columnText", columnText);
|
||
|
||
// let proposal_name = columnText.split('⋮')[0].trim();
|
||
let proposal_name = (closestTh.querySelector('.key_name')?.innerText || '').trim();
|
||
console.log("proposal_name", proposal_name);
|
||
|
||
|
||
if (!checkExistingInsurer(proposal_name, insurerName)) {
|
||
|
||
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) {
|
||
|
||
let insurer_index = checkExistingInsurerIndex(proposal_name, insurerName);
|
||
console.log('insurer_index', insurer_index);
|
||
console.log('insurerName', insurerName);
|
||
let modifiedInsurerName = constructInsurerNameWithVersion(proposal_name, insurerName);
|
||
console.log('modifiedInsurerName', modifiedInsurerName);
|
||
addInsurerData(event, modifiedInsurerName, dataId, insurer_index)
|
||
}else{
|
||
return false;
|
||
}
|
||
});
|
||
|
||
}else{
|
||
addInsurerData(event, insurerName, dataId)
|
||
}
|
||
|
||
if (currentThrdottedMenu != '') {
|
||
currentThrdottedMenu.style.display = 'none'; // Show if it's hidden
|
||
}
|
||
}
|
||
});
|
||
|
||
return;
|
||
}
|
||
|
||
function addInsurerData(event, insurerName, dataId, nextIndex = null) {
|
||
|
||
const closestTh = event.target.closest('th');
|
||
let colIndex = closestTh.cellIndex;
|
||
// console.log('column index of first table', colIndex);
|
||
let columnText = closestTh.innerText;
|
||
// let proposal_name = columnText.split('⋮')[0].trim();
|
||
let proposal_name = (closestTh.querySelector('.key_name')?.innerText || '').trim();
|
||
console.log("proposal_name", proposal_name);
|
||
|
||
let rfqTable = document.getElementById('rfqTable');
|
||
const headerRow = rfqTable.rows[1];
|
||
|
||
const thElements = rfqTable.querySelectorAll('thead tr:first-child th');
|
||
let totalColspan = 0;
|
||
|
||
for (let i = 0; i <= colIndex; i++) {
|
||
const colspan = parseInt(thElements[i].getAttribute('colspan')) || 1;
|
||
totalColspan += colspan;
|
||
}
|
||
|
||
let parentTh = rfqTable.querySelector('thead tr th:nth-child(' + (colIndex + 1) + ')');
|
||
// console.log('parentTh', parentTh);
|
||
let columnIndextoCopyData = totalColspan - parentTh.colSpan;
|
||
parentTh.colSpan += 1;
|
||
|
||
// Determine the position for inserting the column
|
||
let insertPosition = totalColspan; // Default to inserting at the end of the current insurer's columns
|
||
if(nextIndex){
|
||
insertPosition = nextIndex;
|
||
}
|
||
|
||
// if (nextIndex) {
|
||
// insertPosition = totalColspan - parentTh.colSpan + 0; // Insert right after the current insurer's column
|
||
// }
|
||
|
||
// Add a new column to each row
|
||
for (let i = 1; i < rfqTable.rows.length; i++) {
|
||
if (i === 1) {
|
||
|
||
const newHeaderCell = document.createElement('th');
|
||
newHeaderCell.innerHTML = `${insurerName} <span class="dropdown" onclick="showThreeDottedMenu(event)">
|
||
<button class="dropbtn">⋮</button>
|
||
<div class="dropdown-content">
|
||
<a href="#" class="changeInsurer">Change Insurer</a>
|
||
<a href="#" class="qcrInsurer" style="background-color: rgb(221, 221, 221);">QCR <i class="fa fa-check-square" style="color: green; margin-left: 8px;"></i></a>
|
||
<a href="#" class="sendClientInsurer" style="background-color: rgb(221, 221, 221);">Send to Client <i class="fa fa-check-square" style="color: green; margin-left: 8px;"></i></a>
|
||
<a href="#" class="removeInsurer">Remove</a>
|
||
<!-- <a href="#" class="copyInsurerLast">Copy</a> -->
|
||
</div>
|
||
</span>`;
|
||
newHeaderCell.style.backgroundColor = parentTh.style.backgroundColor;
|
||
rfqTable.rows[i].insertBefore(newHeaderCell, rfqTable.rows[i].cells[insertPosition]);
|
||
} else {
|
||
const newCell = rfqTable.rows[i].insertCell(insertPosition);
|
||
newCell.setAttribute('contenteditable', 'true');
|
||
newCell.classList.add('editablecolumns');
|
||
newCell.innerHTML = rfqTable.rows[i].cells[columnIndextoCopyData].innerHTML;
|
||
newCell.style.backgroundColor = parentTh.style.backgroundColor;
|
||
}
|
||
}
|
||
|
||
attachEventListeners();
|
||
|
||
pushInsurerInArray(proposal_name, {
|
||
'ins_name': insurerName.split('-')[0],
|
||
'qcr': 1,
|
||
'stc': 1,
|
||
'display_name': insurerName,
|
||
'id': dataId
|
||
});
|
||
|
||
if(RFQ_or_QCR == 2){
|
||
addInsurerDataForPremiumTable(event, insurerName, proposal_name)
|
||
}
|
||
|
||
isFormDataModified = true; // if any value changeing in the table to set true
|
||
}
|
||
|
||
function dupInsurer(event) {
|
||
|
||
const thPosition = getThPosition(event);
|
||
console.log(thPosition);
|
||
|
||
const insurers = <?= json_encode($insurer); ?>;
|
||
|
||
selectInsurer(insurers).then(result => {
|
||
|
||
insurerName = result.selectedInsurer;
|
||
version = result.insurerDetails;
|
||
dataId = result.dataId;
|
||
|
||
if (version.trim() !== '') {
|
||
insurerName = `${insurerName}-${version.trim()}`.replace(/\s+/g, '');
|
||
}
|
||
|
||
console.log('insurerName', insurerName)
|
||
console.log('version', version)
|
||
|
||
if (insurerName) {
|
||
|
||
let parentThIndex = null;
|
||
const closestTh = event.target.closest('th');
|
||
let colIndex = closestTh.cellIndex;
|
||
let columnText = closestTh.innerText;
|
||
let proposal_name = columnText.split('⋮')[0].trim();
|
||
let rfqTable = document.getElementById('rfqTable');
|
||
const headerRows = rfqTable.querySelectorAll('thead tr');
|
||
|
||
if (thPosition.rowIndex == 1) //copy insurer
|
||
{
|
||
var copyType = event.target.className;
|
||
// alert(copyType);
|
||
let accumulatedColspan = 0;
|
||
let parentTh = null;
|
||
|
||
let subThIndex = colIndex;
|
||
const firstHeaderRow = headerRows[0];
|
||
// Find the parent TH for the specified sub TH index
|
||
for (let i = 0; i < firstHeaderRow.children.length; i++) {
|
||
const currentParentTh = firstHeaderRow.children[i];
|
||
const currentColspan = parseInt(currentParentTh.getAttribute('colspan')) || 1;
|
||
|
||
accumulatedColspan += currentColspan;
|
||
|
||
if (subThIndex < accumulatedColspan) {
|
||
parentTh = currentParentTh;
|
||
break;
|
||
}
|
||
}
|
||
console.log(parentTh.cellIndex);
|
||
parentTh = headerRows[0].children[parentTh.cellIndex];
|
||
parentThIndex = parentTh.cellIndex;
|
||
console.log(accumulatedColspan + ' - ' + parentTh + ' - ' + subThIndex);
|
||
proposal_name = parentTh.innerText.split('⋮')[0].trim();
|
||
// if(copyType == 'copyInsurerLast')
|
||
// {
|
||
// colIndex = parentTh.cellIndex;
|
||
// }
|
||
// else
|
||
// {
|
||
// colIndex = colIndex;
|
||
// }
|
||
}
|
||
|
||
console.log(colIndex);
|
||
|
||
if (!checkExistingInsurer(proposal_name, insurerName)) {
|
||
|
||
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) {
|
||
console.log('insurerName', insurerName);
|
||
let modifiedInsurerName = constructInsurerNameWithVersion(proposal_name, insurerName);
|
||
console.log('modifiedInsurerName', modifiedInsurerName);
|
||
copyInsurerData(event, modifiedInsurerName, dataId)
|
||
}else{
|
||
return false;
|
||
}
|
||
});
|
||
|
||
}else{
|
||
copyInsurerData(event, insurerName, dataId)
|
||
}
|
||
}
|
||
|
||
if (currentThrdottedMenu != '') {
|
||
currentThrdottedMenu.style.display = 'none'; // Show if it's hidden
|
||
}
|
||
});
|
||
|
||
return;
|
||
}
|
||
|
||
function copyInsurerData(event, insurerName, dataId){
|
||
|
||
const thPosition = getThPosition(event);
|
||
|
||
let parentThIndex = null;
|
||
const closestTh = event.target.closest('th');
|
||
let colIndex = closestTh.cellIndex;
|
||
let columnText = closestTh.innerText;
|
||
let proposal_name = columnText.split('⋮')[0].trim();
|
||
let rfqTable = document.getElementById('rfqTable');
|
||
const headerRows = rfqTable.querySelectorAll('thead tr');
|
||
|
||
if (thPosition.rowIndex == 1) //copy insurer
|
||
{
|
||
var copyType = event.target.className;
|
||
// alert(copyType);
|
||
let accumulatedColspan = 0;
|
||
let parentTh = null;
|
||
|
||
let subThIndex = colIndex;
|
||
const firstHeaderRow = headerRows[0];
|
||
// Find the parent TH for the specified sub TH index
|
||
for (let i = 0; i < firstHeaderRow.children.length; i++) {
|
||
const currentParentTh = firstHeaderRow.children[i];
|
||
const currentColspan = parseInt(currentParentTh.getAttribute('colspan')) || 1;
|
||
|
||
accumulatedColspan += currentColspan;
|
||
|
||
if (subThIndex < accumulatedColspan) {
|
||
parentTh = currentParentTh;
|
||
break;
|
||
}
|
||
}
|
||
console.log(parentTh.cellIndex);
|
||
parentTh = headerRows[0].children[parentTh.cellIndex];
|
||
parentThIndex = parentTh.cellIndex;
|
||
console.log(accumulatedColspan + ' - ' + parentTh + ' - ' + subThIndex);
|
||
proposal_name = parentTh.innerText.split('⋮')[0].trim();
|
||
// if(copyType == 'copyInsurerLast')
|
||
// {
|
||
// colIndex = parentTh.cellIndex;
|
||
// }
|
||
// else
|
||
// {
|
||
// colIndex = colIndex;
|
||
// }
|
||
}
|
||
|
||
console.log(colIndex);
|
||
|
||
const headerRow = rfqTable.rows[1];
|
||
// console.log('current col index' + colIndex);
|
||
|
||
//find total no of columns (sub th) untill current parent th
|
||
const thElements = rfqTable.querySelectorAll('thead tr:first-child th');
|
||
let totalColspan = 0;
|
||
|
||
// Loop through the parent th elements within the specified index range
|
||
for (let i = 0; i <= parentThIndex; i++) {
|
||
const colspan = parseInt(thElements[i].getAttribute('colspan')) || 1;
|
||
totalColspan += colspan;
|
||
}
|
||
|
||
|
||
// alert(colIndex+' - '+totalColspan);
|
||
// if(copyType == 'copyInsurerNext')
|
||
// {
|
||
// totalColspan = colIndex;
|
||
// colIndex = colIndex - 1;
|
||
// }
|
||
|
||
|
||
// add colspan of current th
|
||
let parentTh = rfqTable.querySelector('thead tr th:nth-child(' + (parentThIndex + 1) + ')');
|
||
parentTh.colSpan += 1;
|
||
// Add a new column to each row
|
||
for (let i = 1; i < rfqTable.rows.length; i++) {
|
||
|
||
if (i == 1) {
|
||
// Create a new <th> element
|
||
const newHeaderCell = document.createElement('th');
|
||
newHeaderCell.innerHTML = ` ${insurerName} <span class="dropdown" onclick="showThreeDottedMenu(event)">
|
||
<button class="dropbtn">⋮</button>
|
||
<div class="dropdown-content">
|
||
<a href="#" class="changeInsurer">Change Insurer</a>
|
||
<a href="#" class="qcrInsurer" style="background-color: rgb(221, 221, 221);">QCR <i class="fa fa-check-square" style="color: green; margin-left: 8px;"></i></a>
|
||
<a href="#" class="sendClientInsurer" style="background-color: rgb(221, 221, 221);">Send to Client <i class="fa fa-check-square" style="color: green; margin-left: 8px;"></i></a>
|
||
<a href="#" class="removeInsurer">Remove</a>
|
||
<!-- <a href="#" class="copyInsurerNext">Copy to next</a> -->
|
||
<!-- <a href="#" class="copyInsurerLast">Copy</a> -->
|
||
</div>
|
||
</span>`;
|
||
newHeaderCell.style.backgroundColor = parentTh.style.backgroundColor;;
|
||
// Insert the <th> element at the desired position
|
||
rfqTable.rows[i].insertBefore(newHeaderCell, rfqTable.rows[i].cells[totalColspan]);
|
||
|
||
} else {
|
||
const newCell = rfqTable.rows[i].insertCell(totalColspan);
|
||
newCell.setAttribute('contenteditable', 'true');
|
||
newCell.classList.add('editablecolumns');
|
||
newCell.innerHTML = rfqTable.rows[i].cells[colIndex].innerHTML;
|
||
newCell.style.backgroundColor = parentTh.style.backgroundColor;
|
||
}
|
||
|
||
}
|
||
|
||
attachEventListeners();
|
||
|
||
//add insurer into over all column data
|
||
pushInsurerInArray(proposal_name, {
|
||
'ins_name': (insurerName.split('-')[0]),
|
||
'qcr': 1,
|
||
'stc': 1,
|
||
'display_name': insurerName,
|
||
'id': dataId
|
||
});
|
||
|
||
if(RFQ_or_QCR == 2){
|
||
copyInsurerDataForPremiumTable(event, insurerName)
|
||
}
|
||
|
||
isFormDataModified = true; // if any value changeing in the table to set true
|
||
}
|
||
|
||
//--------------------------------------------------------------------------------------------------------
|
||
|
||
function removeProposal(event) {
|
||
|
||
const closestTh = event.target.closest('th');
|
||
let colIndex = closestTh.cellIndex;
|
||
let rfqTable = document.getElementById('rfqTable');
|
||
console.log(rfqTable)
|
||
|
||
Swal.fire({
|
||
title: 'Are you sure?',
|
||
text: "Do you want to remove the Proposal?",
|
||
icon: 'warning',
|
||
showCancelButton: true,
|
||
confirmButtonColor: '#d33',
|
||
cancelButtonColor: '#3085d6',
|
||
confirmButtonText: 'Yes, remove it!',
|
||
cancelButtonText: 'Cancel'
|
||
}).then((result) => {
|
||
if (result.isConfirmed) {
|
||
|
||
const headerRows = rfqTable.querySelectorAll('thead tr');
|
||
const parentTh = headerRows[0].children[colIndex];
|
||
const proposal_name = parentTh.innerText.split('⋮')[0].trim();
|
||
|
||
let parentColspan = 1;
|
||
|
||
if (RFQ_or_QCR == 1) {
|
||
parentColspan = parseInt(parentTh.getAttribute('data-colspan')) || 1;
|
||
}else{
|
||
parentColspan = parseInt(parentTh.getAttribute('colspan')) || 1;
|
||
}
|
||
|
||
const startIndex = Array.from(headerRows[1].children).findIndex(th => th.offsetLeft >= parentTh.offsetLeft);
|
||
|
||
// Remove the parent TH
|
||
headerRows[0].removeChild(parentTh);
|
||
|
||
// Remove the relevant sub THs and corresponding TDs
|
||
for (let i = startIndex; i < startIndex + parentColspan; i++) {
|
||
// Remove the sub THs
|
||
headerRows[1].removeChild(headerRows[1].children[startIndex]);
|
||
|
||
// Remove the corresponding TDs from each row
|
||
rfqTable.querySelectorAll('tbody tr').forEach(row => {
|
||
row.removeChild(row.children[startIndex]);
|
||
});
|
||
}
|
||
|
||
if(RFQ_or_QCR == 2){
|
||
removeProposalForPremiumTable(colIndex);
|
||
}
|
||
|
||
//remove proposal in global array
|
||
if (over_all_column_data.hasOwnProperty(proposal_name)) {
|
||
delete over_all_column_data[proposal_name]; // Delete the property
|
||
console.log(`${proposal_name} deleted successfully.`);
|
||
|
||
isFormDataModified = true; // if any value changeing in the table to set true
|
||
|
||
} else {
|
||
console.log(`${proposal_name} does not exist.`);
|
||
}
|
||
}
|
||
|
||
})
|
||
}
|
||
|
||
function removeInsurer(event) {
|
||
|
||
Swal.fire({
|
||
title: 'Are you sure?',
|
||
text: "Do you want to remove the insurer?",
|
||
icon: 'warning',
|
||
showCancelButton: true,
|
||
confirmButtonColor: '#d33',
|
||
cancelButtonColor: '#3085d6',
|
||
confirmButtonText: 'Yes, remove it!',
|
||
cancelButtonText: 'Cancel'
|
||
}).then((result) => {
|
||
if (result.isConfirmed) {
|
||
// function removeSubColumnByIndex(tableId, subThIndex) {
|
||
const table = document.getElementById('rfqTable');
|
||
const headerRows = table.querySelectorAll('thead tr');
|
||
|
||
const closestTh = event.target.closest('th');
|
||
let insurerName = closestTh.innerText.split('⋮')[0]
|
||
// alert(insurerName);return;
|
||
let subThIndex = closestTh.cellIndex;
|
||
console.log('subThIndex', subThIndex);
|
||
|
||
// Get the sub TH from the second header row
|
||
const subTh = headerRows[1].children[subThIndex];
|
||
console.log('subTh', subTh);
|
||
|
||
let accumulatedColspan = 0;
|
||
let parentTh = null;
|
||
const firstHeaderRow = headerRows[0];
|
||
// Find the parent TH for the specified sub TH index
|
||
for (let i = 0; i < firstHeaderRow.children.length; i++) {
|
||
const currentParentTh = firstHeaderRow.children[i];
|
||
const currentColspan = parseInt(currentParentTh.getAttribute('colspan')) || 1;
|
||
|
||
accumulatedColspan += currentColspan;
|
||
|
||
if (subThIndex < accumulatedColspan) {
|
||
parentTh = currentParentTh;
|
||
break;
|
||
}
|
||
}
|
||
console.log('parentth' + parentTh);
|
||
console.log('sub col indexOf' + subThIndex);
|
||
|
||
|
||
// Get the starting position of the sub TH
|
||
const startIndex = Array.from(headerRows[1].children).indexOf(subTh);
|
||
|
||
// Remove the sub TH
|
||
headerRows[1].removeChild(subTh);
|
||
|
||
// Reduce colspan of parent TH
|
||
const parentColspan = parseInt(parentTh.getAttribute('colspan')) || 1;
|
||
console.log('existing colspan' + parentColspan);
|
||
parentTh.setAttribute('colspan', parentColspan - 1);
|
||
console.log('new colspan' + (parentColspan - 1));
|
||
|
||
// Remove the corresponding TDs from each row
|
||
table.querySelectorAll('tbody tr').forEach(row => {
|
||
row.removeChild(row.children[startIndex]);
|
||
});
|
||
|
||
removeInsurerFromPremiumTable(event, subThIndex)
|
||
|
||
//remove the insurer from gobal array
|
||
let proposal_name = parentTh.innerText.split('⋮')[0];
|
||
popInsurerInArray(proposal_name, insurerName);
|
||
|
||
isFormDataModified = true; // if any value changeing in the table to set true
|
||
}
|
||
|
||
})
|
||
}
|
||
|
||
function showThreeDottedMenu(event) {
|
||
// Prevent the default behavior (optional, depending on your needs)
|
||
event.preventDefault();
|
||
if (currentThrdottedMenu != '') {
|
||
currentThrdottedMenu.style.display = 'none'; // Show if it's hidden
|
||
}
|
||
// Get the dropdown content element
|
||
const dropdownContent = event.currentTarget.querySelector('.dropdown-content');
|
||
currentThrdottedMenu = dropdownContent;
|
||
// Toggle the showThreeDottedMenu happening in the doc on click event listener
|
||
//here only set current dropdown menu DOM object to common variable currentThrdottedMenu
|
||
}
|
||
|
||
function checkExistingInsurer(proposal_name, insurer_name) {
|
||
|
||
console.log("checkExistingInsurer function called");
|
||
|
||
proposal_name = proposal_name.trim(proposal_name);
|
||
console.log('proposal_name - ' + proposal_name);
|
||
console.log("over_all_column_data", over_all_column_data);
|
||
console.log("over_all_column_data[proposal_name]", over_all_column_data[proposal_name]);
|
||
// console.log('insurer_name - ' + insurer_name);
|
||
|
||
if (over_all_column_data[proposal_name]) {
|
||
let tempInsurerList = over_all_column_data[proposal_name].insurers;
|
||
console.log('tempInsurerList', tempInsurerList);
|
||
if (!tempInsurerList.length) {
|
||
return true;
|
||
}
|
||
let result = tempInsurerList.some(item => item.display_name === insurer_name);
|
||
return !result;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
function checkExistingInsurerIndex(proposal_name, insurer_name) {
|
||
|
||
console.log('#####################################################');
|
||
console.log("checkExistingInsurerIndex function called");
|
||
|
||
proposal_name = proposal_name.trim();
|
||
|
||
if (over_all_column_data[proposal_name]) {
|
||
|
||
console.log('over_all_column_data', over_all_column_data);
|
||
|
||
const currentProposalInsurers = over_all_column_data[proposal_name].insurers;
|
||
|
||
// Calculate duplicate insurer IDs within the current proposal
|
||
let duplicate_insurer_id_count = 0;
|
||
const insurerIdCountMap = {};
|
||
|
||
currentProposalInsurers.forEach((insurer) => {
|
||
const insurerId = insurer.id;
|
||
if (insurerId) {
|
||
insurerIdCountMap[insurerId] = (insurerIdCountMap[insurerId] || 0) + 1;
|
||
}
|
||
});
|
||
|
||
duplicate_insurer_id_count = Object.values(insurerIdCountMap).reduce((count, occurrences) => {
|
||
return count + (occurrences > 1 ? occurrences - 1 : 0);
|
||
}, 0);
|
||
|
||
console.log("Duplicate insurer IDs found:", duplicate_insurer_id_count);
|
||
|
||
// Find the proposal index
|
||
const proposalKeys = Object.keys(over_all_column_data);
|
||
const proposalIndex = proposalKeys.indexOf(proposal_name);
|
||
console.log('proposalIndex:', proposalIndex);
|
||
|
||
// Calculate quote and insurer count up to the current proposal
|
||
let quote_count = 0;
|
||
let insurer_count = 0;
|
||
|
||
for (let i = 0; i < proposalIndex; i++) {
|
||
quote_count++;
|
||
const previousProposal = over_all_column_data[proposalKeys[i]];
|
||
if (previousProposal.insurers && Array.isArray(previousProposal.insurers)) {
|
||
insurer_count += previousProposal.insurers.length;
|
||
}
|
||
}
|
||
|
||
let tempInsurerList = over_all_column_data[proposal_name].insurers;
|
||
const insurer_index = tempInsurerList.findIndex(item => item.display_name === insurer_name);
|
||
|
||
|
||
console.log('quote_count:', quote_count);
|
||
console.log('insurer_count:', insurer_count);
|
||
console.log('insurer_index:', insurer_index);
|
||
|
||
// Calculate total index
|
||
const sno_hiddenitem_particulers = 3;
|
||
const current_insurer_and_quote_sum = 2;
|
||
const total = insurer_count + insurer_index + (quote_count + current_insurer_and_quote_sum) + sno_hiddenitem_particulers + duplicate_insurer_id_count;
|
||
console.log('total:', total);
|
||
|
||
console.log('#####################################################');
|
||
return total;
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
function pushInsurerInArray(proposal_name, insurer_arr) {
|
||
|
||
console.log('pushInsurerInArray function called');
|
||
proposal_name = proposal_name.trim();
|
||
console.log("proposal_name", proposal_name);
|
||
console.log("over_all_column_data", over_all_column_data);
|
||
console.log("over_all_column_data[proposal_name]", over_all_column_data[proposal_name]);
|
||
|
||
if (over_all_column_data[proposal_name]) {
|
||
over_all_column_data[proposal_name].insurers.push(insurer_arr);
|
||
console.log('new insurer added in golbal variable');
|
||
console.log(over_all_column_data[proposal_name].insurers);
|
||
return;
|
||
}
|
||
console.log('new insurer not added in golbal variable');
|
||
}
|
||
|
||
function popInsurerInArray(proposal_name, insurerName) {
|
||
proposal_name = proposal_name.trim();
|
||
insurerName = insurerName.trim();
|
||
console.log('Removing....' + proposal_name + ' - ' + insurerName)
|
||
if (over_all_column_data[proposal_name]) {
|
||
let tempInsurerList = over_all_column_data[proposal_name].insurers;
|
||
// console.log(tempInsurerList);
|
||
// if(!tempInsurerList.length) { return true; }
|
||
tempInsurerList = tempInsurerList.filter(item => item.display_name !== insurerName);
|
||
console.log(tempInsurerList);
|
||
over_all_column_data[proposal_name].insurers = tempInsurerList;
|
||
console.log('insurer removed in golbal variable');
|
||
console.log(over_all_column_data[proposal_name].insurers);
|
||
// over_all_column_data[proposal_name].insurers = tempInsurerList
|
||
return;
|
||
}
|
||
console.log('insurer not removed in golbal variable');
|
||
}
|
||
|
||
function changeInsurer(event) {
|
||
|
||
console.log('changeInsurer function called');
|
||
console.log('change insure event', event);
|
||
let proposal_name = getParentHeaderTh(event);
|
||
console.log('proposel Name', proposal_name);
|
||
|
||
if(proposal_name == null || proposal_name == ""){
|
||
toastr.warning("Could not change the insurer", "WARNING")
|
||
return;
|
||
}
|
||
|
||
// let newInsurerName = prompt("Enter New insurer name:");
|
||
const insurers = <?= json_encode($insurer); ?>;
|
||
|
||
selectInsurer(insurers).then(result => {
|
||
|
||
let newInsurerName = result.selectedInsurer
|
||
let newversion = result.insurerDetails;
|
||
let dataId = result.dataId;
|
||
|
||
if (newversion.trim() !== '') {
|
||
newInsurerName = `${newInsurerName}-${newversion.trim()}`.replace(/\s+/g, '');
|
||
}
|
||
|
||
console.log('newInsurerName', newInsurerName);
|
||
console.log('newversion', newversion);
|
||
console.log("dataId", dataId);
|
||
|
||
|
||
const closestTh = event.target.closest('th');
|
||
let oldInsurerName = closestTh.innerText.split('⋮')[0].trim();
|
||
console.log("old and new insure name" , oldInsurerName + ' - ' + newInsurerName);
|
||
|
||
|
||
if (!checkExistingInsurer(proposal_name, newInsurerName) && oldInsurerName != newInsurerName) {
|
||
|
||
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) {
|
||
|
||
console.log("dataId", dataId);
|
||
let modifiedInsurerName = constructInsurerNameWithVersion(proposal_name, newInsurerName);
|
||
console.log('modifiedInsurerName', modifiedInsurerName);
|
||
changeInsurerData(event, modifiedInsurerName, dataId);
|
||
|
||
}else{
|
||
return false;
|
||
}
|
||
});
|
||
|
||
}else{
|
||
changeInsurerData(event, newInsurerName, dataId);
|
||
}
|
||
|
||
|
||
});
|
||
}
|
||
|
||
function changeInsurerData(event, newInsurerName, dataId){
|
||
|
||
console.log("changeInsurerData function called")
|
||
console.log("newInsurerName", newInsurerName)
|
||
console.log("dataId", dataId)
|
||
|
||
if (newInsurerName) {
|
||
|
||
const closestTh = event.target.closest('th');
|
||
let oldInsurerName = closestTh.innerText.split('⋮')[0].trim();
|
||
let subThIndex = closestTh.cellIndex;
|
||
console.log(oldInsurerName + ' - ' + newInsurerName);
|
||
// Iterate over child nodes to find the text node containing "Myname"
|
||
closestTh.childNodes.forEach(node => {
|
||
if (node.nodeType === Node.TEXT_NODE && node.textContent.includes(oldInsurerName)) {
|
||
// Replace the old name with the new name
|
||
node.textContent = node.textContent.replace(oldInsurerName, newInsurerName);
|
||
}
|
||
});
|
||
//find parent th index then it's text content
|
||
|
||
|
||
// Get the sub TH from the second header row
|
||
const table = document.getElementById('rfqTable');
|
||
const headerRows = table.querySelectorAll('thead tr');
|
||
const subTh = headerRows[1].children[subThIndex];
|
||
|
||
let accumulatedColspan = 0;
|
||
let parentTh = null;
|
||
const firstHeaderRow = headerRows[0];
|
||
// Find the parent TH for the specified sub TH index
|
||
for (let i = 0; i < firstHeaderRow.children.length; i++) {
|
||
const currentParentTh = firstHeaderRow.children[i];
|
||
const currentColspan = parseInt(currentParentTh.getAttribute('colspan')) || 1;
|
||
|
||
accumulatedColspan += currentColspan;
|
||
|
||
if (subThIndex < accumulatedColspan) {
|
||
parentTh = currentParentTh;
|
||
break;
|
||
}
|
||
}
|
||
|
||
changeInsurerForPremiumTable(event, newInsurerName, subThIndex);
|
||
|
||
// let proposal_name = parentTh.innerText.split('⋮')[0].trim();
|
||
let proposal_name = (parentTh.querySelector('.key_name')?.innerText || '').trim();
|
||
console.log("proposal_name", proposal_name);
|
||
console.log("over_all_column_data[proposal_name]", over_all_column_data[proposal_name]);
|
||
|
||
if (over_all_column_data[proposal_name]) {
|
||
// let tempInsurerList = over_all_column_data[proposal_name].insurers;
|
||
// console.log(tempInsurerList);
|
||
// if(!tempInsurerList.length) { return true; }
|
||
//replace the old insurer with the new insuren in global array
|
||
over_all_column_data[proposal_name].insurers.forEach(item => {
|
||
if (item.display_name === oldInsurerName) {
|
||
item.display_name = newInsurerName; // Replace with new name
|
||
item.ins_name = newInsurerName.split('-')[0].trim(); // Replace with new name
|
||
item.id = dataId
|
||
}
|
||
});
|
||
// console.log(tempInsurerList);
|
||
// over_all_column_data[proposal_name].insurers = tempInsurerList;
|
||
console.log('insurer name replaced in golbal variable');
|
||
console.log(over_all_column_data[proposal_name].insurers);
|
||
// over_all_column_data[proposal_name].insurers = tempInsurerList
|
||
|
||
isFormDataModified = true; // if any value changeing in the table to set true
|
||
|
||
console.log("over_all_column_data", over_all_column_data);
|
||
|
||
return;
|
||
}
|
||
|
||
console.log('insurer name not replaced in golbal variable');
|
||
|
||
|
||
}else{
|
||
toastr.warning("Could not change the insurer", "WARNING")
|
||
return;
|
||
}
|
||
}
|
||
|
||
function getParentHeaderTh(event) {
|
||
|
||
const currentTh = event.target.closest('th');
|
||
if (!currentTh) return;
|
||
|
||
const colIndex = currentTh.cellIndex;
|
||
|
||
// Get all header rows
|
||
const thead = currentTh.closest('thead');
|
||
const headerRows = thead.querySelectorAll('tr');
|
||
|
||
if (headerRows.length < 2) return; // need at least 2 header rows
|
||
|
||
const secondRowThs = headerRows[1].querySelectorAll('th');
|
||
const firstRowThs = headerRows[0].querySelectorAll('th');
|
||
|
||
// Step 1: Find actual column span index of clicked th in 2nd row
|
||
let actualColIndex = 0;
|
||
for (let i = 0; i < secondRowThs.length; i++) {
|
||
const th = secondRowThs[i];
|
||
const colspan = parseInt(th.getAttribute('colspan')) || 1;
|
||
|
||
if (th === currentTh) break;
|
||
|
||
actualColIndex += colspan;
|
||
}
|
||
|
||
// Step 2: Match it with first row <th>s
|
||
let colSpanCounter = 0;
|
||
for (let i = 0; i < firstRowThs.length; i++) {
|
||
const th = firstRowThs[i];
|
||
const colspan = parseInt(th.getAttribute('colspan')) || 1;
|
||
|
||
if (actualColIndex >= colSpanCounter && actualColIndex < colSpanCounter + colspan) {
|
||
// let proposelName = th.innerText.split('⋮')[0].trim();
|
||
let proposelName = (th.querySelector('.key_name')?.innerText || '').trim();
|
||
console.log("Parent TH Proposal innerText:", proposelName);
|
||
console.log("Parent TH Proposal textContent:", th.textContent.trim());
|
||
return proposelName;
|
||
}
|
||
|
||
colSpanCounter += colspan;
|
||
}
|
||
|
||
console.log("Parent header not found");
|
||
return null;
|
||
}
|
||
|
||
|
||
function changeState(event) {
|
||
|
||
console.log('changeState Function called')
|
||
let type = event.target.className;
|
||
console.log('1 : ', type);
|
||
|
||
// if (type.includes('sendClientProposal') && type.includes('fa fa-check-square')) {
|
||
// type = 'sendClientProposal';
|
||
// } else if (type.includes('qcrProposal') && type.includes('fa fa-check-square')) {
|
||
// type = 'qcrProposal';
|
||
// }
|
||
// console.log('2 : ',type);
|
||
|
||
if (['qcrProposal', 'sendClientProposal'].includes(type)) {
|
||
|
||
console.log('Proposal');
|
||
const closestTh = event.target.closest('th');
|
||
let proposal_name = closestTh.innerText.split('⋮')[0].trim();
|
||
// let subThIndex = closestTh.cellIndex;
|
||
if (over_all_column_data[proposal_name]) {
|
||
|
||
if (type === 'qcrProposal') {
|
||
|
||
console.log('Proposal qcrProposal');
|
||
|
||
over_all_column_data[proposal_name].qcr = !over_all_column_data[proposal_name].qcr;
|
||
this.style.backgroundColor = over_all_column_data[proposal_name].qcr ? '#ddd' : '#f1f1f1';
|
||
|
||
// Check if an icon already exists
|
||
let icon = this.querySelector('.fa-check-square');
|
||
|
||
if (over_all_column_data[proposal_name].qcr) {
|
||
|
||
// If qcr is true and no icon exists, create and append it
|
||
if (!icon) {
|
||
icon = document.createElement('i');
|
||
icon.classList.add('fa', 'fa-check-square');
|
||
icon.style.color = 'green';
|
||
icon.style.marginLeft = '8px';
|
||
this.appendChild(icon);
|
||
}
|
||
|
||
} else {
|
||
|
||
if (icon) {
|
||
this.removeChild(icon);
|
||
}
|
||
}
|
||
|
||
var sendClientProposal = $(this).siblings('.sendClientProposal');
|
||
console.log('sendClientProposal', sendClientProposal);
|
||
|
||
if(sendClientProposal){
|
||
|
||
over_all_column_data[proposal_name].stc = !over_all_column_data[proposal_name].stc;
|
||
sendClientProposal.css('background-color', over_all_column_data[proposal_name].stc ? '#ddd' : '#f1f1f1');
|
||
|
||
// Check if an icon already exists
|
||
let icon = sendClientProposal.find('.fa-check-square')[0];
|
||
|
||
if (over_all_column_data[proposal_name].stc) {
|
||
|
||
// If qcr is true and no icon exists, create and append it
|
||
if (!icon) {
|
||
|
||
if (!icon) {
|
||
icon = $('<i></i>')
|
||
.addClass('fa fa-check-square')
|
||
.css('color', 'green')
|
||
.css('margin-left', '8px');
|
||
sendClientProposal.append(icon);
|
||
}
|
||
}
|
||
} else {
|
||
if (icon) {
|
||
icon.remove();
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
} else {
|
||
|
||
console.log('Proposal sendClientProposal');
|
||
|
||
over_all_column_data[proposal_name].stc = !over_all_column_data[proposal_name].stc;
|
||
this.style.backgroundColor = !over_all_column_data[proposal_name].stc ? '#f1f1f1' : "#ddd";
|
||
|
||
// Check if an icon already exists
|
||
let icon = this.querySelector('.fa-check-square');
|
||
|
||
if (over_all_column_data[proposal_name].stc) {
|
||
|
||
// If qcr is true and no icon exists, create and append it
|
||
if (!icon) {
|
||
icon = document.createElement('i');
|
||
icon.classList.add('fa', 'fa-check-square');
|
||
icon.style.color = 'green';
|
||
icon.style.marginLeft = '8px';
|
||
this.appendChild(icon);
|
||
}
|
||
} else {
|
||
if (icon) {
|
||
this.removeChild(icon);
|
||
}
|
||
}
|
||
}
|
||
|
||
console.log(over_all_column_data[proposal_name])
|
||
|
||
}
|
||
} else {
|
||
console.log('insurer');
|
||
|
||
const closestTh = event.target.closest('th');
|
||
let insurerName = closestTh.innerText.split('⋮')[0].trim();
|
||
let subThIndex = closestTh.cellIndex;
|
||
|
||
//find parent th index then it's text content
|
||
// Get the sub TH from the second header row
|
||
const table = document.getElementById('rfqTable');
|
||
const headerRows = table.querySelectorAll('thead tr');
|
||
const subTh = headerRows[1].children[subThIndex];
|
||
|
||
let accumulatedColspan = 0;
|
||
let parentTh = null;
|
||
const firstHeaderRow = headerRows[0];
|
||
// Find the parent TH for the specified sub TH index
|
||
for (let i = 0; i < firstHeaderRow.children.length; i++) {
|
||
const currentParentTh = firstHeaderRow.children[i];
|
||
const currentColspan = parseInt(currentParentTh.getAttribute('colspan')) || 1;
|
||
|
||
accumulatedColspan += currentColspan;
|
||
|
||
if (subThIndex < accumulatedColspan) {
|
||
parentTh = currentParentTh;
|
||
break;
|
||
}
|
||
}
|
||
let proposal_name = parentTh.innerText.split('⋮')[0].trim();
|
||
if (over_all_column_data[proposal_name]) {
|
||
|
||
over_all_column_data[proposal_name].insurers.forEach(item => {
|
||
if (item.display_name === insurerName) {
|
||
|
||
if (over_all_column_data[proposal_name]) {
|
||
let icon = this.querySelector('.fa-check-square'); // Check if an icon already exists
|
||
|
||
if (type === 'qcrInsurer') {
|
||
item.qcr = !item.qcr;
|
||
this.style.backgroundColor = item.qcr ? '#ddd' : '#f1f1f1';
|
||
|
||
if (item.qcr) {
|
||
// If qcr is true and no icon exists, create and append it
|
||
if (!icon) {
|
||
icon = document.createElement('i');
|
||
icon.classList.add('fa', 'fa-check-square');
|
||
icon.style.color = 'green';
|
||
icon.style.marginLeft = '8px';
|
||
this.appendChild(icon);
|
||
}
|
||
} else {
|
||
// If qcr is false and the icon exists, remove it
|
||
if (icon) {
|
||
this.removeChild(icon);
|
||
}
|
||
}
|
||
} else { // Assuming this block is for 'stc'
|
||
item.stc = !item.stc;
|
||
this.style.backgroundColor = item.stc ? '#ddd' : '#f1f1f1';
|
||
|
||
if (item.stc) {
|
||
// If stc is true and no icon exists, create and append it
|
||
if (!icon) {
|
||
icon = document.createElement('i');
|
||
icon.classList.add('fa', 'fa-check-square');
|
||
icon.style.color = 'green';
|
||
icon.style.marginLeft = '8px';
|
||
this.appendChild(icon);
|
||
}
|
||
} else {
|
||
// If stc is false and the icon exists, remove it
|
||
if (icon) {
|
||
this.removeChild(icon);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
});
|
||
// console.log(tempInsurerList);
|
||
// over_all_column_data[proposal_name].insurers = tempInsurerList;
|
||
// console.log('insurer name replaced in golbal variable');
|
||
console.log(over_all_column_data[proposal_name].insurers);
|
||
// over_all_column_data[proposal_name].insurers = tempInsurerList
|
||
return;
|
||
}
|
||
console.log('insurer name not replaced in golbal variable');
|
||
|
||
}
|
||
|
||
isFormDataModified = true; // if any value changeing in the table to set true
|
||
}
|
||
|
||
function isEventObject(variable) {
|
||
return variable instanceof Event && variable.target !== undefined;
|
||
}
|
||
|
||
function getThPosition(event) {
|
||
var th = null;
|
||
if (isEventObject(event)) {
|
||
th = event.target;
|
||
} else {
|
||
th = event;
|
||
}
|
||
|
||
// const th = event.target;
|
||
// Get the parent row (tr) and all its sibling rows
|
||
const rowIndex = th.parentElement.parentElement.parentElement.parentElement.rowIndex;
|
||
const colIndex = th.parentElement.parentElement.parentElement.cellIndex;
|
||
return {
|
||
rowIndex,
|
||
colIndex
|
||
};
|
||
}
|
||
|
||
function handleChildQuestions(target) {
|
||
// Extract the parent id from the event (assuming parent id is stored in event.target's data attribute)
|
||
let parentId = target.parentElement.id
|
||
// alert(parentId);
|
||
let hiddenInput = target.querySelector('input[type="hidden"]');
|
||
// alert(hiddenInput);
|
||
let inputValue = hiddenInput ? hiddenInput.value : null;
|
||
if (inputValue === null) {
|
||
return true;
|
||
} else {
|
||
inputValue = JSON.parse(inputValue);
|
||
}
|
||
|
||
|
||
// Check if the parent id exists in the suggestions object
|
||
if (suggestions.hasOwnProperty(parentId)) {
|
||
let parentItem = suggestions[parentId];
|
||
|
||
// Check if child_questions exists and has items
|
||
if (parentItem.child_questions && parentItem.child_questions.length > 0) {
|
||
// Get the current column index from the event (assuming the target is within a table cell)
|
||
let currentColumnIndex = target.cellIndex;
|
||
// alert('currentColumnIndex :' + currentColumnIndex);
|
||
// Iterate over the child questions
|
||
parentItem.child_questions.forEach(child => {
|
||
// Find the row in the table with the child key (e.g., 'twin_delivery')
|
||
console.log('processing for ' + child.question);
|
||
let disable_at = child.disable_at;
|
||
// if(inputValue.key == disable_at.key)
|
||
// {
|
||
let childRow = document.querySelector(`tr[id='${child.question}']`);
|
||
console.log(childRow);
|
||
if (childRow) {
|
||
console.log('found row');
|
||
// Get the corresponding column in the same index as the current column
|
||
let childCell = childRow.cells[currentColumnIndex];
|
||
|
||
if (childCell) {
|
||
console.log('found cell',inputValue);
|
||
|
||
if (inputValue.key == disable_at.key) {
|
||
childCell.innerHTML = '';
|
||
childCell.innerText = '';
|
||
//hidden text box for store choosed answers object
|
||
const hiddenInputBox = document.createElement('input');
|
||
hiddenInputBox.type = 'hidden';
|
||
hiddenInputBox.value = JSON.stringify(child.default_answer);
|
||
|
||
childCell.appendChild(hiddenInputBox);
|
||
// alert(input.innerText);
|
||
childCell.appendChild(document.createTextNode(child.default_answer.display_value));
|
||
|
||
// Set the default answer in the child cell
|
||
// childCell.innerHTML = child.default_answer.display_value;
|
||
console.log('setting default value');
|
||
console.log(child.default_answer.display_value)
|
||
childCell.contentEditable = false;
|
||
} else {
|
||
childCell.innerHTML = '';
|
||
childCell.innerText = '';
|
||
//hidden text box for store choosed answers object
|
||
const hiddenInputBox = document.createElement('input');
|
||
hiddenInputBox.type = 'hidden';
|
||
hiddenInputBox.value = JSON.stringify(inputValue.display_value);
|
||
|
||
childCell.appendChild(hiddenInputBox);
|
||
// alert(input.innerText);
|
||
childCell.appendChild(document.createTextNode(inputValue.display_value));
|
||
|
||
// Set the default answer in the child cell
|
||
// childCell.innerHTML = child.default_answer.display_value;
|
||
// console.log('setting default value');
|
||
// console.log(child.default_answer.display_value)
|
||
childCell.contentEditable = true;
|
||
}
|
||
}
|
||
}
|
||
// }
|
||
});
|
||
}
|
||
}
|
||
}
|
||
|
||
function getCellIndices(target) {
|
||
// Get the clicked <td> element
|
||
let td = target;
|
||
|
||
// Get the column index of the clicked <td>
|
||
let columnIndex = td.cellIndex;
|
||
|
||
// Get the parent <tr> (row) of the clicked <td>
|
||
let tr = td.parentElement;
|
||
|
||
// Get the row index of the parent <tr> relative to the table
|
||
let rowIndex = tr.rowIndex;
|
||
|
||
// console.log("Row Index: ", rowIndex);
|
||
// console.log("Column Index: ", columnIndex);
|
||
|
||
return {
|
||
rowIndex,
|
||
columnIndex
|
||
};
|
||
}
|
||
|
||
function setCellInnerHTMLByCellIndex(tableId, rowIndex, colIndex, htmlContent) {
|
||
console.log(tableId + '-' + rowIndex + '-' + colIndex);
|
||
console.log(htmlContent);
|
||
// Get the table by its ID
|
||
let table = document.getElementById(tableId);
|
||
|
||
// Check if the table exists
|
||
if (table) {
|
||
// Get the row at the specified rowIndex
|
||
let row = table.rows[rowIndex];
|
||
|
||
// Check if the row exists
|
||
if (row) {
|
||
// Get the cell at the specified colIndex within the row
|
||
let cell = row.cells[colIndex];
|
||
|
||
// Check if the cell exists
|
||
if (cell) {
|
||
// Set the innerHTML of the cell
|
||
cell.innerHTML = htmlContent;
|
||
console.log(`Updated cell at row ${rowIndex}, column ${colIndex} with content: ${htmlContent}`);
|
||
} else {
|
||
console.error(`Column index ${colIndex} does not exist in row ${rowIndex}`);
|
||
}
|
||
} else {
|
||
console.error(`Row index ${rowIndex} does not exist in the table`);
|
||
}
|
||
} else {
|
||
console.error(`Table with ID ${tableId} not found`);
|
||
}
|
||
}
|
||
|
||
function checkCellValueAndHighlight() {
|
||
console.log('checkCellValueAndHighlight called');
|
||
|
||
const table = document.getElementById('rfqTable');
|
||
const headerRow1 = table.querySelectorAll('thead tr')[0]; // First header row (main headers)
|
||
const headerRow2 = table.querySelectorAll('thead tr')[1]; // Second header row (sub headers)
|
||
const rows = table.querySelectorAll('tbody tr');
|
||
|
||
let startCol = 2; // Start after omitting SNO and items columns
|
||
|
||
headerRow1.querySelectorAll('th').forEach((th, index) => {
|
||
if (index < 2) return; // Skip SNO and items
|
||
|
||
const colspan = th.getAttribute('colspan') ? parseInt(th.getAttribute('colspan')) : 1;
|
||
const compareIndices = [...Array(colspan).keys()].map(i => i +
|
||
startCol); // Get column indices to compare
|
||
|
||
rows.forEach(row => {
|
||
const cells = row.querySelectorAll('td');
|
||
compareRange(cells, compareIndices);
|
||
});
|
||
|
||
startCol += colspan; // Move to the next set of columns
|
||
});
|
||
|
||
isFormDataModified = true; // if any value changeing in the table to set true
|
||
}
|
||
|
||
function compareRange(cells, indices) {
|
||
const baseValue = cells[indices[0]].textContent; // Get the base value for comparison
|
||
indices.forEach(index => {
|
||
if (cells[index].textContent !== baseValue) {
|
||
cells[index].classList.add('bold'); // Highlight mismatched cells
|
||
} else {
|
||
cells[index].classList.remove('bold');
|
||
}
|
||
});
|
||
}
|
||
|
||
function validateCellContent(cell) {
|
||
|
||
console.log('onblur check td text content');
|
||
|
||
// Get the hidden value from the input field inside the cell
|
||
const hiddenInput = cell.querySelector('input[type="hidden"]');
|
||
const hiddenValue = hiddenInput.value;
|
||
|
||
// Get the row ID
|
||
const row = cell.closest('tr');
|
||
const rowId = row.getAttribute('id');
|
||
console.log(rowId);
|
||
const item = suggestions.hasOwnProperty(rowId) ? suggestions[rowId] : false;
|
||
console.log(item); //return;
|
||
|
||
if (item && item.type != 'text') {
|
||
|
||
// Get the text content the user entered in the cell
|
||
const enteredValue = cell.textContent.trim();
|
||
console.log('enteredValue - ' + enteredValue);
|
||
const preDefinedAnswers = item.answers;
|
||
console.log(preDefinedAnswers);
|
||
const correctAnswer = preDefinedAnswers.some(obj => obj['display_value'] === enteredValue);
|
||
// Compare hidden value and entered value
|
||
if (!correctAnswer) {
|
||
// If they are not the same, reset the cell's text content to the hidden value
|
||
cell.textContent = JSON.parse(hiddenValue).display_value;
|
||
cell.appendChild(hiddenInput);
|
||
|
||
// Re-append the hidden input to the cell after setting textContent
|
||
// cell.appendChild(hiddenInput);
|
||
}
|
||
|
||
isFormDataModified = true; // if any value changeing in the table to set true
|
||
}
|
||
}
|
||
|
||
function validateQuestionCellContent(cell) {
|
||
console.log('onblur check td text content for questions');
|
||
|
||
// Get the row ID
|
||
const row = cell.closest('tr');
|
||
const rowId = row.getAttribute('id');
|
||
console.log(rowId);
|
||
console.log(cell.textContent);
|
||
if (rowId && suggestions.hasOwnProperty(rowId) && !rowId.startsWith('special')) {
|
||
const item = suggestions.hasOwnProperty(rowId) ? suggestions[rowId] : false;
|
||
// console.log(item);//return;
|
||
let current_val = cell.textContent;
|
||
let expected_val = item.display_values;
|
||
if (current_val != expected_val) {
|
||
cell.textContent = expected_val;
|
||
}
|
||
} else if (!rowId && cell.textContent != '') {
|
||
alert('Not allowed,Please choose applicable question');
|
||
cell.textContent = '';
|
||
}
|
||
|
||
}
|
||
|
||
async function selectInsurer(insurers) {
|
||
|
||
// 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 setEldersCount(input) {
|
||
|
||
var selectedOption = $(input).find('option:selected');
|
||
var elders_count = selectedOption.data('value')
|
||
if (elders_count) {
|
||
$('#family_elders_count').val(elders_count)
|
||
} else {
|
||
$('#family_elders_count').val('')
|
||
|
||
}
|
||
}
|
||
|
||
function hideQCR() {
|
||
|
||
// console.log('hideQCR() function called')
|
||
// console.log(RFQ_or_QCR)
|
||
|
||
if (RFQ_or_QCR == 2) {
|
||
$('.qcrProposal').hide();
|
||
$('.qcrInsurer').hide();
|
||
$('.addInsurer').show();
|
||
$('.qcr_check_box_title').hide();
|
||
$('#addQuote').hide();
|
||
$('input[name="qcr"]').hide();
|
||
} else {
|
||
$('.qcrProposal').show();
|
||
$('.qcrInsurer').show();
|
||
$('#addQuote').show();
|
||
$('.qcr_check_box_title').show();
|
||
$('.addInsurer').hide();
|
||
$('input[name="qcr"]').show();
|
||
}
|
||
|
||
}
|
||
|
||
function setRowWiseQCRandSTCDatachange(input) {
|
||
|
||
// Ensure input is a jQuery object
|
||
var $input = $(input);
|
||
|
||
// Find the sibling 'input' with name 'client'
|
||
var client = $input.siblings('input[name="client"]');
|
||
console.log('client', client);
|
||
|
||
// Check if the current input is unchecked, and uncheck the client input
|
||
if (!$input.prop('checked')) {
|
||
client.prop('checked', false);
|
||
} else {
|
||
client.prop('checked', true);
|
||
}
|
||
|
||
// Ensure 'isFormDataModified' is declared before using it
|
||
console.log('isFormDataModified', window.isFormDataModified);
|
||
window.isFormDataModified = true; // Mark the form data as modified
|
||
}
|
||
|
||
|
||
//-----------------------------------------------------------------------------------------------------------
|
||
|
||
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", proposalDataForDropDown);
|
||
|
||
const selectElement = document.getElementById('proposals');
|
||
|
||
// Clear existing options
|
||
selectElement.innerHTML = '<option value="">Select Proposals</option>';
|
||
|
||
let loopindex = 1;
|
||
// 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}`);
|
||
|
||
let ProposelDisplayName = "Proposal Coverage"
|
||
if(proposalKey == "Existing Renewal" || proposalKey == "Existing Rollover"){
|
||
ProposelDisplayName = "Existing Coverage"
|
||
}else{
|
||
ProposelDisplayName = "Proposal Coverage " + loopindex;
|
||
loopindex ++
|
||
}
|
||
|
||
option.textContent = `${ProposelDisplayName} - ${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("append data:",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-12">
|
||
<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">
|
||
</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-6">
|
||
<label for="client_cc">CC </label>
|
||
<select class="form-control" id="client_cc" name="client_cc" required multiple>
|
||
<?php if($page_name == "RFQ") { $exclusiveUserList = $userList; } ?>
|
||
<?php if (isset($exclusiveUserList)) { ?>
|
||
<?php foreach ($exclusiveUserList as $user) { ?>
|
||
<?php if ($page_name == "RFQ" || in_array($user['role'],[1,5]) || in_array($user['team_id'],[6,7])) { ?>
|
||
<option value="<?= $user['id'];?>">
|
||
<?= $user['first_name'].' - '.$user['email'];?>
|
||
</option>
|
||
<?php } } ?>
|
||
<?php } ?>
|
||
</select>
|
||
</div>
|
||
|
||
<div class="form-group col-md-6">
|
||
<label for="client_bcc">BCC </label>
|
||
<select class="form-control" id="client_bcc" name="client_bcc" required multiple>
|
||
<?php if($page_name == "RFQ") { $exclusiveUserList = $userList; } ?>
|
||
<?php if (isset($exclusiveUserList)) { ?>
|
||
<?php foreach ($exclusiveUserList as $user) { ?>
|
||
<?php if ($page_name == "RFQ" || in_array($user['role'],[1,5]) || in_array($user['team_id'],[6,7])) { ?>
|
||
<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($page_name == "RFQ") { $exclusiveUserList = $userList; } ?>
|
||
<?php if (isset($exclusiveUserList)) { ?>
|
||
<?php foreach ($exclusiveUserList as $user) { ?>
|
||
<?php if ($page_name == "RFQ" || in_array($user['role'],[1,5]) || in_array($user['team_id'],[6,7])) { ?>
|
||
<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($page_name == "RFQ") { $exclusiveUserList = $userList; } ?>
|
||
<?php if (isset($exclusiveUserList)) { ?>
|
||
<?php foreach ($exclusiveUserList as $user) { ?>
|
||
<?php if ($page_name == "RFQ" || in_array($user['role'],[1,5]) || in_array($user['team_id'],[6,7])) { ?>
|
||
<?= $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){
|
||
var validationStatus = checkMailValidation();
|
||
|
||
if (validationStatus){
|
||
constructURL_ForInsurerAndClientMailSend();
|
||
}else{
|
||
toastr.error("All Client Mail ID's Should Contain Same Domain","ERROR");
|
||
}
|
||
}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();
|
||
var contact_mail = $("#contact_mail").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);
|
||
|
||
var selectedFiles = [];
|
||
$('#insurer_or_clinet_mail_attachment .multi_file_attachment:checked').each(function () {
|
||
selectedFiles.push($(this).val());
|
||
});
|
||
|
||
// 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);
|
||
formData.append('selected_attachment_files', JSON.stringify(selectedFiles));
|
||
|
||
|
||
if (RFQ_or_QCR == 2) {
|
||
formData.append('contact_mail',contact_mail);
|
||
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';
|
||
|
||
var selectedFiles = [];
|
||
$('#internal_mail_attachment .multi_file_attachment:checked').each(function () {
|
||
selectedFiles.push($(this).val());
|
||
});
|
||
|
||
// 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
|
||
formData.append('selected_attachment_files', JSON.stringify(selectedFiles));
|
||
|
||
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 policy_end_date = $('#policy_end_date').val();
|
||
let policy_start_date = $('#policy_start_date').val();
|
||
let payment_date = $('#payment_date').val();
|
||
let is_cd = $("#is_cd_switch").is(":checked") ? 1 : 0;
|
||
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();
|
||
let no_of_installment = $('#no_of_installment').val();
|
||
let is_installment = $("#is_installment_switch").is(":checked") ? 1 : 0;
|
||
console.log("cc1", cc);
|
||
|
||
// 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())`
|
||
|
||
|
||
var selectedFiles = [];
|
||
$('#placement_mail_attachment .multi_file_attachment:checked').each(function () {
|
||
selectedFiles.push($(this).val());
|
||
});
|
||
|
||
let data = [];
|
||
|
||
$('#installment_form_row .form-row').each(function () {
|
||
let installment_amount = $(this).find('input[name="installment_amount[]"]').val();
|
||
let payment_date = $(this).find('input[name="payment_date[]"]').val();
|
||
let utr_no = $(this).find('input[name="utr_no[]"]').val();
|
||
let id = $(this).find('input[name="installment_primary_key[]"]').val();
|
||
console.log('installment_primary_key', id);
|
||
|
||
let obj = {
|
||
lead_id: lead_id,
|
||
installment_amount: installment_amount,
|
||
payment_date: payment_date,
|
||
utr_no: utr_no
|
||
};
|
||
|
||
if (id != undefined && id != null && id != '') {
|
||
obj.id = id;
|
||
}
|
||
|
||
data.push(obj);
|
||
});
|
||
|
||
|
||
// 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('payment_date', payment_date);
|
||
formData.append('policy_end_date', policy_end_date);
|
||
formData.append('policy_start_date', policy_start_date);
|
||
formData.append("is_cd",is_cd);
|
||
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);
|
||
formData.append('selected_attachment_files', JSON.stringify(selectedFiles));
|
||
formData.append('installments', JSON.stringify(data));
|
||
formData.append('no_of_installment', no_of_installment);
|
||
formData.append('is_installment', is_installment);
|
||
|
||
|
||
ajaxRequest(formData);
|
||
|
||
}
|
||
|
||
function ajaxRequest(formData) {
|
||
|
||
// console.log("formData", formData);
|
||
// formData.forEach((value, key) => {
|
||
// console.log(key + ': ' + value);
|
||
// });
|
||
|
||
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 sent Successfully', 'SUCCESS')
|
||
if(res.is_placement == true){
|
||
clearInterval(intervalId);
|
||
console.log('******** Intervel Cleared ********')
|
||
}
|
||
} 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);
|
||
|
||
// Clear existing options and CC entries
|
||
$('#placement_to').empty().append($('<option>', {
|
||
value: '',
|
||
text: 'Select TO Mail'
|
||
}));
|
||
$('.ccInsurerMail').remove();
|
||
|
||
$.each(data, function(index, item) {
|
||
$('#placement_to').append($('<option>', {
|
||
value: item.id,
|
||
text: item.contact_person_email
|
||
}));
|
||
|
||
$('#placement_cc').append($('<option>', {
|
||
value: item.contact_person_email ?? "",
|
||
text: (item.contact_person_name || '') + (item.contact_person_email ? ' - ' + item.contact_person_email : '') + ' (Insurer)',
|
||
class: 'ccInsurerMail'
|
||
}));
|
||
});
|
||
|
||
// Re-initialize Select2
|
||
$('#placement_cc').val(null).select2({
|
||
placeholder: 'Select CC Mail'
|
||
});
|
||
|
||
// Style Select2 textarea input
|
||
setTimeout(function () {
|
||
$('textarea.select2-search__field').attr('rows', '1').css('resize', 'none');
|
||
}, 0);
|
||
}
|
||
|
||
|
||
$('.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');
|
||
})
|
||
|
||
function createFamilyDisplayStringPolicyTerms(familyArray) {
|
||
let displayString = [];
|
||
|
||
console.log('childern ', familyArray['childrens'])
|
||
|
||
// Add 'self' if the value is 1 (true)
|
||
if (familyArray['self']) {
|
||
displayString.push('Self');
|
||
}
|
||
|
||
// Add 'spouse' if the value is 1 (true)
|
||
if (familyArray['spouse']) {
|
||
displayString.push('Spouse');
|
||
}
|
||
|
||
// Add 'children(count)' if count > 0
|
||
if (familyArray['childrens'] > 0) {
|
||
displayString.push(`Children(${familyArray['childrens']})`);
|
||
}
|
||
|
||
// Determine family description based on elders and other conditions
|
||
let familyDescription = '';
|
||
|
||
if (familyArray['parents'] == 1 && familyArray['elders_count'] == 1) {
|
||
familyDescription = 'One Parent';
|
||
} else if (familyArray['parents'] == 2 && familyArray['elders_count'] == 2) {
|
||
familyDescription = 'Two Parents';
|
||
} else if (familyArray['parents-in-law'] == 1 && familyArray['elders_count'] == 1) {
|
||
familyDescription = 'One Parent-in-law';
|
||
} else if (familyArray['parents-in-law'] == 2 && familyArray['elders_count'] == 2) {
|
||
familyDescription = 'Two Parents-in-law';
|
||
} else if (familyArray['either-parents-pil'] == 1 && familyArray['elders_count'] == 2) {
|
||
familyDescription = 'Either Two Parents or Two Parents-in-law';
|
||
} else if (familyArray['either-parents-pil'] == 2 && familyArray['elders_count'] == 2) {
|
||
familyDescription = 'Any Two Parents or Parents-in-law';
|
||
} else if (familyArray['parents'] == 2 && familyArray['parents-in-law'] == 2 && familyArray['elders_count'] == 2) {
|
||
familyDescription = 'All Four Parents/Parents-in-law';
|
||
}
|
||
|
||
// Add the family description if it exists
|
||
if (familyDescription) {
|
||
displayString.push(familyDescription);
|
||
}
|
||
|
||
// Join the array with ' + ' to create the final display string
|
||
return displayString.join(' + ');
|
||
}
|
||
|
||
function mapValues(data) {
|
||
if (typeof data === "object" && data !== null) {
|
||
// Recursively process objects or arrays
|
||
for (const key in data) {
|
||
data[key] = mapValues(data[key]);
|
||
}
|
||
} else if (data === 1 || data === "1") {
|
||
return "Yes";
|
||
} else if (data === 0 || data === "0") {
|
||
return "No";
|
||
}
|
||
return data; // Return unchanged value for other cases
|
||
}
|
||
|
||
const tableContainer1 = document.getElementById('first_table');
|
||
const tableContainer2 = document.getElementById('second_table');
|
||
|
||
function syncScroll(source, target) {
|
||
target.scrollLeft = source.scrollLeft;
|
||
}
|
||
|
||
tableContainer1.addEventListener('scroll', () => {
|
||
syncScroll(tableContainer1, tableContainer2);
|
||
});
|
||
|
||
tableContainer2.addEventListener('scroll', () => {
|
||
syncScroll(tableContainer2, tableContainer1);
|
||
});
|
||
|
||
|
||
function getMailContent(id){
|
||
|
||
let url = '<?= base_url('util/transformMailContent') ?>';
|
||
|
||
let lead_id = $('#lead_id').val();
|
||
let file_type = RFQ_or_QCR == 2 ? 'qcr' : 'rfq';
|
||
let recipient_mail = 'venkateshraman786@gmail.com'
|
||
let recipient_type = 'venkateshraman786@gmail.com'
|
||
|
||
// Data to send in the AJAX request
|
||
let requestData = {
|
||
lead_id: lead_id,
|
||
recipient_type: recipient_type,
|
||
recipient_mail: recipient_mail,
|
||
file_type: file_type,
|
||
};
|
||
|
||
// Send AJAX request
|
||
sendAjaxRequestForGlobal(url, 'GET', requestData, function(response) {
|
||
console.log('Data fetched successfully:', response);
|
||
|
||
if (response.status) {
|
||
console.log(response);
|
||
$('#'+id).val(response.data)
|
||
} else {
|
||
toastr.error(response.message || 'Unable to fetch data', 'ERROR');
|
||
}
|
||
}, function(xhr, status, error) {
|
||
console.error('Error fetching data:', error);
|
||
console.error(xhr.responseText);
|
||
});
|
||
|
||
}
|
||
|
||
//--------------------------------------------------------------------------------------------------------------------------------------------
|
||
|
||
function constructInsurerNameWithVersion(proposal_name, insurerName) {
|
||
|
||
if (over_all_column_data[proposal_name]) {
|
||
let tempInsurerList = over_all_column_data[proposal_name].insurers;
|
||
|
||
if (!tempInsurerList.length) {
|
||
return `${insurerName}-V1`;
|
||
}
|
||
|
||
// Check for existing versions and determine the highest version number
|
||
let maxVersion = 0;
|
||
tempInsurerList.forEach(insurer => {
|
||
if (insurer.display_name.startsWith(`${insurerName}-V`)) {
|
||
let versionMatch = insurer.display_name.match(/-V(\d+)$/);
|
||
let version = versionMatch ? parseInt(versionMatch[1], 10) : 0;
|
||
if (version > maxVersion) {
|
||
maxVersion = version;
|
||
}
|
||
}
|
||
});
|
||
|
||
// Increment the version for the new entry
|
||
let newDisplayName = `${insurerName}-V${maxVersion + 1}`;
|
||
return newDisplayName;
|
||
}
|
||
return insurerName;
|
||
}
|
||
|
||
function checkTheTableDataChanged(redirect_type, url){
|
||
|
||
console.log('isFormDataModified', isFormDataModified);
|
||
|
||
if(isFormDataModified){
|
||
SweertAlert()
|
||
}else{
|
||
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 SweertAlert(){
|
||
|
||
// Swal.fire({
|
||
// title: "The table data has changed?",
|
||
// text: "Do you want Save this!",
|
||
// icon: "warning",
|
||
// showCancelButton: true,
|
||
// confirmButtonColor: "#3085d6",
|
||
// cancelButtonColor: "#d33",
|
||
// confirmButtonText: "Yes, Procced!"
|
||
// }).then((result) => {
|
||
// if (result.isConfirmed) {
|
||
// if(RFQ_or_QCR == 1){
|
||
// submitData();
|
||
// }else if(RFQ_or_QCR == 2) {
|
||
// submitQCRData()
|
||
// }
|
||
// return true;
|
||
// }else{
|
||
// return false;
|
||
// }
|
||
// });
|
||
|
||
Swal.fire({
|
||
title: "The table data has changed?",
|
||
text: "Do you want Save this!",
|
||
icon: "warning",
|
||
showCancelButton: true,
|
||
showDenyButton: true, // Show the "No" button
|
||
confirmButtonColor: "#3085d6",
|
||
cancelButtonColor: "#d33",
|
||
denyButtonColor: "#6c757d", // Optional: Color for the "No" button
|
||
confirmButtonText: "Yes, Proceed!",
|
||
denyButtonText: "No",
|
||
cancelButtonText: "Cancel"
|
||
}).then((result) => {
|
||
if (result.isConfirmed) {
|
||
// "Yes" button clicked
|
||
if (RFQ_or_QCR == 1) {
|
||
submitData();
|
||
} else if (RFQ_or_QCR == 2) {
|
||
submitQCRData();
|
||
}
|
||
return true;
|
||
} else if (result.isDenied) {
|
||
// "No" button clicked
|
||
isFormDataModified = false;
|
||
console.log("Data modification status reset to:", isFormDataModified);
|
||
return false;
|
||
} else {
|
||
// "Cancel" button clicked
|
||
console.log("Action canceled.");
|
||
return false;
|
||
}
|
||
});
|
||
|
||
}
|
||
|
||
//--------------------------------------------------------------------------------------------------------------------------------------------
|
||
|
||
// not in use do not remove this function
|
||
function tableToJson() {
|
||
|
||
const headers = [];
|
||
const data = [];
|
||
const table = document.getElementById('rfqTable');
|
||
console.log('over_all_column_data', over_all_column_data)
|
||
|
||
// Get the parent headers and subheaders
|
||
const parentHeaders = table.querySelectorAll('thead tr:nth-child(1) th');
|
||
const subHeaders = table.querySelectorAll('thead tr:nth-child(2) th');
|
||
|
||
const last_index = parentHeaders.length - 1;
|
||
let headerIndex = 0;
|
||
parentHeaders.forEach((header, index) => {
|
||
|
||
const colspan = header.getAttribute('colspan') || 1;
|
||
const subHeaderArray = [];
|
||
|
||
for (let i = 0; i < colspan; i++) {
|
||
subHeaderArray.push(subHeaders[headerIndex].innerText.replace('⋮', '').trim());
|
||
headerIndex++;
|
||
}
|
||
|
||
let parentHeaderValue;
|
||
if (headerIndex < 3 || headerIndex == last_index) {
|
||
parentHeaderValue = header.innerText.replace('⋮', '').trim();
|
||
} else {
|
||
parentHeaderValue = (header.querySelector('.key_name')?.innerText || '').trim();
|
||
}
|
||
|
||
console.log("parentHeaderValue", parentHeaderValue)
|
||
|
||
headers.push({
|
||
// parentHeader: header.innerText,
|
||
parentHeader: parentHeaderValue,
|
||
subHeaders: subHeaderArray
|
||
});
|
||
});
|
||
|
||
console.log('tableToJson headers', headers);
|
||
|
||
// Get the data from the table body
|
||
const rows = table.querySelectorAll('tbody tr');
|
||
console.log('rows', rows);
|
||
|
||
rows.forEach(row => {
|
||
|
||
const rowId = row.id;
|
||
|
||
console.log('rowId : ', rowId);
|
||
console.log(suggestions)
|
||
console.log(suggestions[rowId]['type'])
|
||
|
||
let inputType = suggestions[rowId]['type']
|
||
|
||
const cells = row.querySelectorAll('td');
|
||
console.log('Table row cells', cells);
|
||
const rowData = {
|
||
SNO: cells[0].innerText,
|
||
items: cells[1].innerText,
|
||
data: []
|
||
};
|
||
console.log('Table row rowData', rowData);
|
||
|
||
let dataIndex = 0;
|
||
|
||
headers.forEach(header => {
|
||
header.subHeaders.forEach(subHeader => {
|
||
|
||
const cell = cells[dataIndex];
|
||
console.log(cell)
|
||
|
||
let content = cells[dataIndex].innerText;
|
||
|
||
if (inputType == "text") {
|
||
|
||
if (header.parentHeader == 'Action') {
|
||
|
||
if (!cell) {
|
||
console.error(`Cell not found for dataIndex: ${dataIndex}`);
|
||
return;
|
||
}
|
||
|
||
const qcrInput = cell.querySelector('input[name="qcr"]');
|
||
const clientInput = cell.querySelector('input[name="client"]');
|
||
|
||
// console.log('qcrInput', qcrInput)
|
||
// console.log('clientInput', clientInput)
|
||
// console.log('qcrInput', qcrInput.checked)
|
||
// console.log('clientInput', clientInput.checked)
|
||
|
||
if (qcrInput != null && clientInput != null) {
|
||
content = {
|
||
qcr: qcrInput.checked ? 1 : 0, // Checkbox handling
|
||
stc: clientInput.checked ? 1 : 0
|
||
};
|
||
}
|
||
|
||
} else {
|
||
|
||
const input = cell.querySelector('input');
|
||
console.log('input cell', input)
|
||
|
||
if (input) {
|
||
content = input.value;
|
||
// console.log('hidden input value', content);
|
||
} else {
|
||
content = cells[dataIndex].innerText;
|
||
}
|
||
}
|
||
|
||
} else {
|
||
|
||
if (!cell) {
|
||
console.error(`Cell not found for dataIndex: ${dataIndex}`);
|
||
return;
|
||
}
|
||
|
||
let value = '';
|
||
const input = cell.querySelector('input');
|
||
console.log('input cell', input)
|
||
|
||
if (input) {
|
||
|
||
if (header.parentHeader == 'Action') {
|
||
|
||
const qcrInput = cell.querySelector('input[name="qcr"]');
|
||
const clientInput = cell.querySelector('input[name="client"]');
|
||
|
||
console.log('qcrInput', qcrInput)
|
||
console.log('clientInput', clientInput)
|
||
|
||
if (qcrInput != null && clientInput != null) {
|
||
value = {
|
||
qcr: qcrInput.checked ? 1 : 0, // Checkbox handling
|
||
stc: clientInput.checked ? 1 : 0
|
||
};
|
||
}
|
||
|
||
} else {
|
||
value = input.value;
|
||
}
|
||
|
||
} else {
|
||
value = cell.innerText;
|
||
}
|
||
|
||
content = value;
|
||
|
||
}
|
||
|
||
|
||
rowData.data.push({
|
||
parentth: header.parentHeader,
|
||
subth: subHeader,
|
||
value: cells[dataIndex].innerText,
|
||
input_value: content
|
||
});
|
||
|
||
dataIndex++;
|
||
});
|
||
});
|
||
|
||
data.push(rowData);
|
||
});
|
||
|
||
const d = JSON.stringify({
|
||
table_data: {
|
||
headers: headers,
|
||
data: data
|
||
},
|
||
proposal_data: {
|
||
over_all_column_data: over_all_column_data
|
||
}
|
||
});
|
||
|
||
localStorage.setItem('data', d);
|
||
|
||
console.log({
|
||
headers,
|
||
data
|
||
});
|
||
|
||
jsonToTable(JSON.parse(d));
|
||
}
|
||
|
||
function jsonToTable(json) {
|
||
|
||
const table = document.getElementById('rfqTable');
|
||
const thead = table.querySelector('thead');
|
||
const tbody = table.querySelector('tbody');
|
||
|
||
// Clear existing rows to avoid duplicates
|
||
thead.innerHTML = '';
|
||
tbody.innerHTML = '';
|
||
|
||
// Create header rows
|
||
const parentHeaderRow = document.createElement('tr');
|
||
const subHeaderRow = document.createElement('tr');
|
||
|
||
var proposels = json.proposal_data.over_all_column_data;
|
||
let randomColor = 'hsl(' + Math.random() * 360 + ', 100%, 93%)';
|
||
|
||
var proposel_count = 0;
|
||
var proposel_count_for_title = 1;
|
||
var proposel_color_count = [];
|
||
|
||
let remove_proposel_name = [];
|
||
// let remove_insurer_name = [];
|
||
|
||
// Add dynamic headers and subheaders
|
||
json.table_data.headers.forEach(header => {
|
||
|
||
// console.log('header.parentHeader', proposels[header.parentHeader])
|
||
|
||
const parentTh = document.createElement('th');
|
||
|
||
//for RFQ hidden perpose
|
||
if(RFQ_or_QCR == 1){
|
||
parentTh.colSpan = 1;
|
||
parentTh.setAttribute('data-colspan', header.subHeaders.length);
|
||
}else{
|
||
parentTh.colSpan = header.subHeaders.length;
|
||
}
|
||
|
||
let randomColor = 'hsl(' + Math.random() * 360 + ', 100%, 93%)';
|
||
|
||
// Check if header is not "Sno", "Item Key", "Particulars", or "Action" before adding dropdown
|
||
if (!["Sno", "Item Key", "Particulars", "Action"].includes(header.parentHeader)) {
|
||
|
||
proposel_count++;
|
||
|
||
// Extract qcr and stc status for the main headers
|
||
const dropdown_data_qcr = proposels[header.parentHeader]?.qcr == 1 ?
|
||
'style="background-color: rgb(221, 221, 221);"' : '';
|
||
const dropdown_data_stc = proposels[header.parentHeader]?.stc == 1 ?
|
||
'style="background-color: rgb(221, 221, 221);"' : '';
|
||
|
||
const check_icon_qcr = proposels[header.parentHeader]?.qcr == 1 ?
|
||
`<i class="fa fa-check-square" style="color: green; margin-left: 8px;"></i>` : '';
|
||
const check_icon_stc = proposels[header.parentHeader]?.stc == 1 ?
|
||
`<i class="fa fa-check-square" style="color: green; margin-left: 8px;"></i>` : '';
|
||
|
||
|
||
let renewal_or_rollover = header.parentHeader;
|
||
let renewal_or_rollover_display_name = "Proposal Coverage " + (proposel_count_for_title);
|
||
|
||
if(["Existing Renewal", "Existing Rollover"].includes(header.parentHeader)){
|
||
renewal_or_rollover_display_name = "Existing Coverage";
|
||
}else{
|
||
proposel_count_for_title ++ ;
|
||
}
|
||
|
||
parentTh.innerHTML = `
|
||
<span class="key_name" style="display: none;">${renewal_or_rollover}</span><span class="display_name">${renewal_or_rollover_display_name}</span>
|
||
<span class="dropdown" onclick="showThreeDottedMenu(event)">
|
||
<button class="dropbtn">⋮</button>
|
||
<div class="dropdown-content">
|
||
<a href="#" class="addInsurer">Add Insurer</a>
|
||
<a href="#" class="qcrProposal" ${dropdown_data_qcr}>QCR${check_icon_qcr}</a>
|
||
<a href="#" class="sendClientProposal" ${dropdown_data_stc}>Send to Client${check_icon_stc}</a>
|
||
<a href="#" class="removeProposal">Remove</a>
|
||
</div>
|
||
</span>`;
|
||
|
||
// console.log('proposel_count', proposel_count);
|
||
|
||
if (proposel_count > 1) {
|
||
parentTh.style.backgroundColor = randomColor;
|
||
proposel_color_count[header.parentHeader] = randomColor;
|
||
}
|
||
|
||
} else {
|
||
if(["Sno"].includes(header.parentHeader)){
|
||
let snoKeyName = header.parentHeader;
|
||
let snoDisplayName = "S.No.";
|
||
parentTh.innerHTML = ` <span class="key_name" style="display: none;">${snoKeyName}</span><span class="display_name">${snoDisplayName}</span>`;
|
||
}else{
|
||
parentTh.innerText = header.parentHeader;
|
||
}
|
||
}
|
||
|
||
// Hide column if header is "Item Key"
|
||
if (header.parentHeader === "Item Key") {
|
||
parentTh.classList.add('hidden', 'no-border');
|
||
parentTh.style.borderRight = '2px solid snow';
|
||
parentTh.style.setProperty('border-right', '2px solid snow', 'important');
|
||
}
|
||
|
||
if (header.parentHeader === "Particulars") {
|
||
parentTh.classList.add('sticky', 'no-border');
|
||
parentTh.style.setProperty('border-top', borderPixel, 'important');
|
||
parentTh.style.setProperty('border-right', borderPixel, 'important');
|
||
|
||
}
|
||
|
||
if (header.parentHeader === "Sno") {
|
||
parentTh.classList.add('sticky', 'no-border');
|
||
parentTh.style.setProperty('border-right', borderPixel, 'important');
|
||
parentTh.style.setProperty('border-left', borderPixel, 'important');
|
||
parentTh.style.setProperty('border-top', borderPixel, 'important');
|
||
parentTh.style.setProperty('min-width', snoColumnWidth, 'important');
|
||
}
|
||
|
||
if (header.parentHeader === "Action") {
|
||
|
||
parentTh.classList.add('no-border');
|
||
parentTh.style.setProperty('border-right', borderPixel, 'important');
|
||
parentTh.style.setProperty('border-left', borderPixel, 'important');
|
||
parentTh.style.setProperty('border-top', borderPixel, 'important');
|
||
}
|
||
|
||
if (RFQ_or_QCR == 2) {
|
||
if (proposels[header.parentHeader] && proposels[header.parentHeader].qcr !== undefined) {
|
||
if (proposels[header.parentHeader].qcr == 0 || proposels[header.parentHeader].qcr == false) {
|
||
parentTh.classList.add('hidden');
|
||
remove_proposel_name.push(header.parentHeader);
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
parentHeaderRow.appendChild(parentTh);
|
||
|
||
// Add subheaders, hiding those under "Item Key"
|
||
header.subHeaders.forEach((subHeader, index) => {
|
||
|
||
const subTh = document.createElement('th');
|
||
|
||
// Hide if parent header is "Item Key"
|
||
if (header.parentHeader === "Item Key") {
|
||
subTh.classList.add('hidden', 'no-border');
|
||
subTh.style.color = '#bfe0e2';
|
||
subTh.style.setProperty('border-right', borderPixel, 'important');
|
||
}
|
||
|
||
if (header.parentHeader === "Particulars") {
|
||
subTh.classList.add('sticky', 'no-border');
|
||
subTh.style.color = '#bfe0e2';
|
||
subTh.style.setProperty('border-bottom', borderPixel, 'important');
|
||
subTh.style.setProperty('border-right', borderPixel, 'important');
|
||
}
|
||
|
||
if (header.parentHeader === "Sno") {
|
||
subTh.classList.add('sticky', 'no-border');
|
||
subTh.style.color = '#bfe0e2';
|
||
subTh.style.setProperty('border-right', borderPixel, 'important');
|
||
subTh.style.setProperty('border-left', borderPixel, 'important');
|
||
subTh.style.setProperty('min-width', snoColumnWidth, 'important');
|
||
}
|
||
|
||
if (header.parentHeader === "Action") {
|
||
subTh.classList.add('no-border');
|
||
subTh.style.color = '#fff';
|
||
subTh.style.setProperty('border-right', borderPixel, 'important');
|
||
subTh.style.setProperty('border-left', borderPixel, 'important');
|
||
}
|
||
|
||
// Add dropdown menu only if subHeader is not "Quote Asked" or "-"
|
||
if (!["Quote Asked", "-", ""].includes(subHeader)) {
|
||
|
||
// Set default values for dropdown data
|
||
let dropdownDataQCRForInsurer = '';
|
||
let dropdownDataSTCForInsurer = '';
|
||
|
||
let checkDropdownDataQCRForInsurer = '';
|
||
let checkDropdownDataSTCForInsurer = '';
|
||
|
||
// Check if header is allowed to have insurer data
|
||
if (!["Sno", "Item Key", "Particulars", "Action", ""].includes(header.parentHeader)) {
|
||
|
||
const insurerData = proposels[header.parentHeader]?.insurers[index - 1] || {};
|
||
|
||
dropdownDataQCRForInsurer = insurerData.qcr == 1 ?
|
||
'style="background-color: rgb(221, 221, 221);"' : '';
|
||
dropdownDataSTCForInsurer = insurerData.stc == 1 ?
|
||
'style="background-color: rgb(221, 221, 221);"' : '';
|
||
|
||
checkDropdownDataQCRForInsurer = insurerData.qcr == 1 ?
|
||
`<i class="fa fa-check-square" style="color: green; margin-left: 8px;"></i>` :
|
||
'';
|
||
checkDropdownDataSTCForInsurer = insurerData.stc == 1 ?
|
||
`<i class="fa fa-check-square" style="color: green; margin-left: 8px;"></i>` :
|
||
'';
|
||
|
||
// console.log('Proposal data for insurer (insurerData):', insurerData);
|
||
// console.log('Proposal data for insurer (QCR):', dropdownDataQCRForInsurer);
|
||
// console.log('Proposal data for insurer (STC):', dropdownDataSTCForInsurer);
|
||
}
|
||
|
||
subTh.innerHTML = `${subHeader} <span class="dropdown" onclick="showThreeDottedMenu(event)">
|
||
<button class="dropbtn">⋮</button>
|
||
<div class="dropdown-content">
|
||
<a href="#" class="changeInsurer">Change Insurer</a>
|
||
<a href="#" class="qcrInsurer" ${dropdownDataQCRForInsurer}>QCR${checkDropdownDataQCRForInsurer}</a>
|
||
<a href="#" class="sendClientInsurer" ${dropdownDataSTCForInsurer}>Send to Client${checkDropdownDataSTCForInsurer}</a>
|
||
<a href="#" class="removeInsurer">Remove</a>
|
||
<!--<a href="#" class="copyInsurerLast">Copy</a> -->
|
||
</div>
|
||
</span>`;
|
||
|
||
//for RFQ hidden perpose
|
||
if(RFQ_or_QCR == 1){
|
||
subTh.classList.add('hidden');
|
||
}
|
||
|
||
} else {
|
||
|
||
if(!["-"].includes(subHeader)){
|
||
let subHeaderDisplayName = subHeader;
|
||
subTh.innerHTML = `<span class="key_name" style="display: none;">${subHeader}</span><span class="display_name">${subHeaderDisplayName}</span>`;
|
||
}else{
|
||
subTh.innerText = subHeader;
|
||
}
|
||
}
|
||
|
||
if (!["-", ""].includes(subHeader) && proposel_count > 1) {
|
||
subTh.style.backgroundColor = randomColor;
|
||
}
|
||
|
||
//for QCR hidden fields
|
||
if(RFQ_or_QCR == 2){
|
||
|
||
if (proposels[header.parentHeader] && proposels[header.parentHeader].qcr !== undefined) {
|
||
if(proposels[header.parentHeader].qcr == 0 || proposels[header.parentHeader].qcr == false){
|
||
subTh.classList.add('hidden')
|
||
}else{
|
||
// proposels[header.parentHeader].insurers.forEach((subHeaderRemove, index) => {
|
||
|
||
// if(subHeaderRemove.qcr == 0 || subHeaderRemove.qcr == false){
|
||
// subTh.classList.add('hidden')
|
||
// remove_insurer_name.push(subHeaderRemove.display_name)
|
||
// }
|
||
|
||
// });
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
subHeaderRow.appendChild(subTh);
|
||
});
|
||
});
|
||
|
||
// console.log('remove_proposel_name', remove_proposel_name);
|
||
// console.log('proposel_color_count', proposel_color_count);
|
||
|
||
thead.appendChild(parentHeaderRow);
|
||
thead.appendChild(subHeaderRow);
|
||
|
||
// Populate table rows based on JSON data
|
||
json.table_data.data.forEach((rowData, rowIndex) => {
|
||
|
||
// console.log(rowData)
|
||
// console.log(rowData.items)
|
||
|
||
const row = document.createElement('tr');
|
||
|
||
// Serial number column
|
||
const snoTd = document.createElement('td');
|
||
snoTd.classList.add('sno');
|
||
snoTd.innerText = rowIndex + 1;
|
||
snoTd.style.setProperty('min-width', snoColumnWidth, 'important');
|
||
row.appendChild(snoTd);
|
||
|
||
// Hidden Item Key column
|
||
const itemKeyTd = document.createElement('td');
|
||
itemKeyTd.classList.add('hidden');
|
||
itemKeyTd.innerText = rowData.items || '';
|
||
row.appendChild(itemKeyTd);
|
||
|
||
row.id = rowData.items || '';
|
||
suggestionKeys.push(rowData.items);
|
||
|
||
// Particulars column
|
||
const particularsTd = document.createElement('td');
|
||
particularsTd.classList.add('particulars', 'sticky');
|
||
particularsTd.contentEditable = true;
|
||
// particularsTd.innerText = rowData.particulars || '';
|
||
particularsTd.innerText = rowData.data.find(d => d.parentth === "Particulars").input_value;
|
||
row.appendChild(particularsTd);
|
||
|
||
// Proposal columns and other data columns
|
||
rowData.data.forEach(dataEntry => {
|
||
|
||
// console.log('dataEntry', dataEntry)
|
||
|
||
const td = document.createElement('td');
|
||
|
||
if(rowData.SNO == "1"){
|
||
td.style.setProperty('border-top', borderPixel, 'important');
|
||
}
|
||
|
||
if (dataEntry.parentth === "Action") {
|
||
td.classList.add('action');
|
||
const qcrChecked = dataEntry.input_value?.qcr ? "checked" : "";
|
||
const clientChecked = dataEntry.input_value?.stc ? "checked" : "";
|
||
td.innerHTML = `
|
||
<input type="checkbox" name="qcr" ${qcrChecked} onchange="setRowWiseQCRandSTCDatachange(this)"> <span class="qcr_check_box_title">QCR</span>
|
||
<input type="checkbox" name="client" ${clientChecked} onchange="setRowWiseQCRandSTCDatachange(this)"> Client
|
||
<button class="btn btn-danger btn-sm removeRow">−</button>
|
||
`;
|
||
} else {
|
||
|
||
//Hide QUOTE ASKED if insurer exist
|
||
let insurerCountForDisableQuoteAsked = 0;
|
||
td.innerText = dataEntry.value || '';
|
||
|
||
if(!["Sno", "Item Key", "Particulars", "Action"].includes(dataEntry.parentth)){
|
||
const insurers = proposels[dataEntry?.parentth]?.insurers;
|
||
insurerCountForDisableQuoteAsked = insurers?.length ?? 0;
|
||
}
|
||
|
||
if(RFQ_or_QCR == 1){
|
||
//if the page is RFQ than check the insurer after disable the quote asked
|
||
if(dataEntry.subth === "Quote Asked" && insurerCountForDisableQuoteAsked > 0){
|
||
td.contentEditable = false;
|
||
td.classList.add('readonly-select');
|
||
}else{
|
||
td.contentEditable = true;
|
||
td.classList.add('editablecolumns');
|
||
}
|
||
}else{
|
||
//if the page is QCR than disable the quote asked default
|
||
if(dataEntry.subth === "Quote Asked"){
|
||
td.contentEditable = false;
|
||
td.classList.add('readonly-select');
|
||
}else{
|
||
td.contentEditable = true;
|
||
td.classList.add('editablecolumns');
|
||
}
|
||
}
|
||
// end of hide QUOTE ASKED if insurer exist
|
||
|
||
const hiddenInput = document.createElement('input');
|
||
hiddenInput.type = 'hidden';
|
||
hiddenInput.value = dataEntry.input_value || '';
|
||
|
||
// console.log('dataEntry.parentth', dataEntry.parentth);
|
||
if (proposel_color_count.hasOwnProperty(dataEntry.parentth)) {
|
||
// console.log('dataEntry.parentth', dataEntry.parentth);
|
||
td.style.backgroundColor = proposel_color_count[dataEntry.parentth];
|
||
}
|
||
|
||
//for RFQ hidden perpose
|
||
if(!["-", "Quote Asked"].includes(dataEntry.subth)){
|
||
if(RFQ_or_QCR == 1){
|
||
td.classList.add('hidden');
|
||
}
|
||
}
|
||
|
||
td.appendChild(hiddenInput);
|
||
}
|
||
|
||
if (dataEntry.parentth !== "Sno" && dataEntry.parentth !== "Item Key" && dataEntry
|
||
.parentth !== "Particulars") {
|
||
row.appendChild(td);
|
||
}
|
||
|
||
if(RFQ_or_QCR == 2){
|
||
|
||
if(remove_proposel_name.includes(dataEntry.parentth)){
|
||
td.classList.add('hidden')
|
||
}
|
||
|
||
if(dataEntry.input_value.qcr == 0 || dataEntry.input_value.qcr == false){
|
||
row.classList.add('hidden')
|
||
}
|
||
}
|
||
});
|
||
|
||
tbody.appendChild(row);
|
||
});
|
||
|
||
proposal_colum_count = proposal_colum_count + proposel_count - 1;
|
||
proposel_count = 0;
|
||
|
||
// // Display JSON data for debugging
|
||
// const div = document.getElementById('second');
|
||
// console.log(div);
|
||
// div.innerHTML = ''; // Clear previous content
|
||
// const p = document.createElement('pre');
|
||
// p.innerText = JSON.stringify(json, null, 2);
|
||
// div.appendChild(p);
|
||
|
||
over_all_column_data = json.proposal_data.over_all_column_data;
|
||
|
||
moveAddRowButton();
|
||
attachEventListeners();
|
||
checkCellValueAndHighlight();
|
||
updateRowNumbers()
|
||
hideQCR()
|
||
|
||
isFormDataModified = false;
|
||
if(RFQ_or_QCR == 2){
|
||
populateTable(json)
|
||
}
|
||
}
|
||
|
||
//Premium Calculation child table
|
||
function populateTable(json) {
|
||
|
||
console.log('populateTable json data', json);
|
||
|
||
const table = document.getElementById("rfqTable_for_calc");
|
||
const thead = document.createElement("thead");
|
||
const tbody = document.createElement("tbody");
|
||
|
||
const headerRow1 = document.createElement("tr");
|
||
const headerRow2 = document.createElement("tr");
|
||
|
||
var proposels = json.proposal_data.over_all_column_data;
|
||
let proposel_count = 1;
|
||
|
||
// Iterate over the headers to create thead
|
||
json.table_data.headers.forEach(header => {
|
||
|
||
let randomColor = 'hsl(' + Math.random() * 360 + ', 100%, 93%)';
|
||
|
||
// Skip unwanted parent headers
|
||
if (!["Item Key"].includes(header.parentHeader)) {
|
||
// console.log(header.parentHeader);
|
||
|
||
// if(header.subHeaders.length == 1){
|
||
// console.log('header.subHeaders.length', header.subHeaders.length)
|
||
// if(!["Sno", "Particulars", "Action"].includes(header.parentHeader)){
|
||
// console.log('returned ............', header.parentHeader);
|
||
// return;
|
||
// }
|
||
// }
|
||
|
||
// Create the parent header
|
||
const th = document.createElement("th");
|
||
|
||
if(["Sno", "Particulars", "Action"].includes(header.parentHeader)){
|
||
th.textContent = header.parentHeader;
|
||
}else{
|
||
|
||
let calc_renewal_or_rollover = header.parentHeader;
|
||
let calc_renewal_or_rollover_display_name = "Proposal Coverage " + (proposel_count);
|
||
|
||
if(["Existing Renewal", "Existing Rollover"].includes(header.parentHeader)){
|
||
calc_renewal_or_rollover_display_name = "Existing Coverage";
|
||
}else{
|
||
proposel_count ++;
|
||
}
|
||
|
||
th.innerHTML = `<span class="key_name" style="display: none;">${calc_renewal_or_rollover}</span><span class="display_name">${calc_renewal_or_rollover_display_name}</span>`
|
||
|
||
}
|
||
|
||
if (header.parentHeader === "Particulars") {
|
||
th.classList.add('sticky', 'no-border');
|
||
th.style.color = '#fff';
|
||
th.style.backgroundColor = '#fff';
|
||
// th.style.borderRight = '2px solid snow';
|
||
// th.style.setProperty('border-right', '2px solid snow', 'important');
|
||
}
|
||
|
||
if (header.parentHeader === "Sno") {
|
||
th.classList.add('sticky', 'no-border');
|
||
th.style.color = '#fff';
|
||
th.style.backgroundColor = '#fff';
|
||
th.style.setProperty('min-width', snoColumnWidth, 'important');
|
||
// th.style.color = "#bfe0e2";
|
||
// th.style.borderRight = '2px solid snow';
|
||
// th.style.setProperty('border-right', '2px solid snow', 'important');
|
||
}
|
||
|
||
if (header.parentHeader === "Action") {
|
||
th.classList.add('readonly-select');
|
||
th.textContent = " ";
|
||
}
|
||
|
||
if(header.parentHeader !== 'Particulars' && header.parentHeader !== 'Sno' && header.parentHeader !== "Action"){
|
||
// th.style.backgroundColor = randomColor;
|
||
}
|
||
|
||
if (header.parentHeader === "Particulars") {
|
||
th.classList.add('readonly-select');
|
||
// th.style.color = "#bfe0e2";
|
||
}
|
||
|
||
// Calculate colspan based on the number of subheaders
|
||
const subHeaderCount = header.subHeaders.length;
|
||
// const subHeaderCount = (header.subHeaders.length) - 1;
|
||
console.log("subHeaderCount : ", subHeaderCount);
|
||
|
||
if (subHeaderCount > 0) {
|
||
th.setAttribute("colspan", subHeaderCount);
|
||
} else {
|
||
th.setAttribute("colspan", 1);
|
||
}
|
||
|
||
if (RFQ_or_QCR == 2) {
|
||
if (proposels[header.parentHeader] && proposels[header.parentHeader].qcr !== undefined) {
|
||
if (proposels[header.parentHeader].qcr == 0 || proposels[header.parentHeader].qcr == false) {
|
||
th.classList.add('hidden');
|
||
}
|
||
}
|
||
}
|
||
|
||
headerRow1.appendChild(th);
|
||
|
||
// Create and append subheaders to the second row
|
||
header.subHeaders.forEach(subHeader => {
|
||
const subTh = document.createElement("th");
|
||
|
||
if(subHeader == "Quote Asked"){
|
||
let subHeaderKeyName = subHeader
|
||
let subHeaderDisplayName = "Particulars"
|
||
subTh.innerHTML = `<span class="key_name" style="display: none;">${subHeaderKeyName}</span><span class="display_name">${subHeaderDisplayName}</span>`;
|
||
}else{
|
||
subTh.textContent = subHeader;
|
||
}
|
||
|
||
if (header.parentHeader === "Particulars") {
|
||
subTh.classList.add('sticky', 'no-border');
|
||
subTh.style.color = '#fff';
|
||
subTh.style.backgroundColor = '#fff';
|
||
// subTh.style.borderRight = '2px solid snow';
|
||
// subTh.style.setProperty('border-right', '2px solid snow', 'important');
|
||
// subTh.style.setProperty('border-bottom', '2px solid snow', 'important');
|
||
}
|
||
|
||
if (header.parentHeader === "Sno") {
|
||
subTh.classList.add('sticky', 'no-border');
|
||
subTh.style.color = '#fff';
|
||
subTh.style.backgroundColor = '#fff';
|
||
subTh.style.setProperty('min-width', snoColumnWidth, 'important');
|
||
// subTh.style.borderRight = '2px solid snow';
|
||
// subTh.style.setProperty('border-right', '2px solid snow', 'important');
|
||
}
|
||
|
||
if (header.parentHeader === "Action") {
|
||
subTh.classList.add('readonly-select');
|
||
subTh.textContent = " ";
|
||
}
|
||
|
||
if(header.parentHeader != "Particulars" && header.parentHeader !== 'Sno' && header.parentHeader !== "Action"){
|
||
// subTh.style.backgroundColor = randomColor;
|
||
}
|
||
|
||
if (header.parentHeader === "Particulars") {
|
||
subTh.classList.add('readonly-select');
|
||
subTh.textContent = " ";
|
||
}
|
||
|
||
//for QCR hidden fields
|
||
if(RFQ_or_QCR == 2){
|
||
if (proposels[header.parentHeader] && proposels[header.parentHeader].qcr !== undefined) {
|
||
if(proposels[header.parentHeader].qcr == 0 || proposels[header.parentHeader].qcr == false){
|
||
subTh.classList.add('hidden')
|
||
}
|
||
}
|
||
}
|
||
|
||
headerRow2.appendChild(subTh);
|
||
});
|
||
|
||
}
|
||
});
|
||
|
||
// Append rows to thead
|
||
thead.appendChild(headerRow1);
|
||
thead.appendChild(headerRow2);
|
||
|
||
// Append thead to table
|
||
table.appendChild(thead);
|
||
|
||
// Generate tbody rows based on subheaders
|
||
const rowLabels = ["Premium", "GST (%)", "GST Amount (₹)", "Total"];
|
||
|
||
rowLabels.forEach((label, rowIndex) => {
|
||
|
||
console.log("rowLabels", rowLabels);
|
||
const tr = document.createElement("tr");
|
||
|
||
// First column: Serial No
|
||
const tdFirst = document.createElement("td");
|
||
tdFirst.textContent = rowIndex + 1;
|
||
tdFirst.className = "sticky readonly-select";
|
||
// tdFirst.style.color = "#bfe0e2";
|
||
tdFirst.style.color = "#fff";
|
||
tdFirst.style.backgroundColor = "#fff";
|
||
tdFirst.style.border = "none";
|
||
tdFirst.style.setProperty('min-width', snoColumnWidth, 'important');
|
||
tr.appendChild(tdFirst);
|
||
|
||
// Second column: Row label
|
||
const tdLabel = document.createElement("td");
|
||
tdLabel.textContent = label;
|
||
// tdLabel.style.color = "#bfe0e2";
|
||
tdLabel.style.color = "#fff";
|
||
tdLabel.style.backgroundColor = "#fff";
|
||
tdLabel.style.border = "none";
|
||
tdLabel.className = "sticky readonly-select";
|
||
tr.appendChild(tdLabel);
|
||
|
||
console.log("before header loop");
|
||
// Create a td for each subheader
|
||
json.table_data.headers.forEach((header, headerIndexForCalc) => {
|
||
if (!["Item Key", "Sno", "Particulars"].includes(header.parentHeader)) {
|
||
|
||
// if(header.subHeaders.length == 1){
|
||
// console.log('DATA header.subHeaders.length', header.subHeaders.length)
|
||
// if(!["Action"].includes(header.parentHeader)){
|
||
// console.log('DATA returned ............', header.parentHeader);
|
||
// return;
|
||
// }
|
||
// }
|
||
|
||
header.subHeaders.forEach((value, index) => {
|
||
|
||
// if(value != '-'){
|
||
const td = document.createElement("td");
|
||
|
||
if(label == "Total") {
|
||
td.setAttribute("contenteditable", false);
|
||
td.classList.add('readonly-select')
|
||
}else{
|
||
td.setAttribute("contenteditable", "true");
|
||
}
|
||
|
||
if(header.parentHeader == "Action"){
|
||
td.setAttribute("contenteditable", false);
|
||
td.classList.add('action');
|
||
td.classList.add('disableborder');
|
||
td.classList.add('readonly-select');
|
||
}
|
||
|
||
td.classList.add(
|
||
'editablecolumnsforcalc',
|
||
label.toLowerCase().replace(/\s+/g, '').replace(/[%₹()]/g, '')
|
||
);
|
||
|
||
|
||
// if(value == "Quote Asked"){
|
||
// td.setAttribute("contenteditable", false);
|
||
// // td.classList.add('hidden');
|
||
// // td.style.color = randomColor;
|
||
// }
|
||
|
||
if(RFQ_or_QCR == 2){
|
||
if (proposels[header.parentHeader] && proposels[header.parentHeader].qcr !== undefined) {
|
||
if(proposels[header.parentHeader].qcr == 0 || proposels[header.parentHeader].qcr == false){
|
||
td.classList.add('hidden')
|
||
}
|
||
}
|
||
}
|
||
|
||
// td.id = `${label.toLowerCase()}`;
|
||
// console.log('child table', header.parentHeader);
|
||
if(value == "Quote Asked"){
|
||
td.setAttribute("contenteditable", false);
|
||
td.textContent = label;
|
||
}else{
|
||
td.textContent = json.premium_data?.data?.[header.parentHeader]?.[value]?.[label] || "";
|
||
}
|
||
tr.appendChild(td);
|
||
// }
|
||
});
|
||
}
|
||
});
|
||
|
||
|
||
console.log("After header loop");
|
||
// Add the row to tbody
|
||
tbody.appendChild(tr);
|
||
});
|
||
|
||
// Append tbody to table
|
||
table.appendChild(tbody);
|
||
|
||
if(premium_data_check){
|
||
isFormDataModified = true;
|
||
}
|
||
}
|
||
|
||
function generateJSONFromTable() {
|
||
|
||
const table = document.getElementById("rfqTable_for_calc");
|
||
console.log(table);
|
||
|
||
const jsonData = { data: {} };
|
||
|
||
// Get header rows
|
||
const headerRows = table.querySelectorAll("thead tr");
|
||
const parentHeaders = [];
|
||
const subHeaders = [];
|
||
|
||
console.log('headerRows', headerRows);
|
||
console.log('headerRows 1', headerRows[1]);
|
||
console.log('headerRows 0', headerRows[0]);
|
||
console.log('headerRows 0', headerRows[1].length);
|
||
|
||
// Extract parent headers
|
||
// headerRows[0].querySelectorAll("th").forEach((th, index) => {
|
||
// if (index > 0) parentHeaders.push(th.textContent.trim());
|
||
// });
|
||
const headerThs = headerRows[0].querySelectorAll("th");
|
||
const last_index = headerThs.length - 1;
|
||
console.log("last_index", last_index);
|
||
|
||
headerThs.forEach((th, index) => {
|
||
let parentHeaderValue;
|
||
|
||
// Skip index 0 if not needed
|
||
if (index > 0) {
|
||
// For index 1 or last column, use full text
|
||
if (index < 2 || index === last_index) {
|
||
parentHeaderValue = th.textContent.trim();
|
||
} else {
|
||
parentHeaderValue = (th.querySelector('.key_name')?.innerText || '').trim();
|
||
}
|
||
|
||
console.log("parentHeaderValue", parentHeaderValue);
|
||
parentHeaders.push(parentHeaderValue);
|
||
}
|
||
});
|
||
|
||
// Calculate how many subheaders belong to each parent header using `colspan`
|
||
let currentParentIndex = 0;
|
||
let remainingColspan = 0;
|
||
let secondHeaderIndex = 0;
|
||
|
||
headerRows[1].querySelectorAll("th").forEach((th, index) => {
|
||
|
||
if (index > 0) { // Skip the first column if it's for row labels
|
||
const subHeaderText = th.querySelector('.key_name')?.innerText || th.textContent.trim();
|
||
|
||
// If no remainingColspan, move to the next parent header
|
||
if (remainingColspan === 0) {
|
||
remainingColspan = parseInt(headerRows[0].querySelectorAll("th")[currentParentIndex + 1]?.getAttribute("colspan") || "1", 10);
|
||
currentParentIndex++;
|
||
}
|
||
|
||
// Add subheader under the current parent header
|
||
subHeaders.push({
|
||
parent: parentHeaders[currentParentIndex - 1], // Adjust for 0-based index
|
||
subHeader: subHeaderText,
|
||
});
|
||
|
||
// Decrease remainingColspan as a subheader is assigned
|
||
remainingColspan--;
|
||
secondHeaderIndex++;
|
||
}
|
||
});
|
||
secondHeaderIndex = 0;
|
||
|
||
// Initialize the structure for all parent headers and subheaders
|
||
parentHeaders.forEach(parent => {
|
||
jsonData.data[parent] = {};
|
||
});
|
||
|
||
// console.log('jsonData', jsonData);
|
||
// console.log('parentHeaders', parentHeaders);
|
||
// console.log('subHeaders', subHeaders);
|
||
|
||
// Extract tbody data
|
||
const bodyRows = table.querySelectorAll("tbody tr");
|
||
// console.log('bodyRows', bodyRows);
|
||
|
||
bodyRows.forEach(row => {
|
||
const cells = row.querySelectorAll("td");
|
||
const rowLabel = cells[1]?.textContent.trim();
|
||
|
||
let cellIndex = 1; // Start after the first column (row labels)
|
||
subHeaders.forEach(({ parent, subHeader }) => {
|
||
|
||
// console.log('parent', parent)
|
||
// console.log('subHeader', subHeader)
|
||
// console.log('parent', jsonData.data[parent])
|
||
// console.log('subHeader', jsonData.data[parent][subHeader])
|
||
if (!jsonData.data[parent][subHeader]) {
|
||
jsonData.data[parent][subHeader] = {};
|
||
}
|
||
|
||
const cellValue = cells[cellIndex]?.textContent.trim() || "";
|
||
jsonData.data[parent][subHeader][rowLabel] = cellValue;
|
||
cellIndex++;
|
||
});
|
||
});
|
||
|
||
console.log(jsonData);
|
||
// console.log(JSON.stringify(jsonData, null, 2));
|
||
localStorage.setItem("premium_data", JSON.stringify(jsonData));
|
||
return jsonData;
|
||
}
|
||
|
||
function addInsurerDataForPremiumTable(event, insurerName, proposal_name) {
|
||
|
||
console.log('##################### ADD INSURER ###################################################')
|
||
|
||
const closestTh = event.target.closest('th');
|
||
let colIndex = closestTh.cellIndex;
|
||
console.log('column index of second table', colIndex);
|
||
colIndex = colIndex -1
|
||
console.log('column index of second table', colIndex);
|
||
|
||
let rfqTable = document.getElementById('rfqTable_for_calc');
|
||
const headerRow = rfqTable.rows[1];
|
||
|
||
const thElements = rfqTable.querySelectorAll('thead tr:first-child th');
|
||
let totalColspan = 0;
|
||
|
||
for (let i = 0; i <= colIndex; i++) {
|
||
const colspan = parseInt(thElements[i].getAttribute('colspan')) || 1;
|
||
totalColspan += colspan;
|
||
}
|
||
|
||
let parentTh = rfqTable.querySelector('thead tr th:nth-child(' + (colIndex + 1) + ')');
|
||
let columnIndextoCopyData = totalColspan - parentTh.colSpan;
|
||
parentTh.colSpan += 1;
|
||
console.log("columnIndextoCopyData", columnIndextoCopyData);
|
||
|
||
// Determine the position for inserting the column
|
||
let insertPosition = totalColspan; // Default to inserting at the end of the current insurer's columns
|
||
const rowLabels = ["Premium", "GST (%)", "GST Amount (₹)", "Total"];
|
||
|
||
// Add a new column to each row
|
||
let labelIncrement = 0
|
||
for (let i = 1; i < rfqTable.rows.length; i++) {
|
||
if (i === 1) {
|
||
const newHeaderCell = document.createElement('th');
|
||
newHeaderCell.innerHTML = insurerName;
|
||
newHeaderCell.style.backgroundColor = parentTh.style.backgroundColor;
|
||
rfqTable.rows[i].insertBefore(newHeaderCell, rfqTable.rows[i].cells[insertPosition]);
|
||
} else {
|
||
const newCell = rfqTable.rows[i].insertCell(insertPosition);
|
||
|
||
if(rowLabels[labelIncrement] == "Total") {
|
||
console.log();
|
||
newCell.setAttribute("contenteditable", false);
|
||
newCell.classList.add('readonly-select')
|
||
}else{
|
||
newCell.setAttribute("contenteditable", "true");
|
||
}
|
||
newCell.classList.add(
|
||
'editablecolumnsforcalc',
|
||
rowLabels[labelIncrement].toLowerCase().replace(/\s+/g, '').replace(/[%₹()]/g, '')
|
||
);
|
||
|
||
// newCell.classList.add('editablecolumns');
|
||
// newCell.innerHTML = rfqTable.rows[i].cells[columnIndextoCopyData].innerHTML; //do not remove this
|
||
// newCell.style.backgroundColor = parentTh.style.backgroundColor;
|
||
labelIncrement++
|
||
}
|
||
}
|
||
|
||
labelIncrement = 0
|
||
isFormDataModified = true; // if any value changeing in the table to set true
|
||
|
||
console.log('########################################################################')
|
||
|
||
}
|
||
|
||
function copyInsurerDataForPremiumTable(event, insurerName){
|
||
|
||
console.log('########## COPPY INSURER ##############')
|
||
|
||
const thPosition = getThPosition(event);
|
||
|
||
let parentThIndex = null;
|
||
const closestTh = event.target.closest('th');
|
||
let colIndex = closestTh.cellIndex;
|
||
console.log('colIndex', colIndex);
|
||
colIndex = colIndex - 1;
|
||
let columnText = closestTh.innerText;
|
||
let proposal_name = columnText.split('⋮')[0].trim();
|
||
let rfqTable = document.getElementById('rfqTable_for_calc');
|
||
const headerRows = rfqTable.querySelectorAll('thead tr');
|
||
|
||
if (thPosition.rowIndex == 1) //copy insurer
|
||
{
|
||
var copyType = event.target.className;
|
||
let accumulatedColspan = 0;
|
||
let parentTh = null;
|
||
|
||
let subThIndex = colIndex;
|
||
const firstHeaderRow = headerRows[0];
|
||
|
||
// Find the parent TH for the specified sub TH index
|
||
for (let i = 0; i < firstHeaderRow.children.length; i++) {
|
||
const currentParentTh = firstHeaderRow.children[i];
|
||
const currentColspan = parseInt(currentParentTh.getAttribute('colspan')) || 1;
|
||
|
||
accumulatedColspan += currentColspan;
|
||
|
||
if (subThIndex < accumulatedColspan) {
|
||
parentTh = currentParentTh;
|
||
break;
|
||
}
|
||
}
|
||
console.log(parentTh.cellIndex);
|
||
parentTh = headerRows[0].children[parentTh.cellIndex];
|
||
parentThIndex = parentTh.cellIndex;
|
||
console.log(accumulatedColspan + ' - ' + parentTh + ' - ' + subThIndex);
|
||
proposal_name = parentTh.innerText.split('⋮')[0].trim();
|
||
}
|
||
|
||
console.log(colIndex);
|
||
|
||
const headerRow = rfqTable.rows[1];
|
||
|
||
//find total no of columns (sub th) untill current parent th
|
||
const thElements = rfqTable.querySelectorAll('thead tr:first-child th');
|
||
let totalColspan = 0;
|
||
|
||
// Loop through the parent th elements within the specified index range
|
||
for (let i = 0; i <= parentThIndex; i++) {
|
||
const colspan = parseInt(thElements[i].getAttribute('colspan')) || 1;
|
||
totalColspan += colspan;
|
||
}
|
||
|
||
|
||
// add colspan of current th
|
||
let parentTh = rfqTable.querySelector('thead tr th:nth-child(' + (parentThIndex + 1) + ')');
|
||
parentTh.colSpan += 1;
|
||
|
||
let labelIncrement = 0;
|
||
// Add a new column to each row
|
||
for (let i = 1; i < rfqTable.rows.length; i++) {
|
||
|
||
if (i == 1) {
|
||
|
||
// Create a new <th> element
|
||
const newHeaderCell = document.createElement('th');
|
||
newHeaderCell.innerHTML = insurerName;
|
||
newHeaderCell.style.backgroundColor = parentTh.style.backgroundColor;
|
||
|
||
// Insert the <th> element at the desired position
|
||
rfqTable.rows[i].insertBefore(newHeaderCell, rfqTable.rows[i].cells[totalColspan]);
|
||
|
||
} else {
|
||
const newCell = rfqTable.rows[i].insertCell(totalColspan);
|
||
|
||
if(rowLabels[labelIncrement] == "Total") {
|
||
console.log();
|
||
newCell.setAttribute("contenteditable", false);
|
||
newCell.classList.add('readonly-select')
|
||
}else{
|
||
newCell.setAttribute("contenteditable", "true");
|
||
}
|
||
newCell.classList.add(
|
||
'editablecolumnsforcalc',
|
||
rowLabels[labelIncrement].toLowerCase().replace(/\s+/g, '').replace(/[%₹()]/g, '')
|
||
);
|
||
|
||
// newCell.setAttribute('contenteditable', 'true');
|
||
newCell.innerHTML = rfqTable.rows[i].cells[colIndex].innerHTML;
|
||
// newCell.style.backgroundColor = parentTh.style.backgroundColor;
|
||
labelIncrement++
|
||
}
|
||
|
||
}
|
||
labelIncrement = 0
|
||
}
|
||
|
||
function changeInsurerForPremiumTable(event, newInsurerName, secondRowIndex) {
|
||
|
||
const table = document.getElementById('rfqTable_for_calc');
|
||
const headerRows = table.querySelectorAll('thead tr');
|
||
secondRowIndex = secondRowIndex - 1
|
||
const secondRow = headerRows[1];
|
||
const thElements = secondRow.querySelectorAll('th');
|
||
const closestTh = thElements[secondRowIndex];
|
||
|
||
let oldInsurerName = closestTh.innerText.split('⋮')[0].trim();
|
||
|
||
let subThIndex = secondRowIndex - 2;
|
||
console.log(oldInsurerName + ' - ' + newInsurerName);
|
||
|
||
// Iterate over child nodes to find the text node containing "Myname"
|
||
closestTh.childNodes.forEach(node => {
|
||
if (node.nodeType === Node.TEXT_NODE && node.textContent.includes(oldInsurerName)) {
|
||
// Replace the old name with the new name
|
||
node.textContent = node.textContent.replace(oldInsurerName, newInsurerName);
|
||
}
|
||
});
|
||
}
|
||
|
||
function removeInsurerFromPremiumTable(event, secondRowIndex) {
|
||
|
||
console.log('########################################################################')
|
||
|
||
const table = document.getElementById('rfqTable_for_calc');
|
||
const headerRows = table.querySelectorAll('thead tr');
|
||
|
||
console.log('secondRowIndex', secondRowIndex)
|
||
const closestTh = event.target.closest('th');
|
||
let insurerName = closestTh.innerText.split('⋮')[0]
|
||
console.log('insurerName', insurerName);
|
||
// let subThIndex = closestTh.cellIndex;
|
||
// console.log('subThIndex', subThIndex);
|
||
subThIndex = secondRowIndex - 1
|
||
console.log('subThIndex', subThIndex);
|
||
|
||
// Get the sub TH from the second header row
|
||
const subTh = headerRows[1].children[subThIndex];
|
||
|
||
let accumulatedColspan = 0;
|
||
let parentTh = null;
|
||
|
||
const firstHeaderRow = headerRows[0];
|
||
|
||
// Find the parent TH for the specified sub TH index
|
||
for (let i = 0; i < firstHeaderRow.children.length; i++) {
|
||
|
||
const currentParentTh = firstHeaderRow.children[i];
|
||
const currentColspan = parseInt(currentParentTh.getAttribute('colspan')) || 1;
|
||
|
||
accumulatedColspan += currentColspan;
|
||
if (subThIndex < accumulatedColspan) {
|
||
parentTh = currentParentTh;
|
||
break;
|
||
}
|
||
}
|
||
|
||
console.log('parentth' + parentTh);
|
||
console.log('sub col indexOf' + subThIndex);
|
||
|
||
// Get the starting position of the sub TH
|
||
const startIndex = Array.from(headerRows[1].children).indexOf(subTh);
|
||
console.log('startIndex', startIndex);
|
||
|
||
// Remove the sub TH
|
||
headerRows[1].removeChild(subTh);
|
||
|
||
// Reduce colspan of parent TH
|
||
const parentColspan = parseInt(parentTh.getAttribute('colspan')) || 1;
|
||
console.log('existing colspan' + parentColspan);
|
||
parentTh.setAttribute('colspan', parentColspan - 1);
|
||
console.log('new colspan' + (parentColspan - 1));
|
||
|
||
// Remove the corresponding TDs from each row
|
||
table.querySelectorAll('tbody tr').forEach(row => {
|
||
row.removeChild(row.children[startIndex]);
|
||
});
|
||
|
||
console.log('########################################################################')
|
||
|
||
}
|
||
|
||
function removeProposalForPremiumTable(secondRowIndex) {
|
||
|
||
let colIndex = secondRowIndex - 1;
|
||
console.log('colIndex', colIndex);
|
||
|
||
const rfqPremiumTable = document.getElementById('rfqTable_for_calc');
|
||
console.log(rfqPremiumTable)
|
||
const headerRows = rfqPremiumTable.querySelectorAll('thead tr');
|
||
|
||
const parentTh = headerRows[0].children[colIndex];
|
||
console.log('parentTh', parentTh);
|
||
const parentColspan = parseInt(parentTh.getAttribute('colspan')) || 1;
|
||
const startIndex = Array.from(headerRows[1].children).findIndex(
|
||
th => th.offsetLeft >= parentTh.offsetLeft
|
||
);
|
||
console.log('startIndex', startIndex);
|
||
console.log('parentColspan', parentColspan);
|
||
|
||
// Remove the parent TH
|
||
headerRows[0].removeChild(parentTh);
|
||
|
||
// Remove the relevant sub THs and corresponding TDs
|
||
for (let i = 0; i < parentColspan; i++) {
|
||
const subThIndex = startIndex; // The index doesn't shift since we're always removing the same `startIndex`
|
||
|
||
// Remove the sub THs
|
||
const subTh = headerRows[1].children[subThIndex];
|
||
console.log('Removing subTh', subTh);
|
||
headerRows[1].removeChild(subTh);
|
||
|
||
// Remove the corresponding TDs from each row
|
||
rfqPremiumTable.querySelectorAll('tbody tr').forEach(row => {
|
||
const tdToRemove = row.children[subThIndex];
|
||
console.log('Removing td', tdToRemove);
|
||
row.removeChild(tdToRemove);
|
||
});
|
||
}
|
||
}
|
||
|
||
document.getElementById('rfqTable_for_calc').addEventListener('focusout', function(e) {
|
||
console.log('callsed', e);
|
||
console.log('callsed', e.target);
|
||
console.log('callsed', e.target.tagName);
|
||
console.log('callsed', e.target.classList);
|
||
|
||
// Ensure the event target is a td element
|
||
if (e.target && e.target.tagName === 'TD' && e.target.classList.contains('editablecolumnsforcalc')) {
|
||
autoCaluculationForPremiumChildTable(e.target);
|
||
}
|
||
});
|
||
|
||
// function autoCaluculationForPremiumChildTable(input) {
|
||
|
||
// console.log('autoCaluculationForPremiumChildTable input', input);
|
||
// console.log('autoCalucationForPremiumChildTable textContent', input.textContent);
|
||
|
||
// // Get the row where the input was made
|
||
// const row = input.closest('tr');
|
||
// console.log('row', row);
|
||
|
||
// // Find the index of the input td
|
||
// const tdIndex = Array.from(row.children).indexOf(input);
|
||
// console.log('tdIndex', tdIndex);
|
||
|
||
// // Get all rows (assuming there are exactly 3 rows)
|
||
// const rows = Array.from(row.parentNode.children);
|
||
// console.log('rows', rows);
|
||
|
||
// // Now we need to get the relevant td values from all rows based on the tdIndex
|
||
// let premium = 0, gst = 0, total = 0, gst_amt = 0;
|
||
|
||
// rows.forEach((r, index) => {
|
||
// const tds = r.querySelectorAll('td');
|
||
|
||
// // Check if the row contains premium, gst, or total based on tdIndex
|
||
// if (index === 0) { // First row
|
||
// premium = Number(tds[tdIndex]?.textContent) || 0;
|
||
// } else if (index === 1) { // Second row
|
||
// gst = Number(tds[tdIndex]?.textContent) || 0;
|
||
// } else if (index === 2) { // Third row
|
||
// gst_amt = Number(tds[tdIndex]?.textContent) || 0;
|
||
// }else if (index === 3) { // Fouth row
|
||
// total = Number(tds[tdIndex]?.textContent) || 0;
|
||
// }
|
||
// });
|
||
|
||
// console.log('premium', premium);
|
||
// console.log('gst', gst);
|
||
// console.log('gst_amt', gst_amt);
|
||
// console.log('total', total);
|
||
|
||
// // Perform calculation for GST (for example, premium * gst / 100)
|
||
// const calculatedGSTAmount = (premium * gst) / 100 || 0;
|
||
// console.log('Calculated GST Amount:', calculatedGSTAmount);
|
||
|
||
// const calculatedTotal = premium + calculatedGSTAmount;
|
||
// console.log('Calculated Total Amount:', calculatedTotal);
|
||
|
||
// const beforeLastRow = rows[1]; // Assuming the last row is the total row
|
||
// const gstAmtCell = beforeLastRow.children[tdIndex];
|
||
// gstAmtCell.textContent = calculatedTotal.toFixed(2); // Set the calculated total to two decimal places
|
||
|
||
// // Update the total field in the last row
|
||
// const lastRow = rows[2]; // Assuming the last row is the total row
|
||
// const totalCell = lastRow.children[tdIndex];
|
||
// totalCell.textContent = calculatedTotal.toFixed(2); // Set the calculated total to two decimal places
|
||
// }
|
||
|
||
function autoCaluculationForPremiumChildTable(input) {
|
||
console.log('autoCaluculationForPremiumChildTable input', input);
|
||
|
||
// Get the row where the input was made
|
||
const row = input.closest('tr');
|
||
console.log('row', row);
|
||
|
||
const hasPremiumClass = input.classList.contains('premium');
|
||
const hasGstClass = input.classList.contains('gst');
|
||
const hasGstAmtClass = input.classList.contains('gstamount');
|
||
|
||
console.log('hasPremiumClass', hasPremiumClass);
|
||
console.log('hasGstClass', hasGstClass);
|
||
|
||
|
||
// Find the index of the input td
|
||
const tdIndex = Array.from(row.children).indexOf(input);
|
||
console.log('tdIndex', tdIndex);
|
||
|
||
// Get all rows (assuming there are exactly 4 rows: Premium, GST, GST Amount, Total)
|
||
const rows = Array.from(row.parentNode.children);
|
||
console.log('rows', rows);
|
||
|
||
// Extract values from the corresponding cells in each row
|
||
const premium = Number(rows[0].children[tdIndex]?.textContent.trim()) || 0;
|
||
const gst = Number(rows[1].children[tdIndex]?.textContent.trim()) || 0;
|
||
const gstAmt = Number(rows[2].children[tdIndex]?.textContent.trim()) || 0;
|
||
|
||
console.log('premium', premium);
|
||
console.log('gst', gst);
|
||
|
||
|
||
// Calculate GST Amount and Total
|
||
if(hasPremiumClass || hasGstClass){
|
||
|
||
const gstAmount = (premium * gst) / 100;
|
||
const total = premium + gstAmount;
|
||
|
||
console.log('Calculated GST Amount:', gstAmount.toFixed(2));
|
||
console.log('Calculated Total Amount:', total.toFixed(2));
|
||
|
||
// Update GST Amount row
|
||
rows[2].children[tdIndex].textContent = gstAmount.toFixed(2);
|
||
|
||
// Update Total row
|
||
rows[3].children[tdIndex].textContent = total.toFixed(2);
|
||
|
||
}else if (hasGstAmtClass){
|
||
|
||
// Calculate GST percentage based on GST amount and premium
|
||
const gstPercent = premium > 0 ? (gstAmt / premium) * 100 : 0;
|
||
const total = premium + gstAmt;
|
||
|
||
console.log('Calculated GST Percentage:', gstPercent.toFixed(2));
|
||
console.log('Calculated Total Amount:', total.toFixed(2));
|
||
|
||
// Update GST row with calculated GST percentage
|
||
rows[1].children[tdIndex].textContent = gstPercent.toFixed(2);
|
||
|
||
// Update Total row
|
||
rows[3].children[tdIndex].textContent = total.toFixed(2);
|
||
|
||
}
|
||
}
|
||
|
||
|
||
function appendMultiFileData(data) {
|
||
|
||
console.log('appendMultiFileData function called');
|
||
console.log(data)
|
||
}
|
||
</script>
|
||
|
||
|
||
<script>
|
||
|
||
async function submitData(input) {
|
||
|
||
console.log("The submit function called RFQ and QCR");
|
||
console.log("over_all_column_data", over_all_column_data);
|
||
|
||
try {
|
||
// Show loader if necessary
|
||
// $('.loader').fadeIn();
|
||
// $('.loader-mask').fadeIn();
|
||
|
||
// Construct the JSON data
|
||
const jsonData = await tableToJsonForFormSubmit();
|
||
console.log(jsonData);
|
||
|
||
// return;
|
||
|
||
// Create a FormData object
|
||
const formData = new FormData();
|
||
let lead_id = $('#lead_id').val();
|
||
let rfq_primaryKey = $('#rfq_primaryKey').val();
|
||
|
||
let submit_type = "RFQ"
|
||
if(RFQ_or_QCR == 2){submit_type = 'QCR'}
|
||
|
||
formData.append('json', JSON.stringify(jsonData));
|
||
formData.append('lead_id', lead_id);
|
||
formData.append('submit_type', submit_type);
|
||
|
||
if(input == 1){
|
||
formData.append('rfq_primaryKey', rfq_primaryKey);
|
||
}
|
||
|
||
const postUrl = '<?= base_url('rfq/create')?>';
|
||
console.log(postUrl);
|
||
|
||
const response = await $.ajax({
|
||
url: postUrl,
|
||
type: 'POST',
|
||
data: formData,
|
||
processData: false, // Prevent jQuery from processing the data
|
||
contentType: false, // Let jQuery set the content type correctly
|
||
});
|
||
|
||
console.log('Data sent successfully:', response);
|
||
|
||
if (response.status == true) {
|
||
if(input == 1){
|
||
console.log(response.message, 'SUCCESS');
|
||
showTinyToast();
|
||
}else{
|
||
toastr.success(response.message, 'SUCCESS');
|
||
}
|
||
$('#rfq_primaryKey').val(response.id);
|
||
} else {
|
||
toastr.warning(response.message, 'WARNING');
|
||
}
|
||
|
||
if(input != 1){
|
||
window.location.reload();
|
||
}
|
||
|
||
} catch (error) {
|
||
console.error('An error occurred during the AJAX request:');
|
||
|
||
if (error.responseText) {
|
||
try {
|
||
const errorResponse = JSON.parse(error.responseText);
|
||
console.error('Server Response:', errorResponse);
|
||
} catch (parseError) {
|
||
console.error('Error Message:', error.message);
|
||
console.error('Could not parse error response:', error.responseText);
|
||
}
|
||
} else {
|
||
console.error('Error Message:', error.message);
|
||
}
|
||
|
||
console.error('Full Error Object:', error);
|
||
}
|
||
}
|
||
|
||
// Attach the function to the button click event
|
||
$('#submitData').on('click', submitData);
|
||
|
||
|
||
async function submitQCRData() {
|
||
|
||
console.log(over_all_column_data);
|
||
|
||
let qcr_count = $('#qcr_count').val();
|
||
let lead_id = $('#lead_id').val();
|
||
|
||
if (qcr_count != 0 && RFQ_or_QCR == 1) {
|
||
console.log('QCR found');
|
||
const url = '<?= base_url('rfq/list/') ?>' + lead_id + '/' + 2;
|
||
window.location.href = url;
|
||
} else {
|
||
console.log('QCR not found');
|
||
|
||
try {
|
||
|
||
$('.loader').fadeIn();
|
||
$('.loader-mask').fadeIn();
|
||
|
||
// Construct the JSON data
|
||
const jsonData = await convertJsonForQCR();
|
||
|
||
// Create a FormData object
|
||
const formData = new FormData();
|
||
formData.append('json', JSON.stringify(jsonData));
|
||
formData.append('lead_id', lead_id);
|
||
|
||
const postUrl = '<?= base_url('rfq/createQCR')?>';
|
||
console.log(postUrl);
|
||
|
||
const response = await $.ajax({
|
||
url: postUrl,
|
||
type: 'POST',
|
||
data: formData,
|
||
processData: false, // Prevent jQuery from processing the data
|
||
contentType: false, // Let jQuery set the content type correctly
|
||
});
|
||
|
||
console.log('Data sent successfully:', response);
|
||
|
||
if (response.status == true) {
|
||
toastr.success(response.message, 'SUCCESS');
|
||
} else {
|
||
toastr.warning(response.message, 'WARNING');
|
||
}
|
||
|
||
window.location.href = '<?= base_url('rfq/list/') ?>' + lead_id + '/' + 2;
|
||
|
||
} catch (error) {
|
||
console.error('An error occurred during the AJAX request:');
|
||
|
||
if (error.responseText) {
|
||
try {
|
||
const errorResponse = JSON.parse(error.responseText);
|
||
console.error('Server Response:', errorResponse);
|
||
} catch (parseError) {
|
||
console.error('Error Message:', error.message);
|
||
console.error('Could not parse error response:', error.responseText);
|
||
}
|
||
} else {
|
||
console.error('Error Message:', error.message);
|
||
}
|
||
|
||
console.error('Full Error Object:', error);
|
||
}
|
||
}
|
||
}
|
||
// $('#submitQCRData').on('click', submitQCRData);
|
||
|
||
async function tableToJsonForFormSubmit() {
|
||
|
||
console.log('tableToJsonForFormSubmit function clled');
|
||
|
||
return new Promise((resolve) => {
|
||
|
||
const headers = [];
|
||
const data = [];
|
||
const table = document.getElementById('rfqTable');
|
||
|
||
let premium_data = '';
|
||
if(RFQ_or_QCR == 2){
|
||
premium_data = generateJSONFromTable();
|
||
console.log('save premium data', premium_data);
|
||
}
|
||
|
||
// Collect parent and subheaders
|
||
const parentHeaders = table.querySelectorAll('thead tr:nth-child(1) th');
|
||
const subHeaders = table.querySelectorAll('thead tr:nth-child(2) th');
|
||
|
||
// console.log('parentHeaders length', parentHeaders.length);
|
||
// console.log('subHeaders length', subHeaders.length);
|
||
|
||
const last_index = parentHeaders.length - 1;
|
||
console.log("last_index", last_index)
|
||
let headerIndex = 0;
|
||
let headerIndex1 = 0;
|
||
let secondHeaderIndex = 0;
|
||
parentHeaders.forEach((header, FirstHeaderRowIndex) => {
|
||
|
||
// console.log('header names', header);
|
||
// console.log('header header.innerText', header.innerText);
|
||
// const colspan = header.getAttribute('colspan') || 4;
|
||
|
||
let colspan = 1;
|
||
|
||
if (RFQ_or_QCR == 1) {
|
||
colspan = header.getAttribute('data-colspan') || 1;
|
||
} else {
|
||
colspan = header.getAttribute('colspan') || 1;
|
||
}
|
||
|
||
// console.log('colspan', colspan);
|
||
const subHeaderArray = [];
|
||
|
||
// console.log('headerIndex', headerIndex);
|
||
for (let i = 0; i < colspan; i++) {
|
||
console.log('headerIndex', headerIndex);
|
||
// console.log('subHeaders[headerIndex]', subHeaders[headerIndex]);
|
||
let cleanedText = subHeaders[headerIndex].textContent.trim().split('⋮')[0].trim();
|
||
if(FirstHeaderRowIndex > 2 && secondHeaderIndex == 0){
|
||
cleanedText = (subHeaders[headerIndex].querySelector('.key_name')?.innerText || '').trim();
|
||
}
|
||
if(headerIndex1 === last_index){
|
||
cleanedText = "-";
|
||
}
|
||
console.log('cleanedText', cleanedText);
|
||
subHeaderArray.push(cleanedText);
|
||
headerIndex++;
|
||
secondHeaderIndex ++;
|
||
}
|
||
secondHeaderIndex = 0;
|
||
|
||
// let parentHeaderValue;
|
||
// if (headerIndex1 < 3 || headerIndex1 == last_index) {
|
||
// if(FirstHeaderRowIndex == 0){
|
||
// parentHeaderValue = (header.querySelector('.key_name')?.innerText || '').trim();
|
||
// }else{
|
||
// parentHeaderValue = header.innerText.trim().split('⋮')[0].trim();
|
||
// }
|
||
// } else {
|
||
// parentHeaderValue = (header.querySelector('.key_name')?.innerText || '').trim();
|
||
// }
|
||
|
||
let parentHeaderValue;
|
||
|
||
if (headerIndex1 < 3 || headerIndex1 === last_index) {
|
||
if (FirstHeaderRowIndex === 0) {
|
||
parentHeaderValue = (header.querySelector('.key_name')?.innerText || (header.innerText.split('⋮')[0] || '-')).trim() ?? "-";
|
||
} else {
|
||
parentHeaderValue = (header.innerText.split('⋮')[0] || '-').trim() ?? "-";
|
||
}
|
||
} else {
|
||
parentHeaderValue = (header.querySelector('.key_name')?.innerText || (header.innerText.split('⋮')[0] || '')).trim() ?? "-";
|
||
}
|
||
|
||
|
||
headers.push({
|
||
parentHeader: parentHeaderValue,
|
||
subHeaders: subHeaderArray
|
||
});
|
||
|
||
headerIndex1++;
|
||
});
|
||
|
||
// Get the data from table rows
|
||
const rows = table.querySelectorAll('tbody tr');
|
||
|
||
rows.forEach(row => {
|
||
|
||
const rowId = row.id;
|
||
const cells = row.querySelectorAll('td');
|
||
const rowData = {
|
||
SNO: cells[0].textContent.trim(),
|
||
items: cells[1].textContent.trim(),
|
||
data: []
|
||
};
|
||
|
||
let dataIndex = 0;
|
||
headers.forEach(header => {
|
||
header.subHeaders.forEach(subHeader => {
|
||
const cell = cells[dataIndex];
|
||
// console.log('cells', cell);
|
||
let content = cells[dataIndex]?.textContent.trim() || '';
|
||
|
||
// Ensure suggestions[rowId] exists
|
||
const inputType = suggestions[rowId]?.type;
|
||
|
||
// console.log('inputType', inputType);
|
||
|
||
// Handle 'text' input types
|
||
if (inputType === "text") {
|
||
|
||
if (header.parentHeader === 'Action' && cell) {
|
||
const qcrInput = cell.querySelector(
|
||
'input[name="qcr"]');
|
||
const clientInput = cell.querySelector(
|
||
'input[name="client"]');
|
||
content = {
|
||
qcr: qcrInput?.checked ? 1 : 0,
|
||
stc: clientInput?.checked ? 1 : 0
|
||
};
|
||
} else {
|
||
const input = cell.querySelector('input');
|
||
if (input) {
|
||
content = input.value;
|
||
// console.log('hidden input value', content);
|
||
} else {
|
||
content = cells[dataIndex].textContent.trim();
|
||
}
|
||
}
|
||
} else {
|
||
// if (cell) {
|
||
const input = cell.querySelector('input');
|
||
if (input && header.parentHeader === 'Action') {
|
||
const qcrInput = cell.querySelector(
|
||
'input[name="qcr"]');
|
||
const clientInput = cell.querySelector(
|
||
'input[name="client"]');
|
||
content = {
|
||
qcr: qcrInput?.checked ? 1 : 0,
|
||
stc: clientInput?.checked ? 1 : 0
|
||
};
|
||
} else {
|
||
content = input ? input.value : cell.textContent.trim();
|
||
}
|
||
// }
|
||
}
|
||
|
||
|
||
|
||
rowData.data.push({
|
||
parentth: header.parentHeader,
|
||
subth: subHeader,
|
||
value: cells[dataIndex]?.textContent.trim() || '',
|
||
input_value: content
|
||
});
|
||
dataIndex++;
|
||
});
|
||
});
|
||
|
||
data.push(rowData);
|
||
});
|
||
|
||
const jsonData = {
|
||
table_data: {
|
||
headers: headers,
|
||
data: data
|
||
},
|
||
proposal_data: {
|
||
over_all_column_data: over_all_column_data
|
||
}
|
||
};
|
||
|
||
// Add `premium_data` only if `QCR` equals 2
|
||
// if (RFQ_or_QCR == 2) {
|
||
jsonData.premium_data = premium_data;
|
||
// }
|
||
|
||
console.log('JSON.stringify(jsonData)', JSON.stringify(jsonData))
|
||
localStorage.setItem('data', JSON.stringify(jsonData));
|
||
resolve(jsonData);
|
||
});
|
||
}
|
||
|
||
async function convertJsonForQCR() {
|
||
|
||
var json = await tableToJsonForFormSubmit()
|
||
console.log("convertJsonForQCR json", json);
|
||
|
||
if (json) {
|
||
|
||
const first_json = JSON.parse(JSON.stringify(json)); // Deep copy
|
||
// console.log("Original JSON:", json);
|
||
|
||
let rowIndexArray = [];
|
||
let rowIndexArray2 = [];
|
||
|
||
// Column-wise Check: Remove headers and relevant data if qcr == 0
|
||
Object.entries(json.proposal_data.over_all_column_data).forEach(([proposalKey, proposalData], index) => {
|
||
|
||
// console.log('over_all_column_data index', index);
|
||
|
||
if (proposalData.qcr == 0 || proposalData.qcr == false) {
|
||
|
||
// Remove matching parentHeader in headers
|
||
const headerIndex = first_json.table_data.headers.findIndex(header => header
|
||
.parentHeader === proposalKey);
|
||
if (headerIndex !== -1) first_json.table_data.headers.splice(headerIndex, 1);
|
||
|
||
first_json.table_data.data.forEach(item => {
|
||
item.data = item.data.filter(entry => entry.parentth !== proposalKey);
|
||
});
|
||
|
||
// Remove data entries with matching parentth
|
||
// Object.values(first_json.table_data.data).forEach(dataEntry => {
|
||
// const dataArray = dataEntry.data;
|
||
// if (dataArray) {
|
||
// const dataIndex = dataArray.findIndex(dataItem => dataItem.parentth === proposalKey);
|
||
// if (dataIndex !== -1) dataArray.splice(dataIndex, 1);
|
||
// }
|
||
// });
|
||
|
||
// Remove proposalKey from over_all_column_data
|
||
// Object.entries(first_json.proposal_data.over_all_column_data).splice(index, 1);
|
||
|
||
|
||
const updatedData = Object.keys(first_json.proposal_data.over_all_column_data)
|
||
.filter(key => key !== proposalKey)
|
||
.reduce((acc, key) => {
|
||
acc[key] = first_json.proposal_data.over_all_column_data[key];
|
||
return acc;
|
||
}, {});
|
||
|
||
// Assign the updated data back if needed
|
||
first_json.proposal_data.over_all_column_data = updatedData;
|
||
}
|
||
|
||
// Insurer Check: Remove subHeaders and relevant data for insurers with qcr == 0
|
||
proposalData.insurers.forEach((insurer, insurerIndex) => {
|
||
// console.log('insurer', insurer)
|
||
if (insurer.qcr === 0 || insurer.qcr == false) {
|
||
|
||
// console.log(insurer.qcr)
|
||
|
||
first_json.table_data.headers.forEach(header => {
|
||
const subHeaderIndex = header.subHeaders.findIndex(sub => sub ===
|
||
insurer.display_name);
|
||
if (subHeaderIndex !== -1) header.subHeaders.splice(subHeaderIndex,
|
||
1);
|
||
});
|
||
|
||
first_json.table_data.data.forEach(item => {
|
||
item.data = item.data.filter(entry => entry.subth !== insurer
|
||
.display_name);
|
||
});
|
||
|
||
// Object.values(first_json.table_data.data).forEach(dataEntry => {
|
||
// const dataArray = dataEntry.data;
|
||
// if (dataArray) {
|
||
// const dataIndex = dataArray.findIndex(dataItem => dataItem.subth === insurer.display_name);
|
||
// if (dataIndex !== -1) dataArray.splice(dataIndex, 1);
|
||
// }
|
||
// });
|
||
|
||
// Remove insurer from proposal's insurers array
|
||
// console.log('insurerIndex', insurerIndex)
|
||
first_json.proposal_data.over_all_column_data[proposalKey].insurers.splice(
|
||
insurerIndex, 1);
|
||
}
|
||
|
||
});
|
||
});
|
||
|
||
// rowIndexArray.sort((a, b) => b - a);
|
||
|
||
// rowIndexArray2.forEach((index) => {
|
||
// rowIndexArray.forEach((index2) => {
|
||
// first_json.table_data.data[index].data.splice(index2, 1);
|
||
// })
|
||
// });
|
||
|
||
|
||
// Row-wise Check: Remove rows if qcr == 0 for actions
|
||
Object.entries(first_json.table_data.data).forEach(([rowKey, rowData]) => {
|
||
const actionData = rowData.data.find(data => data.parentth === "Action" && data.input_value
|
||
.qcr === 0);
|
||
if (actionData) first_json.table_data.data.splice(rowKey, 1);
|
||
});
|
||
|
||
console.log("Modified JSON:", first_json);
|
||
return first_json;
|
||
}
|
||
|
||
}
|
||
|
||
function convertRFQJsonToQCRJson(json) {
|
||
|
||
if (json) {
|
||
|
||
const first_json = JSON.parse(JSON.stringify(json)); // Deep copy
|
||
// console.log("Original JSON:", json);
|
||
|
||
let rowIndexArray = [];
|
||
let rowIndexArray2 = [];
|
||
|
||
// Column-wise Check: Remove headers and relevant data if qcr == 0
|
||
Object.entries(json.proposal_data.over_all_column_data).forEach(([proposalKey, proposalData], index) => {
|
||
|
||
// console.log('over_all_column_data index', index);
|
||
|
||
if (proposalData.qcr == 0 || proposalData.qcr == false) {
|
||
|
||
// Remove matching parentHeader in headers
|
||
const headerIndex = first_json.table_data.headers.findIndex(header => header
|
||
.parentHeader === proposalKey);
|
||
if (headerIndex !== -1) first_json.table_data.headers.splice(headerIndex, 1);
|
||
|
||
first_json.table_data.data.forEach(item => {
|
||
item.data = item.data.filter(entry => entry.parentth !== proposalKey);
|
||
});
|
||
|
||
// Remove data entries with matching parentth
|
||
// Object.values(first_json.table_data.data).forEach(dataEntry => {
|
||
// const dataArray = dataEntry.data;
|
||
// if (dataArray) {
|
||
// const dataIndex = dataArray.findIndex(dataItem => dataItem.parentth === proposalKey);
|
||
// if (dataIndex !== -1) dataArray.splice(dataIndex, 1);
|
||
// }
|
||
// });
|
||
|
||
// Remove proposalKey from over_all_column_data
|
||
// Object.entries(first_json.proposal_data.over_all_column_data).splice(index, 1);
|
||
|
||
|
||
const updatedData = Object.keys(first_json.proposal_data.over_all_column_data)
|
||
.filter(key => key !== proposalKey)
|
||
.reduce((acc, key) => {
|
||
acc[key] = first_json.proposal_data.over_all_column_data[key];
|
||
return acc;
|
||
}, {});
|
||
|
||
// Assign the updated data back if needed
|
||
first_json.proposal_data.over_all_column_data = updatedData;
|
||
}
|
||
|
||
// Insurer Check: Remove subHeaders and relevant data for insurers with qcr == 0
|
||
proposalData.insurers.forEach((insurer, insurerIndex) => {
|
||
// console.log('insurer', insurer)
|
||
if (insurer.qcr === 0 || insurer.qcr == false) {
|
||
|
||
// console.log(insurer.qcr)
|
||
|
||
first_json.table_data.headers.forEach(header => {
|
||
const subHeaderIndex = header.subHeaders.findIndex(sub => sub ===
|
||
insurer.display_name);
|
||
if (subHeaderIndex !== -1) header.subHeaders.splice(subHeaderIndex,
|
||
1);
|
||
});
|
||
|
||
first_json.table_data.data.forEach(item => {
|
||
item.data = item.data.filter(entry => entry.subth !== insurer
|
||
.display_name);
|
||
});
|
||
|
||
// Object.values(first_json.table_data.data).forEach(dataEntry => {
|
||
// const dataArray = dataEntry.data;
|
||
// if (dataArray) {
|
||
// const dataIndex = dataArray.findIndex(dataItem => dataItem.subth === insurer.display_name);
|
||
// if (dataIndex !== -1) dataArray.splice(dataIndex, 1);
|
||
// }
|
||
// });
|
||
|
||
// Remove insurer from proposal's insurers array
|
||
// console.log('insurerIndex', insurerIndex)
|
||
first_json.proposal_data.over_all_column_data[proposalKey].insurers.splice(
|
||
insurerIndex, 1);
|
||
}
|
||
|
||
});
|
||
});
|
||
|
||
// rowIndexArray.sort((a, b) => b - a);
|
||
|
||
// rowIndexArray2.forEach((index) => {
|
||
// rowIndexArray.forEach((index2) => {
|
||
// first_json.table_data.data[index].data.splice(index2, 1);
|
||
// })
|
||
// });
|
||
|
||
|
||
// Row-wise Check: Remove rows if qcr == 0 for actions
|
||
Object.entries(first_json.table_data.data).forEach(([rowKey, rowData]) => {
|
||
const actionData = rowData.data.find(data => data.parentth === "Action" && data.input_value
|
||
.qcr === 0);
|
||
if (actionData) first_json.table_data.data.splice(rowKey, 1);
|
||
});
|
||
|
||
console.log("Modified JSON:", first_json);
|
||
return first_json;
|
||
}
|
||
|
||
}
|
||
|
||
$("#is_cd_switch").change(function (){
|
||
var switch_status = ($("#is_cd_switch").is(":checked")? "on" : "off");
|
||
console.log("Switch status",switch_status);
|
||
if (switch_status == "on"){
|
||
|
||
$("#cd_amount").show();
|
||
$("#total_amount").show();
|
||
$("#cd_amount").closest('.form-group').show();
|
||
$("#total_amount").closest('.form-group').show();
|
||
|
||
}else{
|
||
|
||
$("#cd_amount").hide();
|
||
$("#total_amount").hide();
|
||
$("#cd_amount").closest('.form-group').hide();
|
||
$("#total_amount").closest('.form-group').hide();
|
||
|
||
}
|
||
})
|
||
|
||
$("#is_installment_switch").change(function (){
|
||
|
||
var switch_status = ($(this).is(":checked")? "on" : "off");
|
||
console.log("Switch status",switch_status);
|
||
if (switch_status == "on"){
|
||
$("#no_of_installment").show();
|
||
$("#payment_date").hide();
|
||
$("#utr_no").hide();
|
||
$("#no_of_installment").closest('.form-group').show();
|
||
$("#payment_date").closest('.form-group').hide();
|
||
$("#utr_no").closest('.form-group').hide();
|
||
let $installmentContainer = $('#installment_form_row');
|
||
let row_count = $installmentContainer.find('.form-row').length;
|
||
|
||
if (row_count == 0 ) { addInstallmentHTML()}
|
||
// addInstallmentHTML()
|
||
}else{
|
||
console.log("inside else")
|
||
|
||
let $installmentContainer = $('#installment_form_row');
|
||
let row_count = $installmentContainer.find('.form-row').length;
|
||
let remove_count = $("#no_of_installment").val();
|
||
let lead_id = $('#lead_id').val();
|
||
console.log("row count",row_count);
|
||
if (row_count > 0 ) {
|
||
let ids = $installmentContainer.find('.form-row').slice(-remove_count).find('input[name="installment_primary_key[]"]').map(function() {
|
||
return $(this).val();
|
||
}).get();
|
||
Swal.fire({
|
||
title: "Do you want to remove all the entries?",
|
||
icon: "warning",
|
||
showCancelButton: true,
|
||
confirmButtonColor: "#3085d6",
|
||
cancelButtonColor: "#d33",
|
||
confirmButtonText: "Yes, Proceed!"
|
||
}).then((result) => {
|
||
if (result.isConfirmed) {
|
||
let url = '<?= base_url('util/removeInstallments') ?>';
|
||
let requestData = { id: ids,'lead_id': lead_id};
|
||
|
||
if (requestData.id.length == 0) {
|
||
|
||
$("#no_of_installment").hide();
|
||
$("#payment_date").show();
|
||
$("#utr_no").show();
|
||
$("#no_of_installment").closest('.form-group').hide();
|
||
$("#payment_date").closest('.form-group').show();
|
||
$("#utr_no").closest('.form-group').show();
|
||
$('#installment_form_row').empty();
|
||
$('#no_of_installment').val("");
|
||
|
||
return;
|
||
}
|
||
|
||
$('.loader').fadeIn();
|
||
$('.loader-mask').fadeIn();
|
||
|
||
sendAjaxRequestForGlobal(url, 'GET', requestData, function(response) {
|
||
console.log('Data fetched successfully:', response);
|
||
|
||
if (response.status === true) {
|
||
toastr.success(response.message, 'SUCCESS');
|
||
$("#no_of_installment").closest('.form-group').hide();
|
||
$('#no_of_installment').val("");
|
||
$('#installment_form_row').empty();
|
||
// $("#no_of_installment").hide();
|
||
$("#payment_date").show();
|
||
$("#utr_no").show();
|
||
$("#payment_date").closest('.form-group').show();
|
||
$("#utr_no").closest('.form-group').show();
|
||
$('#not_installment').empty();
|
||
|
||
newhtml = `
|
||
<div class="form-group col-md-3">
|
||
<label for="payment_date">Payment Date</label>
|
||
<input type="text" class="form-control payment_date" id="payment_date" name="payment_date" placeholder="DD/MM/YYY">
|
||
</div>
|
||
|
||
<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>
|
||
`;
|
||
$('#not_installment').append(newhtml);
|
||
$('.payment_date').flatpickr({
|
||
dateFormat: 'd-m-Y',
|
||
});
|
||
} else {
|
||
toastr.error(response.message, 'WARNING');
|
||
}
|
||
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
|
||
}, function(xhr, status, error) {
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
console.error('Error fetching data:', error);
|
||
console.error(xhr.responseText);
|
||
toastr.error('An error occurred while removing the installment.', 'ERROR');
|
||
});
|
||
}else{
|
||
// alert("Inside else");
|
||
$('#no_of_installment').val(row_count);
|
||
// $("#is_installment_switch").bootstrapToggle('on');
|
||
// $('#is_installment_switch').val('1').change();
|
||
// $('#is_installment_switch').bootstrapToggle('on');
|
||
// $('#is_installment_switch').prop('checked', true).trigger('change');
|
||
$('#is_installment_switch').trigger('click'); // in some cases, this forces the CSS to update
|
||
|
||
}
|
||
});
|
||
}
|
||
|
||
}
|
||
})
|
||
|
||
|
||
$(document).on("input", "#cd_amount, #premium_amount", function() {
|
||
|
||
// alert("Function called");
|
||
|
||
var cd_amount = parseInt($("#cd_amount").val()) || 0;
|
||
var premium_amount = parseInt($("#premium_amount").val()) || 0;
|
||
|
||
var total_amount = (cd_amount + premium_amount);
|
||
$("#total_amount").val(total_amount);
|
||
|
||
|
||
});
|
||
|
||
function checkMailValidation(){
|
||
|
||
emailString = $("#contact_mail").val();
|
||
|
||
if (RFQ_or_QCR == 1){
|
||
if (typeof emailString !== 'string' || !emailString.includes(',')) return true;
|
||
}else{
|
||
if (typeof emailString !== 'string') return false;
|
||
}
|
||
|
||
const invalidChars = /[;|]/;
|
||
if (invalidChars.test(emailString)) return false;
|
||
|
||
|
||
const emails = emailString.split(',').map(email => email.trim());
|
||
|
||
if (emails.length === 0) return false;
|
||
|
||
const getDomain = email => email.split('@')[1]?.toLowerCase();
|
||
const firstDomain = getDomain(emails[0]);
|
||
|
||
if (!firstDomain) return false;
|
||
|
||
return emails.every(email => getDomain(email) === firstDomain);
|
||
}
|
||
|
||
function addInstallmentHTML() {
|
||
let html = `
|
||
<div class="form-row align-items-end">
|
||
<div class="form-group col-md-3">
|
||
<label for="installment_amount">Installment Amount</label>
|
||
<input type="text" class="form-control" name="installment_amount[]" placeholder="Enter Amount">
|
||
</div>
|
||
|
||
<div class="form-group col-md-3">
|
||
<label for="payment_date">Payment Date</label>
|
||
<input type="text" class="form-control payment_date" name="payment_date[]" placeholder="DD/MM/YYYY">
|
||
</div>
|
||
|
||
<div class="form-group col-md-3">
|
||
<label for="utr_no">UTR No.</label>
|
||
<input type="text" class="form-control" name="utr_no[]" placeholder="Enter UTR No.">
|
||
</div>
|
||
|
||
<div class="form-group col-md-2">
|
||
<button type="button" class="btn btn-danger remove-installment">X</button>
|
||
</div>
|
||
</div>
|
||
`;
|
||
|
||
$('#installment_form_row').append(html);
|
||
|
||
$('.payment_date').flatpickr({
|
||
dateFormat: 'd-m-Y',
|
||
});
|
||
}
|
||
|
||
$(document).on('click', '.remove-installment', function () {
|
||
let $this = $(this); // Store reference to the clicked element
|
||
let row_count = $('#installment_form_row .form-row').length;
|
||
console.log("row_count", row_count);
|
||
|
||
let id = $this.closest('.form-row').find('input[name="installment_primary_key[]"]').val() ?? null;
|
||
console.log("id", id);
|
||
let ids = id ? [id] : [];
|
||
console.log("ids", ids);
|
||
|
||
if (id != null && row_count > 1) {
|
||
Swal.fire({
|
||
title: "Do you want to remove this?",
|
||
icon: "warning",
|
||
showCancelButton: true,
|
||
confirmButtonColor: "#3085d6",
|
||
cancelButtonColor: "#d33",
|
||
confirmButtonText: "Yes, Proceed!"
|
||
}).then((result) => {
|
||
if (result.isConfirmed) {
|
||
let url = '<?= base_url('util/removeInstallments') ?>';
|
||
let requestData = { id: ids };
|
||
|
||
$('.loader').fadeIn();
|
||
$('.loader-mask').fadeIn();
|
||
|
||
sendAjaxRequestForGlobal(url, 'GET', requestData, function(response) {
|
||
console.log('Data fetched successfully:', response);
|
||
|
||
if (response.status === true) {
|
||
toastr.success(response.message, 'SUCCESS');
|
||
|
||
$this.closest('.form-row').remove();
|
||
let updated_row_count = $('#installment_form_row .form-row').length;
|
||
$('#no_of_installment').val(updated_row_count);
|
||
console.log("after remove row_count", updated_row_count);
|
||
} else {
|
||
toastr.error(response.message, 'WARNING');
|
||
}
|
||
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
|
||
}, function(xhr, status, error) {
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
console.error('Error fetching data:', error);
|
||
console.error(xhr.responseText);
|
||
toastr.error('An error occurred while removing the installment.', 'ERROR');
|
||
});
|
||
}
|
||
});
|
||
} else {
|
||
if (row_count > 1) {
|
||
$this.closest('.form-row').remove();
|
||
let updated_row_count = $('#installment_form_row .form-row').length;
|
||
$('#no_of_installment').val(updated_row_count);
|
||
console.log("after remove row_count", updated_row_count);
|
||
} else {
|
||
console.log("Only one row left. Not removing.");
|
||
}
|
||
}
|
||
});
|
||
|
||
$('#no_of_installment').on('change', function () {
|
||
let no_of_installments = parseInt($(this).val());
|
||
let $installmentContainer = $('#installment_form_row');
|
||
let row_count = $installmentContainer.find('.form-row').length;
|
||
|
||
console.log("Form row count:", row_count);
|
||
|
||
if (row_count === 1) {
|
||
// $installmentContainer.empty();
|
||
for (let index = 0; index < no_of_installments - 1; index++) {
|
||
addInstallmentHTML();
|
||
}
|
||
} else if (no_of_installments === row_count) {
|
||
console.log('Same row count, no change needed.');
|
||
} else if (no_of_installments < row_count) {
|
||
|
||
// Remove extra rows from the end
|
||
let remove_count = row_count - no_of_installments;
|
||
let ids = $installmentContainer.find('.form-row')
|
||
.slice(-remove_count)
|
||
.find('input[name="installment_primary_key[]"]')
|
||
.map(function() {
|
||
return $(this).val();
|
||
}).get();
|
||
|
||
console.log('ids', ids);
|
||
|
||
if (Object.keys(ids).length > 0) {
|
||
Swal.fire({
|
||
title: "Do you want to remove the last " + (remove_count ?? "") + " entries?",
|
||
icon: "warning",
|
||
showCancelButton: true,
|
||
confirmButtonColor: "#3085d6",
|
||
cancelButtonColor: "#d33",
|
||
confirmButtonText: "Yes, Proceed!"
|
||
}).then((result) => {
|
||
if (result.isConfirmed) {
|
||
let url = '<?= base_url('util/removeInstallments') ?>';
|
||
let requestData = { id: ids };
|
||
|
||
$('.loader').fadeIn();
|
||
$('.loader-mask').fadeIn();
|
||
|
||
sendAjaxRequestForGlobal(url, 'GET', requestData, function(response) {
|
||
console.log('Data fetched successfully:', response);
|
||
|
||
if (response.status === true) {
|
||
toastr.success(response.message, 'SUCCESS');
|
||
$installmentContainer.find('.form-row').slice(-remove_count).remove();
|
||
} else {
|
||
toastr.error(response.message, 'WARNING');
|
||
}
|
||
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
|
||
}, function(xhr, status, error) {
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
console.error('Error fetching data:', error);
|
||
console.error(xhr.responseText);
|
||
toastr.error('An error occurred while removing the installment.', 'ERROR');
|
||
});
|
||
}else{
|
||
$('#no_of_installment').val(row_count);
|
||
}
|
||
});
|
||
} else {
|
||
$installmentContainer.find('.form-row').slice(-remove_count).remove();
|
||
}
|
||
|
||
} else if (no_of_installments > row_count) {
|
||
// Add extra rows from the end
|
||
let add_count = no_of_installments - row_count;
|
||
for (let index = 0; index < add_count; index++) {
|
||
addInstallmentHTML();
|
||
}
|
||
} else {
|
||
// Add missing rows
|
||
let add_count = no_of_installments - row_count;
|
||
for (let index = 0; index < add_count; index++) {
|
||
addInstallmentHTML();
|
||
}
|
||
}
|
||
});
|
||
|
||
$(document).ready(function(){
|
||
setTimeout(function(){
|
||
$('.payment_date').flatpickr({
|
||
dateFormat: 'd-m-Y',
|
||
});
|
||
}, 2000)
|
||
})
|
||
|
||
|
||
</script>
|
||
|
||
<script>
|
||
|
||
function showTinyToast(){
|
||
const saveIndicator = document.getElementById('saveIndicator');
|
||
saveIndicator.classList.add('show');
|
||
setTimeout(() => {
|
||
saveIndicator.classList.remove('show');
|
||
}, 2000);
|
||
}
|
||
|
||
</script>
|