FEAT_RACK_RATE_EXCEL_UPLOAD
This commit is contained in:
parent
fba9a6e777
commit
a4cf69362a
@ -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';
|
||||
|
||||
|
||||
@ -38,10 +38,13 @@
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<a href="#" id='copyfromexcel'>Copy from excel</a>
|
||||
<hr>
|
||||
|
||||
<div class="form-row" id="grid_content_input">
|
||||
<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>
|
||||
@ -71,6 +74,26 @@ $('.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) {
|
||||
|
||||
|
||||
241
app/Views/policy_grid_excel.php
Normal file
241
app/Views/policy_grid_excel.php
Normal 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>
|
||||
Loading…
Reference in New Issue
Block a user