From 342d03722e2f746b21eb125db83403e65d19187f Mon Sep 17 00:00:00 2001 From: Wahyudin Date: Tue, 13 Oct 2026 14:54:50 +0700 Subject: [PATCH] feat: replace gate verification with verification logs for Admin PG and restrict gate inspection to gate officers --- .../Pg/VerificationLogController.php | 101 +++++ resources/views/layouts/app.blade.php | 20 +- .../views/pg/verification_logs.blade.php | 410 ++++++++++++++++++ routes/web.php | 10 +- tests/Feature/AuthenticationTest.php | 11 +- tests/Feature/VehicleActivityTest.php | 40 ++ 6 files changed, 578 insertions(+), 14 deletions(-) create mode 100644 app/Http/Controllers/Pg/VerificationLogController.php create mode 100644 resources/views/pg/verification_logs.blade.php diff --git a/app/Http/Controllers/Pg/VerificationLogController.php b/app/Http/Controllers/Pg/VerificationLogController.php new file mode 100644 index 0000000..1afc198 --- /dev/null +++ b/app/Http/Controllers/Pg/VerificationLogController.php @@ -0,0 +1,101 @@ +orderByRaw('COALESCE(validated_at, recorded_at) DESC'); + + // 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 Regu Satpam (1, 2, 3) + if ($request->filled('team')) { + $team = (int) $request->input('team'); + $query->whereHas('securityGuard', function ($sq) use ($team) { + $sq->where('team', $team); + }); + } + + // Filter Petugas Satpam Spesifik + if ($request->filled('security_guard_id')) { + $query->where('security_guard_id', $request->input('security_guard_id')); + } + + // Filter Pos Gerbang + if ($request->filled('gate_id')) { + $query->where('gate_id', $request->input('gate_id')); + } + + // Filter Arah Gerbang (in / out) + if ($request->filled('direction')) { + $query->where('direction', $request->input('direction')); + } + + // Filter Status Verifikasi (approved, rejected, pending) + if ($request->filled('status')) { + $query->where('validation_status', $request->input('status')); + } + + // Filter Kata Kunci Pencarian (No Transaksi, Petugas Satpam, Badge, Driver, NIK, Plat, Kode LV) + if ($request->filled('search')) { + $search = trim($request->input('search')); + $query->where(function ($q) use ($search) { + $q->where('transaction_no', 'like', "%{$search}%") + ->orWhere('purpose', 'like', "%{$search}%") + ->orWhere('rejection_note', 'like', "%{$search}%") + ->orWhereHas('securityGuard', function ($sq) use ($search) { + $sq->where('name', 'like', "%{$search}%") + ->orWhere('badge_id', 'like', "%{$search}%"); + }) + ->orWhereHas('vehicle', function ($vq) use ($search) { + $vq->where('code', 'like', "%{$search}%") + ->orWhere('brand_type', 'like', "%{$search}%") + ->orWhere('license_plate', 'like', "%{$search}%"); + }) + ->orWhereHas('driver', function ($dq) use ($search) { + $dq->where('name', 'like', "%{$search}%") + ->orWhere('nik', 'like', "%{$search}%"); + }); + }); + } + + // Data Statistik Ringkas untuk Admin PG + $totalApproved = VehicleActivity::where('validation_status', 'approved')->count(); + $totalRejected = VehicleActivity::where('validation_status', 'rejected')->count(); + $totalPending = VehicleActivity::where('validation_status', 'pending')->count(); + $todayInspections = VehicleActivity::whereDate('recorded_at', Carbon::today())->count(); + + $activities = $query->paginate(20)->withQueryString(); + $gates = Gate::where('is_active', true)->orderBy('name')->get(); + $guards = SecurityGuard::orderBy('name')->get(); + + return view('pg.verification_logs', compact( + 'activities', + 'gates', + 'guards', + 'totalApproved', + 'totalRejected', + 'totalPending', + 'todayInspections' + )); + } +} diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index 6322eb5..576f3de 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -94,7 +94,7 @@ Dashboard - @elseif(auth()->user()->isPgAdmin() || auth()->user()->isGateOfficer()) + @elseif(auth()->user()->isGateOfficer()) @@ -183,13 +183,11 @@ Data Satpam - @endif - @if(auth()->user()->isGateOfficer() || auth()->user()->isPgAdmin() || auth()->user()->isAdmin()) - - - Verifikasi Gerbang + + + Log Verifikasi Gerbang @endif @@ -320,8 +318,12 @@ Data Satpam + + + Log Verifikasi Gerbang + @endif - @if(auth()->user()->isGateOfficer() || auth()->user()->isPgAdmin() || auth()->user()->isAdmin()) + @if(auth()->user()->isGateOfficer()) Pos Gerbang @@ -384,6 +386,8 @@ Verifikasi Pos Gerbang @elseif(request()->routeIs('pg.guards.*')) Data Satpam + @elseif(request()->routeIs('pg.logs.*')) + Log Verifikasi Gerbang @else Dashboard @endif diff --git a/resources/views/pg/verification_logs.blade.php b/resources/views/pg/verification_logs.blade.php new file mode 100644 index 0000000..4d09faf --- /dev/null +++ b/resources/views/pg/verification_logs.blade.php @@ -0,0 +1,410 @@ +@extends('layouts.app') + +@section('title', 'Log Riwayat Verifikasi Gerbang - Admin Private Guard | PT Kerinci Merangin Hidro') + +@section('content') +
+ + + + + +
+ +
+
+ +
+
+

