feat: fix HSE simper 500 error, enhance PG rejection, P2H wizard, simper renewal, QMA table UI, and nginx upload timeouts

This commit is contained in:
Ray1111-aa
2026-11-01 21:26:22 +07:00
parent bc6213d864
commit b83a8fa843
12 changed files with 1020 additions and 170 deletions
+87 -10
View File
@@ -588,6 +588,10 @@ class EmployeeController extends Controller
'is_operator' => ['required', 'in:1,0'], 'is_operator' => ['required', 'in:1,0'],
'simper_expired_at' => ['nullable', 'date'], 'simper_expired_at' => ['nullable', 'date'],
'photo' => ['nullable', 'image', 'mimes:jpeg,png,jpg,webp', 'max:10240'], 'photo' => ['nullable', 'image', 'mimes:jpeg,png,jpg,webp', 'max:10240'],
'simper_assignments' => ['nullable', 'array'],
'simper_assignments.*.expired_at' => ['nullable', 'date'],
'simper_assignments.*.simper_number' => ['nullable', 'string', 'max:100'],
'renew_simper_type_id' => ['nullable', 'string'],
], [ ], [
'nik.required' => 'NIK wajib diisi.', 'nik.required' => 'NIK wajib diisi.',
'nik.unique' => 'NIK sudah terdaftar dalam sistem.', 'nik.unique' => 'NIK sudah terdaftar dalam sistem.',
@@ -696,6 +700,10 @@ class EmployeeController extends Controller
'is_operator' => ['required', 'in:1,0'], 'is_operator' => ['required', 'in:1,0'],
'simper_expired_at' => ['nullable', 'date'], 'simper_expired_at' => ['nullable', 'date'],
'photo' => ['nullable', 'image', 'mimes:jpeg,png,jpg,webp', 'max:10240'], 'photo' => ['nullable', 'image', 'mimes:jpeg,png,jpg,webp', 'max:10240'],
'simper_assignments' => ['nullable', 'array'],
'simper_assignments.*.expired_at' => ['nullable', 'date'],
'simper_assignments.*.simper_number' => ['nullable', 'string', 'max:100'],
'renew_simper_type_id' => ['nullable', 'string'],
], [ ], [
'nik.unique' => 'NIK sudah digunakan oleh karyawan lain.', 'nik.unique' => 'NIK sudah digunakan oleh karyawan lain.',
'name.required' => 'Nama lengkap wajib diisi.', 'name.required' => 'Nama lengkap wajib diisi.',
@@ -810,7 +818,8 @@ class EmployeeController extends Controller
private function syncEmployeeSimpers(Employee $employee, Request $request, bool $isOperator, ?string $fallbackDate): void private function syncEmployeeSimpers(Employee $employee, Request $request, bool $isOperator, ?string $fallbackDate): void
{ {
if (! $isOperator) { if (! $isOperator) {
$employee->simpers()->delete(); $employee->simpers()->forceDelete();
$employee->update(['simper_expired_at' => null]);
return; return;
} }
@@ -821,20 +830,30 @@ class EmployeeController extends Controller
$maxExpiredAt = null; $maxExpiredAt = null;
foreach ($simperAssignments as $typeId => $data) { foreach ($simperAssignments as $typeId => $data) {
$isEnabled = ! empty($data['enabled']) || (! isset($data['enabled']) && ! empty($data['expired_at'])); // Hanya aktif jika dicentang eksplisit, ATAU fallback jika form tidak menyertakan checkbox enabled namun memiliki tanggal
$isEnabled = ! empty($data['enabled']);
if (! $isEnabled && ! isset($data['enabled']) && ! empty($data['expired_at'])) {
$isEnabled = true;
}
if ($isEnabled && ! empty($data['expired_at'])) { if ($isEnabled && ! empty($data['expired_at'])) {
$expDate = $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)); $simperNum = ! empty($data['simper_number']) ? trim($data['simper_number']) : ('SMP-' . str_pad($employee->id, 4, '0', STR_PAD_LEFT));
EmployeeSimper::updateOrCreate( $simper = EmployeeSimper::withTrashed()->updateOrCreate(
['employee_id' => $employee->id, 'simper_type_id' => $typeId], ['employee_id' => $employee->id, 'simper_type_id' => (int) $typeId],
[ [
'simper_number' => $simperNum, 'simper_number' => $simperNum,
'expired_at' => $expDate, 'expired_at' => $expDate,
'status' => 'active', 'status' => 'active',
'deleted_at' => null,
] ]
); );
if ($simper->trashed()) {
$simper->restore();
}
$activeTypeIds[] = (int) $typeId; $activeTypeIds[] = (int) $typeId;
if (! $maxExpiredAt || $expDate > $maxExpiredAt) { if (! $maxExpiredAt || $expDate > $maxExpiredAt) {
@@ -843,26 +862,84 @@ class EmployeeController extends Controller
} }
} }
// Hapus jenis SIMPER yang sudah tidak dicentang // Hapus jenis SIMPER yang sudah tidak dicentang (Gunakan forceDelete agar tidak memicu benturan Unique Index)
EmployeeSimper::where('employee_id', $employee->id) EmployeeSimper::where('employee_id', $employee->id)
->whereNotIn('simper_type_id', $activeTypeIds) ->whereNotIn('simper_type_id', $activeTypeIds)
->delete(); ->forceDelete();
if ($maxExpiredAt && $employee->simper_expired_at != $maxExpiredAt) {
$employee->update(['simper_expired_at' => $maxExpiredAt]); $employee->update(['simper_expired_at' => $maxExpiredAt]);
} elseif ($request->filled('renew_simper_type_id')) {
// Khusus alur Perpanjang SIMPER via Modal (#renewModal)
$renewTypeId = $request->input('renew_simper_type_id');
$newExpiry = $request->input('simper_expired_at');
if ($newExpiry) {
if ($renewTypeId === 'all') {
// Perpanjang semua SIMPER yang aktif dimiliki oleh karyawan
$existingSimpers = $employee->simpers;
if ($existingSimpers->isNotEmpty()) {
foreach ($existingSimpers as $s) {
$s->update([
'expired_at' => $newExpiry,
'status' => 'active',
]);
} }
} elseif ($fallbackDate) { } else {
// Fallback untuk form sederhana / pengujian yang mengirimkan 1 tanggal simper_expired_at // Jika belum ada SIMPER sama sekali, buatkan SIMPER-LV default
$lvTypeId = SimperType::where('code', 'SIMPER-LV')->value('id'); $lvTypeId = SimperType::where('code', 'SIMPER-LV')->value('id');
if ($lvTypeId) { if ($lvTypeId) {
EmployeeSimper::updateOrCreate( $simper = EmployeeSimper::withTrashed()->updateOrCreate(
['employee_id' => $employee->id, 'simper_type_id' => $lvTypeId],
[
'simper_number' => 'SMP-' . str_pad($employee->id, 4, '0', STR_PAD_LEFT),
'expired_at' => $newExpiry,
'status' => 'active',
'deleted_at' => null,
]
);
if ($simper->trashed()) {
$simper->restore();
}
}
}
} else {
// Perpanjang jenis SIMPER spesifik yang dipilih pada dropdown
$targetTypeId = (int) $renewTypeId;
$simper = EmployeeSimper::withTrashed()->updateOrCreate(
['employee_id' => $employee->id, 'simper_type_id' => $targetTypeId],
[
'simper_number' => 'SMP-' . str_pad($employee->id, 4, '0', STR_PAD_LEFT),
'expired_at' => $newExpiry,
'status' => 'active',
'deleted_at' => null,
]
);
if ($simper->trashed()) {
$simper->restore();
}
}
// Sinkronkan simper_expired_at master karyawan dengan tanggal terlama di antara simper aktif
$latestMax = $employee->simpers()->max('expired_at');
$employee->update(['simper_expired_at' => $latestMax]);
}
} elseif ($fallbackDate) {
// Fallback untuk pengujian sederhana yang mengirimkan 1 tanggal simper_expired_at
$lvTypeId = SimperType::where('code', 'SIMPER-LV')->value('id');
if ($lvTypeId) {
$simper = EmployeeSimper::withTrashed()->updateOrCreate(
['employee_id' => $employee->id, 'simper_type_id' => $lvTypeId], ['employee_id' => $employee->id, 'simper_type_id' => $lvTypeId],
[ [
'simper_number' => 'SMP-' . str_pad($employee->id, 4, '0', STR_PAD_LEFT), 'simper_number' => 'SMP-' . str_pad($employee->id, 4, '0', STR_PAD_LEFT),
'expired_at' => $fallbackDate, 'expired_at' => $fallbackDate,
'status' => 'active', 'status' => 'active',
'deleted_at' => null,
] ]
); );
if ($simper->trashed()) {
$simper->restore();
}
$employee->update(['simper_expired_at' => $fallbackDate]);
} }
} }
} }
@@ -3,6 +3,7 @@
namespace App\Http\Controllers\Pg; namespace App\Http\Controllers\Pg;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Models\AdminActivityLog;
use App\Models\Gate; use App\Models\Gate;
use App\Models\SecurityGuard; use App\Models\SecurityGuard;
use App\Models\VehicleActivity; use App\Models\VehicleActivity;
@@ -268,6 +269,15 @@ class GateInspectionController extends Controller
'validated_at' => Carbon::now(), 'validated_at' => Carbon::now(),
]); ]);
return back()->with('success', "Aktivitas kendaraan {$activity->vehicle->code} telah ditolak."); AdminActivityLog::record(
'reject',
'pos_gerbang',
"Penolakan perlintasan gerbang untuk kendaraan {$activity->vehicle?->code} (Driver: {$activity->driver?->name}). Alasan: {$activity->rejection_note}",
'vehicle_activity',
$activity->id,
$activity->transaction_no
);
return back()->with('success', "Aktivitas perlintasan kendaraan {$activity->vehicle->code} telah ditolak.");
} }
} }
+7 -1
View File
@@ -9,6 +9,11 @@ server {
index index.php index.html; index index.php index.html;
client_max_body_size 500M; client_max_body_size 500M;
client_body_buffer_size 1M;
client_body_timeout 600s;
client_header_timeout 600s;
send_timeout 600s;
keepalive_timeout 600s;
# Security Headers # Security Headers
add_header X-Frame-Options "SAMEORIGIN" always; add_header X-Frame-Options "SAMEORIGIN" always;
@@ -56,7 +61,8 @@ server {
fastcgi_hide_header X-Powered-By; fastcgi_hide_header X-Powered-By;
fastcgi_buffers 16 16k; fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k; fastcgi_buffer_size 32k;
fastcgi_read_timeout 300; fastcgi_read_timeout 600;
fastcgi_send_timeout 600;
} }
location ~ /\.(?!well-known).* { location ~ /\.(?!well-known).* {
@@ -1012,6 +1012,7 @@
const xhr = new XMLHttpRequest(); const xhr = new XMLHttpRequest();
xhr.open('POST', form.action, true); xhr.open('POST', form.action, true);
xhr.timeout = 600000; // 10 Menit timeout untuk berkas backup besar
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
xhr.upload.onprogress = function(e) { xhr.upload.onprogress = function(e) {
@@ -1074,6 +1075,18 @@
document.getElementById('directRestoreError').classList.remove('hidden'); document.getElementById('directRestoreError').classList.remove('hidden');
}; };
xhr.ontimeout = function() {
loading.classList.add('hidden');
document.getElementById('directRestoreDropzoneContainer').classList.remove('hidden');
if (btn) {
btn.disabled = false;
btn.classList.remove('opacity-75', 'cursor-not-allowed');
}
if (text) text.textContent = 'Mulai Pemulihan Sistem';
document.getElementById('directRestoreErrorMessage').textContent = 'Waktu pengunggahan habis (Timeout 10 Menit). Silakan periksa kestabilan jaringan internet Anda.';
document.getElementById('directRestoreError').classList.remove('hidden');
};
xhr.send(formData); xhr.send(formData);
return false; return false;
} }
@@ -1239,6 +1252,7 @@
const xhr = new XMLHttpRequest(); const xhr = new XMLHttpRequest();
xhr.open('POST', `{{ route('admin.backups.converter.inspect') }}`, true); xhr.open('POST', `{{ route('admin.backups.converter.inspect') }}`, true);
xhr.timeout = 600000; // 10 Menit timeout
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
xhr.setRequestHeader('Accept', 'application/json'); xhr.setRequestHeader('Accept', 'application/json');
@@ -1314,6 +1328,12 @@
showConverterError('Koneksi terputus saat mengunggah berkas.'); showConverterError('Koneksi terputus saat mengunggah berkas.');
}; };
xhr.ontimeout = function() {
loading.classList.add('hidden');
document.getElementById('panelConverterUpload').classList.remove('hidden');
showConverterError('Waktu pengunggahan habis (Timeout 10 Menit). Silakan periksa kestabilan jaringan internet Anda.');
};
xhr.send(formData); xhr.send(formData);
} }
+15 -2
View File
@@ -242,9 +242,11 @@
</label> </label>
<input type="text" <input type="text"
name="simper_assignments[{{ $st->id }}][simper_number]" name="simper_assignments[{{ $st->id }}][simper_number]"
id="inputSimperNum_{{ $st->id }}"
value="{{ $simperNum }}" value="{{ $simperNum }}"
{{ $isChecked ? '' : 'disabled' }}
placeholder="Contoh: SMP-LV-001" placeholder="Contoh: SMP-LV-001"
class="w-full text-xs px-3 py-2 rounded-xl border border-slate-200 bg-white text-slate-800 font-mono font-bold focus:outline-none focus:border-emerald-600"> class="w-full text-xs px-3 py-2 rounded-xl border border-slate-200 bg-white text-slate-800 font-mono font-bold focus:outline-none focus:border-emerald-600 disabled:opacity-50 disabled:bg-slate-100">
</div> </div>
<div> <div>
<label class="block text-[11px] font-bold text-slate-600 mb-1"> <label class="block text-[11px] font-bold text-slate-600 mb-1">
@@ -252,8 +254,10 @@
</label> </label>
<input type="date" <input type="date"
name="simper_assignments[{{ $st->id }}][expired_at]" name="simper_assignments[{{ $st->id }}][expired_at]"
id="inputSimperExp_{{ $st->id }}"
value="{{ $simperExp }}" value="{{ $simperExp }}"
class="w-full text-xs px-3 py-2 rounded-xl border border-slate-200 bg-white text-slate-800 font-semibold focus:outline-none focus:border-emerald-600"> {{ $isChecked ? '' : 'disabled' }}
class="w-full text-xs px-3 py-2 rounded-xl border border-slate-200 bg-white text-slate-800 font-semibold focus:outline-none focus:border-emerald-600 disabled:opacity-50 disabled:bg-slate-100">
</div> </div>
</div> </div>
</div> </div>
@@ -359,11 +363,20 @@
function toggleSimperRow(id) { function toggleSimperRow(id) {
const chk = document.getElementById(`chkSimper_${id}`); const chk = document.getElementById(`chkSimper_${id}`);
const fields = document.getElementById(`fieldsSimper_${id}`); const fields = document.getElementById(`fieldsSimper_${id}`);
const numInp = document.getElementById(`inputSimperNum_${id}`);
const expInp = document.getElementById(`inputSimperExp_${id}`);
if (chk && fields) { if (chk && fields) {
if (chk.checked) { if (chk.checked) {
fields.classList.remove('hidden'); fields.classList.remove('hidden');
if (numInp) numInp.disabled = false;
if (expInp) expInp.disabled = false;
} else { } else {
fields.classList.add('hidden'); fields.classList.add('hidden');
if (numInp) numInp.disabled = true;
if (expInp) {
expInp.disabled = true;
expInp.value = '';
}
} }
} }
} }
+178 -34
View File
@@ -281,7 +281,7 @@
<i class="fa-solid fa-up-right-from-square text-[11px]"></i> <i class="fa-solid fa-up-right-from-square text-[11px]"></i>
</a> </a>
<span class="text-slate-200">|</span> <span class="text-slate-200">|</span>
<button onclick="openRenewModal({{ $emp->id }}, '{{ addslashes($emp->name) }}', '{{ $emp->simper_expired_at ? $emp->simper_expired_at->format('Y-m-d') : '' }}', {{ $emp->is_operator ? '1' : '0' }})" <button onclick='openRenewModal(@json($emp))'
class="text-emerald-700 hover:text-emerald-900 font-bold underline text-[11px] px-1 cursor-pointer" class="text-emerald-700 hover:text-emerald-900 font-bold underline text-[11px] px-1 cursor-pointer"
title="Perpanjang Masa Berlaku SIMPER"> title="Perpanjang Masa Berlaku SIMPER">
Perpanjang Perpanjang
@@ -633,43 +633,81 @@
</div> </div>
</div> </div>
<!-- Modal Dialog Perpanjang SIMPER (Clean White Card) --> <!-- Modal Dialog Perpanjang SIMPER (Clean White Card dengan Dukungan Multi-SIMPER) -->
<div id="renewModal" data-backdrop="static" class="hidden fixed inset-0 z-50 bg-slate-900/50 backdrop-blur-sm flex items-center justify-center p-4"> <div id="renewModal" data-backdrop="static" 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-md w-full p-7 border border-slate-100 overflow-hidden"> <div class="bg-white rounded-3xl shadow-2xl max-w-md 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 class="flex items-center justify-between pb-4 border-b border-slate-100">
<h3 class="text-xl font-bold text-slate-900 tracking-tight">Perpanjang SIMPER</h3> <div>
<h3 class="text-lg font-bold text-slate-900 tracking-tight flex items-center gap-2">
<i class="fa-solid fa-id-card-clip text-emerald-700"></i>
<span>Perpanjang Masa Berlaku SIMPER</span>
</h3>
<p class="text-xs text-slate-500 mt-0.5">Pilih jenis SIMPER dan tentukan tanggal perpanjangan izin operasional.</p>
</div>
<button type="button" onclick="closeRenewModal()" class="text-slate-400 hover:text-slate-600 transition p-1"> <button type="button" onclick="closeRenewModal()" class="text-slate-400 hover:text-slate-600 transition p-1">
<i class="fa-solid fa-xmark text-lg"></i> <i class="fa-solid fa-xmark text-lg"></i>
</button> </button>
</div> </div>
<form id="renewForm" method="POST" action="" class="mt-5 space-y-4"> <form id="renewForm" method="POST" action="" class="mt-4 space-y-4">
@csrf @csrf
<div class="bg-slate-50 p-3.5 rounded-2xl border border-slate-200/80"> <!-- Identitas Driver -->
<span class="text-xs text-slate-400 block font-medium">Pengemudi:</span> <div class="bg-slate-50 p-3.5 rounded-2xl border border-slate-200/80 flex items-center justify-between">
<strong id="renewName" class="block text-base text-slate-900 font-bold mt-0.5"></strong>
</div>
<div> <div>
<label class="block text-sm font-bold text-slate-800 mb-2">Status Driver</label> <span class="text-[10px] text-slate-400 block font-bold uppercase tracking-wider">Pengemudi / Operator:</span>
<select name="is_operator" id="renewOperator" onchange="toggleSimperInput('renew')" <strong id="renewName" class="block text-sm text-slate-900 font-bold mt-0.5"></strong>
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"> <span id="renewNik" class="text-[11px] font-mono text-slate-500"></span>
<option value="1">YA (Aktif Mengemudi)</option> </div>
<option value="0">TIDAK (Bukan Driver)</option> <span class="px-2.5 py-1 rounded-xl text-xs font-bold bg-emerald-100 text-[#1b5e20] border border-emerald-200/80">
Driver Aktif
</span>
</div>
<!-- Status Driver (Hidden input default 1) -->
<input type="hidden" name="is_operator" id="renewOperator" value="1">
<!-- Dropdown Pilihan Jenis SIMPER -->
<div>
<label for="renewSimperTypeSelect" class="block text-xs font-bold text-slate-800 mb-1.5 flex items-center justify-between">
<span>Jenis SIMPER yang Diperpanjang <span class="text-rose-500">*</span></span>
<span id="renewSimperBadge" class="text-[10px] font-normal text-slate-400 font-mono"></span>
</label>
<select name="renew_simper_type_id" id="renewSimperTypeSelect" onchange="onRenewSimperTypeChange(this.value)" required
class="w-full text-xs px-3.5 py-2.5 rounded-xl border border-slate-200 bg-white text-slate-800 font-semibold focus:outline-none focus:border-[#1b5e20] focus:ring-2 focus:ring-[#1b5e20]/10 transition">
<!-- Dinamis via JavaScript -->
</select> </select>
<p id="renewCurrentExpInfo" class="text-[11px] text-slate-500 mt-1.5 flex items-center gap-1 font-medium"></p>
</div> </div>
<!-- Input Tanggal Kedaluwarsa Baru -->
<div> <div>
<label class="block text-sm font-bold text-slate-800 mb-2">Masa Berlaku Baru <span class="text-rose-500">*</span></label> <label for="renewDate" class="block text-xs font-bold text-slate-800 mb-1.5">
Masa Berlaku Baru <span class="text-rose-500">*</span>
</label>
<input type="date" name="simper_expired_at" id="renewDate" required <input type="date" name="simper_expired_at" id="renewDate" required
class="w-full text-sm px-4 py-3 rounded-2xl border border-slate-200 bg-white text-slate-800 focus:outline-none focus:border-[#1b5e20] focus:ring-2 focus:ring-[#1b5e20]/10 transition"> class="w-full text-xs px-3.5 py-2.5 rounded-xl border border-slate-200 bg-white text-slate-800 font-semibold focus:outline-none focus:border-[#1b5e20] focus:ring-2 focus:ring-[#1b5e20]/10 transition">
<!-- Quick Preset Buttons (+6 Bulan, +1 Tahun) -->
<div class="flex items-center gap-2 mt-2">
<span class="text-[10px] text-slate-400 font-bold uppercase tracking-wider">Pintas:</span>
<button type="button" onclick="setRenewDateOffset(6)" class="text-[11px] px-2.5 py-1 rounded-lg border border-slate-200 bg-slate-50 hover:bg-slate-100 text-slate-700 font-semibold transition cursor-pointer">
+6 Bulan
</button>
<button type="button" onclick="setRenewDateOffset(12)" class="text-[11px] px-2.5 py-1 rounded-lg border border-slate-200 bg-slate-50 hover:bg-slate-100 text-slate-700 font-semibold transition cursor-pointer">
+1 Tahun
</button>
</div> </div>
<div class="pt-6 border-t border-slate-100 flex items-center justify-end space-x-3 mt-6"> </div>
<div class="pt-4 border-t border-slate-100 flex items-center justify-end space-x-2.5 mt-5">
<button type="button" onclick="closeRenewModal()" <button type="button" onclick="closeRenewModal()"
class="px-6 py-2.5 rounded-xl border border-slate-300 bg-white hover:bg-slate-50 text-slate-700 font-bold text-sm transition"> class="px-4 py-2 rounded-xl border border-slate-300 bg-white hover:bg-slate-50 text-slate-700 font-bold text-xs transition">
Batal Batal
</button> </button>
<button type="submit" <button type="submit"
class="px-6 py-2.5 rounded-xl bg-[#1b5e20] hover:bg-[#144919] text-white font-bold text-sm transition shadow-sm"> class="px-5 py-2 rounded-xl bg-[#1b5e20] hover:bg-[#144919] text-white font-bold text-xs transition shadow-sm inline-flex items-center gap-1.5">
Simpan Data <i class="fa-solid fa-floppy-disk text-xs"></i>
<span>Simpan Perpanjangan</span>
</button> </button>
</div> </div>
</form> </form>
@@ -1152,13 +1190,20 @@
function toggleEditSimperFields(id) { function toggleEditSimperFields(id) {
const check = document.getElementById(`editSimperCheck_${id}`); const check = document.getElementById(`editSimperCheck_${id}`);
const fields = document.getElementById(`editSimperFields_${id}`); const fields = document.getElementById(`editSimperFields_${id}`);
const numInp = document.getElementById(`editSimperNum_${id}`);
const expInp = document.getElementById(`editSimperExp_${id}`);
if (check && fields) { if (check && fields) {
if (check.checked) { if (check.checked) {
fields.classList.remove('hidden'); fields.classList.remove('hidden');
if (numInp) numInp.disabled = false;
if (expInp) expInp.disabled = false;
} else { } else {
fields.classList.add('hidden'); fields.classList.add('hidden');
const expInp = document.getElementById(`editSimperExp_${id}`); if (numInp) numInp.disabled = true;
if (expInp) expInp.value = ''; if (expInp) {
expInp.disabled = true;
expInp.value = '';
}
} }
} }
syncEditPrimarySimperDate(); syncEditPrimarySimperDate();
@@ -1248,9 +1293,9 @@
const fields = document.getElementById(`editSimperFields_${id}`); const fields = document.getElementById(`editSimperFields_${id}`);
if (fields) fields.classList.add('hidden'); if (fields) fields.classList.add('hidden');
const num = document.getElementById(`editSimperNum_${id}`); const num = document.getElementById(`editSimperNum_${id}`);
if (num) num.value = ''; if (num) { num.value = ''; num.disabled = true; }
const exp = document.getElementById(`editSimperExp_${id}`); const exp = document.getElementById(`editSimperExp_${id}`);
if (exp) exp.value = ''; if (exp) { exp.value = ''; exp.disabled = true; }
}); });
// Isi checklist SIMPER dari data emp.simpers // Isi checklist SIMPER dari data emp.simpers
@@ -1263,8 +1308,8 @@
if (cb) { if (cb) {
cb.checked = true; cb.checked = true;
if (fields) fields.classList.remove('hidden'); if (fields) fields.classList.remove('hidden');
if (num) num.value = s.simper_number || ''; if (num) { num.value = s.simper_number || ''; num.disabled = false; }
if (exp && s.expired_at) exp.value = s.expired_at.substring(0, 10); if (exp && s.expired_at) { exp.value = s.expired_at.substring(0, 10); exp.disabled = false; }
} }
}); });
} else if (emp.is_operator && expDate) { } else if (emp.is_operator && expDate) {
@@ -1274,8 +1319,10 @@
const id = firstCb.id.replace('editSimperCheck_', ''); const id = firstCb.id.replace('editSimperCheck_', '');
const fields = document.getElementById(`editSimperFields_${id}`); const fields = document.getElementById(`editSimperFields_${id}`);
if (fields) fields.classList.remove('hidden'); if (fields) fields.classList.remove('hidden');
const num = document.getElementById(`editSimperNum_${id}`);
if (num) num.disabled = false;
const exp = document.getElementById(`editSimperExp_${id}`); const exp = document.getElementById(`editSimperExp_${id}`);
if (exp) exp.value = expDate; if (exp) { exp.value = expDate; exp.disabled = false; }
} }
} }
syncEditPrimarySimperDate(); syncEditPrimarySimperDate();
@@ -1327,21 +1374,118 @@
if (modal) modal.classList.add('hidden'); if (modal) modal.classList.add('hidden');
} }
function openRenewModal(id, name, expiredDate, isOperator) { let currentRenewEmployee = null;
document.getElementById('renewName').textContent = name;
document.getElementById('renewOperator').value = isOperator ? '1' : '0';
document.getElementById('renewDate').value = expiredDate;
// Cek status driver untuk mengunci/membuka input SIMPER function openRenewModal(empOrId, legacyName, legacyDate, legacyIsOp) {
toggleSimperInput('renew'); let emp = null;
if (typeof empOrId === 'object' && empOrId !== null) {
emp = empOrId;
} else {
emp = {
id: empOrId,
name: legacyName || '',
nik: '',
is_operator: legacyIsOp ? 1 : 0,
simper_expired_at: legacyDate || '',
simpers: []
};
}
currentRenewEmployee = emp;
document.getElementById('renewForm').action = `/hse/employees/${id}`; document.getElementById('renewName').textContent = emp.name || '-';
document.getElementById('renewNik').textContent = emp.nik ? `NIK: ${emp.nik}` : '';
document.getElementById('renewOperator').value = '1';
const select = document.getElementById('renewSimperTypeSelect');
const badge = document.getElementById('renewSimperBadge');
select.innerHTML = '';
const simpers = Array.isArray(emp.simpers) ? emp.simpers : [];
const simperCount = simpers.length;
if (simperCount > 1) {
badge.textContent = `${simperCount} Izin SIMPER`;
// Opsi Semua SIMPER Sekaligus
const allOpt = document.createElement('option');
allOpt.value = 'all';
allOpt.textContent = '★ Perpanjang Semua Jenis SIMPER Sekaligus';
select.appendChild(allOpt);
simpers.forEach(s => {
const opt = document.createElement('option');
opt.value = s.simper_type_id;
const typeName = s.simper_type ? s.simper_type.name : `SIMPER ID #${s.simper_type_id}`;
const expText = s.expired_at ? s.expired_at.substring(0, 10) : 'Belum diatur';
opt.textContent = `${typeName} (s/d ${expText})`;
opt.dataset.exp = s.expired_at ? s.expired_at.substring(0, 10) : '';
select.appendChild(opt);
});
} else if (simperCount === 1) {
badge.textContent = '1 Izin SIMPER';
const s = simpers[0];
const opt = document.createElement('option');
opt.value = s.simper_type_id;
const typeName = s.simper_type ? s.simper_type.name : 'SIMPER';
const expText = s.expired_at ? s.expired_at.substring(0, 10) : 'Belum diatur';
opt.textContent = `${typeName} (Masa berlaku saat ini: ${expText})`;
opt.dataset.exp = s.expired_at ? s.expired_at.substring(0, 10) : '';
select.appendChild(opt);
} else {
badge.textContent = 'Belum Ada SIMPER';
const opt = document.createElement('option');
opt.value = 'all';
opt.textContent = 'SIMPER Standar / Default (Semua)';
select.appendChild(opt);
}
// Sinkronisasi tanggal
onRenewSimperTypeChange(select.value);
document.getElementById('renewForm').action = `/hse/employees/${emp.id}`;
document.getElementById('renewModal').classList.remove('hidden'); document.getElementById('renewModal').classList.remove('hidden');
} }
function onRenewSimperTypeChange(val) {
const select = document.getElementById('renewSimperTypeSelect');
const selectedOpt = select.options[select.selectedIndex];
const infoEl = document.getElementById('renewCurrentExpInfo');
const dateInput = document.getElementById('renewDate');
let currentExp = '';
if (selectedOpt && selectedOpt.dataset.exp) {
currentExp = selectedOpt.dataset.exp;
} else if (currentRenewEmployee && currentRenewEmployee.simper_expired_at) {
currentExp = currentRenewEmployee.simper_expired_at.substring(0, 10);
}
if (currentExp) {
infoEl.innerHTML = `<i class="fa-regular fa-clock text-slate-400"></i> Masa berlaku saat ini: <strong class="text-slate-700">${currentExp}</strong>`;
// Preset tanggal baru: 1 tahun dari masa berlaku sekarang (jika masa depan) atau 1 tahun dari hari ini
const currDateObj = new Date(currentExp);
const today = new Date();
const targetBase = (!isNaN(currDateObj) && currDateObj > today) ? currDateObj : today;
const newDate = new Date(targetBase);
newDate.setFullYear(newDate.getFullYear() + 1);
dateInput.value = newDate.toISOString().substring(0, 10);
} else {
infoEl.innerHTML = `<i class="fa-solid fa-circle-info text-amber-500"></i> Belum ada masa berlaku sebelumnya.`;
const now = new Date();
now.setFullYear(now.getFullYear() + 1);
dateInput.value = now.toISOString().substring(0, 10);
}
}
function setRenewDateOffset(months) {
const dateInput = document.getElementById('renewDate');
const now = new Date();
now.setMonth(now.getMonth() + months);
dateInput.value = now.toISOString().substring(0, 10);
}
function closeRenewModal() { function closeRenewModal() {
const modal = document.getElementById('renewModal'); const modal = document.getElementById('renewModal');
if (modal) modal.classList.add('hidden'); if (modal) modal.classList.add('hidden');
currentRenewEmployee = null;
} }
function openDeleteEmployeeModal(id, name, nik) { function openDeleteEmployeeModal(id, name, nik) {
+124 -15
View File
@@ -165,8 +165,13 @@
onclick="switchP2hSection('{{ $secKey }}')" onclick="switchP2hSection('{{ $secKey }}')"
id="p2h-tab-{{ $secKey }}" id="p2h-tab-{{ $secKey }}"
data-section-key="{{ $secKey }}" data-section-key="{{ $secKey }}"
class="p2h-section-tab group inline-flex items-center px-4 py-2.5 rounded-xl text-xs font-bold transition whitespace-nowrap cursor-pointer shrink-0 {{ $isFirst ? 'bg-[#1b5e20] text-white shadow-xs border border-[#1b5e20]' : 'bg-white border border-slate-200 text-slate-700 hover:bg-slate-50 hover:border-slate-300' }}"> data-section-index="{{ $loop->index }}"
class="p2h-section-tab group inline-flex items-center space-x-1.5 px-4 py-2.5 rounded-xl text-xs font-bold transition whitespace-nowrap cursor-pointer shrink-0 {{ $isFirst ? 'bg-[#1b5e20] text-white shadow-xs border border-[#1b5e20]' : 'bg-white border border-slate-200 text-slate-700 hover:bg-slate-50 hover:border-slate-300' }}">
<span class="step-num text-[10px] font-mono opacity-80">#{{ $loop->iteration }}</span>
<span>{{ $sectionName }}</span> <span>{{ $sectionName }}</span>
<span id="tab-check-{{ $secKey }}" class="tab-check-icon hidden text-emerald-400 font-black">
<i class="fa-solid fa-circle-check text-[11px]"></i>
</span>
</button> </button>
@endforeach @endforeach
</div> </div>
@@ -289,15 +294,15 @@
@endforeach @endforeach
</div> </div>
<!-- Navigasi Cepat Antar Section (Sebelumnya & Selanjutnya) --> <!-- Navigasi Wizard Bertahap Antar Section -->
@if(count($groupedItems) > 1) @if(count($groupedItems) > 1)
<div class="px-4 py-3 bg-slate-50/80 border-t border-slate-100 flex items-center justify-between"> <div class="px-4 py-3 bg-slate-50/80 border-t border-slate-100 flex items-center justify-between">
@if($prevKey) @if($prevKey)
<button type="button" <button type="button"
onclick="switchP2hSection('{{ $prevKey }}')" onclick="switchP2hSection('{{ $prevKey }}')"
class="inline-flex items-center space-x-1.5 px-3 py-1.5 rounded-lg text-xs font-semibold text-slate-600 hover:text-slate-900 bg-white border border-slate-200 hover:bg-slate-100 transition shadow-2xs cursor-pointer"> class="inline-flex items-center space-x-1.5 px-3.5 py-2 rounded-xl text-xs font-semibold text-slate-600 hover:text-slate-900 bg-white border border-slate-200 hover:bg-slate-100 transition shadow-2xs cursor-pointer">
<i class="fa-solid fa-chevron-left text-[10px]"></i> <i class="fa-solid fa-chevron-left text-[10px]"></i>
<span>Bagian Sebelumnya</span> <span>Kembali</span>
</button> </button>
@else @else
<div></div> <div></div>
@@ -305,15 +310,18 @@
@if($nextKey) @if($nextKey)
<button type="button" <button type="button"
onclick="switchP2hSection('{{ $nextKey }}')" onclick="completeAndNextSection('{{ $secKey }}', '{{ $nextKey }}')"
class="inline-flex items-center space-x-1.5 px-3 py-1.5 rounded-lg text-xs font-bold text-emerald-800 bg-emerald-50 hover:bg-emerald-100 border border-emerald-200 transition shadow-2xs cursor-pointer"> class="inline-flex items-center space-x-1.5 px-4 py-2 rounded-xl text-xs font-bold text-white bg-[#1b5e20] hover:bg-[#144918] transition shadow-xs cursor-pointer">
<span>Bagian Selanjutnya</span> <span>Selesaikan Bagian Ini & Lanjut</span>
<i class="fa-solid fa-chevron-right text-[10px]"></i> <i class="fa-solid fa-chevron-right text-[10px]"></i>
</button> </button>
@else @else
<span class="text-[11px] font-semibold text-slate-400 flex items-center"> <button type="button"
<i class="fa-solid fa-flag-checkered mr-1.5 text-emerald-600"></i> Bagian Terakhir onclick="markLastSectionComplete('{{ $secKey }}')"
</span> class="inline-flex items-center space-x-1.5 px-4 py-2 rounded-xl text-xs font-bold text-emerald-800 bg-emerald-100 hover:bg-emerald-200 border border-emerald-300 transition shadow-xs cursor-pointer">
<i class="fa-solid fa-circle-check text-xs"></i>
<span>Selesaikan Pemeriksaan Bagian Terakhir</span>
</button>
@endif @endif
</div> </div>
@endif @endif
@@ -330,12 +338,21 @@
<textarea name="general_notes" id="general_notes" rows="3" placeholder="Tuliskan temuan atau catatan umum lainnya mengenai kondisi Heavy Equipment hari ini..." class="w-full rounded-xl border border-slate-300 bg-white px-3.5 py-2.5 text-xs text-slate-800 focus:border-emerald-500 focus:ring-4 focus:ring-emerald-500/10 transition resize-none">{{ old('general_notes') }}</textarea> <textarea name="general_notes" id="general_notes" rows="3" placeholder="Tuliskan temuan atau catatan umum lainnya mengenai kondisi Heavy Equipment hari ini..." class="w-full rounded-xl border border-slate-300 bg-white px-3.5 py-2.5 text-xs text-slate-800 focus:border-emerald-500 focus:ring-4 focus:ring-emerald-500/10 transition resize-none">{{ old('general_notes') }}</textarea>
</div> </div>
<!-- Tombol Aksi Submit --> <!-- Card Tombol Aksi Submit P2H (Aktif Setelah Seluruh Bagian Ditinjau) -->
<div class="bg-white rounded-2xl shadow-sm border border-slate-200 p-4 sm:p-5 flex items-center justify-between gap-3"> <div id="p2hSubmitCard" class="bg-white rounded-2xl shadow-sm border border-slate-200 p-4 sm:p-5 transition-all">
<div id="p2hPendingNotice" class="{{ count($groupedItems) > 1 ? '' : 'hidden' }} flex items-center justify-between text-xs text-amber-800 bg-amber-50 border border-amber-200 rounded-xl p-3 mb-3">
<div class="flex items-center gap-2">
<i class="fa-solid fa-circle-info text-amber-600 text-sm"></i>
<span>Harap selesaikan pemeriksaan pada seluruh bagian (section) di atas untuk memunculkan tombol pengiriman formulir P2H ke QMA.</span>
</div>
</div>
<div class="flex items-center justify-between gap-3">
<a href="{{ route('p2h.index') }}" class="bg-slate-100 hover:bg-slate-200 text-slate-600 font-semibold py-2.5 px-4 rounded-xl transition text-xs"> <a href="{{ route('p2h.index') }}" class="bg-slate-100 hover:bg-slate-200 text-slate-600 font-semibold py-2.5 px-4 rounded-xl transition text-xs">
Batal Batal
</a> </a>
<div id="p2hSubmitBtnContainer" class="{{ count($groupedItems) > 1 ? 'hidden' : '' }}">
<button type="submit" <button type="submit"
id="btnSubmitP2h" id="btnSubmitP2h"
class="bg-[#1b5e20] hover:bg-[#144918] active:scale-[0.99] text-white font-bold py-2.5 px-6 rounded-xl shadow-sm hover:shadow transition flex items-center space-x-2 text-xs sm:text-sm cursor-pointer"> class="bg-[#1b5e20] hover:bg-[#144918] active:scale-[0.99] text-white font-bold py-2.5 px-6 rounded-xl shadow-sm hover:shadow transition flex items-center space-x-2 text-xs sm:text-sm cursor-pointer">
@@ -343,26 +360,34 @@
<span>Kirim Formulir P2H ke QMA</span> <span>Kirim Formulir P2H ke QMA</span>
</button> </button>
</div> </div>
</div>
</div>
</form> </form>
</div> </div>
@endsection @endsection
@section('scripts') @section('scripts')
<script> <script>
const allSectionKeys = @json($sectionKeys);
const completedSections = {};
function switchP2hSection(secKey) { function switchP2hSection(secKey) {
// 1. Update tab styling // 1. Update tab styling
const allTabs = document.querySelectorAll('.p2h-section-tab'); const allTabs = document.querySelectorAll('.p2h-section-tab');
allTabs.forEach(tab => { allTabs.forEach(tab => {
const key = tab.dataset.sectionKey; const key = tab.dataset.sectionKey;
const isCompleted = !!completedSections[key];
if (key === secKey) { if (key === secKey) {
tab.className = 'p2h-section-tab group inline-flex items-center px-4 py-2.5 rounded-xl text-xs font-bold transition whitespace-nowrap cursor-pointer shrink-0 bg-[#1b5e20] text-white shadow-xs border border-[#1b5e20]'; tab.className = 'p2h-section-tab group inline-flex items-center space-x-1.5 px-4 py-2.5 rounded-xl text-xs font-bold transition whitespace-nowrap cursor-pointer shrink-0 bg-[#1b5e20] text-white shadow-xs border border-[#1b5e20]';
tab.scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'center' }); tab.scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'center' });
} else if (isCompleted) {
tab.className = 'p2h-section-tab group inline-flex items-center space-x-1.5 px-4 py-2.5 rounded-xl text-xs font-bold transition whitespace-nowrap cursor-pointer shrink-0 bg-emerald-50 border border-emerald-200 text-emerald-800 hover:bg-emerald-100';
} else { } else {
tab.className = 'p2h-section-tab group inline-flex items-center px-4 py-2.5 rounded-xl text-xs font-bold transition whitespace-nowrap cursor-pointer shrink-0 bg-white border border-slate-200 text-slate-700 hover:bg-slate-50 hover:border-slate-300'; tab.className = 'p2h-section-tab group inline-flex items-center space-x-1.5 px-4 py-2.5 rounded-xl text-xs font-bold transition whitespace-nowrap cursor-pointer shrink-0 bg-white border border-slate-200 text-slate-700 hover:bg-slate-50 hover:border-slate-300';
} }
}); });
// 2. Show active panel, hide others // 2. Tampilkan panel aktif, sembunyikan lainnya
const allPanels = document.querySelectorAll('.p2h-section-content'); const allPanels = document.querySelectorAll('.p2h-section-content');
allPanels.forEach(panel => { allPanels.forEach(panel => {
if (panel.id === 'p2h-content-' + secKey) { if (panel.id === 'p2h-content-' + secKey) {
@@ -371,6 +396,83 @@
panel.classList.add('hidden'); panel.classList.add('hidden');
} }
}); });
checkAllSectionsCompleted();
}
function validateSectionNotes(secKey) {
const panel = document.getElementById('p2h-content-' + secKey);
if (!panel) return true;
const damagedRadios = panel.querySelectorAll('input[type="radio"][value="rusak"]:checked');
for (const radio of damagedRadios) {
const match = radio.name.match(/items\[(\d+)\]/);
if (match && match[1]) {
const notesInput = panel.querySelector(`input[name="items[${match[1]}][notes]"]`);
if (notesInput && !notesInput.value.trim()) {
notesInput.focus();
alert('Mohon isi catatan kerusakan pada butir yang Anda tandai "Rusak" sebelum melanjutkan.');
return false;
}
}
}
return true;
}
function completeAndNextSection(currentKey, nextKey) {
if (!validateSectionNotes(currentKey)) {
return;
}
completedSections[currentKey] = true;
const checkIcon = document.getElementById('tab-check-' + currentKey);
if (checkIcon) checkIcon.classList.remove('hidden');
switchP2hSection(nextKey);
}
function markLastSectionComplete(lastSecKey) {
if (!validateSectionNotes(lastSecKey)) {
return;
}
completedSections[lastSecKey] = true;
const checkIcon = document.getElementById('tab-check-' + lastSecKey);
if (checkIcon) checkIcon.classList.remove('hidden');
checkAllSectionsCompleted();
// Gulir halus ke tombol kirim di bawah
const submitCard = document.getElementById('p2hSubmitCard');
if (submitCard) {
submitCard.scrollIntoView({ behavior: 'smooth', block: 'center' });
}
}
function checkAllSectionsCompleted() {
if (!allSectionKeys || allSectionKeys.length <= 1) {
showSubmitButton();
return;
}
let allDone = true;
for (const key of allSectionKeys) {
if (!completedSections[key]) {
allDone = false;
break;
}
}
if (allDone) {
showSubmitButton();
}
}
function showSubmitButton() {
const container = document.getElementById('p2hSubmitBtnContainer');
const notice = document.getElementById('p2hPendingNotice');
if (container) container.classList.remove('hidden');
if (notice) notice.classList.add('hidden');
} }
function handleConditionChange(itemId, condition) { function handleConditionChange(itemId, condition) {
@@ -396,5 +498,12 @@
} }
}); });
} }
// Inisialisasi awal
document.addEventListener('DOMContentLoaded', function() {
if (!allSectionKeys || allSectionKeys.length <= 1) {
showSubmitButton();
}
});
</script> </script>
@endsection @endsection
@@ -471,6 +471,38 @@
openGateSelectionModal(true); openGateSelectionModal(true);
}); });
@endif @endif
// Modal Tolak Perjalanan Kendaraan di Pos Gerbang
function openRejectModal(id, unit, driver, direction) {
document.getElementById('rejectUnitDisplay').textContent = unit || '-';
document.getElementById('rejectDriverDisplay').textContent = driver || '-';
const dirEl = document.getElementById('rejectDirectionDisplay');
if (direction === 'in') {
dirEl.textContent = 'Masuk Gerbang (IN)';
dirEl.className = 'font-bold text-xs uppercase px-2 py-0.5 rounded-md bg-blue-100 text-blue-800';
} else {
dirEl.textContent = 'Keluar Gerbang (OUT)';
dirEl.className = 'font-bold text-xs uppercase px-2 py-0.5 rounded-md bg-amber-100 text-amber-800';
}
document.getElementById('rejectNoteInput').value = '';
document.getElementById('rejectForm').action = `/pg/gate-inspection/${id}/reject`;
const modal = document.getElementById('rejectModal');
if (modal) modal.classList.remove('hidden');
}
function closeRejectModal() {
const modal = document.getElementById('rejectModal');
if (modal) modal.classList.add('hidden');
}
function setQuickReason(text) {
const input = document.getElementById('rejectNoteInput');
if (input) {
input.value = text;
input.focus();
}
}
</script> </script>
<!-- MODAL LIGHTBOX PRATINJAU FOTO DRIVER & MOBIL LV --> <!-- MODAL LIGHTBOX PRATINJAU FOTO DRIVER & MOBIL LV -->
@@ -581,4 +613,111 @@
</div> </div>
</div> </div>
</div> </div>
<!-- ========================================================================= -->
<!-- MODAL POPUP: TOLAK PERJALANAN KENDARAAN (DENGAN DETAIL ALASAN) -->
<!-- ========================================================================= -->
<div id="rejectModal" data-backdrop="static" class="hidden fixed inset-0 z-50 bg-slate-900/60 backdrop-blur-xs 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 space-y-4">
<!-- Header Modal -->
<div class="flex items-start justify-between gap-3 pb-3 border-b border-slate-100">
<div class="flex items-center space-x-3">
<div class="w-12 h-12 rounded-2xl bg-rose-100 text-rose-700 flex items-center justify-center text-xl flex-shrink-0 shadow-2xs">
<i class="fa-solid fa-ban"></i>
</div>
<div>
<h3 class="text-base sm:text-lg font-black text-slate-900 tracking-tight">
Tolak Perjalanan Kendaraan
</h3>
<p class="text-xs text-slate-500 mt-0.5">
Berikan alasan penolakan secara jelas untuk catatan log audit & driver.
</p>
</div>
</div>
<button type="button" onclick="closeRejectModal()" class="text-slate-400 hover:text-slate-600 p-1.5 rounded-lg hover:bg-slate-100 transition cursor-pointer">
<i class="fa-solid fa-xmark text-sm"></i>
</button>
</div>
<!-- Identitas Kendaraan & Driver -->
<div class="bg-slate-50 p-3.5 rounded-2xl border border-slate-200/80 space-y-1.5">
<div class="flex items-center justify-between text-xs">
<span class="text-slate-500 font-bold">Kendaraan:</span>
<span id="rejectUnitDisplay" class="font-mono font-black text-slate-900"></span>
</div>
<div class="flex items-center justify-between text-xs">
<span class="text-slate-500 font-bold">Pengemudi:</span>
<span id="rejectDriverDisplay" class="font-bold text-slate-900"></span>
</div>
<div class="flex items-center justify-between text-xs">
<span class="text-slate-500 font-bold">Arah Perlintasan:</span>
<span id="rejectDirectionDisplay" class="font-bold text-xs uppercase px-2 py-0.5 rounded-md"></span>
</div>
</div>
<!-- Form Penolakan -->
<form id="rejectForm" method="POST" action="" class="space-y-4">
@csrf
@if($currentGuard)
<input type="hidden" name="security_guard_id" value="{{ $currentGuard->id }}">
@elseif($guards->isNotEmpty())
<div>
<label class="block text-xs font-bold text-slate-700 mb-1">
Petugas Satpam Pemeriksa <span class="text-rose-500">*</span>
</label>
<select name="security_guard_id" required class="w-full text-xs px-3.5 py-2.5 rounded-xl border border-slate-200 bg-white text-slate-800 font-semibold focus:outline-none focus:border-rose-600">
@foreach($guards as $g)
<option value="{{ $g->id }}">{{ $g->name }} (Reg: {{ $g->badge_id }})</option>
@endforeach
</select>
</div>
@endif
<!-- Quick Reason Chips -->
<div>
<label class="block text-xs font-bold text-slate-700 mb-1.5">
Pilih Cepat Alasan Penolakan:
</label>
<div class="flex flex-wrap gap-1.5">
<button type="button" onclick="setQuickReason('Masa berlaku SIMPER pengemudi telah kedaluwarsa (Expired)')" class="text-[11px] px-2.5 py-1 rounded-lg border border-slate-200 bg-slate-50 hover:bg-rose-50 hover:border-rose-300 hover:text-rose-700 transition font-medium cursor-pointer">
SIMPER Expired
</button>
<button type="button" onclick="setQuickReason('Kondisi fisik kendaraan tidak layak jalan (Rem blong / Lampu mati / Ban botak)')" class="text-[11px] px-2.5 py-1 rounded-lg border border-slate-200 bg-slate-50 hover:bg-rose-50 hover:border-rose-300 hover:text-rose-700 transition font-medium cursor-pointer">
Fisik Tidak Layak
</button>
<button type="button" onclick="setQuickReason('Tujuan atau keperluan perjalanan tidak jelas / Tanpa instruksi kerja')" class="text-[11px] px-2.5 py-1 rounded-lg border border-slate-200 bg-slate-50 hover:bg-rose-50 hover:border-rose-300 hover:text-rose-700 transition font-medium cursor-pointer">
Tujuan Tidak Jelas
</button>
<button type="button" onclick="setQuickReason('Surat jalan / BAST belum lengkap')" class="text-[11px] px-2.5 py-1 rounded-lg border border-slate-200 bg-slate-50 hover:bg-rose-50 hover:border-rose-300 hover:text-rose-700 transition font-medium cursor-pointer">
Surat Jalan Kurang
</button>
<button type="button" onclick="setQuickReason('Pengemudi bukan operator / driver yang terdaftar untuk unit ini')" class="text-[11px] px-2.5 py-1 rounded-lg border border-slate-200 bg-slate-50 hover:bg-rose-50 hover:border-rose-300 hover:text-rose-700 transition font-medium cursor-pointer">
Bukan Driver Resmi
</button>
</div>
</div>
<!-- Detail Alasan Wajib -->
<div>
<label for="rejectNoteInput" class="block text-xs font-bold text-slate-700 mb-1.5">
Detail Catatan / Alasan Penolakan <span class="text-rose-500">*</span>
</label>
<textarea name="rejection_note" id="rejectNoteInput" rows="3" required
placeholder="Jelaskan alasan penolakan secara spesifik..."
class="w-full text-xs p-3 rounded-xl border border-slate-300 bg-white text-slate-800 placeholder:text-slate-400 focus:outline-none focus:border-rose-600 focus:ring-2 focus:ring-rose-500/10 transition resize-none"></textarea>
</div>
<div class="pt-3 border-t border-slate-100 flex items-center justify-end gap-2.5">
<button type="button" onclick="closeRejectModal()" class="px-4 py-2 text-xs font-bold text-slate-600 hover:bg-slate-100 rounded-xl transition cursor-pointer">
Batal
</button>
<button type="submit"
onclick="if(!document.getElementById('rejectNoteInput').value.trim()){ alert('Alasan penolakan wajib diisi!'); return false; }"
class="px-5 py-2.5 bg-rose-600 hover:bg-rose-700 active:bg-rose-800 text-white font-bold text-xs rounded-xl shadow-xs transition flex items-center space-x-1.5 cursor-pointer">
<i class="fa-solid fa-ban text-xs"></i>
<span>Konfirmasi Tolak Perjalanan</span>
</button>
</div>
</form>
</div>
</div>
@endsection @endsection
@@ -113,15 +113,25 @@
</div> </div>
@endif @endif
<!-- Baris 4: Tombol Verifikasi Langsung di Card (Tanpa Popup & Tanpa Fitur Tolak) --> <!-- Baris 4: Tombol Aksi Verifikasi & Tolak Perjalanan -->
<div class="mt-3.5 pt-3 border-t border-slate-100 flex flex-col sm:flex-row items-center justify-between gap-2.5"> <div class="mt-3.5 pt-3 border-t border-slate-100 flex flex-col sm:flex-row items-center justify-between gap-2.5">
<span class="text-[11px] text-slate-400 font-medium hidden sm:inline flex items-center gap-1.5"> <span class="text-[11px] text-slate-400 font-medium hidden sm:inline flex items-center gap-1.5">
<i class="fa-solid fa-shield-check text-[#1b5e20]"></i> <i class="fa-solid fa-shield-check text-[#1b5e20]"></i>
<span>Cek fisik kendaraan lalu klik verifikasi untuk membuka portal</span> <span>Cek fisik kendaraan lalu pilih verifikasi atau tolak</span>
</span> </span>
<div class="flex items-center gap-2 w-full sm:w-auto">
@can('gate.reject')
<button type="button"
onclick="openRejectModal({{ $act->id }}, '{{ addslashes($act->vehicle->code . ' (' . ($act->vehicle->license_plate ?? 'Tanpa Plat') . ')') }}', '{{ addslashes($act->driver->name ?? 'Pengemudi') }}', '{{ strtolower($act->direction) }}')"
class="w-1/2 sm:w-auto px-4 py-2.5 bg-rose-50 hover:bg-rose-100 active:bg-rose-200 text-rose-700 border border-rose-200 font-bold text-xs sm:text-sm rounded-xl transition flex items-center justify-center space-x-1.5 cursor-pointer shadow-2xs">
<i class="fa-solid fa-ban text-xs"></i>
<span>Tolak</span>
</button>
@endcan
@can('gate.approve') @can('gate.approve')
<form action="{{ route('pg.gate.approve', $act->id) }}" method="POST" class="w-full sm:w-auto m-0"> <form action="{{ route('pg.gate.approve', $act->id) }}" method="POST" class="w-1/2 sm:w-auto m-0">
@csrf @csrf
@if($currentGuard) @if($currentGuard)
<input type="hidden" name="security_guard_id" value="{{ $currentGuard->id }}"> <input type="hidden" name="security_guard_id" value="{{ $currentGuard->id }}">
@@ -136,10 +146,9 @@
<span>Verifikasi</span> <span>Verifikasi</span>
</button> </button>
</form> </form>
@else
<span class="text-xs text-slate-400 italic">Tidak memiliki izin verifikasi</span>
@endcan @endcan
</div> </div>
</div>
</div> </div>
@empty @empty
@@ -173,99 +173,91 @@
</form> </form>
</div> </div>
<!-- Tabel Riwayat Transfer Unit dengan Header Biru Tua Navy (Pada Mobile: Format Kotak Tanpa Border Radius) --> <!-- Tabel Riwayat Transfer Unit dengan Header Biru Tua Navy (Format Ramping & Nyaman) -->
<div class="bg-white rounded-none sm:rounded-2xl border border-slate-200 shadow-sm overflow-hidden"> <div class="bg-white rounded-none sm:rounded-2xl border border-slate-200 shadow-sm overflow-hidden">
<div class="overflow-x-auto"> <div class="overflow-x-auto">
<table class="min-w-full text-xs text-left border-collapse"> <table class="min-w-full text-xs text-left border-collapse">
<!-- Header Tabel Navy Gelap Solid #06213f --> <!-- Header Tabel Navy Gelap Solid #06213f -->
<thead class="bg-[#06213f] text-white font-bold text-[11px] uppercase tracking-wider"> <thead class="bg-[#06213f] text-white font-bold text-[11px] uppercase tracking-wider">
<tr> <tr>
<th class="py-3.5 px-4 text-center w-12">NO</th> <th class="py-3 px-3.5 text-center w-10">NO</th>
<th class="py-3.5 px-4 whitespace-nowrap">TANGGAL & NO TRANSFER</th> <th class="py-3 px-3.5 whitespace-nowrap">DOKUMEN & TANGGAL</th>
<th class="py-3.5 px-4 whitespace-nowrap">BERITA ACARA (BAST)</th> <th class="py-3 px-3.5 whitespace-nowrap">UNIT ALAT BERAT</th>
<th class="py-3.5 px-4 whitespace-nowrap min-w-[180px]">UNIT ALAT BERAT</th> <th class="py-3 px-3.5 whitespace-nowrap">RUTE PEMINDAHAN</th>
<th class="py-3.5 px-4 whitespace-nowrap min-w-[200px]">PERPINDAHAN LOKASI</th> <th class="py-3 px-3.5 whitespace-nowrap">PENGANGKUT & SUPIR</th>
<th class="py-3.5 px-4 whitespace-nowrap">ARMADA & SUPIR</th> <th class="py-3 px-3.5 whitespace-nowrap">PELAPOR</th>
<th class="py-3.5 px-4 whitespace-nowrap">PELAPOR</th> <th class="py-3 px-3.5 text-center whitespace-nowrap w-24">AKSI</th>
<th class="py-3.5 px-4 text-center whitespace-nowrap w-28">AKSI</th>
</tr> </tr>
</thead> </thead>
<tbody class="divide-y divide-slate-100 text-slate-700 bg-white"> <tbody class="divide-y divide-slate-100 text-slate-700 bg-white">
@forelse($transfers as $index => $t) @forelse($transfers as $index => $t)
<tr class="hover:bg-slate-50/80 transition"> <tr class="hover:bg-slate-50/80 transition">
<!-- 1. No --> <!-- 1. No -->
<td class="py-3.5 px-3.5 text-center text-slate-400 font-medium"> <td class="py-2.5 px-3.5 text-center text-slate-400 font-medium">
{{ $transfers->firstItem() + $index }} {{ $transfers->firstItem() + $index }}
</td> </td>
<!-- 2. Tanggal & No Transfer --> <!-- 2. Dokumen BAST & Tanggal Transfer -->
<td class="py-3.5 px-3.5 whitespace-nowrap"> <td class="py-2.5 px-3.5 whitespace-nowrap">
<div class="font-bold text-slate-900"> <div class="flex items-center space-x-1.5">
{{ $t->transfer_date ? $t->transfer_date->translatedFormat('d M Y') : '-' }}
</div>
<span class="inline-block mt-0.5 font-mono text-[10px] text-slate-500 bg-slate-100 px-1.5 py-0.5 rounded">
{{ $t->transfer_no }}
</span>
</td>
<!-- 3. Berita Acara -->
<td class="py-3.5 px-3.5 min-w-[200px]">
@if($t->document_number) @if($t->document_number)
<div class="font-bold text-slate-900 leading-tight font-mono text-xs"> <span class="font-bold text-slate-900 font-mono text-xs">
{{ $t->document_number }} {{ $t->document_number }}
</div> </span>
<div class="text-[11px] text-slate-500 mt-0.5 line-clamp-1" title="{{ $t->document_title }}">
{{ $t->document_title }}
</div>
@if($t->document_file_path) @if($t->document_file_path)
<a href="{{ $t->document_file_url }}" target="_blank" class="inline-flex items-center space-x-1 text-[10px] font-bold text-emerald-700 hover:text-emerald-900 mt-1"> <a href="{{ $t->document_file_url }}" target="_blank" class="text-emerald-700 hover:text-emerald-900 text-xs" title="Lihat Lampiran Berkas">
<i class="fa-solid fa-paperclip"></i> <i class="fa-solid fa-paperclip"></i>
<span>Lihat Lampiran</span>
</a> </a>
@endif @endif
@else @else
<span class="inline-flex items-center space-x-1 px-2 py-0.5 rounded text-[11px] font-medium text-slate-500 bg-slate-100 border border-slate-200"> <span class="px-1.5 py-0.5 rounded text-[10px] font-bold text-slate-600 bg-slate-100 border border-slate-200">
<span>Tanpa BAST (Internal Site)</span> Internal Site
</span> </span>
@endif @endif
</div>
<div class="text-[11px] text-slate-500 mt-0.5 flex items-center gap-1.5 font-medium">
<span>{{ $t->transfer_date ? $t->transfer_date->translatedFormat('d M Y') : '-' }}</span>
<span class="text-slate-300">&bull;</span>
<span class="font-mono text-[10px] text-slate-400">{{ $t->transfer_no }}</span>
</div>
</td> </td>
<!-- 4. Unit Alat Berat --> <!-- 3. Unit Alat Berat -->
<td class="py-3.5 px-3.5 whitespace-nowrap"> <td class="py-2.5 px-3.5 whitespace-nowrap">
<div class="flex items-center space-x-2.5"> <div class="flex items-center space-x-2">
@if($t->vehicle && $t->vehicle->photo_url) @if($t->vehicle && $t->vehicle->photo_url)
<img src="{{ $t->vehicle->photo_url }}" alt="{{ $t->vehicle->code }}" class="w-9 h-9 rounded-xl object-cover border border-slate-200 shrink-0"> <img src="{{ $t->vehicle->photo_url }}" alt="{{ $t->vehicle->code }}" class="w-8 h-8 rounded-lg object-cover border border-slate-200 shrink-0">
@else @else
<div class="w-9 h-9 rounded-xl bg-slate-100 text-slate-400 flex items-center justify-center shrink-0 border border-slate-200"> <div class="w-8 h-8 rounded-lg bg-slate-100 text-slate-400 flex items-center justify-center shrink-0 border border-slate-200 text-xs">
<i class="fa-solid fa-truck-monster text-sm"></i> <i class="fa-solid fa-truck-monster"></i>
</div> </div>
@endif @endif
<div> <div>
<div class="font-black text-slate-900 tracking-tight"> <div class="font-black text-slate-900 tracking-tight text-xs">
{{ $t->vehicle?->code ?? '-' }} {{ $t->vehicle?->code ?? '-' }}
</div> </div>
<div class="text-[11px] text-slate-500"> <div class="text-[10px] text-slate-500 max-w-[150px] truncate" title="{{ $t->vehicle?->brand_type ?? '-' }}">
{{ $t->vehicle?->brand_type ?? '-' }} {{ $t->vehicle?->brand_type ?? '-' }}
</div> </div>
</div> </div>
</div> </div>
</td> </td>
<!-- 5. Lokasi Asal -> Lokasi Tujuan --> <!-- 4. Rute Pemindahan -->
<td class="py-3.5 px-3.5"> <td class="py-2.5 px-3.5">
<div class="flex items-center space-x-1.5 text-xs"> <div class="flex items-center space-x-1.5 text-xs whitespace-nowrap">
<span class="text-slate-600 font-medium">{{ $t->from_location }}</span> <span class="text-slate-600 font-medium">{{ $t->from_location }}</span>
<i class="fa-solid fa-arrow-right text-[10px] text-emerald-600"></i> <i class="fa-solid fa-arrow-right text-[10px] text-slate-400"></i>
<span class="font-extrabold text-[#1b5e20]">{{ $t->to_location }}</span> <span class="font-bold text-[#1b5e20]">{{ $t->to_location }}</span>
</div> </div>
<div class="mt-1"> <div class="mt-0.5">
@if($t->isToInsideSite()) @if($t->isToInsideSite())
<span class="inline-flex items-center space-x-1 px-2 py-0.5 rounded-full text-[10px] font-bold bg-emerald-50 text-emerald-700 border border-emerald-200"> <span class="inline-flex items-center gap-1 text-[10px] font-semibold text-emerald-700">
<span class="w-1.5 h-1.5 rounded-full bg-emerald-500"></span> <span class="w-1.5 h-1.5 rounded-full bg-emerald-500"></span>
<span>Di Dalam Site</span> <span>Di Dalam Site</span>
</span> </span>
@else @else
<span class="inline-flex items-center space-x-1 px-2 py-0.5 rounded-full text-[10px] font-bold bg-amber-50 text-amber-700 border border-amber-200"> <span class="inline-flex items-center gap-1 text-[10px] font-semibold text-amber-700">
<span class="w-1.5 h-1.5 rounded-full bg-amber-500"></span> <span class="w-1.5 h-1.5 rounded-full bg-amber-500"></span>
<span>Di Luar Site</span> <span>Di Luar Site</span>
</span> </span>
@@ -273,34 +265,33 @@
</div> </div>
</td> </td>
<!-- 6. Armada & Supir Pengangkut --> <!-- 5. Armada & Supir Pengangkut -->
<td class="py-3.5 px-3.5 whitespace-nowrap"> <td class="py-2.5 px-3.5 whitespace-nowrap">
<div class="font-semibold text-slate-800"> <div class="font-semibold text-slate-800 text-xs flex items-center gap-1">
<i class="fa-solid fa-truck-moving text-slate-400 mr-1 text-[11px]"></i> <i class="fa-solid fa-truck-moving text-slate-400 text-[10px]"></i>
{{ $t->transporter_unit_name ?: ($t->transporterVehicle?->code ?? 'Tanpa Pengangkut') }} <span>{{ $t->transporter_unit_name ?: ($t->transporterVehicle?->code ?? 'Tanpa Pengangkut') }}</span>
</div> </div>
<div class="text-[11px] text-slate-500 mt-0.5"> <div class="text-[11px] text-slate-500 mt-0.5">
<i class="fa-solid fa-id-badge text-slate-400 mr-1 text-[11px]"></i>
{{ $t->transporter_driver_name ?: ($t->transporterDriver?->name ?? '-') }} {{ $t->transporter_driver_name ?: ($t->transporterDriver?->name ?? '-') }}
</div> </div>
</td> </td>
<!-- 7. Pelapor --> <!-- 6. Pelapor -->
<td class="py-3.5 px-3.5 whitespace-nowrap"> <td class="py-2.5 px-3.5 whitespace-nowrap">
<div class="font-bold text-slate-800"> <div class="font-bold text-slate-800 text-xs">
{{ $t->reported_by }} {{ $t->reported_by }}
</div> </div>
<div class="text-[10px] text-slate-400"> <div class="text-[10px] text-slate-400">
Petugas QMA QMA
</div> </div>
</td> </td>
<!-- 8. Aksi --> <!-- 7. Aksi -->
<td class="py-3.5 px-3.5 text-center whitespace-nowrap"> <td class="py-2.5 px-3.5 text-center whitespace-nowrap">
<div class="inline-flex items-center space-x-1.5"> <div class="inline-flex items-center space-x-1">
<!-- Tombol Lihat Detail BAST --> <!-- Tombol Lihat Detail BAST -->
<a href="{{ route('qma.unit_transfers.show', $t->id) }}" <a href="{{ route('qma.unit_transfers.show', $t->id) }}"
class="p-2 rounded-xl text-emerald-700 bg-emerald-50 hover:bg-emerald-100 border border-emerald-200/80 transition shadow-2xs" class="p-1.5 rounded-lg text-emerald-700 bg-emerald-50 hover:bg-emerald-100 border border-emerald-200/80 transition"
title="Lihat Berita Acara & Detail"> title="Lihat Berita Acara & Detail">
<i class="fa-solid fa-file-invoice text-xs"></i> <i class="fa-solid fa-file-invoice text-xs"></i>
</a> </a>
@@ -309,7 +300,7 @@
@can('qma.vehicles.delete') @can('qma.vehicles.delete')
<button type="button" <button type="button"
onclick="openDeleteModal('{{ $t->id }}', '{{ e($t->document_number) }}', '{{ e($t->vehicle?->code ?? 'Unit') }}')" onclick="openDeleteModal('{{ $t->id }}', '{{ e($t->document_number) }}', '{{ e($t->vehicle?->code ?? 'Unit') }}')"
class="p-2 rounded-xl text-rose-600 bg-rose-50 hover:bg-rose-100 border border-rose-200/80 transition shadow-2xs cursor-pointer" class="p-1.5 rounded-lg text-rose-600 bg-rose-50 hover:bg-rose-100 border border-rose-200/80 transition cursor-pointer"
title="Hapus Data Transfer"> title="Hapus Data Transfer">
<i class="fa-solid fa-trash text-xs"></i> <i class="fa-solid fa-trash text-xs"></i>
</button> </button>
@@ -319,12 +310,12 @@
</tr> </tr>
@empty @empty
<tr> <tr>
<td colspan="8" class="py-12 text-center text-slate-400"> <td colspan="7" class="py-12 text-center text-slate-400">
<div class="w-16 h-16 rounded-full bg-slate-100 flex items-center justify-center mx-auto mb-3 text-slate-400 text-2xl"> <div class="w-14 h-14 rounded-full bg-slate-100 flex items-center justify-center mx-auto mb-2 text-slate-400 text-xl">
<i class="fa-solid fa-truck-ramp-box"></i> <i class="fa-solid fa-truck-ramp-box"></i>
</div> </div>
<p class="text-sm font-bold text-slate-700">Belum Ada Data Pemindahan Unit</p> <p class="text-xs font-bold text-slate-700">Belum Ada Data Pemindahan Unit</p>
<p class="text-xs text-slate-400 mt-1 max-w-sm mx-auto"> <p class="text-[11px] text-slate-400 mt-0.5 max-w-sm mx-auto">
Belum ada transaksi pemindahan alat berat yang tercatat. Silakan klik tombol "Buat Transfer Unit" untuk membuat Berita Acara baru. Belum ada transaksi pemindahan alat berat yang tercatat. Silakan klik tombol "Buat Transfer Unit" untuk membuat Berita Acara baru.
</p> </p>
@canany(['qma.vehicles.create', 'qma.vehicles.edit']) @canany(['qma.vehicles.create', 'qma.vehicles.edit'])
+91
View File
@@ -190,4 +190,95 @@ class GateInspectionTest extends TestCase
'gate_id' => null, 'gate_id' => null,
]); ]);
} }
public function test_guard_can_reject_vehicle_activity_with_rejection_note(): void
{
$vehicle = Vehicle::create([
'code' => 'LV-REJECT-01',
'category' => 'light_vehicle',
'brand_type' => 'Mitsubishi Triton',
'current_km' => 2000,
]);
$driver = Employee::create([
'name' => 'Driver Mau Lewat',
'nik' => 'KMH-REJ-01',
]);
$activity = VehicleActivity::create([
'transaction_no' => 'TRX-REJ-001',
'vehicle_id' => $vehicle->id,
'driver_id' => $driver->id,
'gate_id' => $this->gate1->id,
'direction' => 'out',
'previous_km' => 2000,
'current_km' => 2050,
'distance' => 50,
'purpose' => 'Ambil Material Proyek',
'validation_status' => 'pending',
'recorded_at' => now(),
]);
$response = $this->actingAs($this->guardUser)
->post(route('pg.gate.reject', $activity->id), [
'security_guard_id' => $this->guard->id,
'rejection_note' => 'Masa berlaku SIMPER pengemudi telah kedaluwarsa (Expired)',
]);
$response->assertRedirect();
$response->assertSessionHas('success');
$activity->refresh();
$this->assertEquals('rejected', $activity->validation_status);
$this->assertEquals($this->guard->id, $activity->security_guard_id);
$this->assertEquals('Masa berlaku SIMPER pengemudi telah kedaluwarsa (Expired)', $activity->rejection_note);
$this->assertNotNull($activity->validated_at);
// Verifikasi tercatat di AdminActivityLog
$this->assertDatabaseHas('admin_activity_logs', [
'action_type' => 'reject',
'module' => 'pos_gerbang',
'target_type' => 'vehicle_activity',
'target_id' => $activity->id,
]);
}
public function test_cannot_reject_vehicle_activity_without_rejection_note(): void
{
$vehicle = Vehicle::create([
'code' => 'LV-REJECT-02',
'category' => 'light_vehicle',
'brand_type' => 'Toyota Hilux',
'current_km' => 1500,
]);
$driver = Employee::create([
'name' => 'Driver No Note',
'nik' => 'KMH-REJ-02',
]);
$activity = VehicleActivity::create([
'transaction_no' => 'TRX-REJ-002',
'vehicle_id' => $vehicle->id,
'driver_id' => $driver->id,
'gate_id' => $this->gate1->id,
'direction' => 'in',
'previous_km' => 1500,
'current_km' => 1520,
'distance' => 20,
'purpose' => 'Patroli',
'validation_status' => 'pending',
'recorded_at' => now(),
]);
$response = $this->actingAs($this->guardUser)
->post(route('pg.gate.reject', $activity->id), [
'security_guard_id' => $this->guard->id,
'rejection_note' => '',
]);
$response->assertSessionHasErrors('rejection_note');
$activity->refresh();
$this->assertEquals('pending', $activity->validation_status);
}
} }
@@ -430,4 +430,245 @@ class HseEmployeeFlexibleUnitKerjaAndModalTest extends TestCase
'position' => 'Anggota', 'position' => 'Anggota',
]); ]);
} }
public function test_unchecking_and_readding_simper_does_not_trigger_500_unique_constraint_violation(): void
{
$simperLv = \App\Models\SimperType::firstOrCreate(
['code' => 'SIMPER-LV'],
['name' => 'SIMPER Light Vehicle', 'category_scope' => 'light_vehicle', 'is_active' => true]
);
$simperDt = \App\Models\SimperType::firstOrCreate(
['code' => 'SIMPER-DT'],
['name' => 'SIMPER Dump Truck', 'category_scope' => 'unit_support_mobile', 'is_active' => true]
);
$employee = Employee::create([
'nik' => 'KMH-MULTI-SIMPER',
'name' => 'Driver Multi Izin',
'employee_type' => 'Karyawan',
'unit_kerja' => 'Umum',
'division' => 'Operasi',
'position' => 'Driver Tambang',
'is_operator' => true,
'simper_expired_at' => '2026-12-31',
]);
// 1. Tambah 2 SIMPER awal
\App\Models\EmployeeSimper::create([
'employee_id' => $employee->id,
'simper_type_id' => $simperLv->id,
'simper_number' => 'SMP-001-LV',
'expired_at' => '2026-12-31',
'status' => 'active',
]);
\App\Models\EmployeeSimper::create([
'employee_id' => $employee->id,
'simper_type_id' => $simperDt->id,
'simper_number' => 'SMP-001-DT',
'expired_at' => '2026-12-31',
'status' => 'active',
]);
// 2. Edit Karyawan: Hilangkan (uncheck) SIMPER-DT (hanya sisakan SIMPER-LV)
$responseUncheck = $this->actingAs($this->hseAdmin)
->post(route('hse.employees.update', $employee->id), [
'name' => 'Driver Multi Izin',
'is_operator' => '1',
'simper_assignments' => [
$simperLv->id => [
'enabled' => '1',
'simper_number' => 'SMP-001-LV',
'expired_at' => '2026-12-31',
],
$simperDt->id => [
// Unchecked: enabled tidak dikirim
'simper_number' => 'SMP-001-DT',
'expired_at' => '',
],
],
]);
$responseUncheck->assertSessionHasNoErrors();
$responseUncheck->assertRedirect();
// SIMPER-DT harus terhapus
$this->assertDatabaseMissing('employee_simpers', [
'employee_id' => $employee->id,
'simper_type_id' => $simperDt->id,
'deleted_at' => null,
]);
// 3. Edit Karyawan LAGI: Centang kembali (re-add) SIMPER-DT
// Ini adalah skenario yang sebelumnya memicu 500 Duplicate entry
$responseReadd = $this->actingAs($this->hseAdmin)
->post(route('hse.employees.update', $employee->id), [
'name' => 'Driver Multi Izin',
'is_operator' => '1',
'simper_assignments' => [
$simperLv->id => [
'enabled' => '1',
'simper_number' => 'SMP-001-LV',
'expired_at' => '2026-12-31',
],
$simperDt->id => [
'enabled' => '1',
'simper_number' => 'SMP-001-DT-RENEWED',
'expired_at' => '2027-06-30',
],
],
]);
$responseReadd->assertSessionHasNoErrors();
$responseReadd->assertRedirect();
// Verifikasi bahwa SIMPER-DT berhasil aktif kembali tanpa error 500
$this->assertDatabaseHas('employee_simpers', [
'employee_id' => $employee->id,
'simper_type_id' => $simperDt->id,
'simper_number' => 'SMP-001-DT-RENEWED',
'expired_at' => '2027-06-30 00:00:00',
'status' => 'active',
'deleted_at' => null,
]);
$employee->refresh();
$this->assertEquals('2027-06-30', $employee->simper_expired_at->format('Y-m-d'));
}
public function test_hse_can_renew_specific_simper_with_dropdown_selection(): void
{
$simperLv = \App\Models\SimperType::firstOrCreate(
['code' => 'SIMPER-LV'],
['name' => 'SIMPER Light Vehicle', 'category_scope' => 'light_vehicle', 'is_active' => true]
);
$simperDt = \App\Models\SimperType::firstOrCreate(
['code' => 'SIMPER-DT'],
['name' => 'SIMPER Dump Truck', 'category_scope' => 'unit_support_mobile', 'is_active' => true]
);
$employee = Employee::create([
'nik' => 'KMH-RENEW-TEST',
'name' => 'Operator Perpanjang',
'employee_type' => 'Karyawan',
'unit_kerja' => 'Operasi',
'division' => 'Operasi',
'position' => 'Driver',
'is_operator' => true,
'simper_expired_at' => '2026-10-01',
]);
\App\Models\EmployeeSimper::create([
'employee_id' => $employee->id,
'simper_type_id' => $simperLv->id,
'simper_number' => 'SMP-LV-01',
'expired_at' => '2026-10-01',
'status' => 'active',
]);
\App\Models\EmployeeSimper::create([
'employee_id' => $employee->id,
'simper_type_id' => $simperDt->id,
'simper_number' => 'SMP-DT-01',
'expired_at' => '2026-09-01',
'status' => 'active',
]);
// Perpanjang HANYA SIMPER-DT via modal dropdown (renew_simper_type_id = DT)
$response = $this->actingAs($this->hseAdmin)
->post(route('hse.employees.update', $employee->id), [
'is_operator' => '1',
'renew_simper_type_id' => (string) $simperDt->id,
'simper_expired_at' => '2027-12-31',
]);
$response->assertSessionHasNoErrors();
$response->assertRedirect();
// SIMPER-DT harus diperpanjang ke 2027-12-31
$this->assertDatabaseHas('employee_simpers', [
'employee_id' => $employee->id,
'simper_type_id' => $simperDt->id,
'expired_at' => '2027-12-31 00:00:00',
]);
// SIMPER-LV harus tetap 2026-10-01 (tidak berubah)
$this->assertDatabaseHas('employee_simpers', [
'employee_id' => $employee->id,
'simper_type_id' => $simperLv->id,
'expired_at' => '2026-10-01 00:00:00',
]);
// Max expired_at master employee harus ikut naik ke 2027-12-31
$employee->refresh();
$this->assertEquals('2027-12-31', $employee->simper_expired_at->format('Y-m-d'));
}
public function test_hse_can_renew_all_simpers_simultaneously(): void
{
$simperLv = \App\Models\SimperType::firstOrCreate(
['code' => 'SIMPER-LV'],
['name' => 'SIMPER Light Vehicle', 'category_scope' => 'light_vehicle', 'is_active' => true]
);
$simperDt = \App\Models\SimperType::firstOrCreate(
['code' => 'SIMPER-DT'],
['name' => 'SIMPER Dump Truck', 'category_scope' => 'unit_support_mobile', 'is_active' => true]
);
$employee = Employee::create([
'nik' => 'KMH-RENEW-ALL',
'name' => 'Operator All Renew',
'employee_type' => 'Karyawan',
'unit_kerja' => 'Operasi',
'division' => 'Operasi',
'position' => 'Driver',
'is_operator' => true,
'simper_expired_at' => '2026-05-01',
]);
\App\Models\EmployeeSimper::create([
'employee_id' => $employee->id,
'simper_type_id' => $simperLv->id,
'simper_number' => 'SMP-LV-02',
'expired_at' => '2026-05-01',
'status' => 'active',
]);
\App\Models\EmployeeSimper::create([
'employee_id' => $employee->id,
'simper_type_id' => $simperDt->id,
'simper_number' => 'SMP-DT-02',
'expired_at' => '2026-06-01',
'status' => 'active',
]);
// Perpanjang SEMUA SIMPER sekaligus (renew_simper_type_id = all)
$response = $this->actingAs($this->hseAdmin)
->post(route('hse.employees.update', $employee->id), [
'is_operator' => '1',
'renew_simper_type_id' => 'all',
'simper_expired_at' => '2028-01-01',
]);
$response->assertSessionHasNoErrors();
$response->assertRedirect();
// Keduanya harus naik ke 2028-01-01
$this->assertDatabaseHas('employee_simpers', [
'employee_id' => $employee->id,
'simper_type_id' => $simperLv->id,
'expired_at' => '2028-01-01 00:00:00',
]);
$this->assertDatabaseHas('employee_simpers', [
'employee_id' => $employee->id,
'simper_type_id' => $simperDt->id,
'expired_at' => '2028-01-01 00:00:00',
]);
$employee->refresh();
$this->assertEquals('2028-01-01', $employee->simper_expired_at->format('Y-m-d'));
}
} }