feat: implement flexible hse simper types, multi-simper personil, and mobile heavy timesheet integration

This commit is contained in:
Ray1111-aa
2026-10-25 22:34:11 +07:00
parent c2116712e7
commit 9897404f61
25 changed files with 2096 additions and 70 deletions
@@ -0,0 +1,119 @@
<?php
namespace App\Console\Commands;
use App\Models\SimperType;
use App\Models\Vehicle;
use App\Services\SimpleXlsxImporter;
use Illuminate\Console\Command;
class SyncTimesheetMobileUnitsCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'units:sync-timesheet-mobile
{--file= : Path ke file Excel DATA LOKASI TERBARU RKM KMH.xlsx}
{--simper=SIMPER-DT : Kode SIMPER yang diwajibkan untuk unit ini}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Sinkronisasi 140 unit heavy equipment mobile ke timesheet mobilisasi karyawan berdasarkan file Excel data lokasi';
/**
* Execute the console command.
*/
public function handle(): int
{
$filePath = $this->option('file') ?: base_path('Berkas/DATA LOKASI TERBARU RKM KMH.xlsx');
if (!file_exists($filePath)) {
$this->error("File Excel tidak ditemukan pada path: {$filePath}");
return Command::FAILURE;
}
$this->info("Membaca data dari: {$filePath}");
$rows = SimpleXlsxImporter::parse($filePath);
if (empty($rows)) {
$this->error("Gagal membaca atau file Excel kosong.");
return Command::FAILURE;
}
$simperCode = $this->option('simper') ?: 'SIMPER-DT';
$simperType = SimperType::where('code', $simperCode)->first();
if (!$simperType) {
$this->warn("SIMPER type dengan kode '{$simperCode}' belum ada. Menggunakan SIMPER pertama atau default.");
$simperType = SimperType::first();
}
$simperTypeId = $simperType ? $simperType->id : null;
$this->info("SIMPER yang diasosiasikan: " . ($simperType ? "{$simperType->name} ({$simperType->code})" : 'None'));
$matchedCount = 0;
$unmatchedCount = 0;
$updatedList = [];
foreach ($rows as $index => $row) {
if ($index === 0) {
continue; // Skip header
}
$jenis = isset($row[7]) ? trim((string) $row[7]) : '';
if (strtoupper($jenis) !== 'TIMESHEET MOBILE') {
continue;
}
$code1 = isset($row[4]) ? trim((string) $row[4]) : '';
$code2 = isset($row[5]) ? trim((string) $row[5]) : '';
$desc = isset($row[6]) ? trim((string) $row[6]) : '';
$lokasi = isset($row[8]) ? trim((string) $row[8]) : '';
$vehicle = Vehicle::where('code', $code1)
->orWhere('code', $code2)
->orWhere('license_plate', $code1)
->orWhere('license_plate', $code2)
->first();
if ($vehicle) {
$vehicle->is_timesheet_mobile = true;
if ($simperTypeId) {
$vehicle->required_simper_type_id = $simperTypeId;
}
if ($lokasi && empty($vehicle->location)) {
$vehicle->location = $lokasi;
}
$vehicle->save();
$matchedCount++;
if (count($updatedList) < 15) {
$updatedList[] = [
'code' => $vehicle->code,
'category' => $vehicle->category,
'unit_type' => $vehicle->unit_type ?: $desc,
'required_simper' => $simperType ? $simperType->code : '-',
];
}
} else {
$unmatchedCount++;
$this->warn("Tidak ditemukan unit di database: Code1='{$code1}', Code2='{$code2}'");
}
}
$this->newLine();
$this->table(['Unit Code', 'Kategori', 'Tipe Unit', 'Wajib SIMPER'], $updatedList);
$this->info("Berhasil sinkronisasi {$matchedCount} unit heavy equipment mobile ke Timesheet!");
if ($unmatchedCount > 0) {
$this->warn("Terdapat {$unmatchedCount} unit yang tidak cocok di database.");
}
return Command::SUCCESS;
}
}
@@ -4,6 +4,8 @@ namespace App\Http\Controllers\Hse;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Models\Employee; use App\Models\Employee;
use App\Models\EmployeeSimper;
use App\Models\SimperType;
use App\Models\User; use App\Models\User;
use App\Services\ImageCompressionService; use App\Services\ImageCompressionService;
use App\Services\SimperPdfExporter; use App\Services\SimperPdfExporter;
@@ -73,7 +75,7 @@ class EmployeeController extends Controller
*/ */
private function getFilteredEmployees(Request $request): Builder private function getFilteredEmployees(Request $request): Builder
{ {
$query = Employee::query(); $query = Employee::with(['simpers.simperType']);
// 1. Pencarian Kata Kunci (NIK, Nama, Jabatan, Unit, Divisi) // 1. Pencarian Kata Kunci (NIK, Nama, Jabatan, Unit, Divisi)
if ($request->filled('search')) { if ($request->filled('search')) {
@@ -156,7 +158,9 @@ class EmployeeController extends Controller
$employeeTypes[] = 'Sukon'; $employeeTypes[] = 'Sukon';
} }
return view('hse.employees_index', compact('employees', 'employeeTypes')); $availableSimperTypes = SimperType::active()->orderBy('name')->get();
return view('hse.employees_index', compact('employees', 'employeeTypes', 'availableSimperTypes'));
} }
/** /**
@@ -613,7 +617,7 @@ class EmployeeController extends Controller
$user->update(['photo_path' => $photoPath]); $user->update(['photo_path' => $photoPath]);
} }
Employee::create([ $employee = Employee::create([
'nik' => $validated['nik'], 'nik' => $validated['nik'],
'name' => $validated['name'], 'name' => $validated['name'],
'employee_type' => $employeeType, 'employee_type' => $employeeType,
@@ -626,6 +630,9 @@ class EmployeeController extends Controller
'user_id' => $user->id, 'user_id' => $user->id,
]); ]);
// Sinkronisasi Multi-SIMPER Personil
$this->syncEmployeeSimpers($employee, $request, $isOperator, $simperExpiredAt);
return back()->with('success', "Data karyawan {$validated['name']} berhasil ditambahkan."); return back()->with('success', "Data karyawan {$validated['name']} berhasil ditambahkan.");
} }
@@ -677,6 +684,9 @@ class EmployeeController extends Controller
'photo_path' => $photoPath, 'photo_path' => $photoPath,
]); ]);
// Sinkronisasi Multi-SIMPER Personil
$this->syncEmployeeSimpers($employee, $request, $isOperator, $simperExpiredAt);
// Sinkronkan akun login User terkait // Sinkronkan akun login User terkait
$linkedUser = $employee->user ?: User::where('username', $employee->nik)->first(); $linkedUser = $employee->user ?: User::where('username', $employee->nik)->first();
if ($linkedUser) { if ($linkedUser) {
@@ -691,4 +701,67 @@ class EmployeeController extends Controller
return back()->with('success', "Data SIMPER untuk {$employee->name} berhasil diperbarui."); return back()->with('success', "Data SIMPER untuk {$employee->name} berhasil diperbarui.");
} }
/**
* Helper sinkronisasi multi-SIMPER personil.
*/
private function syncEmployeeSimpers(Employee $employee, Request $request, bool $isOperator, ?string $fallbackDate): void
{
if (! $isOperator) {
$employee->simpers()->delete();
return;
}
$simperAssignments = $request->input('simper_assignments') ?? $request->input('simpers');
if (is_array($simperAssignments) && count($simperAssignments) > 0) {
$activeTypeIds = [];
$maxExpiredAt = null;
foreach ($simperAssignments as $typeId => $data) {
$isEnabled = ! empty($data['enabled']) || (! isset($data['enabled']) && ! empty($data['expired_at']));
if ($isEnabled && ! empty($data['expired_at'])) {
$expDate = $data['expired_at'];
$simperNum = ! empty($data['simper_number']) ? trim($data['simper_number']) : ('SMP-' . str_pad($employee->id, 4, '0', STR_PAD_LEFT));
EmployeeSimper::updateOrCreate(
['employee_id' => $employee->id, 'simper_type_id' => $typeId],
[
'simper_number' => $simperNum,
'expired_at' => $expDate,
'status' => 'active',
]
);
$activeTypeIds[] = (int) $typeId;
if (! $maxExpiredAt || $expDate > $maxExpiredAt) {
$maxExpiredAt = $expDate;
}
}
}
// Hapus jenis SIMPER yang sudah tidak dicentang
EmployeeSimper::where('employee_id', $employee->id)
->whereNotIn('simper_type_id', $activeTypeIds)
->delete();
if ($maxExpiredAt && $employee->simper_expired_at != $maxExpiredAt) {
$employee->update(['simper_expired_at' => $maxExpiredAt]);
}
} elseif ($fallbackDate) {
// Fallback untuk form sederhana / pengujian yang mengirimkan 1 tanggal simper_expired_at
$lvTypeId = SimperType::where('code', 'SIMPER-LV')->value('id');
if ($lvTypeId) {
EmployeeSimper::updateOrCreate(
['employee_id' => $employee->id, 'simper_type_id' => $lvTypeId],
[
'simper_number' => 'SMP-' . str_pad($employee->id, 4, '0', STR_PAD_LEFT),
'expired_at' => $fallbackDate,
'status' => 'active',
]
);
}
}
}
} }
@@ -0,0 +1,106 @@
<?php
namespace App\Http\Controllers\Hse;
use App\Http\Controllers\Controller;
use App\Models\SimperType;
use Carbon\Carbon;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Validation\Rule;
use Illuminate\View\View;
class SimperTypeController extends Controller
{
/**
* Tampilkan daftar master jenis SIMPER.
*/
public function index(Request $request): View
{
$today = Carbon::today()->toDateString();
$simperTypes = SimperType::withCount([
'employeeSimpers as active_holders_count' => function ($q) use ($today) {
$q->where('status', 'active')
->whereNotNull('expired_at')
->where('expired_at', '>=', $today);
},
'employeeSimpers as total_holders_count',
])
->orderBy('name')
->get();
$categoryScopes = SimperType::SCOPES;
return view('hse.simper_types_index', compact('simperTypes', 'categoryScopes'));
}
/**
* Tambah jenis SIMPER baru.
*/
public function store(Request $request): RedirectResponse
{
$validated = $request->validate([
'code' => ['required', 'string', 'max:50', 'unique:simper_types,code'],
'name' => ['required', 'string', 'max:100'],
'category_scope' => ['required', 'string', Rule::in(array_keys(SimperType::SCOPES))],
'description' => ['nullable', 'string', 'max:500'],
'is_active' => ['nullable', 'boolean'],
]);
$code = strtoupper(trim($validated['code']));
SimperType::create([
'code' => $code,
'name' => trim($validated['name']),
'category_scope' => $validated['category_scope'],
'description' => $validated['description'] ?? null,
'is_active' => $request->boolean('is_active', true),
]);
return back()->with('success', "Jenis SIMPER '{$validated['name']}' ({$code}) berhasil ditambahkan.");
}
/**
* Perbarui data jenis SIMPER.
*/
public function update(Request $request, int $id): RedirectResponse
{
$simperType = SimperType::findOrFail($id);
$validated = $request->validate([
'code' => ['required', 'string', 'max:50', Rule::unique('simper_types', 'code')->ignore($simperType->id)],
'name' => ['required', 'string', 'max:100'],
'category_scope' => ['required', 'string', Rule::in(array_keys(SimperType::SCOPES))],
'description' => ['nullable', 'string', 'max:500'],
'is_active' => ['nullable', 'boolean'],
]);
$simperType->update([
'code' => strtoupper(trim($validated['code'])),
'name' => trim($validated['name']),
'category_scope' => $validated['category_scope'],
'description' => $validated['description'] ?? null,
'is_active' => $request->boolean('is_active', true),
]);
return back()->with('success', "Jenis SIMPER '{$simperType->name}' berhasil diperbarui.");
}
/**
* Hapus jenis SIMPER.
*/
public function destroy(int $id): RedirectResponse
{
$simperType = SimperType::withCount('employeeSimpers')->findOrFail($id);
if ($simperType->employee_simpers_count > 0) {
return back()->with('error', "Jenis SIMPER '{$simperType->name}' tidak dapat dihapus karena masih digunakan oleh {$simperType->employee_simpers_count} personil. Anda dapat menonaktifkan statusnya.");
}
$name = $simperType->name;
$simperType->delete();
return back()->with('success', "Jenis SIMPER '{$name}' berhasil dihapus.");
}
}
@@ -26,7 +26,7 @@ class VerificationLogController extends Controller
// Otomatis batalkan antrean pending yang melewati batas 5 jam // Otomatis batalkan antrean pending yang melewati batas 5 jam
VehicleActivity::expireOverduePendingActivities(); VehicleActivity::expireOverduePendingActivities();
$query = VehicleActivity::with(['vehicle', 'driver', 'gate', 'securityGuard']) $query = VehicleActivity::with(['vehicle', 'driver.simpers.simperType', 'gate', 'securityGuard'])
->orderByRaw('COALESCE(validated_at, recorded_at) DESC'); ->orderByRaw('COALESCE(validated_at, recorded_at) DESC');
// Filter Rentang Tanggal (Default Hari Ini) // Filter Rentang Tanggal (Default Hari Ini)
@@ -24,7 +24,14 @@ class VehicleActivityFormController extends Controller
*/ */
public function index(Request $request): View public function index(Request $request): View
{ {
$query = Vehicle::lightVehicles(); $type = $request->input('type', 'all');
$query = Vehicle::timesheetEligible();
if ($type === 'light_vehicle') {
$query->where('category', 'light_vehicle');
} elseif ($type === 'unit_support') {
$query->where('category', 'unit_support')->where('is_timesheet_mobile', true);
}
if ($request->filled('search')) { if ($request->filled('search')) {
$search = trim($request->input('search')); $search = trim($request->input('search'));
@@ -43,7 +50,7 @@ class VehicleActivityFormController extends Controller
$employee = auth()->user()->getOrCreateEmployee(); $employee = auth()->user()->getOrCreateEmployee();
} }
return view('mobilisasi.index', compact('vehicles', 'employee')); return view('mobilisasi.index', compact('vehicles', 'employee', 'type'));
} }
/** /**
@@ -51,8 +58,8 @@ class VehicleActivityFormController extends Controller
*/ */
public function show(Request $request, string $code): View|RedirectResponse public function show(Request $request, string $code): View|RedirectResponse
{ {
$vehicle = Vehicle::where('code', $code) $vehicle = Vehicle::timesheetEligible()
->where('category', 'light_vehicle') ->where('code', $code)
->firstOrFail(); ->firstOrFail();
// Jika pengemudi scan lewat kamera luar dan belum login, arahkan ke login dengan intended URL // Jika pengemudi scan lewat kamera luar dan belum login, arahkan ke login dengan intended URL
@@ -77,11 +84,13 @@ class VehicleActivityFormController extends Controller
$nikErrorTitle = 'Verifikasi Gagal'; $nikErrorTitle = 'Verifikasi Gagal';
$inputNik = trim((string) ($request->input('nik') ?? $request->input('driver_nik') ?? '')); $inputNik = trim((string) ($request->input('nik') ?? $request->input('driver_nik') ?? ''));
$requiredSimper = $vehicle->requiredSimperType ? $vehicle->requiredSimperType->name : ($vehicle->isLightVehicle() ? 'SIMPER LV' : 'SIMPER Dump Truck / Heavy Mobile');
// Cek jika ada pengemudi yang sudah terverifikasi sebelumnya (via form error redirect atau query string NIK) // Cek jika ada pengemudi yang sudah terverifikasi sebelumnya (via form error redirect atau query string NIK)
$oldDriverId = old('driver_id'); $oldDriverId = old('driver_id');
if ($oldDriverId) { if ($oldDriverId) {
$emp = Employee::find($oldDriverId); $emp = Employee::find($oldDriverId);
if ($emp && $emp->is_operator && $emp->hasValidSimper()) { if ($emp && $emp->is_operator && $emp->hasValidSimperForVehicle($vehicle)) {
$verifiedDriver = $emp; $verifiedDriver = $emp;
} }
} elseif ($inputNik !== '') { } elseif ($inputNik !== '') {
@@ -95,14 +104,19 @@ class VehicleActivityFormController extends Controller
} elseif (!$emp->is_operator) { } elseif (!$emp->is_operator) {
$nikErrorTitle = 'Bukan Driver Terdaftar'; $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."; $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()) { } elseif (!$emp->hasValidSimperForVehicle($vehicle)) {
if ($emp->simper_expired_at) { if (!$emp->hasValidSimper()) {
$expiredDate = $emp->simper_expired_at->format('d/m/Y'); if ($emp->simper_expired_at) {
$nikErrorTitle = 'Peringatan: SIMPER Kedaluwarsa'; $expiredDate = $emp->simper_expired_at->format('d/m/Y');
$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."; $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 { } else {
$nikErrorTitle = 'SIMPER Belum Terdaftar'; $nikErrorTitle = 'Izin SIMPER Tidak Sesuai';
$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."; $nikError = "Karyawan atas nama {$emp->name} (NIK: {$emp->nik} - {$emp->division}) tidak memiliki izin SIMPER aktif yang sesuai untuk mengoperasikan unit {$vehicle->code} (Wajib: {$requiredSimper}). Silakan hubungi Divisi HSE.";
} }
} else { } else {
$verifiedDriver = $emp; $verifiedDriver = $emp;
@@ -113,9 +127,14 @@ class VehicleActivityFormController extends Controller
if (!$emp->is_operator) { if (!$emp->is_operator) {
$nikErrorTitle = 'Bukan Driver Terdaftar'; $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."; $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()) { } elseif (!$emp->hasValidSimperForVehicle($vehicle)) {
$nikErrorTitle = 'Peringatan: SIMPER Kedaluwarsa'; if (!$emp->hasValidSimper()) {
$nikError = "SIMPER atas nama {$emp->name} (NIK: {$emp->nik} - {$emp->division}) telah KEDALUWARSA. Anda tidak diizinkan mengoperasikan kendaraan. Silakan hubungi Divisi HSE untuk perpanjangan masa berlaku SIMPER."; $nikErrorTitle = 'Peringatan: SIMPER Kedaluwarsa';
$nikError = "SIMPER atas nama {$emp->name} (NIK: {$emp->nik} - {$emp->division}) telah KEDALUWARSA. Anda tidak diizinkan mengoperasikan kendaraan. Silakan hubungi Divisi HSE untuk perpanjangan masa berlaku SIMPER.";
} else {
$nikErrorTitle = 'Izin SIMPER Tidak Sesuai';
$nikError = "Karyawan atas nama {$emp->name} (NIK: {$emp->nik} - {$emp->division}) tidak memiliki izin SIMPER aktif yang sesuai untuk mengoperasikan unit {$vehicle->code} (Wajib: {$requiredSimper}). Silakan hubungi Divisi HSE.";
}
} else { } else {
$verifiedDriver = $emp; $verifiedDriver = $emp;
$inputNik = $emp->nik; $inputNik = $emp->nik;
@@ -147,8 +166,8 @@ class VehicleActivityFormController extends Controller
*/ */
public function checkNik(Request $request, string $code): JsonResponse public function checkNik(Request $request, string $code): JsonResponse
{ {
$vehicle = Vehicle::where('code', $code) $vehicle = Vehicle::timesheetEligible()
->where('category', 'light_vehicle') ->where('code', $code)
->firstOrFail(); ->firstOrFail();
$rawNik = trim((string) $request->input('nik', '')); $rawNik = trim((string) $request->input('nik', ''));
@@ -188,16 +207,24 @@ class VehicleActivityFormController extends Controller
], 422); ], 422);
} }
// Pengecekan 2: Karyawan adalah Driver, tapi masa berlaku SIMPER kedaluwarsa $requiredSimper = $vehicle->requiredSimperType ? $vehicle->requiredSimperType->name : ($vehicle->isLightVehicle() ? 'SIMPER LV' : 'SIMPER Dump Truck / Heavy Mobile');
if (!$employee->hasValidSimper()) {
if ($employee->simper_expired_at) { // Pengecekan 2: Karyawan adalah Driver, tapi masa berlaku SIMPER tidak sesuai untuk unit ini
$expiredDate = $employee->simper_expired_at->format('d/m/Y'); if (!$employee->hasValidSimperForVehicle($vehicle)) {
$title = 'Peringatan: SIMPER Kedaluwarsa'; if (!$employee->hasValidSimper()) {
$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."; 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.";
}
} else { } else {
$expiredDate = 'Belum Ada'; $expiredDate = $employee->simper_expired_at ? $employee->simper_expired_at->format('d/m/Y') : '-';
$title = 'SIMPER Belum Terdaftar'; $title = 'Izin SIMPER Tidak Sesuai';
$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."; $message = "Karyawan atas nama {$employee->name} (NIK: {$employee->nik} - {$employee->division}) tidak memiliki izin SIMPER aktif yang sesuai untuk mengoperasikan unit {$vehicle->code} (Wajib: {$requiredSimper}). Silakan hubungi Divisi HSE.";
} }
return response()->json([ return response()->json([
@@ -218,14 +245,14 @@ class VehicleActivityFormController extends Controller
return response()->json([ return response()->json([
'status' => 'valid', 'status' => 'valid',
'title' => 'SIMPER Valid', 'title' => 'SIMPER Valid',
'message' => "SIMPER valid. Selamat bertugas, {$employee->name}!", 'message' => "SIMPER valid ({$requiredSimper}). Selamat bertugas, {$employee->name}!",
'employee' => [ 'employee' => [
'id' => $employee->id, 'id' => $employee->id,
'name' => $employee->name, 'name' => $employee->name,
'nik' => $employee->nik, 'nik' => $employee->nik,
'division' => $employee->division ?? 'Umum', 'division' => $employee->division ?? 'Umum',
'position' => $employee->position ?? 'Karyawan', 'position' => $employee->position ?? 'Karyawan',
'simper_expired_at' => $employee->simper_expired_at->format('d/m/Y'), 'simper_expired_at' => $employee->simper_expired_at ? $employee->simper_expired_at->format('d/m/Y') : '-',
'is_operator' => true, 'is_operator' => true,
], ],
]); ]);
@@ -241,8 +268,8 @@ class VehicleActivityFormController extends Controller
->with('warning', 'Sesi login Anda telah berakhir. Silakan login kembali.'); ->with('warning', 'Sesi login Anda telah berakhir. Silakan login kembali.');
} }
$vehicle = Vehicle::where('code', $code) $vehicle = Vehicle::timesheetEligible()
->where('category', 'light_vehicle') ->where('code', $code)
->firstOrFail(); ->firstOrFail();
$previousKm = (float) $vehicle->current_km; $previousKm = (float) $vehicle->current_km;
@@ -26,7 +26,7 @@ class ActivityLogController extends Controller
// Otomatis update status perjalanan pending yang kedaluwarsa (> 5 jam) // Otomatis update status perjalanan pending yang kedaluwarsa (> 5 jam)
VehicleActivity::expireOverduePendingActivities(); VehicleActivity::expireOverduePendingActivities();
$query = VehicleActivity::with(['vehicle', 'driver', 'gate', 'securityGuard']) $query = VehicleActivity::with(['vehicle', 'driver.simpers.simperType', 'gate', 'securityGuard'])
->latest('recorded_at'); ->latest('recorded_at');
// Filter Rentang Tanggal (Default Hari Ini jika tidak diisi) // Filter Rentang Tanggal (Default Hari Ini jika tidak diisi)
@@ -138,7 +138,8 @@ class SupportTimesheetController extends Controller
->orderBy('code') ->orderBy('code')
->get(); ->get();
$operators = Employee::orderBy('name') $operators = Employee::with(['simpers.simperType'])
->orderBy('name')
->get(['id', 'nik', 'name', 'position', 'is_operator', 'employee_type', 'simper_expired_at']); ->get(['id', 'nik', 'name', 'position', 'is_operator', 'employee_type', 'simper_expired_at']);
$shifts = self::SHIFTS; $shifts = self::SHIFTS;
+19 -1
View File
@@ -7,6 +7,7 @@ use App\Models\Employee;
use App\Models\Gate; use App\Models\Gate;
use App\Models\P2hRecord; use App\Models\P2hRecord;
use App\Models\P2hTemplate; use App\Models\P2hTemplate;
use App\Models\SimperType;
use App\Models\Vehicle; use App\Models\Vehicle;
use App\Models\VehicleActivity; use App\Models\VehicleActivity;
use App\Services\ImageCompressionService; use App\Services\ImageCompressionService;
@@ -414,6 +415,8 @@ class VehicleController extends Controller
->values() ->values()
->all(); ->all();
$simperTypes = SimperType::active()->orderBy('name')->get();
return view('qma.vehicles_support_units', compact( return view('qma.vehicles_support_units', compact(
'category', 'category',
'units', 'units',
@@ -425,7 +428,8 @@ class VehicleController extends Controller
'nextUnitNumber', 'nextUnitNumber',
'nextUnitCode', 'nextUnitCode',
'existingCodes', 'existingCodes',
'masterLocations' 'masterLocations',
'simperTypes'
)); ));
} }
@@ -897,6 +901,8 @@ class VehicleController extends Controller
'ownership' => ['nullable', 'string', 'max:150'], 'ownership' => ['nullable', 'string', 'max:150'],
'division' => ['nullable', 'string', 'max:100'], 'division' => ['nullable', 'string', 'max:100'],
'photo' => ['nullable', 'image', 'mimes:jpeg,png,jpg,webp', 'max:10240'], 'photo' => ['nullable', 'image', 'mimes:jpeg,png,jpg,webp', 'max:10240'],
'is_timesheet_mobile' => ['nullable', 'boolean'],
'required_simper_type_id' => ['nullable', 'exists:simper_types,id'],
]); ]);
return DB::transaction(function () use ($request, $category) { return DB::transaction(function () use ($request, $category) {
@@ -947,6 +953,8 @@ class VehicleController extends Controller
'silo_document' => $request->input('silo_document'), 'silo_document' => $request->input('silo_document'),
'kir_document' => $request->input('kir_document'), 'kir_document' => $request->input('kir_document'),
'photo_path' => $photoPath, 'photo_path' => $photoPath,
'is_timesheet_mobile' => $request->boolean('is_timesheet_mobile'),
'required_simper_type_id' => $request->input('required_simper_type_id') ?: null,
]); ]);
return back()->with('success', "Unit fisik [{$unit->code}] berhasil ditambahkan ke kategori {$category->unit_category}."); return back()->with('success', "Unit fisik [{$unit->code}] berhasil ditambahkan ke kategori {$category->unit_category}.");
@@ -971,6 +979,8 @@ class VehicleController extends Controller
'status' => [$category === 'unit_support' ? 'nullable' : 'required', 'string', 'in:Operation,Standby,Breakdown,Maintenance'], 'status' => [$category === 'unit_support' ? 'nullable' : 'required', 'string', 'in:Operation,Standby,Breakdown,Maintenance'],
'current_km' => [$category === 'unit_support' ? 'nullable' : 'required', 'numeric', 'min:0'], 'current_km' => [$category === 'unit_support' ? 'nullable' : 'required', 'numeric', 'min:0'],
'photo' => ['nullable', 'image', 'mimes:jpeg,png,jpg,webp', 'max:10240'], 'photo' => ['nullable', 'image', 'mimes:jpeg,png,jpg,webp', 'max:10240'],
'is_timesheet_mobile' => ['nullable', 'boolean'],
'required_simper_type_id' => ['nullable', 'exists:simper_types,id'],
]; ];
// Atribut opsional spesifik Heavy Equipment (Kendaraan Berat) // Atribut opsional spesifik Heavy Equipment (Kendaraan Berat)
@@ -1003,6 +1013,9 @@ class VehicleController extends Controller
$validated['current_km'] = $validated['current_km'] ?? 0; $validated['current_km'] = $validated['current_km'] ?? 0;
} }
$validated['is_timesheet_mobile'] = $request->boolean('is_timesheet_mobile');
$validated['required_simper_type_id'] = $request->input('required_simper_type_id') ?: null;
if ($request->hasFile('photo')) { if ($request->hasFile('photo')) {
$validated['photo_path'] = ImageCompressionService::uploadAndCompress($request->file('photo'), 'vehicles', 800, 800, 75); $validated['photo_path'] = ImageCompressionService::uploadAndCompress($request->file('photo'), 'vehicles', 800, 800, 75);
} }
@@ -1060,6 +1073,8 @@ class VehicleController extends Controller
'pajak_document' => ['nullable', 'string', 'max:150'], 'pajak_document' => ['nullable', 'string', 'max:150'],
'kir_document' => ['nullable', 'string', 'max:150'], 'kir_document' => ['nullable', 'string', 'max:150'],
'photo' => ['nullable', 'image', 'mimes:jpeg,png,jpg,webp', 'max:10240'], 'photo' => ['nullable', 'image', 'mimes:jpeg,png,jpg,webp', 'max:10240'],
'is_timesheet_mobile' => ['nullable', 'boolean'],
'required_simper_type_id' => ['nullable', 'exists:simper_types,id'],
]; ];
$validated = $request->validate($rules, [ $validated = $request->validate($rules, [
@@ -1075,6 +1090,9 @@ class VehicleController extends Controller
} }
unset($validated['photo']); unset($validated['photo']);
$validated['is_timesheet_mobile'] = $request->boolean('is_timesheet_mobile');
$validated['required_simper_type_id'] = $request->input('required_simper_type_id') ?: null;
DB::transaction(function () use ($vehicle, $validated, $oldCode, $newCode) { DB::transaction(function () use ($vehicle, $validated, $oldCode, $newCode) {
$vehicle->update($validated); $vehicle->update($validated);
@@ -55,12 +55,12 @@ class StoreVehicleActivityRequest extends FormRequest
{ {
$validator->after(function ($validator) { $validator->after(function ($validator) {
$vehicleCode = $this->route('code'); $vehicleCode = $this->route('code');
$vehicle = Vehicle::where('code', $vehicleCode) $vehicle = Vehicle::timesheetEligible()
->where('category', 'light_vehicle') ->where('code', $vehicleCode)
->first(); ->first();
if (!$vehicle) { if (!$vehicle) {
$validator->errors()->add('vehicle', 'Kendaraan ringan tidak valid atau tidak terdaftar.'); $validator->errors()->add('vehicle', 'Kendaraan tidak valid atau tidak diizinkan untuk timesheet mobilisasi.');
return; return;
} }
@@ -72,11 +72,12 @@ class StoreVehicleActivityRequest extends FormRequest
'driver_id', 'driver_id',
"Karyawan ({$driver->name}) terdaftar sebagai Bukan Driver dan tidak memiliki izin mengemudi (SIMPER)." "Karyawan ({$driver->name}) terdaftar sebagai Bukan Driver dan tidak memiliki izin mengemudi (SIMPER)."
); );
} elseif (!$driver->hasValidSimper()) { } elseif (!$driver->hasValidSimperForVehicle($vehicle)) {
$requiredSimper = $vehicle->requiredSimperType ? $vehicle->requiredSimperType->name : ($vehicle->isLightVehicle() ? 'SIMPER LV' : 'SIMPER Dump Truck / Heavy Mobile');
$expiredText = $driver->simper_expired_at ? $driver->simper_expired_at->format('d/m/Y') : 'Belum Terdaftar'; $expiredText = $driver->simper_expired_at ? $driver->simper_expired_at->format('d/m/Y') : 'Belum Terdaftar';
$validator->errors()->add( $validator->errors()->add(
'driver_id', 'driver_id',
"Masa berlaku SIMPER pengemudi ({$driver->name}) telah kedaluwarsa pada {$expiredText}. Karyawan wajib memperpanjang SIMPER ke Divisi HSE sebelum mengoperasikan kendaraan." "Pengemudi ({$driver->name}) tidak memiliki izin SIMPER aktif yang sesuai untuk mengoperasikan unit {$vehicle->code} (Wajib: {$requiredSimper}). Tanggal SIMPER terakhir: {$expiredText}. Silakan hubungi Divisi HSE."
); );
} }
} }
+97
View File
@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasMany;
class Employee extends Model class Employee extends Model
@@ -73,6 +74,102 @@ class Employee extends Model
return $this->simper_expired_at->isFuture() || $this->simper_expired_at->isToday(); return $this->simper_expired_at->isFuture() || $this->simper_expired_at->isToday();
} }
public function simpers(): HasMany
{
return $this->hasMany(EmployeeSimper::class)->with('simperType');
}
public function simperTypes(): BelongsToMany
{
return $this->belongsToMany(SimperType::class, 'employee_simpers')
->withPivot(['simper_number', 'expired_at', 'status', 'notes'])
->withTimestamps();
}
/**
* Cek apakah personil memiliki SIMPER aktif untuk kode jenis SIMPER tertentu.
*/
public function hasValidSimperForType(string $code): bool
{
$hasAnySimper = $this->relationLoaded('simpers') ? $this->simpers->isNotEmpty() : $this->simpers()->exists();
// Jika belum ada record di employee_simpers, gunakan fallback kolom simper_expired_at
if (! $hasAnySimper) {
return $this->hasValidSimper();
}
$simpers = $this->relationLoaded('simpers') ? $this->simpers : $this->simpers()->with('simperType')->get();
foreach ($simpers as $s) {
if ($s->simperType && $s->simperType->code === $code && $s->isValid()) {
return true;
}
}
return false;
}
/**
* Cek apakah personil memiliki SIMPER dengan cakupan scope tertentu.
*/
public function hasValidSimperForScope(string $scope): bool
{
$simpers = $this->relationLoaded('simpers') ? $this->simpers : $this->simpers()->with('simperType')->get();
foreach ($simpers as $s) {
if ($s->simperType && $s->simperType->category_scope === $scope && $s->isValid()) {
return true;
}
}
return false;
}
/**
* Cek apakah personil memiliki izin SIMPER yang sah untuk kendaraan tertentu.
*/
public function hasValidSimperForVehicle(Vehicle $vehicle): bool
{
if (! $this->is_operator) {
return false;
}
$hasAnySimper = $this->relationLoaded('simpers') ? $this->simpers->isNotEmpty() : $this->simpers()->exists();
// Fallback jika belum dimigrasikan ke employee_simpers
if (! $hasAnySimper) {
return $this->hasValidSimper();
}
// 1. Jika kendaraan mensyaratkan spesifik required_simper_type_id
if ($vehicle->required_simper_type_id) {
$simpers = $this->relationLoaded('simpers') ? $this->simpers : $this->simpers()->get();
foreach ($simpers as $s) {
if ($s->simper_type_id === $vehicle->required_simper_type_id && $s->isValid()) {
return true;
}
}
return false;
}
// 2. Berdasarkan kategori kendaraan
if ($vehicle->isLightVehicle()) {
return $this->hasValidSimperForType('SIMPER-LV') || $this->hasValidSimperForScope(SimperType::SCOPE_ALL);
}
if ($vehicle->isUnitSupport() && $vehicle->is_timesheet_mobile) {
return $this->hasValidSimperForType('SIMPER-DT')
|| $this->hasValidSimperForType('SIMPER-HEAVY')
|| $this->hasValidSimperForScope(SimperType::SCOPE_ALL);
}
if ($vehicle->isUnitSupport()) {
return $this->hasValidSimperForType('SIMPER-HEAVY')
|| $this->hasValidSimperForType('SIMPER-DT')
|| $this->hasValidSimperForScope(SimperType::SCOPE_ALL);
}
return $this->hasValidSimper();
}
public function getPhotoUrlAttribute(): ?string public function getPhotoUrlAttribute(): ?string
{ {
$path = $this->photo_path; $path = $this->photo_path;
+64
View File
@@ -0,0 +1,64 @@
<?php
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class EmployeeSimper extends Model
{
use HasFactory;
public const STATUS_ACTIVE = 'active';
public const STATUS_EXPIRED = 'expired';
public const STATUS_SUSPENDED = 'suspended';
protected $fillable = [
'employee_id',
'simper_type_id',
'simper_number',
'expired_at',
'status',
'notes',
];
protected $casts = [
'expired_at' => 'date',
];
public function employee(): BelongsTo
{
return $this->belongsTo(Employee::class);
}
public function simperType(): BelongsTo
{
return $this->belongsTo(SimperType::class);
}
public function isValid(): bool
{
if ($this->status !== self::STATUS_ACTIVE || ! $this->expired_at) {
return false;
}
return $this->expired_at->isFuture() || $this->expired_at->isToday();
}
public function scopeActive(Builder $query): Builder
{
return $query->where('status', self::STATUS_ACTIVE);
}
public function scopeValid(Builder $query): Builder
{
$today = Carbon::today()->toDateString();
return $query->where('status', self::STATUS_ACTIVE)
->whereNotNull('expired_at')
->where('expired_at', '>=', $today);
}
}
+55
View File
@@ -0,0 +1,55 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
class SimperType extends Model
{
use HasFactory;
public const SCOPE_LIGHT_VEHICLE = 'light_vehicle';
public const SCOPE_UNIT_SUPPORT_MOBILE = 'unit_support_mobile';
public const SCOPE_UNIT_SUPPORT_HEAVY = 'unit_support_heavy';
public const SCOPE_ALL = 'all';
public const SCOPES = [
self::SCOPE_LIGHT_VEHICLE => 'Armada Ringan (Light Vehicle)',
self::SCOPE_UNIT_SUPPORT_MOBILE => 'Armada Berat Bergerak (Heavy Mobile / Dump Truck)',
self::SCOPE_UNIT_SUPPORT_HEAVY => 'Alat Berat Operasional (Statis / Tambang)',
self::SCOPE_ALL => 'Semua Kategori Armada',
];
protected $fillable = [
'code',
'name',
'category_scope',
'description',
'is_active',
];
protected $casts = [
'is_active' => 'boolean',
];
public function employeeSimpers(): HasMany
{
return $this->hasMany(EmployeeSimper::class);
}
public function employees(): BelongsToMany
{
return $this->belongsToMany(Employee::class, 'employee_simpers')
->withPivot(['simper_number', 'expired_at', 'status', 'notes'])
->withTimestamps();
}
public function scopeActive(Builder $query): Builder
{
return $query->where('is_active', true);
}
}
+29
View File
@@ -33,6 +33,8 @@ class Vehicle extends Model
'production_year', 'production_year',
'location', 'location',
'site_status', 'site_status',
'is_timesheet_mobile',
'required_simper_type_id',
'location_updated_at', 'location_updated_at',
'location_updated_by', 'location_updated_by',
'location_note', 'location_note',
@@ -48,6 +50,7 @@ class Vehicle extends Model
'fuel_consumption' => 'decimal:2', 'fuel_consumption' => 'decimal:2',
'production_year' => 'integer', 'production_year' => 'integer',
'parent_id' => 'integer', 'parent_id' => 'integer',
'is_timesheet_mobile' => 'boolean',
'location_updated_at' => 'datetime', 'location_updated_at' => 'datetime',
]; ];
@@ -76,6 +79,32 @@ class Vehicle extends Model
return $this->category === 'light_vehicle'; return $this->category === 'light_vehicle';
} }
public function isTimesheetMobile(): bool
{
return (bool) ($this->is_timesheet_mobile ?? false);
}
public function requiredSimperType(): BelongsTo
{
return $this->belongsTo(SimperType::class, 'required_simper_type_id');
}
/**
* Scope unit yang diizinkan untuk formulir timesheet mobilisasi gerbang:
* - Seluruh Light Vehicle (LV)
* - Unit Support yang ditandai sebagai Timesheet Mobile (Dump Truck, dsb.)
*/
public function scopeTimesheetEligible(Builder $query): Builder
{
return $query->where(function (Builder $q) {
$q->where('category', 'light_vehicle')
->orWhere(function (Builder $sq) {
$sq->where('category', 'unit_support')
->where('is_timesheet_mobile', true);
});
});
}
public function getPhotoUrlAttribute(): ?string public function getPhotoUrlAttribute(): ?string
{ {
if (!$this->photo_path) { if (!$this->photo_path) {
@@ -0,0 +1,156 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
// 1. Tabel Master Jenis SIMPER
Schema::create('simper_types', function (Blueprint $table) {
$table->id();
$table->string('code', 50)->unique();
$table->string('name', 100);
$table->string('category_scope', 50)->default('all')->index();
$table->text('description')->nullable();
$table->boolean('is_active')->default(true)->index();
$table->timestamps();
});
// 2. Tabel Relasi Multi-SIMPER Personil (Karyawan & Sukon)
Schema::create('employee_simpers', function (Blueprint $table) {
$table->id();
$table->foreignId('employee_id')->constrained('employees')->cascadeOnDelete();
$table->foreignId('simper_type_id')->constrained('simper_types')->cascadeOnDelete();
$table->string('simper_number', 100)->nullable();
$table->date('expired_at')->index();
$table->string('status', 20)->default('active')->index();
$table->text('notes')->nullable();
$table->timestamps();
$table->unique(['employee_id', 'simper_type_id']);
});
// 3. Tambahkan kolom pendukung di tabel vehicles
Schema::table('vehicles', function (Blueprint $table) {
$table->boolean('is_timesheet_mobile')->default(false)->after('site_status')->index();
$table->foreignId('required_simper_type_id')->nullable()->after('is_timesheet_mobile')->constrained('simper_types')->nullOnDelete();
});
// 4. Inisialisasi Data Master Default SIMPER
$now = now();
$defaultTypes = [
[
'code' => 'SIMPER-LV',
'name' => 'SIMPER Light Vehicle (LV)',
'category_scope' => 'light_vehicle',
'description' => 'Izin mengemudi armada ringan proyek (Hilux, Triton, Avanza, dsb.)',
'is_active' => true,
'created_at' => $now,
'updated_at' => $now,
],
[
'code' => 'SIMPER-DT',
'name' => 'SIMPER Dump Truck / Heavy Mobile',
'category_scope' => 'unit_support_mobile',
'description' => 'Izin mengemudi armada berat bergerak (Dump Truck, Mixer Truck, Water Truck, Fuel Truck, Manhaul, dsb.)',
'is_active' => true,
'created_at' => $now,
'updated_at' => $now,
],
[
'code' => 'SIMPER-HEAVY',
'name' => 'SIMPER Alat Berat Operasional',
'category_scope' => 'unit_support_heavy',
'description' => 'Izin operasi alat berat konstruksi & tambang (Excavator, Dozer, Wheel Loader, Crane, Drilling Rig, dsb.)',
'is_active' => true,
'created_at' => $now,
'updated_at' => $now,
],
];
DB::table('simper_types')->insert($defaultTypes);
// Ambil ID SIMPER default
$lvTypeId = DB::table('simper_types')->where('code', 'SIMPER-LV')->value('id');
$dtTypeId = DB::table('simper_types')->where('code', 'SIMPER-DT')->value('id');
$heavyTypeId = DB::table('simper_types')->where('code', 'SIMPER-HEAVY')->value('id');
// 5. Migrasi Data SIMPER Karyawan Lama agar 100% Tidak Ada yang Terganggu
$existingEmployees = DB::table('employees')
->where('is_operator', 1)
->whereNotNull('simper_expired_at')
->get();
foreach ($existingEmployees as $emp) {
$pos = strtolower($emp->position ?? '');
$empType = $emp->employee_type ?? 'Karyawan';
// Karyawan LV selalu dapat SIMPER-LV
if ($lvTypeId) {
DB::table('employee_simpers')->insertOrIgnore([
'employee_id' => $emp->id,
'simper_type_id' => $lvTypeId,
'simper_number' => 'SMP-' . str_pad($emp->id, 4, '0', STR_PAD_LEFT),
'expired_at' => $emp->simper_expired_at,
'status' => 'active',
'created_at' => $now,
'updated_at' => $now,
]);
}
// Jika posisi terkait alat berat/truk/sukon, berikan juga SIMPER-DT & SIMPER-HEAVY
if (
$empType === 'Sukon' ||
str_contains($pos, 'operator') ||
str_contains($pos, 'driver') ||
str_contains($pos, 'dump') ||
str_contains($pos, 'truck') ||
str_contains($pos, 'heavy')
) {
if ($dtTypeId) {
DB::table('employee_simpers')->insertOrIgnore([
'employee_id' => $emp->id,
'simper_type_id' => $dtTypeId,
'simper_number' => 'SMP-DT-' . str_pad($emp->id, 4, '0', STR_PAD_LEFT),
'expired_at' => $emp->simper_expired_at,
'status' => 'active',
'created_at' => $now,
'updated_at' => $now,
]);
}
if ($heavyTypeId) {
DB::table('employee_simpers')->insertOrIgnore([
'employee_id' => $emp->id,
'simper_type_id' => $heavyTypeId,
'simper_number' => 'SMP-HV-' . str_pad($emp->id, 4, '0', STR_PAD_LEFT),
'expired_at' => $emp->simper_expired_at,
'status' => 'active',
'created_at' => $now,
'updated_at' => $now,
]);
}
}
}
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('vehicles', function (Blueprint $table) {
$table->dropForeign(['required_simper_type_id']);
$table->dropColumn(['is_timesheet_mobile', 'required_simper_type_id']);
});
Schema::dropIfExists('employee_simpers');
Schema::dropIfExists('simper_types');
}
};
+253 -11
View File
@@ -219,10 +219,24 @@
@endif @endif
</td> </td>
<!-- Masa Berlaku SIMPER --> <!-- Masa Berlaku SIMPER & Multi-SIMPER Badges -->
<td class="py-3.5 px-4 text-center whitespace-nowrap"> <td class="py-3.5 px-4 text-center">
@if(!$emp->is_operator) @if(!$emp->is_operator)
<span class="text-slate-400 italic text-[11px]">-</span> <span class="text-slate-400 italic text-[11px]">-</span>
@elseif($emp->simpers && $emp->simpers->isNotEmpty())
<div class="flex flex-col gap-1 items-center">
@foreach($emp->simpers as $sm)
@php
$smValid = $sm->isValid();
$smCode = $sm->simperType?->code ?: 'SIMPER';
$shortCode = str_replace('SIMPER-', '', $smCode);
@endphp
<span class="inline-flex items-center px-2 py-0.5 rounded text-[10px] font-bold font-mono {{ $smValid ? 'bg-emerald-50 text-emerald-800 border border-emerald-200' : 'bg-rose-50 text-rose-700 border border-rose-200' }}" title="{{ $sm->simperType?->name }}: s/d {{ $sm->expired_at ? $sm->expired_at->format('d/m/Y') : '-' }}">
<i class="fa-solid {{ $smValid ? 'fa-circle-check text-emerald-600' : 'fa-circle-xmark text-rose-600' }} mr-1 text-[8px]"></i>
{{ $shortCode }}: {{ $sm->expired_at ? $sm->expired_at->format('d/m/y') : '-' }}
</span>
@endforeach
</div>
@elseif($isValid) @elseif($isValid)
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-[11px] font-semibold bg-emerald-50 text-emerald-700 border border-emerald-200 font-mono"> <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-[11px] font-semibold bg-emerald-50 text-emerald-700 border border-emerald-200 font-mono">
<i class="fa-solid fa-circle-check mr-1.5 text-emerald-600 text-[10px]"></i> <i class="fa-solid fa-circle-check mr-1.5 text-emerald-600 text-[10px]"></i>
@@ -414,10 +428,61 @@
<option value="0">TIDAK (Bukan Driver)</option> <option value="0">TIDAK (Bukan Driver)</option>
</select> </select>
</div> </div>
<div id="addSimperDateWrapper"> <div id="addSimperDateWrapper" class="col-span-1 sm:col-span-2 space-y-2">
<label class="block text-xs font-bold text-slate-800 mb-1.5">Masa Berlaku SIMPER</label> <div class="flex items-center justify-between">
<input type="date" name="simper_expired_at" id="addSimperDateInput" <label class="block text-xs font-bold text-slate-800">
class="w-full text-xs px-3.5 py-2.5 rounded-xl border border-slate-200 bg-slate-50 focus:bg-white text-slate-800 focus:outline-none focus:border-[#1b5e20] transition"> Izin SIMPER yang Diberikan <span class="text-rose-500">*</span>
</label>
<span class="text-[10px] text-slate-400">Centang jenis izin & tentukan masa berlakunya</span>
</div>
<input type="hidden" name="simper_expired_at" id="addSimperDateInput">
@if(isset($availableSimperTypes) && count($availableSimperTypes) > 0)
<div class="space-y-2 max-h-48 overflow-y-auto pr-1">
@foreach($availableSimperTypes as $st)
<div class="p-2.5 rounded-xl border border-slate-200 bg-slate-50/70 hover:bg-slate-50 transition">
<div class="flex items-center justify-between">
<label class="flex items-center space-x-2 text-xs font-bold text-slate-800 cursor-pointer">
<input type="checkbox"
name="simper_assignments[{{ $st->id }}][enabled]"
value="1"
id="addSimperCheck_{{ $st->id }}"
onchange="toggleAddSimperFields({{ $st->id }})"
class="w-4 h-4 rounded text-emerald-700 border-slate-300 focus:ring-emerald-500">
<span>{{ $st->name }} ({{ $st->code }})</span>
</label>
<span class="text-[9px] font-mono px-1.5 py-0.5 rounded bg-slate-200 text-slate-700 font-bold uppercase">
{{ str_replace('_', ' ', $st->category_scope) }}
</span>
</div>
<div id="addSimperFields_{{ $st->id }}" class="hidden grid grid-cols-1 sm:grid-cols-2 gap-2 mt-2 pt-2 border-t border-slate-200/60">
<div>
<label class="block text-[10px] font-bold text-slate-500 mb-1">Nomor Registrasi SIMPER</label>
<input type="text"
name="simper_assignments[{{ $st->id }}][simper_number]"
id="addSimperNum_{{ $st->id }}"
placeholder="Contoh: SMP-LV-001"
class="w-full text-xs px-2.5 py-1.5 rounded-lg border border-slate-200 bg-white text-slate-800 font-mono">
</div>
<div>
<label class="block text-[10px] font-bold text-slate-500 mb-1">Masa Berlaku SIMPER <span class="text-rose-500">*</span></label>
<input type="date"
name="simper_assignments[{{ $st->id }}][expired_at]"
id="addSimperExp_{{ $st->id }}"
onchange="syncAddPrimarySimperDate()"
class="w-full text-xs px-2.5 py-1.5 rounded-lg border border-slate-200 bg-white text-slate-800">
</div>
</div>
</div>
@endforeach
</div>
@else
<div>
<input type="date" name="simper_expired_at" id="addSimperDateLegacy"
class="w-full text-xs px-3.5 py-2.5 rounded-xl border border-slate-200 bg-slate-50 focus:bg-white text-slate-800 focus:outline-none focus:border-[#1b5e20] transition">
</div>
@endif
</div> </div>
</div> </div>
@@ -667,11 +732,61 @@
<option value="0">TIDAK (Bukan Driver)</option> <option value="0">TIDAK (Bukan Driver)</option>
</select> </select>
</div> </div>
<div> <div id="editSimperWrapper" class="space-y-2">
<label class="block text-sm font-bold text-slate-800 mb-2">Masa Berlaku SIMPER</label> <div class="flex items-center justify-between">
<input type="date" name="simper_expired_at" id="editSimperDate" <label class="block text-sm font-bold text-slate-800">
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"> Izin SIMPER yang Dimiliki <span class="text-rose-500">*</span>
<p class="text-[11px] text-slate-400 mt-1">Kosongkan jika bukan driver atau belum memiliki SIMPER.</p> </label>
<span class="text-[11px] text-slate-400">Pilih izin & perbarui masa berlakunya</span>
</div>
<input type="hidden" name="simper_expired_at" id="editSimperDate">
@if(isset($availableSimperTypes) && count($availableSimperTypes) > 0)
<div class="space-y-2.5 max-h-56 overflow-y-auto pr-1">
@foreach($availableSimperTypes as $st)
<div class="p-3 rounded-2xl border border-slate-200 bg-slate-50/70 hover:bg-slate-50 transition">
<div class="flex items-center justify-between">
<label class="flex items-center space-x-2.5 text-xs font-bold text-slate-800 cursor-pointer">
<input type="checkbox"
name="simper_assignments[{{ $st->id }}][enabled]"
value="1"
id="editSimperCheck_{{ $st->id }}"
onchange="toggleEditSimperFields({{ $st->id }})"
class="w-4 h-4 rounded text-emerald-700 border-slate-300 focus:ring-emerald-500">
<span>{{ $st->name }} ({{ $st->code }})</span>
</label>
<span class="text-[10px] font-mono px-2 py-0.5 rounded bg-slate-200 text-slate-700 font-bold uppercase">
{{ str_replace('_', ' ', $st->category_scope) }}
</span>
</div>
<div id="editSimperFields_{{ $st->id }}" class="hidden grid grid-cols-1 sm:grid-cols-2 gap-2 mt-2 pt-2 border-t border-slate-200/60">
<div>
<label class="block text-[10px] font-bold text-slate-500 mb-1">Nomor Registrasi SIMPER</label>
<input type="text"
name="simper_assignments[{{ $st->id }}][simper_number]"
id="editSimperNum_{{ $st->id }}"
placeholder="No. SIMPER"
class="w-full text-xs px-2.5 py-1.5 rounded-xl border border-slate-200 bg-white text-slate-800 font-mono font-bold">
</div>
<div>
<label class="block text-[10px] font-bold text-slate-500 mb-1">Masa Berlaku SIMPER</label>
<input type="date"
name="simper_assignments[{{ $st->id }}][expired_at]"
id="editSimperExp_{{ $st->id }}"
onchange="syncEditPrimarySimperDate()"
class="w-full text-xs px-2.5 py-1.5 rounded-xl border border-slate-200 bg-white text-slate-800 font-semibold">
</div>
</div>
</div>
@endforeach
</div>
@else
<div>
<input type="date" name="simper_expired_at" id="editSimperDateLegacy"
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">
</div>
@endif
</div> </div>
<!-- Footer Tombol --> <!-- Footer Tombol -->
@@ -821,6 +936,10 @@
if (type === 'edit') { if (type === 'edit') {
opSelect = document.getElementById('editOperator'); opSelect = document.getElementById('editOperator');
dateInput = document.getElementById('editSimperDate'); dateInput = document.getElementById('editSimperDate');
const wrapper = document.getElementById('editSimperWrapper');
if (wrapper) {
wrapper.style.display = opSelect.value === '0' ? 'none' : 'block';
}
} else if (type === 'renew') { } else if (type === 'renew') {
opSelect = document.getElementById('renewOperator'); opSelect = document.getElementById('renewOperator');
dateInput = document.getElementById('renewDate'); dateInput = document.getElementById('renewDate');
@@ -843,6 +962,70 @@
} }
} }
// Toggle Field Multi-SIMPER Tambah
function toggleAddSimperFields(id) {
const check = document.getElementById(`addSimperCheck_${id}`);
const fields = document.getElementById(`addSimperFields_${id}`);
if (check && fields) {
if (check.checked) {
fields.classList.remove('hidden');
} else {
fields.classList.add('hidden');
const expInp = document.getElementById(`addSimperExp_${id}`);
if (expInp) expInp.value = '';
}
}
syncAddPrimarySimperDate();
}
function syncAddPrimarySimperDate() {
let maxDate = '';
const expInputs = document.querySelectorAll('[id^="addSimperExp_"]');
expInputs.forEach(inp => {
const id = inp.id.replace('addSimperExp_', '');
const check = document.getElementById(`addSimperCheck_${id}`);
if (check && check.checked && inp.value) {
if (!maxDate || inp.value > maxDate) {
maxDate = inp.value;
}
}
});
const primaryInp = document.getElementById('addSimperDateInput');
if (primaryInp) primaryInp.value = maxDate;
}
// Toggle Field Multi-SIMPER Edit
function toggleEditSimperFields(id) {
const check = document.getElementById(`editSimperCheck_${id}`);
const fields = document.getElementById(`editSimperFields_${id}`);
if (check && fields) {
if (check.checked) {
fields.classList.remove('hidden');
} else {
fields.classList.add('hidden');
const expInp = document.getElementById(`editSimperExp_${id}`);
if (expInp) expInp.value = '';
}
}
syncEditPrimarySimperDate();
}
function syncEditPrimarySimperDate() {
let maxDate = '';
const expInputs = document.querySelectorAll('[id^="editSimperExp_"]');
expInputs.forEach(inp => {
const id = inp.id.replace('editSimperExp_', '');
const check = document.getElementById(`editSimperCheck_${id}`);
if (check && check.checked && inp.value) {
if (!maxDate || inp.value > maxDate) {
maxDate = inp.value;
}
}
});
const primaryInp = document.getElementById('editSimperDate');
if (primaryInp) primaryInp.value = maxDate;
}
function previewEmployeeImage(input, imgId, placeholderId) { function previewEmployeeImage(input, imgId, placeholderId) {
if (input.files && input.files[0]) { if (input.files && input.files[0]) {
const reader = new FileReader(); const reader = new FileReader();
@@ -891,6 +1074,45 @@
expDate = emp.simper_expired_at.substring(0, 10); expDate = emp.simper_expired_at.substring(0, 10);
} }
document.getElementById('editSimperDate').value = expDate; document.getElementById('editSimperDate').value = expDate;
// Reset semua checklist SIMPER di editModal
document.querySelectorAll('[id^="editSimperCheck_"]').forEach(cb => {
cb.checked = false;
const id = cb.id.replace('editSimperCheck_', '');
const fields = document.getElementById(`editSimperFields_${id}`);
if (fields) fields.classList.add('hidden');
const num = document.getElementById(`editSimperNum_${id}`);
if (num) num.value = '';
const exp = document.getElementById(`editSimperExp_${id}`);
if (exp) exp.value = '';
});
// Isi checklist SIMPER dari data emp.simpers
if (emp.simpers && emp.simpers.length > 0) {
emp.simpers.forEach(s => {
const cb = document.getElementById(`editSimperCheck_${s.simper_type_id}`);
const fields = document.getElementById(`editSimperFields_${s.simper_type_id}`);
const num = document.getElementById(`editSimperNum_${s.simper_type_id}`);
const exp = document.getElementById(`editSimperExp_${s.simper_type_id}`);
if (cb) {
cb.checked = true;
if (fields) fields.classList.remove('hidden');
if (num) num.value = s.simper_number || '';
if (exp && s.expired_at) exp.value = s.expired_at.substring(0, 10);
}
});
} else if (emp.is_operator && expDate) {
const firstCb = document.querySelector('[id^="editSimperCheck_"]');
if (firstCb) {
firstCb.checked = true;
const id = firstCb.id.replace('editSimperCheck_', '');
const fields = document.getElementById(`editSimperFields_${id}`);
if (fields) fields.classList.remove('hidden');
const exp = document.getElementById(`editSimperExp_${id}`);
if (exp) exp.value = expDate;
}
}
syncEditPrimarySimperDate();
// Set jenis personil // Set jenis personil
const editTypeSelect = document.getElementById('editEmployeeType'); const editTypeSelect = document.getElementById('editEmployeeType');
@@ -1074,6 +1296,18 @@
addTypeSelect.value = 'Karyawan'; addTypeSelect.value = 'Karyawan';
toggleCustomEmployeeType('Karyawan', 'add'); toggleCustomEmployeeType('Karyawan', 'add');
} }
document.querySelectorAll('[id^="addSimperCheck_"]').forEach(cb => {
cb.checked = false;
const id = cb.id.replace('addSimperCheck_', '');
const fields = document.getElementById(`addSimperFields_${id}`);
if (fields) fields.classList.add('hidden');
const num = document.getElementById(`addSimperNum_${id}`);
if (num) num.value = '';
const exp = document.getElementById(`addSimperExp_${id}`);
if (exp) exp.value = '';
});
const addSimperDateInp = document.getElementById('addSimperDateInput');
if (addSimperDateInp) addSimperDateInp.value = '';
if (modal) modal.classList.remove('hidden'); if (modal) modal.classList.remove('hidden');
} }
function closeAddKaryawanModal() { function closeAddKaryawanModal() {
@@ -1089,6 +1323,14 @@
} else { } else {
wrapper.style.display = 'none'; wrapper.style.display = 'none';
if (input) input.value = ''; if (input) input.value = '';
document.querySelectorAll('[id^="addSimperCheck_"]').forEach(cb => {
cb.checked = false;
const id = cb.id.replace('addSimperCheck_', '');
const fields = document.getElementById(`addSimperFields_${id}`);
if (fields) fields.classList.add('hidden');
const exp = document.getElementById(`addSimperExp_${id}`);
if (exp) exp.value = '';
});
} }
} }
} }
@@ -0,0 +1,496 @@
@extends('layouts.app')
@section('title', 'Master Jenis SIMPER - Admin HSE | PT Kerinci Merangin Hidro')
@section('content')
<div class="w-full space-y-6">
<!-- Header Judul & Tombol Aksi -->
<div class="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4">
<div>
<div class="flex items-center space-x-1.5 mb-1">
<span class="text-xs font-bold uppercase tracking-wider text-[#1b5e20]">
MANAJEMEN HSE
</span>
<button type="button"
onclick="openSimperTypeGuideModal()"
class="w-3.5 h-3.5 rounded-full bg-slate-200/90 hover:bg-slate-300 text-slate-500 hover:text-slate-800 text-[8px] inline-flex items-center justify-center font-bold transition shadow-2xs cursor-pointer focus:outline-none"
title="Panduan Jenis SIMPER">
<i class="fa-solid fa-info"></i>
</button>
</div>
<h2 class="text-3xl sm:text-4xl font-extrabold text-slate-900 tracking-tight">
Jenis SIMPER
</h2>
<p class="text-xs text-slate-500 mt-1">
Kelola kategori izin mengemudi (SIMPER) dan cakupan kendaraan yang diizinkan untuk personil.
</p>
</div>
<div class="flex items-center gap-2.5 sm:gap-3 w-full sm:w-auto">
<a href="{{ route('hse.employees.index') }}"
class="w-full sm:w-auto border border-slate-200 bg-white hover:bg-slate-50 text-slate-700 px-3.5 py-2.5 rounded-xl text-xs font-bold flex items-center justify-center space-x-2 transition shadow-xs">
<i class="fa-solid fa-arrow-left text-slate-400"></i>
<span>Kembali ke Data Personil</span>
</a>
@can('hse.employees.edit')
<button type="button"
onclick="openAddSimperTypeModal()"
class="w-full sm:w-auto bg-[#1b5e20] hover:bg-[#144919] text-white px-4 py-2.5 rounded-xl text-xs font-bold flex items-center justify-center space-x-2 transition shadow-sm cursor-pointer">
<i class="fa-solid fa-plus text-xs"></i>
<span>Tambah Jenis SIMPER</span>
</button>
@endcan
</div>
</div>
<!-- Alert Notifikasi -->
@if(session('success'))
<div class="p-3.5 rounded-2xl bg-emerald-50 border border-emerald-200 text-emerald-800 text-xs font-semibold flex items-center justify-between shadow-2xs">
<div class="flex items-center space-x-2.5">
<i class="fa-solid fa-circle-check text-emerald-600 text-base"></i>
<span>{{ session('success') }}</span>
</div>
<button type="button" onclick="this.parentElement.remove()" class="text-emerald-500 hover:text-emerald-800 p-1">
<i class="fa-solid fa-xmark text-sm"></i>
</button>
</div>
@endif
@if(session('error'))
<div class="p-3.5 rounded-2xl bg-rose-50 border border-rose-200 text-rose-800 text-xs font-semibold flex items-center justify-between shadow-2xs">
<div class="flex items-center space-x-2.5">
<i class="fa-solid fa-triangle-exclamation text-rose-600 text-base"></i>
<span>{{ session('error') }}</span>
</div>
<button type="button" onclick="this.parentElement.remove()" class="text-rose-500 hover:text-rose-800 p-1">
<i class="fa-solid fa-xmark text-sm"></i>
</button>
</div>
@endif
@if($errors->any())
<div class="p-3.5 rounded-2xl bg-rose-50 border border-rose-200 text-rose-800 text-xs font-semibold flex items-center justify-between shadow-2xs">
<div class="flex items-center space-x-2.5">
<i class="fa-solid fa-circle-exclamation text-rose-600 text-base"></i>
<span>{{ $errors->first() }}</span>
</div>
<button type="button" onclick="this.parentElement.remove()" class="text-rose-500 hover:text-rose-800 p-1">
<i class="fa-solid fa-xmark text-sm"></i>
</button>
</div>
@endif
<!-- Kartu KPI Ringkasan -->
<div class="grid grid-cols-1 sm:grid-cols-3 gap-4">
<div class="bg-white rounded-2xl border border-slate-200 p-4 shadow-xs flex items-center space-x-3.5">
<div class="w-11 h-11 rounded-xl bg-emerald-50 text-[#1b5e20] flex items-center justify-center text-lg flex-shrink-0">
<i class="fa-solid fa-id-card"></i>
</div>
<div>
<p class="text-[11px] font-bold text-slate-400 uppercase tracking-wider">Total Kategori</p>
<p class="text-xl font-extrabold text-slate-900 mt-0.5">{{ count($simperTypes) }} Jenis</p>
</div>
</div>
<div class="bg-white rounded-2xl border border-slate-200 p-4 shadow-xs flex items-center space-x-3.5">
<div class="w-11 h-11 rounded-xl bg-blue-50 text-blue-700 flex items-center justify-center text-lg flex-shrink-0">
<i class="fa-solid fa-users-gear"></i>
</div>
<div>
<p class="text-[11px] font-bold text-slate-400 uppercase tracking-wider">Pemegang Aktif</p>
<p class="text-xl font-extrabold text-slate-900 mt-0.5">
{{ $simperTypes->sum('active_holders_count') }} Personil
</p>
</div>
</div>
<div class="bg-white rounded-2xl border border-slate-200 p-4 shadow-xs flex items-center space-x-3.5">
<div class="w-11 h-11 rounded-xl bg-amber-50 text-amber-700 flex items-center justify-center text-lg flex-shrink-0">
<i class="fa-solid fa-shield-halved"></i>
</div>
<div>
<p class="text-[11px] font-bold text-slate-400 uppercase tracking-wider">Status Fleksibilitas</p>
<p class="text-sm font-extrabold text-slate-800 mt-0.5">Siap Dikustomisasi HSE</p>
</div>
</div>
</div>
<!-- Tabel Data Master Jenis SIMPER -->
<div class="bg-white rounded-2xl border border-slate-200 shadow-sm overflow-hidden">
<div class="overflow-x-auto">
<table class="min-w-full text-xs text-left border-collapse">
<thead class="bg-[#06213f] text-white font-bold text-[11px] uppercase tracking-wider">
<tr>
<th class="py-3.5 px-4 text-center w-12">NO</th>
<th class="py-3.5 px-4 whitespace-nowrap">KODE</th>
<th class="py-3.5 px-4 whitespace-nowrap min-w-[200px]">NAMA JENIS SIMPER</th>
<th class="py-3.5 px-4 whitespace-nowrap">CAKUPAN KENDARAAN</th>
<th class="py-3.5 px-4 text-center whitespace-nowrap">PEMEGANG AKTIF</th>
<th class="py-3.5 px-4 text-center whitespace-nowrap">STATUS</th>
<th class="py-3.5 px-4 whitespace-nowrap min-w-[220px]">KETERANGAN</th>
<th class="py-3.5 px-4 text-center whitespace-nowrap w-24">AKSI</th>
</tr>
</thead>
<tbody class="divide-y divide-slate-100 text-slate-700 bg-white font-medium">
@forelse($simperTypes as $idx => $st)
<tr class="hover:bg-slate-50/80 transition">
<td class="py-3 px-4 text-center text-slate-400 font-mono">{{ $idx + 1 }}</td>
<td class="py-3 px-4">
<span class="font-mono font-extrabold text-xs text-emerald-800 bg-emerald-50 px-2 py-0.5 rounded border border-emerald-200">
{{ $st->code }}
</span>
</td>
<td class="py-3 px-4">
<span class="font-bold text-slate-900 text-xs">{{ $st->name }}</span>
</td>
<td class="py-3 px-4">
@if($st->category_scope === 'light_vehicle')
<span class="inline-flex items-center px-2 py-0.5 rounded text-[10px] font-bold bg-blue-50 text-blue-700 border border-blue-200">
<i class="fa-solid fa-car-side mr-1"></i> Light Vehicle (LV)
</span>
@elseif($st->category_scope === 'unit_support_mobile')
<span class="inline-flex items-center px-2 py-0.5 rounded text-[10px] font-bold bg-amber-50 text-amber-700 border border-amber-200">
<i class="fa-solid fa-truck-moving mr-1"></i> Heavy Mobile / Dump Truck
</span>
@elseif($st->category_scope === 'unit_support_heavy')
<span class="inline-flex items-center px-2 py-0.5 rounded text-[10px] font-bold bg-emerald-50 text-emerald-700 border border-emerald-200">
<i class="fa-solid fa-trowel-bricks mr-1"></i> Alat Berat Operasional
</span>
@else
<span class="inline-flex items-center px-2 py-0.5 rounded text-[10px] font-bold bg-purple-50 text-purple-700 border border-purple-200">
<i class="fa-solid fa-shapes mr-1"></i> Semua Kategori
</span>
@endif
</td>
<td class="py-3 px-4 text-center font-bold">
<span class="font-mono text-slate-800 bg-slate-100 px-2 py-0.5 rounded">
{{ $st->active_holders_count }} Personil
</span>
</td>
<td class="py-3 px-4 text-center">
@if($st->is_active)
<span class="inline-flex items-center px-2 py-0.5 rounded-full text-[10px] font-bold bg-emerald-50 text-emerald-700 border border-emerald-200">
Aktif
</span>
@else
<span class="inline-flex items-center px-2 py-0.5 rounded-full text-[10px] font-bold bg-slate-100 text-slate-500 border border-slate-200">
Nonaktif
</span>
@endif
</td>
<td class="py-3 px-4 text-slate-500 text-[11px] line-clamp-2">
{{ $st->description ?: '-' }}
</td>
<td class="py-3 px-4 text-center whitespace-nowrap">
<div class="flex items-center justify-center space-x-1">
@can('hse.employees.edit')
<button type="button"
onclick="openEditSimperTypeModal({{ json_encode($st) }})"
class="p-1.5 rounded-lg text-amber-600 hover:text-amber-800 hover:bg-amber-50 transition cursor-pointer"
title="Edit Jenis SIMPER">
<i class="fa-regular fa-pen-to-square text-xs"></i>
</button>
@if($st->total_holders_count == 0)
<button type="button"
onclick="openDeleteSimperTypeModal({{ $st->id }}, '{{ $st->name }}')"
class="p-1.5 rounded-lg text-rose-600 hover:text-rose-800 hover:bg-rose-50 transition cursor-pointer"
title="Hapus Jenis SIMPER">
<i class="fa-regular fa-trash-can text-xs"></i>
</button>
@endif
@endcan
</div>
</td>
</tr>
@empty
<tr>
<td colspan="8" class="py-12 text-center text-slate-400">
<i class="fa-solid fa-id-card text-3xl mb-2 block text-slate-300"></i>
<p class="text-sm font-semibold text-slate-700">Belum ada data jenis SIMPER</p>
<p class="text-xs text-slate-400 mt-1">Klik tombol "+ Tambah Jenis SIMPER" untuk membuat kategori baru.</p>
</td>
</tr>
@endforelse
</tbody>
</table>
</div>
</div>
</div>
<!-- ========================================================================= -->
<!-- MODAL: TAMBAH JENIS SIMPER -->
<!-- ========================================================================= -->
<div id="addSimperTypeModal" onclick="if(event.target === this) closeAddSimperTypeModal()" class="hidden fixed inset-0 z-50 bg-slate-900/50 backdrop-blur-sm flex items-center justify-center p-4 overflow-y-auto">
<div class="bg-white rounded-3xl shadow-2xl max-w-lg w-full p-6 sm:p-7 border border-slate-100 overflow-hidden animate-scale-in">
<div class="flex items-center justify-between pb-4 border-b border-slate-100">
<div>
<h3 class="text-lg font-bold text-slate-900 tracking-tight flex items-center gap-2">
<i class="fa-solid fa-id-card text-emerald-700"></i>
<span>Tambah Jenis SIMPER</span>
</h3>
<p class="text-xs text-slate-500 mt-0.5">Definisikan kategori izin mengemudi dan cakupan unitnya.</p>
</div>
<button type="button" onclick="closeAddSimperTypeModal()" class="text-slate-400 hover:text-slate-600 transition p-1">
<i class="fa-solid fa-xmark text-lg"></i>
</button>
</div>
<form action="{{ route('hse.simper_types.store') }}" method="POST" class="mt-4 space-y-4">
@csrf
<div class="grid grid-cols-1 sm:grid-cols-2 gap-3.5">
<div>
<label class="block text-xs font-bold text-slate-800 mb-1.5">Kode SIMPER <span class="text-rose-500">*</span></label>
<input type="text" name="code" required placeholder="Contoh: SIMPER-CRANE"
class="w-full text-xs px-3.5 py-2.5 rounded-xl border border-slate-200 bg-slate-50 focus:bg-white text-slate-800 font-mono font-bold focus:outline-none focus:border-[#1b5e20] transition uppercase">
</div>
<div>
<label class="block text-xs font-bold text-slate-800 mb-1.5">Cakupan Kendaraan <span class="text-rose-500">*</span></label>
<select name="category_scope" required class="w-full text-xs px-3.5 py-2.5 rounded-xl border border-slate-200 bg-slate-50 focus:bg-white text-slate-800 font-semibold focus:outline-none focus:border-[#1b5e20] transition">
@foreach($categoryScopes as $scopeKey => $scopeLabel)
<option value="{{ $scopeKey }}">{{ $scopeLabel }}</option>
@endforeach
</select>
</div>
</div>
<div>
<label class="block text-xs font-bold text-slate-800 mb-1.5">Nama Jenis SIMPER <span class="text-rose-500">*</span></label>
<input type="text" name="name" required placeholder="Contoh: SIMPER Mobile Crane & Rigging"
class="w-full text-xs px-3.5 py-2.5 rounded-xl border border-slate-200 bg-slate-50 focus:bg-white text-slate-800 font-bold focus:outline-none focus:border-[#1b5e20] transition">
</div>
<div>
<label class="block text-xs font-bold text-slate-800 mb-1.5">Keterangan / Persyaratan K3 <span class="text-slate-400 font-normal">(Opsional)</span></label>
<textarea name="description" rows="2" placeholder="Catatan kualifikasi SIO, sertifikasi Kemnaker, atau jenis unit spesifik..."
class="w-full text-xs px-3.5 py-2.5 rounded-xl border border-slate-200 bg-slate-50 focus:bg-white text-slate-800 focus:outline-none focus:border-[#1b5e20] transition resize-none"></textarea>
</div>
<div class="flex items-center space-x-2 pt-1">
<input type="checkbox" name="is_active" id="addSimperActive" value="1" checked
class="w-4 h-4 rounded text-emerald-700 border-slate-300 focus:ring-emerald-500">
<label for="addSimperActive" class="text-xs font-bold text-slate-700 cursor-pointer">
Aktifkan jenis SIMPER ini untuk penugasan ke personil
</label>
</div>
<div class="pt-4 border-t border-slate-100 flex items-center justify-end gap-2.5">
<button type="button" onclick="closeAddSimperTypeModal()" class="px-4 py-2.5 rounded-xl border border-slate-200 bg-slate-100 hover:bg-slate-200 text-slate-600 font-bold text-xs transition">
Batal
</button>
<button type="submit" class="px-5 py-2.5 rounded-xl bg-[#1b5e20] hover:bg-[#144919] text-white font-bold text-xs transition shadow-sm">
Simpan Jenis SIMPER
</button>
</div>
</form>
</div>
</div>
<!-- ========================================================================= -->
<!-- MODAL: EDIT JENIS SIMPER -->
<!-- ========================================================================= -->
<div id="editSimperTypeModal" onclick="if(event.target === this) closeEditSimperTypeModal()" class="hidden fixed inset-0 z-50 bg-slate-900/50 backdrop-blur-sm flex items-center justify-center p-4 overflow-y-auto">
<div class="bg-white rounded-3xl shadow-2xl max-w-lg w-full p-6 sm:p-7 border border-slate-100 overflow-hidden animate-scale-in">
<div class="flex items-center justify-between pb-4 border-b border-slate-100">
<div>
<h3 class="text-lg font-bold text-slate-900 tracking-tight flex items-center gap-2">
<i class="fa-solid fa-pen-to-square text-amber-600"></i>
<span>Edit Jenis SIMPER</span>
</h3>
<p class="text-xs text-slate-500 mt-0.5">Perbarui informasi dan cakupan kendaraan izin SIMPER.</p>
</div>
<button type="button" onclick="closeEditSimperTypeModal()" class="text-slate-400 hover:text-slate-600 transition p-1">
<i class="fa-solid fa-xmark text-lg"></i>
</button>
</div>
<form id="editSimperTypeForm" action="" method="POST" class="mt-4 space-y-4">
@csrf
@method('PUT')
<div class="grid grid-cols-1 sm:grid-cols-2 gap-3.5">
<div>
<label class="block text-xs font-bold text-slate-800 mb-1.5">Kode SIMPER <span class="text-rose-500">*</span></label>
<input type="text" name="code" id="editSimperCode" required
class="w-full text-xs px-3.5 py-2.5 rounded-xl border border-slate-200 bg-slate-50 focus:bg-white text-slate-800 font-mono font-bold focus:outline-none focus:border-[#1b5e20] transition uppercase">
</div>
<div>
<label class="block text-xs font-bold text-slate-800 mb-1.5">Cakupan Kendaraan <span class="text-rose-500">*</span></label>
<select name="category_scope" id="editSimperScope" required class="w-full text-xs px-3.5 py-2.5 rounded-xl border border-slate-200 bg-slate-50 focus:bg-white text-slate-800 font-semibold focus:outline-none focus:border-[#1b5e20] transition">
@foreach($categoryScopes as $scopeKey => $scopeLabel)
<option value="{{ $scopeKey }}">{{ $scopeLabel }}</option>
@endforeach
</select>
</div>
</div>
<div>
<label class="block text-xs font-bold text-slate-800 mb-1.5">Nama Jenis SIMPER <span class="text-rose-500">*</span></label>
<input type="text" name="name" id="editSimperName" required
class="w-full text-xs px-3.5 py-2.5 rounded-xl border border-slate-200 bg-slate-50 focus:bg-white text-slate-800 font-bold focus:outline-none focus:border-[#1b5e20] transition">
</div>
<div>
<label class="block text-xs font-bold text-slate-800 mb-1.5">Keterangan / Persyaratan K3 <span class="text-slate-400 font-normal">(Opsional)</span></label>
<textarea name="description" id="editSimperDescription" rows="2"
class="w-full text-xs px-3.5 py-2.5 rounded-xl border border-slate-200 bg-slate-50 focus:bg-white text-slate-800 focus:outline-none focus:border-[#1b5e20] transition resize-none"></textarea>
</div>
<div class="flex items-center space-x-2 pt-1">
<input type="checkbox" name="is_active" id="editSimperActive" value="1"
class="w-4 h-4 rounded text-emerald-700 border-slate-300 focus:ring-emerald-500">
<label for="editSimperActive" class="text-xs font-bold text-slate-700 cursor-pointer">
Aktifkan jenis SIMPER ini
</label>
</div>
<div class="pt-4 border-t border-slate-100 flex items-center justify-end gap-2.5">
<button type="button" onclick="closeEditSimperTypeModal()" class="px-4 py-2.5 rounded-xl border border-slate-200 bg-slate-100 hover:bg-slate-200 text-slate-600 font-bold text-xs transition">
Batal
</button>
<button type="submit" class="px-5 py-2.5 rounded-xl bg-amber-600 hover:bg-amber-700 text-white font-bold text-xs transition shadow-sm">
Simpan Perubahan
</button>
</div>
</form>
</div>
</div>
<!-- ========================================================================= -->
<!-- MODAL: HAPUS JENIS SIMPER -->
<!-- ========================================================================= -->
<div id="deleteSimperTypeModal" onclick="if(event.target === this) closeDeleteSimperTypeModal()" class="hidden fixed inset-0 z-50 bg-slate-900/50 backdrop-blur-sm flex items-center justify-center p-4">
<div class="bg-white rounded-3xl shadow-2xl max-w-sm w-full p-6 border border-slate-100 text-center animate-scale-in">
<div class="w-12 h-12 rounded-full bg-rose-100 text-rose-600 flex items-center justify-center text-xl mx-auto mb-3">
<i class="fa-solid fa-triangle-exclamation"></i>
</div>
<h3 class="text-sm font-bold text-slate-900 mb-1">Hapus Jenis SIMPER?</h3>
<p class="text-xs text-slate-500 mb-4">
Apakah Anda yakin ingin menghapus jenis SIMPER <strong id="deleteSimperTypeName" class="text-slate-800"></strong>?
</p>
<form id="deleteSimperTypeForm" action="" method="POST" class="flex items-center justify-center gap-2">
@csrf
@method('DELETE')
<button type="button" onclick="closeDeleteSimperTypeModal()" class="px-4 py-2 rounded-xl text-xs font-bold text-slate-600 hover:bg-slate-100 transition">
Batal
</button>
<button type="submit" class="bg-rose-600 hover:bg-rose-700 text-white px-5 py-2 rounded-xl text-xs font-bold transition shadow-xs">
Ya, Hapus
</button>
</form>
</div>
</div>
<!-- ========================================================================= -->
<!-- MODAL: PANDUAN HALAMAN MASTER SIMPER -->
<!-- ========================================================================= -->
<div id="simperTypeGuideModal" onclick="if(event.target === this) closeSimperTypeGuideModal()" class="hidden fixed inset-0 z-50 bg-slate-900/60 backdrop-blur-sm flex items-center justify-center p-4 overflow-y-auto">
<div class="bg-white rounded-3xl shadow-2xl max-w-lg w-full p-6 sm:p-7 border border-slate-100">
<div class="flex items-center justify-between pb-4 border-b border-slate-100">
<div class="flex items-center space-x-3">
<div class="w-10 h-10 rounded-2xl bg-emerald-50 text-[#1b5e20] flex items-center justify-center text-lg shadow-2xs">
<i class="fa-solid fa-book-open"></i>
</div>
<div>
<h3 class="text-base font-extrabold text-slate-900 tracking-tight">Panduan Master SIMPER</h3>
<p class="text-xs text-slate-500 font-medium">Pengelolaan izin mengemudi & pengoperasian unit proyek</p>
</div>
</div>
<button type="button" onclick="closeSimperTypeGuideModal()" class="w-8 h-8 rounded-full bg-slate-100 hover:bg-slate-200 text-slate-400 hover:text-slate-600 flex items-center justify-center transition">
<i class="fa-solid fa-xmark text-sm"></i>
</button>
</div>
<div class="py-5 space-y-3.5 text-xs text-slate-600 leading-relaxed max-h-[60vh] overflow-y-auto pr-1">
<div class="p-3.5 rounded-2xl bg-emerald-50/60 border border-emerald-100/80">
<h4 class="font-bold text-[#1b5e20] text-xs flex items-center mb-1">
<i class="fa-solid fa-car-side mr-1.5"></i> 1. SIMPER Light Vehicle (LV)
</h4>
<p class="text-slate-600">
Diperuntukkan bagi driver armada ringan (Hilux, Triton, Avanza, dsb.) yang melintasi gerbang proyek untuk mobilisasi harian.
</p>
</div>
<div class="p-3.5 rounded-2xl bg-amber-50/60 border border-amber-100/80">
<h4 class="font-bold text-amber-800 text-xs flex items-center mb-1">
<i class="fa-solid fa-truck-moving mr-1.5"></i> 2. SIMPER Dump Truck / Heavy Mobile
</h4>
<p class="text-slate-600">
Diperuntukkan bagi operator/driver armada berat yang bergerak aktif di jalan proyek melintasi pos gerbang (Dump Truck, Mixer, Fuel Truck, Water Truck, Manhaul, dsb.).
</p>
</div>
<div class="p-3.5 rounded-2xl bg-slate-50 border border-slate-100">
<h4 class="font-bold text-slate-800 text-xs flex items-center mb-1">
<i class="fa-solid fa-trowel-bricks mr-1.5 text-emerald-700"></i> 3. SIMPER Alat Berat Operasional
</h4>
<p class="text-slate-600">
Diperuntukkan bagi operator alat berat galian, tambang, atau lifting (Excavator, Bulldozer, Wheel Loader, Crane) yang jam kerjanya dicatat terpusat di modul QMA.
</p>
</div>
</div>
<div class="pt-4 border-t border-slate-100 flex justify-end">
<button type="button" onclick="closeSimperTypeGuideModal()" class="px-5 py-2.5 rounded-xl bg-[#1b5e20] hover:bg-[#144919] text-white text-xs font-bold transition shadow-sm">
Saya Mengerti
</button>
</div>
</div>
</div>
@endsection
@section('scripts')
<script>
function openAddSimperTypeModal() {
const modal = document.getElementById('addSimperTypeModal');
if (modal) modal.classList.remove('hidden');
}
function closeAddSimperTypeModal() {
const modal = document.getElementById('addSimperTypeModal');
if (modal) modal.classList.add('hidden');
}
function openEditSimperTypeModal(st) {
document.getElementById('editSimperCode').value = st.code || '';
document.getElementById('editSimperName').value = st.name || '';
document.getElementById('editSimperScope').value = st.category_scope || 'all';
document.getElementById('editSimperDescription').value = st.description || '';
document.getElementById('editSimperActive').checked = Boolean(st.is_active);
const form = document.getElementById('editSimperTypeForm');
form.action = `/hse/simper-types/${st.id}`;
const modal = document.getElementById('editSimperTypeModal');
if (modal) modal.classList.remove('hidden');
}
function closeEditSimperTypeModal() {
const modal = document.getElementById('editSimperTypeModal');
if (modal) modal.classList.add('hidden');
}
function openDeleteSimperTypeModal(id, name) {
document.getElementById('deleteSimperTypeName').textContent = name;
const form = document.getElementById('deleteSimperTypeForm');
form.action = `/hse/simper-types/${id}`;
const modal = document.getElementById('deleteSimperTypeModal');
if (modal) modal.classList.remove('hidden');
}
function closeDeleteSimperTypeModal() {
const modal = document.getElementById('deleteSimperTypeModal');
if (modal) modal.classList.add('hidden');
}
function openSimperTypeGuideModal() {
const modal = document.getElementById('simperTypeGuideModal');
if (modal) modal.classList.remove('hidden');
}
function closeSimperTypeGuideModal() {
const modal = document.getElementById('simperTypeGuideModal');
if (modal) modal.classList.add('hidden');
}
</script>
@endsection
+11
View File
@@ -264,6 +264,11 @@
<i class="fa-solid fa-id-card text-base w-5 text-center"></i> <i class="fa-solid fa-id-card text-base w-5 text-center"></i>
<span>Data Simper</span> <span>Data Simper</span>
</a> </a>
<a href="{{ route('hse.simper_types.index') }}"
class="flex items-center space-x-3 px-3.5 py-2.5 text-sm {{ request()->routeIs('hse.simper_types.*') ? 'sidebar-item-active' : 'sidebar-item-inactive' }}">
<i class="fa-solid fa-sliders text-base w-5 text-center"></i>
<span>Jenis SIMPER</span>
</a>
</nav> </nav>
</div> </div>
@endcan @endcan
@@ -636,6 +641,10 @@
<i class="fa-solid fa-id-card w-5 text-center"></i> <i class="fa-solid fa-id-card w-5 text-center"></i>
<span>Data Simper</span> <span>Data Simper</span>
</a> </a>
<a href="{{ route('hse.simper_types.index') }}" class="flex items-center space-x-3 px-3 py-2.5 rounded-xl text-sm {{ request()->routeIs('hse.simper_types.*') ? 'sidebar-item-active' : 'sidebar-item-inactive' }}">
<i class="fa-solid fa-sliders w-5 text-center"></i>
<span>Jenis SIMPER</span>
</a>
</nav> </nav>
</div> </div>
@endcan @endcan
@@ -902,6 +911,8 @@
Dashboard Dashboard
@elseif(request()->routeIs('hse.employees.*')) @elseif(request()->routeIs('hse.employees.*'))
Data Simper Data Simper
@elseif(request()->routeIs('hse.simper_types.*'))
Jenis SIMPER
@elseif(request()->routeIs('qma.vehicles.lv')) @elseif(request()->routeIs('qma.vehicles.lv'))
Light Vehicle Light Vehicle
@elseif(request()->routeIs('qma.vehicles.support.units*')) @elseif(request()->routeIs('qma.vehicles.support.units*'))
+37 -8
View File
@@ -9,10 +9,10 @@
<div class="min-w-0"> <div class="min-w-0">
<div class="flex items-center flex-wrap gap-2.5"> <div class="flex items-center flex-wrap gap-2.5">
<h1 class="text-lg sm:text-xl font-black text-slate-900 tracking-tight"> <h1 class="text-lg sm:text-xl font-black text-slate-900 tracking-tight">
Timesheet Kendaraan Ringan Timesheet Kendaraan Ringan & Armada Mobile
</h1> </h1>
<span class="px-2.5 py-1 rounded-lg text-xs font-black bg-emerald-50 text-emerald-800 border border-emerald-200"> <span class="px-2.5 py-1 rounded-lg text-xs font-black bg-emerald-50 text-emerald-800 border border-emerald-200">
Kendaraan Ringan (LV) Kendaraan Ringan (LV) & Heavy Mobile
</span> </span>
</div> </div>
<div class="text-sm sm:text-base text-slate-600 font-medium truncate mt-1 flex items-center flex-wrap gap-1.5"> <div class="text-sm sm:text-base text-slate-600 font-medium truncate mt-1 flex items-center flex-wrap gap-1.5">
@@ -33,8 +33,25 @@
</div> </div>
</div> </div>
<!-- Segmented Filter Tab: Semua Armada / LV / Heavy Mobile -->
<div class="flex items-center space-x-1 sm:space-x-2 border-b border-slate-200/80 overflow-x-auto pb-px">
<a href="{{ route('mobilisasi.index', array_filter(['search' => request('search'), 'type' => 'all'])) }}"
class="px-4 py-2 text-xs font-bold rounded-t-xl transition whitespace-nowrap {{ ($type ?? 'all') === 'all' ? 'bg-[#1b5e20] text-white shadow-xs' : 'text-slate-600 hover:text-slate-900 hover:bg-slate-100' }}">
<i class="fa-solid fa-layer-group mr-1.5"></i>Semua Armada
</a>
<a href="{{ route('mobilisasi.index', array_filter(['search' => request('search'), 'type' => 'light_vehicle'])) }}"
class="px-4 py-2 text-xs font-bold rounded-t-xl transition whitespace-nowrap {{ ($type ?? '') === 'light_vehicle' ? 'bg-[#1b5e20] text-white shadow-xs' : 'text-slate-600 hover:text-slate-900 hover:bg-slate-100' }}">
<i class="fa-solid fa-car-side mr-1.5"></i>Light Vehicle (LV)
</a>
<a href="{{ route('mobilisasi.index', array_filter(['search' => request('search'), 'type' => 'unit_support'])) }}"
class="px-4 py-2 text-xs font-bold rounded-t-xl transition whitespace-nowrap {{ ($type ?? '') === 'unit_support' ? 'bg-[#1b5e20] text-white shadow-xs' : 'text-slate-600 hover:text-slate-900 hover:bg-slate-100' }}">
<i class="fa-solid fa-truck-moving mr-1.5"></i>Heavy Equipment Mobile
</a>
</div>
<!-- Filter & Search Bar (Tanpa Card Wrapper, Format Referensi Sesuai Standar) --> <!-- Filter & Search Bar (Tanpa Card Wrapper, Format Referensi Sesuai Standar) -->
<form method="GET" action="{{ route('mobilisasi.index') }}" id="lvFilterForm" class="flex flex-col sm:flex-row items-stretch sm:items-center justify-between gap-2.5 sm:gap-3"> <form method="GET" action="{{ route('mobilisasi.index') }}" id="lvFilterForm" class="flex flex-col sm:flex-row items-stretch sm:items-center justify-between gap-2.5 sm:gap-3">
<input type="hidden" name="type" value="{{ $type ?? 'all' }}">
<!-- Pencarian Cepat di Kiri --> <!-- Pencarian Cepat di Kiri -->
<div class="relative w-full sm:max-w-md"> <div class="relative w-full sm:max-w-md">
<span class="absolute inset-y-0 left-0 pl-3.5 flex items-center pointer-events-none text-slate-400"> <span class="absolute inset-y-0 left-0 pl-3.5 flex items-center pointer-events-none text-slate-400">
@@ -68,9 +85,15 @@
<div> <div>
<!-- Badge Kategori & Status --> <!-- Badge Kategori & Status -->
<div class="flex items-center justify-between mb-3"> <div class="flex items-center justify-between mb-3">
<span class="inline-flex items-center px-2.5 py-1 rounded-lg text-[11px] font-bold bg-emerald-50 text-emerald-800 border border-emerald-200"> @if($v->isLightVehicle())
Kendaraan Ringan (LV) <span class="inline-flex items-center px-2.5 py-1 rounded-lg text-[11px] font-bold bg-emerald-50 text-emerald-800 border border-emerald-200">
</span> <i class="fa-solid fa-car-side mr-1 text-emerald-600"></i> LV
</span>
@else
<span class="inline-flex items-center px-2.5 py-1 rounded-lg text-[11px] font-bold bg-amber-50 text-amber-800 border border-amber-200">
<i class="fa-solid fa-truck-moving mr-1 text-amber-600"></i> Heavy Mobile
</span>
@endif
@php @php
$statusBadge = match($v->status) { $statusBadge = match($v->status) {
@@ -122,9 +145,15 @@
<span>Unit Sedang Breakdown</span> <span>Unit Sedang Breakdown</span>
</div> </div>
@else @else
<a href="{{ route('vehicle.activity.form', ['code' => $v->code]) }}" class="w-full bg-[#1b5e20] hover:bg-[#144918] active:scale-[0.99] text-white font-bold py-2.5 px-4 rounded-xl shadow-sm transition text-center block text-xs"> @if($v->isLightVehicle())
Isi Form Mobilisasi LV <a href="{{ route('vehicle.activity.form', ['code' => $v->code]) }}" class="w-full bg-[#1b5e20] hover:bg-[#144918] active:scale-[0.99] text-white font-bold py-2.5 px-4 rounded-xl shadow-sm transition text-center block text-xs">
</a> Isi Form Mobilisasi LV
</a>
@else
<a href="{{ route('vehicle.activity.form', ['code' => $v->code]) }}" class="w-full bg-[#1b5e20] hover:bg-[#144918] active:scale-[0.99] text-white font-bold py-2.5 px-4 rounded-xl shadow-sm transition text-center block text-xs">
Isi Form Mobilisasi Unit
</a>
@endif
@endif @endif
</div> </div>
</div> </div>
@@ -348,8 +348,15 @@
</div> </div>
@endif @endif
<div class="min-w-0"> <div class="min-w-0">
<div class="font-bold text-slate-900 truncate"> <div class="font-bold text-slate-900 truncate flex items-center gap-1.5 flex-wrap">
{{ $item->driver->name }} <span>{{ $item->driver->name }}</span>
@if($item->driver->simpers && $item->driver->simpers->isNotEmpty())
@foreach($item->driver->simpers->take(2) as $s)
<span class="inline-flex items-center px-1.5 py-0.2 rounded text-[9px] font-mono font-bold bg-emerald-50 text-emerald-700 border border-emerald-200">
{{ $s->simperType?->code ?? 'SIMPER' }}
</span>
@endforeach
@endif
</div> </div>
<div class="text-[11px] text-slate-500 font-mono truncate"> <div class="text-[11px] text-slate-500 font-mono truncate">
{{ $item->driver->nik }} {{ $item->driver->nik }}
@@ -9,7 +9,7 @@
@if(auth()->check()) @if(auth()->check())
<a href="{{ route('mobilisasi.index') }}" class="inline-flex items-center space-x-1.5 text-xs font-bold text-slate-600 hover:text-[#1b5e20] transition bg-white px-3 py-1.5 rounded-xl border border-slate-200 shadow-sm"> <a href="{{ route('mobilisasi.index') }}" class="inline-flex items-center space-x-1.5 text-xs font-bold text-slate-600 hover:text-[#1b5e20] transition bg-white px-3 py-1.5 rounded-xl border border-slate-200 shadow-sm">
<i class="fa-solid fa-arrow-left text-[11px]"></i> <i class="fa-solid fa-arrow-left text-[11px]"></i>
<span>Kembali ke Katalog LV</span> <span>Kembali ke Katalog Armada</span>
</a> </a>
@else @else
<div></div> <div></div>
@@ -20,9 +20,15 @@
<!-- Header Info Kendaraan (Readonly Card) --> <!-- Header Info Kendaraan (Readonly Card) -->
<div class="bg-gradient-to-r from-slate-800 to-slate-900 text-white p-5 rounded-2xl shadow-sm border border-slate-700"> <div class="bg-gradient-to-r from-slate-800 to-slate-900 text-white p-5 rounded-2xl shadow-sm border border-slate-700">
<div class="flex items-center justify-between mb-3"> <div class="flex items-center justify-between mb-3">
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-semibold bg-emerald-500/20 text-emerald-300 border border-emerald-500/30"> @if($vehicle->isLightVehicle())
<i class="fa-solid fa-car mr-1.5"></i> Kendaraan Ringan (LV) <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-semibold bg-emerald-500/20 text-emerald-300 border border-emerald-500/30">
</span> <i class="fa-solid fa-car mr-1.5"></i> Kendaraan Ringan (LV)
</span>
@else
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-semibold bg-amber-500/20 text-amber-300 border border-amber-500/30">
<i class="fa-solid fa-truck-moving mr-1.5"></i> Heavy Equipment Mobile
</span>
@endif
<span class="text-xs text-slate-400 flex items-center"> <span class="text-xs text-slate-400 flex items-center">
<span class="w-1.5 h-1.5 rounded-full bg-emerald-400 animate-pulse mr-1.5"></span> <span class="w-1.5 h-1.5 rounded-full bg-emerald-400 animate-pulse mr-1.5"></span>
Scan QR Code Aktif Scan QR Code Aktif
@@ -44,7 +50,8 @@
<div><span class="text-slate-400 font-medium">Nopol:</span> <span class="font-bold text-amber-300 text-sm ml-1">{{ $vehicle->license_plate ?? '-' }}</span></div> <div><span class="text-slate-400 font-medium">Nopol:</span> <span class="font-bold text-amber-300 text-sm ml-1">{{ $vehicle->license_plate ?? '-' }}</span></div>
<div class="col-span-1 sm:col-span-2"><span class="text-slate-400 font-medium">Merk / Tipe:</span> <span class="text-white ml-1">{{ $vehicle->brand_type }}</span></div> <div class="col-span-1 sm:col-span-2"><span class="text-slate-400 font-medium">Merk / Tipe:</span> <span class="text-white ml-1">{{ $vehicle->brand_type }}</span></div>
<div><span class="text-slate-400 font-medium">Penanggung Jawab:</span> <span class="text-slate-200 ml-1">{{ $vehicle->ownership ?? '-' }}</span></div> <div><span class="text-slate-400 font-medium">Penanggung Jawab:</span> <span class="text-slate-200 ml-1">{{ $vehicle->ownership ?? '-' }}</span></div>
<div><span class="text-slate-400 font-medium">KM Sebelumnya:</span> <span class="font-bold text-emerald-400 text-sm ml-1">{{ number_format($vehicle->current_km, 0, ',', '.') }} KM</span></div> <div><span class="text-slate-400 font-medium">Odometer Sebelumnya:</span> <span class="font-bold text-emerald-400 text-sm ml-1">{{ number_format($vehicle->current_km, 0, ',', '.') }} KM</span></div>
<div class="col-span-1 sm:col-span-2"><span class="text-slate-400 font-medium">Wajib SIMPER:</span> <span class="font-bold text-amber-300 ml-1">{{ $vehicle->requiredSimperType ? $vehicle->requiredSimperType->name : ($vehicle->isLightVehicle() ? 'SIMPER LV' : 'SIMPER Dump Truck / Heavy Mobile') }}</span></div>
</div> </div>
</div> </div>
+10 -1
View File
@@ -255,7 +255,16 @@
<!-- Driver --> <!-- Driver -->
<td class="py-3.5 px-4"> <td class="py-3.5 px-4">
<div class="font-bold text-slate-900">{{ $act->driver?->name ?? '-' }}</div> <div class="font-bold text-slate-900 flex items-center gap-1.5 flex-wrap">
<span>{{ $act->driver?->name ?? '-' }}</span>
@if($act->driver && $act->driver->simpers && $act->driver->simpers->isNotEmpty())
@foreach($act->driver->simpers->take(2) as $s)
<span class="inline-flex items-center px-1.5 py-0.2 rounded text-[9px] font-mono font-bold bg-emerald-50 text-emerald-700 border border-emerald-200" title="{{ $s->simperType?->name }}">
{{ $s->simperType?->code ?? 'SIMPER' }}
</span>
@endforeach
@endif
</div>
<div class="text-[10px] text-slate-400 font-normal">{{ $act->driver?->division ?? '-' }}</div> <div class="text-[10px] text-slate-400 font-normal">{{ $act->driver?->division ?? '-' }}</div>
</td> </td>
@@ -165,6 +165,11 @@
<span class="bg-blue-50 text-blue-800 px-2.5 py-1 rounded-lg border border-blue-200 font-bold"> <span class="bg-blue-50 text-blue-800 px-2.5 py-1 rounded-lg border border-blue-200 font-bold">
{{ $u->code }} {{ $u->code }}
</span> </span>
@if($u->is_timesheet_mobile)
<span class="inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-bold bg-amber-50 text-amber-700 border border-amber-200" title="Unit ini aktif di Timesheet Mobilisasi Karyawan">
<i class="fa-solid fa-route mr-1"></i>Mobile
</span>
@endif
</div> </div>
</td> </td>
@@ -492,7 +497,30 @@
</div> </div>
</div> </div>
<!-- Tombol Aksi Batal & Simpan Unit (Sesuai Desain Mockup) --> <!-- Pengaturan Timesheet Mobilisasi & Izin SIMPER -->
<div class="p-3.5 bg-slate-50 border border-slate-200 rounded-xl space-y-3">
<div class="flex items-center space-x-2">
<input type="checkbox" name="is_timesheet_mobile" id="add_is_timesheet_mobile" value="1"
class="rounded border-slate-300 text-emerald-600 focus:ring-emerald-500 w-4 h-4 cursor-pointer"
onchange="toggleSimperReq('add')">
<label for="add_is_timesheet_mobile" class="text-xs font-bold text-slate-800 cursor-pointer">
Izinkan Unit untuk Timesheet Mobilisasi Karyawan & Gerbang Pos Satpam
</label>
</div>
<div id="add_simper_container" class="hidden">
<label class="block text-xs font-bold text-slate-700 mb-1">
Wajib Jenis SIMPER untuk Driver / Operator
</label>
<select name="required_simper_type_id" class="w-full text-xs px-3.5 py-2 rounded-xl border border-slate-200 bg-white text-slate-800 font-medium focus:outline-none focus:border-emerald-600">
<option value="">-- Standar (Sesuai Kategori / Default) --</option>
@foreach($simperTypes ?? [] as $st)
<option value="{{ $st->id }}">{{ $st->name }} ({{ $st->code }})</option>
@endforeach
</select>
<p class="text-[11px] text-slate-500 mt-1">Driver yang mobilisasi unit ini wajib memiliki izin SIMPER aktif yang sesuai.</p>
</div>
</div>
<div class="pt-4 flex items-center justify-end space-x-3"> <div class="pt-4 flex items-center justify-end space-x-3">
<button type="button" <button type="button"
onclick="closeAddUnitModal()" onclick="closeAddUnitModal()"
@@ -602,6 +630,30 @@
</div> </div>
</div> </div>
<!-- Pengaturan Timesheet Mobilisasi & Izin SIMPER -->
<div class="p-3.5 bg-slate-50 border border-slate-200 rounded-xl space-y-3">
<div class="flex items-center space-x-2">
<input type="checkbox" name="is_timesheet_mobile" id="edit_is_timesheet_mobile" value="1"
class="rounded border-slate-300 text-emerald-600 focus:ring-emerald-500 w-4 h-4 cursor-pointer"
onchange="toggleSimperReq('edit')">
<label for="edit_is_timesheet_mobile" class="text-xs font-bold text-slate-800 cursor-pointer">
Izinkan Unit untuk Timesheet Mobilisasi Karyawan & Gerbang Pos Satpam
</label>
</div>
<div id="edit_simper_container" class="hidden">
<label class="block text-xs font-bold text-slate-700 mb-1">
Wajib Jenis SIMPER untuk Driver / Operator
</label>
<select name="required_simper_type_id" id="edit_required_simper_type_id" class="w-full text-xs px-3.5 py-2 rounded-xl border border-slate-200 bg-white text-slate-800 font-medium focus:outline-none focus:border-emerald-600">
<option value="">-- Standar (Sesuai Kategori / Default) --</option>
@foreach($simperTypes ?? [] as $st)
<option value="{{ $st->id }}">{{ $st->name }} ({{ $st->code }})</option>
@endforeach
</select>
<p class="text-[11px] text-slate-500 mt-1">Driver yang mobilisasi unit ini wajib memiliki izin SIMPER aktif yang sesuai.</p>
</div>
</div>
<div class="pt-4 flex items-center justify-end space-x-3"> <div class="pt-4 flex items-center justify-end space-x-3">
<button type="button" onclick="closeEditModal()" class="px-5 py-2.5 text-xs font-bold text-slate-700 bg-white border border-slate-300 rounded-xl hover:bg-slate-50 transition cursor-pointer">Batal</button> <button type="button" onclick="closeEditModal()" class="px-5 py-2.5 text-xs font-bold text-slate-700 bg-white border border-slate-300 rounded-xl hover:bg-slate-50 transition cursor-pointer">Batal</button>
<button type="submit" class="px-5 py-2.5 text-xs font-bold text-white bg-[#1b5e20] hover:bg-[#144919] rounded-xl transition shadow-sm cursor-pointer">Simpan Perubahan</button> <button type="submit" class="px-5 py-2.5 text-xs font-bold text-white bg-[#1b5e20] hover:bg-[#144919] rounded-xl transition shadow-sm cursor-pointer">Simpan Perubahan</button>
@@ -714,6 +766,18 @@
<script> <script>
const categoryCode = "{{ $category->code }}"; const categoryCode = "{{ $category->code }}";
function toggleSimperReq(prefix) {
const chk = document.getElementById(prefix + '_is_timesheet_mobile');
const container = document.getElementById(prefix + '_simper_container');
if (chk && container) {
if (chk.checked) {
container.classList.remove('hidden');
} else {
container.classList.add('hidden');
}
}
}
function previewUnitImage(input, imgId, placeholderId) { function previewUnitImage(input, imgId, placeholderId) {
if (input.files && input.files[0]) { if (input.files && input.files[0]) {
const reader = new FileReader(); const reader = new FileReader();
@@ -747,6 +811,9 @@
if (addPhotoPlaceholder) { if (addPhotoPlaceholder) {
addPhotoPlaceholder.classList.remove('hidden'); addPhotoPlaceholder.classList.remove('hidden');
} }
const addMobileChk = document.getElementById('add_is_timesheet_mobile');
if (addMobileChk) addMobileChk.checked = false;
toggleSimperReq('add');
document.getElementById('unitNumberInput').focus(); document.getElementById('unitNumberInput').focus();
} }
@@ -812,6 +879,16 @@
if (editPhotoPlaceholder) editPhotoPlaceholder.classList.remove('hidden'); if (editPhotoPlaceholder) editPhotoPlaceholder.classList.remove('hidden');
} }
const isMobileChk = document.getElementById('edit_is_timesheet_mobile');
if (isMobileChk) {
isMobileChk.checked = !!(unit.is_timesheet_mobile == 1 || unit.is_timesheet_mobile === true);
}
const simperSelect = document.getElementById('edit_required_simper_type_id');
if (simperSelect) {
simperSelect.value = unit.required_simper_type_id || '';
}
toggleSimperReq('edit');
const modal = document.getElementById('editModal'); const modal = document.getElementById('editModal');
modal.classList.remove('hidden'); modal.classList.remove('hidden');
modal.style.display = 'block'; modal.style.display = 'block';
+7
View File
@@ -7,6 +7,7 @@ use App\Http\Controllers\Admin\UserController;
use App\Http\Controllers\Auth\LoginController; use App\Http\Controllers\Auth\LoginController;
use App\Http\Controllers\HomeController; use App\Http\Controllers\HomeController;
use App\Http\Controllers\Hse\EmployeeController; use App\Http\Controllers\Hse\EmployeeController;
use App\Http\Controllers\Hse\SimperTypeController;
use App\Http\Controllers\P2h\P2hFormController; use App\Http\Controllers\P2h\P2hFormController;
use App\Http\Controllers\Pg\DashboardController as PgDashboardController; use App\Http\Controllers\Pg\DashboardController as PgDashboardController;
use App\Http\Controllers\Pg\GateInspectionController; use App\Http\Controllers\Pg\GateInspectionController;
@@ -62,6 +63,12 @@ Route::middleware('auth')->group(function () {
Route::post('/employees/import', [EmployeeController::class, 'import'])->name('employees.import')->middleware('permission:hse.employees.create'); Route::post('/employees/import', [EmployeeController::class, 'import'])->name('employees.import')->middleware('permission:hse.employees.create');
Route::post('/employees', [EmployeeController::class, 'store'])->name('employees.store')->middleware('permission:hse.employees.create'); Route::post('/employees', [EmployeeController::class, 'store'])->name('employees.store')->middleware('permission:hse.employees.create');
Route::post('/employees/{id}', [EmployeeController::class, 'update'])->name('employees.update')->middleware('permission:hse.employees.edit'); Route::post('/employees/{id}', [EmployeeController::class, 'update'])->name('employees.update')->middleware('permission:hse.employees.edit');
// Master Jenis SIMPER (Konfigurasi Fleksibel HSE)
Route::get('/simper-types', [SimperTypeController::class, 'index'])->name('simper_types.index')->middleware('permission:hse.employees.view');
Route::post('/simper-types', [SimperTypeController::class, 'store'])->name('simper_types.store')->middleware('permission:hse.employees.create|hse.employees.edit');
Route::put('/simper-types/{id}', [SimperTypeController::class, 'update'])->name('simper_types.update')->middleware('permission:hse.employees.edit');
Route::delete('/simper-types/{id}', [SimperTypeController::class, 'destroy'])->name('simper_types.destroy')->middleware('permission:hse.employees.edit');
}); });
// 3. Modul QMA: Admin QMA - Dashboard, Data Kendaraan & Log Aktivitas // 3. Modul QMA: Admin QMA - Dashboard, Data Kendaraan & Log Aktivitas
+192
View File
@@ -0,0 +1,192 @@
<?php
namespace Tests\Feature;
use App\Models\Employee;
use App\Models\EmployeeSimper;
use App\Models\SimperType;
use App\Models\User;
use Carbon\Carbon;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Spatie\Permission\Models\Permission;
use Spatie\Permission\Models\Role;
use Tests\TestCase;
class HseSimperTypeTest extends TestCase
{
use RefreshDatabase;
protected User $adminHse;
protected User $regularUser;
protected function setUp(): void
{
parent::setUp();
// Siapkan permission & role
Permission::firstOrCreate(['name' => 'hse.employees.view', 'guard_name' => 'web']);
Permission::firstOrCreate(['name' => 'hse.employees.create', 'guard_name' => 'web']);
Permission::firstOrCreate(['name' => 'hse.employees.edit', 'guard_name' => 'web']);
$roleHse = Role::firstOrCreate(['name' => 'admin_hse', 'guard_name' => 'web']);
$roleHse->givePermissionTo(['hse.employees.view', 'hse.employees.create', 'hse.employees.edit']);
$this->adminHse = User::create([
'name' => 'Admin HSE Tester',
'username' => 'admin_hse_tester',
'email' => '[email protected]',
'role' => 'admin_hse',
'password' => bcrypt('password'),
]);
$this->adminHse->assignRole('admin_hse');
$this->regularUser = User::create([
'name' => 'Regular User',
'username' => 'regular_user',
'email' => '[email protected]',
'role' => 'employee',
'password' => bcrypt('password'),
]);
}
/**
* Tamu diarahkan ke login.
*/
public function test_guest_cannot_access_simper_types(): void
{
$response = $this->get(route('hse.simper_types.index'));
$response->assertRedirect(route('login'));
}
/**
* Admin HSE dapat melihat halaman master jenis SIMPER.
*/
public function test_admin_hse_can_view_simper_types_index(): void
{
$response = $this->actingAs($this->adminHse)->get(route('hse.simper_types.index'));
$response->assertStatus(200);
$response->assertSee('Master Jenis SIMPER');
$response->assertSee('SIMPER-LV');
$response->assertSee('SIMPER-DT');
}
/**
* Admin HSE dapat menambahkan jenis SIMPER baru.
*/
public function test_admin_hse_can_create_new_simper_type(): void
{
$data = [
'code' => 'SIMPER-FORKLIFT',
'name' => 'SIMPER Forklift & Material Handler',
'category_scope' => 'unit_support_heavy',
'description' => 'Izin mengoperasikan unit forklift di gudang.',
'is_active' => '1',
];
$response = $this->actingAs($this->adminHse)
->from(route('hse.simper_types.index'))
->post(route('hse.simper_types.store'), $data);
$response->assertRedirect(route('hse.simper_types.index'));
$response->assertSessionHas('success');
$this->assertDatabaseHas('simper_types', [
'code' => 'SIMPER-FORKLIFT',
'name' => 'SIMPER Forklift & Material Handler',
'category_scope' => 'unit_support_heavy',
]);
}
/**
* Validasi menolak kode duplikat.
*/
public function test_cannot_create_duplicate_simper_code(): void
{
$existing = SimperType::first();
$data = [
'code' => $existing->code,
'name' => 'Nama Lain',
'category_scope' => 'all',
];
$response = $this->actingAs($this->adminHse)
->from(route('hse.simper_types.index'))
->post(route('hse.simper_types.store'), $data);
$response->assertSessionHasErrors('code');
}
/**
* Admin HSE dapat mengupdate jenis SIMPER.
*/
public function test_admin_hse_can_update_simper_type(): void
{
$type = SimperType::first();
$data = [
'code' => $type->code,
'name' => 'Nama Terkoreksi',
'category_scope' => 'light_vehicle',
'description' => 'Deskripsi baru',
'is_active' => '1',
];
$response = $this->actingAs($this->adminHse)
->from(route('hse.simper_types.index'))
->put(route('hse.simper_types.update', $type->id), $data);
$response->assertRedirect(route('hse.simper_types.index'));
$response->assertSessionHas('success');
$this->assertDatabaseHas('simper_types', [
'id' => $type->id,
'name' => 'Nama Terkoreksi',
]);
}
/**
* Admin HSE dapat mendaftarkan personil (Sukon / Karyawan) dengan multi-SIMPER.
*/
public function test_admin_hse_can_assign_multi_simper_to_employee(): void
{
$typeLv = SimperType::where('code', 'SIMPER-LV')->first();
$typeDt = SimperType::where('code', 'SIMPER-DT')->first();
$data = [
'nik' => 'SKN-9901',
'name' => 'Bambang Sukon DT',
'employee_type' => 'Sukon',
'unit_kerja' => 'PT Mandiri Sukon Perkasa',
'position' => 'Driver Dump Truck',
'division' => 'Hauling Operation',
'is_operator' => '1',
'simpers' => [
$typeLv->id => [
'simper_number' => 'SMP-LV-001',
'expired_at' => Carbon::now()->addYear()->format('Y-m-d'),
],
$typeDt->id => [
'simper_number' => 'SMP-DT-001',
'expired_at' => Carbon::now()->addMonths(6)->format('Y-m-d'),
],
],
];
$response = $this->actingAs($this->adminHse)
->from(route('hse.employees.index'))
->post(route('hse.employees.store'), $data);
$response->assertRedirect(route('hse.employees.index'));
$response->assertSessionHas('success');
$emp = Employee::where('nik', 'SKN-9901')->first();
$this->assertNotNull($emp);
$this->assertTrue($emp->isSukon());
$this->assertEquals(2, $emp->simpers()->count());
$this->assertTrue($emp->hasValidSimperForType('SIMPER-LV'));
$this->assertTrue($emp->hasValidSimperForType('SIMPER-DT'));
$this->assertFalse($emp->hasValidSimperForType('SIMPER-HEAVY'));
}
}
@@ -0,0 +1,203 @@
<?php
namespace Tests\Feature;
use App\Models\Employee;
use App\Models\EmployeeSimper;
use App\Models\Gate;
use App\Models\SimperType;
use App\Models\User;
use App\Models\Vehicle;
use App\Models\VehicleActivity;
use Carbon\Carbon;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class VehicleActivitySimperValidationTest extends TestCase
{
use RefreshDatabase;
protected User $driverUser;
protected Employee $driverLvOnly;
protected Employee $driverDtOnly;
protected Vehicle $lightVehicle;
protected Vehicle $heavyMobileUnit;
protected Gate $gate;
protected SimperType $simperLv;
protected SimperType $simperDt;
protected function setUp(): void
{
parent::setUp();
$this->simperLv = SimperType::where('code', 'SIMPER-LV')->first();
$this->simperDt = SimperType::where('code', 'SIMPER-DT')->first();
$this->gate = Gate::create([
'code' => 'GATE-01',
'name' => 'Pos Gerbang Utama KMH',
'location' => 'Main Gate Site',
'is_active' => true,
]);
$this->lightVehicle = Vehicle::create([
'code' => 'LV-01',
'category' => 'light_vehicle',
'brand_type' => 'Toyota Hilux 4x4 Double Cabin',
'license_plate' => 'BH 1234 KM',
'status' => 'Operation',
'current_km' => 10000.00,
]);
$this->heavyMobileUnit = Vehicle::create([
'code' => 'DT-01',
'category' => 'unit_support',
'brand_type' => 'Hino 500 Dump Truck',
'license_plate' => 'BH 5678 DT',
'status' => 'Operation',
'current_km' => 5000.00,
'is_timesheet_mobile' => true,
'required_simper_type_id' => $this->simperDt->id,
]);
// Driver 1: Hanya punya SIMPER LV
$this->driverLvOnly = Employee::create([
'nik' => 'DRV-LV-01',
'name' => 'Andi Driver LV',
'position' => 'Driver Operasional',
'division' => 'Logistik',
'is_operator' => true,
'simper_expired_at' => Carbon::now()->addYear(),
]);
EmployeeSimper::create([
'employee_id' => $this->driverLvOnly->id,
'simper_type_id' => $this->simperLv->id,
'simper_number' => 'SMP-LV-001',
'expired_at' => Carbon::now()->addYear(),
'is_active' => true,
]);
// Driver 2: Sukon dengan SIMPER DT
$this->driverDtOnly = Employee::create([
'nik' => 'SKN-DT-01',
'name' => 'Budi Sukon DT',
'employee_type' => 'Sukon',
'position' => 'Driver Dump Truck',
'division' => 'Hauling',
'is_operator' => true,
'simper_expired_at' => Carbon::now()->addYear(),
]);
EmployeeSimper::create([
'employee_id' => $this->driverDtOnly->id,
'simper_type_id' => $this->simperDt->id,
'simper_number' => 'SMP-DT-001',
'expired_at' => Carbon::now()->addYear(),
'is_active' => true,
]);
// Akun login untuk pengujian form
$this->driverUser = User::create([
'name' => 'Andi Driver LV',
'username' => 'driver_andi',
'email' => '[email protected]',
'role' => 'employee',
'password' => bcrypt('password'),
]);
$this->driverLvOnly->update(['user_id' => $this->driverUser->id]);
}
/**
* Unit heavy mobile muncul di katalog /timesheet.
*/
public function test_timesheet_catalog_shows_both_lv_and_heavy_mobile(): void
{
$response = $this->actingAs($this->driverUser)->get(route('mobilisasi.index'));
$response->assertStatus(200);
$response->assertSee('LV-01');
$response->assertSee('DT-01');
$response->assertSee('Heavy Equipment Mobile');
}
/**
* Driver LV dapat mengakses form mobilisasi LV.
*/
public function test_driver_lv_can_access_lv_form(): void
{
$response = $this->actingAs($this->driverUser)
->get(route('vehicle.activity.form', ['code' => 'LV-01']));
$response->assertStatus(200);
$response->assertSee('LV-01');
$response->assertDontSee('Izin SIMPER Tidak Sesuai');
}
/**
* Driver yang hanya punya SIMPER LV ditolak saat mengakses unit Dump Truck (SIMPER-DT).
*/
public function test_driver_lv_only_is_rejected_on_dump_truck(): void
{
$response = $this->actingAs($this->driverUser)
->get(route('vehicle.activity.form', ['code' => 'DT-01']));
$response->assertStatus(200);
$response->assertSee('Izin SIMPER Tidak Sesuai');
$response->assertSee('SIMPER Dump Truck');
}
/**
* Cek NIK AJAX menolak Driver LV pada unit Dump Truck.
*/
public function test_ajax_check_nik_rejects_mismatched_simper(): void
{
$response = $this->actingAs($this->driverUser)
->postJson(route('vehicle.activity.check.nik', ['code' => 'DT-01']), [
'nik' => $this->driverLvOnly->nik,
]);
$response->assertStatus(422);
$response->assertJsonPath('status', 'expired');
$response->assertJsonPath('title', 'Izin SIMPER Tidak Sesuai');
}
/**
* Cek NIK AJAX menerima Driver Sukon DT pada unit Dump Truck.
*/
public function test_ajax_check_nik_accepts_valid_dt_driver(): void
{
$response = $this->actingAs($this->driverUser)
->postJson(route('vehicle.activity.check.nik', ['code' => 'DT-01']), [
'nik' => $this->driverDtOnly->nik,
]);
$response->assertStatus(200);
$response->assertJsonPath('status', 'valid');
$response->assertJsonPath('title', 'SIMPER Valid');
}
/**
* Submit timesheet mobilisasi Dump Truck berhasil bila pengemudi memiliki SIMPER DT.
*/
public function test_submit_activity_succeeds_for_authorized_dt_driver(): void
{
$postData = [
'driver_id' => $this->driverDtOnly->id,
'gate_id' => $this->gate->id,
'direction' => 'out',
'current_km' => 5050.00,
'purpose' => 'Mobilisasi angkut material agregat ke area powerhouse',
];
$response = $this->actingAs($this->driverUser)
->post(route('vehicle.activity.store', ['code' => 'DT-01']), $postData);
$response->assertRedirect(route('employee.dashboard'));
$response->assertSessionHas('success');
$this->assertDatabaseHas('vehicle_activities', [
'vehicle_id' => $this->heavyMobileUnit->id,
'driver_id' => $this->driverDtOnly->id,
'direction' => 'out',
'current_km' => 5050.00,
]);
}
}