FEAT_COPY_PASTE_EXCEL_TO_RACK_RATE_DATA_COMPLETE : RV

This commit is contained in:
VENKATESHWARAN 2024-05-29 11:46:55 +05:30
parent 0df9ea4398
commit 65987607c5
3 changed files with 501 additions and 262 deletions

View File

@ -1165,21 +1165,24 @@ class ClientController extends AdminController
$self = $policy_terms_data->family_floaters;
}
$emp_count = $this->employeeModel->join('client_policy cp', "employees.client_id = cp.client_id")
->join('employee_polices ep', "cp.id = ep.client_policy_id AND employees.id = ep.employee_id")
->where("employees.client_id", $record['client_id'])
->where("employees.emp_status", 'active')
->where("ep.status", 'active')
->where("employees.is_active", 1)
->where("ep.is_active", 1)
// $emp_count = $this->employeeModel
// ->join('client_policy cp', "employees.client_id = cp.client_id")
// ->join('employee_polices ep', "cp.id = ep.client_policy_id AND employees.id = ep.employee_id")
// ->where("employees.client_id", $record['client_id'])
// ->where("employees.emp_status", 'active')
// ->where("ep.status", 'active')
// ->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();
// $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);
// if($emp_count == 0){
@ -1289,14 +1292,14 @@ class ClientController extends AdminController
// print_r($premium1);
// 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') {
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 {
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);
}
}

View File

