detail trip

This commit is contained in:
Pringgosutono
2025-09-11 10:11:42 +07:00
parent 64235d08f5
commit 5d585a6e26
3 changed files with 154 additions and 5434 deletions

View File

@ -17,6 +17,7 @@ use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithStyles;
use Maatwebsite\Excel\Concerns\WithCustomStartCell;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use Carbon\Carbon;
class ReportsController extends Controller
{
@ -107,7 +108,8 @@ class ReportsController extends Controller
tvd.pool_code, tvd.dc_code
FROM agg agg
join t_vehicles_detail tvd on tvd.vid = agg.id
ORDER BY agg.id, trip_id ";
ORDER BY agg.id, trip_id
";
$d = [$from_date, $to_date, $vid, $vid];
$list = DB::select($q, $d);
@ -193,7 +195,88 @@ class ReportsController extends Controller
}
public function view_report_trip_detail(Request $req)
{
return view('menu_v1.reports._trip_detail');
$vid = $req->vid;
$tgl0 = $req->tgl0;
$tgl1 = $req->tgl1;
$nopol1 = $req->nopol1;
$q = "
select
t.crt_s , t.latitude, t.longitude, t.speed,
tgta.fulladdress,
t.pre_milleage, t.vhc_milleage
FROM
t_gps_tracks t
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_s BETWEEN ? AND ?
ORDER BY t.crt_s asc
";
$d = [$vid, $tgl0, $tgl1];
$list = DB::select($q, $d);
$start = [
'time' => date('d-m-Y H:i:s', $list[0]->crt_s),
'fulladdress' => urldecode($list[0]->fulladdress),
'mileage' => $list[0]->vhc_milleage,
];
$finish = [
'time' => date('d-m-Y H:i:s', $list[count($list) - 1]->crt_s),
'fulladdress' => urldecode($list[count($list) - 1]->fulladdress),
'mileage' => $list[count($list) - 1]->vhc_milleage,
];
$t0 = Carbon::createFromTimestamp($list[0]->crt_s);
$t1 = Carbon::createFromTimestamp($list[count($list) - 1]->crt_s);
$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;
$polyline = [];
foreach ($list as $item) {
$polyline[] = [$item->latitude, $item->longitude];
}
// $q0 = "
// select
// t.crt_s , t.latitude, t.longitude, t.speed,
// tgta.fulladdress,
// t.pre_milleage, t.vhc_milleage
// FROM
// t_gps_tracks t
// 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_s BETWEEN ? AND ?
// ORDER BY t.crt_s asc
// ";
// $d = [$vid, $tgl0, $tgl1];
$data = [
'nopol1' => $nopol1,
'vid' => $vid,
'tgl0' => $tgl0,
'tgl1' => $tgl1,
'list' => $list,
'start' => $start,
'finish' => $finish,
'duration' => $duration,
'distance' => $distance,
'polyline' => json_encode($polyline),
];
// dd($list);
return view('menu_v1.reports._trip_detail', $data);
}
public function view_report_abnormalities(Request $req)

File diff suppressed because it is too large Load Diff

View File

@ -94,8 +94,8 @@
<th class="">Duration</th>
<th class="">Start (km)</th>
<th class="">Finish (km)</th>
<th class="">Mileage (km)</th>
<th class="" hidden>Detail</th>
<th class="">Distance (km)</th>
<th class="">Detail</th>
</tr>
</thead>
<!-- <tbody>
@ -246,9 +246,10 @@
const vid = $(this).data('vid');
const tgl0 = $(this).data('tgl0');
const tgl1 = $(this).data('tgl1');
const nopol1 = $(this).data('nopol1');
// $("#mdlDetailTrip").load("{{ route('view_report_trip_detail') }}");
$('#mdlDetailTrip').empty().load("{{ route('view_report_trip_detail') }}", `vid=${vid}&tgl0=${tgl0}&tgl1=${tgl1}`, () => {
$('#mdlDetailTrip').empty().load("{{ route('view_report_trip_detail') }}", `vid=${vid}&tgl0=${tgl0}&tgl1=${tgl1}&nopol1=${nopol1}`, () => {
$('#mdlDetailTrip').modal('show')
})
@ -293,7 +294,8 @@
cptid=${AppState.current_company}
&from_date=${moment($('#tgl0').val(), "DD-MM-YYYY HH:mm").unix()}
&to_date=${moment($('#tgl1').val(), "DD-MM-YYYY HH:mm").unix()}
&vid=${$('#filterNopol').val() || ''}`,
&vid=${$('#filterNopol').val() || ''}
`,
type: 'GET',
success: function(json) {
callback(json);
@ -359,8 +361,6 @@
{
data: 'startMileage',
className: 'text-end', render: function(data, type, row, meta) {
console.log(data);
return (data === null) ? '0' : parseFloat(data).toFixed(0);
}
},
@ -373,16 +373,18 @@
{
data: 'mileage',
className: 'text-end', render: function(data, type, row, meta) {
return (data === null) ? '0' : parseFloat(data).toFixed(2);
const mileage = (row.finishMileage !== null && row.startMileage !== null) ? (row.finishMileage - row.startMileage) : row.mileage;
return (parseFloat(mileage).toFixed(2));
}
},
{
visible: false,
data: 'id',
// visible: false,
data: 'vhc_id',
className: 'text-center',
render: function(data, type, row, meta) {
let action = `
<a href="#" class="text-decoration-none me-1 btnDetailTrip" data-vid="${data}" data-tgl0="${row.start}" data-tgl1="${row.finish}">
<a href="#" class="text-decoration-none me-1 btnDetailTrip"
data-vid="${data}" data-tgl0="${row.start}" data-tgl1="${row.finish}" data-nopol1="${row.nopol1}">
<span class="icon ion-eye fz-16"></span>
</a>
`;