update
This commit is contained in:
@ -145,7 +145,28 @@ class ReportsController extends Controller
|
||||
// ORDER BY agg.id, trip_id
|
||||
// ", [$from_date, $to_date, $vid, $vid]);
|
||||
|
||||
$list = DB::select("WITH TotalMileage AS (
|
||||
// $list = DB::select("WITH TotalMileage AS (
|
||||
// SELECT id, SUM(mileage) AS total_mileage, count(*) total_trip
|
||||
// FROM trips
|
||||
// WHERE start BETWEEN ? AND ?
|
||||
// GROUP BY id
|
||||
// )
|
||||
// SELECT
|
||||
// t.*,
|
||||
// tm.total_mileage, 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 if(? , t.id = ? , 1=1)
|
||||
// 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]);
|
||||
$sql = "WITH TotalMileage AS (
|
||||
SELECT id, SUM(mileage) AS total_mileage, count(*) total_trip
|
||||
FROM trips
|
||||
WHERE start BETWEEN ? AND ?
|
||||
@ -162,11 +183,27 @@ class ReportsController extends Controller
|
||||
LEFT JOIN t_vehicles_cats vt ON vt.id = tvt.cat_id
|
||||
WHERE
|
||||
t.start BETWEEN ? AND ?
|
||||
and if(? , t.id = ? , 1=1)
|
||||
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]);
|
||||
and (? IS NULL or t.id = ?)
|
||||
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, [
|
||||
$from_date,
|
||||
$to_date,
|
||||
$from_date,
|
||||
$to_date,
|
||||
$vid,
|
||||
$vid,
|
||||
$vt,
|
||||
$vt,
|
||||
$poolcode,
|
||||
$poolcode,
|
||||
]);
|
||||
// // RETURN 1 - LIST
|
||||
// if($req->type != 'report'){
|
||||
$apiResp = Responses::success("success list vehicles report");
|
||||
@ -311,9 +348,11 @@ class ReportsController extends Controller
|
||||
{
|
||||
$q = "select id, nopol1 from t_vehicles WHERE dlt is null order by nopol1";
|
||||
$listNopol = DB::select($q);
|
||||
$listpool = DB::table('t_conf_pool')->where('dlt', null)->get();
|
||||
|
||||
$data = [
|
||||
'listNopol' => $listNopol,
|
||||
'listpool' => $listpool
|
||||
];
|
||||
|
||||
$log = [
|
||||
@ -342,6 +381,7 @@ class ReportsController extends Controller
|
||||
$from_date = $req->input('from_date') - Helper::TIMEFIX;
|
||||
$to_date = $req->input('to_date') - Helper::TIMEFIX;
|
||||
$vid = $req->input('vid');
|
||||
$poolcode = $req->input('poolcode');
|
||||
|
||||
// Create a period between the two timestamps
|
||||
$period = CarbonPeriod::create(
|
||||
@ -363,7 +403,31 @@ class ReportsController extends Controller
|
||||
$qString = "(" . implode(' UNION ALL ', $subQueryParts) . ")";
|
||||
// dd("qString", $qString);
|
||||
try {
|
||||
$list = DB::select("SELECT
|
||||
// $list = DB::select("SELECT
|
||||
// tv.name,
|
||||
// tv.nopol1,
|
||||
// t.crt_d,
|
||||
// t.speed,
|
||||
// tgta.fulladdress,
|
||||
// tvd.speed_limit,
|
||||
// tvd.pool_code,
|
||||
// tvd.dc_code
|
||||
// FROM
|
||||
// $qString t
|
||||
// INNER JOIN t_vehicles tv ON tv.id = t.vhc_id
|
||||
// INNER JOIN t_vehicles_detail tvd ON tvd.vid = tv.id
|
||||
// LEFT JOIN t_gps_tracks_address tgta ON tgta.master_id = t.id
|
||||
// WHERE
|
||||
// if(? , tv.id = ? , 1=1)
|
||||
// AND t.speed > tvd.speed_limit
|
||||
// AND if(? , tvd.pool_code = ? , 1=1)
|
||||
// ORDER BY t.crt_d;
|
||||
// ", [$vid, $vid, $poolcode, $poolcode]);
|
||||
|
||||
$vid = $vid ?: null;
|
||||
$poolcode = $poolcode ?: null;
|
||||
|
||||
$sql = "SELECT
|
||||
tv.name,
|
||||
tv.nopol1,
|
||||
t.crt_d,
|
||||
@ -378,10 +442,18 @@ class ReportsController extends Controller
|
||||
INNER JOIN t_vehicles_detail tvd ON tvd.vid = tv.id
|
||||
LEFT JOIN t_gps_tracks_address tgta ON tgta.master_id = t.id
|
||||
WHERE
|
||||
if(? , tv.id = ? , 1=1)
|
||||
(? IS NULL OR tv.id = ?)
|
||||
AND t.speed > tvd.speed_limit
|
||||
ORDER BY t.crt_d;
|
||||
", [$vid, $vid]);
|
||||
AND (? IS NULL OR tvd.pool_code = ?)
|
||||
ORDER BY t.crt_d
|
||||
";
|
||||
|
||||
$list = DB::select($sql, [
|
||||
$vid,
|
||||
$vid,
|
||||
$poolcode,
|
||||
$poolcode,
|
||||
]);
|
||||
|
||||
// // RETURN 1 - LIST
|
||||
// if($req->type != 'report'){
|
||||
|
||||
@ -38,24 +38,25 @@
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<!-- filter -->
|
||||
<div class="row">
|
||||
<div class="col-2">
|
||||
<div class="row g-3 align-items-end">
|
||||
|
||||
<div class="col-6 col-md-3 col-lg-2">
|
||||
<div class="form-group">
|
||||
<label class="text-muted">From</label>
|
||||
<!-- default today -->
|
||||
<!-- <input class="form-control" id="tgl0" value="20-08-2025 00:00"> -->
|
||||
<label class="form-label text-muted mb-1">From</label>
|
||||
<input class="form-control" id="tgl0" value="{{ date('d-m-Y 00:00') }}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-2">
|
||||
|
||||
<div class="col-6 col-md-3 col-lg-2">
|
||||
<div class="form-group">
|
||||
<label class="text-muted">To</label>
|
||||
<label class="form-label text-muted mb-1">To</label>
|
||||
<input class="form-control" id="tgl1" value="{{ date('d-m-Y 23:59') }}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-2">
|
||||
|
||||
<div class="col-6 col-md-3 col-lg-2">
|
||||
<div class="form-group">
|
||||
<label class="text-muted">License Plate</label>
|
||||
<label class="form-label text-muted mb-1">License Plate</label>
|
||||
<select name="license_plate" class="form-control" id="filterNopol">
|
||||
<option value="">-- All --</option>
|
||||
@foreach ($listNopol as $nopol)
|
||||
@ -64,12 +65,28 @@
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-1 d-flex align-items-end">
|
||||
<button class="btn btn-primary" id="submitFilter">Submit</button>
|
||||
|
||||
<div class="col-6 col-md-3 col-lg-2">
|
||||
<div class="form-group">
|
||||
<label class="form-label text-muted mb-1">Pool</label>
|
||||
<select name="poolcode" class="form-control" id="poolcode">
|
||||
<option value="">-- All --</option>
|
||||
@foreach ($listpool as $listpools)
|
||||
<option value="{{ $listpools->pool_code }}">{{ $listpools->pool_name }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-5 d-flex align-items-end">
|
||||
<button class="btn btn-sm btn-danger ms-auto" id="btnDownloadReport">Download Report</button>
|
||||
</div>
|
||||
|
||||
<div class="col-12 col-lg-4 d-flex gap-2 justify-content-lg-end">
|
||||
<button class="btn btn-primary w-100 w-lg-auto" id="submitFilter">
|
||||
<i class="fa fa-search me-1"></i> Submit
|
||||
</button>
|
||||
<button class="btn btn-danger w-100 w-lg-auto" id="btnDownloadReport">
|
||||
<i class="fa fa-download me-1"></i> Download Report
|
||||
</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="table-responsive p-3">
|
||||
@ -120,10 +137,10 @@
|
||||
Wrapper.event();
|
||||
// DTable.activate();
|
||||
},
|
||||
init: ()=>{
|
||||
init: () => {
|
||||
$('#tgl0, #tgl1').datetimepicker({
|
||||
format:'d-m-Y H:i',
|
||||
defaultTime:'00:00',
|
||||
format: 'd-m-Y H:i',
|
||||
defaultTime: '00:00',
|
||||
closeOnDateSelect: true,
|
||||
// mask:true
|
||||
});
|
||||
@ -176,7 +193,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() || ''}
|
||||
&poolcode=${$('#poolcode').val() || ''}`,
|
||||
type: 'GET',
|
||||
success: function(json) {
|
||||
callback(json);
|
||||
@ -214,10 +232,14 @@
|
||||
data: "crt_d",
|
||||
className: 'text-nowrap',
|
||||
render: (data, type, row, meta) => {
|
||||
return moment.unix(data + AppState.TIMEFIX).format('DD MMM YYYY HH:mm:ss');
|
||||
return moment.unix(data + AppState.TIMEFIX).format(
|
||||
'DD MMM YYYY HH:mm:ss');
|
||||
}
|
||||
},
|
||||
{ data: "speed", className: 'text-end'},
|
||||
{
|
||||
data: "speed",
|
||||
className: 'text-end'
|
||||
},
|
||||
{
|
||||
data: "fulladdress",
|
||||
render: (data, type, row, meta) => {
|
||||
@ -226,8 +248,7 @@
|
||||
},
|
||||
],
|
||||
paging: false,
|
||||
buttons: [
|
||||
{
|
||||
buttons: [{
|
||||
extend: 'excelHtml5',
|
||||
title: () => {
|
||||
return `
|
||||
@ -240,8 +261,7 @@
|
||||
exportOptions: {
|
||||
columns: ':visible:not(:first-child)' // 🔹 exclude first column
|
||||
}
|
||||
}
|
||||
]
|
||||
}]
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
@ -41,21 +41,22 @@
|
||||
<div class="card-body">
|
||||
<!-- filter -->
|
||||
<div class="row g-3 align-items-end">
|
||||
<div class="col-md-2">
|
||||
|
||||
<div class="col-6 col-md-3 col-lg-2">
|
||||
<div class="form-group">
|
||||
<label class="form-label text-muted mb-1">From</label>
|
||||
<input type="text" class="form-control" id="tgl0" value="{{ date('d-m-Y 00:00') }}">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-2">
|
||||
<div class="col-6 col-md-3 col-lg-2">
|
||||
<div class="form-group">
|
||||
<label class="form-label text-muted mb-1">To</label>
|
||||
<input type="text" class="form-control" id="tgl1" value="{{ date('d-m-Y 23:59') }}">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-2">
|
||||
<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">
|
||||
@ -67,7 +68,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-2">
|
||||
<div class="col-6 col-md-3 col-lg-2">
|
||||
<div class="form-group">
|
||||
<label class="form-label text-muted mb-1">Vehicle Category</label>
|
||||
<select name="vehicle_type" class="form-control" id="vehicleType">
|
||||
@ -79,7 +80,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-2">
|
||||
<div class="col-6 col-md-3 col-lg-2">
|
||||
<div class="form-group">
|
||||
<label class="form-label text-muted mb-1">Pool</label>
|
||||
<select name="poolcode" class="form-control" id="poolcode">
|
||||
@ -91,14 +92,15 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4 d-flex justify-content-end gap-2">
|
||||
<button class="btn btn-primary" id="submitFilter">
|
||||
<div class="col-12 col-lg-2 d-flex gap-2 justify-content-lg-end">
|
||||
<button class="btn btn-primary w-100 w-lg-auto" id="submitFilter">
|
||||
<i class="fa fa-search me-1"></i> Submit
|
||||
</button>
|
||||
<button class="btn btn-danger" id="btnDownloadReport">
|
||||
<button class="btn btn-danger w-100 w-lg-auto" id="btnDownloadReport">
|
||||
<i class="fa fa-download me-1"></i> Download Report
|
||||
</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="table-responsive p-3">
|
||||
|
||||
Reference in New Issue
Block a user