nhance/app/Views/commission_file_upload.php

585 lines
23 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 th,
.table td {
padding: 8px;
}
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;
}
</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;
}
</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 Month</div></th>
<th><div class="column-header">Department</div></th>
<th><div class="column-header">Rules Count</div></th>
<th><div class="column-header">File<br>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><?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-delete mr-2 text-muted font-18 vertical-middle"></i>Download Error File</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" 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" 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" 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>
document.addEventListener("DOMContentLoaded", function() {
const table = document.getElementById("tickets-table");
// Create custom dropdown
function createCustomDropdown(row) {
const originalDropdown = row.querySelector('.dropdown-menu');
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;
}
});
});
$(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>>",
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: 'Client-List',
// title: function() {
// return $('#toggleButtons').is(':checked')
// ? 'GC-Client-List'
// : 'RC-Client-List';
// },
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>
`);
})
$(document).ready(function() {
$('#insurer_id').select2();
$('#commission_month').datepicker({
format: 'yyyy-M',
viewMode: 'months',
minViewMode: 'months',
autoclose: true
});
});
$(document).ready(function() {
$('#file_upload').on('hidden.bs.modal', function () {
console.log("Modal closed");
});
});
$(document).ready(function() {
// 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();
});
</script>
<script>
function showFileUploadModal(input) {
var myModal = new bootstrap.Modal(document.getElementById('file_upload'));
myModal.show();
// $(input).val('');
}
$('#commission_upload_form').submit(function(event) {
event.preventDefault();
var isValid = $('#commission_upload_form').parsley().validate();
if (!isValid) {
console.log('Form is Empty', 'Warning');
return;
}
$('#btnSubmit').prop('disabled', true).text('Submitting...');
// Create FormData object
var formData = new FormData($(this)[0]);
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
$.ajax({
url: $(this).attr("action"),
type: "POST",
data: formData,
processData: false, // Prevent jQuery from automatically processing the data
contentType: false, // Let jQuery handle the content type
headers: {
// "Content-Type":"multipart/form-data",
"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 successs','SUCCESS');
$('.close').click();
window.location.reload(true);
} else if (response.code === 404 && response.status === false) {
console.error('no data found', response);
toastr.error(response.message, 'FAILED');
window.location.reload(true);
} else {
console.error('Something went wrong!');
toastr.error('Something went wrong! Try later', 'ERROR');
window.location.reload(true);
}
$('.close').click()
$('.loader').fadeOut();
$('.loader-mask').delay(10).fadeOut('slow');
$('#btnSubmit').prop('disabled', false).text('Submit');
},
error: function(xhr, status, error) {
// Request failed, handle 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');
// window.location.reload(true);
}
});
});
function deleteCommissionData(id) {
Swal.fire({
title: "Do you want to delete commission & it's data if any?",
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);
}
});
}
});
}
</script>