diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 9a0b4f9..dba6077 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -74,7 +74,7 @@ class LoginController extends Controller return match ($user->role) { 'hse_admin' => redirect()->route('hse.dashboard'), 'qma_admin' => redirect()->route('qma.dashboard'), - 'pg_admin' => redirect()->route('pg.guards.index'), + 'pg_admin' => redirect()->route('pg.dashboard'), 'gate_officer' => redirect()->route('pg.gate.inspection'), default => redirect()->route('qma.dashboard'), }; diff --git a/app/Http/Controllers/Pg/DashboardController.php b/app/Http/Controllers/Pg/DashboardController.php new file mode 100644 index 0000000..c78689c --- /dev/null +++ b/app/Http/Controllers/Pg/DashboardController.php @@ -0,0 +1,56 @@ +count(); + $totalGates = Gate::where('is_active', true)->count(); + $todayVerifications = VehicleActivity::whereDate('recorded_at', Carbon::today())->count(); + $totalRejections = VehicleActivity::where('validation_status', 'rejected')->count(); + + // Log Verifikasi Gerbang Terkini (Panel Kiri) + $recentActivities = VehicleActivity::with(['vehicle', 'driver', 'gate', 'securityGuard']) + ->latest('recorded_at') + ->take(5) + ->get(); + + // Personel Satpam Terkini per Regu (Panel Kanan Atas) + $recentGuards = SecurityGuard::with('gate') + ->orderBy('team') + ->take(5) + ->get(); + + // Ringkasan Jumlah Personel per Regu Tugas (Panel Kanan Bawah) + $team1Count = SecurityGuard::where('team', 1)->where('is_active', true)->count(); + $team2Count = SecurityGuard::where('team', 2)->where('is_active', true)->count(); + $team3Count = SecurityGuard::where('team', 3)->where('is_active', true)->count(); + + return view('pg.dashboard', compact( + 'totalGuards', + 'activeGuards', + 'totalGates', + 'todayVerifications', + 'totalRejections', + 'recentActivities', + 'recentGuards', + 'team1Count', + 'team2Count', + 'team3Count' + )); + } +} diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index 576f3de..2ed8921 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -94,6 +94,17 @@ Dashboard + @elseif(auth()->user()->isPgAdmin()) + + + + + + + + Dashboard + @elseif(auth()->user()->isGateOfficer()) @@ -105,17 +116,6 @@ Pos Gerbang - @else - - - - - - - - Dashboard - @endif @@ -314,6 +314,15 @@ @endif @if(auth()->user()->isPgAdmin() || auth()->user()->isAdmin()) + + + + + + + + Dashboard + Data Satpam @@ -382,6 +391,8 @@ Summary Aktivitas Kendaraan @elseif(request()->routeIs('profile.*')) Profil Saya + @elseif(request()->routeIs('pg.dashboard')) + Dashboard @elseif(request()->routeIs('pg.gate.*')) Verifikasi Pos Gerbang @elseif(request()->routeIs('pg.guards.*')) diff --git a/resources/views/pg/dashboard.blade.php b/resources/views/pg/dashboard.blade.php new file mode 100644 index 0000000..9cead8a --- /dev/null +++ b/resources/views/pg/dashboard.blade.php @@ -0,0 +1,216 @@ +@extends('layouts.app') + +@section('title', 'Dashboard - Admin Private Guard | PT Kerinci Merangin Hidro') + +@section('content') +
+ + +
+ + SISTEM ADMINISTRATOR + +
+

+ Selamat datang, {{ auth()->user()->name }} +

+ + + +
+

+ Berikut ringkasan operasional sistem keamanan pos gerbang dan tata kelola personel Satpam PT Kerinci Merangin Hidro secara keseluruhan. +

+
+ + +
+ +
+
+ {{ $totalGuards }} +
+

TOTAL SATPAM

+
+ + +
+
+ {{ $activeGuards }} +
+

SATPAM AKTIF

+
+ + +
+
+ {{ $totalGates }} +
+

POS GERBANG

+
+ + +
+
+ {{ $todayVerifications }} +
+

VERIFIKASI HARI INI

+
+ + +
+
+ {{ $totalRejections }} +
+

PENOLAKAN GERBANG

+
+
+ + +
+ + +
+ + +
+ @forelse($recentActivities as $act) +
+
+ +
+ {{ strtoupper(substr($act->driver->name ?? 'G', 0, 1)) }} +
+ +
+

+ {{ $act->transaction_no }} ke {{ $act->driver->name ?? 'Pengemudi' }} +

+

+ {{ $act->vehicle->code ?? 'Armada' }} • Pos {{ $act->gate->name ?? '-' }} (Arah: {{ $act->direction === 'in' ? 'Masuk' : 'Keluar' }}) +

+

+ {{ $act->recorded_at ? $act->recorded_at->format('d M Y H:i') : '-' }} WIB +

+
+
+ + +
+ @if($act->validation_status === 'approved') + + Disetujui + + @elseif($act->validation_status === 'rejected') + + Ditolak + + @else + + Menunggu + + @endif +
+
+ @empty +
+
+ +
+

Belum ada aktivitas verifikasi gerbang

+

Aktivitas kendaraan di pos gerbang akan muncul otomatis di sini.

+
+ @endforelse +
+
+ + +
+ + +
+
+

Petugas Satpam per Regu

+ + Lihat Semua + +
+ +
+ @forelse($recentGuards as $g) +
+
+ +
+ {{ strtoupper(substr($g->name, 0, 1)) }} +
+ +
+

+ {{ $g->badge_id }} • {{ $g->name }} +

+

+ Pos: {{ $g->gate->name ?? 'Belum Ditentukan' }} +

