feat(qma): default start_date and end_date to today on activity log
This commit is contained in:
@@ -19,11 +19,19 @@ class ActivityLogController extends Controller
|
||||
$query = VehicleActivity::with(['vehicle', 'driver', 'gate', 'securityGuard'])
|
||||
->latest('recorded_at');
|
||||
|
||||
// Filter Rentang Tanggal
|
||||
if ($request->filled('start_date') && $request->filled('end_date')) {
|
||||
$startDate = Carbon::parse($request->input('start_date'))->startOfDay();
|
||||
$endDate = Carbon::parse($request->input('end_date'))->endOfDay();
|
||||
$query->whereBetween('recorded_at', [$startDate, $endDate]);
|
||||
// Filter Rentang Tanggal (Default Hari Ini)
|
||||
$today = Carbon::today()->toDateString();
|
||||
$startDate = $request->input('start_date', $today);
|
||||
$endDate = $request->input('end_date', $today);
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
// Filter Gerbang
|
||||
@@ -59,7 +67,7 @@ class ActivityLogController extends Controller
|
||||
$activities = $query->paginate(20)->withQueryString();
|
||||
$gates = Gate::where('is_active', true)->orderBy('name')->get();
|
||||
|
||||
return view('qma.activity_log', compact('activities', 'gates'));
|
||||
return view('qma.activity_log', compact('activities', 'gates', 'startDate', 'endDate'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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 py-2 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 py-2 text-slate-800 focus:outline-none focus:ring-2 focus:ring-[#1b5e20]/20 focus:border-[#1b5e20] transition">
|
||||
</div>
|
||||
|
||||
@@ -203,6 +203,16 @@ class VehicleActivityTest extends TestCase
|
||||
$responseFiltered->assertSee('<span>Reset Filter</span>', false);
|
||||
}
|
||||
|
||||
public function test_qma_log_defaults_date_filter_to_today(): void
|
||||
{
|
||||
$qmaAdmin = User::where('role', 'qma_admin')->first();
|
||||
$today = Carbon::today()->toDateString();
|
||||
|
||||
$response = $this->actingAs($qmaAdmin)->get('/qma/activity-log');
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('value="' . $today . '"', false);
|
||||
}
|
||||
|
||||
public function test_admin_pg_can_store_security_guard_and_creates_login_account(): void
|
||||
{
|
||||
$adminPg = User::where('role', 'pg_admin')->first();
|
||||
|
||||
Reference in New Issue
Block a user