feat: add verification log filtering, gate inspection, and dashboard views for private guard module
This commit is contained in:
@@ -7,6 +7,7 @@ use App\Models\Gate;
|
||||
use App\Models\SecurityGuard;
|
||||
use App\Models\VehicleActivity;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -28,24 +29,12 @@ class GateInspectionController extends Controller
|
||||
$gate = $gateId ? Gate::find($gateId) : Gate::first();
|
||||
|
||||
$pendingActivities = collect();
|
||||
$todayApprovedCount = 0;
|
||||
$todayRejectedCount = 0;
|
||||
if ($gate) {
|
||||
$pendingActivities = VehicleActivity::where('gate_id', $gate->id)
|
||||
->where('validation_status', 'pending')
|
||||
->with(['vehicle', 'driver'])
|
||||
->orderBy('recorded_at', 'asc')
|
||||
->get();
|
||||
|
||||
$todayApprovedCount = VehicleActivity::where('gate_id', $gate->id)
|
||||
->where('validation_status', 'approved')
|
||||
->whereDate('validated_at', Carbon::today())
|
||||
->count();
|
||||
|
||||
$todayRejectedCount = VehicleActivity::where('gate_id', $gate->id)
|
||||
->where('validation_status', 'rejected')
|
||||
->whereDate('validated_at', Carbon::today())
|
||||
->count();
|
||||
}
|
||||
|
||||
// Daftar satpam aktif untuk fallback pilihan
|
||||
@@ -55,12 +44,37 @@ class GateInspectionController extends Controller
|
||||
'gate',
|
||||
'pendingActivities',
|
||||
'guards',
|
||||
'currentGuard',
|
||||
'todayApprovedCount',
|
||||
'todayRejectedCount'
|
||||
'currentGuard'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Endpoint sync antrean realtime (Fetch) tanpa reload halaman.
|
||||
*/
|
||||
public function liveQueue(Request $request): JsonResponse
|
||||
{
|
||||
$user = $request->user();
|
||||
$gateId = $user ? $user->gate_id : $request->query('gate_id');
|
||||
$gate = $gateId ? Gate::find($gateId) : Gate::first();
|
||||
|
||||
$pendingActivities = collect();
|
||||
if ($gate) {
|
||||
$pendingActivities = VehicleActivity::where('gate_id', $gate->id)
|
||||
->where('validation_status', 'pending')
|
||||
->with(['vehicle', 'driver'])
|
||||
->orderBy('recorded_at', 'asc')
|
||||
->get();
|
||||
}
|
||||
|
||||
$currentGuard = $user ? $user->securityGuard : null;
|
||||
$guards = SecurityGuard::where('is_active', true)->orderBy('name')->get();
|
||||
|
||||
return response()->json([
|
||||
'count' => $pendingActivities->count(),
|
||||
'html' => view('pg.partials.queue_cards', compact('pendingActivities', 'currentGuard', 'guards'))->render(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setujui aktivitas kendaraan oleh Satpam di pos gerbang.
|
||||
*/
|
||||
@@ -71,12 +85,17 @@ class GateInspectionController extends Controller
|
||||
$guardId = $request->input('security_guard_id') ?? ($currentGuard ? $currentGuard->id : null);
|
||||
|
||||
if (!$guardId) {
|
||||
$request->validate([
|
||||
'security_guard_id' => ['required', 'exists:security_guards,id'],
|
||||
], [
|
||||
'security_guard_id.required' => 'Silakan pilih nama petugas Satpam yang melakukan pemeriksaan.',
|
||||
]);
|
||||
$guardId = $request->input('security_guard_id');
|
||||
$fallbackGuard = SecurityGuard::where('is_active', true)->first() ?? SecurityGuard::first();
|
||||
if ($fallbackGuard) {
|
||||
$guardId = $fallbackGuard->id;
|
||||
} else {
|
||||
$request->validate([
|
||||
'security_guard_id' => ['required', 'exists:security_guards,id'],
|
||||
], [
|
||||
'security_guard_id.required' => 'Silakan pilih nama petugas Satpam yang melakukan pemeriksaan.',
|
||||
]);
|
||||
$guardId = $request->input('security_guard_id');
|
||||
}
|
||||
}
|
||||
|
||||
$activity = VehicleActivity::with('vehicle')->findOrFail($id);
|
||||
|
||||
@@ -17,10 +17,33 @@ class SecurityGuardController extends Controller
|
||||
/**
|
||||
* Tampilkan daftar petugas Satpam beserta daftar pos gerbang.
|
||||
*/
|
||||
public function index(): View
|
||||
public function index(Request $request): View
|
||||
{
|
||||
$guards = SecurityGuard::with(['gate', 'user'])
|
||||
->orderBy('team')
|
||||
$query = SecurityGuard::with(['gate', 'user']);
|
||||
|
||||
// 1. Pencarian Kata Kunci (ID Satpam / Nama Lengkap / Pos Gerbang)
|
||||
if ($request->filled('search')) {
|
||||
$search = trim($request->input('search'));
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('badge_id', 'like', "%{$search}%")
|
||||
->orWhere('name', 'like', "%{$search}%")
|
||||
->orWhereHas('gate', function ($gq) use ($search) {
|
||||
$gq->where('name', 'like', "%{$search}%");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// 2. Filter Regu Satpam (Regu 1, 2, atau 3)
|
||||
if ($request->filled('team')) {
|
||||
$query->where('team', (int) $request->input('team'));
|
||||
}
|
||||
|
||||
// 3. Filter Penempatan Pos Gerbang
|
||||
if ($request->filled('gate_id')) {
|
||||
$query->where('gate_id', (int) $request->input('gate_id'));
|
||||
}
|
||||
|
||||
$guards = $query->orderBy('team')
|
||||
->orderBy('name')
|
||||
->get();
|
||||
|
||||
@@ -138,4 +161,25 @@ class SecurityGuardController extends Controller
|
||||
$statusText = $newStatus ? 'diaktifkan' : 'dinonaktifkan';
|
||||
return back()->with('success', "Status petugas Satpam ({$guard->name}) berhasil {$statusText}.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Hapus data petugas Satpam beserta akun login terkait.
|
||||
*/
|
||||
public function destroy(int $id): RedirectResponse
|
||||
{
|
||||
$guard = SecurityGuard::with('user')->findOrFail($id);
|
||||
$guardName = $guard->name;
|
||||
$badgeId = $guard->badge_id;
|
||||
|
||||
DB::transaction(function () use ($guard) {
|
||||
$user = $guard->user;
|
||||
$guard->delete();
|
||||
|
||||
if ($user) {
|
||||
$user->delete();
|
||||
}
|
||||
});
|
||||
|
||||
return back()->with('success', "Data petugas Satpam {$guardName} ({$badgeId}) berhasil dihapus.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,11 +20,19 @@ class VerificationLogController extends Controller
|
||||
$query = VehicleActivity::with(['vehicle', 'driver', 'gate', 'securityGuard'])
|
||||
->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 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 Regu Satpam (1, 2, 3)
|
||||
@@ -82,6 +90,6 @@ class VerificationLogController extends Controller
|
||||
$gates = Gate::where('is_active', true)->orderBy('name')->get();
|
||||
$guards = SecurityGuard::orderBy('name')->get();
|
||||
|
||||
return view('pg.verification_logs', compact('activities', 'gates', 'guards'));
|
||||
return view('pg.verification_logs', compact('activities', 'gates', 'guards', 'startDate', 'endDate'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user