update
This commit is contained in:
@ -63,12 +63,24 @@ class ReportsController extends Controller
|
||||
// $to_date = $req->input('to_date');
|
||||
$from_date = $req->input('from_date') - Helper::TIMEFIX;
|
||||
$to_date = $req->input('to_date') - Helper::TIMEFIX;
|
||||
$vid = $req->input('vid');
|
||||
|
||||
// vid sekarang bisa berupa multiple value (dari select2 multiple di FE)
|
||||
// bisa datang sebagai array (vid[]=1&vid[]=2) atau string comma-separated ("1,2,3")
|
||||
$vidInput = $req->input('vid');
|
||||
$vt = $req->input('vt');
|
||||
$poolcode = $req->input('poolcode');
|
||||
// $from_date = 1756054800;
|
||||
// $to_date = 1756745940;
|
||||
|
||||
// Normalisasi $vid jadi array of int, buang value kosong (mis. opsi "-- All --")
|
||||
$vidArr = [];
|
||||
if (is_array($vidInput)) {
|
||||
$vidArr = array_filter($vidInput, fn($v) => $v !== null && $v !== '');
|
||||
} elseif (!empty($vidInput)) {
|
||||
$vidArr = array_filter(explode(',', $vidInput), fn($v) => $v !== '');
|
||||
}
|
||||
$vidArr = array_values($vidArr);
|
||||
|
||||
// get month year
|
||||
$date = Carbon::createFromTimestamp($from_date);
|
||||
$yymm = $date->format('ym');
|
||||
@ -166,6 +178,16 @@ class ReportsController extends Controller
|
||||
// and if(? , vt.id = ? , 1=1)
|
||||
// and if(? , t.pool_code = ? , 1=1)
|
||||
// ", [$from_date, $to_date, $from_date, $to_date, $vid, $vid, $vt, $vt, $poolcode, $poolcode]);
|
||||
|
||||
// Bangun klausa IN untuk vid secara dinamis (jumlah placeholder = jumlah item terpilih)
|
||||
// kalau kosong -> tidak difilter (1=1)
|
||||
if (count($vidArr) > 0) {
|
||||
$vidPlaceholders = implode(',', array_fill(0, count($vidArr), '?'));
|
||||
$vidCondition = "t.id IN ($vidPlaceholders)";
|
||||
} else {
|
||||
$vidCondition = "1=1";
|
||||
}
|
||||
|
||||
$sql =
|
||||
"WITH TotalMileage AS (
|
||||
SELECT
|
||||
@ -191,27 +213,35 @@ class ReportsController extends Controller
|
||||
LEFT JOIN t_vehicles_cats vt ON vt.id = tvt.cat_id
|
||||
WHERE
|
||||
t.start BETWEEN ? AND ?
|
||||
AND (? IS NULL OR t.id = ?)
|
||||
AND {$vidCondition}
|
||||
AND (? IS NULL OR vt.id = ?)
|
||||
AND (? IS NULL OR t.pool_code = ?);
|
||||
";
|
||||
|
||||
$vid = $vid ?: null;
|
||||
$vt = $vt ?: null;
|
||||
$poolcode = $poolcode ?: null;
|
||||
|
||||
$list = DB::select($sql, [
|
||||
$bindings = [
|
||||
$from_date,
|
||||
$to_date,
|
||||
$from_date,
|
||||
$to_date,
|
||||
$vid,
|
||||
$vid,
|
||||
];
|
||||
|
||||
// masukkan binding untuk IN(...) hanya kalau ada isinya
|
||||
if (count($vidArr) > 0) {
|
||||
$bindings = array_merge($bindings, $vidArr);
|
||||
}
|
||||
|
||||
$bindings = array_merge($bindings, [
|
||||
$vt,
|
||||
$vt,
|
||||
$poolcode,
|
||||
$poolcode,
|
||||
]);
|
||||
|
||||
$list = DB::select($sql, $bindings);
|
||||
|
||||
// // RETURN 1 - LIST
|
||||
// if($req->type != 'report'){
|
||||
$apiResp = Responses::success("success list vehicles report");
|
||||
|
||||
@ -59,7 +59,8 @@
|
||||
<div class="col-6 col-md-3 col-lg-2">
|
||||
<div class="form-group">
|
||||
<label class="form-label text-muted mb-1">License Plate</label>
|
||||
<select name="license_plate" class="form-control" id="filterNopol">
|
||||
<select name="license_plate" class="form-control" id="filterNopol" style="width:100%;"
|
||||
multiple="multiple">
|
||||
<option value="">-- All --</option>
|
||||
@foreach ($listNopol as $nopol)
|
||||
<option value="{{ $nopol->id }}">{{ $nopol->nopol1 }}</option>
|
||||
@ -289,6 +290,7 @@
|
||||
})
|
||||
|
||||
});
|
||||
$('#filterNopol').select2({});
|
||||
},
|
||||
};
|
||||
// Data referensi site (lat/lng dalam desimal, bukan koma)
|
||||
@ -514,7 +516,7 @@
|
||||
const nearestSite = findNearestSite(startLat, startLng);
|
||||
|
||||
if (nearestSite) {
|
||||
return formatSiteLabel(nearestSite);
|
||||
return `${moment.unix(data + AppState.TIMEFIX).format('DD MMM YYYY HH:mm:ss')}<br>`+formatSiteLabel(nearestSite);
|
||||
}
|
||||
return `
|
||||
${moment.unix(data + AppState.TIMEFIX).format('DD MMM YYYY HH:mm:ss')}<br>
|
||||
@ -548,7 +550,7 @@
|
||||
const nearestSite = findNearestSite(finishLat, finishLng);
|
||||
|
||||
if (nearestSite) {
|
||||
return formatSiteLabel(nearestSite);
|
||||
return `${moment.unix(data + AppState.TIMEFIX).format('DD MMM YYYY HH:mm:ss')}<br>`+formatSiteLabel(nearestSite);
|
||||
}
|
||||
|
||||
// Tampilan di tabel
|
||||
|
||||
Reference in New Issue
Block a user