feat: add verification log filtering, gate inspection, and dashboard views for private guard module
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Employee;
|
||||
use App\Models\Gate;
|
||||
use App\Models\Vehicle;
|
||||
use App\Models\VehicleActivity;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
/**
|
||||
* Tampilkan halaman utama (Homepage) Sistem RKM.
|
||||
* Menyajikan ringkasan sistem, statistik real-time,
|
||||
* serta tombol akses ke menu aktivitas kendaraan lewat gate.
|
||||
*/
|
||||
public function index(): View
|
||||
{
|
||||
// 1. Data Statistik Ringkasan Sistem
|
||||
$totalLv = Vehicle::lightVehicles()->count();
|
||||
$operationalLv = Vehicle::lightVehicles()->where('status', 'Operation')->count();
|
||||
$standbyLv = Vehicle::lightVehicles()->where('status', 'Standby')->count();
|
||||
|
||||
$totalDrivers = Employee::operators()->count();
|
||||
$validSimperCount = Employee::operators()
|
||||
->whereNotNull('simper_expired_at')
|
||||
->where('simper_expired_at', '>=', Carbon::today())
|
||||
->count();
|
||||
$expiredSimperCount = max(0, $totalDrivers - $validSimperCount);
|
||||
|
||||
$totalGates = Gate::where('is_active', true)->count();
|
||||
$todayActivitiesCount = VehicleActivity::whereDate('recorded_at', Carbon::today())->count();
|
||||
$totalActivities = VehicleActivity::count();
|
||||
|
||||
// 2. Daftar Seluruh Pos Gerbang Proyek
|
||||
$gates = Gate::where('is_active', true)
|
||||
->orderBy('name')
|
||||
->get();
|
||||
|
||||
return view('home', compact(
|
||||
'totalLv',
|
||||
'operationalLv',
|
||||
'standbyLv',
|
||||
'totalDrivers',
|
||||
'validSimperCount',
|
||||
'expiredSimperCount',
|
||||
'totalGates',
|
||||
'todayActivitiesCount',
|
||||
'totalActivities',
|
||||
'gates'
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -31,9 +31,14 @@ class EmployeeController extends Controller
|
||||
->take(5)
|
||||
->get();
|
||||
|
||||
// 2. Log Status & Masa Berlaku SIMPER (Semua Driver dengan status SIMPER)
|
||||
// 2. Monitoring Status & Masa Berlaku SIMPER (Prioritas Kedaluwarsa & Segera Habis)
|
||||
$today = now()->toDateString();
|
||||
$simperLogs = Employee::where('is_operator', true)
|
||||
->orderBy('simper_expired_at', 'asc')
|
||||
->orderByRaw("CASE
|
||||
WHEN simper_expired_at IS NULL THEN 1
|
||||
WHEN simper_expired_at < '{$today}' THEN 0
|
||||
ELSE 2
|
||||
END ASC, simper_expired_at ASC")
|
||||
->take(5)
|
||||
->get();
|
||||
|
||||
|
||||
@@ -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'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,27 +9,25 @@ use App\Models\Gate;
|
||||
use App\Models\Vehicle;
|
||||
use App\Models\VehicleActivity;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class VehicleActivityFormController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* Tampilkan form pencatatan aktivitas kendaraan saat scan QR code.
|
||||
*/
|
||||
public function show(string $code): View
|
||||
public function show(Request $request, string $code): View
|
||||
{
|
||||
$vehicle = Vehicle::where('code', $code)
|
||||
->where('category', 'light_vehicle')
|
||||
->firstOrFail();
|
||||
|
||||
// Ambil semua driver/operator aktif
|
||||
$drivers = Employee::operators()
|
||||
->orderBy('name')
|
||||
->get();
|
||||
|
||||
// Ambil daftar gerbang aktif
|
||||
$gates = Gate::where('is_active', true)
|
||||
->orderBy('name')
|
||||
@@ -38,7 +36,141 @@ class VehicleActivityFormController extends Controller
|
||||
// Tentukan arah yang diperbolehkan berdasarkan riwayat terakhir
|
||||
$allowedDirection = $vehicle->determineNextAllowedDirection();
|
||||
|
||||
return view('public.vehicle_activity_form', compact('vehicle', 'drivers', 'gates', 'allowedDirection'));
|
||||
$verifiedDriver = null;
|
||||
$nikError = null;
|
||||
$nikErrorTitle = 'Verifikasi Gagal';
|
||||
$inputNik = trim((string) $request->input('nik', ''));
|
||||
|
||||
// Cek jika ada pengemudi yang sudah terverifikasi sebelumnya (via form error redirect atau query string NIK)
|
||||
$oldDriverId = old('driver_id');
|
||||
if ($oldDriverId) {
|
||||
$emp = Employee::find($oldDriverId);
|
||||
if ($emp && $emp->is_operator && $emp->hasValidSimper()) {
|
||||
$verifiedDriver = $emp;
|
||||
}
|
||||
} elseif ($inputNik !== '') {
|
||||
$emp = Employee::where('nik', $inputNik)
|
||||
->orWhereRaw('LOWER(nik) = ?', [strtolower($inputNik)])
|
||||
->first();
|
||||
|
||||
if (!$emp) {
|
||||
$nikErrorTitle = 'Verifikasi Gagal';
|
||||
$nikError = "NIK '{$inputNik}' tidak terdaftar dalam database SIMPER PT KMH. Silakan periksa kembali atau hubungi Divisi HSE.";
|
||||
} elseif (!$emp->is_operator) {
|
||||
$nikErrorTitle = 'Bukan Driver Terdaftar';
|
||||
$nikError = "Karyawan atas nama {$emp->name} (NIK: {$emp->nik} - {$emp->division}) terdaftar sebagai BUKAN DRIVER dan tidak memiliki izin mengemudi (SIMPER). Anda tidak diizinkan mengoperasikan kendaraan unit. Silakan hubungi Divisi HSE.";
|
||||
} elseif (!$emp->hasValidSimper()) {
|
||||
if ($emp->simper_expired_at) {
|
||||
$expiredDate = $emp->simper_expired_at->format('d/m/Y');
|
||||
$nikErrorTitle = 'Peringatan: SIMPER Kedaluwarsa';
|
||||
$nikError = "SIMPER atas nama {$emp->name} (NIK: {$emp->nik} - {$emp->division}) telah KEDALUWARSA pada {$expiredDate}. Anda tidak diizinkan mengoperasikan kendaraan. Silakan hubungi Divisi HSE untuk perpanjangan masa berlaku SIMPER.";
|
||||
} else {
|
||||
$nikErrorTitle = 'SIMPER Belum Terdaftar';
|
||||
$nikError = "Karyawan atas nama {$emp->name} (NIK: {$emp->nik} - {$emp->division}) belum memiliki tanggal masa berlaku SIMPER aktif. Anda tidak diizinkan mengoperasikan kendaraan. Silakan hubungi Divisi HSE.";
|
||||
}
|
||||
} else {
|
||||
$verifiedDriver = $emp;
|
||||
}
|
||||
}
|
||||
|
||||
return view('public.vehicle_activity_form', compact(
|
||||
'vehicle',
|
||||
'gates',
|
||||
'allowedDirection',
|
||||
'verifiedDriver',
|
||||
'nikError',
|
||||
'nikErrorTitle',
|
||||
'inputNik'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Cek validitas NIK dan status SIMPER pengemudi via AJAX / real-time request.
|
||||
*/
|
||||
public function checkNik(Request $request, string $code): JsonResponse
|
||||
{
|
||||
$vehicle = Vehicle::where('code', $code)
|
||||
->where('category', 'light_vehicle')
|
||||
->firstOrFail();
|
||||
|
||||
$rawNik = trim((string) $request->input('nik', ''));
|
||||
if ($rawNik === '') {
|
||||
return response()->json([
|
||||
'status' => 'empty',
|
||||
'title' => 'Input Kosong',
|
||||
'message' => 'Silakan masukkan Nomor Induk Karyawan (NIK) Anda terlebih dahulu.',
|
||||
], 422);
|
||||
}
|
||||
|
||||
$employee = Employee::where('nik', $rawNik)
|
||||
->orWhereRaw('LOWER(nik) = ?', [strtolower($rawNik)])
|
||||
->first();
|
||||
|
||||
if (!$employee) {
|
||||
return response()->json([
|
||||
'status' => 'not_found',
|
||||
'title' => 'Verifikasi Gagal',
|
||||
'message' => "NIK '{$rawNik}' tidak terdaftar dalam database SIMPER PT KMH. Silakan periksa kembali atau hubungi Divisi HSE.",
|
||||
], 404);
|
||||
}
|
||||
|
||||
// Pengecekan 1: Karyawan terdaftar tapi BUKAN DRIVER
|
||||
if (!$employee->is_operator) {
|
||||
return response()->json([
|
||||
'status' => 'not_driver',
|
||||
'title' => 'Bukan Driver Terdaftar',
|
||||
'message' => "Karyawan atas nama {$employee->name} (NIK: {$employee->nik} - {$employee->division}) terdaftar sebagai BUKAN DRIVER dan tidak memiliki izin mengemudi (SIMPER). Anda tidak diizinkan mengoperasikan kendaraan unit. Silakan hubungi Divisi HSE.",
|
||||
'employee' => [
|
||||
'id' => $employee->id,
|
||||
'name' => $employee->name,
|
||||
'nik' => $employee->nik,
|
||||
'division' => $employee->division ?? 'Umum',
|
||||
'is_operator' => false,
|
||||
],
|
||||
], 422);
|
||||
}
|
||||
|
||||
// Pengecekan 2: Karyawan adalah Driver, tapi masa berlaku SIMPER kedaluwarsa
|
||||
if (!$employee->hasValidSimper()) {
|
||||
if ($employee->simper_expired_at) {
|
||||
$expiredDate = $employee->simper_expired_at->format('d/m/Y');
|
||||
$title = 'Peringatan: SIMPER Kedaluwarsa';
|
||||
$message = "SIMPER atas nama {$employee->name} (NIK: {$employee->nik} - {$employee->division}) telah KEDALUWARSA pada {$expiredDate}. Anda tidak diizinkan mengoperasikan kendaraan. Silakan hubungi Divisi HSE untuk perpanjangan masa berlaku SIMPER.";
|
||||
} else {
|
||||
$expiredDate = 'Belum Ada';
|
||||
$title = 'SIMPER Belum Terdaftar';
|
||||
$message = "Karyawan atas nama {$employee->name} (NIK: {$employee->nik} - {$employee->division}) belum memiliki tanggal masa berlaku SIMPER aktif. Anda tidak diizinkan mengoperasikan kendaraan. Silakan hubungi Divisi HSE.";
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'status' => 'expired',
|
||||
'title' => $title,
|
||||
'message' => $message,
|
||||
'employee' => [
|
||||
'id' => $employee->id,
|
||||
'name' => $employee->name,
|
||||
'nik' => $employee->nik,
|
||||
'division' => $employee->division ?? 'Umum',
|
||||
'simper_expired_at' => $expiredDate,
|
||||
'is_operator' => true,
|
||||
],
|
||||
], 422);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'status' => 'valid',
|
||||
'title' => 'SIMPER Valid',
|
||||
'message' => "SIMPER valid. Selamat bertugas, {$employee->name}!",
|
||||
'employee' => [
|
||||
'id' => $employee->id,
|
||||
'name' => $employee->name,
|
||||
'nik' => $employee->nik,
|
||||
'division' => $employee->division ?? 'Umum',
|
||||
'position' => $employee->position ?? 'Karyawan',
|
||||
'simper_expired_at' => $employee->simper_expired_at->format('d/m/Y'),
|
||||
'is_operator' => true,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user