nhance/app/Views/commission_file_upload.php
2026-02-09 12:57:17 +05:30

695 lines
28 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>
.table td,
.table th {
padding: 3px 8px !important;
vertical-align: middle;
line-height: 1.2;
}
table.dataTable tbody td {
padding: 4px 4px !important;
}
.highlight {
border: 2px solid red;
background-color: #ffe6e6;
}
.column-header {
margin-right: 10px;
/* Adjust this value as needed */
}
.form-section {
border: 1px solid #ccc;
padding: 15px;
margin-bottom: 20px;
}
.row-box {
border: 1px solid #ccc;
padding: 10px;
margin-bottom: 10px;
}
table[data-custom-table-css="table"] tbody tr td {
padding: 1px 10px !important;
line-height: 12px;
min-height: 40px;
vertical-align: middle;
}
.reload:hover {
cursor: pointer;
}
.swal-append-btn {
background-color: #007bff !important; /* Blue */
color: #fff !important;
border: none !important;
box-shadow: none !important;
}
</style>
<style>
.switch {
position: relative;
display: inline-block;
width: 54px;
height: 34px;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
-webkit-transition: .4s;
transition: .4s;
}
.slider:before {
position: absolute;
content: "";
height: 19px;
width: 19px;
left: 4px;
bottom: 4px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
}
input:checked+.slider {
background-color: #2196F3;
}
input:focus+.slider {
box-shadow: 0 0 1px #2196F3;
}
input:checked+.slider:before {
-webkit-transform: translateX(26px);
-ms-transform: translateX(26px);
transform: translateX(26px);
}
/* Rounded sliders */
.slider.round {
border-radius: 34px;
}
.slider.round:before {
border-radius: 50%;
}
.disabled-option {
color: gray;
}
.custom-dropdown-menu {
display: none;
position: absolute;
background-color: #ffffff !important;
border: 1px solid rgba(0, 0, 0, 0.15);
border-radius: 0.25rem;
padding: 0.5rem 0;
min-width: 10rem;
z-index: 9999;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.custom-dropdown-menu .dropdown-item {
display: block !important;
width: 100% !important;
padding: 0.5rem 1rem !important;
color: #212529 !important;
text-decoration: none !important;
background-color: transparent !important;
}
.custom-dropdown-menu .dropdown-item:hover {
background-color: #f8f9fa !important;
color: #16181b !important;
cursor: pointer !important;
}
.dataTables_length label {height: 21px !important;}
</style>
<div class="row" id="inception_list">
<div class="col-12">
<div class="card">
<div class="card-body">
<div>
<div class="table-responsive">
<table data-custom-table-css="table" class="table table-striped mb-0 nowrap" cellspacing="0" id="tickets-table">
<thead class="bg-light">
<tr>
<th><div class="column-header">S.No.</div></th>
<th><div class="column-header">File Name</div></th>
<th><div class="column-header">Insurer</div></th>
<th><div class="column-header">Commission <br> Month</div></th>
<th><div class="column-header">Department</div></th>
<th><div class="column-header">Rules <br> Count</div></th>
<th><div class="column-header">status</div></th>
<th><div class="column-header">User/Time</div></th>
<th><div class="column-header">Action</div></th>
</tr>
</thead>
<tbody>
<?php if (isset($commission_file_list)) : ?>
<?php foreach ($commission_file_list as $index => $row) { ?>
<tr>
<td class="text-center"><?= $index+1 ?></td>
<td style="overflow: hidden;" class="reload truncate" data-toggle="tooltip" data-placement="top" title="<?php echo $row['file_name'] ?>">
<?php echo $row['file_name'] ?>
</td>
<td><?php echo $row['insurer_name'] ?> </td>
<td><?php echo change_date_format($row['commission_month'], 'Y-m-d', 'M-Y'); ?></td>
<td><?php echo ucfirst($row['department']) ?> </td>
<td><?php echo $row['rules_count'] ?></td>
<td><?php echo ucfirst($row['file_status']) ?> </td>
<td><?php echo change_date_format($row['created_at'],'Y-m-d H:i:s', 'd M Y h:i A') . ' by <strong>' . $row['created_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">
<?php if($row['file_status'] == "failed") : ?>
<a href="<?= base_url('commission/downloadErrorFile?file_id=') . $row['id'] ?>" class="dropdown-item" target="_blank"><i class="mdi mdi-download mr-2 text-muted font-18 vertical-middle"></i>Download Error File</a>
<?php endif; ?>
<?php if($row['file_status'] == "success") : ?>
<a href="<?= base_url('commission/rules/list/') . $row['id'] ?>" class="dropdown-item" target="_blank"><i class="mdi mdi-eye mr-2 text-muted font-18 vertical-middle"></i>View Rules</a>
<?php endif; ?>
<a class="dropdown-item btnEdit" data-id="<?= $row['id']; ?>" onclick="deleteCommissionData(<?= $row['id']; ?>)">
<i class="mdi mdi-delete mr-2 text-muted font-18 vertical-middle"></i>Delete
</a>
</div>
</div>
</td>
</tr>
<?php } ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="modal fade" id="file_upload" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="title">Commission File Upload</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body p-4">
<div class="">
<form role="form" class="parsley-examples" method="post" id="commission_upload_form" enctype="multipart/form-data" action="upload">
<div class="form-group">
<div class="row">
<div class="form-group float-right-end offset-8 col-4">
<span><a href="sample_file" id="download_sample_file" style="font-size: small; color:red !important;">Download sample file</a></span>
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label for="insurer"> Insurer <spanclass="text-danger">*</spanclass=></label>
<select class="form-control" id="insurer_id" name="insurer_id" onchange="checkSameEntry(this)" required>
<option value="" selected>Select Insurer</option>
<?php
if (isset($insurers) && count($insurers)) {
foreach ($insurers as $key => $value) {
echo "<option value=" . $value['id'] . ">" . $value['short_name'] . "</option>";
}
}
?>
</select>
</div>
<div class="form-group col-md-6">
<label for="statement_month">Commission Month</label>
<input type="text" class="form-control" id="commission_month" name="commission_month" onchange="checkSameEntry(this)" placeholder="" required readonly>
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label for="statement_no">Department</label>
<select class="form-control" id="department" name="department" onchange="checkSameEntry(this)" required>
<option value="" selected>Select Department</option>
<?php
if (isset($departments) && count($departments)) {
foreach ($departments as $key => $value) {
echo "<option value=" . $key . ">" . $value . "</option>";
}
}
?>
</select>
</div>
<div class="form-group col-md-6">
<label for="statment">File</label>
<div class="input-icon">
<input type="file" class="form-control" name="rules_file" required accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,
application/vnd.ms-excel,
application/vnd.oasis.opendocument.spreadsheet,
text/csv"
>
<i class="mdi mdi-upload additional-icon"></i>
</div>
</div>
</div>
</div>
<div class="form-group text-right m-b-0">
<button type="button" class="btn app-btn-outline-secondary mr-2" data-dismiss="modal" aria-hidden="true">Cancel</button>
<button type="submit" class="btn btn-primary waves-effect waves-light mr-1" id="btnSubmit">Submit</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<script>
let isDublicateFound = false;
// document.addEventListener("DOMContentLoaded", function() {
// const table = document.getElementById("tickets-table");
// // Create custom dropdown
// function createCustomDropdown(row) {
// const originalDropdown = row.querySelector('.dropdown-menu');
// console.log('originalDropdown', originalDropdown)
// if (!originalDropdown) return null;
// const customDropdown = document.createElement('div');
// customDropdown.className = 'custom-dropdown-menu';
// customDropdown.innerHTML = originalDropdown.innerHTML;
// // Remove inline onclick handlers and store them in data attributes
// const originalItems = originalDropdown.querySelectorAll('.dropdown-item');
// customDropdown.querySelectorAll('.dropdown-item').forEach((item, index) => {
// const originalOnclick = originalItems[index].getAttribute('onclick');
// item.removeAttribute('onclick'); // Remove the inline handler
// item.setAttribute('data-onclick', originalOnclick); // Store in data attribute
// });
// return customDropdown;
// }
// let activeDropdown = null;
// // Add click event listener to rows
// table.querySelectorAll("tbody tr").forEach(row => {
// const customDropdown = createCustomDropdown(row);
// if (!customDropdown) return;
// document.body.appendChild(customDropdown);
// row.addEventListener("click", function(event) {
// // Ignore clicks on the first column
// if (event.target.closest('td:first-child')) return;
// if (activeDropdown) activeDropdown.style.display = 'none';
// const rect = event.target.getBoundingClientRect();
// customDropdown.style.display = 'block';
// customDropdown.style.position = 'fixed';
// customDropdown.style.left = `${rect.left}px`;
// customDropdown.style.top = `${rect.bottom + 5}px`;
// activeDropdown = customDropdown;
// event.stopPropagation();
// });
// // Handle custom dropdown clicks
// customDropdown.querySelectorAll('.dropdown-item').forEach(item => {
// item.addEventListener('click', function(e) {
// e.preventDefault();
// // Execute the original onclick from data attribute
// const onclickAttr = this.getAttribute('data-onclick');
// if (onclickAttr) eval(onclickAttr);
// // Handle href navigation
// const href = this.getAttribute('href');
// if (href && href !== '#') window.location.href = href;
// if (activeDropdown) {
// activeDropdown.style.display = 'none';
// activeDropdown = null;
// }
// e.stopPropagation();
// });
// });
// });
// // Close dropdown on outside click
// document.addEventListener("click", function() {
// if (activeDropdown) {
// activeDropdown.style.display = 'none';
// activeDropdown = null;
// }
// });
// });
//datatable
$(document).ready(function() {
table = $('#tickets-table').DataTable({
scrollX: true,
// dom: "<'row'<'col-12 d-flex justify-content-between align-items-center'<'datatable-search dataTables_filter'f><'datatable-buttons dt-buttons'B>>>" +
// "<'row'<'col-sm-12'tr>>" +
// "<'row'<'col-sm-5'i><'col-sm-7'p>>",
dom: "<'row'<'col-12 d-flex justify-content-between align-items-center'<'datatable-search dataTables_filter'f><'datatable-buttons dt-buttons'B>>>" +
"<'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: 'Upload <i class="mdi mdi-upload"></i>',
className: 'btn app-btn-primary mr-2', // custom class
action: function(e, dt, node, config) {
showFileUploadModal();
}
},
{
extend: 'collection',
text: '<span class=" btn-custom"> Export </span><i class="mdi mdi-menu-down"></i>',
className: 'btn app-btn-secondary ',
buttons: [
{
extend: 'csv',
text: '<i class="mdi mdi-file-delimited " ></i><span class=" btn-custom"> CSV </span>',
title: 'List',
className: 'app-btn-primary ',
exportOptions: {
columns: ':not(:last-child)'
},
},
{
extend: 'excel',
title: 'List',
text: '<i class="mdi mdi-file-excel " ></i><span class=" btn-custom"> EXCEL </span>',
className: 'app-btn-primary ',
exportOptions: {
columns: ':not(:last-child)'
},
}
]
}
],
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,
// pagingType: 'full_numbers'
});
$(".datatable-buttons").prepend(`
<span id="statusSwitchWrapper" class="dt-switch-wrapper" style="margin-right: 20px !important;">
<span class="custom-switch" style="text-align: left;">
<input type="checkbox" class="custom-control-input" id="statusSwitch">
<label class="custom-control-label" for="statusSwitch" style="vertical-align: middle !important;">Failed Status</label>
</span>
</span>
`);
})
// others
$(document).ready(function() {
$('#insurer_id').select2();
$('#commission_month').datepicker({
format: 'yyyy-M',
viewMode: 'months',
minViewMode: 'months',
autoclose: true
});
// Add custom filter function to DataTables
$.fn.dataTable.ext.search.push(function(settings, data, dataIndex) {
const showFailedStatus = $('#statusSwitch').is(':checked');
const status = data[6].toLowerCase().trim(); // Index 6 is the file_status column
if (showFailedStatus) {
return status.includes('failed');
} else{
return !status.includes('failed');
}
});
// Add event listener for switch changes
$('#statusSwitch').on('change', function() {
table.draw(); // Redraw the table to apply the filter
});
// Trigger initial filter to show only success status
table.draw();
});
// form submit
$('#commission_upload_form').submit(function(event) {
event.preventDefault();
var isValid = $('#commission_upload_form').parsley().validate();
if (!isValid) {
console.log('Form is Empty', 'Warning');
return;
}
// Create FormData object
var formData = new FormData($(this)[0]);
// FUNCTION to actually submit AJAX
function submitAjax(formData) {
$('#btnSubmit').prop('disabled', true).text('Submitting...');
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
$.ajax({
url: $('#commission_upload_form').attr("action"),
type: "POST",
data: formData,
processData: false,
contentType: false,
headers: {
"X-Requested-With": "XMLHttpRequest"
},
success: function(response) {
console.log(response);
$('#commission_upload_form')[0].reset();
if (response.code === 200 && response.status === true) {
toastr.success('File upload success', 'Success');
} else if (response.code === 404 && response.status === false) {
toastr.error(response.message, 'Failed');
} else {
toastr.error('Something went wrong! Try later', 'Error');
}
$('.close').click();
$('.loader').fadeOut();
$('.loader-mask').delay(10).fadeOut('slow');
$('#btnSubmit').prop('disabled', false).text('Submit');
window.location.reload(true);
},
error: function(xhr, status, error) {
console.error("Request failed:", status, error);
toastr.error('Something went wrong! Try later', 'Error');
$('.close').click();
$('.loader').fadeOut();
$('.loader-mask').delay(10).fadeOut('slow');
$('#btnSubmit').prop('disabled', false).text('Submit');
window.location.reload(true);
}
});
}
// Duplicate check
if (isDublicateFound) {
Swal.fire({
icon: "warning",
title: "Existing rules found for this insurer and month. What would you like to do?",
showDenyButton: true, // For Append
showCancelButton: true, // For Cancel
confirmButtonText: "Overwrite",
denyButtonText: "Append",
cancelButtonText: "Cancel",
confirmButtonColor: "#ff3333",
customClass: {
denyButton: 'swal-append-btn' // Apply CSS class
}
}).then((result) => {
if (result.isConfirmed) {
// Overwrite
formData.append('overwrite', 1);
submitAjax(formData);
isDublicateFound = false;
} else if (result.isDenied) {
// Append
formData.append('overwrite', 0);
submitAjax(formData);
isDublicateFound = false;
} else if (result.dismiss === Swal.DismissReason.cancel) {
// Cancel clicked
console.log("Cancelled");
isDublicateFound = true;
}
});
return;
}
// If no duplicate, submit normally
submitAjax(formData);
});
// open the file upload modal
function showFileUploadModal(input) {
var myModal = new bootstrap.Modal(document.getElementById('file_upload'));
myModal.show();
}
// remove the file entry
function deleteCommissionData(id) {
Swal.fire({
icon: "warning",
title: "Do you want to delete commission & it's data if any?",
html: "<small class='text-danger'>This data cannot be retrieved.</small>",
showCancelButton: true,
confirmButtonText: "Delete",
confirmButtonColor: "#ff3333",
}).then((result) => {
console.log(result);
if (result.isConfirmed) {
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
var apiURL = 'deleteCommissionData/' + id;
$.ajax({
url: apiURL,
method: 'GET',
headers: {
"X-Requested-With": "XMLHttpRequest"
},
success: function(response) {
$('.loader').fadeOut();
$('.loader-mask').delay(10).fadeOut('slow');
if (response.code === 200 && response.status === true) {
Swal.fire({
title: "Deleted!",
icon: "success"
});
window.location.reload(true);
} else {
Swal.fire({
title: "Failed!",
text: 'Something went wrong! Try later',
icon: "error"
});
window.location.reload(true);
}
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
$('.loader').fadeOut();
$('.loader-mask').delay(10).fadeOut('slow');
console.error('Error fetching data from API:', error);
toastr.error('Something went wrong! Try later', 'Error');
window.location.reload(true);
}
});
}
});
}
// avoid dublicate entry
function checkSameEntry()
{
let insurer_id = $('#insurer_id').val()
let commission_month = $('#commission_month').val()
let department = $('#department').val()
let url = '<?= base_url('commission/checkSameEntry') ?>';
// Data to send in the AJAX request
let requestData = {
insurer_id: insurer_id,
commission_month: commission_month,
department: department,
};
// Send AJAX request
sendAjaxRequestForGlobal(url, 'GET', requestData, function(response) {
console.log('Data fetched successfully:', response);
if (response.status == true) {
isDublicateFound = true;
}else{
isDublicateFound = false;
}
}, function(xhr, status, error) {
isDublicateFound = false;
console.error('Error fetching data:', error);
console.error(xhr.responseText);
console.log('An error occurred while fetching the data.', 'ERROR');
});
}
</script>