MERGE_POLICY_GIRD_PHP_FILE : RV

This commit is contained in:
VENKATESHWARAN 2024-05-28 12:22:37 +05:30
commit 0df9ea4398
3 changed files with 317 additions and 48 deletions

View File

@ -1119,10 +1119,11 @@ class EmployeeServiceController extends AdminController
public function getFileMetaDataByFileId($file_id, $status = 'success'){
$data = $this->fileModel
->select('files.*, clients.client_name, clients.short_name, policies.name as policy_name')
->select('files.*, clients.client_name, clients.short_name, policies.name as policy_name,client_branch.branch_code')
->join('clients', 'clients.id = files.client_id')
->join('client_policy', 'client_policy.id = files.policy_id')
->join('policies', 'policies.id = client_policy.policy_id')
->join('client_branch', 'client_branch.id = files.client_branch_id')
->where('files.id', $file_id)
->first();
@ -1135,7 +1136,7 @@ class EmployeeServiceController extends AdminController
$msg_title = 'File Upload Failure';
}
$msg_txt = $data['client_name'] . ' - ' . $data['policy_name'] . ' - ' . ucfirst($data['action']);
$msg_txt = $data['client_name'] . ' ('.$data['branch_code'].') - ' . $data['policy_name'] . ' - ' . ucfirst($data['action']);
$user_id = $data['created_by'];
$url = 'employee/upload';

View File

