feat(qma): default start_date and end_date to today on activity summary
This commit is contained in:
@@ -67,17 +67,22 @@ class ActivityLogController extends Controller
|
||||
*/
|
||||
public function summary(Request $request): View
|
||||
{
|
||||
$startDate = $request->input('start_date');
|
||||
$endDate = $request->input('end_date');
|
||||
$today = Carbon::today()->toDateString();
|
||||
$startDate = $request->input('start_date', $today);
|
||||
$endDate = $request->input('end_date', $today);
|
||||
$type = $request->input('type');
|
||||
$gateId = $request->input('gate_id');
|
||||
|
||||
$query = VehicleActivity::query();
|
||||
|
||||
if ($request->filled('start_date') && $request->filled('end_date')) {
|
||||
if ($startDate && $endDate) {
|
||||
$start = Carbon::parse($startDate)->startOfDay();
|
||||
$end = Carbon::parse($endDate)->endOfDay();
|
||||
$query->whereBetween('recorded_at', [$start, $end]);
|
||||
} elseif ($startDate) {
|
||||
$query->where('recorded_at', '>=', Carbon::parse($startDate)->startOfDay());
|
||||
} elseif ($endDate) {
|
||||
$query->where('recorded_at', '<=', Carbon::parse($endDate)->endOfDay());
|
||||
}
|
||||
|
||||
if ($request->filled('gate_id')) {
|
||||
@@ -133,6 +138,8 @@ class ActivityLogController extends Controller
|
||||
$gates = Gate::where('is_active', true)->orderBy('name')->get();
|
||||
|
||||
return view('qma.activity_summary', compact(
|
||||
'startDate',
|
||||
'endDate',
|
||||
'totalActivities',
|
||||
'totalDistance',
|
||||
'activeVehiclesCount',
|
||||
|
||||
@@ -112,7 +112,7 @@
|
||||
</label>
|
||||
<input type="date"
|
||||
name="start_date"
|
||||
value="{{ request('start_date') }}"
|
||||
value="{{ request('start_date', $startDate ?? now()->format('Y-m-d')) }}"
|
||||
onchange="this.form.submit()"
|
||||
class="w-full text-xs rounded-xl border border-slate-200 bg-slate-50/50 hover:bg-white focus:bg-white px-3.5 py-2.5 text-slate-800 focus:outline-none focus:ring-2 focus:ring-[#1b5e20]/20 focus:border-[#1b5e20] transition">
|
||||
</div>
|
||||
@@ -124,7 +124,7 @@
|
||||
</label>
|
||||
<input type="date"
|
||||
name="end_date"
|
||||
value="{{ request('end_date') }}"
|
||||
value="{{ request('end_date', $endDate ?? now()->format('Y-m-d')) }}"
|
||||
onchange="this.form.submit()"
|
||||
class="w-full text-xs rounded-xl border border-slate-200 bg-slate-50/50 hover:bg-white focus:bg-white px-3.5 py-2.5 text-slate-800 focus:outline-none focus:ring-2 focus:ring-[#1b5e20]/20 focus:border-[#1b5e20] transition">
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user