report, timezone
This commit is contained in:
@ -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];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user