update trip report

This commit is contained in:
Pringgosutono
2025-09-02 09:57:39 +07:00
parent cf6594a5da
commit 3ad22e0cf5
2 changed files with 96 additions and 74 deletions

View File

@ -183,26 +183,48 @@
const DTable = {
table: null,
lastAjax: null, // keep track of the last ajax request
activate: function() {
DTable.reload();
},
reload: function() {
DTable.table = $('#tVehicleTrips').DataTable({
processing: true,
serverSide: false,
bLengthChange: true,
deferRender: true,
destroy: true,
ajax: {
url: `{{ route('api_report_vehicle_trips_list') }}?
cptid=${AppState.current_company}
&from_date=${moment(safeVal('#tgl0')).startOf('day').unix()}
&to_date=${moment(safeVal('#tgl1')).endOf('day').unix()}`,
type: 'GET',
complete: function() {
// removeTableSkeletonLoading()
},
},
// Abort the last request if it's still running
if (DTable.lastAjax) {
DTable.lastAjax.abort();
}
DTable.table = $('#tVehicleTrips').DataTable({
processing: true,
serverSide: false,
bLengthChange: true,
deferRender: true,
destroy: true,
ajax: function(data, callback, settings) {
// Abort previous
if (DTable.lastAjax) {
DTable.lastAjax.abort();
}
// Fire new request
DTable.lastAjax = $.ajax({
url: `{{ route('api_report_vehicle_trips_list') }}?
cptid=${AppState.current_company}
&from_date=${moment(safeVal('#tgl0')).startOf('day').unix()}
&to_date=${moment(safeVal('#tgl1')).endOf('day').unix()}`,
type: 'GET',
success: function(json) {
callback(json);
},
error: function(xhr, status, error) {
if (status !== 'abort') {
console.error("AJAX error:", error);
}
},
complete: function() {
DTable.lastAjax = null;
}
});
},
deferRender: true,
columns: [
{
@ -240,7 +262,7 @@
buttons: [
{
extend: 'excelHtml5',
title: 'Trip Report',
title: `Vehicle Trip Report - ${moment(safeVal('#tgl0')).format('DD MMM YYYY')} to ${moment(safeVal('#tgl1')).format('DD MMM YYYY')}`,
className: 'd-none' // hide default button
}
]