Disetujui

+

{{ number_format($totalApproved, 0, ',', '.') }}

+
+
+ + +
+
+ +
+
+

Ditolak

+

{{ number_format($totalRejected, 0, ',', '.') }}

+
+
+ + +
+
+ +
+
+

Menunggu

+

{{ number_format($totalPending, 0, ',', '.') }}

+
+
+ + +
+
+ +
+
+

Hari Ini

+

{{ number_format($todayInspections, 0, ',', '.') }}

+
+
+
+ + +
+
+ +
+
+ + Filter & Pencarian Log Audit +
+ @if(request()->hasAny(['search', 'team', 'security_guard_id', 'gate_id', 'direction', 'status', 'start_date', 'end_date'])) + + + Reset Semua Filter + + @endif +
+ + +
+ +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ +
+
+
+
+ + +
+
+ + + + + + + + + + + + + + + + + + @forelse($activities as $index => $item) + @php + $rowNum = $activities->firstItem() ? ($activities->firstItem() + $index) : ($index + 1); + $validatedTime = $item->validated_at ?? $item->recorded_at; + @endphp + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @empty + + + + @endforelse + +
NOWAKTU VERIFIKASINO. TRANSAKSIPETUGAS SATPAMPOS GERBANGKENDARAANDRIVER / PENGEMUDIARAHODOMETERSTATUS & CATATAN
+ {{ $rowNum }} + +
+ {{ $validatedTime ? $validatedTime->format('d/m/Y') : '-' }} +
+
+ + {{ $validatedTime ? $validatedTime->format('H:i') . ' WIB' : '-' }} +
+
+ + + {{ $item->transaction_no }} + + + @if($item->securityGuard) +
+
+

+ {{ $item->securityGuard->name }} +

+
+ + {{ $item->securityGuard->badge_id }} + + + Regu {{ $item->securityGuard->team }} + +
+
+
+ @else + - Belum ada - + @endif +
+
+ + {{ $item->gate ? $item->gate->name : '-' }} +
+
+ @if($item->vehicle) +
+ {{ $item->vehicle->license_plate }} +
+
+ {{ $item->vehicle->code }} + • + {{ $item->vehicle->brand_type }} +
+ @else + - + @endif +
+ @if($item->driver) +
+ {{ $item->driver->name }} +
+
+ {{ $item->driver->nik }} +
+ @else + - + @endif +
+ @if($item->direction === 'in') + + + Masuk + + @else + + + Keluar + + @endif + +
+ {{ number_format($item->current_km, 0, ',', '.') }} KM +
+
+ Awal: {{ number_format($item->previous_km, 0, ',', '.') }} KM + @if($item->distance > 0) + (+{{ number_format($item->distance, 0, ',', '.') }}) + @endif +
+
+ @if($item->validation_status === 'approved') + + + Disetujui + + @elseif($item->validation_status === 'rejected') +
+ + + Ditolak + + @if($item->rejection_note) +

+ {{ $item->rejection_note }} +

+ @endif +
+ @else + + + Menunggu + + @endif +
+
+
+ +
+

Belum ada catatan log riwayat verifikasi gerbang

+

Aktivitas kendaraan yang diverifikasi oleh petugas Satpam akan tercatat otomatis di sini.

