update
This commit is contained in:
@ -63,12 +63,24 @@ class ReportsController extends Controller
|
|||||||
// $to_date = $req->input('to_date');
|
// $to_date = $req->input('to_date');
|
||||||
$from_date = $req->input('from_date') - Helper::TIMEFIX;
|
$from_date = $req->input('from_date') - Helper::TIMEFIX;
|
||||||
$to_date = $req->input('to_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');
|
$vt = $req->input('vt');
|
||||||
$poolcode = $req->input('poolcode');
|
$poolcode = $req->input('poolcode');
|
||||||
// $from_date = 1756054800;
|
// $from_date = 1756054800;
|
||||||
// $to_date = 1756745940;
|
// $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
|
// get month year
|
||||||
$date = Carbon::createFromTimestamp($from_date);
|
$date = Carbon::createFromTimestamp($from_date);
|
||||||
$yymm = $date->format('ym');
|
$yymm = $date->format('ym');
|
||||||
@ -166,6 +178,16 @@ class ReportsController extends Controller
|
|||||||
// and if(? , vt.id = ? , 1=1)
|
// and if(? , vt.id = ? , 1=1)
|
||||||
// and if(? , t.pool_code = ? , 1=1)
|
// and if(? , t.pool_code = ? , 1=1)
|
||||||
// ", [$from_date, $to_date, $from_date, $to_date, $vid, $vid, $vt, $vt, $poolcode, $poolcode]);
|
// ", [$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 =
|
$sql =
|
||||||
"WITH TotalMileage AS (
|
"WITH TotalMileage AS (
|
||||||
SELECT
|
SELECT
|
||||||
@ -191,27 +213,35 @@ class ReportsController extends Controller
|
|||||||
LEFT JOIN t_vehicles_cats vt ON vt.id = tvt.cat_id
|
LEFT JOIN t_vehicles_cats vt ON vt.id = tvt.cat_id
|
||||||
WHERE
|
WHERE
|
||||||
t.start BETWEEN ? AND ?
|
t.start BETWEEN ? AND ?
|
||||||
AND (? IS NULL OR t.id = ?)
|
AND {$vidCondition}
|
||||||
AND (? IS NULL OR vt.id = ?)
|
AND (? IS NULL OR vt.id = ?)
|
||||||
AND (? IS NULL OR t.pool_code = ?);
|
AND (? IS NULL OR t.pool_code = ?);
|
||||||
";
|
";
|
||||||
|
|
||||||
$vid = $vid ?: null;
|
|
||||||
$vt = $vt ?: null;
|
$vt = $vt ?: null;
|
||||||
$poolcode = $poolcode ?: null;
|
$poolcode = $poolcode ?: null;
|
||||||
|
|
||||||
$list = DB::select($sql, [
|
$bindings = [
|
||||||
$from_date,
|
$from_date,
|
||||||
$to_date,
|
$to_date,
|
||||||
$from_date,
|
$from_date,
|
||||||
$to_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,
|
||||||
$vt,
|
$vt,
|
||||||
$poolcode,
|
$poolcode,
|
||||||
$poolcode,
|
$poolcode,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$list = DB::select($sql, $bindings);
|
||||||
|
|
||||||
// // RETURN 1 - LIST
|
// // RETURN 1 - LIST
|
||||||
// if($req->type != 'report'){
|
// if($req->type != 'report'){
|
||||||
$apiResp = Responses::success("success list vehicles report");
|
$apiResp = Responses::success("success list vehicles report");
|
||||||
|
|||||||
@ -59,7 +59,8 @@
|
|||||||
<div class="col-6 col-md-3 col-lg-2">
|
<div class="col-6 col-md-3 col-lg-2">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="form-label text-muted mb-1">License Plate</label>
|
<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>
|
<option value="">-- All --</option>
|
||||||
@foreach ($listNopol as $nopol)
|
@foreach ($listNopol as $nopol)
|
||||||
<option value="{{ $nopol->id }}">{{ $nopol->nopol1 }}</option>
|
<option value="{{ $nopol->id }}">{{ $nopol->nopol1 }}</option>
|
||||||
@ -289,6 +290,7 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
});
|
});
|
||||||
|
$('#filterNopol').select2({});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
// Data referensi site (lat/lng dalam desimal, bukan koma)
|
// Data referensi site (lat/lng dalam desimal, bukan koma)
|
||||||
@ -514,7 +516,7 @@
|
|||||||
const nearestSite = findNearestSite(startLat, startLng);
|
const nearestSite = findNearestSite(startLat, startLng);
|
||||||
|
|
||||||
if (nearestSite) {
|
if (nearestSite) {
|
||||||
return formatSiteLabel(nearestSite);
|
return `${moment.unix(data + AppState.TIMEFIX).format('DD MMM YYYY HH:mm:ss')}<br>`+formatSiteLabel(nearestSite);
|
||||||
}
|
}
|
||||||
return `
|
return `
|
||||||
${moment.unix(data + AppState.TIMEFIX).format('DD MMM YYYY HH:mm:ss')}<br>
|
${moment.unix(data + AppState.TIMEFIX).format('DD MMM YYYY HH:mm:ss')}<br>
|
||||||
@ -548,7 +550,7 @@
|
|||||||
const nearestSite = findNearestSite(finishLat, finishLng);
|
const nearestSite = findNearestSite(finishLat, finishLng);
|
||||||
|
|
||||||
if (nearestSite) {
|
if (nearestSite) {
|
||||||
return formatSiteLabel(nearestSite);
|
return `${moment.unix(data + AppState.TIMEFIX).format('DD MMM YYYY HH:mm:ss')}<br>`+formatSiteLabel(nearestSite);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tampilan di tabel
|
// Tampilan di tabel
|
||||||
|
|||||||
Reference in New Issue
Block a user