FEAT_COPY_PASTE_EXCEL_TO_RACK_RATE_DATA_COMPLETE : RV
This commit is contained in:
parent
0df9ea4398
commit
65987607c5
@ -1165,21 +1165,24 @@ class ClientController extends AdminController
|
|||||||
$self = $policy_terms_data->family_floaters;
|
$self = $policy_terms_data->family_floaters;
|
||||||
}
|
}
|
||||||
|
|
||||||
$emp_count = $this->employeeModel->join('client_policy cp', "employees.client_id = cp.client_id")
|
// $emp_count = $this->employeeModel
|
||||||
->join('employee_polices ep', "cp.id = ep.client_policy_id AND employees.id = ep.employee_id")
|
// ->join('client_policy cp', "employees.client_id = cp.client_id")
|
||||||
->where("employees.client_id", $record['client_id'])
|
// ->join('employee_polices ep', "cp.id = ep.client_policy_id AND employees.id = ep.employee_id")
|
||||||
->where("employees.emp_status", 'active')
|
// ->where("employees.client_id", $record['client_id'])
|
||||||
->where("ep.status", 'active')
|
// ->where("employees.emp_status", 'active')
|
||||||
->where("employees.is_active", 1)
|
// ->where("ep.status", 'active')
|
||||||
->where("ep.is_active", 1)
|
// ->where("employees.is_active", 1)
|
||||||
|
// ->where("ep.is_active", 1)
|
||||||
|
// ->countAllResults();
|
||||||
|
|
||||||
|
|
||||||
|
$emp_count = $this->employeePolicyModel
|
||||||
|
->join('client_policy cp', "cp.id = employee_polices.client_policy_id")
|
||||||
|
->where("employee_polices.client_policy_id", $client_policy_id)
|
||||||
|
->where("employee_polices.status", 'active')
|
||||||
|
->where("employee_polices.is_active", 1)
|
||||||
->countAllResults();
|
->countAllResults();
|
||||||
|
|
||||||
|
|
||||||
// $data = $this->employeePolicyModel->select('employee_polices.id')
|
|
||||||
// ->where('employee_polices.is_active', 1)
|
|
||||||
// ->where('employee_polices.client_policy_id', $client_policy_id)
|
|
||||||
// ->findAll();
|
|
||||||
|
|
||||||
// $emp_count = count($data);
|
// $emp_count = count($data);
|
||||||
|
|
||||||
// if($emp_count == 0){
|
// if($emp_count == 0){
|
||||||
@ -1289,14 +1292,14 @@ class ClientController extends AdminController
|
|||||||
// print_r($premium1);
|
// print_r($premium1);
|
||||||
// print_r($premium2); die;
|
// print_r($premium2); die;
|
||||||
|
|
||||||
return $this->respond(['status' => true, 'code' => 200, 'data' => $resultss, 'premiumData' => json_encode($premiumDataa), 'count' => $emp_count, 'policy_name' => $policy_name, 'family_floater' => $family_floater, 'self' => $self], 200);
|
return $this->respond(['status' => true, 'code' => 200, 'data' => $resultss, 'premiumData' => json_encode($premiumDataa), 'count' => $emp_count, 'policy_name' => $policy_name, 'family_floater' => $family_floater, 'self' => $self, 'client_policy_id' => $client_policy_id], 200);
|
||||||
|
|
||||||
} else if ($search_term === 'GPA') {
|
} else if ($search_term === 'GPA') {
|
||||||
|
|
||||||
return $this->respond(['status' => true, 'code' => 200, 'data' => $results, 'premiumData' => json_encode($premiumData), 'count' => $emp_count, 'policy_name' => $policy_name, 'family_floater' => $family_floater, 'self' => $self], 200);
|
return $this->respond(['status' => true, 'code' => 200, 'data' => $results, 'premiumData' => json_encode($premiumData), 'count' => $emp_count, 'policy_name' => $policy_name, 'family_floater' => $family_floater, 'self' => $self, 'client_policy_id' => $client_policy_id], 200);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
return $this->respond(['status' => false, 'code' => 200, 'data' => $results, 'premiumData' => json_encode($premiumData), 'count' => $emp_count, 'policy_name' => $policy_name, 'family_floater' => $family_floater, 'self' => $self], 200);
|
return $this->respond(['status' => false, 'code' => 200, 'data' => $results, 'premiumData' => json_encode($premiumData), 'count' => $emp_count, 'policy_name' => $policy_name, 'family_floater' => $family_floater, 'self' => $self, 'client_policy_id' => $client_policy_id], 200);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
<?php include('policy_grid_excel.php')?>
|
||||||
|
|
||||||
<!-- Modal content for the Large example -->
|
<!-- Modal content for the Large example -->
|
||||||
<div class="modal fade" id="bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel"
|
<div class="modal fade" id="bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel"
|
||||||
aria-hidden="true" aria-modal="true" data-backdrop="static" style="padding-right: 15px">
|
aria-hidden="true" aria-modal="true" data-backdrop="static" style="padding-right: 15px">
|
||||||
@ -71,11 +73,15 @@
|
|||||||
|
|
||||||
<div class="form-row" id="grid_content_input" style="display: true;">
|
<div class="form-row" id="grid_content_input" style="display: true;">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row" id="grid_content_from_excel" style="display: none;">
|
|
||||||
<?php include('policy_grid_excel.php')?>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-row" id="grid_content_input">
|
|
||||||
|
<div class="form-row" id="grid_content_from_excel" style="display: none;">
|
||||||
|
|
||||||
|
<p>Paste excel data here: <a href="#" type="button" onclick="copyHeaders(0)">Copy Excel Headers</a></p>
|
||||||
|
<textarea class="form-control excel_textarea" id="copied_excel_data" name="copied_excel_data" style="width:100%;height:200px;" oninput="generateTable(0)"></textarea><br>
|
||||||
|
<hr>
|
||||||
|
<div class="excel_table_class" id="excel_table" style="display: none;"></div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@ -121,16 +127,25 @@
|
|||||||
Insurance </label>
|
Insurance </label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div class="form-row" id="relationship">
|
<div class="form-row" id="relationship">
|
||||||
</div>
|
</div> <br>
|
||||||
|
|
||||||
|
<a href="#" id='copyfromexcelforadditional'>Copy from excel</a>
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
<div class="form-row" id="additional_grid_content_input">
|
<div class="form-row" id="additional_grid_content_input" style="display: true;">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-row" id="additional_grid_content_from_excel" style="display: none;">
|
||||||
|
|
||||||
|
<p>Paste excel data here: <a href="#" type="button" onclick="copyHeaders(1)">Copy Excel Headers</a></p>
|
||||||
|
<textarea class="form-control excel_textarea" id="additional_copied_excel_data" name="additional_copied_excel_data" style="width:100%;height:200px;" oninput="generateTable(1)"></textarea><br>
|
||||||
|
<hr>
|
||||||
|
<div class="excel_table_class" id="additional_excel_table" style="display: none;"></div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@ -158,6 +173,26 @@ $('#btnGridSubmit').hide();
|
|||||||
|
|
||||||
$('.close').click(function() {
|
$('.close').click(function() {
|
||||||
|
|
||||||
|
$('#grid_content_input').show();
|
||||||
|
$('#grid_content_from_excel').hide();
|
||||||
|
|
||||||
|
if ($('#copyfromexcel').text() == "Manual entry") {
|
||||||
|
$('#copyfromexcel').text("Copy from excel")
|
||||||
|
} else {
|
||||||
|
$('#copyfromexcel').text("Copy from excel");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$('#additional_grid_content_input').show();
|
||||||
|
$('#additional_grid_content_from_excel').hide();
|
||||||
|
|
||||||
|
if ($('#copyfromexcelforadditional').text() == "Manual entry") {
|
||||||
|
$('#copyfromexcelforadditional').text("Copy from excel")
|
||||||
|
} else {
|
||||||
|
$('#copyfromexcelforadditional').text("Copy from excel");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
for (var i = 1; i <= 13; i++) {
|
for (var i = 1; i <= 13; i++) {
|
||||||
$('#grid_' + i).remove();
|
$('#grid_' + i).remove();
|
||||||
$('#add_grid_' + i).remove();
|
$('#add_grid_' + i).remove();
|
||||||
@ -166,6 +201,7 @@ $('.close').click(function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
$('#copyfromexcel').click(function() {
|
$('#copyfromexcel').click(function() {
|
||||||
|
|
||||||
// alert('called');
|
// alert('called');
|
||||||
// $('#copyfromexcel').toggle();
|
// $('#copyfromexcel').toggle();
|
||||||
// $("#copied_excel_data").val(result.exampleMessage);
|
// $("#copied_excel_data").val(result.exampleMessage);
|
||||||
@ -182,6 +218,22 @@ $('#copyfromexcel').click(function() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#copyfromexcelforadditional').click(function() {
|
||||||
|
|
||||||
|
if ($(this).text() == "Copy from excel") {
|
||||||
|
$(this).text("Manual entry")
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$(this).text("Copy from excel");
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#additional_grid_content_input').toggle();
|
||||||
|
$('#additional_grid_content_from_excel').toggle();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = false, rr_type = false) {
|
function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = false, rr_type = false) {
|
||||||
@ -807,8 +859,7 @@ $("#GridForm").submit(function(event) {
|
|||||||
|
|
||||||
$('.loader').fadeOut();
|
$('.loader').fadeOut();
|
||||||
$('.loader-mask').delay(350).fadeOut('slow');
|
$('.loader-mask').delay(350).fadeOut('slow');
|
||||||
var message = (policy_PrimaryKey === '') ? 'Policy Premium Added successfully' :
|
var message = (policy_PrimaryKey === '') ? 'Policy Premium Added successfully' :'Policy Premium Added Successfully';
|
||||||
'Policy Premium Added Successfully';
|
|
||||||
toastr.success(message, 'Success');
|
toastr.success(message, 'Success');
|
||||||
// $('.close').click();
|
// $('.close').click();
|
||||||
|
|
||||||
@ -829,7 +880,6 @@ $("#GridForm").submit(function(event) {
|
|||||||
$("#AdditionalGridForm").submit(function(event) {
|
$("#AdditionalGridForm").submit(function(event) {
|
||||||
|
|
||||||
var check = checkDuplicate(1);
|
var check = checkDuplicate(1);
|
||||||
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
if ($('#grid_emp_count').val() == 'false') {
|
if ($('#grid_emp_count').val() == 'false') {
|
||||||
@ -966,18 +1016,21 @@ $('body').on('click', '.btnPolicyModel', function() {
|
|||||||
res.premiumData = JSON.parse(res.premiumData);
|
res.premiumData = JSON.parse(res.premiumData);
|
||||||
|
|
||||||
console.log('policy grid responce', res.premiumData);
|
console.log('policy grid responce', res.premiumData);
|
||||||
console.log('policy grid responce', res.policy_name);
|
console.log('policy name', res.policy_name);
|
||||||
|
|
||||||
|
|
||||||
$('#nameOfThePolicy').html(' - ' + res.policy_name);
|
$('#nameOfThePolicy').text(' - ' + res.policy_name);
|
||||||
$('#grid_emp_count').val(res.count);
|
$('#grid_emp_count').val(res.count);
|
||||||
|
|
||||||
|
|
||||||
if (res.count > 0) {
|
if (res.count > 0) {
|
||||||
$("#hide_smbt_btn").hide();
|
$("#hide_smbt_btn").hide();
|
||||||
|
$("#secondary_rack_rate_btn_grp").hide();
|
||||||
} else {
|
} else {
|
||||||
$("#hide_smbt_btn").show();
|
$("#hide_smbt_btn").show();
|
||||||
|
$("#secondary_rack_rate_btn_grp").show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (res.status === false) {
|
if (res.status === false) {
|
||||||
toastr.error(res.status);
|
toastr.error(res.status);
|
||||||
@ -1037,8 +1090,6 @@ $('body').on('click', '.btnPolicyModel', function() {
|
|||||||
console.log('policy_grid_id_value', policy_grid_id_value);
|
console.log('policy_grid_id_value', policy_grid_id_value);
|
||||||
console.log('secondary_policy_grid_id_value', secondary_policy_grid_id_value);
|
console.log('secondary_policy_grid_id_value', secondary_policy_grid_id_value);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$('#grid_content_input').empty();
|
$('#grid_content_input').empty();
|
||||||
var policeGridOptionHTML = '';
|
var policeGridOptionHTML = '';
|
||||||
policeGridOptionHTML += ` <option value="">Select Premium Type</option>`;
|
policeGridOptionHTML += ` <option value="">Select Premium Type</option>`;
|
||||||
@ -1050,7 +1101,7 @@ $('body').on('click', '.btnPolicyModel', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
$('#additional_grid_content_input').empty();
|
||||||
var policeGridOptionHTMLforSecondary = '';
|
var policeGridOptionHTMLforSecondary = '';
|
||||||
policeGridOptionHTMLforSecondary +=
|
policeGridOptionHTMLforSecondary +=
|
||||||
` <option value="">Select Premium Type</option>`;
|
` <option value="">Select Premium Type</option>`;
|
||||||
@ -1129,7 +1180,12 @@ $('body').on('click', '.btnPolicyModel', function() {
|
|||||||
$(this).trigger('keyup');
|
$(this).trigger('keyup');
|
||||||
});
|
});
|
||||||
|
|
||||||
var id_for_trigger = temp_for_premiumData[0].policy_grid_id;
|
var id_for_trigger = [];
|
||||||
|
if (temp_for_premiumData.length > 0 && temp_for_premiumData[0] !== undefined) {
|
||||||
|
id_for_trigger = temp_for_premiumData[0].policy_grid_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$(`input[name="${id_for_trigger}_si[]"]`).each(function() {
|
$(`input[name="${id_for_trigger}_si[]"]`).each(function() {
|
||||||
// console.log($(this));
|
// console.log($(this));
|
||||||
$(this).trigger('keyup');
|
$(this).trigger('keyup');
|
||||||
@ -1167,6 +1223,8 @@ $('body').on('click', '.btnPolicyModel', function() {
|
|||||||
|
|
||||||
$('#grid').change(function() {
|
$('#grid').change(function() {
|
||||||
|
|
||||||
|
$('.excel_textarea').val('');
|
||||||
|
|
||||||
var grid_id = $(this)[0].value;
|
var grid_id = $(this)[0].value;
|
||||||
var client_policy_id = $('#client_policy_id')[0].value;
|
var client_policy_id = $('#client_policy_id')[0].value;
|
||||||
|
|
||||||
@ -1239,7 +1297,6 @@ $('#grid').change(function() {
|
|||||||
si_or_bp_value = res.premiumData[0].si_or_bp;
|
si_or_bp_value = res.premiumData[0].si_or_bp;
|
||||||
|
|
||||||
$('#si_or_bp').val(si_or_bp_value);
|
$('#si_or_bp').val(si_or_bp_value);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1277,6 +1334,8 @@ $('#grid').change(function() {
|
|||||||
|
|
||||||
$('#additional_grid').change(function() {
|
$('#additional_grid').change(function() {
|
||||||
|
|
||||||
|
$('.excel_textarea').val('');
|
||||||
|
|
||||||
var grid_id = $(this)[0].value;
|
var grid_id = $(this)[0].value;
|
||||||
var client_policy_id = $('#client_policy_id')[0].value;
|
var client_policy_id = $('#client_policy_id')[0].value;
|
||||||
|
|
||||||
@ -1302,9 +1361,9 @@ $('#additional_grid').change(function() {
|
|||||||
|
|
||||||
if (res.count > 0) {
|
if (res.count > 0) {
|
||||||
// console.log(' hide submit btn count ', res.count);
|
// console.log(' hide submit btn count ', res.count);
|
||||||
$("#hide_smbt_btn").hide();
|
$("#secondary_rack_rate_btn_grp").hide();
|
||||||
} else {
|
} else {
|
||||||
$("#hide_smbt_btn").show();
|
$("#secondary_rack_rate_btn_grp").show();
|
||||||
// console.log('show submit btn count ', res.count);
|
// console.log('show submit btn count ', res.count);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1315,9 +1374,9 @@ $('#additional_grid').change(function() {
|
|||||||
|
|
||||||
if (res.count > 0) {
|
if (res.count > 0) {
|
||||||
// console.log(' hide submit btn count ', res.count);
|
// console.log(' hide submit btn count ', res.count);
|
||||||
$("#hide_smbt_btn").hide();
|
$("#secondary_rack_rate_btn_grp").hide();
|
||||||
} else {
|
} else {
|
||||||
$("#hide_smbt_btn").show();
|
$("#secondary_rack_rate_btn_grp").show();
|
||||||
// console.log('show submit btn count ', res.count);
|
// console.log('show submit btn count ', res.count);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1332,7 +1391,7 @@ $('#additional_grid').change(function() {
|
|||||||
policy_grid_id_value = res.premiumData[0].policy_grid_id;
|
policy_grid_id_value = res.premiumData[0].policy_grid_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
$('#grid_content_input').empty();
|
$('#additional_grid_content_input').empty();
|
||||||
var policeGridOptionHTML = '';
|
var policeGridOptionHTML = '';
|
||||||
policeGridOptionHTML += ` <option value="">Select Premium Type</option>`;
|
policeGridOptionHTML += ` <option value="">Select Premium Type</option>`;
|
||||||
$.each(res.data, function(index, item) {
|
$.each(res.data, function(index, item) {
|
||||||
@ -1341,7 +1400,9 @@ $('#additional_grid').change(function() {
|
|||||||
'selected="selected"' : '') + '>' + item.policy_grid_type +
|
'selected="selected"' : '') + '>' + item.policy_grid_type +
|
||||||
'</option>';
|
'</option>';
|
||||||
});
|
});
|
||||||
|
|
||||||
// $('#grid').html(policeGridOptionHTML);
|
// $('#grid').html(policeGridOptionHTML);
|
||||||
|
|
||||||
var si_or_bp_value = '';
|
var si_or_bp_value = '';
|
||||||
if (res.premiumData && res.premiumData.length > 0) {
|
if (res.premiumData && res.premiumData.length > 0) {
|
||||||
|
|
||||||
@ -2530,12 +2591,16 @@ function getCurrentTime() {
|
|||||||
|
|
||||||
|
|
||||||
function createCheckboxes(obj, additional_relationship) {
|
function createCheckboxes(obj, additional_relationship) {
|
||||||
|
|
||||||
console.log('createCheckboxes function called');
|
console.log('createCheckboxes function called');
|
||||||
|
|
||||||
console.log(additional_relationship)
|
console.log(additional_relationship);
|
||||||
additional_relationship = JSON.parse(additional_relationship);
|
try {
|
||||||
console.log(additional_relationship)
|
additional_relationship = JSON.parse(additional_relationship);
|
||||||
|
console.log(additional_relationship);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error parsing additional_relationship:", error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$('#relationship').empty();
|
$('#relationship').empty();
|
||||||
const $relationshipElement = $('#relationship');
|
const $relationshipElement = $('#relationship');
|
||||||
@ -2545,24 +2610,24 @@ function createCheckboxes(obj, additional_relationship) {
|
|||||||
const multiplier = 7; // Adjust this value as needed
|
const multiplier = 7; // Adjust this value as needed
|
||||||
|
|
||||||
$.each(obj, function(key, value) {
|
$.each(obj, function(key, value) {
|
||||||
|
|
||||||
if (value > 0 && key != 'either-parents-pil') {
|
if (value > 0 && key != 'either-parents-pil') {
|
||||||
|
const isChecked = additional_relationship && typeof additional_relationship === 'object' && additional_relationship[key] == 1 ? 'checked' : '';
|
||||||
key = formatString(key);
|
key = formatString(key);
|
||||||
const isChecked = additional_relationship && additional_relationship[key] === 1 ? 'checked' : '';
|
console.log('isChecked', isChecked);
|
||||||
html += `
|
html += `
|
||||||
<div class="col-2">
|
<div class="col-2">
|
||||||
<input type="checkbox" ${isChecked} name="${key}">
|
<input type="checkbox" name="${key}" ${isChecked}>
|
||||||
<label style="position: relative;left: 18px;bottom: 30px;">${key}</label>
|
<label style="position: relative;left: 18px;bottom: 30px;">${key}</label>
|
||||||
</div>`;
|
</div>`;
|
||||||
|
// console.log(html);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$relationshipElement.append(html);
|
$relationshipElement.append(html);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function formatString(str) {
|
function formatString(str) {
|
||||||
return str.split('-').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join(' ');
|
return str.split('-').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join(' ');
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,241 +1,412 @@
|
|||||||
<style>
|
<style>
|
||||||
table {
|
table {
|
||||||
border-collapse: collapse;
|
border-collapse: collapse;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
td, th {
|
|
||||||
padding: 0.2rem; /* Adjust padding as needed */
|
|
||||||
}
|
|
||||||
.error {
|
|
||||||
background-color: #f8d7da;
|
|
||||||
}
|
|
||||||
.duplicate {
|
|
||||||
background-color: #fff3cd;
|
|
||||||
}
|
|
||||||
.container {
|
|
||||||
margin-top: 20px;
|
|
||||||
}
|
|
||||||
.compact-table td, .compact-table th {
|
|
||||||
padding: 0.1rem; /* Adjust padding as needed */
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<div>
|
td,
|
||||||
|
th {
|
||||||
<!-- <div> -->
|
padding: 0.2rem;
|
||||||
<p>Paste excel data here: <a href="#" type="button" onclick="copyHeaders()">Copy Excel Headers</a></p>
|
}
|
||||||
<textarea id="copied_excel_data" name="copied_excel_data" style="width:100%;height:200px;" oninput="generateTable()"></textarea><br>
|
|
||||||
|
|
||||||
<!-- </div> -->
|
|
||||||
<hr>
|
|
||||||
<div id="excel_table"></div>
|
|
||||||
|
|
||||||
<hr>
|
|
||||||
<div>
|
|
||||||
<input type="button" id="submitBtn" onclick="submitData()" value="Submit" disabled/>
|
|
||||||
<br><br>
|
|
||||||
<p>JSON output:</p>
|
|
||||||
<div id="json_output"></div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script>
|
.error {
|
||||||
const formatType = 0; // Specify the format type here
|
background-color: #f8d7da;
|
||||||
const excel_headers = {
|
}
|
||||||
3: {
|
|
||||||
"sum_insured": "Sum Insured",
|
.duplicate {
|
||||||
"premium": "Premium"
|
background-color: #fff3cd;
|
||||||
},
|
}
|
||||||
4: {
|
|
||||||
"sum_insured": "Sum Insured",
|
.container {
|
||||||
"from_age": "From Age",
|
margin-top: 20px;
|
||||||
"to_age": "To Age",
|
}
|
||||||
"premium": "Premium"
|
|
||||||
},
|
.compact-table td,
|
||||||
5: {
|
.compact-table th {
|
||||||
"sum_insured": "Sum Insured",
|
padding: 0.1rem;
|
||||||
"from_age": "From Age",
|
}
|
||||||
"to_age": "To Age",
|
</style>
|
||||||
"premium": "Premium"
|
|
||||||
},
|
|
||||||
6: {
|
|
||||||
"sum_insured": "Sum Insured",
|
<script>
|
||||||
"from_age": "From Age",
|
const formatType = 0; // Specify the format type here
|
||||||
"to_age": "To Age",
|
const excel_headers = {
|
||||||
"premium": "Premium"
|
3: {
|
||||||
},
|
"sum_insured": "Sum Insured",
|
||||||
7: {
|
"premium": "Premium"
|
||||||
"sum_insured": "Sum Insured",
|
},
|
||||||
"from_age": "From Age",
|
4: {
|
||||||
"to_age": "To Age",
|
"sum_insured": "Sum Insured",
|
||||||
"premium": "Premium"
|
"from_age": "From Age",
|
||||||
},
|
"to_age": "To Age",
|
||||||
8: {
|
"premium": "Premium"
|
||||||
"sum_insured": "Sum Insured",
|
},
|
||||||
"grade": "Grade",
|
5: {
|
||||||
"premium": "Premium"
|
"sum_insured": "Sum Insured",
|
||||||
},
|
"from_age": "From Age",
|
||||||
9:
|
"to_age": "To Age",
|
||||||
{
|
"premium": "Premium"
|
||||||
"sum_insured": "Sum Insured",
|
},
|
||||||
"premium": "Premium"
|
6: {
|
||||||
},
|
"sum_insured": "Sum Insured",
|
||||||
10: {
|
"from_age": "From Age",
|
||||||
"sum_insured": "Sum Insured",
|
"to_age": "To Age",
|
||||||
"from_age": "From Age",
|
"premium": "Premium"
|
||||||
"to_age": "To Age",
|
},
|
||||||
"premium": "Premium"
|
7: {
|
||||||
},
|
"sum_insured": "Sum Insured",
|
||||||
11: {
|
"from_age": "From Age",
|
||||||
"sum_insured": "Sum Insured",
|
"to_age": "To Age",
|
||||||
"grade": "Grade",
|
"premium": "Premium"
|
||||||
"premium": "Premium",
|
},
|
||||||
"max_si": "Max Si"
|
8: {
|
||||||
},
|
"sum_insured": "Sum Insured",
|
||||||
12: {
|
"grade": "Grade",
|
||||||
"sum_insured": "Sum Insured",
|
"premium": "Premium"
|
||||||
"relationship": "Relationship",
|
},
|
||||||
"premium": "Premium"
|
9: {
|
||||||
},
|
"sum_insured": "Sum Insured",
|
||||||
13: {
|
"premium": "Premium"
|
||||||
"sum_insured": "Sum Insured",
|
},
|
||||||
"relationship": "Relationship",
|
10: {
|
||||||
"from_age": "From Age",
|
"sum_insured": "Sum Insured",
|
||||||
"to_age": "To Age",
|
"from_age": "From Age",
|
||||||
"premium": "Premium"
|
"to_age": "To Age",
|
||||||
|
"premium": "Premium"
|
||||||
|
},
|
||||||
|
11: {
|
||||||
|
"sum_insured": "Sum Insured",
|
||||||
|
"grade": "Grade",
|
||||||
|
"premium": "Premium",
|
||||||
|
"max_si": "Max Si"
|
||||||
|
},
|
||||||
|
12: {
|
||||||
|
"sum_insured": "Sum Insured",
|
||||||
|
"relationship": "Relationship",
|
||||||
|
"premium": "Premium"
|
||||||
|
},
|
||||||
|
13: {
|
||||||
|
"sum_insured": "Sum Insured",
|
||||||
|
"relationship": "Relationship",
|
||||||
|
"from_age": "From Age",
|
||||||
|
"to_age": "To Age",
|
||||||
|
"premium": "Premium"
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
function slugify(text) {
|
||||||
|
return text.toString().toLowerCase().replace(/\s+/g, '_').replace(/[^\w\-]+/g, '').replace(/\-\-+/g, '_')
|
||||||
|
.replace(/^-+/, '').replace(/-+$/, '');
|
||||||
|
}
|
||||||
|
|
||||||
|
function copyHeaders(rack_rate_type) {
|
||||||
|
|
||||||
|
let formatType = $('#grid').val();
|
||||||
|
var obj = $('#grid');
|
||||||
|
if(rack_rate_type == 1){
|
||||||
|
formatType = $('#additional_grid').val();
|
||||||
|
obj = $('#additional_grid');
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(obj)
|
||||||
|
console.log(formatType)
|
||||||
|
|
||||||
|
if(!formatType && formatType == ""){
|
||||||
|
toastr.warning('Please select the Policy Premium Type', 'Warning');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const headerString = Object.values(excel_headers[formatType]).join("\t"); // Using specified format type for copying headers
|
||||||
|
navigator.clipboard.writeText(headerString).then(function() {
|
||||||
|
toastr.success('Headers copied to clipboard', 'success');
|
||||||
|
}, function(err) {
|
||||||
|
toastr.error(err, 'Could not copy headers:');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function generateTable(rack_rate_type) {
|
||||||
|
|
||||||
|
var data = $('#copied_excel_data').val();
|
||||||
|
let formatType = $('#grid').val();
|
||||||
|
var obj = $('#grid');
|
||||||
|
|
||||||
|
if (rack_rate_type == 1) {
|
||||||
|
data = $('#additional_copied_excel_data').val();
|
||||||
|
formatType = $('#additional_grid').val();
|
||||||
|
obj = $('#additional_grid');
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(obj);
|
||||||
|
console.log(formatType);
|
||||||
|
console.log(data);
|
||||||
|
|
||||||
|
if (!formatType || formatType == "") {
|
||||||
|
$('.excel_table_class').empty();
|
||||||
|
$('.excel_textarea').val('');
|
||||||
|
toastr.warning('Please select the Policy Premium Type', 'Warning');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if Excel data is empty
|
||||||
|
if (!data.trim()) {
|
||||||
|
toastr.warning('Excel data is empty.', 'Warning');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var rows = data.split("\n");
|
||||||
|
|
||||||
|
// Filter out empty rows
|
||||||
|
rows = rows.filter(rowText => rowText.split("\t").some(cell => cell.trim()));
|
||||||
|
|
||||||
|
if (rows.length === 0) {
|
||||||
|
toastr.warning('All rows are empty after filtering.', 'Warning');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var header = rows[0].split("\t");
|
||||||
|
|
||||||
|
// Determine the columns to keep (non-empty columns)
|
||||||
|
var columnsToKeep = [];
|
||||||
|
for (let i = 0; i < header.length; i++) {
|
||||||
|
if (rows.some(rowText => rowText.split("\t")[i].trim())) {
|
||||||
|
columnsToKeep.push(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
function slugify(text) {
|
|
||||||
return text.toString().toLowerCase().replace(/\s+/g, '_').replace(/[^\w\-]+/g, '').replace(/\-\-+/g, '_').replace(/^-+/, '').replace(/-+$/, '');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function copyHeaders() {
|
// Filter header based on columns to keep
|
||||||
const headerString = Object.values(excel_headers[formatType]).join("\t"); // Using specified format type for copying headers
|
header = columnsToKeep.map(i => slugify(header[i]));
|
||||||
navigator.clipboard.writeText(headerString).then(function() {
|
|
||||||
alert('Headers copied to clipboard');
|
if (!excel_headers[formatType]) {
|
||||||
}, function(err) {
|
toastr.warning("Unknown format type. Please check the header columns.", 'Warning');
|
||||||
alert('Could not copy headers: ', err);
|
$('.excel_table_class').empty();
|
||||||
|
$('.excel_textarea').val('');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var expectedHeader = Object.keys(excel_headers[formatType]);
|
||||||
|
|
||||||
|
if (JSON.stringify(header) !== JSON.stringify(expectedHeader)) {
|
||||||
|
const expectedHeaders = JSON.stringify(Object.values(excel_headers[formatType]));
|
||||||
|
const receivedHeaders = JSON.stringify(columnsToKeep.map(i => rows[0].split("\t")[i]));
|
||||||
|
|
||||||
|
Swal.fire({
|
||||||
|
title: "Header Mismatch",
|
||||||
|
html: `
|
||||||
|
<p>Header columns do not match expected format:</p>
|
||||||
|
<p><strong>Expected:</strong> ${expectedHeaders}</p>
|
||||||
|
<p><strong>Received:</strong> ${receivedHeaders}</p>
|
||||||
|
`,
|
||||||
|
icon: "error"
|
||||||
});
|
});
|
||||||
|
$('.excel_table_class').empty();
|
||||||
|
$('.excel_textarea').val('');
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateTable() {
|
var table = $('<table class="table table-striped compact-table" />');
|
||||||
var data = $('#copied_excel_data').val();
|
var uniqueRows = new Set();
|
||||||
const formatType = $('#grid').val();
|
var emptyCellCount = 0;
|
||||||
alert(formatType);
|
|
||||||
// Check if Excel data is empty
|
|
||||||
if (!data.trim()) {
|
|
||||||
alert('Excel data is empty.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var rows = data.split("\n");
|
|
||||||
var table = $('<table class="table table-striped compact-table" />');
|
|
||||||
var header = rows[0].split("\t").map(cell => slugify(cell));
|
|
||||||
|
|
||||||
if (!excel_headers[formatType]) {
|
rows.forEach((rowText, y) => {
|
||||||
alert("Unknown format type. Please check the header columns.");
|
var cells = rowText.split("\t").filter((_, i) => columnsToKeep.includes(i));
|
||||||
$('#submitBtn').prop('disabled', true);
|
var row = $('<tr />');
|
||||||
$('#excel_table').empty();
|
|
||||||
|
// Skip empty rows after filtering columns
|
||||||
|
if (cells.every(cell => !cell.trim())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var expectedHeader = Object.keys(excel_headers[formatType]);
|
cells.forEach(cellText => {
|
||||||
|
row.append('<td>' + cellText + '</td>');
|
||||||
if (JSON.stringify(header) !== JSON.stringify(expectedHeader)) {
|
if (!cellText.trim()) {
|
||||||
alert("Header columns do not match expected format:\nExpected: " + JSON.stringify(Object.values(excel_headers[formatType])) + "\nReceived: " + JSON.stringify(rows[0].split("\t")));
|
emptyCellCount++;
|
||||||
$('#submitBtn').prop('disabled', true);
|
|
||||||
$('#excel_table').empty();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var uniqueRows = new Set();
|
|
||||||
var emptyCellCount = 0;
|
|
||||||
|
|
||||||
rows.forEach((rowText, y) => {
|
|
||||||
var cells = rowText.split("\t");
|
|
||||||
|
|
||||||
// Skip empty rows
|
|
||||||
if (cells.every(cell => !cell.trim())) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var row = $('<tr />');
|
|
||||||
cells.forEach(cellText => {
|
|
||||||
row.append('<td>'+cellText+'</td>');
|
|
||||||
if (!cellText.trim()) {
|
|
||||||
emptyCellCount++;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
var key;
|
|
||||||
switch(formatType) {
|
|
||||||
case 1:
|
|
||||||
key = cells[0] + "|" + cells[1] + "|" + cells[2]; // Sum Insured, From Age, To Age
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
key = cells[0] + "|" + cells[1]; // Sum Insured, Grade
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
key = cells[0] + "|" + cells[1] + "|" + cells[2] + "|" + cells[3]; // Sum Insured, Relationship, From Age, To Age
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
key = cells[0]; // Sum Insured
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
key = cells[0] + "|" + cells[1]; // Sum Insured, Grade
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
key = cells.join("|");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (y > 0 && uniqueRows.has(key)) {
|
|
||||||
row.addClass('duplicate');
|
|
||||||
} else {
|
|
||||||
uniqueRows.add(key);
|
|
||||||
}
|
|
||||||
table.append(row);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#submitBtn').prop('disabled', $('.duplicate').length > 0);
|
var key;
|
||||||
|
switch (formatType) {
|
||||||
|
case 3:
|
||||||
|
key = cells[0] + "|" + cells[1] // Sum Insured, Premium
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
key = cells[0] + "|" + cells[1] + "|" + cells[2] + "|" + cells[3]; // Sum Insured, From Age, To Age, Premium
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
key = cells[0] + "|" + cells[1] + "|" + cells[2] + "|" + cells[3]; // Sum Insured, From Age, To Age, Premium
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
key = cells[0] + "|" + cells[1] + "|" + cells[2] + "|" + cells[3]; // Sum Insured, From Age, To Age, Premium
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
key = cells[0] + "|" + cells[1] + "|" + cells[2] + "|" + cells[3]; // Sum Insured, From Age, To Age, Premium
|
||||||
|
break;
|
||||||
|
case 8:
|
||||||
|
key = cells[0] + "|" + cells[1] + "|" + cells[2]; // Sum Insured, Grade, Premium
|
||||||
|
break;
|
||||||
|
case 9:
|
||||||
|
key = cells[0] + "|" + cells[1]; // Sum Insured, Premium
|
||||||
|
break;
|
||||||
|
case 10:
|
||||||
|
key = cells[0] + "|" + cells[1] + "|" + cells[2] + "|" + cells[3]; // Sum Insured, From Age, To Age, Premium
|
||||||
|
break;
|
||||||
|
case 11:
|
||||||
|
key = cells[0] + "|" + cells[1] + "|" + cells[2] + "|" + cells[3]; // Sum Insured, Grade, Premium, Max SI
|
||||||
|
break;
|
||||||
|
case 12:
|
||||||
|
key = cells[0] + "|" + cells[1] + "|" + cells[2]; // Sum Insured, Relationship, Premium
|
||||||
|
break;
|
||||||
|
case 13:
|
||||||
|
key = cells[0] + "|" + cells[1] + "|" + cells[2] + "|" + cells[3] + "|" + cells[4]; // Sum Insured, Relationship, From Age, To Age, Premium
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
key = cells.join("|");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (y > 0 && uniqueRows.has(key)) {
|
||||||
|
row.addClass('duplicate');
|
||||||
|
} else {
|
||||||
|
uniqueRows.add(key);
|
||||||
|
}
|
||||||
|
table.append(row);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (rack_rate_type == 1) {
|
||||||
|
$('#additional_excel_table').empty();
|
||||||
|
$('#additional_excel_table').html(table);
|
||||||
|
} else if (rack_rate_type == 0) {
|
||||||
|
$('#excel_table').empty();
|
||||||
$('#excel_table').html(table);
|
$('#excel_table').html(table);
|
||||||
|
}
|
||||||
|
|
||||||
if ($('.duplicate').length > 0) {
|
if ($('.duplicate').length > 0) {
|
||||||
alert("Duplicate records found.");
|
console.log('test');
|
||||||
|
toastr.warning("Duplicates found!", "warning");
|
||||||
|
$('.excel_table_class').empty();
|
||||||
|
$('.excel_textarea').val('');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (emptyCellCount > 0) {
|
||||||
|
toastr.warning('Number of empty cells: ' + emptyCellCount);
|
||||||
|
$('.excel_table_class').empty();
|
||||||
|
$('.excel_textarea').val('');
|
||||||
|
}
|
||||||
|
submitData(rack_rate_type);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function submitData(rack_rate_type) {
|
||||||
|
|
||||||
|
let formatType = $('#grid').val();
|
||||||
|
var table = $('#excel_table table');
|
||||||
|
var obj = $('#grid');
|
||||||
|
|
||||||
|
if(rack_rate_type == 1){
|
||||||
|
|
||||||
|
formatType = $('#additional_grid').val();
|
||||||
|
table = $('#additional_excel_table table');
|
||||||
|
obj = $('#additional_grid');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var headers = $(table).find('tr').first().find('td').map(function() {
|
||||||
|
return slugify($(this).text());
|
||||||
|
}).get();
|
||||||
|
|
||||||
|
var rows = $(table).find('tr:gt(0)').map(function() {
|
||||||
|
return $(this).find('td').map(function() {
|
||||||
|
return $(this).text();
|
||||||
|
}).get();
|
||||||
|
}).get();
|
||||||
|
|
||||||
|
var jsonData = [];
|
||||||
|
|
||||||
|
$(table).find('tr:gt(0)').each(function(idx) {
|
||||||
|
var row = $(this).find('td').map(function() {
|
||||||
|
return $(this).text();
|
||||||
|
}).get();
|
||||||
|
var rowData = {};
|
||||||
|
row.forEach((cell, colIdx) => {
|
||||||
|
rowData[headers[colIdx]] = cell;
|
||||||
|
});
|
||||||
|
jsonData.push(rowData);
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(jsonData);
|
||||||
|
|
||||||
|
jsonData.forEach(obj => {
|
||||||
|
|
||||||
|
if ('sum_insured' in obj) {
|
||||||
|
obj.si = obj.sum_insured;
|
||||||
|
delete obj.sum_insured;
|
||||||
}
|
}
|
||||||
|
|
||||||
alert('Number of empty cells: ' + emptyCellCount);
|
if ('from_age' in obj) {
|
||||||
submitData();
|
obj.age_from = obj.from_age;
|
||||||
|
delete obj.from_age;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('to_age' in obj) {
|
||||||
|
obj.age_to = obj.to_age;
|
||||||
|
delete obj.to_age;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(jsonData);
|
||||||
|
|
||||||
|
|
||||||
|
if(rack_rate_type == 1){
|
||||||
|
|
||||||
|
$('#additional_grid_content_input').empty()
|
||||||
|
|
||||||
|
if ($('#copyfromexcelforadditional').text() == "Manual entry") {
|
||||||
|
$('#copyfromexcelforadditional').text("Copy from excel")
|
||||||
|
} else {
|
||||||
|
$('#copyfromexcelforadditional').text("Copy from excel");
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#additional_grid_content_input').toggle();
|
||||||
|
$('#additional_grid_content_from_excel').toggle();
|
||||||
|
|
||||||
|
}else{
|
||||||
|
|
||||||
|
$('#grid_content_input').empty()
|
||||||
|
|
||||||
|
if ($('#copyfromexcel').text() == "Manual entry") {
|
||||||
|
$('#copyfromexcel').text("Copy from excel")
|
||||||
|
} else {
|
||||||
|
$('#copyfromexcel').text("Copy from excel");
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#grid_content_input').toggle();
|
||||||
|
$('#grid_content_from_excel').toggle();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function submitData() {
|
$.each(jsonData, function(index, item) {
|
||||||
$('#json_output').empty(); // Clear existing JSON output
|
appendGridtHtml(formatType, rack_rate_type, item)
|
||||||
|
});
|
||||||
|
|
||||||
var table = $('#excel_table table');
|
|
||||||
var headers = $(table).find('tr').first().find('td').map(function() {
|
|
||||||
return slugify($(this).text());
|
|
||||||
}).get();
|
|
||||||
|
|
||||||
var rows = $(table).find('tr:gt(0)').map(function() {
|
$('input[name="11_max_si[]"]').each(function() {
|
||||||
return $(this).find('td').map(function() {
|
$(this).trigger('keyup');
|
||||||
return $(this).text();
|
});
|
||||||
}).get();
|
|
||||||
}).get();
|
|
||||||
|
|
||||||
var jsonData = [];
|
|
||||||
|
|
||||||
$(table).find('tr:gt(0)').each(function(idx) {
|
$(`input[name="${formatType}_si[]"]`).each(function() {
|
||||||
var row = $(this).find('td').map(function() {
|
// console.log($(this));
|
||||||
return $(this).text();
|
$(this).trigger('keyup');
|
||||||
}).get();
|
});
|
||||||
var rowData = {};
|
|
||||||
row.forEach((cell, colIdx) => {
|
|
||||||
rowData[headers[colIdx]] = cell;
|
|
||||||
});
|
|
||||||
jsonData.push(rowData);
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#json_output').text(JSON.stringify(jsonData, null, 2));
|
$(`input[name="${formatType}_premium[]"]`).each(function() {
|
||||||
}
|
// console.log($(this));
|
||||||
</script>
|
$(this).trigger('keyup');
|
||||||
</div>
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
Loading…
Reference in New Issue
Block a user