update add vehicle type filter at report

This commit is contained in:
wayanrivan
2026-06-17 11:33:30 +07:00
parent 4c96d4ca79
commit 37c0c1ea25
4 changed files with 815 additions and 760 deletions

View File

@ -16,16 +16,19 @@ use App\Models\UserLogs;
use Illuminate\Support\Facades\Crypt; use Illuminate\Support\Facades\Crypt;
use Illuminate\Contracts\Encryption\DecryptException; use Illuminate\Contracts\Encryption\DecryptException;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use App\Models\ConfTruckTypes;
class ReportsController extends Controller class ReportsController extends Controller
{ {
public function view_report_vehicle_trips(Request $req) public function view_report_vehicle_trips(Request $req)
{ {
$q = "SELECT id, nopol1 from t_vehicles WHERE dlt is null order by nopol1"; $q = "SELECT id, nopol1 from t_vehicles WHERE dlt is null order by nopol1";
$vehicletype = DB::table('t_vehicles_types')->where('is_active', 1)->get();
$listNopol = DB::select($q); $listNopol = DB::select($q);
$data = [ $data = [
'listNopol' => $listNopol, 'listNopol' => $listNopol,
'vehicletype' => $vehicletype
]; ];
$log = [ $log = [
@ -59,6 +62,7 @@ class ReportsController extends Controller
$from_date = $req->input('from_date') - Helper::TIMEFIX; $from_date = $req->input('from_date') - Helper::TIMEFIX;
$to_date = $req->input('to_date') - Helper::TIMEFIX; $to_date = $req->input('to_date') - Helper::TIMEFIX;
$vid = $req->input('vid'); $vid = $req->input('vid');
$vt = $req->input('vt');
// $from_date = 1756054800; // $from_date = 1756054800;
// $to_date = 1756745940; // $to_date = 1756745940;
@ -147,13 +151,17 @@ class ReportsController extends Controller
SELECT SELECT
t.*, t.*,
tm.total_mileage, total_trip, tm.total_mileage, total_trip,
vt.name as type_name,
ROW_NUMBER() OVER (PARTITION BY t.id ORDER BY t.start) AS trip_id ROW_NUMBER() OVER (PARTITION BY t.id ORDER BY t.start) AS trip_id
FROM trips t FROM trips t
JOIN TotalMileage tm ON t.id = tm.id JOIN TotalMileage tm ON t.id = tm.id
LEFT JOIN t_vehicles tvt ON tvt.id = t.vhc_id
LEFT JOIN t_vehicles_types vt ON vt.id = tvt.type_id
WHERE WHERE
t.start BETWEEN ? AND ? t.start BETWEEN ? AND ?
and if(? , t.id = ? , 1=1) and if(? , t.id = ? , 1=1)
", [$from_date, $to_date, $from_date, $to_date, $vid, $vid]); and if(? , vt.id = ? , 1=1)
", [$from_date, $to_date, $from_date, $to_date, $vid, $vid, $vt, $vt]);
// // RETURN 1 - LIST // // RETURN 1 - LIST
// if($req->type != 'report'){ // if($req->type != 'report'){

View File

@ -9,12 +9,8 @@
@endsection @endsection
@section('customcss') @section('customcss')
<link <link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css"
rel="stylesheet" integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=" crossorigin="" />
href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css"
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY="
crossorigin=""
/>
@endsection @endsection
@section('content') @section('content')
@ -44,25 +40,24 @@
</div> </div>
<div class="card-body"> <div class="card-body">
<!-- filter --> <!-- filter -->
<div class="row"> <div class="row g-3 align-items-end">
<div class="col-2"> <div class="col-md-2">
<div class="form-group"> <div class="form-group">
<label class="text-muted">From</label> <label class="form-label text-muted mb-1">From</label>
<!-- default today --> <input type="text" class="form-control" id="tgl0" value="{{ date('d-m-Y 00:00') }}">
<!-- <input class="form-control" id="tgl0" value="02-09-2025 00:00"> -->
<input class="form-control" id="tgl0" value="{{ date('d-m-Y 00:00') }}">
</div> </div>
</div> </div>
<div class="col-2">
<div class="col-md-2">
<div class="form-group"> <div class="form-group">
<label class="text-muted">To</label> <label class="form-label text-muted mb-1">To</label>
<!-- <input class="form-control" id="tgl1" value="02-09-2025 23:00"> --> <input type="text" class="form-control" id="tgl1" value="{{ date('d-m-Y 23:59') }}">
<input class="form-control" id="tgl1" value="{{ date('d-m-Y 23:59') }}">
</div> </div>
</div> </div>
<div class="col-2">
<div class="col-md-2">
<div class="form-group"> <div class="form-group">
<label class="text-muted">License Plate</label> <label class="form-label text-muted mb-1">License Plate</label>
<select name="license_plate" class="form-control" id="filterNopol"> <select name="license_plate" class="form-control" id="filterNopol">
<option value="">-- All --</option> <option value="">-- All --</option>
@foreach ($listNopol as $nopol) @foreach ($listNopol as $nopol)
@ -71,11 +66,26 @@
</select> </select>
</div> </div>
</div> </div>
<div class="col-1 d-flex align-items-end">
<button class="btn btn-primary" id="submitFilter">Submit</button> <div class="col-md-2">
<div class="form-group">
<label class="form-label text-muted mb-1">Vehicle Type</label>
<select name="vehicle_type" class="form-control" id="vehicleType">
<option value="">-- All --</option>
@foreach ($vehicletype as $vehicletypes)
<option value="{{ $vehicletypes->id }}">{{ $vehicletypes->name }}</option>
@endforeach
</select>
</div> </div>
<div class="col-5 d-flex align-items-end"> </div>
<button class="btn btn-sm btn-danger ms-auto" id="btnDownloadReport">Download Report</button>
<div class="col-md-4 d-flex justify-content-end gap-2">
<button class="btn btn-primary" id="submitFilter">
<i class="fa fa-search me-1"></i> Submit
</button>
<button class="btn btn-danger" id="btnDownloadReport">
<i class="fa fa-download me-1"></i> Download Report
</button>
</div> </div>
</div> </div>
</div> </div>
@ -97,6 +107,7 @@
<th class="">Finish (km)</th> <th class="">Finish (km)</th>
<th class="">Distance (km)</th> <th class="">Distance (km)</th>
<th class="">Fuel (L)</th> <th class="">Fuel (L)</th>
<th class="">Vehicle Type</th>
<th class="">Detail</th> <th class="">Detail</th>
</tr> </tr>
</thead> </thead>
@ -176,7 +187,8 @@
</div> </div>
<!-- modal --> <!-- modal -->
<div class="modal fade" data-bs-backdrop="static" data-bs-keyboard="false" id="mdlDetailTrip" aria-labelledby="mdlDetailTripLabel" aria-hidden="true"> <div class="modal fade" data-bs-backdrop="static" data-bs-keyboard="false" id="mdlDetailTrip"
aria-labelledby="mdlDetailTripLabel" aria-hidden="true">
<!-- <div class="modal-dialog modal-dialog modal-dialog-centered modal-dialog-scrollable modal-xl"> <!-- <div class="modal-dialog modal-dialog modal-dialog-centered modal-dialog-scrollable modal-xl">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
@ -198,8 +210,11 @@
<script src="https://cdn.datatables.net/buttons/2.4.2/js/dataTables.buttons.min.js"></script> <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://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 src="https://cdn.datatables.net/buttons/2.4.2/js/buttons.html5.min.js"></script>
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/1.0.4/leaflet.draw.js" integrity="sha512-ozq8xQKq6urvuU6jNgkfqAmT7jKN2XumbrX1JiB3TnF7tI48DPI4Gy1GXKD/V3EExgAs1V+pRO7vwtS1LHg0Gw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script> --> <!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/1.0.4/leaflet.draw.js"
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js" integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo=" crossorigin=""></script> integrity="sha512-ozq8xQKq6urvuU6jNgkfqAmT7jKN2XumbrX1JiB3TnF7tI48DPI4Gy1GXKD/V3EExgAs1V+pRO7vwtS1LHg0Gw=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script> -->
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"
integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo=" crossorigin=""></script>
<script src="https://unpkg.com/leaflet-routing-machine@3.2.12/dist/leaflet-routing-machine.js"></script> <script src="https://unpkg.com/leaflet-routing-machine@3.2.12/dist/leaflet-routing-machine.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
@ -224,10 +239,10 @@
// DTable.table = $('#tVehicleTrips').DataTable() // DTable.table = $('#tVehicleTrips').DataTable()
// DTable.activate(); // DTable.activate();
}, },
init: ()=>{ init: () => {
$('#tgl0, #tgl1').datetimepicker({ $('#tgl0, #tgl1').datetimepicker({
format:'d-m-Y H:i', format: 'd-m-Y H:i',
defaultTime:'00:00', defaultTime: '00:00',
closeOnDateSelect: true, closeOnDateSelect: true,
// mask:true // mask:true
}); });
@ -251,7 +266,8 @@
const nopol1 = $(this).data('nopol1'); const nopol1 = $(this).data('nopol1');
// $("#mdlDetailTrip").load("{{ route('view_report_trip_detail') }}"); // $("#mdlDetailTrip").load("{{ route('view_report_trip_detail') }}");
$('#mdlDetailTrip').empty().load("{{ route('view_report_trip_detail') }}", `vid=${vid}&tgl0=${tgl0}&tgl1=${tgl1}&nopol1=${nopol1}`, () => { $('#mdlDetailTrip').empty().load("{{ route('view_report_trip_detail') }}",
`vid=${vid}&tgl0=${tgl0}&tgl1=${tgl1}&nopol1=${nopol1}`, () => {
$('#mdlDetailTrip').modal('show') $('#mdlDetailTrip').modal('show')
}) })
@ -297,6 +313,7 @@
&from_date=${moment($('#tgl0').val(), "DD-MM-YYYY HH:mm").unix()} &from_date=${moment($('#tgl0').val(), "DD-MM-YYYY HH:mm").unix()}
&to_date=${moment($('#tgl1').val(), "DD-MM-YYYY HH:mm").unix()} &to_date=${moment($('#tgl1').val(), "DD-MM-YYYY HH:mm").unix()}
&vid=${$('#filterNopol').val() || ''} &vid=${$('#filterNopol').val() || ''}
&vt=${$('#vehicleType').val() || ''}
`, `,
type: 'GET', type: 'GET',
success: function(json) { success: function(json) {
@ -313,8 +330,10 @@
}); });
}, },
deferRender: true, deferRender: true,
columns: [ columns: [{
{ data: 'id', visible: false }, // vhc_id data: 'id',
visible: false
}, // vhc_id
{ {
data: 'nopol1', data: 'nopol1',
className: 'text-start', className: 'text-start',
@ -322,11 +341,27 @@
orderable: true, orderable: true,
searchable: true, searchable: true,
}, },
{ data: "dc_code", className: 'text-start'}, {
{ data: "pool_code", className: 'text-start'}, data: "dc_code",
{ data: "total_trip", className: 'text-end'}, className: 'text-start'
{ data: "total_mileage", className: 'text-end', render: (data, type, row, meta) => parseFloat(data).toFixed(2)}, },
{ data: "trip_id", className: 'text-end'}, {
data: "pool_code",
className: 'text-start'
},
{
data: "total_trip",
className: 'text-end'
},
{
data: "total_mileage",
className: 'text-end',
render: (data, type, row, meta) => parseFloat(data).toFixed(2)
},
{
data: "trip_id",
className: 'text-end'
},
{ {
data: 'start', data: 'start',
render: (data, type, row, meta) => { render: (data, type, row, meta) => {
@ -348,7 +383,8 @@
} }
}, },
{ {
className: 'text-start', render: function(data, type, row, meta) { className: 'text-start',
render: function(data, type, row, meta) {
const start = moment.unix(row.start); const start = moment.unix(row.start);
const finish = moment.unix(row.finish); const finish = moment.unix(row.finish);
@ -362,30 +398,38 @@
}, },
{ {
data: 'startMileage', data: 'startMileage',
className: 'text-end', render: function(data, type, row, meta) { className: 'text-end',
render: function(data, type, row, meta) {
return (data === null) ? '0' : parseFloat(data).toFixed(0); return (data === null) ? '0' : parseFloat(data).toFixed(0);
} }
}, },
{ {
data: 'finishMileage', data: 'finishMileage',
className: 'text-end', render: function(data, type, row, meta) { className: 'text-end',
render: function(data, type, row, meta) {
return (data === null) ? '0' : parseFloat(data).toFixed(0); return (data === null) ? '0' : parseFloat(data).toFixed(0);
} }
}, },
{ {
data: 'mileage', data: 'mileage',
className: 'text-end', render: function(data, type, row, meta) { className: 'text-end',
render: function(data, type, row, meta) {
// const mileage = (row.finishMileage !== null && row.startMileage !== null) ? (row.finishMileage - row.startMileage) : row.mileage; // const mileage = (row.finishMileage !== null && row.startMileage !== null) ? (row.finishMileage - row.startMileage) : row.mileage;
return (parseFloat(data).toFixed(2)); return (parseFloat(data).toFixed(2));
} }
}, },
{ {
data: 'fuel_consume', data: 'fuel_consume',
className: 'text-end', render: function(data, type, row, meta) { className: 'text-end',
render: function(data, type, row, meta) {
// const mileage = (row.finishMileage !== null && row.startMileage !== null) ? (row.finishMileage - row.startMileage) : row.mileage; // const mileage = (row.finishMileage !== null && row.startMileage !== null) ? (row.finishMileage - row.startMileage) : row.mileage;
return (parseFloat(data/10).toFixed(1)); return (parseFloat(data / 10).toFixed(1));
} }
}, },
{
data: "type_name",
className: 'text-start'
},
{ {
// visible: false, // visible: false,
data: 'vhc_id', data: 'vhc_id',
@ -402,20 +446,26 @@
}, },
], ],
paging: false, paging: false,
drawCallback: function (settings) { drawCallback: function(settings) {
const api = this.api(); const api = this.api();
const rows = api.rows({ page: 'current' }).nodes(); const rows = api.rows({
page: 'current'
}).nodes();
let last = null; let last = null;
api.column(0, { page: 'current' }) // vhc_id col api.column(0, {
page: 'current'
}) // vhc_id col
.data() .data()
.each(function (group, i) { .each(function(group, i) {
if (last !== group) { if (last !== group) {
// count how many rows this vhc_id spans // count how many rows this vhc_id spans
const rowspanCount = api const rowspanCount = api
.column(0, { page: 'current' }) .column(0, {
page: 'current'
})
.data() .data()
.filter(function (d) { .filter(function(d) {
return d === group; return d === group;
}).length; }).length;
@ -440,8 +490,7 @@
} }
}); });
}, },
buttons: [ buttons: [{
{
extend: 'excelHtml5', extend: 'excelHtml5',
title: () => { title: () => {
return ` return `
@ -454,8 +503,7 @@
exportOptions: { exportOptions: {
columns: ':visible:not(:last-child)' // columns: ':visible:not(:last-child)' //
} }
} }]
]
}); });
}, },
}; };

View File

@ -183,7 +183,6 @@ Route::middleware(["auth", "auth.user"])->group(function () {
Route::get("/reports/vehicle-trip-detail", "ReportsController@view_report_trip_detail")->name("view_report_trip_detail"); Route::get("/reports/vehicle-trip-detail", "ReportsController@view_report_trip_detail")->name("view_report_trip_detail");
Route::get("/reports/abnormalities", "ReportsController@view_report_abnormalities")->name("view_report_abnormalities"); Route::get("/reports/abnormalities", "ReportsController@view_report_abnormalities")->name("view_report_abnormalities");
Route::get("/reports/abnormalities-list", "ReportsController@api_report_abnormalities_list")->name("api_report_abnormalities_list"); Route::get("/reports/abnormalities-list", "ReportsController@api_report_abnormalities_list")->name("api_report_abnormalities_list");
// media // media
Route::get("/media", "MediaController@view_media") Route::get("/media", "MediaController@view_media")
->name("view_media") ->name("view_media")