This commit is contained in:
wayanrivan
2026-07-14 10:55:42 +07:00
parent 583ea3b9a0
commit 32229a1b52
2 changed files with 133 additions and 134 deletions

View File

@ -178,10 +178,6 @@ class ReportsController extends Controller
)
SELECT
t.*,
ttll.start_latitude,
ttll.start_longitude,
ttll.finish_latitude,
ttll.finish_longitude,
tm.total_mileage,
tm.total_trip,
vt.name AS type_name,
@ -193,7 +189,6 @@ class ReportsController extends Controller
JOIN TotalMileage tm ON t.id = tm.id
LEFT JOIN t_vehicles tvt ON tvt.id = t.vhc_id
LEFT JOIN t_vehicles_cats vt ON vt.id = tvt.cat_id
LEFT JOIN t_trips_latitude_longitude ttll ON t.id = ttll.tripsid
WHERE
t.start BETWEEN ? AND ?
AND (? IS NULL OR t.id = ?)

View File

@ -321,6 +321,30 @@
// Radius toleransi "berdekatan" dalam meter — sesuaikan sesuai kebutuhan
const SITE_PROXIMITY_RADIUS_METERS = 500;
// Helper untuk parse string "lat, long" menjadi { lat, lng }
function parseLatLong(latLongStr) {
if (!latLongStr || typeof latLongStr !== 'string') {
return {
lat: null,
lng: null
};
}
const parts = latLongStr.split(',').map(part => parseFloat(part.trim()));
if (parts.length !== 2 || isNaN(parts[0]) || isNaN(parts[1])) {
return {
lat: null,
lng: null
};
}
return {
lat: parts[0],
lng: parts[1]
};
}
// Hitung jarak antara 2 koordinat (formula Haversine), hasil dalam meter
function getDistanceMeters(lat1, lon1, lat2, lon2) {
const R = 6371000; // radius bumi (meter)
@ -470,12 +494,15 @@
{
data: 'start',
render: (data, type, row, meta) => {
// Parse start_lat_long -> { lat, lng }
const {
lat: startLat,
lng: startLng
} = parseLatLong(row.start_lat_long);
// saat export, hanya tampilkan lokasi tanpa tanggal/jam
if (type === 'export') {
const nearestSite = findNearestSite(
row.start_latitude,
row.start_longitude
);
const nearestSite = findNearestSite(startLat, startLng);
if (nearestSite) {
return formatSiteLabel(nearestSite);
@ -483,10 +510,8 @@
return Helper.shortenText(decodeURIComponent(row.startLoc ||
'address'), 255) || "-";
}
const nearestSite = findNearestSite(
row.start_latitude,
row.start_longitude
);
const nearestSite = findNearestSite(startLat, startLng);
if (nearestSite) {
return formatSiteLabel(nearestSite);
@ -497,36 +522,18 @@
`;
}
},
// {
// data: 'finish',
// render: (data, type, row, meta) => {
// console.log(row)
// // saat export, hanya tampilkan lokasi tanpa tanggal/jam
// if (type === 'export') {
// return Helper.shortenText(decodeURIComponent(row.finishLoc ||
// 'address'), 255) || "-";
// }
// return `
// ${moment.unix(data + AppState.TIMEFIX).format('DD MMM YYYY HH:mm:ss')}<br>
// ${Helper.shortenText(decodeURIComponent(row.finishLoc || 'address'), 255) || "-"}
// `;
// }
// },
{
data: 'finish',
render: (data, type, row) => {
// console.log(row.fulladdress);
// console.log(row.latitude);
// console.log(row.longitude);
// console.log("End Loc : ",row.endLoc)
// Parse finish_lat_long -> { lat, lng }
const {
lat: finishLat,
lng: finishLng
} = parseLatLong(row.finish_lat_long);
// Saat export Excel
if (type === 'export') {
const nearestSite = findNearestSite(
row.finish_latitude,
row.finish_longitude
);
const nearestSite = findNearestSite(finishLat, finishLng);
if (nearestSite) {
return formatSiteLabel(nearestSite);
@ -538,10 +545,7 @@
) || '-';
}
const nearestSite = findNearestSite(
row.finish_latitude,
row.finish_longitude
);
const nearestSite = findNearestSite(finishLat, finishLng);
if (nearestSite) {
return formatSiteLabel(nearestSite);