This commit is contained in:
wayanrivan
2026-07-01 14:50:17 +07:00
parent 81a131d7a0
commit eb1d5c4187
3 changed files with 383 additions and 289 deletions

View File

@ -23,8 +23,8 @@
@if ($user_role == \App\Models\Users::ROLE_VENDOR || $user_role == \App\Models\Users::ROLE_ADMIN)
@can('vehicle.create')
<!-- <div class="col text-end">
<button id="btnMdlNewVhc" class="btn btn-sm btn-danger">Add New Vehicle</button>
</div> -->
<button id="btnMdlNewVhc" class="btn btn-sm btn-danger">Add New Vehicle</button>
</div> -->
@endcan
{{-- <div class="col-auto text-end ps-0">
@ -37,73 +37,90 @@
</div>
</div>
<div class="card-body">
<!-- filter -->
<div class="row">
<div class="col-2">
<div class="form-group">
<label class="text-muted">From</label>
<!-- default today -->
<!-- <input class="form-control" id="tgl0" value="20-08-2025 00:00"> -->
<input class="form-control" id="tgl0" value="{{ date('d-m-Y 00:00') }}">
</div>
</div>
<div class="col-2">
<div class="form-group">
<label class="text-muted">To</label>
<input class="form-control" id="tgl1" value="{{ date('d-m-Y 23:59') }}">
</div>
</div>
<div class="col-2">
<div class="form-group">
<label class="text-muted">License Plate</label>
<select name="license_plate" class="form-control" id="filterNopol">
<option value="">-- All --</option>
@foreach ($listNopol as $nopol)
<option value="{{ $nopol->id }}">{{ $nopol->nopol1 }}</option>
@endforeach
</select>
</div>
</div>
<div class="col-1 d-flex align-items-end">
<button class="btn btn-primary" id="submitFilter">Submit</button>
</div>
<div class="col-5 d-flex align-items-end">
<button class="btn btn-sm btn-danger ms-auto" id="btnDownloadReport">Download Report</button>
</div>
</div>
</div>
<div class="table-responsive p-3">
<table id="tVehicleTrips" class="table table-hover dataTable w-100">
<thead>
<tr class="">
<!-- <th class="">Vehicle ID</th> -->
<!-- <th class="text-center">Action</th> -->
<!-- <th class="">Vehicle Name</th> -->
<th class="">License Plate Number</th>
<th class="">Dist. Cat.</th>
<th class="">Pool</th>
<th class="">Time</th>
<th class="">Speed (kph)</th>
<th class="">Location</th>
</tr>
</thead>
</table>
<!-- filter -->
<div class="row g-3 align-items-end">
<div class="col-6 col-md-3 col-lg-2">
<div class="form-group">
<label class="form-label text-muted mb-1">From</label>
<input class="form-control" id="tgl0" value="{{ date('d-m-Y 00:00') }}">
</div>
</div>
<div class="col-6 col-md-3 col-lg-2">
<div class="form-group">
<label class="form-label text-muted mb-1">To</label>
<input class="form-control" id="tgl1" value="{{ date('d-m-Y 23:59') }}">
</div>
</div>
<div class="col-6 col-md-3 col-lg-2">
<div class="form-group">
<label class="form-label text-muted mb-1">License Plate</label>
<select name="license_plate" class="form-control" id="filterNopol">
<option value="">-- All --</option>
@foreach ($listNopol as $nopol)
<option value="{{ $nopol->id }}">{{ $nopol->nopol1 }}</option>
@endforeach
</select>
</div>
</div>
<div class="col-6 col-md-3 col-lg-2">
<div class="form-group">
<label class="form-label text-muted mb-1">Pool</label>
<select name="poolcode" class="form-control" id="poolcode">
<option value="">-- All --</option>
@foreach ($listpool as $listpools)
<option value="{{ $listpools->pool_code }}">{{ $listpools->pool_name }}</option>
@endforeach
</select>
</div>
</div>
<div class="col-12 col-lg-4 d-flex gap-2 justify-content-lg-end">
<button class="btn btn-primary w-100 w-lg-auto" id="submitFilter">
<i class="fa fa-search me-1"></i> Submit
</button>
<button class="btn btn-danger w-100 w-lg-auto" id="btnDownloadReport">
<i class="fa fa-download me-1"></i> Download Report
</button>
</div>
</div>
</div>
<div class="table-responsive p-3">
<table id="tVehicleTrips" class="table table-hover dataTable w-100">
<thead>
<tr class="">
<!-- <th class="">Vehicle ID</th> -->
<!-- <th class="text-center">Action</th> -->
<!-- <th class="">Vehicle Name</th> -->
<th class="">License Plate Number</th>
<th class="">Dist. Cat.</th>
<th class="">Pool</th>
<th class="">Time</th>
<th class="">Speed (kph)</th>
<th class="">Location</th>
</tr>
</thead>
</table>
</div>
</div>
</div>
</div>
</div>
<!-- modal -->
<!-- modal -->
@endsection
@section('customjs')
<script src="{{ asset('assets/js/load-image.all.min.js') }}"></script>
<!-- DataTables Buttons + JSZip (for Excel export) -->
<script src="https://cdn.datatables.net/buttons/2.4.2/js/dataTables.buttons.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
<script src="https://cdn.datatables.net/buttons/2.4.2/js/buttons.html5.min.js"></script>
<script>
<!-- DataTables Buttons + JSZip (for Excel export) -->
<script src="https://cdn.datatables.net/buttons/2.4.2/js/dataTables.buttons.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
<script src="https://cdn.datatables.net/buttons/2.4.2/js/buttons.html5.min.js"></script>
<script>
'use strict';
const State = {
file_jimp_worker: "{{ asset('assets/js/worker/jimp.js') }}",
@ -119,130 +136,133 @@
Wrapper.init();
Wrapper.event();
// DTable.activate();
},
init: ()=>{
$('#tgl0, #tgl1').datetimepicker({
format:'d-m-Y H:i',
defaultTime:'00:00',
closeOnDateSelect: true,
// mask:true
});
},
init: () => {
$('#tgl0, #tgl1').datetimepicker({
format: 'd-m-Y H:i',
defaultTime: '00:00',
closeOnDateSelect: true,
// mask:true
});
},
},
event: function() {
$('#submitFilter').on('click', function() {
DTable.reload();
});
// Trigger export on external button click
$('#btnDownloadReport').on('click', function() {
DTable.table.button('.buttons-excel').trigger();
});
DTable.reload();
});
// Trigger export on external button click
$('#btnDownloadReport').on('click', function() {
DTable.table.button('.buttons-excel').trigger();
});
},
};
const DTable = {
table: null,
lastAjax: null, // keep track of the last ajax request
table: null,
lastAjax: null, // keep track of the last ajax request
activate: function() {
DTable.reload();
},
reload: function() {
// Abort the last request if it's still running
if (DTable.lastAjax) {
DTable.lastAjax.abort();
}
if (DTable.table) {
// If table already exists → reload
DTable.table.ajax.reload();
return;
}
// Abort the last request if it's still running
if (DTable.lastAjax) {
DTable.lastAjax.abort();
}
if (DTable.table) {
// If table already exists → reload
DTable.table.ajax.reload();
return;
}
DTable.table = $('#tVehicleTrips').DataTable({
searching: false, // 🔹 remove search box
ordering: false, // 🔹 disable sorting for all columns
processing: true,
serverSide: false,
bLengthChange: true,
deferRender: true,
ajax: function(data, callback, settings) {
// Abort previous
if (DTable.lastAjax) {
DTable.lastAjax.abort();
}
DTable.table = $('#tVehicleTrips').DataTable({
searching: false, // 🔹 remove search box
ordering: false, // 🔹 disable sorting for all columns
processing: true,
serverSide: false,
bLengthChange: true,
deferRender: true,
ajax: function(data, callback, settings) {
// Abort previous
if (DTable.lastAjax) {
DTable.lastAjax.abort();
}
// Fire new request
DTable.lastAjax = $.ajax({
url: `{{ route('api_report_abnormalities_list') }}?
// Fire new request
DTable.lastAjax = $.ajax({
url: `{{ route('api_report_abnormalities_list') }}?
cptid=${AppState.current_company}
&from_date=${moment($('#tgl0').val(), "DD-MM-YYYY HH:mm").unix()}
&to_date=${moment($('#tgl1').val(), "DD-MM-YYYY HH:mm").unix()}
&vid=${$('#filterNopol').val() || ''}`,
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;
}
});
},
&vid=${$('#filterNopol').val() || ''}
&poolcode=${$('#poolcode').val() || ''}`,
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: [
// { data: 'id', visible: false }, // vhc_id
// {
// data: 'name',
// className: 'text-start text-nowrap',
// },
{
data: 'nopol1',
className: 'text-start',
},
{
data: 'dc_code',
className: 'text-start',
},
{
data: 'pool_code',
className: 'text-start',
},
{
data: "crt_d",
className: 'text-nowrap',
render: (data, type, row, meta) => {
return moment.unix(data + AppState.TIMEFIX).format('DD MMM YYYY HH:mm:ss');
}
},
{ data: "speed", className: 'text-end'},
{
data: "fulladdress",
render: (data, type, row, meta) => {
return Helper.shortenText(decodeURIComponent(data || ''), 255)
},
},
],
paging: false,
buttons: [
{
extend: 'excelHtml5',
title: () => {
return `
columns: [
// { data: 'id', visible: false }, // vhc_id
// {
// data: 'name',
// className: 'text-start text-nowrap',
// },
{
data: 'nopol1',
className: 'text-start',
},
{
data: 'dc_code',
className: 'text-start',
},
{
data: 'pool_code',
className: 'text-start',
},
{
data: "crt_d",
className: 'text-nowrap',
render: (data, type, row, meta) => {
return moment.unix(data + AppState.TIMEFIX).format(
'DD MMM YYYY HH:mm:ss');
}
},
{
data: "speed",
className: 'text-end'
},
{
data: "fulladdress",
render: (data, type, row, meta) => {
return Helper.shortenText(decodeURIComponent(data || ''), 255)
},
},
],
paging: false,
buttons: [{
extend: 'excelHtml5',
title: () => {
return `
Abnormality Trip Report -
${moment($('#tgl0').val(), "DD-MM-YYYY HH:mm").format('DD MMM YYYY HH:mm')}
to
${moment($('#tgl1').val(), "DD-MM-YYYY HH:mm").format('DD MMM YYYY HH:mm')}`
},
className: 'd-none', // hide default button
exportOptions: {
columns: ':visible:not(:first-child)' // 🔹 exclude first column
}
}
]
});
},
className: 'd-none', // hide default button
exportOptions: {
columns: ':visible:not(:first-child)' // 🔹 exclude first column
}
}]
});
},
};