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

View File

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