feat(pg): add flexible gate selection pop-up and remove rigid guard gate assignment
This commit is contained in:
@@ -21,13 +21,30 @@ class GateInspectionController extends Controller
|
||||
*/
|
||||
public function index(Request $request): View
|
||||
{
|
||||
// Ambil gerbang yang terikat pada akun petugas pos jaga yang sedang login
|
||||
$user = $request->user();
|
||||
$currentGuard = $user ? $user->securityGuard : null;
|
||||
$gateId = $user ? $user->gate_id : $request->query('gate_id');
|
||||
|
||||
// Jika tidak ada gate_id terikat, ambil gerbang pertama sebagai fallback
|
||||
$gate = $gateId ? Gate::find($gateId) : Gate::first();
|
||||
$allGates = Gate::where('is_active', true)->orderBy('name')->get();
|
||||
|
||||
// Cek gate yang dipilih: query param > session 'active_gate_id' > user->gate_id
|
||||
$selectedGateId = $request->query('gate_id')
|
||||
?: session('active_gate_id')
|
||||
?: ($user?->gate_id);
|
||||
|
||||
$needsGateSelection = false;
|
||||
$gate = null;
|
||||
|
||||
if ($selectedGateId && $allGates->contains('id', (int) $selectedGateId)) {
|
||||
$gate = $allGates->firstWhere('id', (int) $selectedGateId);
|
||||
session(['active_gate_id' => $gate->id]);
|
||||
if ($user && $user->gate_id !== $gate->id) {
|
||||
$user->update(['gate_id' => $gate->id]);
|
||||
}
|
||||
} else {
|
||||
// Belum ada pos yang dipilih di sesi
|
||||
$gate = $allGates->first();
|
||||
$needsGateSelection = true;
|
||||
}
|
||||
|
||||
$pendingActivities = collect();
|
||||
if ($gate) {
|
||||
@@ -38,24 +55,61 @@ class GateInspectionController extends Controller
|
||||
->get();
|
||||
}
|
||||
|
||||
// Hitung antrean pending di setiap gerbang untuk pop-up pemilihan
|
||||
$gateQueueCounts = VehicleActivity::where('validation_status', 'pending')
|
||||
->select('gate_id', DB::raw('count(*) as count'))
|
||||
->groupBy('gate_id')
|
||||
->pluck('count', 'gate_id');
|
||||
|
||||
// Daftar satpam aktif untuk fallback pilihan
|
||||
$guards = SecurityGuard::where('is_active', true)->orderBy('name')->get();
|
||||
|
||||
return view('pg.gate_inspection', compact(
|
||||
'gate',
|
||||
'allGates',
|
||||
'gateQueueCounts',
|
||||
'needsGateSelection',
|
||||
'pendingActivities',
|
||||
'guards',
|
||||
'currentGuard'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set / ganti pos gerbang aktif yang sedang dijaga oleh petugas saat ini.
|
||||
*/
|
||||
public function selectGate(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'gate_id' => ['required', 'exists:gates,id'],
|
||||
], [
|
||||
'gate_id.required' => 'Silakan pilih salah satu pos gerbang.',
|
||||
'gate_id.exists' => 'Pos gerbang yang dipilih tidak valid.',
|
||||
]);
|
||||
|
||||
$gateId = (int) $request->input('gate_id');
|
||||
$gate = Gate::findOrFail($gateId);
|
||||
|
||||
session(['active_gate_id' => $gate->id]);
|
||||
|
||||
$user = $request->user();
|
||||
if ($user && $user->gate_id !== $gate->id) {
|
||||
$user->update(['gate_id' => $gate->id]);
|
||||
}
|
||||
|
||||
return redirect()->route('pg.gate.inspection', ['gate_id' => $gate->id])
|
||||
->with('success', "Pos jaga aktif berhasil dialihkan ke: {$gate->name}");
|
||||
}
|
||||
|
||||
/**
|
||||
* 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');
|
||||
$gateId = $request->query('gate_id')
|
||||
?: session('active_gate_id')
|
||||
?: ($user ? $user->gate_id : null);
|
||||
$gate = $gateId ? Gate::find($gateId) : Gate::first();
|
||||
|
||||
$pendingActivities = collect();
|
||||
|
||||
@@ -215,7 +215,7 @@ class SecurityGuardController extends Controller
|
||||
'badge_id' => ['required', 'string', 'max:50', 'unique:security_guards,badge_id', 'unique:users,username'],
|
||||
'name' => ['required', 'string', 'max:100'],
|
||||
'team' => ['required', 'integer', 'in:1,2,3'],
|
||||
'gate_id' => ['required', 'exists:gates,id'],
|
||||
'gate_id' => ['nullable', 'exists:gates,id'],
|
||||
'password' => ['required', 'string', 'min:4'],
|
||||
], [
|
||||
'badge_id.required' => 'ID Satpam wajib diisi.',
|
||||
@@ -223,13 +223,13 @@ class SecurityGuardController extends Controller
|
||||
'name.required' => 'Nama lengkap Satpam wajib diisi.',
|
||||
'team.required' => 'Silakan pilih Regu Satpam (1, 2, atau 3).',
|
||||
'team.in' => 'Regu Satpam harus bernilai 1, 2, atau 3.',
|
||||
'gate_id.required' => 'Silakan tentukan penempatan Pos Gerbang.',
|
||||
'password.required' => 'Password akun login Satpam wajib diisi.',
|
||||
'password.min' => 'Password minimal terdiri dari 4 karakter.',
|
||||
]);
|
||||
|
||||
DB::transaction(function () use ($request) {
|
||||
$badgeId = strtoupper(trim($request->input('badge_id')));
|
||||
$gateId = $request->input('gate_id') ?: null;
|
||||
|
||||
// 1. Buat akun User untuk login Satpam di pos jaga
|
||||
$user = User::create([
|
||||
@@ -238,7 +238,7 @@ class SecurityGuardController extends Controller
|
||||
'email' => strtolower($badgeId) . '@kmh.co.id',
|
||||
'password' => Hash::make($request->input('password')),
|
||||
'role' => 'gate_officer',
|
||||
'gate_id' => $request->input('gate_id'),
|
||||
'gate_id' => $gateId,
|
||||
]);
|
||||
|
||||
// 2. Simpan master data Satpam
|
||||
@@ -246,7 +246,7 @@ class SecurityGuardController extends Controller
|
||||
'badge_id' => $badgeId,
|
||||
'name' => $request->input('name'),
|
||||
'team' => (int) $request->input('team'),
|
||||
'gate_id' => $request->input('gate_id'),
|
||||
'gate_id' => $gateId,
|
||||
'user_id' => $user->id,
|
||||
'is_active' => true,
|
||||
]);
|
||||
@@ -265,26 +265,27 @@ class SecurityGuardController extends Controller
|
||||
$request->validate([
|
||||
'name' => ['required', 'string', 'max:100'],
|
||||
'team' => ['required', 'integer', 'in:1,2,3'],
|
||||
'gate_id' => ['required', 'exists:gates,id'],
|
||||
'gate_id' => ['nullable', 'exists:gates,id'],
|
||||
'password' => ['nullable', 'string', 'min:4'],
|
||||
], [
|
||||
'name.required' => 'Nama lengkap Satpam wajib diisi.',
|
||||
'team.required' => 'Silakan pilih Regu Satpam (1, 2, atau 3).',
|
||||
'gate_id.required' => 'Silakan tentukan penempatan Pos Gerbang.',
|
||||
'password.min' => 'Password minimal terdiri dari 4 karakter.',
|
||||
]);
|
||||
|
||||
DB::transaction(function () use ($request, $guard) {
|
||||
$gateId = $request->has('gate_id') ? ($request->input('gate_id') ?: null) : $guard->gate_id;
|
||||
|
||||
$guard->update([
|
||||
'name' => $request->input('name'),
|
||||
'team' => (int) $request->input('team'),
|
||||
'gate_id' => $request->input('gate_id'),
|
||||
'gate_id' => $gateId,
|
||||
]);
|
||||
|
||||
if ($guard->user) {
|
||||
$userData = [
|
||||
'name' => $request->input('name'),
|
||||
'gate_id' => $request->input('gate_id'),
|
||||
'gate_id' => $gateId,
|
||||
];
|
||||
|
||||
if ($request->filled('password')) {
|
||||
|
||||
@@ -36,6 +36,14 @@
|
||||
<span class="px-2.5 py-1 rounded-lg text-xs font-black bg-blue-50 text-blue-700 border border-blue-200">
|
||||
Regu {{ $currentGuard->team ?? '1' }}
|
||||
</span>
|
||||
<!-- Tombol Fleksibel Ganti Pos Jaga -->
|
||||
<button type="button"
|
||||
onclick="openGateSelectionModal()"
|
||||
class="inline-flex items-center gap-1.5 px-3 py-1 rounded-xl text-xs font-bold bg-amber-500 hover:bg-amber-600 text-white transition shadow-2xs cursor-pointer"
|
||||
title="Ganti pos gerbang yang sedang dijaga">
|
||||
<i class="fa-solid fa-arrows-rotate text-[11px]"></i>
|
||||
<span>Ganti Pos</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="text-sm sm:text-base text-slate-600 font-medium truncate mt-1 flex items-center flex-wrap gap-1.5">
|
||||
<span>Petugas: <strong class="text-slate-900 font-bold">{{ $currentGuard ? $currentGuard->name : auth()->user()->name }}</strong></span>
|
||||
@@ -336,7 +344,7 @@
|
||||
isSyncing = true;
|
||||
|
||||
try {
|
||||
const response = await fetch("{{ route('pg.gate.live_queue') }}", {
|
||||
const response = await fetch("{{ route('pg.gate.live_queue') }}?gate_id={{ $gate ? $gate->id : '' }}", {
|
||||
headers: {
|
||||
'X-Requested-With': 'XMLHttpRequest',
|
||||
'Accept': 'application/json'
|
||||
@@ -427,6 +435,41 @@
|
||||
const modal = document.getElementById('imageLightboxModal');
|
||||
if (modal) modal.classList.add('hidden');
|
||||
}
|
||||
|
||||
// Modal Pemilihan Pos Gerbang Bertugas
|
||||
let isGateModalForced = {{ $needsGateSelection ? 'true' : 'false' }};
|
||||
|
||||
function openGateSelectionModal(isForced = false) {
|
||||
isGateModalForced = isForced;
|
||||
const modal = document.getElementById('gateSelectionModal');
|
||||
if (modal) {
|
||||
modal.classList.remove('hidden');
|
||||
modal.style.display = 'block';
|
||||
}
|
||||
}
|
||||
|
||||
function closeGateSelectionModal() {
|
||||
if (isGateModalForced) {
|
||||
return;
|
||||
}
|
||||
const modal = document.getElementById('gateSelectionModal');
|
||||
if (modal) {
|
||||
modal.classList.add('hidden');
|
||||
modal.style.display = 'none';
|
||||
}
|
||||
}
|
||||
|
||||
function onGateModalBackdropClick() {
|
||||
if (!isGateModalForced) {
|
||||
closeGateSelectionModal();
|
||||
}
|
||||
}
|
||||
|
||||
@if($needsGateSelection)
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
openGateSelectionModal(true);
|
||||
});
|
||||
@endif
|
||||
</script>
|
||||
|
||||
<!-- MODAL LIGHTBOX PRATINJAU FOTO DRIVER & MOBIL LV -->
|
||||
@@ -443,4 +486,98 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ========================================================================= -->
|
||||
<!-- MODAL POPUP: PILIH POS GERBANG BERTUGAS -->
|
||||
<!-- ========================================================================= -->
|
||||
<div id="gateSelectionModal"
|
||||
class="{{ $needsGateSelection ? '' : 'hidden' }} fixed inset-0 z-50 overflow-y-auto"
|
||||
style="{{ $needsGateSelection ? 'display: block;' : 'display: none;' }}">
|
||||
<!-- Backdrop Gelap -->
|
||||
<div class="fixed inset-0 bg-slate-900/60 backdrop-blur-xs transition-opacity"
|
||||
onclick="onGateModalBackdropClick()"></div>
|
||||
|
||||
<div class="flex min-h-full items-center justify-center p-4">
|
||||
<div class="relative w-full max-w-xl bg-white rounded-3xl shadow-2xl border border-slate-100 overflow-hidden transform transition-all p-6 sm:p-7 space-y-5">
|
||||
<!-- Header Modal -->
|
||||
<div class="flex items-start justify-between gap-3 pb-3 border-b border-slate-100">
|
||||
<div class="flex items-center space-x-3">
|
||||
<div class="w-12 h-12 rounded-2xl bg-amber-100 text-amber-700 flex items-center justify-center text-xl flex-shrink-0 shadow-2xs">
|
||||
<i class="fa-solid fa-door-open"></i>
|
||||
</div>
|
||||
<div>
|
||||
<h3 class="text-base sm:text-lg font-black text-slate-900 tracking-tight">
|
||||
Pilih Pos Gerbang Bertugas
|
||||
</h3>
|
||||
<p class="text-xs text-slate-500 mt-0.5">
|
||||
Tentukan gerbang tempat Anda berjaga saat ini untuk verifikasi perlintasan.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@if(!$needsGateSelection)
|
||||
<button type="button" onclick="closeGateSelectionModal()" class="text-slate-400 hover:text-slate-600 p-1.5 rounded-lg hover:bg-slate-100 transition cursor-pointer">
|
||||
<i class="fa-solid fa-xmark text-sm"></i>
|
||||
</button>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<!-- Form Pemilihan Pos Gerbang -->
|
||||
<form action="{{ route('pg.gate.select_gate') }}" method="POST" id="gateSelectionForm">
|
||||
@csrf
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 gap-3.5 max-h-[60vh] overflow-y-auto p-1">
|
||||
@foreach($allGates as $g)
|
||||
@php
|
||||
$isCurrent = $gate && $gate->id === $g->id;
|
||||
$queueCount = $gateQueueCounts[$g->id] ?? 0;
|
||||
@endphp
|
||||
<label class="relative flex flex-col justify-between p-4 rounded-2xl border-2 cursor-pointer transition-all hover:shadow-md {{ $isCurrent ? 'border-amber-500 bg-amber-50/50' : 'border-slate-200 bg-white hover:border-slate-300' }}">
|
||||
<input type="radio"
|
||||
name="gate_id"
|
||||
value="{{ $g->id }}"
|
||||
{{ $isCurrent ? 'checked' : '' }}
|
||||
class="sr-only"
|
||||
onchange="document.getElementById('gateSelectionForm').submit()">
|
||||
<div>
|
||||
<div class="flex items-center justify-between mb-2">
|
||||
<span class="w-8 h-8 rounded-xl flex items-center justify-center text-xs font-bold {{ $isCurrent ? 'bg-amber-500 text-white' : 'bg-slate-100 text-slate-700' }}">
|
||||
<i class="fa-solid fa-shield-halved"></i>
|
||||
</span>
|
||||
@if($isCurrent)
|
||||
<span class="text-[10px] font-black uppercase px-2 py-0.5 rounded-full bg-emerald-100 text-emerald-800 border border-emerald-300">
|
||||
Pos Aktif
|
||||
</span>
|
||||
@elseif($queueCount > 0)
|
||||
<span class="text-[10px] font-black px-2 py-0.5 rounded-full bg-amber-100 text-amber-900 border border-amber-300">
|
||||
{{ $queueCount }} Antrean
|
||||
</span>
|
||||
@else
|
||||
<span class="text-[10px] font-semibold px-2 py-0.5 rounded-full bg-slate-100 text-slate-500">
|
||||
Bebas
|
||||
</span>
|
||||
@endif
|
||||
</div>
|
||||
<h4 class="text-sm font-black text-slate-900">{{ $g->name }}</h4>
|
||||
<p class="text-xs text-slate-500 mt-1 line-clamp-2">
|
||||
{{ $g->location ?: 'Pos pemeriksaan keluar/masuk kendaraan' }}
|
||||
</p>
|
||||
</div>
|
||||
<div class="mt-4 pt-3 border-t border-slate-100 flex items-center justify-between text-xs font-bold {{ $isCurrent ? 'text-amber-700' : 'text-slate-600' }}">
|
||||
<span>{{ $isCurrent ? 'Sedang Dipilih' : 'Klik untuk Memilih' }}</span>
|
||||
<i class="fa-solid fa-arrow-right text-[11px]"></i>
|
||||
</div>
|
||||
</label>
|
||||
@endforeach
|
||||
</div>
|
||||
|
||||
@if(!$needsGateSelection)
|
||||
<div class="flex items-center justify-end pt-3 border-t border-slate-100 mt-4">
|
||||
<button type="button" onclick="closeGateSelectionModal()" class="px-4 py-2 text-xs font-bold text-slate-600 hover:bg-slate-100 rounded-xl transition cursor-pointer">
|
||||
Batal
|
||||
</button>
|
||||
</div>
|
||||
@endif
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@@ -78,30 +78,17 @@
|
||||
|
||||
<!-- Filter di Kanan (Pada Mobile: Sejajar 2 Kolom di Bawah Search Bar) -->
|
||||
<div class="flex flex-col sm:flex-row items-stretch sm:items-center justify-end gap-2 sm:gap-2.5 w-full sm:w-auto">
|
||||
<div class="grid grid-cols-2 gap-2 sm:flex sm:items-center sm:gap-2.5 w-full sm:w-auto">
|
||||
<div class="flex items-center gap-2 sm:gap-2.5 w-full sm:w-auto">
|
||||
<!-- Filter Regu Satpam -->
|
||||
<select name="team"
|
||||
id="guardTeamSelect"
|
||||
onchange="this.form.submit()"
|
||||
class="w-full sm:w-auto text-xs rounded-xl border border-slate-200 bg-white px-2.5 sm:px-3 py-2.5 text-slate-700 font-semibold focus:outline-none focus:border-[#1b5e20] focus:ring-2 focus:ring-[#1b5e20]/10 shadow-sm transition truncate">
|
||||
class="w-full sm:w-auto text-xs rounded-xl border border-slate-200 bg-white px-3 py-2.5 text-slate-700 font-semibold focus:outline-none focus:border-[#1b5e20] focus:ring-2 focus:ring-[#1b5e20]/10 shadow-sm transition truncate">
|
||||
<option value="">Semua Regu</option>
|
||||
<option value="1" {{ request('team') == '1' ? 'selected' : '' }}>Regu 1</option>
|
||||
<option value="2" {{ request('team') == '2' ? 'selected' : '' }}>Regu 2</option>
|
||||
<option value="3" {{ request('team') == '3' ? 'selected' : '' }}>Regu 3</option>
|
||||
</select>
|
||||
|
||||
<!-- Filter Penempatan Pos Gerbang -->
|
||||
<select name="gate_id"
|
||||
id="guardGateSelect"
|
||||
onchange="this.form.submit()"
|
||||
class="w-full sm:w-auto text-xs rounded-xl border border-slate-200 bg-white px-2.5 sm:px-3 py-2.5 text-slate-700 font-semibold focus:outline-none focus:border-[#1b5e20] focus:ring-2 focus:ring-[#1b5e20]/10 shadow-sm transition truncate">
|
||||
<option value="">Semua Penempatan</option>
|
||||
@foreach($gates as $gate)
|
||||
<option value="{{ $gate->id }}" {{ request('gate_id') == $gate->id ? 'selected' : '' }}>
|
||||
{{ $gate->name }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<!-- Tombol Reset Filter (Sesuai Referensi Merah / Rose Clean Text) -->
|
||||
@@ -129,7 +116,6 @@
|
||||
<th class="py-3.5 px-4">ID SATPAM</th>
|
||||
<th class="py-3.5 px-4">NAMA LENGKAP</th>
|
||||
<th class="py-3.5 px-4 text-center">REGU</th>
|
||||
<th class="py-3.5 px-4 text-center">PENEMPATAN</th>
|
||||
<th class="py-3.5 px-4 text-center">STATUS</th>
|
||||
<th class="py-3.5 px-4 text-center w-36">AKSI</th>
|
||||
</tr>
|
||||
@@ -171,13 +157,6 @@
|
||||
@endif
|
||||
</td>
|
||||
|
||||
<!-- Penempatan Pos Gerbang -->
|
||||
<td class="py-3.5 px-4 text-center whitespace-nowrap">
|
||||
<span class="inline-flex items-center px-2.5 py-1 rounded-lg text-xs font-semibold bg-slate-100 text-slate-700 border border-slate-200">
|
||||
{{ $g->gate->name ?? 'Belum Ditentukan' }}
|
||||
</span>
|
||||
</td>
|
||||
|
||||
<!-- Status Aktif / Nonaktif -->
|
||||
<td class="py-3.5 px-4 text-center whitespace-nowrap">
|
||||
@if($g->is_active)
|
||||
@@ -232,7 +211,7 @@
|
||||
</tr>
|
||||
@empty
|
||||
<tr id="serverGuardEmptyRow">
|
||||
<td colspan="7" class="py-12 text-center text-slate-400">
|
||||
<td colspan="6" class="py-12 text-center text-slate-400">
|
||||
<i class="fa-solid fa-magnifying-glass text-3xl mb-3 block text-slate-300"></i>
|
||||
@if(request('search'))
|
||||
<p class="text-sm font-semibold text-slate-700">
|
||||
@@ -241,7 +220,7 @@
|
||||
<p class="text-xs text-slate-400 mt-1">Pastikan ejaan ID Satpam atau nama petugas yang dicari sudah benar.</p>
|
||||
@elseif(request()->anyFilled(['team', 'gate_id']))
|
||||
<p class="text-sm font-semibold text-slate-700">Belum ada data petugas Satpam yang sesuai kriteria filter.</p>
|
||||
<p class="text-xs text-slate-400 mt-1">Silakan pilih regu atau penempatan pos gerbang lain.</p>
|
||||
<p class="text-xs text-slate-400 mt-1">Silakan pilih regu atau ubah kata kunci pencarian.</p>
|
||||
@else
|
||||
<i class="fa-solid fa-user-slash text-3xl mb-2 block text-slate-300"></i>
|
||||
<p class="text-sm font-semibold text-slate-700">Belum ada data petugas Satpam terdaftar.</p>
|
||||
@@ -317,39 +296,21 @@
|
||||
class="w-full text-sm px-4 py-3 rounded-2xl border border-slate-200 bg-white text-slate-800 placeholder-slate-400 focus:outline-none focus:border-[#1b5e20] focus:ring-2 focus:ring-[#1b5e20]/10 transition">
|
||||
</div>
|
||||
|
||||
<!-- Grid: Regu & Penempatan -->
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 gap-3.5">
|
||||
<div>
|
||||
<label for="team" class="block text-sm font-bold text-slate-800 mb-2">
|
||||
Regu Tugas <span class="text-rose-500">*</span>
|
||||
</label>
|
||||
<select name="team"
|
||||
id="team"
|
||||
required
|
||||
class="w-full text-sm px-4 py-3 rounded-2xl border border-slate-200 bg-white text-slate-800 focus:outline-none focus:border-[#1b5e20] focus:ring-2 focus:ring-[#1b5e20]/10 transition">
|
||||
<option value="" disabled selected>Pilih Regu</option>
|
||||
<option value="1" {{ old('team') == 1 ? 'selected' : '' }}>Regu 1</option>
|
||||
<option value="2" {{ old('team') == 2 ? 'selected' : '' }}>Regu 2</option>
|
||||
<option value="3" {{ old('team') == 3 ? 'selected' : '' }}>Regu 3</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="gate_id" class="block text-sm font-bold text-slate-800 mb-2">
|
||||
Penempatan Pos <span class="text-rose-500">*</span>
|
||||
</label>
|
||||
<select name="gate_id"
|
||||
id="gate_id"
|
||||
required
|
||||
class="w-full text-sm px-4 py-3 rounded-2xl border border-slate-200 bg-white text-slate-800 focus:outline-none focus:border-[#1b5e20] focus:ring-2 focus:ring-[#1b5e20]/10 transition">
|
||||
<option value="" disabled selected>Pilih Pos Gerbang</option>
|
||||
@foreach($gates as $gate)
|
||||
<option value="{{ $gate->id }}" {{ old('gate_id') == $gate->id ? 'selected' : '' }}>
|
||||
{{ $gate->name }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
<!-- Regu Tugas Satpam (Fleksibel Lintas Seluruh Pos Gerbang) -->
|
||||
<div>
|
||||
<label for="team" class="block text-sm font-bold text-slate-800 mb-2">
|
||||
Regu Tugas <span class="text-rose-500">*</span>
|
||||
</label>
|
||||
<select name="team"
|
||||
id="team"
|
||||
required
|
||||
class="w-full text-sm px-4 py-3 rounded-2xl border border-slate-200 bg-white text-slate-800 focus:outline-none focus:border-[#1b5e20] focus:ring-2 focus:ring-[#1b5e20]/10 transition">
|
||||
<option value="" disabled selected>Pilih Regu</option>
|
||||
<option value="1" {{ old('team') == 1 ? 'selected' : '' }}>Regu 1</option>
|
||||
<option value="2" {{ old('team') == 2 ? 'selected' : '' }}>Regu 2</option>
|
||||
<option value="3" {{ old('team') == 3 ? 'selected' : '' }}>Regu 3</option>
|
||||
</select>
|
||||
<span class="text-[11px] text-slate-400 block mt-1">Petugas dapat memilih pos gerbang jaga saat login/bertugas secara fleksibel.</span>
|
||||
</div>
|
||||
|
||||
<!-- Password Akun Login -->
|
||||
@@ -414,31 +375,18 @@
|
||||
class="w-full text-sm px-4 py-3 rounded-2xl border border-slate-200 bg-white text-slate-800 placeholder-slate-400 focus:outline-none focus:border-[#1b5e20] focus:ring-2 focus:ring-[#1b5e20]/10 transition">
|
||||
</div>
|
||||
|
||||
<!-- Grid: Regu & Penempatan -->
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 gap-3.5">
|
||||
<div>
|
||||
<label for="editTeam" class="block text-sm font-bold text-slate-800 mb-2">
|
||||
Regu Tugas <span class="text-rose-500">*</span>
|
||||
</label>
|
||||
<select name="team" id="editTeam" required
|
||||
class="w-full text-sm px-4 py-3 rounded-2xl border border-slate-200 bg-white text-slate-800 focus:outline-none focus:border-[#1b5e20] focus:ring-2 focus:ring-[#1b5e20]/10 transition">
|
||||
<option value="1">Regu 1</option>
|
||||
<option value="2">Regu 2</option>
|
||||
<option value="3">Regu 3</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="editGateId" class="block text-sm font-bold text-slate-800 mb-2">
|
||||
Penempatan Pos <span class="text-rose-500">*</span>
|
||||
</label>
|
||||
<select name="gate_id" id="editGateId" required
|
||||
class="w-full text-sm px-4 py-3 rounded-2xl border border-slate-200 bg-white text-slate-800 focus:outline-none focus:border-[#1b5e20] focus:ring-2 focus:ring-[#1b5e20]/10 transition">
|
||||
@foreach($gates as $gate)
|
||||
<option value="{{ $gate->id }}">{{ $gate->name }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
<!-- Regu Tugas -->
|
||||
<div>
|
||||
<label for="editTeam" class="block text-sm font-bold text-slate-800 mb-2">
|
||||
Regu Tugas <span class="text-rose-500">*</span>
|
||||
</label>
|
||||
<select name="team" id="editTeam" required
|
||||
class="w-full text-sm px-4 py-3 rounded-2xl border border-slate-200 bg-white text-slate-800 focus:outline-none focus:border-[#1b5e20] focus:ring-2 focus:ring-[#1b5e20]/10 transition">
|
||||
<option value="1">Regu 1</option>
|
||||
<option value="2">Regu 2</option>
|
||||
<option value="3">Regu 3</option>
|
||||
</select>
|
||||
<span class="text-[11px] text-slate-400 block mt-1">Petugas dapat memilih pos gerbang jaga saat login/bertugas secara fleksibel.</span>
|
||||
</div>
|
||||
|
||||
<!-- Ganti Password Baru (Opsional) -->
|
||||
@@ -659,7 +607,8 @@
|
||||
document.getElementById('editBadgeId').value = guard.badge_id || ('SEC-' + String(guard.id).padStart(3, '0'));
|
||||
document.getElementById('editName').value = guard.name || '';
|
||||
document.getElementById('editTeam').value = guard.team || 1;
|
||||
document.getElementById('editGateId').value = guard.gate_id || '';
|
||||
const editGateInput = document.getElementById('editGateId');
|
||||
if (editGateInput) editGateInput.value = guard.gate_id || '';
|
||||
document.getElementById('editPassword').value = '';
|
||||
|
||||
modal.classList.remove('hidden');
|
||||
@@ -710,7 +659,7 @@
|
||||
const emptyTr = document.createElement('tr');
|
||||
emptyTr.id = 'guardEmptySearchRow';
|
||||
emptyTr.innerHTML = `
|
||||
<td colspan="7" class="py-12 text-center text-slate-400">
|
||||
<td colspan="6" class="py-12 text-center text-slate-400">
|
||||
<i class="fa-solid fa-magnifying-glass text-3xl mb-3 block text-slate-300"></i>
|
||||
<p class="text-sm font-semibold text-slate-700">
|
||||
Data "<span class="text-rose-600 font-bold">${escapeHtml(rawValue)}</span>" tidak ditemukan di tabel
|
||||
|
||||
@@ -161,6 +161,7 @@ Route::middleware('auth')->group(function () {
|
||||
|
||||
// Verifikasi Pos Gerbang (Khusus Petugas Satpam Pos Gerbang)
|
||||
Route::get('/gate-inspection', [GateInspectionController::class, 'index'])->name('gate.inspection')->middleware('permission:gate.inspect');
|
||||
Route::post('/gate-inspection/select-gate', [GateInspectionController::class, 'selectGate'])->name('gate.select_gate')->middleware('permission:gate.inspect');
|
||||
Route::get('/gate-inspection/live-queue', [GateInspectionController::class, 'liveQueue'])->name('gate.live_queue')->middleware('permission:gate.inspect');
|
||||
Route::post('/gate-inspection/{id}/approve', [GateInspectionController::class, 'approve'])->name('gate.approve')->middleware('permission:gate.approve');
|
||||
Route::post('/gate-inspection/{id}/reject', [GateInspectionController::class, 'reject'])->name('gate.reject')->middleware('permission:gate.reject');
|
||||
|
||||
@@ -0,0 +1,193 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\Employee;
|
||||
use App\Models\Gate;
|
||||
use App\Models\SecurityGuard;
|
||||
use App\Models\User;
|
||||
use App\Models\Vehicle;
|
||||
use App\Models\VehicleActivity;
|
||||
use Database\Seeders\RolePermissionSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class GateInspectionTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private User $guardUser;
|
||||
private SecurityGuard $guard;
|
||||
private Gate $gate1;
|
||||
private Gate $gate2;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->seed(RolePermissionSeeder::class);
|
||||
|
||||
$this->gate1 = Gate::create([
|
||||
'name' => 'Pos Gerbang Utama',
|
||||
'code' => 'GATE-01',
|
||||
'location' => 'Main Entrance',
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
$this->gate2 = Gate::create([
|
||||
'name' => 'Pos Gerbang Bendungan',
|
||||
'code' => 'GATE-02',
|
||||
'location' => 'Dam Access',
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
// Satpam dibuat TANPA gate_id (fleksibel)
|
||||
$this->guardUser = User::factory()->create([
|
||||
'name' => 'Petugas Satpam Uji',
|
||||
'username' => 'SEC999',
|
||||
'role' => 'gate_officer',
|
||||
'gate_id' => null,
|
||||
]);
|
||||
$this->guardUser->assignRole('gate_officer');
|
||||
|
||||
$this->guard = SecurityGuard::create([
|
||||
'badge_id' => 'SEC999',
|
||||
'name' => 'Petugas Satpam Uji',
|
||||
'team' => 1,
|
||||
'gate_id' => null,
|
||||
'user_id' => $this->guardUser->id,
|
||||
'is_active' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saat satpam pertama kali login dan belum memilih gerbang di sesi,
|
||||
* flag needsGateSelection = true dan modal pemilihan pos gerbang ditampilkan.
|
||||
*/
|
||||
public function test_guard_without_selected_gate_sees_selection_modal(): void
|
||||
{
|
||||
$response = $this->actingAs($this->guardUser)
|
||||
->get(route('pg.gate.inspection'));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertViewHas('needsGateSelection', true);
|
||||
$response->assertSee('Pilih Pos Gerbang Bertugas');
|
||||
$response->assertSee('Pos Gerbang Utama');
|
||||
$response->assertSee('Pos Gerbang Bendungan');
|
||||
$response->assertSee('Ganti Pos');
|
||||
}
|
||||
|
||||
/**
|
||||
* Satpam dapat memilih pos gerbang via POST select-gate.
|
||||
* Sistem menyimpan ke session active_gate_id dan mengalihkan ke verifikasi gerbang terkait.
|
||||
*/
|
||||
public function test_guard_can_select_gate_and_stores_in_session(): void
|
||||
{
|
||||
$response = $this->actingAs($this->guardUser)
|
||||
->post(route('pg.gate.select_gate'), [
|
||||
'gate_id' => $this->gate2->id,
|
||||
]);
|
||||
|
||||
$response->assertRedirect(route('pg.gate.inspection', ['gate_id' => $this->gate2->id]));
|
||||
$response->assertSessionHas('active_gate_id', $this->gate2->id);
|
||||
|
||||
$this->guardUser->refresh();
|
||||
$this->assertEquals($this->gate2->id, $this->guardUser->gate_id);
|
||||
|
||||
// Setelah tersimpan di sesi, kunjungan berikutnya tidak memunculkan needsGateSelection = true
|
||||
$pageResponse = $this->actingAs($this->guardUser)
|
||||
->withSession(['active_gate_id' => $this->gate2->id])
|
||||
->get(route('pg.gate.inspection'));
|
||||
|
||||
$pageResponse->assertOk();
|
||||
$pageResponse->assertViewHas('needsGateSelection', false);
|
||||
$pageResponse->assertSee('Pos Pos Gerbang Bendungan');
|
||||
}
|
||||
|
||||
/**
|
||||
* Live queue mengambil data antrean sesuai gerbang yang sedang aktif.
|
||||
*/
|
||||
public function test_live_queue_filters_by_active_gate(): void
|
||||
{
|
||||
$vehicle = Vehicle::create([
|
||||
'code' => 'LV-99',
|
||||
'category' => 'light_vehicle',
|
||||
'brand_type' => 'Toyota Hilux 4x4',
|
||||
'current_km' => 1000,
|
||||
]);
|
||||
|
||||
$driver = Employee::create([
|
||||
'name' => 'Driver Uji',
|
||||
'nik' => 'KMH-999',
|
||||
]);
|
||||
|
||||
// Buat aktivitas pending di Gate 2
|
||||
VehicleActivity::create([
|
||||
'transaction_no' => 'TRX-999-01',
|
||||
'vehicle_id' => $vehicle->id,
|
||||
'driver_id' => $driver->id,
|
||||
'gate_id' => $this->gate2->id,
|
||||
'direction' => 'in',
|
||||
'previous_km' => 1000,
|
||||
'current_km' => 1050,
|
||||
'distance' => 50,
|
||||
'purpose' => 'Mobilisasi Pekerja Project',
|
||||
'validation_status' => 'pending',
|
||||
'recorded_at' => now(),
|
||||
]);
|
||||
|
||||
// Request live queue dengan gate_id Gate 1 -> count = 0
|
||||
$resGate1 = $this->actingAs($this->guardUser)
|
||||
->getJson(route('pg.gate.live_queue', ['gate_id' => $this->gate1->id]));
|
||||
|
||||
$resGate1->assertOk();
|
||||
$resGate1->assertJsonPath('count', 0);
|
||||
|
||||
// Request live queue dengan gate_id Gate 2 -> count = 1
|
||||
$resGate2 = $this->actingAs($this->guardUser)
|
||||
->getJson(route('pg.gate.live_queue', ['gate_id' => $this->gate2->id]));
|
||||
|
||||
$resGate2->assertOk();
|
||||
$resGate2->assertJsonPath('count', 1);
|
||||
$this->assertStringContainsString('LV-99', $resGate2->json('html'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin PG dapat mendaftarkan Satpam baru tanpa mengisi gate_id (penempatan fleksibel).
|
||||
*/
|
||||
public function test_admin_pg_can_store_guard_without_gate_id(): void
|
||||
{
|
||||
$adminPg = User::factory()->create([
|
||||
'name' => 'Admin PG Tester',
|
||||
'username' => 'admin_pg_test',
|
||||
'role' => 'pg_admin',
|
||||
]);
|
||||
$adminPg->assignRole('pg_admin');
|
||||
|
||||
$data = [
|
||||
'badge_id' => 'SEC-NEW-01',
|
||||
'name' => 'Satpam Baru Fleksibel',
|
||||
'team' => 2,
|
||||
'password' => 'secret123',
|
||||
// gate_id dikosongkan
|
||||
];
|
||||
|
||||
$response = $this->actingAs($adminPg)
|
||||
->post(route('pg.guards.store'), $data);
|
||||
|
||||
$response->assertRedirect();
|
||||
$response->assertSessionHas('success');
|
||||
|
||||
$this->assertDatabaseHas('security_guards', [
|
||||
'badge_id' => 'SEC-NEW-01',
|
||||
'name' => 'Satpam Baru Fleksibel',
|
||||
'team' => 2,
|
||||
'gate_id' => null,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('users', [
|
||||
'username' => 'SEC-NEW-01',
|
||||
'role' => 'gate_officer',
|
||||
'gate_id' => null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,7 @@ class SecurityGuardFilterTest extends TestCase
|
||||
$response->assertSee('Data Satpam');
|
||||
$response->assertSee('Cari ID Satpam atau nama petugas...');
|
||||
$response->assertSee('Semua Regu');
|
||||
$response->assertSee('Semua Penempatan');
|
||||
$response->assertDontSee('Semua Penempatan');
|
||||
$response->assertSee('Ahmad Fauzi');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user