This commit is contained in:
meusinfirmary
2025-06-20 01:17:16 +09:00
parent a4276d9a6a
commit ed42967eef
5 changed files with 350 additions and 235 deletions

View File

@ -370,7 +370,61 @@ class Tracks extends Model
$query .= " ;";
return DB::select($query, $params);
// return DB::select($query, $params);
$rawTracks = DB::select($query, $params);
$cleanTracks = self::filterJumps($rawTracks);
if (isset($filter["limit"])) {
return array_slice($cleanTracks, 0, $filter["limit"]);
}
return $cleanTracks;
}
public static function haversineDistance($lat1, $lon1, $lat2, $lon2)
{
$earthRadius = 6371000; // meters
$lat1 = deg2rad($lat1);
$lon1 = deg2rad($lon1);
$lat2 = deg2rad($lat2);
$lon2 = deg2rad($lon2);
$dlat = $lat2 - $lat1;
$dlon = $lon2 - $lon1;
$a = sin($dlat / 2) ** 2 + cos($lat1) * cos($lat2) * sin($dlon / 2) ** 2;
$c = 2 * atan2(sqrt($a), sqrt(1 - $a));
return $earthRadius * $c;
}
public static function filterJumps($points, $maxDistance = 50, $maxTimeGap = 10)
{
$filtered = [];
$last = null;
foreach ($points as $p) {
if (!$last) {
$filtered[] = $p;
$last = $p;
continue;
}
$distance = self::haversineDistance(
$last->latitude,
$last->longitude,
$p->latitude,
$p->longitude
);
$timeGap = $p->lst_loc_crt - $last->lst_loc_crt;
if ($distance <= $maxDistance || $timeGap > $maxTimeGap) {
$filtered[] = $p;
$last = $p;
}
}
return $filtered;
}
public static function nearestInCircle($lat, $lng, $rad, $filter = [])

View File

