This commit is contained in:
wayanrivan
2026-07-07 13:59:57 +07:00
parent 07092134e3
commit 29ded633ba
2 changed files with 28 additions and 23 deletions

View File

@ -166,29 +166,34 @@ class ReportsController extends Controller
// and if(? , vt.id = ? , 1=1) // and if(? , vt.id = ? , 1=1)
// and if(? , t.pool_code = ? , 1=1) // and if(? , t.pool_code = ? , 1=1)
// ", [$from_date, $to_date, $from_date, $to_date, $vid, $vid, $vt, $vt, $poolcode, $poolcode]); // ", [$from_date, $to_date, $from_date, $to_date, $vid, $vid, $vt, $vt, $poolcode, $poolcode]);
$sql = "WITH TotalMileage AS ( $sql =
SELECT id, SUM(mileage) AS total_mileage, count(*) total_trip "WITH TotalMileage AS (
SELECT
id,
SUM(mileage) AS total_mileage,
COUNT(*) AS total_trip
FROM trips FROM trips
WHERE start BETWEEN ? AND ? WHERE start BETWEEN ? AND ?
GROUP BY id GROUP BY id
) )
SELECT SELECT
t.*, t.*,
tm.total_mileage, total_trip, tm.total_mileage,
vt.name as type_name, tm.total_trip,
ROW_NUMBER() OVER (PARTITION BY t.id ORDER BY t.start) AS trip_id, vt.name AS type_name,
-- tgt.latitude, ROW_NUMBER() OVER (
-- tgt.longitude 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 tvt ON tvt.id = t.vhc_id
LEFT JOIN t_vehicles_cats vt ON vt.id = tvt.cat_id LEFT JOIN t_vehicles_cats vt ON vt.id = tvt.cat_id
-- LEFT JOIN t_gps_tracks tgt ON t.vhc_id = tgt.vhc_id
WHERE WHERE
t.start BETWEEN ? AND ? t.start BETWEEN ? AND ?
and (? IS NULL or t.id = ?) AND (? IS NULL OR t.id = ?)
and (? IS NULL or vt.id = ?) AND (? IS NULL OR vt.id = ?)
and (? IS NULL or t.pool_code = ?) AND (? IS NULL OR t.pool_code = ?);
"; ";
$vid = $vid ?: null; $vid = $vid ?: null;

View File

@ -117,8 +117,8 @@
<th class="hidden">Date</th> <th class="hidden">Date</th>
<th class="hidden">Hour Start</th> <th class="hidden">Hour Start</th>
<th class="hidden">Hour Finish</th> <th class="hidden">Hour Finish</th>
<th class="hidden">Latitude</th> {{-- <th class="hidden">Latitude</th>
<th class="hidden">Longitude</th> <th class="hidden">Longitude</th> --}}
<th class="">Start</th> <th class="">Start</th>
<th class="">Finish</th> <th class="">Finish</th>
<th class="">Duration</th> <th class="">Duration</th>