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'])
|
$query = VehicleActivity::with(['vehicle', 'driver', 'gate', 'securityGuard'])
|
||||||
->latest('recorded_at');
|
->latest('recorded_at');
|
||||||
|
|
||||||
// Filter Rentang Tanggal
|
// Filter Rentang Tanggal (Default Hari Ini)
|
||||||
if ($request->filled('start_date') && $request->filled('end_date')) {
|
$today = Carbon::today()->toDateString();
|
||||||
$startDate = Carbon::parse($request->input('start_date'))->startOfDay();
|
$startDate = $request->input('start_date', $today);
|
||||||
$endDate = Carbon::parse($request->input('end_date'))->endOfDay();
|
$endDate = $request->input('end_date', $today);
|
||||||
$query->whereBetween('recorded_at', [$startDate, $endDate]);
|
|
||||||
|
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
|
// Filter Gerbang
|
||||||
@@ -59,7 +67,7 @@ class ActivityLogController extends Controller
|
|||||||
$activities = $query->paginate(20)->withQueryString();
|
$activities = $query->paginate(20)->withQueryString();
|
||||||
$gates = Gate::where('is_active', true)->orderBy('name')->get();
|
$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>
|
</label>
|
||||||
<input type="date"
|
<input type="date"
|
||||||
name="start_date"
|
name="start_date"
|
||||||
value="{{ request('start_date') }}"
|
value="{{ request('start_date', $startDate ?? now()->format('Y-m-d')) }}"
|
||||||
onchange="this.form.submit()"
|
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">
|
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>
|
</div>
|
||||||
@@ -124,7 +124,7 @@
|
|||||||
</label>
|
</label>
|
||||||
<input type="date"
|
<input type="date"
|
||||||
name="end_date"
|
name="end_date"
|
||||||
value="{{ request('end_date') }}"
|
value="{{ request('end_date', $endDate ?? now()->format('Y-m-d')) }}"
|
||||||
onchange="this.form.submit()"
|
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">
|
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>
|
</div>
|
||||||
|
|||||||
@@ -203,6 +203,16 @@ class VehicleActivityTest extends TestCase
|
|||||||
$responseFiltered->assertSee('<span>Reset Filter</span>', false);
|
$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
|
public function test_admin_pg_can_store_security_guard_and_creates_login_account(): void
|
||||||
{
|
{
|
||||||
$adminPg = User::where('role', 'pg_admin')->first();
|
$adminPg = User::where('role', 'pg_admin')->first();
|
||||||
|
|||||||
Reference in New Issue
Block a user