@ -766,13 +766,13 @@
},
calcPeriodeDate: function(startDate, endDate) {
if (startDate.format('YYYY-MM-DD') === 'Invalid date') {
Helper.toast('Warning', 'just now', 'Tanggal mulai periode tidak valid');
Helper.toast('Warning', 'just now', 'Start date of the period is not valid');
return {
isValid: false
};
}
if (endDate.format('YYYY-MM-DD') === 'Invalid date') {
Helper.toast('Warning', 'just now', 'Tanggal akhir periode tidak valid');
Helper.toast('Warning', 'just now', 'End date of the period is not valid');
return {
isValid: false
};
@ -781,13 +781,13 @@
const duration = moment.duration(endDate.diff(startDate));
const diffDays = duration.days();
if (diffDays > 30) {
Helper.toast('Warning', 'just now', 'Maksimal periode 1 bulan');
Helper.toast('Warning', 'just now', 'Maximum period is 1 month');
return {
isValid: false
};
}
if (diffDays < 0) {
Helper.toast('Warning', 'just now', 'Rentang periode tidak valid');
Helper.toast('Warning', 'just now', 'Invalid period range');
return {
isValid: false
};
@ -2606,7 +2606,7 @@
let startMarker = Leaflet.addMarkers({
lat: start.latitude,
lng: start.longitude,
label: `<b>Titik Awal</b><br>${start.nopol1} ${start.nopol2} ${start.nopol3}<br>${moment.unix(start?.lst_loc_crt).format('DD MMM YYYY HH:mm')}<br>Speed: ${(typeof start.lst_speed != 'undefined') ? start.lst_speed : '0'}<br>${Number(start.latitude).toFixed(5)},${Number(start.longitude).toFixed(6)}<br>${decodeURIComponent(start.fulladdress || 'address')}`,
label: `<b>Start Poin</b><br>${start.nopol1} ${start.nopol2} ${start.nopol3}<br>${moment.unix(start?.lst_loc_crt).format('DD MMM YYYY HH:mm')}<br>Speed: ${(typeof start.lst_speed != 'undefined') ? start.lst_speed : '0'}<br>${Number(start.latitude).toFixed(5)},${Number(start.longitude).toFixed(6)}<br>${decodeURIComponent(start.fulladdress || 'address')}`,
options: {
icon: Icon.titikAwal(),
// rotationAngle: 290
@ -2615,7 +2615,7 @@
let finishMarker = Leaflet.addMarkers({
lat: finish.latitude,
lng: finish.longitude,
label: `<b>Titik Akhir</b><br>${finish.nopol1} ${finish.nopol2} ${finish.nopol3}<br>${moment.unix(finish?.lst_loc_crt).format('DD MMM YYYY HH:mm')}<br>Speed: ${(typeof finish.lst_speed != 'undefined') ? finish.lst_speed : '0'}<br>${Number(finish.latitude).toFixed(5)},${Number(finish.longitude).toFixed(6)}<br>${decodeURIComponent(finish.fulladdress || 'address')}`,
label: `<b>End Poin</b><br>${finish.nopol1} ${finish.nopol2} ${finish.nopol3}<br>${moment.unix(finish?.lst_loc_crt).format('DD MMM YYYY HH:mm')}<br>Speed: ${(typeof finish.lst_speed != 'undefined') ? finish.lst_speed : '0'}<br>${Number(finish.latitude).toFixed(5)},${Number(finish.longitude).toFixed(6)}<br>${decodeURIComponent(finish.fulladdress || 'address')}`,
options: {
icon: Icon.titikAkhir()
}

View File

@ -78,8 +78,7 @@
<tr class="">
<td class="">1</td>
<td class="">
<a href="{{ route('view_keuangan_billing_view') }}"
class="">
<a href="{{ route('view_keuangan_billing_view') }}" class="">
<span class="icon ion-eye text-danger fz-16"></span>
</a>
</td>
@ -177,14 +176,20 @@
},
evPeriodeDate: function() {
$('#filter-startDate').on('change', function(e) {
const { isValid, data } = Filter.calcPeriodeDate(moment($('#filter-startDate').val()), moment($('#filter-endDate').val()))
const {
isValid,
data
} = Filter.calcPeriodeDate(moment($('#filter-startDate').val()), moment($('#filter-endDate').val()))
if (!isValid) return false;
State.periodeStartDate = data.startDate.unix();
State.periodeEndDate = data.endDate.unix();
DTable.reload();
});
$('#filter-endDate').on('change', function(e) {
const { isValid, data } = Filter.calcPeriodeDate(moment($('#filter-startDate').val()), moment($('#filter-endDate').val()))
const {
isValid,
data
} = Filter.calcPeriodeDate(moment($('#filter-startDate').val()), moment($('#filter-endDate').val()))
if (!isValid) return false;
State.periodeStartDate = data.startDate.unix();
State.periodeEndDate = data.endDate.unix();
@ -194,23 +199,37 @@
calcPeriodeDate: function(startDate, endDate) {
if (startDate.format('YYYY-MM-DD') === 'Invalid date') {
Helper.toast('Warning', 'just now', 'Tanggal mulai periode tidak valid');
return { isValid: false };
return {
isValid: false
};
}
if (endDate.format('YYYY-MM-DD') === 'Invalid date') {
Helper.toast('Warning', 'just now', 'Tanggal akhir periode tidak valid');
return { isValid: false };
Helper.toast('Warning', 'just now', 'End date of the period is not valid');
return {
isValid: false
};
}
const duration = moment.duration(endDate.diff(startDate));
const diffDays = duration.days();
if (diffDays > 30) {
Helper.toast('Warning', 'just now', 'Maksimal periode 1 bulan');
return { isValid: false };
return {
isValid: false
};
}
if (diffDays < 0) {
Helper.toast('Warning', 'just now', 'Rentang periode tidak valid');
return { isValid: false };
return {
isValid: false
};
}
return { isValid: true, data: { startDate, endDate } };
return {
isValid: true,
data: {
startDate,
endDate
}
};
},
}

View File

@ -187,14 +187,20 @@
},
evPeriodeDate: function() {
$('#filter-startDate').on('change', function(e) {
const { isValid, data } = Filter.calcPeriodeDate(moment($('#filter-startDate').val()), moment($('#filter-endDate').val()))
const {
isValid,
data
} = Filter.calcPeriodeDate(moment($('#filter-startDate').val()), moment($('#filter-endDate').val()))
if (!isValid) return false;
State.periodeStartDate = data.startDate.unix();
State.periodeEndDate = data.endDate.unix();
DTable.reload();
});
$('#filter-endDate').on('change', function(e) {
const { isValid, data } = Filter.calcPeriodeDate(moment($('#filter-startDate').val()), moment($('#filter-endDate').val()))
const {
isValid,
data
} = Filter.calcPeriodeDate(moment($('#filter-startDate').val()), moment($('#filter-endDate').val()))
if (!isValid) return false;
State.periodeStartDate = data.startDate.unix();
State.periodeEndDate = data.endDate.unix();
@ -204,23 +210,37 @@
calcPeriodeDate: function(startDate, endDate) {
if (startDate.format('YYYY-MM-DD') === 'Invalid date') {
Helper.toast('Warning', 'just now', 'Tanggal mulai periode tidak valid');
return { isValid: false };
return {
isValid: false
};
}
if (endDate.format('YYYY-MM-DD') === 'Invalid date') {
Helper.toast('Warning', 'just now', 'Tanggal akhir periode tidak valid');
return { isValid: false };
Helper.toast('Warning', 'just now', 'End date of the period is not valid');
return {
isValid: false
};
}
const duration = moment.duration(endDate.diff(startDate));
const diffDays = duration.days();
if (diffDays > 30) {
Helper.toast('Warning', 'just now', 'Maksimal periode 1 bulan');
return { isValid: false };
return {
isValid: false
};
}
if (diffDays < 0) {
Helper.toast('Warning', 'just now', 'Rentang periode tidak valid');
return { isValid: false };
return {
isValid: false
};
}
return { isValid: true, data: { startDate, endDate } };
return {
isValid: true,
data: {
startDate,
endDate
}
};
},
}
@ -355,21 +375,20 @@
$('#totAllOut').text((new Intl.NumberFormat('id-ID')).format(total_out));
},
eventChildRow: function() {
$('#tLedgerBl tbody').on('click', 'td.dt-control', function () {
$('#tLedgerBl tbody').on('click', 'td.dt-control', function() {
var tr = $(this).closest('tr');
var row = DTable.table.row( tr );
var row = DTable.table.row(tr);
if ( row.child.isShown() ) {
if (row.child.isShown()) {
// This row is already open - close it
row.child.hide();
tr.removeClass('shown');
}
else {
} else {
// Open this row
row.child( DTable.formatChildRow(row.data()) ).show();
row.child(DTable.formatChildRow(row.data())).show();
tr.addClass('shown');
}
} );
});
},
formatChildRow: function(d) {
// `d` is the original data object for the row
@ -393,7 +412,10 @@
if (item.calc_to_vdr == State.calc_to_vdr.yes && item.is_aprv != State.is_aprv.yes) continue;
if (item.invc_to_client == State.invc_to_client.yes && item.is_bill_aprv != State.is_aprv.yes) continue;
let small_desc = '', amt_in = 0, amt_out = 0, amt_bl = 0;
let small_desc = '',
amt_in = 0,
amt_out = 0,
amt_bl = 0;
if (item.is_bill_paid == State.is_a_item_paid.paid) {
amt_in = item.amt_in;
small_desc += `<br><small>waktu dibayarkan <span class="text-success">${moment.unix(item.paid_bill_at).format('DD MMM YYYY HH:mm:ss')}</span></small>`;

View File

@ -192,14 +192,20 @@
},
evPeriodeDate: function() {
$('#filter-startDate').on('change', function(e) {
const { isValid, data } = Filter.calcPeriodeDate(moment($('#filter-startDate').val()), moment($('#filter-endDate').val()))
const {
isValid,
data
} = Filter.calcPeriodeDate(moment($('#filter-startDate').val()), moment($('#filter-endDate').val()))
if (!isValid) return false;
State.periodeStartDate = data.startDate.unix();
State.periodeEndDate = data.endDate.unix();
DTable.reload();
});
$('#filter-endDate').on('change', function(e) {
const { isValid, data } = Filter.calcPeriodeDate(moment($('#filter-startDate').val()), moment($('#filter-endDate').val()))
const {
isValid,
data
} = Filter.calcPeriodeDate(moment($('#filter-startDate').val()), moment($('#filter-endDate').val()))
if (!isValid) return false;
State.periodeStartDate = data.startDate.unix();
State.periodeEndDate = data.endDate.unix();
@ -209,23 +215,37 @@
calcPeriodeDate: function(startDate, endDate) {
if (startDate.format('YYYY-MM-DD') === 'Invalid date') {
Helper.toast('Warning', 'just now', 'Tanggal mulai periode tidak valid');
return { isValid: false };
return {
isValid: false
};
}
if (endDate.format('YYYY-MM-DD') === 'Invalid date') {
Helper.toast('Warning', 'just now', 'Tanggal akhir periode tidak valid');
return { isValid: false };
Helper.toast('Warning', 'just now', 'End date of the period is not valid');
return {
isValid: false
};
}
const duration = moment.duration(endDate.diff(startDate));
const diffDays = duration.days();
if (diffDays > 30) {
Helper.toast('Warning', 'just now', 'Maksimal periode 1 bulan');
return { isValid: false };
return {
isValid: false
};
}
if (diffDays < 0) {
Helper.toast('Warning', 'just now', 'Rentang periode tidak valid');
return { isValid: false };
return {
isValid: false
};
}
return { isValid: true, data: { startDate, endDate } };
return {
isValid: true,
data: {
startDate,
endDate
}
};
},
}