nhance/app/Views/claim_mis_file_list.php

396 lines
15 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<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;}
.readonly-select { background-color: #f3f3f3 !important; cursor: not-allowed; pointer-events: none; }
</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&nbsp;</th>
<th class="font-weight-medium">File name</th>
<th class="font-weight-medium">User/Time</th>
<th class="font-weight-medium">Action</th>
</tr>
</thead>
<tbody class="font-12">
<?php
if (isset($claim_mis_file_list)) {
foreach ($claim_mis_file_list as $key => $file) {
?>
<tr>
<td class="text-center"><b><?php echo ($key + 1) ?></b></td>
<td class="text-center"><?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>
<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("claim_mis/download?id=") . $file['id']; ?>"><i class="mdi mdi-download mr-2 text-muted font-18 vertical-middle"></i>Download</a>
</div>
</div>
</td>
</tr>
<?php }
} ?>
</tbody>
</table>
</div>
</div>
</div><!-- end col -->
<!-- Center modal content for upload file-->
<div class="modal fade" id="claim-mis-file-upload-modal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="myCenterModalLabel">Cliam MIS File upload</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<form class="parsley-examples" id="claim-mis-upload-form" enctype="multipart/form-data">
<div class="form-group">
<div class="form-row">
<div class="form-group col-md-4">
<label>Client<span id="tpa_danger" class="text-danger">*</span></label>
<select name="client_id" class="form-control" id="client_id" required>
<option value="">Select</option>
</select>
</div>
<div class="form-group col-md-4">
<label>Policy <span id="tpa_danger" class="text-danger">*</span></label>
<select name="client_policy_id" class="form-control" id="client_policy_id" required>
<option value="">Select</option>
</select>
</div>
<div class="form-group col-md-4">
<label for="tpa">TPA<span id="tpa_danger" class="text-danger">*</span></label>
<select class="form-control readonly-select" id="tpa_id" name="tpa_id" required>
<option value="">Select TPA</option>
<?php foreach ($tpa_list as $value) { ?>
<option value="<?= $value['id'] ?>"><?= $value['short_name'] ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-4">
<label>From Date<span id="tpa_danger" class="text-danger">*</span></label>
<input class="form-control" type="text" name="from_date" id="from_date" required>
</div>
<div class="form-group col-md-4">
<label>To Date<span id="tpa_danger" class="text-danger">*</span></label>
<input class="form-control" type="text" name="to_date" id="to_date" required>
</div>
</div>
<div class="form-row" id="file_upload">
<div class="form-group col-md-4">
<label>Upload file</label>
<input type="file" name="file" id="file" accept=".pdf,.xls,.xlsx,application/pdf,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" required>
</div>
<div class="form-group col-md-3" style="margin-top: 40px;margin-left: 170px;">
<button id="claim_mis_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>
let policyListByClient = null;
let client_list = null;
$(document).ready(function() {
getClientAndBranchAndPolicy();
$('#client_id').select2();
$('#client_policy_id').select2();
var from_date = flatpickr("#from_date", {
dateFormat: "d/m/Y",
allowInput: false
});
var to_date = flatpickr("#to_date", {
dateFormat: "d/m/Y",
allowInput: false
});
// AJAX Form Submit Function
$('#claim-mis-upload-form').on('submit', function(e) {
e.preventDefault(); // Prevent default form submission
// Get form data
var formData = new FormData(this);
var fileInput = $('#file')[0];
// Validate file type
var allowedTypes = [
'application/pdf',
'application/vnd.ms-excel',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'application/vnd.oasis.opendocument.spreadsheet'
];
if (!fileInput.files || !fileInput.files.length) {
toastr.warning('Please select a file', 'WARNING');
return false;
}
var selectedFile = fileInput.files[0];
// Some browsers return empty type → fallback to extension
var allowedExtensions = ['pdf', 'xls', 'xlsx', 'ods'];
var fileExtension = selectedFile.name.split('.').pop().toLowerCase();
if (
(!allowedTypes.includes(selectedFile.type)) &&
(!allowedExtensions.includes(fileExtension))
) {
toastr.warning(
'Please upload a valid file (PDF / Excel: .pdf, .xls, .xlsx, .ods)',
'WARNING'
);
return false;
}
//form submit url;
let url = `<?php echo base_url('claim_mis/upload'); ?>`;
// Show loading state
var submitButton = $('#claim_mis_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
$('#claim-mis-upload-form')[0].reset();
$('.close').click();
window.location.reload();
},
error: function(xhr, status, error) {
// Handle error response
console.error('Upload failed:', error);
console.error('Upload failed:', error);
if (xhr.status === 400) {
var response = JSON.parse(xhr.responseText);
toastr.warning(response.message || 'Validation failed', 'Warning');
}
if (xhr.status === 500) {
var response = JSON.parse(xhr.responseText);
toastr.warning(response.message || 'Validation failed', 'Warning');
}
},
complete: function() {
// Reset button state
submitButton.prop('disabled', false).text(originalText);
}
});
});
$('#client_id').on('change', function(){
let client_id = $(this).val();
if(policyListByClient != '') {
console.log(policyListByClient[client_id]);
let data = policyListByClient[client_id];
appendPolicies(data);
}
})
$('#client_policy_id').on('change', function(){
let tpa_id = $(this).find(':selected').data('tpaid');
console.log('tpa_id', tpa_id);
if(tpa_id){
$('#tpa_id').val(tpa_id);
}else{
$('#tpa_id').val('');
}
})
});
// 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 openDumpUploadModal() {
var myModal = new bootstrap.Modal(document.getElementById('claim-mis-file-upload-modal'));
myModal.show();
}
function getClientAndBranchAndPolicy() {
$.ajax({
url: '<?= base_url("/util/getClientAndBranchAndPolicy") ?>',
type: "GET",
dataType: 'json',
success: function(res) {
console.log('getClientAndBranchAndPolicy', res);
if (res.status == true) {
policyListByClient = res.policyListByClient;
client_list = res.client_data;
appendClients(res.client_data);
} else {
console.log('No data found');
}
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
}
});
}
function appendClients(data) {
$('#client_id').empty();
$('#client_id').append($('<option>', {
value: '',
text: 'Select Client'
}));
$.each(data, function(index, item) {
if (item.client_policy_count > 0) {
var option = $('<option>', {
value: item.id,
text: item.client_name
});
$('#client_id').append(option);
}
});
}
function appendPolicies(data) {
$('#client_policy_id').empty();
$('#client_policy_id').append($('<option>', {
value: '',
text: 'Select Policy',
}));
$.each(data, function(index, item) {
var option = $('<option>', {
value: item.id,
text: item.policy_type + '-' + item.policy_no,
'data-tpaid': item.id,
});
$('#client_policy_id').append(option);
});
}
</script>