416 lines
20 KiB
PHP
416 lines
20 KiB
PHP
<style>
|
||
|
||
.reload:hover {
|
||
cursor: pointer;
|
||
}
|
||
|
||
.table th,
|
||
.table td {
|
||
padding: 8px;
|
||
}
|
||
|
||
table.dataTable tbody td {
|
||
padding: 4px 4px !important;
|
||
}
|
||
|
||
.addbtnStyle{
|
||
margin-left: 20px !important;
|
||
}
|
||
|
||
.dataTables_filter {
|
||
position: absolute;
|
||
}
|
||
|
||
.dataTables_length label {height: 21px !important;}
|
||
</style>
|
||
|
||
<div class="col-12">
|
||
<div class="card">
|
||
<div class="card-body">
|
||
<table data-custom-table-css="table" class="table table-hover m-0 table-centered dt-responsive w-100" cellspacing="0" id="tickets-table">
|
||
<thead class="bg-light">
|
||
<tr>
|
||
<th class="font-weight-medium">S.No </th>
|
||
<th class="font-weight-medium">File name</th>
|
||
<th class="font-weight-medium">User/Time</th>
|
||
<th class="font-weight-medium">Status</th>
|
||
<th class="font-weight-medium">Action</th>
|
||
</tr>
|
||
</thead>
|
||
|
||
<tbody class="font-12">
|
||
<?php
|
||
if (isset($bds_dump_file_data)) {
|
||
foreach ($bds_dump_file_data as $key => $file) {
|
||
?>
|
||
|
||
<tr>
|
||
<td class="text-center"><b><?php echo ($key + 1) ?></b></td>
|
||
<td style="overflow: hidden;" class="reload truncate" data-toggle="tooltip" data-placement="top" title="<?php echo $file['file_name'] ?>">
|
||
<?php echo $file['file_name'] ?>
|
||
</td>
|
||
<td><?php echo change_date_format($file['created_at'], 'Y-m-d H:i:s', 'd M Y h:i A') . ' by <strong>' . $file['user_name'] . '</strong>' ?> </td>
|
||
<td>
|
||
<?php if ($file['status'] == "failed") { ?>
|
||
<span> <?= $file['status'] ?> </span>
|
||
<span class='col-xl-3 col-lg-4 col-sm-6'>
|
||
<!-- <a href="<?= base_url('util/bds_dump_excel_error/') . $file['file_id'] ?>" target="_blank" class='fe-alert-circle' data-err="<?= $file['file_id'] ?>"></a> -->
|
||
<a href="#" class='fe-alert-circle' onclick="fetchFileError(<?= $file['file_id'] ?>)"></a>
|
||
</span>
|
||
<?php } else if ($file['status'] == "inprogress") { ?>
|
||
<a data-id="<?= $file['status'] ?>" class="reload" href="#">
|
||
<?= $file['status'] ?>
|
||
</a>
|
||
<?php } else { ?>
|
||
<span> <?= $file['status'] ?> </span>
|
||
<?php } ?>
|
||
</td>
|
||
<td>
|
||
<div class="btn-group dropdown">
|
||
<a href="javascript: void(0);" class="dropdown-toggle arrow-none btn btn-light btn-sm"
|
||
data-toggle="dropdown" aria-expanded="false"><i
|
||
class="mdi mdi-dots-horizontal"></i></a>
|
||
<div class="dropdown-menu dropdown-menu-right">
|
||
<a target="_blank" class="dropdown-item" href="<?= base_url("bds_upload/downloadBDSDumpFile/") . $file['file_id']; ?>"><i class="mdi mdi-download mr-2 text-muted font-18 vertical-middle"></i>Download</a>
|
||
<!-- <a data-id="<?php echo $file['file_id'] ?>" data-toggle="modal" data-target="#full-width-modal-emp-list" class="dropdown-item view_emp_list" href="#"><i class="mdi mdi-eye mr-2 text-muted font-18 vertical-middle"></i>View</a> -->
|
||
</div>
|
||
</div>
|
||
</td>
|
||
</tr>
|
||
<?php }
|
||
} ?>
|
||
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
</div>
|
||
</div><!-- end col -->
|
||
|
||
<!-- Center modal content -->
|
||
<div class="modal fade" id="bds-dump-file-err-modal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static">
|
||
<div class="modal-dialog modal-dialog-centered">
|
||
<div class="modal-content">
|
||
<div class="modal-header">
|
||
<h4 class="modal-title" id="myCenterModalLabel">File Rejected Reason</h4>
|
||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||
</div>
|
||
<div id="modal_body" class="modal-body">
|
||
<div class="spinner-border text-primary" role="status" style="position: relative; left: 200px;"></div>
|
||
</div>
|
||
</div>
|
||
</div><!-- /.modal-dialog -->
|
||
</div><!-- /.modal -->
|
||
|
||
<!-- Center modal content for upload file-->
|
||
<div class="modal fade" id="bds-file-upload-modal" tabindex="-1" role="dialog" aria-hidden="true">
|
||
<div class="modal-dialog modal-dialog-centered">
|
||
<div class="modal-content">
|
||
<div class="modal-header">
|
||
<h4 class="modal-title" id="myCenterModalLabel">BDS Bulk Upload</h4>
|
||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||
</div>
|
||
<div class="modal-body">
|
||
<form class="parsley-examples" id="bds-upload-form" enctype="multipart/form-data">
|
||
<div class="form-group">
|
||
<div class="row">
|
||
<div class="form-group float-right-end offset-8 col-4">
|
||
<span><a href="<?= base_url("util/download-excel/bds_upload"); ?>" id="download_sample_file" style="font-size: small; color:red !important;">Download sample file</a></span>
|
||
</div>
|
||
</div>
|
||
<div class="form-row" id="file_upload">
|
||
<div class="form-group col-md-9">
|
||
<label>Upload file</label>
|
||
<!-- [ <a href="#" id="excel_download" data-toggle="tooltip" data-placement="top" title="Download Sample Excel">Sample Excel</a> ] -->
|
||
<input type="file" name="bds_dump_list" id="bds_dump_list" accept=" application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel,application/vnd.oasis.opendocument.spreadsheet" required>
|
||
</div>
|
||
<div class="form-group col-md-3" style="margin-top: 40px;">
|
||
<button id="bds_form_submit_button" type="submit" class="btn btn-primary waves-effect waves-light justify-content-end">Upload</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
</div><!-- /.modal-content -->
|
||
</div><!-- /.modal-dialog -->
|
||
</div><!-- /.modal -->
|
||
|
||
<script>
|
||
|
||
$(document).ready(function() {
|
||
|
||
// AJAX Form Submit Function
|
||
$('#bds-upload-form').on('submit', function(e) {
|
||
e.preventDefault(); // Prevent default form submission
|
||
|
||
// Get form data
|
||
var formData = new FormData(this);
|
||
var fileInput = $('#bds_dump_list')[0];
|
||
|
||
// Validate file type
|
||
var allowedTypes = [
|
||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||
'application/vnd.ms-excel',
|
||
'application/vnd.oasis.opendocument.spreadsheet'
|
||
];
|
||
|
||
var selectedFile = fileInput.files[0];
|
||
if (!allowedTypes.includes(selectedFile.type)) {
|
||
alert('Please upload a valid Excel file (.xlsx, .xls, .ods)');
|
||
return false;
|
||
}
|
||
|
||
//form submit url;
|
||
let url = `<?php echo base_url('bds_upload/list'); ?>`;
|
||
|
||
// Show loading state
|
||
var submitButton = $('#bds_form_submit_button');
|
||
var originalText = submitButton.text();
|
||
submitButton.prop('disabled', true).text('Uploading...');
|
||
|
||
|
||
// AJAX request
|
||
$.ajax({
|
||
url: url, // Your route URL
|
||
type: 'POST',
|
||
data: formData,
|
||
processData: false, // CRITICAL: Don't process the data
|
||
contentType: false, // CRITICAL: Don't set content-type header
|
||
cache: false,
|
||
success: function(response) {
|
||
|
||
// Handle successful response
|
||
console.log('Upload successful:', response);
|
||
|
||
if (response.status == true) {
|
||
toastr.success(response.message, "Success");
|
||
} else {
|
||
toastr.error(response.message, "Error");
|
||
}
|
||
|
||
// Reset form
|
||
$('#bds-upload-form')[0].reset();
|
||
$('.close').click();
|
||
window.location.reload();
|
||
|
||
},
|
||
error: function(xhr, status, error) {
|
||
// Handle error response
|
||
console.error('Upload failed:', error);
|
||
console.error('Unexpected error:', xhr.responseText);
|
||
if (xhr.status === 400) {
|
||
let response = JSON.parse(xhr.responseText);
|
||
let errorMessages = "";
|
||
let seenMessages = []; // Array to store unique messages
|
||
if (response.errors) {
|
||
$.each(response.errors, function (field, message) {
|
||
if (!seenMessages.includes(message)) {
|
||
errorMessages += `• ${message}<br>`;
|
||
seenMessages.push(message); // Mark this message as "seen"
|
||
}
|
||
});
|
||
toastr.error(errorMessages, 'Validation Error', { "allowHtml": true });
|
||
} else {
|
||
toastr.warning(response.message || 'Validation failed', 'Warning');
|
||
}
|
||
} else if (xhr.status === 403) {
|
||
let response = JSON.parse(xhr.responseText);
|
||
toastr.error(response.message, 'Security Policy');
|
||
} else if (xhr.status === 500) {
|
||
toastr.error('Something went wrong . Please try again later.', 'Server Error');
|
||
} else {
|
||
toastr.error('An unexpected error occurred. Please try again later.', 'Error');
|
||
}
|
||
},
|
||
complete: function() {
|
||
// Reset button state
|
||
submitButton.prop('disabled', false).text(originalText);
|
||
}
|
||
});
|
||
});
|
||
|
||
// File input change event for additional validation
|
||
$('#bds_dump_list').on('change', function() {
|
||
var fileInput = this;
|
||
var file = fileInput.files[0];
|
||
|
||
if (file) {
|
||
// Check file size (optional - set max size as needed, e.g., 10MB)
|
||
var maxSize = 10 * 1024 * 1024; // 10MB in bytes
|
||
if (file.size > maxSize) {
|
||
toastr.warning('File size should not exceed 10MB', 'Warning');
|
||
$(this).val(''); // Clear the input
|
||
return false;
|
||
}
|
||
|
||
// Display selected file name
|
||
var fileName = file.name;
|
||
if ($('#selected-file').length === 0) {
|
||
$('<div id="selected-file" class="mt-2 text-muted"><small>Selected file: <span id="file-name"></span></small></div>')
|
||
.insertAfter('#bds_dump_list');
|
||
}
|
||
$('#file-name').text(fileName);
|
||
}
|
||
});
|
||
|
||
$('body').on('click', '.reload', function() {
|
||
status = this.getAttribute('data-id')
|
||
console.log(status);
|
||
if (status == 'inprogress') {
|
||
window.location.reload(true);
|
||
}
|
||
})
|
||
|
||
});
|
||
|
||
// Datatable document ready
|
||
$(document).ready(function() {
|
||
|
||
var ticketsTable = $('#tickets-table');
|
||
|
||
if (ticketsTable.length) {
|
||
ticketsTable.DataTable({
|
||
scrollX: true,
|
||
// dom: "<'row'<'col-sm-7'f><'col-sm-5 text-right'B>>" + // Filter left, buttons right
|
||
// "<'row'<'col-sm-12'tr>>" +
|
||
// "<'row'<'col-sm-5'i><'col-sm-7'p>>", // Pagination at the bottom, without page length selector
|
||
dom: "<'row'<'col-sm-7'f><'col-sm-5 text-right'B>>" + // Filter left, buttons right
|
||
"<'row'<'col-sm-12'tr>>" +
|
||
"<'row align-items-center'<'col-5 text-start'i><'col-7 d-flex justify-content-end align-items-center'<'me-2'l>p>>",
|
||
lengthMenu: [[10, 20, 50, 100], [10, 20, 50, 100]],
|
||
buttons: [
|
||
{
|
||
text: 'Add',
|
||
className: 'buttons-html5 addbtnStyle',
|
||
action: function (e, dt, node, config) {
|
||
openDumpUploadModal();
|
||
}
|
||
}
|
||
],
|
||
language: {
|
||
search: `
|
||
<div class="datatable-search-wrapper" style="position:relative; display:inline-block;">
|
||
_INPUT_
|
||
<i class="mdi mdi-magnify datatable-search-icon"
|
||
style="position:absolute; right:10px; top:50%; transform:translateY(-50%); color:#666;"></i>
|
||
<i class="mdi mdi-close-circle datatable-clear-icon"
|
||
style="position:absolute; right:10px; top:50%; transform:translateY(-50%); color:#666; display:none;"></i>
|
||
</div>`,
|
||
searchPlaceholder: "Search",
|
||
emptyTable: '<div class="text-center text-muted">No Data found</div>'
|
||
},
|
||
paging: true, // Enable pagination
|
||
pageLength: 15, // Set default number of rows per page (optional)
|
||
});
|
||
} else {
|
||
console.error("Table not found.");
|
||
}
|
||
});
|
||
|
||
function fetchFileError(file_id) {
|
||
|
||
var url = '<?php echo base_url('bds_upload/getBdsDumpFileErrorData/'); ?>';
|
||
let requestData = { file_id: file_id };
|
||
|
||
var myModal = new bootstrap.Modal(document.getElementById('bds-dump-file-err-modal'));
|
||
myModal.show();
|
||
|
||
sendAjaxRequestForGlobal(url, 'GET', requestData, function(response) {
|
||
console.log('Data fetched successfully:', response);
|
||
|
||
$('#modal_body').empty();
|
||
if (response.status === true) {
|
||
|
||
var file_error_data = (JSON.parse(response.data));
|
||
var file_error_html = "";
|
||
|
||
for (var key in file_error_data['error_summary']) {
|
||
var err_id = parseInt(key);
|
||
var err_count = file_error_data['error_summary'][key];
|
||
switch (err_id) {
|
||
case 0:
|
||
file_error_html += "<strong>" + file_error_data['error_data'] + "</strong>";
|
||
break;
|
||
case 1:
|
||
file_error_html += "<strong>Mandatory values missing</strong> <span class='badge badge-danger float-right'>" +
|
||
err_count + "</span><br>";
|
||
break;
|
||
case 2:
|
||
file_error_html += "<strong>Values not in expected format</strong> <span class='badge badge-danger float-right'>" +
|
||
err_count + "</span><br>";
|
||
break;
|
||
case 3:
|
||
file_error_html += "<strong>Field contains not allowed values</strong> <span class='badge badge-danger float-right'>" +
|
||
err_count + "</span><br>";
|
||
break;
|
||
case 4:
|
||
file_error_html += "<strong>Rule Conflict</strong> <span class='badge badge-danger float-right'>" +
|
||
err_count + "</span><br>";
|
||
break;
|
||
case 5:
|
||
file_error_html += "<strong>" + (file_error_data['error_data'] || 'Error data not available') + "</strong>";
|
||
break;
|
||
case 6:
|
||
file_error_html += "<strong>" + (file_error_data['error_data'] || 'Error data not available') + "</strong>";
|
||
break;
|
||
case 7:
|
||
file_error_html += "<strong>Bds already exist</strong> <span class='badge badge-danger float-right'>" +
|
||
err_count + "</span><br>";
|
||
break;
|
||
case 8:
|
||
file_error_html += "<strong>Policy not found</strong> <span class='badge badge-warning float-right'>" +
|
||
err_count + "</span><br>";
|
||
break;
|
||
case 9:
|
||
file_error_html += "<strong>Employee not found</strong> <span class='badge badge-danger float-right'>" +
|
||
err_count + "</span><br>";
|
||
break;
|
||
case 10:
|
||
file_error_html += "<strong>ACM not found</strong> <span class='badge badge-danger float-right'>" +
|
||
err_count + "</span><br>";
|
||
break;
|
||
default:
|
||
file_error_html += "<strong>Unknown error type</strong> <span class='badge badge-secondary float-right'>" +
|
||
err_count + "</span><br>";
|
||
break;
|
||
}
|
||
|
||
}
|
||
if (err_id != 5 && err_id != 6 && err_id != 0) {
|
||
file_error_html += (file_error_html != "" ?
|
||
"<a href ='<?php echo base_url('bds_upload/getBdsDumpExcelFileErrors/') ?>" + file_id +
|
||
"' target=_blank>click here to more details...</a>" : "");
|
||
}
|
||
|
||
// console.log(file_error_html);
|
||
$('#modal_body').append(file_error_html);
|
||
|
||
} else {
|
||
console.log('Response status was false');
|
||
$('#modal_body').append('<div class="alert alert-warning">No error data available.</div>');
|
||
}
|
||
|
||
}, function(xhr, status, error) {
|
||
console.error('Error fetching data:', error);
|
||
console.error('Status:', status);
|
||
console.error('Response:', xhr.responseText);
|
||
|
||
// Show error message to user
|
||
$('#modal_body').empty().append(
|
||
'<div class="alert alert-danger">Failed to fetch error data. Please try again.</div>'
|
||
);
|
||
});
|
||
|
||
}
|
||
|
||
$('.close').click(function(){
|
||
$('#modal_body').empty()
|
||
let html = `<div class="spinner-border text-primary" role="status" style="position: relative; left: 200px;"></div>`
|
||
$('#modal_body').append(html);
|
||
});
|
||
|
||
function openDumpUploadModal() {
|
||
var myModal = new bootstrap.Modal(document.getElementById('bds-file-upload-modal'));
|
||
myModal.show();
|
||
}
|
||
|
||
</script>
|