update & fix

This commit is contained in:
Pringgosutono
2025-09-11 10:34:45 +07:00
parent 5d585a6e26
commit bc92ed5234
2 changed files with 17 additions and 43 deletions

View File

@ -56,8 +56,7 @@ class ReportsController extends Controller
// $to_date = 1756745940; // $to_date = 1756745940;
try { try {
$q = " $list = DB::select("WITH trips AS (
WITH trips AS (
SELECT SELECT
t.*, t.*,
-- mark the start of a trip when ignition=4 and previous ignition <> 4 -- mark the start of a trip when ignition=4 and previous ignition <> 4
@ -109,10 +108,7 @@ class ReportsController extends Controller
FROM agg agg FROM agg agg
join t_vehicles_detail tvd on tvd.vid = agg.id join t_vehicles_detail tvd on tvd.vid = agg.id
ORDER BY agg.id, trip_id ORDER BY agg.id, trip_id
"; ", [$from_date, $to_date, $vid, $vid]);
$d = [$from_date, $to_date, $vid, $vid];
$list = DB::select($q, $d);
// // RETURN 1 - LIST // // RETURN 1 - LIST
// if($req->type != 'report'){ // if($req->type != 'report'){
@ -200,8 +196,8 @@ class ReportsController extends Controller
$tgl1 = $req->tgl1; $tgl1 = $req->tgl1;
$nopol1 = $req->nopol1; $nopol1 = $req->nopol1;
$q = " $d = [$vid, $tgl0, $tgl1];
select $list = DB::select("SELECT
t.crt_s , t.latitude, t.longitude, t.speed, t.crt_s , t.latitude, t.longitude, t.speed,
tgta.fulladdress, tgta.fulladdress,
t.pre_milleage, t.vhc_milleage t.pre_milleage, t.vhc_milleage
@ -215,9 +211,7 @@ class ReportsController extends Controller
AND t.action = 'location' AND t.action = 'location'
AND t.crt_s BETWEEN ? AND ? AND t.crt_s BETWEEN ? AND ?
ORDER BY t.crt_s asc ORDER BY t.crt_s asc
"; ", $d);
$d = [$vid, $tgl0, $tgl1];
$list = DB::select($q, $d);
$start = [ $start = [
'time' => date('d-m-Y H:i:s', $list[0]->crt_s), 'time' => date('d-m-Y H:i:s', $list[0]->crt_s),
@ -244,25 +238,6 @@ class ReportsController extends Controller
$polyline[] = [$item->latitude, $item->longitude]; $polyline[] = [$item->latitude, $item->longitude];
} }
// $q0 = "
// select
// t.crt_s , t.latitude, t.longitude, t.speed,
// tgta.fulladdress,
// t.pre_milleage, t.vhc_milleage
// FROM
// t_gps_tracks t
// join t_gps_tracks_address tgta on tgta.master_id = t.id
// WHERE
// t.vhc_id = ?
// 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
// ";
// $d = [$vid, $tgl0, $tgl1];
$data = [ $data = [
'nopol1' => $nopol1, 'nopol1' => $nopol1,
'vid' => $vid, 'vid' => $vid,
@ -310,8 +285,7 @@ class ReportsController extends Controller
$vid = $req->input('vid'); $vid = $req->input('vid');
try { try {
$q = " $list = DB::select("SELECT
select
tv.name, tv.nopol1, tv.name, tv.nopol1,
t.crt_s, t.speed, tgta.fulladdress, t.crt_s, t.speed, tgta.fulladdress,
tvd.speed_limit, tvd.pool_code, tvd.dc_code tvd.speed_limit, tvd.pool_code, tvd.dc_code
@ -328,10 +302,7 @@ class ReportsController extends Controller
-- and t.speed > tvd.speed_limit -- and t.speed > tvd.speed_limit
having t.speed >= tvd.speed_limit having t.speed >= tvd.speed_limit
ORDER BY t.crt_s ORDER BY t.crt_s
"; ", [$from_date, $to_date, $vid, $vid]);
$d = [$from_date, $to_date, $vid, $vid];
$list = DB::select($q, $d);
// // RETURN 1 - LIST // // RETURN 1 - LIST
// if($req->type != 'report'){ // if($req->type != 'report'){

View File

@ -100,12 +100,12 @@
<script> <script>
$(document).ready(function(){ $(document).ready(function(){
setTimeout(function () { setTimeout(() => {
window.dispatchEvent(new Event('resize')); map.invalidateSize(); // force Leaflet to recalc
}, 1000); map.fitBounds(polyline.getBounds());
}, 200);
const linesData = (@json($list)); const linesData = (@json($list));
console.log(linesData);
// 1) Initialize map // 1) Initialize map
const map = L.map("leafMap").setView([-8.90507, 125.9945732], 10) const map = L.map("leafMap").setView([-8.90507, 125.9945732], 10)
@ -115,8 +115,10 @@
maxZoom: 20, maxZoom: 20,
}).addTo(map) }).addTo(map)
// // 3) Coordinates (Lat, Lng) for polyline // // // 3) Coordinates (Lat, Lng) for polyline
const points = linesData.map((point) => [point.latitude, point.longitude]) const points = linesData
.filter(p => p.latitude && p.longitude)
.map((point) => [point.latitude, point.longitude])
// // 4) Add polyline // // 4) Add polyline
const polyline = L.polyline(points, { const polyline = L.polyline(points, {
@ -145,6 +147,7 @@
// 5) Auto-fit map to polyline bounds // 5) Auto-fit map to polyline bounds
map.fitBounds(polyline.getBounds()) map.fitBounds(polyline.getBounds())
console.log("Points:", points)
console.log("Bounds:", polyline.getBounds())
}); });
</script> </script>