update report
This commit is contained in:
@ -79,24 +79,32 @@ class ReportsController extends Controller
|
||||
-- assign a trip_id by cumulative sum of trip_start
|
||||
SUM(trip_start) OVER (PARTITION BY vhc_id ORDER BY crt_d) AS trip_id
|
||||
FROM trips
|
||||
)
|
||||
select
|
||||
),
|
||||
agg AS (
|
||||
SELECT
|
||||
v.id,
|
||||
-- coalesce(max(a.trip_id), 0) numOfTrip,
|
||||
-- SUM(pre_milleage) AS total_milleage,
|
||||
v.name, v.nopol1,
|
||||
vhc_id, trip_id,
|
||||
sum(pre_milleage) milleage, min(a.crt_d ) start, max(a.crt_d ) finish,
|
||||
(select fulladdress from t_gps_tracks_address where master_id = min(a.id) limit 1) startLoc,
|
||||
(select fulladdress from t_gps_tracks_address where master_id = max(a.id) limit 1) finishLoc
|
||||
FROM
|
||||
t_vehicles v
|
||||
left join numbered a on a.vhc_id = v.id
|
||||
v.name,
|
||||
v.nopol1,
|
||||
vhc_id,
|
||||
trip_id,
|
||||
SUM(pre_milleage) AS mileage,
|
||||
MIN(a.crt_d) AS start,
|
||||
MAX(a.crt_d) AS finish,
|
||||
(SELECT fulladdress FROM t_gps_tracks_address WHERE master_id = MIN(a.id) LIMIT 1) AS startLoc,
|
||||
(SELECT fulladdress FROM t_gps_tracks_address WHERE master_id = MAX(a.id) LIMIT 1) AS finishLoc
|
||||
FROM t_vehicles v
|
||||
LEFT JOIN numbered a ON a.vhc_id = v.id
|
||||
WHERE
|
||||
v.dlt is null and trip_id != 0
|
||||
and if(? , v.id = ? , 1=1)
|
||||
GROUP BY v.id, a.trip_id
|
||||
ORDER BY v.id
|
||||
)
|
||||
SELECT
|
||||
*,
|
||||
SUM(mileage) OVER (PARTITION BY id) AS total_mileage,
|
||||
COUNT(trip_id) OVER (PARTITION BY id) AS total_trip
|
||||
FROM agg
|
||||
ORDER BY id, trip_id;
|
||||
";
|
||||
$d = [$from_date, $to_date, $vid, $vid];
|
||||
|
||||
@ -229,7 +237,7 @@ class ReportsController extends Controller
|
||||
AND t.crt_d BETWEEN ? AND ?
|
||||
and if(? , tv.id = ? , 1=1)
|
||||
-- and t.speed > tvd.speed_limit
|
||||
having t.speed > tvd.speed_limit
|
||||
having t.speed >= tvd.speed_limit
|
||||
ORDER BY t.crt_d
|
||||
";
|
||||
$d = [$from_date, $to_date, $vid, $vid];
|
||||
|
||||
@ -78,7 +78,7 @@
|
||||
<tr class="">
|
||||
<!-- <th class="">Vehicle ID</th> -->
|
||||
<!-- <th class="text-center">Action</th> -->
|
||||
<th class="">Vehicle Name</th>
|
||||
<!-- <th class="">Vehicle Name</th> -->
|
||||
<th class="">License Plate Number</th>
|
||||
<th class="">Time</th>
|
||||
<th class="">Speed (kph)</th>
|
||||
@ -116,8 +116,7 @@
|
||||
activate: function() {
|
||||
Wrapper.init();
|
||||
Wrapper.event();
|
||||
DTable.activate();
|
||||
|
||||
// DTable.activate();
|
||||
},
|
||||
init: ()=>{
|
||||
$('#tgl0, #tgl1').datetimepicker({
|
||||
@ -193,10 +192,10 @@
|
||||
deferRender: true,
|
||||
columns: [
|
||||
// { data: 'id', visible: false }, // vhc_id
|
||||
{
|
||||
data: 'name',
|
||||
className: 'text-start text-nowrap',
|
||||
},
|
||||
// {
|
||||
// data: 'name',
|
||||
// className: 'text-start text-nowrap',
|
||||
// },
|
||||
{
|
||||
data: 'nopol1',
|
||||
className: 'text-start',
|
||||
@ -220,7 +219,13 @@
|
||||
buttons: [
|
||||
{
|
||||
extend: 'excelHtml5',
|
||||
title: `Abnormality Report - ${moment(safeVal('#tgl0')).format('DD MMM YYYY')} to ${moment(safeVal('#tgl1')).format('DD MMM YYYY')}`,
|
||||
title: () => {
|
||||
return `
|
||||
Vehicle 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
|
||||
|
||||
@ -43,7 +43,7 @@
|
||||
<div class="form-group">
|
||||
<label class="text-muted">From</label>
|
||||
<!-- default today -->
|
||||
<!-- <input type="date" class="form-control" id="tgl0" value="{{ date('Y-m-d') }}"> -->
|
||||
<!-- <input class="form-control" id="tgl0" value="25-08-2025 00:00"> -->
|
||||
<input class="form-control" id="tgl0" value="{{ date('d-m-Y 00:00') }}">
|
||||
</div>
|
||||
</div>
|
||||
@ -77,8 +77,6 @@
|
||||
<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="">Number of Trip</th>
|
||||
<th class="">Total Mileage (km)</th>
|
||||
@ -187,8 +185,7 @@
|
||||
activate: function() {
|
||||
Wrapper.init();
|
||||
Wrapper.event();
|
||||
DTable.activate();
|
||||
|
||||
// DTable.activate();
|
||||
},
|
||||
init: ()=>{
|
||||
$('#tgl0, #tgl1').datetimepicker({
|
||||
@ -227,10 +224,6 @@
|
||||
return;
|
||||
}
|
||||
|
||||
let mileageSum = {};
|
||||
let tripCount = {};
|
||||
|
||||
|
||||
DTable.table = $('#tVehicleTrips').DataTable({
|
||||
searching: false, // 🔹 remove search box
|
||||
ordering: false, // 🔹 disable sorting for all columns
|
||||
@ -254,17 +247,6 @@
|
||||
&vid=${$('#filterNopol').val() || ''}`,
|
||||
type: 'GET',
|
||||
success: function(json) {
|
||||
// Precompute totals by vhc_id
|
||||
|
||||
json.data.forEach(row => {
|
||||
const id = row.id; // vhc_id
|
||||
if (!mileageSum[id]) {
|
||||
mileageSum[id] = 0;
|
||||
tripCount[id] = 0;
|
||||
}
|
||||
mileageSum[id] += parseFloat(row.milleage || 0);
|
||||
tripCount[id] += 1;
|
||||
});
|
||||
callback(json);
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
@ -280,13 +262,6 @@
|
||||
deferRender: true,
|
||||
columns: [
|
||||
{ data: 'id', visible: false }, // vhc_id
|
||||
{
|
||||
data: 'name',
|
||||
className: 'text-start text-nowrap',
|
||||
visible: true,
|
||||
orderable: true,
|
||||
searchable: true,
|
||||
},
|
||||
{
|
||||
data: 'nopol1',
|
||||
className: 'text-start',
|
||||
@ -294,8 +269,8 @@
|
||||
orderable: true,
|
||||
searchable: true,
|
||||
},
|
||||
{ data: "id", className: 'text-end'},
|
||||
{ data: "id", className: 'text-end'},
|
||||
{ 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',
|
||||
@ -318,7 +293,7 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
data: 'milleage',
|
||||
data: 'mileage',
|
||||
className: 'text-end', render: function(data, type, row, meta) {
|
||||
return (data === null) ? '0' : parseFloat(data).toFixed(2);
|
||||
}
|
||||
@ -346,17 +321,7 @@
|
||||
$(rows).eq(i).find('td:eq(0)').attr('rowspan', rowspanCount);
|
||||
$(rows).eq(i).find('td:eq(1)').attr('rowspan', rowspanCount);
|
||||
$(rows).eq(i).find('td:eq(2)').attr('rowspan', rowspanCount);
|
||||
$(rows).eq(i).find('td:eq(3)').attr('rowspan', rowspanCount);
|
||||
|
||||
// fill trip count
|
||||
$(rows).eq(i).find('td:eq(2)')
|
||||
.attr('rowspan', rowspanCount)
|
||||
.text(tripCount[group]);
|
||||
|
||||
// fill mileage sum
|
||||
$(rows).eq(i).find('td:eq(3)')
|
||||
.attr('rowspan', rowspanCount)
|
||||
.text(mileageSum[group].toFixed(2));
|
||||
// $(rows).eq(i).find('td:eq(3)').attr('rowspan', rowspanCount);
|
||||
|
||||
last = group;
|
||||
} else {
|
||||
@ -364,17 +329,23 @@
|
||||
$(rows).eq(i).find('td:eq(0)').remove();
|
||||
$(rows).eq(i).find('td:eq(0)').remove();
|
||||
$(rows).eq(i).find('td:eq(0)').remove();
|
||||
$(rows).eq(i).find('td:eq(0)').remove();
|
||||
// $(rows).eq(i).find('td:eq(0)').remove();
|
||||
}
|
||||
});
|
||||
},
|
||||
buttons: [
|
||||
{
|
||||
extend: 'excelHtml5',
|
||||
title: `Vehicle Trip Report - ${moment(safeVal('#tgl0')).format('DD MMM YYYY')} to ${moment(safeVal('#tgl1')).format('DD MMM YYYY')}`,
|
||||
title: () => {
|
||||
return `
|
||||
Vehicle 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
|
||||
columns: ':visible' // 🔹 exclude first column
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user