report abnormalities

This commit is contained in:
Pringgosutono
2025-09-03 17:25:43 +07:00
parent 3ad22e0cf5
commit c492711d83
5 changed files with 468 additions and 38 deletions

View File

@ -22,11 +22,11 @@ class ReportsController extends Controller
{
public function view_report_vehicle_trips(Request $req)
{
$q = "select id, nopol1 from t_vehicles WHERE dlt is null order by nopol1";
$listNopol = DB::select($q);
$data = [
// 'lanes' => ConfRates::getLanesActive(),
// 'provs' => Region::listProv(),
// 'vendors' => Users::getUsersActiveByRole(Users::ROLE_VENDOR),
// 'truck_types' => ConfTruckTypes::listTruckTypes(ConfTruckTypes::IS_ACTIVE),
'listNopol' => $listNopol,
];
return view('menu_v1.reports.vehicle_trips', $data);
@ -49,10 +49,9 @@ class ReportsController extends Controller
return new Response($apiResp, $apiResp["meta"]["code"]);
}
$from_date = $req->input('from_date');
$to_date = $req->input('to_date');
$vid = $req->input('vid');
// $from_date = 1756054800;
// $to_date = 1756745940;
@ -81,19 +80,25 @@ class ReportsController extends Controller
SUM(trip_start) OVER (PARTITION BY vhc_id ORDER BY crt_d) AS trip_id
FROM trips
)
SELECT
select
v.id,
coalesce(max(a.trip_id), 0) numOfTrip,
SUM(pre_milleage) AS total_milleage,
v.name, v.nopol1
-- coalesce(max(a.trip_id), 0) numOfTrip,
-- SUM(pre_milleage) AS total_milleage,
v.name, v.nopol1,
vhc_id, trip_id,
sum(pre_milleage) milleage, min(a.crt_d ) start, max(a.crt_d ) finish,
(select fulladdress from t_gps_tracks_address where master_id = min(a.id) limit 1) startLoc,
(select fulladdress from t_gps_tracks_address where master_id = max(a.id) limit 1) finishLoc
FROM
t_vehicles v
left join numbered a on a.vhc_id = v.id
WHERE v.dlt is null
GROUP BY v.id
ORDER BY v.id;
";
$d = [$from_date, $to_date];
WHERE
v.dlt is null and trip_id != 0
and if(? , v.id = ? , 1=1)
GROUP BY v.id, a.trip_id
ORDER BY v.id
";
$d = [$from_date, $to_date, $vid, $vid];
$list = DB::select($q, $d);
@ -177,5 +182,72 @@ class ReportsController extends Controller
}
}
public function view_report_abnormalities(Request $req)
{
$q = "select id, nopol1 from t_vehicles WHERE dlt is null order by nopol1";
$listNopol = DB::select($q);
$data = [
'listNopol' => $listNopol,
];
return view('menu_v1.reports.abnormalities', $data);
}
public function api_report_abnormalities_list(Request $req)
{
// Validate input
$rules = [
// 'from_date' => 'required|date',
// 'to_date' => 'required|date|after_or_equal:from_date',
'type' => 'nullable|in:report,list', // enum "report", "list". nullable default "list"
];
$isValidInput = Validator::make($req->all(), $rules);
if (!$isValidInput->passes()) {
$apiResp = Responses::bad_input($isValidInput->messages()->first());
return new Response($apiResp, $apiResp["meta"]["code"]);
}
$from_date = $req->input('from_date');
$to_date = $req->input('to_date');
$vid = $req->input('vid');
try {
$q = "
select
tv.name, tv.nopol1,
t.crt_d, t.speed, tgta.fulladdress,
tvd.speed_limit
from
t_gps_tracks t
left join t_vehicles tv on tv.id = t.vhc_id
left join t_vehicles_detail tvd on tvd.vid = tv.id
left join t_gps_tracks_address tgta on tgta.master_id = t.id
WHERE
t.action = 'location'
and t.speed != 0
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_d
";
$d = [$from_date, $to_date, $vid, $vid];
$list = DB::select($q, $d);
// // RETURN 1 - LIST
// if($req->type != 'report'){
$apiResp = Responses::success("success list abnormalities report");
$apiResp["data"] = $list;
return new Response($apiResp, $apiResp["meta"]["code"]);
// }
} catch (\Exception $e) {
$apiResp = Responses::error($e->getMessage());
return new Response($apiResp, $apiResp["meta"]["code"]);
// return Responses::json(Responses::SERVER_ERROR, 'An error occurred while generating the report.', (object)[]);
}
}
}