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_M = 6371000;
const EARTH_RADIUS_KM = 6371; const EARTH_RADIUS_KM = 6371;
const EARTH_RADIUS_MILES = 3959; // 3958.756 || 3959 || 3963 const EARTH_RADIUS_MILES = 3959; // 3958.756 || 3959 || 3963
const TIMEFIX = 25200;
/** /**
* Calculates the great-circle distance between two points, with * 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"]); 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'); $from_date = $req->input('from_date');
$to_date = $req->input('to_date'); $to_date = $req->input('to_date');
$vid = $req->input('vid'); $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 -- mark the start of a trip when ignition=4 and previous ignition <> 4
CASE CASE
WHEN ignition = 4 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 THEN 1 ELSE 0
END AS trip_start END AS trip_start
FROM t_gps_tracks t FROM t_gps_tracks t
@ -70,13 +72,13 @@ class ReportsController extends Controller
t.latitude IS NOT NULL t.latitude IS NOT NULL
AND t.longitude IS NOT NULL AND t.longitude IS NOT NULL
AND t.action = 'location' AND t.action = 'location'
AND t.crt_s BETWEEN ? AND ? AND t.crt_d BETWEEN ? AND ?
) )
, numbered AS ( , numbered AS (
SELECT SELECT
*, *,
-- assign a trip_id by cumulative sum of trip_start -- 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 FROM trips
where ignition = 4 where ignition = 4
), ),
@ -88,10 +90,10 @@ class ReportsController extends Controller
v.nopol1, v.nopol1,
vhc_id, vhc_id,
-- trip_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, SUM(pre_milleage) AS mileage,
MIN(a.crt_s) AS start, MIN(a.crt_d) AS start,
MAX(a.crt_s) AS finish, MAX(a.crt_d) AS finish,
MIN(a.vhc_milleage) AS startMileage, MIN(a.vhc_milleage) AS startMileage,
MAX(a.vhc_milleage) AS finishMileage, 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 = MIN(a.id) LIMIT 1) AS startLoc,
@ -202,7 +204,7 @@ class ReportsController extends Controller
$d = [$vid, $tgl0, $tgl1]; $d = [$vid, $tgl0, $tgl1];
$list = DB::select("SELECT $list = DB::select("SELECT
t.crt_s , t.latitude, t.longitude, t.speed, t.crt_d , t.latitude, t.longitude, t.speed,
tgta.fulladdress, tgta.fulladdress,
t.pre_milleage, t.vhc_milleage t.pre_milleage, t.vhc_milleage
FROM FROM
@ -213,23 +215,23 @@ class ReportsController extends Controller
and t.latitude IS NOT NULL and t.latitude IS NOT NULL
AND t.longitude IS NOT NULL AND t.longitude IS NOT NULL
AND t.action = 'location' AND t.action = 'location'
AND t.crt_s BETWEEN ? AND ? AND t.crt_d BETWEEN ? AND ?
ORDER BY t.crt_s asc ORDER BY t.crt_d asc
", $d); ", $d);
$start = [ $start = [
'time' => $list[0]->crt_s, 'time' => $list[0]->crt_d,
'fulladdress' => urldecode($list[0]->fulladdress), 'fulladdress' => urldecode($list[0]->fulladdress),
'mileage' => $list[0]->vhc_milleage, 'mileage' => $list[0]->vhc_milleage,
]; ];
$finish = [ $finish = [
'time' => $list[count($list) - 1]->crt_s, 'time' => $list[count($list) - 1]->crt_d,
'fulladdress' => urldecode($list[count($list) - 1]->fulladdress), 'fulladdress' => urldecode($list[count($list) - 1]->fulladdress),
'mileage' => $list[count($list) - 1]->vhc_milleage, 'mileage' => $list[count($list) - 1]->vhc_milleage,
]; ];
$t0 = Carbon::createFromTimestamp($list[0]->crt_s); $t0 = Carbon::createFromTimestamp($list[0]->crt_d);
$t1 = Carbon::createFromTimestamp($list[count($list) - 1]->crt_s); $t1 = Carbon::createFromTimestamp($list[count($list) - 1]->crt_d);
$diff = $t1->diff($t0); $diff = $t1->diff($t0);
$hours = $diff->h + ($diff->days * 24); // include days converted to hours $hours = $diff->h + ($diff->days * 24); // include days converted to hours
$minutes = $diff->i; $minutes = $diff->i;
@ -285,7 +287,7 @@ class ReportsController extends Controller
try { try {
$list = DB::select("SELECT $list = DB::select("SELECT
tv.name, tv.nopol1, 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 tvd.speed_limit, tvd.pool_code, tvd.dc_code
from from
t_gps_tracks t t_gps_tracks t
@ -295,11 +297,11 @@ class ReportsController extends Controller
WHERE WHERE
t.action = 'location' t.action = 'location'
and t.speed != 0 and t.speed != 0
AND t.crt_s BETWEEN ? AND ? AND t.crt_d BETWEEN ? AND ?
and if(? , tv.id = ? , 1=1) and if(? , tv.id = ? , 1=1)
-- 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_d
", [$from_date, $to_date, $vid, $vid]); ", [$from_date, $to_date, $vid, $vid]);
// // RETURN 1 - LIST // // RETURN 1 - LIST

View File

@ -77,6 +77,7 @@
<script src="{{ asset('assets/js/bootstrap-datepicker.min.js') }}"></script> <script src="{{ asset('assets/js/bootstrap-datepicker.min.js') }}"></script>
<script src="{{ asset('assets/js/helper.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/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> <script>
const AppState = { const AppState = {
@ -87,6 +88,7 @@
route_segment1: "{{ Request::segment(1) }}", route_segment1: "{{ Request::segment(1) }}",
route_segment2: "{{ Request::segment(2) }}", route_segment2: "{{ Request::segment(2) }}",
current_company: 0, // cptid current_company: 0, // cptid
TIMEFIX: new Date().getTimezoneOffset() * -60
} }
// function startTime() { // function startTime() {

View File

@ -76,7 +76,7 @@
</li> --> </li> -->
@foreach ($list as $item) @foreach ($list as $item)
<!-- <li class="list-group-item p-1 px-2"> <!-- <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">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">{{number_format($item->latitude, 6)}} - {{number_format($item->longitude, 6)}}</p>
<p class="text-muted mb-0 dtl-text">{{urldecode($item->fulladdress)}}</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"> <li class="list-group-item p-1 px-2">
<div class="row"> <div class="row">
<div class="col-4"> <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">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> <p class="text-muted mb-0 dtl-text">Current speed: {{$item->speed}} km/h</p>
</div> </div>
@ -108,7 +108,7 @@
<script> <script>
$(document).ready(function(){ $(document).ready(function(){
$('.time').each(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')); $(this).text(moment.unix(unix).format('DD MMM YYYY HH:mm:ss'));
}); });

View File

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