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,52 +178,70 @@ 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
|
||||
id,
|
||||
SUM(mileage) AS total_mileage,
|
||||
COUNT(*) AS total_trip
|
||||
FROM trips
|
||||
WHERE start BETWEEN ? AND ?
|
||||
GROUP BY id
|
||||
)
|
||||
SELECT
|
||||
t.*,
|
||||
tm.total_mileage,
|
||||
tm.total_trip,
|
||||
vt.name AS type_name,
|
||||
ROW_NUMBER() OVER (
|
||||
PARTITION BY t.id
|
||||
ORDER BY t.start
|
||||
) AS trip_id
|
||||
FROM trips t
|
||||
JOIN TotalMileage tm ON t.id = tm.id
|
||||
LEFT JOIN t_vehicles tvt ON tvt.id = t.vhc_id
|
||||
LEFT JOIN t_vehicles_cats vt ON vt.id = tvt.cat_id
|
||||
WHERE
|
||||
t.start BETWEEN ? AND ?
|
||||
AND (? IS NULL OR t.id = ?)
|
||||
AND (? IS NULL OR vt.id = ?)
|
||||
AND (? IS NULL OR t.pool_code = ?);
|
||||
";
|
||||
id,
|
||||
SUM(mileage) AS total_mileage,
|
||||
COUNT(*) AS total_trip
|
||||
FROM trips
|
||||
WHERE start BETWEEN ? AND ?
|
||||
GROUP BY id
|
||||
)
|
||||
SELECT
|
||||
t.*,
|
||||
tm.total_mileage,
|
||||
tm.total_trip,
|
||||
vt.name AS type_name,
|
||||
ROW_NUMBER() OVER (
|
||||
PARTITION BY t.id
|
||||
ORDER BY t.start
|
||||
) AS trip_id
|
||||
FROM trips t
|
||||
JOIN TotalMileage tm ON t.id = tm.id
|
||||
LEFT JOIN t_vehicles tvt ON tvt.id = t.vhc_id
|
||||
LEFT JOIN t_vehicles_cats vt ON vt.id = tvt.cat_id
|
||||
WHERE
|
||||
t.start BETWEEN ? AND ?
|
||||
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");
|
||||
|
||||
@ -25,8 +25,8 @@
|
||||
@if ($user_role == \App\Models\Users::ROLE_VENDOR || $user_role == \App\Models\Users::ROLE_ADMIN)
|
||||
@can('vehicle.create')
|
||||
<!-- <div class="col text-end">
|
||||
<button id="btnMdlNewVhc" class="btn btn-sm btn-danger">Add New Vehicle</button>
|
||||
</div> -->
|
||||
<button id="btnMdlNewVhc" class="btn btn-sm btn-danger">Add New Vehicle</button>
|
||||
</div> -->
|
||||
@endcan
|
||||
|
||||
{{-- <div class="col-auto text-end ps-0">
|
||||
@ -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>
|
||||
@ -129,73 +130,73 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<!-- <tbody>
|
||||
<tr>
|
||||
<td>24-679</td>
|
||||
<td>24-679</td>
|
||||
<td>26</td>
|
||||
<td>442.3</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>24-682</td>
|
||||
<td>24-682</td>
|
||||
<td>28</td>
|
||||
<td>312.7</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>24-877</td>
|
||||
<td>24-877</td>
|
||||
<td>15</td>
|
||||
<td>276.4</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>A.16-347</td>
|
||||
<td>A.16-347</td>
|
||||
<td>37</td>
|
||||
<td>543.2</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>AL2025-B21</td>
|
||||
<td>AL2025-B21</td>
|
||||
<td>18</td>
|
||||
<td>295.4</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>B.16-542</td>
|
||||
<td>B.16-542</td>
|
||||
<td>32</td>
|
||||
<td>478.2</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>B.24-264</td>
|
||||
<td>B.24-264</td>
|
||||
<td>24</td>
|
||||
<td>188.4</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>B.24-274</td>
|
||||
<td>B.24-274</td>
|
||||
<td>33</td>
|
||||
<td>440.1</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Ford Ranger</td>
|
||||
<td>26-199</td>
|
||||
<td>30</td>
|
||||
<td>631.4</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Nissan AD</td>
|
||||
<td>B.10-517</td>
|
||||
<td>27</td>
|
||||
<td>375.9</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Triton</td>
|
||||
<td>A.29-127</td>
|
||||
<td>26</td>
|
||||
<td>508.2</td>
|
||||
</tr>
|
||||
</tbody> -->
|
||||
<tr>
|
||||
<td>24-679</td>
|
||||
<td>24-679</td>
|
||||
<td>26</td>
|
||||
<td>442.3</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>24-682</td>
|
||||
<td>24-682</td>
|
||||
<td>28</td>
|
||||
<td>312.7</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>24-877</td>
|
||||
<td>24-877</td>
|
||||
<td>15</td>
|
||||
<td>276.4</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>A.16-347</td>
|
||||
<td>A.16-347</td>
|
||||
<td>37</td>
|
||||
<td>543.2</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>AL2025-B21</td>
|
||||
<td>AL2025-B21</td>
|
||||
<td>18</td>
|
||||
<td>295.4</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>B.16-542</td>
|
||||
<td>B.16-542</td>
|
||||
<td>32</td>
|
||||
<td>478.2</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>B.24-264</td>
|
||||
<td>B.24-264</td>
|
||||
<td>24</td>
|
||||
<td>188.4</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>B.24-274</td>
|
||||
<td>B.24-274</td>
|
||||
<td>33</td>
|
||||
<td>440.1</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Ford Ranger</td>
|
||||
<td>26-199</td>
|
||||
<td>30</td>
|
||||
<td>631.4</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Nissan AD</td>
|
||||
<td>B.10-517</td>
|
||||
<td>27</td>
|
||||
<td>375.9</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Triton</td>
|
||||
<td>A.29-127</td>
|
||||
<td>26</td>
|
||||
<td>508.2</td>
|
||||
</tr>
|
||||
</tbody> -->
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
@ -207,17 +208,17 @@
|
||||
<div class="modal fade" data-bs-backdrop="static" data-bs-keyboard="false" id="mdlDetailTrip"
|
||||
aria-labelledby="mdlDetailTripLabel" aria-hidden="true">
|
||||
<!-- <div class="modal-dialog modal-dialog modal-dialog-centered modal-dialog-scrollable modal-xl">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="mdlDetailTripLabel">-----</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="mdlDetailTripLabel">-----</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
</div>
|
||||
</div>
|
||||
</div> -->
|
||||
</div> -->
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@ -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