+
+
+
+ + + @if($activities->hasPages()) +
+ {{ $activities->links() }} +
+ @endif +
+ +
+@endsection diff --git a/routes/web.php b/routes/web.php index 3b1da3b..2d3a641 100644 --- a/routes/web.php +++ b/routes/web.php @@ -4,6 +4,7 @@ use App\Http\Controllers\Auth\LoginController; use App\Http\Controllers\Hse\EmployeeController; use App\Http\Controllers\Pg\GateInspectionController; use App\Http\Controllers\Pg\SecurityGuardController; +use App\Http\Controllers\Pg\VerificationLogController; use App\Http\Controllers\ProfileController; use App\Http\Controllers\Public\VehicleActivityFormController; use App\Http\Controllers\Qma\ActivityLogController; @@ -68,18 +69,19 @@ Route::middleware('auth')->group(function () { Route::get('/activity-summary', [ActivityLogController::class, 'summary'])->name('activity.summary'); }); - // 4. Modul Private Guard (PG): Admin PG (Admin PG - AdminPG) & Pos Gerbang Satpam + // 4. Modul Private Guard (PG): Admin PG & Pos Gerbang Satpam Route::prefix('pg')->name('pg.')->group(function () { - // Master Satpam (Hanya Admin PG) + // Modul Admin PG (Data Satpam & Log Verifikasi Gerbang) Route::middleware('role:pg_admin')->group(function () { 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'); Route::post('/guards/{id}/toggle', [SecurityGuardController::class, 'toggleStatus'])->name('guards.toggle'); + Route::get('/verification-logs', [VerificationLogController::class, 'index'])->name('logs.index'); }); - // Verifikasi Pos Gerbang (Petugas Pos Gerbang & Admin PG) - Route::middleware('role:gate_officer,pg_admin')->group(function () { + // Verifikasi Pos Gerbang (Khusus Petugas Satpam Pos Gerbang) + Route::middleware('role:gate_officer')->group(function () { Route::get('/gate-inspection', [GateInspectionController::class, 'index'])->name('gate.inspection'); Route::post('/gate-inspection/{id}/approve', [GateInspectionController::class, 'approve'])->name('gate.approve'); Route::post('/gate-inspection/{id}/reject', [GateInspectionController::class, 'reject'])->name('gate.reject'); diff --git a/tests/Feature/AuthenticationTest.php b/tests/Feature/AuthenticationTest.php index e089d94..a179533 100644 --- a/tests/Feature/AuthenticationTest.php +++ b/tests/Feature/AuthenticationTest.php @@ -124,10 +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 & gate inspection, ditolak dari HSE + // 4. Admin PG dapat akses modul PG guards & log verifikasi, ditolak dari pos gerbang verifikasi & HSE $this->actingAs($pgUser)->get('/pg/guards')->assertStatus(200); - $this->actingAs($pgUser)->get('/pg/gate-inspection')->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 + $gateOfficer = User::where('role', 'gate_officer')->first(); + $this->actingAs($gateOfficer)->get('/pg/gate-inspection')->assertStatus(200); + $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 69b90cb..1dbdc7a 100644 --- a/tests/Feature/VehicleActivityTest.php +++ b/tests/Feature/VehicleActivityTest.php @@ -251,4 +251,44 @@ class VehicleActivityTest extends TestCase 'security_guard_id' => $guard->id, ]); } + + public function test_admin_pg_can_view_and_filter_verification_logs(): void + { + $pgUser = User::where('role', 'pg_admin')->first(); + $guard = SecurityGuard::first(); + $vehicle = Vehicle::first(); + $driver = Employee::first(); + + // Buat data aktivitas verifikasi + VehicleActivity::create([ + 'transaction_no' => 'TRX-LOG-PG-001', + 'vehicle_id' => $vehicle->id, + 'driver_id' => $driver->id, + 'gate_id' => $guard->gate_id, + 'direction' => 'out', + 'previous_km' => 1000, + 'current_km' => 1050, + 'distance' => 50, + 'purpose' => 'Dinas Luar', + 'recorded_at' => Carbon::now(), + 'validated_at' => Carbon::now(), + 'security_guard_id' => $guard->id, + 'validation_status' => 'approved', + ]); + + $response = $this->actingAs($pgUser)->get(route('pg.logs.index')); + $response->assertStatus(200); + $response->assertSee('Log Riwayat Verifikasi Gerbang'); + $response->assertSee('TRX-LOG-PG-001'); + $response->assertSee($guard->name); + + // Test filter parameter + $filterResponse = $this->actingAs($pgUser)->get(route('pg.logs.index', [ + 'team' => $guard->team, + 'status' => 'approved', + 'search' => 'TRX-LOG-PG', + ])); + $filterResponse->assertStatus(200); + $filterResponse->assertSee('TRX-LOG-PG-001'); + } }