@ -9,7 +9,7 @@
</div>
<div class="modal-body">
<input type="hidden" id="policy_terms_count">
<input type="hidden" id="policy_terms_count">
<div class="text-center" id="no_data"></div>
@ -65,11 +65,16 @@
Insurance </label>
</div>
</div>
</div>
<a href="#" id='copyfromexcel'>Copy from excel</a>
<hr>
<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>
@ -88,7 +93,8 @@
<form role="form" class="parsley-examples" method="post" id="AdditionalGridForm"
enctype="multipart/form-data">
<input type="hidden" value="<?= csrf_hash() ?>" name="<?= csrf_token() ?>" />
<input type="hidden" name="client_id" id="Client_id" value="<?= isset($client['id']) ? $client['id'] : '' ?>" />
<input type="hidden" name="client_id" id="Client_id"
value="<?= isset($client['id']) ? $client['id'] : '' ?>" />
<input type="hidden" name="client_policy_id" id="client_policy_id_2" />
<input type="hidden" name="rack_rate_type" id="rack_rate_type" value="1" />
<div class="form-group">
@ -97,13 +103,14 @@
<div class="form-group col-md-6">
<label for="emp_code">Policy Premium Type<span
class="text-danger">*</span></label>
<select data-secondary="1" class="form-control" id="additional_grid" name="policy_grid_id"
onchange="addGridHTML(event)" required>
<select data-secondary="1" class="form-control" id="additional_grid"
name="policy_grid_id" onchange="addGridHTML(event)" required>
</select>
</div>
<div class="form-group col-md-4"
style="position: relative; left: 45px; display:none" id="additional_rack_rate_premium_type">
style="position: relative; left: 45px; display:none"
id="additional_rack_rate_premium_type">
<label for="css"> Premium Calculation </label>
<div style="display: flex; align-items: center;">
<input type="radio" id="individual_2" name="premium_type" value="2">
@ -158,6 +165,24 @@ $('.close').click(function() {
}
});
$('#copyfromexcel').click(function() {
// alert('called');
// $('#copyfromexcel').toggle();
// $("#copied_excel_data").val(result.exampleMessage);
$('#copied_excel_data').val("");
if ($(this).text() == "Copy from excel") {
$(this).text("Manual entry")
} else {
$(this).text("Copy from excel");
}
$('#grid_content_input').toggle();
$('#grid_content_from_excel').toggle();
});
function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = false, rr_type = false) {
@ -166,7 +191,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa
console.log('secondaryValue', secondaryValue)
console.log(rr_type);
if(!secondaryValue){
if (!secondaryValue) {
secondaryValue = rr_type
}
@ -200,7 +225,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa
if (dataIdValue == '1') {
for (var i = 1; i <= 13; i++) {
$('#'+id_var+ i).remove();
$('#' + id_var + i).remove();
}
grid_html = `
@ -322,7 +347,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa
} else if (dataIdValue == '2') {
for (var i = 1; i <= 13; i++) {
$('#'+id_var + i).remove();
$('#' + id_var + i).remove();
}
grid_html = `
@ -344,7 +369,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa
for (var i = 1; i <= 13; i++) {
$('#'+id_var+ i).remove();
$('#' + id_var + i).remove();
}
grid_html = `
@ -369,7 +394,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa
for (var i = 1; i <= 13; i++) {
$('#'+id_var+ i).remove();
$('#' + id_var + i).remove();
}
grid_html = `
<div class="form-row" id="${id_var}4" style="width:84%">
@ -403,7 +428,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa
for (var i = 1; i <= 13; i++) {
$('#'+id_var+ i).remove();
$('#' + id_var + i).remove();
}
grid_html = `
@ -436,7 +461,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa
for (var i = 1; i <= 13; i++) {
$('#'+id_var+ i).remove();
$('#' + id_var + i).remove();
}
grid_html = `
@ -471,7 +496,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa
for (var i = 1; i <= 13; i++) {
$('#'+id_var+ i).remove();
$('#' + id_var + i).remove();
}
grid_html = `
@ -504,7 +529,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa
for (var i = 1; i <= 13; i++) {
$('#'+id_var+ i).remove();
$('#' + id_var + i).remove();
}
@ -534,7 +559,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa
} else if (dataIdValue == '9') {
for (var i = 1; i <= 13; i++) {
$('#'+id_var+ i).remove();
$('#' + id_var + i).remove();
}
grid_html = `
@ -556,7 +581,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa
for (var i = 1; i <= 13; i++) {
$('#'+id_var+ i).remove();
$('#' + id_var + i).remove();
}
grid_html = `
@ -588,7 +613,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa
} else if (dataIdValue == '11') {
for (var i = 1; i <= 13; i++) {
$('#'+id_var+ i).remove();
$('#' + id_var + i).remove();
}
grid_html = `
@ -622,7 +647,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa
} else if (dataIdValue == '12') {
for (var i = 1; i <= 13; i++) {
$('#'+id_var+ i).remove();
$('#' + id_var + i).remove();
}
grid_html = `
@ -660,7 +685,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa
} else if (dataIdValue == '13') {
for (var i = 1; i <= 13; i++) {
$('#'+id_var+ i).remove();
$('#' + id_var + i).remove();
}
grid_html = `
@ -705,7 +730,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa
} else {
for (var i = 1; i <= 13; i++) {
$('#'+id_var+ i).remove();
$('#' + id_var + i).remove();
}
grid_html = '';
$('#btnGridSubmit').hide();
@ -782,7 +807,8 @@ $("#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();
@ -847,7 +873,9 @@ $("#AdditionalGridForm").submit(function(event) {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
var message = (policy_PrimaryKey === '') ? 'Policy Additional Rack Rate Added successfully' : 'Policy Additional Rack Rate Added Successfully';
var message = (policy_PrimaryKey === '') ?
'Policy Additional Rack Rate Added successfully' :
'Policy Additional Rack Rate Added Successfully';
toastr.success(message, 'Success');
$('.close').click();
@ -886,13 +914,13 @@ $('body').on('click', '.btnPolicyModel', function() {
$('.loader-mask').fadeIn();
if(policy_type_string == 'GPA'){
$('#rack_rate_one').hide()
$('#rack_rate_two').hide()
$('#AdditionalGridForm').hide()
$('#additional_rack_rate_premium_type').hide()
if (policy_type_string == 'GPA') {
$('#rack_rate_one').hide()
$('#rack_rate_two').hide()
$('#AdditionalGridForm').hide()
$('#additional_rack_rate_premium_type').hide()
}else{
} else {
$('#rack_rate_one').show()
$('#rack_rate_two').show()
$('#AdditionalGridForm').show()
@ -909,10 +937,11 @@ $('body').on('click', '.btnPolicyModel', function() {
dataType: 'json',
success: function(res) {
if(res.self == ""){
if (res.self == "") {
$('.close').click();
toastr.warning('Unable to create rack rate due to the absence of policy terms.', 'Warning');
}
toastr.warning('Unable to create rack rate due to the absence of policy terms.',
'Warning');
}
$('#GridForm')[0].reset();
$('#AdditionalGridForm')[0].reset();
@ -1023,10 +1052,12 @@ $('body').on('click', '.btnPolicyModel', function() {
var policeGridOptionHTMLforSecondary = '';
policeGridOptionHTMLforSecondary += ` <option value="">Select Premium Type</option>`;
policeGridOptionHTMLforSecondary +=
` <option value="">Select Premium Type</option>`;
$.each(res.data, function(index, item) {
policeGridOptionHTMLforSecondary += '<option data-id="' + item.ui_type +
'" value="' + item.id + '" ' + (secondary_policy_grid_id_value === item.id ?
'" value="' + item.id + '" ' + (secondary_policy_grid_id_value ===
item.id ?
'selected="selected"' : '') + '>' + item.policy_grid_type +
'</option>';
});
@ -1062,7 +1093,7 @@ $('body').on('click', '.btnPolicyModel', function() {
res.premiumData.shift();
$.each(res.premiumData, function(index, item) {
if (item.si_or_bp == '1') {
appendGridtHtml('1', item.rack_rate_type, item);
} else {
@ -1368,7 +1399,7 @@ function appendGridtHtml(ui_type = false, secondary = 0, data = false) {
Count++;
var container = document.getElementById('grid_content_input');
if(secondary == 1){
if (secondary == 1) {
container = document.getElementById('additional_grid_content_input')
}
@ -1795,12 +1826,12 @@ function checkDuplicate(val) {
$('#additional_grid_content_input');
$('#grid_content_input')
var id = $('#additional_grid')[0];
var container = $('#additional_grid_content_input');
if(val == 0){
id = $('#grid')[0];
container = $('#grid_content_input');
if (val == 0) {
id = $('#grid')[0];
container = $('#grid_content_input');
}
console.log(id);
@ -2533,10 +2564,6 @@ function createCheckboxes(obj, additional_relationship) {
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(' ');
}
</script>

View File

@ -0,0 +1,241 @@
<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>
<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>
<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() {
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);
});
}
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));
if (!excel_headers[formatType]) {
alert("Unknown format type. Please check the header columns.");
$('#submitBtn').prop('disabled', true);
$('#excel_table').empty();
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;
}
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);
$('#excel_table').html(table);
if ($('.duplicate').length > 0) {
alert("Duplicate records found.");
}
alert('Number of empty cells: ' + emptyCellCount);
submitData();
}
function submitData() {
$('#json_output').empty(); // Clear existing JSON output
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();
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);
});
$('#json_output').text(JSON.stringify(jsonData, null, 2));
}
</script>
</div>