+
+
+ + +
+ + Regu {{ $g->team }} + +
+
+ @empty +
+

Belum ada data Satpam

+
+ @endforelse +
+
+ + +
+
+

Ringkasan Personel Regu Tugas

+ + Kelola Satpam + +
+ +
+ +
+

REGU 1

+

{{ $team1Count }}

+

Personel

+
+ + +
+

REGU 2

+

{{ $team2Count }}

+

Personel

+
+ + +
+

REGU 3

+

{{ $team3Count }}

+

Personel

+
+
+
+ +
+ +
+ +
+@endsection diff --git a/routes/web.php b/routes/web.php index 2d3a641..6fa06df 100644 --- a/routes/web.php +++ b/routes/web.php @@ -2,6 +2,7 @@ use App\Http\Controllers\Auth\LoginController; use App\Http\Controllers\Hse\EmployeeController; +use App\Http\Controllers\Pg\DashboardController as PgDashboardController; use App\Http\Controllers\Pg\GateInspectionController; use App\Http\Controllers\Pg\SecurityGuardController; use App\Http\Controllers\Pg\VerificationLogController; @@ -20,7 +21,7 @@ Route::get('/', function () { return match ($user->role) { 'hse_admin' => redirect()->route('hse.dashboard'), 'qma_admin' => redirect()->route('qma.dashboard'), - 'pg_admin' => redirect()->route('pg.guards.index'), + 'pg_admin' => redirect()->route('pg.dashboard'), 'gate_officer' => redirect()->route('pg.gate.inspection'), default => redirect()->route('qma.dashboard'), }; @@ -71,8 +72,9 @@ Route::middleware('auth')->group(function () { // 4. Modul Private Guard (PG): Admin PG & Pos Gerbang Satpam Route::prefix('pg')->name('pg.')->group(function () { - // Modul Admin PG (Data Satpam & Log Verifikasi Gerbang) + // Modul Admin PG (Dashboard, Data Satpam & Log Verifikasi Gerbang) Route::middleware('role:pg_admin')->group(function () { + Route::get('/dashboard', [PgDashboardController::class, 'index'])->name('dashboard'); Route::get('/guards', [SecurityGuardController::class, 'index'])->name('guards.index'); Route::post('/guards', [SecurityGuardController::class, 'store'])->name('guards.store'); Route::post('/guards/{id}', [SecurityGuardController::class, 'update'])->name('guards.update'); diff --git a/tests/Feature/AuthenticationTest.php b/tests/Feature/AuthenticationTest.php index a179533..703b971 100644 --- a/tests/Feature/AuthenticationTest.php +++ b/tests/Feature/AuthenticationTest.php @@ -77,7 +77,7 @@ class AuthenticationTest extends TestCase 'password' => 'password', ]); - $response->assertRedirect('/pg/guards'); + $response->assertRedirect('/pg/dashboard'); $this->assertAuthenticated(); $user = auth()->user(); @@ -124,15 +124,17 @@ class AuthenticationTest extends TestCase $this->actingAs($qmaUser)->get('/hse/employees')->assertStatus(403); $this->actingAs($qmaUser)->get('/pg/guards')->assertStatus(403); - // 4. Admin PG dapat akses modul PG guards & log verifikasi, ditolak dari pos gerbang verifikasi & HSE + // 4. Admin PG dapat akses modul PG dashboard, guards & log verifikasi, ditolak dari pos gerbang verifikasi & HSE + $this->actingAs($pgUser)->get('/pg/dashboard')->assertStatus(200); $this->actingAs($pgUser)->get('/pg/guards')->assertStatus(200); $this->actingAs($pgUser)->get('/pg/verification-logs')->assertStatus(200); $this->actingAs($pgUser)->get('/pg/gate-inspection')->assertStatus(403); $this->actingAs($pgUser)->get('/hse/employees')->assertStatus(403); - // 5. Petugas Satpam Pos Gerbang dapat akses verifikasi pos gerbang, ditolak dari master guards & logs + // 5. Petugas Satpam Pos Gerbang dapat akses verifikasi pos gerbang, ditolak dari master guards & logs & dashboard $gateOfficer = User::where('role', 'gate_officer')->first(); $this->actingAs($gateOfficer)->get('/pg/gate-inspection')->assertStatus(200); + $this->actingAs($gateOfficer)->get('/pg/dashboard')->assertStatus(403); $this->actingAs($gateOfficer)->get('/pg/guards')->assertStatus(403); $this->actingAs($gateOfficer)->get('/pg/verification-logs')->assertStatus(403); } diff --git a/tests/Feature/VehicleActivityTest.php b/tests/Feature/VehicleActivityTest.php index 1dbdc7a..c64cd9e 100644 --- a/tests/Feature/VehicleActivityTest.php +++ b/tests/Feature/VehicleActivityTest.php @@ -291,4 +291,19 @@ class VehicleActivityTest extends TestCase $filterResponse->assertStatus(200); $filterResponse->assertSee('TRX-LOG-PG-001'); } + + public function test_admin_pg_can_view_dashboard_with_summary_metrics(): void + { + $pgUser = User::where('role', 'pg_admin')->first(); + + $response = $this->actingAs($pgUser)->get(route('pg.dashboard')); + $response->assertStatus(200); + $response->assertSee('TOTAL SATPAM'); + $response->assertSee('SATPAM AKTIF'); + $response->assertSee('POS GERBANG'); + $response->assertSee('VERIFIKASI HARI INI'); + $response->assertSee('PENOLAKAN GERBANG'); + $response->assertSee('Log Verifikasi Gerbang Terkini'); + $response->assertSee('Petugas Satpam per Regu'); + } }