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