This commit is contained in:
wayanrivan
2026-07-08 17:12:44 +07:00
parent fb0bfed78b
commit 8d90b0d8a4
2 changed files with 71 additions and 68 deletions

View File

@ -167,7 +167,7 @@ class ReportsController extends Controller
// // and if(? , t.pool_code = ? , 1=1)
// // ", [$from_date, $to_date, $from_date, $to_date, $vid, $vid, $vt, $vt, $poolcode, $poolcode]);
// $sql =
// "WITH TotalMileage AS (
// "WITH TotalMileage AS (
// SELECT
// id,
// SUM(mileage) AS total_mileage,
@ -444,66 +444,66 @@ class ReportsController extends Controller
}
}
// public function view_report_trip_detail(Request $req)
// {
// $vid = $req->vid;
// $tgl0 = $req->tgl0;
// $tgl1 = $req->tgl1;
// $nopol1 = $req->nopol1;
public function view_report_trip_detail(Request $req)
{
$vid = $req->vid;
$tgl0 = $req->tgl0;
$tgl1 = $req->tgl1;
$nopol1 = $req->nopol1;
// $d = [$vid, $tgl0, $tgl1];
// $list = DB::select("SELECT
// t.crt_d , t.latitude, t.longitude, t.speed,
// tgta.fulladdress,
// t.pre_milleage, t.vhc_milleage, fuel_count
// FROM
// t_gps_tracks t
// left join t_gps_tracks_address tgta on tgta.master_id = t.id
// WHERE
// t.vhc_id = ?
// and t.latitude IS NOT NULL
// AND t.longitude IS NOT NULL
// AND t.action = 'location'
// AND t.crt_d BETWEEN ? AND ?
// ORDER BY t.crt_d asc
// ", $d);
$d = [$vid, $tgl0, $tgl1];
$list = DB::select("SELECT
t.crt_d , t.latitude, t.longitude, t.speed,
tgta.fulladdress,
t.pre_milleage, t.vhc_milleage, fuel_count
FROM
t_gps_tracks t
left join t_gps_tracks_address tgta on tgta.master_id = t.id
WHERE
t.vhc_id = ?
and t.latitude IS NOT NULL
AND t.longitude IS NOT NULL
AND t.action = 'location'
AND t.crt_d BETWEEN ? AND ?
ORDER BY t.crt_d asc
", $d);
// $start = [
// 'time' => $list[0]->crt_d,
// 'fulladdress' => urldecode($list[0]->fulladdress),
// 'mileage' => $list[0]->vhc_milleage,
// ];
// $finish = [
// 'time' => $list[count($list) - 1]->crt_d,
// 'fulladdress' => urldecode($list[count($list) - 1]->fulladdress),
// 'mileage' => $list[count($list) - 1]->vhc_milleage,
// ];
$start = [
'time' => $list[0]->crt_d,
'fulladdress' => urldecode($list[0]->fulladdress),
'mileage' => $list[0]->vhc_milleage,
];
$finish = [
'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_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;
// $duration = "{$hours} hour" . ($hours > 1 ? 's' : '') . " {$minutes} minute" . ($minutes > 1 ? '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;
$duration = "{$hours} hour" . ($hours > 1 ? 's' : '') . " {$minutes} minute" . ($minutes > 1 ? 's' : '');
// $distance = $list[count($list) - 1]->vhc_milleage - $list[0]->vhc_milleage;
// $fuel_consumed = $list[count($list) - 1]->fuel_count - $list[0]->fuel_count;
$distance = $list[count($list) - 1]->vhc_milleage - $list[0]->vhc_milleage;
$fuel_consumed = $list[count($list) - 1]->fuel_count - $list[0]->fuel_count;
// $data = [
// 'nopol1' => $nopol1,
// 'vid' => $vid,
// 'tgl0' => $tgl0,
// 'tgl1' => $tgl1,
// 'list' => $list,
// 'start' => $start,
// 'finish' => $finish,
// 'duration' => $duration,
// 'distance' => $distance,
// 'fuel_consumed' => $fuel_consumed,
// ];
// // dd($list);
// return view('menu_v1.reports._trip_detail', $data);
// }
$data = [
'nopol1' => $nopol1,
'vid' => $vid,
'tgl0' => $tgl0,
'tgl1' => $tgl1,
'list' => $list,
'start' => $start,
'finish' => $finish,
'duration' => $duration,
'distance' => $distance,
'fuel_consumed' => $fuel_consumed,
];
// dd($list);
return view('menu_v1.reports._trip_detail', $data);
}
public function view_report_abnormalities(Request $req)
{

View File

@ -484,6 +484,7 @@
// {
// 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 ||
@ -494,28 +495,30 @@
// ${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(row.fulladdress);
// console.log(row.latitude);
// console.log(row.longitude);
// console.log("End Loc : ",row.endLoc)
console.log('fulll data ',row)
// Saat export Excel
if (type === 'export') {
const nearestSite = findNearestSite(
row.latitude,
row.longitude
);
// const nearestSite = findNearestSite(
// row.latitude,
// row.longitude
// );
if (nearestSite) {
return formatSiteLabel(nearestSite);
}
// if (nearestSite) {
// return formatSiteLabel(nearestSite);
// }
return Helper.shortenText(
decodeURIComponent(row.fulladdress || 'address'),
decodeURIComponent(row.finishLoc || 'address'),
255
) || '-';
}