This commit is contained in:
Pringgosutono
2025-09-18 13:41:30 +07:00
parent 0621b14b77
commit 0fe1cac8bf
5 changed files with 26 additions and 21 deletions

View File

@ -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

View File

@ -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

View File

@ -77,6 +77,7 @@
<script src="{{ asset('assets/js/bootstrap-datepicker.min.js') }}"></script>
<script src="{{ asset('assets/js/helper.js') }}"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-datetimepicker/2.5.20/jquery.datetimepicker.full.min.js" integrity="sha512-AIOTidJAcHBH2G/oZv9viEGXRqDNmfdPVPYOYKGy3fti0xIplnlgMHUGfuNRzC6FkzIo0iIxgFnr9RikFxK+sw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.34/moment-timezone-with-data.min.js"></script> -->
<script>
const AppState = {
@ -87,6 +88,7 @@
route_segment1: "{{ Request::segment(1) }}",
route_segment2: "{{ Request::segment(2) }}",
current_company: 0, // cptid
TIMEFIX: new Date().getTimezoneOffset() * -60
}
// function startTime() {

View File

@ -76,7 +76,7 @@
</li> -->
@foreach ($list as $item)
<!-- <li class="list-group-item p-1 px-2">
<p class="text-bold mb-0">Time: {{date('d-m-Y H:i:s', $item->crt_s)}}</p>
<p class="text-bold mb-0">Time: {{date('d-m-Y H:i:s', $item->crt_d)}}</p>
<p class="text-muted mb-0 dtl-text">Vehicle Mileage: {{number_format($item->vhc_milleage, 2)}} km</p>
<p class="text-muted mb-0 dtl-text">{{number_format($item->latitude, 6)}} - {{number_format($item->longitude, 6)}}</p>
<p class="text-muted mb-0 dtl-text">{{urldecode($item->fulladdress)}}</p>
@ -85,7 +85,7 @@
<li class="list-group-item p-1 px-2">
<div class="row">
<div class="col-4">
<p class="text-bold mb-0 dtl-text">Time: <span class="time">{{ $item->crt_s }}</span></p>
<p class="text-bold mb-0 dtl-text">Time: <span class="time">{{ $item->crt_d }}</span></p>
<p class="text-muted mb-0 dtl-text">Vehicle Mileage: {{number_format($item->vhc_milleage, 2)}} km</p>
<p class="text-muted mb-0 dtl-text">Current speed: {{$item->speed}} km/h</p>
</div>
@ -108,7 +108,7 @@
<script>
$(document).ready(function(){
$('.time').each(function () {
const unix = $(this).text().trim();
const unix = parseInt($(this).text().trim());
$(this).text(moment.unix(unix).format('DD MMM YYYY HH:mm:ss'));
});

View File

@ -49,14 +49,14 @@
<div class="form-group">
<label class="text-muted">From</label>
<!-- default today -->
<!-- <input class="form-control" id="tgl0" value="12-09-2025 00:00"> -->
<!-- <input class="form-control" id="tgl0" value="02-09-2025 00:00"> -->
<input class="form-control" id="tgl0" value="{{ date('d-m-Y 00:00') }}">
</div>
</div>
<div class="col-2">
<div class="form-group">
<label class="text-muted">To</label>
<!-- <input class="form-control" id="tgl1" value="12-09-2025 23:00"> -->
<!-- <input class="form-control" id="tgl1" value="02-09-2025 23:00"> -->
<input class="form-control" id="tgl1" value="{{ date('d-m-Y 23:59') }}">
</div>
</div>