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

View File

@ -321,6 +321,30 @@
// Radius toleransi "berdekatan" dalam meter — sesuaikan sesuai kebutuhan // Radius toleransi "berdekatan" dalam meter — sesuaikan sesuai kebutuhan
const SITE_PROXIMITY_RADIUS_METERS = 500; 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 // Hitung jarak antara 2 koordinat (formula Haversine), hasil dalam meter
function getDistanceMeters(lat1, lon1, lat2, lon2) { function getDistanceMeters(lat1, lon1, lat2, lon2) {
const R = 6371000; // radius bumi (meter) const R = 6371000; // radius bumi (meter)
@ -470,12 +494,15 @@
{ {
data: 'start', data: 'start',
render: (data, type, row, meta) => { 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 // saat export, hanya tampilkan lokasi tanpa tanggal/jam
if (type === 'export') { if (type === 'export') {
const nearestSite = findNearestSite( const nearestSite = findNearestSite(startLat, startLng);
row.start_latitude,
row.start_longitude
);
if (nearestSite) { if (nearestSite) {
return formatSiteLabel(nearestSite); return formatSiteLabel(nearestSite);
@ -483,10 +510,8 @@
return Helper.shortenText(decodeURIComponent(row.startLoc || return Helper.shortenText(decodeURIComponent(row.startLoc ||
'address'), 255) || "-"; 'address'), 255) || "-";
} }
const nearestSite = findNearestSite(
row.start_latitude, const nearestSite = findNearestSite(startLat, startLng);
row.start_longitude
);
if (nearestSite) { if (nearestSite) {
return formatSiteLabel(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', data: 'finish',
render: (data, type, row) => { render: (data, type, row) => {
// console.log(row.fulladdress); // Parse finish_lat_long -> { lat, lng }
// console.log(row.latitude); const {
// console.log(row.longitude); lat: finishLat,
// console.log("End Loc : ",row.endLoc) lng: finishLng
} = parseLatLong(row.finish_lat_long);
// Saat export Excel // Saat export Excel
if (type === 'export') { if (type === 'export') {
const nearestSite = findNearestSite(finishLat, finishLng);
const nearestSite = findNearestSite(
row.finish_latitude,
row.finish_longitude
);
if (nearestSite) { if (nearestSite) {
return formatSiteLabel(nearestSite); return formatSiteLabel(nearestSite);
@ -538,10 +545,7 @@
) || '-'; ) || '-';
} }
const nearestSite = findNearestSite( const nearestSite = findNearestSite(finishLat, finishLng);
row.finish_latitude,
row.finish_longitude
);
if (nearestSite) { if (nearestSite) {
return formatSiteLabel(nearestSite); return formatSiteLabel(nearestSite);
@ -558,7 +562,7 @@
255 255
) || '-' ) || '-'
} }
`; `;
} }
}, },
{ {