From 0fe1cac8bfa6888eda8330a67bace90636463bc8 Mon Sep 17 00:00:00 2001 From: Pringgosutono Date: Thu, 18 Sep 2025 13:41:30 +0700 Subject: [PATCH] timefix --- app/Helper.php | 1 + app/Http/Controllers/ReportsController.php | 34 ++++++++++--------- resources/views/app/app.blade.php | 2 ++ .../menu_v1/reports/_trip_detail.blade.php | 6 ++-- .../menu_v1/reports/vehicle_trips.blade.php | 4 +-- 5 files changed, 26 insertions(+), 21 deletions(-) diff --git a/app/Helper.php b/app/Helper.php index c962865..e2d35bb 100755 --- a/app/Helper.php +++ b/app/Helper.php @@ -9,6 +9,7 @@ class Helper const EARTH_RADIUS_M = 6371000; const EARTH_RADIUS_KM = 6371; const EARTH_RADIUS_MILES = 3959; // 3958.756 || 3959 || 3963 + const TIMEFIX = 25200; /** * Calculates the great-circle distance between two points, with diff --git a/app/Http/Controllers/ReportsController.php b/app/Http/Controllers/ReportsController.php index 2fd3ae6..69f6364 100644 --- a/app/Http/Controllers/ReportsController.php +++ b/app/Http/Controllers/ReportsController.php @@ -49,6 +49,8 @@ class ReportsController extends Controller return new Response($apiResp, $apiResp["meta"]["code"]); } + // $from_date = $req->input('from_date'); + // $to_date = $req->input('to_date'); $from_date = $req->input('from_date'); $to_date = $req->input('to_date'); $vid = $req->input('vid'); @@ -62,7 +64,7 @@ class ReportsController extends Controller -- mark the start of a trip when ignition=4 and previous ignition <> 4 CASE WHEN ignition = 4 - AND LAG(ignition, 1, 0) OVER (PARTITION BY vhc_id ORDER BY crt_s) <> 4 + AND LAG(ignition, 1, 0) OVER (PARTITION BY vhc_id ORDER BY crt_d) <> 4 THEN 1 ELSE 0 END AS trip_start FROM t_gps_tracks t @@ -70,13 +72,13 @@ class ReportsController extends Controller t.latitude IS NOT NULL AND t.longitude IS NOT NULL AND t.action = 'location' - AND t.crt_s BETWEEN ? AND ? + AND t.crt_d BETWEEN ? AND ? ) , numbered AS ( SELECT *, -- assign a trip_id by cumulative sum of trip_start - SUM(trip_start) OVER (PARTITION BY vhc_id ORDER BY crt_s) AS trip_id + SUM(trip_start) OVER (PARTITION BY vhc_id ORDER BY crt_d) AS trip_id FROM trips where ignition = 4 ), @@ -88,10 +90,10 @@ class ReportsController extends Controller v.nopol1, vhc_id, -- trip_id, - ROW_NUMBER() OVER (PARTITION BY v.id ORDER BY MIN(a.crt_s)) AS trip_id, + ROW_NUMBER() OVER (PARTITION BY v.id ORDER BY MIN(a.crt_d)) AS trip_id, SUM(pre_milleage) AS mileage, - MIN(a.crt_s) AS start, - MAX(a.crt_s) AS finish, + MIN(a.crt_d) AS start, + MAX(a.crt_d) AS finish, MIN(a.vhc_milleage) AS startMileage, MAX(a.vhc_milleage) AS finishMileage, (SELECT fulladdress FROM t_gps_tracks_address WHERE master_id = MIN(a.id) LIMIT 1) AS startLoc, @@ -202,7 +204,7 @@ class ReportsController extends Controller $d = [$vid, $tgl0, $tgl1]; $list = DB::select("SELECT - t.crt_s , t.latitude, t.longitude, t.speed, + t.crt_d , t.latitude, t.longitude, t.speed, tgta.fulladdress, t.pre_milleage, t.vhc_milleage FROM @@ -213,23 +215,23 @@ class ReportsController extends Controller and t.latitude IS NOT NULL AND t.longitude IS NOT NULL AND t.action = 'location' - AND t.crt_s BETWEEN ? AND ? - ORDER BY t.crt_s asc + AND t.crt_d BETWEEN ? AND ? + ORDER BY t.crt_d asc ", $d); $start = [ - 'time' => $list[0]->crt_s, + 'time' => $list[0]->crt_d, 'fulladdress' => urldecode($list[0]->fulladdress), 'mileage' => $list[0]->vhc_milleage, ]; $finish = [ - 'time' => $list[count($list) - 1]->crt_s, + 'time' => $list[count($list) - 1]->crt_d, 'fulladdress' => urldecode($list[count($list) - 1]->fulladdress), 'mileage' => $list[count($list) - 1]->vhc_milleage, ]; - $t0 = Carbon::createFromTimestamp($list[0]->crt_s); - $t1 = Carbon::createFromTimestamp($list[count($list) - 1]->crt_s); + $t0 = Carbon::createFromTimestamp($list[0]->crt_d); + $t1 = Carbon::createFromTimestamp($list[count($list) - 1]->crt_d); $diff = $t1->diff($t0); $hours = $diff->h + ($diff->days * 24); // include days converted to hours $minutes = $diff->i; @@ -285,7 +287,7 @@ class ReportsController extends Controller try { $list = DB::select("SELECT tv.name, tv.nopol1, - t.crt_s, t.speed, tgta.fulladdress, + t.crt_d, t.speed, tgta.fulladdress, tvd.speed_limit, tvd.pool_code, tvd.dc_code from t_gps_tracks t @@ -295,11 +297,11 @@ class ReportsController extends Controller WHERE t.action = 'location' and t.speed != 0 - AND t.crt_s BETWEEN ? AND ? + AND t.crt_d BETWEEN ? AND ? and if(? , tv.id = ? , 1=1) -- and t.speed > tvd.speed_limit having t.speed >= tvd.speed_limit - ORDER BY t.crt_s + ORDER BY t.crt_d ", [$from_date, $to_date, $vid, $vid]); // // RETURN 1 - LIST diff --git a/resources/views/app/app.blade.php b/resources/views/app/app.blade.php index 98fcee2..af2d868 100755 --- a/resources/views/app/app.blade.php +++ b/resources/views/app/app.blade.php @@ -77,6 +77,7 @@ +