diff --git a/app/Http/Controllers/ReportsController.php b/app/Http/Controllers/ReportsController.php index 4def1d0..d9727ad 100644 --- a/app/Http/Controllers/ReportsController.php +++ b/app/Http/Controllers/ReportsController.php @@ -31,7 +31,6 @@ class ReportsController extends Controller return view('menu_v1.reports.vehicle_trips', $data); } - public function api_report_vehicle_trips_list(Request $req) { // Validate input @@ -63,7 +62,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_d) <> 4 + AND LAG(ignition, 1, 0) OVER (PARTITION BY vhc_id ORDER BY crt_s) <> 4 THEN 1 ELSE 0 END AS trip_start FROM t_gps_tracks t @@ -71,13 +70,13 @@ class ReportsController extends Controller t.latitude IS NOT NULL AND t.longitude IS NOT NULL AND t.action = 'location' - AND t.crt_d BETWEEN ? AND ? + AND t.crt_s 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_d) AS trip_id + SUM(trip_start) OVER (PARTITION BY vhc_id ORDER BY crt_s) AS trip_id FROM trips ), agg AS ( @@ -88,8 +87,10 @@ class ReportsController extends Controller vhc_id, trip_id, SUM(pre_milleage) AS mileage, - MIN(a.crt_d) AS start, - MAX(a.crt_d) AS finish, + MIN(a.crt_s) AS start, + MAX(a.crt_s) 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, (SELECT fulladdress FROM t_gps_tracks_address WHERE master_id = MAX(a.id) LIMIT 1) AS finishLoc FROM t_vehicles v @@ -101,11 +102,12 @@ class ReportsController extends Controller ) 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; - "; + SUM(mileage) OVER (PARTITION BY agg.id) AS total_mileage, + COUNT(trip_id) OVER (PARTITION BY agg.id) AS total_trip, + tvd.pool_code, tvd.dc_code + FROM agg agg + join t_vehicles_detail tvd on tvd.vid = agg.id + ORDER BY agg.id, trip_id "; $d = [$from_date, $to_date, $vid, $vid]; $list = DB::select($q, $d); @@ -189,6 +191,10 @@ class ReportsController extends Controller // return Responses::json(Responses::SERVER_ERROR, 'An error occurred while generating the report.', (object)[]); } } + public function view_report_trip_detail(Request $req) + { + return view('menu_v1.reports._trip_detail'); + } public function view_report_abnormalities(Request $req) { @@ -224,8 +230,8 @@ class ReportsController extends Controller $q = " select tv.name, tv.nopol1, - t.crt_d, t.speed, tgta.fulladdress, - tvd.speed_limit + t.crt_s, t.speed, tgta.fulladdress, + tvd.speed_limit, tvd.pool_code, tvd.dc_code from t_gps_tracks t left join t_vehicles tv on tv.id = t.vhc_id @@ -234,11 +240,11 @@ class ReportsController extends Controller WHERE t.action = 'location' and t.speed != 0 - AND t.crt_d BETWEEN ? AND ? + AND t.crt_s BETWEEN ? AND ? and if(? , tv.id = ? , 1=1) -- and t.speed > tvd.speed_limit having t.speed >= tvd.speed_limit - ORDER BY t.crt_d + ORDER BY t.crt_s "; $d = [$from_date, $to_date, $vid, $vid]; diff --git a/app/Models/Tracks.php b/app/Models/Tracks.php index c809e2e..f7f4369 100755 --- a/app/Models/Tracks.php +++ b/app/Models/Tracks.php @@ -433,7 +433,7 @@ class Tracks extends Model $params[] = $filter["company"]; } - $query .= " GROUP BY v.id ORDER BY tr.crt_d DESC LIMIT 500"; + $query .= " GROUP BY v.id ORDER BY tr.crt_s DESC LIMIT 500"; $list = DB::select($query, $params); // dd($list); @@ -542,7 +542,7 @@ class Tracks extends Model // array_push($params, strtotime('-24 hours', $now), $now); if (isset($filter["start_date"]) && isset($filter["end_date"])) { - $query .= " AND tr.crt_d BETWEEN ? AND ?"; + $query .= " AND tr.crt_s BETWEEN ? AND ?"; array_push($params, $filter["start_date"], $filter["end_date"]); } @@ -552,8 +552,8 @@ class Tracks extends Model } // last move based on last count data - $query .= " GROUP BY tr.crt_d"; - $query .= " ORDER BY tr.crt_d DESC"; + $query .= " GROUP BY tr.crt_s"; + $query .= " ORDER BY tr.crt_s DESC"; // $query .= " ORDER BY tr.id DESC"; // array_push($params, strtotime('-24 hours', $now), $now); diff --git a/resources/views/menu_v1/dashboard.blade.php b/resources/views/menu_v1/dashboard.blade.php index 03933a9..6861198 100755 --- a/resources/views/menu_v1/dashboard.blade.php +++ b/resources/views/menu_v1/dashboard.blade.php @@ -1363,7 +1363,7 @@ //
${(obj?.city_text || obj?.state_text || 'address')} - ${(obj?.postcode || 'postcode')}
//${moment.unix(obj?.lst_loc_crt).format('DD MMM YYYY HH:mm')}
// yang ini mix - //Device Time: ${moment.unix(obj?.lst_loc_crt_d).format('DD MMM YYYY HH:mm')}
+ //Device Time: ${moment.unix(obj?.lst_loc_crt_s).format('DD MMM YYYY HH:mm')}
//Server Time: ${moment.unix(obj?.lst_loc_crt_s).format('DD MMM YYYY HH:mm')}
//Pre Milleage: ${(obj.pre_milleage).toFixed(3)} Km
@@ -1371,7 +1371,7 @@ // //${obj.key_index}
- //Time: ${moment.unix(obj?.lst_loc_crt_d).format('DD MMM YYYY HH:mm')}
+ //Time: ${moment.unix(obj?.lst_loc_crt_s).format('DD MMM YYYY HH:mm')}
//Speed: ${(typeof obj.speed != 'undefined') ? obj.speed : '0'}
//${Number(obj.latitude).toFixed(5)} - ${Number(obj.longitude).toFixed(6)}
//${Helper.shortenText(decodeURIComponent(obj?.fulladdress || 'address'), 25)}
@@ -1384,7 +1384,7 @@ // //${arrIdx + 1}
- //Time: ${moment.unix(obj?.lst_loc_crt_d).format('DD MMM YYYY HH:mm:ss')}
+ //Time: ${moment.unix(obj?.lst_loc_crt_s).format('DD MMM YYYY HH:mm:ss')}
//${Number(obj.latitude).toFixed(5)} - ${Number(obj.longitude).toFixed(6)}
//${Helper.shortenText(decodeURIComponent(obj?.fulladdress || 'address'), 255)}
//Current speed: ${Number(obj.speed)}km/h
@@ -1395,7 +1395,7 @@${arrIdx + 1}
-Time: ${moment.unix(obj?.lst_loc_crt_d).format('DD MMM YYYY HH:mm:ss')}
+Time: ${moment.unix(obj?.lst_loc_crt_s).format('DD MMM YYYY HH:mm:ss')}
${Number(obj.latitude).toFixed(5)} - ${Number(obj.longitude).toFixed(6)}
${Helper.shortenText(decodeURIComponent(obj?.fulladdress || 'address'), 255)}
Current speed: ${Number(obj.speed)}km/h
@@ -1422,7 +1422,7 @@ lng: tr.longitude, // label: `${tr.key_index}