@ -1,3 +1,5 @@
<?php include('policy_grid_excel.php')?>
<!-- Modal content for the Large example -->
<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">
@ -71,11 +73,15 @@
<div class="form-row" id="grid_content_input" style="display: true;">
</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>
@ -121,16 +127,25 @@
Insurance </label>
</div>
</div>
</div>
<div class="form-row" id="relationship">
</div>
</div> <br>
<a href="#" id='copyfromexcelforadditional'>Copy from excel</a>
<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>
@ -158,6 +173,26 @@ $('#btnGridSubmit').hide();
$('.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++) {
$('#grid_' + i).remove();
$('#add_grid_' + i).remove();
@ -166,6 +201,7 @@ $('.close').click(function() {
});
$('#copyfromexcel').click(function() {
// alert('called');
// $('#copyfromexcel').toggle();
// $("#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) {
@ -807,8 +859,7 @@ $("#GridForm").submit(function(event) {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
var message = (policy_PrimaryKey === '') ? 'Policy Premium Added successfully' :
'Policy Premium Added Successfully';
var message = (policy_PrimaryKey === '') ? 'Policy Premium Added successfully' :'Policy Premium Added Successfully';
toastr.success(message, 'Success');
// $('.close').click();
@ -829,7 +880,6 @@ $("#GridForm").submit(function(event) {
$("#AdditionalGridForm").submit(function(event) {
var check = checkDuplicate(1);
event.preventDefault();
if ($('#grid_emp_count').val() == 'false') {
@ -966,18 +1016,21 @@ $('body').on('click', '.btnPolicyModel', function() {
res.premiumData = JSON.parse(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);
if (res.count > 0) {
$("#hide_smbt_btn").hide();
$("#secondary_rack_rate_btn_grp").hide();
} else {
$("#hide_smbt_btn").show();
$("#secondary_rack_rate_btn_grp").show();
}
if (res.status === false) {
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('secondary_policy_grid_id_value', secondary_policy_grid_id_value);
$('#grid_content_input').empty();
var policeGridOptionHTML = '';
policeGridOptionHTML += ` <option value="">Select Premium Type</option>`;
@ -1050,7 +1101,7 @@ $('body').on('click', '.btnPolicyModel', function() {
});
$('#additional_grid_content_input').empty();
var policeGridOptionHTMLforSecondary = '';
policeGridOptionHTMLforSecondary +=
` <option value="">Select Premium Type</option>`;
@ -1129,7 +1180,12 @@ $('body').on('click', '.btnPolicyModel', function() {
$(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() {
// console.log($(this));
$(this).trigger('keyup');
@ -1167,6 +1223,8 @@ $('body').on('click', '.btnPolicyModel', function() {
$('#grid').change(function() {
$('.excel_textarea').val('');
var grid_id = $(this)[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').val(si_or_bp_value);
}
@ -1277,6 +1334,8 @@ $('#grid').change(function() {
$('#additional_grid').change(function() {
$('.excel_textarea').val('');
var grid_id = $(this)[0].value;
var client_policy_id = $('#client_policy_id')[0].value;
@ -1302,9 +1361,9 @@ $('#additional_grid').change(function() {
if (res.count > 0) {
// console.log(' hide submit btn count ', res.count);
$("#hide_smbt_btn").hide();
$("#secondary_rack_rate_btn_grp").hide();
} else {
$("#hide_smbt_btn").show();
$("#secondary_rack_rate_btn_grp").show();
// console.log('show submit btn count ', res.count);
}
@ -1315,9 +1374,9 @@ $('#additional_grid').change(function() {
if (res.count > 0) {
// console.log(' hide submit btn count ', res.count);
$("#hide_smbt_btn").hide();
$("#secondary_rack_rate_btn_grp").hide();
} else {
$("#hide_smbt_btn").show();
$("#secondary_rack_rate_btn_grp").show();
// 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;
}
$('#grid_content_input').empty();
$('#additional_grid_content_input').empty();
var policeGridOptionHTML = '';
policeGridOptionHTML += ` <option value="">Select Premium Type</option>`;
$.each(res.data, function(index, item) {
@ -1341,7 +1400,9 @@ $('#additional_grid').change(function() {
'selected="selected"' : '') + '>' + item.policy_grid_type +
'</option>';
});
// $('#grid').html(policeGridOptionHTML);
var si_or_bp_value = '';
if (res.premiumData && res.premiumData.length > 0) {
@ -2530,12 +2591,16 @@ function getCurrentTime() {
function createCheckboxes(obj, additional_relationship) {
console.log('createCheckboxes function called');
console.log(additional_relationship)
additional_relationship = JSON.parse(additional_relationship);
console.log(additional_relationship)
console.log(additional_relationship);
try {
additional_relationship = JSON.parse(additional_relationship);
console.log(additional_relationship);
} catch (error) {
console.error("Error parsing additional_relationship:", error);
return;
}
$('#relationship').empty();
const $relationshipElement = $('#relationship');
@ -2545,24 +2610,24 @@ function createCheckboxes(obj, additional_relationship) {
const multiplier = 7; // Adjust this value as needed
$.each(obj, function(key, value) {
if (value > 0 && key != 'either-parents-pil') {
const isChecked = additional_relationship && typeof additional_relationship === 'object' && additional_relationship[key] == 1 ? 'checked' : '';
key = formatString(key);
const isChecked = additional_relationship && additional_relationship[key] === 1 ? 'checked' : '';
console.log('isChecked', isChecked);
html += `
<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>
</div>`;
// console.log(html);
}
});
$relationshipElement.append(html);
}
function formatString(str) {
return str.split('-').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join(' ');
}

View File

@ -1,241 +1,412 @@
<style>
table {
border-collapse: collapse;
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>
table {
border-collapse: collapse;
width: 100%;
}
<div>
<!-- <div> -->
<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>
td,
th {
padding: 0.2rem;
}
<script>
const formatType = 0; // Specify the format type here
const excel_headers = {
3: {
"sum_insured": "Sum Insured",
"premium": "Premium"
},
4: {
"sum_insured": "Sum Insured",
"from_age": "From Age",
"to_age": "To Age",
"premium": "Premium"
},
5: {
"sum_insured": "Sum Insured",
"from_age": "From Age",
"to_age": "To Age",
"premium": "Premium"
},
6: {
"sum_insured": "Sum Insured",
"from_age": "From Age",
"to_age": "To Age",
"premium": "Premium"
},
7: {
"sum_insured": "Sum Insured",
"from_age": "From Age",
"to_age": "To Age",
"premium": "Premium"
},
8: {
"sum_insured": "Sum Insured",
"grade": "Grade",
"premium": "Premium"
},
9:
{
"sum_insured": "Sum Insured",
"premium": "Premium"
},
10: {
"sum_insured": "Sum Insured",
"from_age": "From Age",
"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"
.error {
background-color: #f8d7da;
}
.duplicate {
background-color: #fff3cd;
}
.container {
margin-top: 20px;
}
.compact-table td,
.compact-table th {
padding: 0.1rem;
}
</style>
<script>
const formatType = 0; // Specify the format type here
const excel_headers = {
3: {
"sum_insured": "Sum Insured",
"premium": "Premium"
},
4: {
"sum_insured": "Sum Insured",
"from_age": "From Age",
"to_age": "To Age",
"premium": "Premium"
},
5: {
"sum_insured": "Sum Insured",
"from_age": "From Age",
"to_age": "To Age",
"premium": "Premium"
},
6: {
"sum_insured": "Sum Insured",
"from_age": "From Age",
"to_age": "To Age",
"premium": "Premium"
},
7: {
"sum_insured": "Sum Insured",
"from_age": "From Age",
"to_age": "To Age",
"premium": "Premium"
},
8: {
"sum_insured": "Sum Insured",
"grade": "Grade",
"premium": "Premium"
},
9: {
"sum_insured": "Sum Insured",
"premium": "Premium"
},
10: {
"sum_insured": "Sum Insured",
"from_age": "From Age",
"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() {
const headerString = Object.values(excel_headers[formatType]).join("\t"); // Using specified format type for copying headers
navigator.clipboard.writeText(headerString).then(function() {
alert('Headers copied to clipboard');
}, function(err) {
alert('Could not copy headers: ', err);
// Filter header based on columns to keep
header = columnsToKeep.map(i => slugify(header[i]));
if (!excel_headers[formatType]) {
toastr.warning("Unknown format type. Please check the header columns.", 'Warning');
$('.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 data = $('#copied_excel_data').val();
const formatType = $('#grid').val();
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));
var table = $('<table class="table table-striped compact-table" />');
var uniqueRows = new Set();
var emptyCellCount = 0;
if (!excel_headers[formatType]) {
alert("Unknown format type. Please check the header columns.");
$('#submitBtn').prop('disabled', true);
$('#excel_table').empty();
rows.forEach((rowText, y) => {
var cells = rowText.split("\t").filter((_, i) => columnsToKeep.includes(i));
var row = $('<tr />');
// Skip empty rows after filtering columns
if (cells.every(cell => !cell.trim())) {
return;
}
var expectedHeader = Object.keys(excel_headers[formatType]);
if (JSON.stringify(header) !== JSON.stringify(expectedHeader)) {
alert("Header columns do not match expected format:\nExpected: " + JSON.stringify(Object.values(excel_headers[formatType])) + "\nReceived: " + JSON.stringify(rows[0].split("\t")));
$('#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;
cells.forEach(cellText => {
row.append('<td>' + cellText + '</td>');
if (!cellText.trim()) {
emptyCellCount++;
}
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);
}
if ($('.duplicate').length > 0) {
alert("Duplicate records found.");
if ($('.duplicate').length > 0) {
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);
submitData();
if ('from_age' in obj) {
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() {
$('#json_output').empty(); // Clear existing JSON output
$.each(jsonData, function(index, item) {
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() {
return $(this).find('td').map(function() {
return $(this).text();
}).get();
}).get();
$('input[name="11_max_si[]"]').each(function() {
$(this).trigger('keyup');
});
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);
});
$(`input[name="${formatType}_si[]"]`).each(function() {
// console.log($(this));
$(this).trigger('keyup');
});
$('#json_output').text(JSON.stringify(jsonData, null, 2));
}
</script>
</div>
$(`input[name="${formatType}_premium[]"]`).each(function() {
// console.log($(this));
$(this).trigger('keyup');
});
}
</script>