feat: support multiple vehicle category scopes selection in hse master simper types
This commit is contained in:
@@ -45,22 +45,31 @@ class SimperTypeController extends Controller
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$scopes = $this->resolveScopesInput($request);
|
||||
$request->merge(['category_scopes' => $scopes]);
|
||||
|
||||
$validScopes = array_keys(SimperType::getAvailableScopes());
|
||||
|
||||
$validated = $request->validate([
|
||||
'code' => ['required', 'string', 'max:50', 'unique:simper_types,code'],
|
||||
'name' => ['required', 'string', 'max:100'],
|
||||
'category_scope' => ['required', 'string', Rule::in($validScopes)],
|
||||
'category_scopes' => ['required', 'array', 'min:1'],
|
||||
'category_scopes.*' => ['required', 'string', Rule::in($validScopes)],
|
||||
'description' => ['nullable', 'string', 'max:500'],
|
||||
'is_active' => ['nullable', 'boolean'],
|
||||
], [
|
||||
'category_scopes.required' => 'Pilih minimal satu cakupan kategori kendaraan.',
|
||||
'category_scopes.min' => 'Pilih minimal satu cakupan kategori kendaraan.',
|
||||
]);
|
||||
|
||||
$code = strtoupper(trim($validated['code']));
|
||||
$finalScopes = $validated['category_scopes'];
|
||||
$storedScope = count($finalScopes) === 1 ? $finalScopes[0] : json_encode($finalScopes);
|
||||
|
||||
SimperType::create([
|
||||
'code' => $code,
|
||||
'name' => trim($validated['name']),
|
||||
'category_scope' => $validated['category_scope'],
|
||||
'category_scope' => $storedScope,
|
||||
'description' => $validated['description'] ?? null,
|
||||
'is_active' => $request->boolean('is_active', true),
|
||||
]);
|
||||
@@ -74,20 +83,31 @@ class SimperTypeController extends Controller
|
||||
public function update(Request $request, int $id): RedirectResponse
|
||||
{
|
||||
$simperType = SimperType::findOrFail($id);
|
||||
$scopes = $this->resolveScopesInput($request);
|
||||
$request->merge(['category_scopes' => $scopes]);
|
||||
|
||||
$validScopes = array_keys(SimperType::getAvailableScopes());
|
||||
|
||||
$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($validScopes)],
|
||||
'category_scopes' => ['required', 'array', 'min:1'],
|
||||
'category_scopes.*' => ['required', 'string', Rule::in($validScopes)],
|
||||
'description' => ['nullable', 'string', 'max:500'],
|
||||
'is_active' => ['nullable', 'boolean'],
|
||||
], [
|
||||
'category_scopes.required' => 'Pilih minimal satu cakupan kategori kendaraan.',
|
||||
'category_scopes.min' => 'Pilih minimal satu cakupan kategori kendaraan.',
|
||||
]);
|
||||
|
||||
$code = strtoupper(trim($validated['code']));
|
||||
$finalScopes = $validated['category_scopes'];
|
||||
$storedScope = count($finalScopes) === 1 ? $finalScopes[0] : json_encode($finalScopes);
|
||||
|
||||
$simperType->update([
|
||||
'code' => strtoupper(trim($validated['code'])),
|
||||
'code' => $code,
|
||||
'name' => trim($validated['name']),
|
||||
'category_scope' => $validated['category_scope'],
|
||||
'category_scope' => $storedScope,
|
||||
'description' => $validated['description'] ?? null,
|
||||
'is_active' => $request->boolean('is_active', true),
|
||||
]);
|
||||
@@ -95,6 +115,35 @@ class SimperTypeController extends Controller
|
||||
return back()->with('success', "Jenis SIMPER '{$simperType->name}' berhasil diperbarui.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper normalisasi input cakupan kategori kendaraan.
|
||||
* Mendukung multiple array (category_scopes[]) maupun legacy single string (category_scope).
|
||||
*
|
||||
* @return array<string>
|
||||
*/
|
||||
private function resolveScopesInput(Request $request): array
|
||||
{
|
||||
$raw = $request->input('category_scopes') ?? $request->input('category_scope');
|
||||
|
||||
if (is_string($raw)) {
|
||||
$trimmed = trim($raw);
|
||||
if (str_starts_with($trimmed, '[') && str_ends_with($trimmed, ']')) {
|
||||
$decoded = json_decode($trimmed, true);
|
||||
if (is_array($decoded)) {
|
||||
$raw = $decoded;
|
||||
} else {
|
||||
$raw = [$trimmed];
|
||||
}
|
||||
} else {
|
||||
$raw = [$trimmed];
|
||||
}
|
||||
} elseif (!is_array($raw)) {
|
||||
$raw = [];
|
||||
}
|
||||
|
||||
return array_values(array_filter(array_unique($raw)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Hapus jenis SIMPER.
|
||||
*/
|
||||
|
||||
@@ -116,7 +116,7 @@ class Employee extends Model
|
||||
{
|
||||
$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()) {
|
||||
if ($s->simperType && $s->simperType->coversScope($scope) && $s->isValid()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,6 +94,95 @@ class SimperType extends Model
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
|
||||
protected $appends = [
|
||||
'scopes',
|
||||
'category_scope_display',
|
||||
];
|
||||
|
||||
/**
|
||||
* Dapatkan seluruh cakupan kategori dalam bentuk array terurai.
|
||||
*
|
||||
* @return array<string>
|
||||
*/
|
||||
public function getScopesAttribute(): array
|
||||
{
|
||||
$raw = $this->category_scope;
|
||||
|
||||
if (empty($raw)) {
|
||||
return [self::SCOPE_ALL];
|
||||
}
|
||||
|
||||
if (is_array($raw)) {
|
||||
return array_values(array_unique($raw));
|
||||
}
|
||||
|
||||
if (is_string($raw)) {
|
||||
$trimmed = trim($raw);
|
||||
if (str_starts_with($trimmed, '[') && str_ends_with($trimmed, ']')) {
|
||||
$decoded = json_decode($trimmed, true);
|
||||
if (is_array($decoded)) {
|
||||
return array_values(array_unique($decoded));
|
||||
}
|
||||
}
|
||||
if (str_contains($trimmed, ',')) {
|
||||
return array_values(array_filter(array_map('trim', explode(',', $trimmed))));
|
||||
}
|
||||
return [$trimmed];
|
||||
}
|
||||
|
||||
return [(string) $raw];
|
||||
}
|
||||
|
||||
/**
|
||||
* Cek apakah jenis SIMPER ini mencakup scope target tertentu.
|
||||
*/
|
||||
public function coversScope(string $targetScope): bool
|
||||
{
|
||||
$scopes = $this->scopes;
|
||||
|
||||
// Universal scope mencakup semua kategori
|
||||
if (in_array(self::SCOPE_ALL, $scopes, true) || in_array('all', $scopes, true)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (in_array($targetScope, $scopes, true)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Bandingkan case-insensitive
|
||||
foreach ($scopes as $s) {
|
||||
if (strcasecmp($s, $targetScope) === 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Teks ringkas representasi cakupan kendaraan untuk badge UI.
|
||||
*/
|
||||
public function getCategoryScopeDisplayAttribute(): string
|
||||
{
|
||||
$scopes = $this->scopes;
|
||||
|
||||
if (empty($scopes) || in_array(self::SCOPE_ALL, $scopes, true)) {
|
||||
return 'Semua Kategori (Universal)';
|
||||
}
|
||||
|
||||
if (count($scopes) === 1 && $scopes[0] === self::SCOPE_LIGHT_VEHICLE) {
|
||||
return 'Light Vehicle (LV)';
|
||||
}
|
||||
|
||||
$formatted = array_map(function ($s) {
|
||||
if ($s === self::SCOPE_LIGHT_VEHICLE) return 'LV';
|
||||
if ($s === self::SCOPE_ALL) return 'Universal';
|
||||
return str_replace('_', ' ', $s);
|
||||
}, $scopes);
|
||||
|
||||
return implode(', ', $formatted);
|
||||
}
|
||||
|
||||
public function employeeSimpers(): HasMany
|
||||
{
|
||||
return $this->hasMany(EmployeeSimper::class);
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('simper_types', function (Blueprint $table) {
|
||||
try {
|
||||
$table->dropIndex('simper_types_category_scope_index');
|
||||
} catch (\Throwable $e) {
|
||||
// Ignore jika indeks tidak ada
|
||||
}
|
||||
$table->text('category_scope')->change();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('simper_types', function (Blueprint $table) {
|
||||
$table->string('category_scope', 50)->change();
|
||||
$table->index('category_scope');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -180,17 +180,17 @@
|
||||
</div>
|
||||
</label>
|
||||
|
||||
@if($st->category_scope === 'light_vehicle')
|
||||
<span class="text-[10px] font-mono px-2 py-0.5 rounded bg-blue-50 text-blue-700 font-bold border border-blue-200">
|
||||
LV
|
||||
</span>
|
||||
@elseif($st->category_scope === 'all')
|
||||
@if($st->coversScope('all'))
|
||||
<span class="text-[10px] font-mono px-2 py-0.5 rounded bg-purple-50 text-purple-700 font-bold border border-purple-200">
|
||||
SEMUA ARMADA
|
||||
</span>
|
||||
@elseif($st->scopes === ['light_vehicle'])
|
||||
<span class="text-[10px] font-mono px-2 py-0.5 rounded bg-blue-50 text-blue-700 font-bold border border-blue-200">
|
||||
LV
|
||||
</span>
|
||||
@else
|
||||
<span class="text-[10px] font-mono px-2 py-0.5 rounded bg-amber-50 text-amber-700 font-bold border border-amber-200">
|
||||
{{ strtoupper($st->category_scope) }}
|
||||
<span class="text-[10px] font-mono px-2 py-0.5 rounded bg-amber-50 text-amber-700 font-bold border border-amber-200 max-w-[200px] truncate" title="{{ $st->category_scope_display }}">
|
||||
{{ strtoupper($st->category_scope_display) }}
|
||||
</span>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
@@ -473,8 +473,8 @@
|
||||
class="w-4 h-4 rounded text-emerald-700 border-slate-300 focus:ring-emerald-500 flex-shrink-0">
|
||||
<span class="truncate">{{ $st->name }} ({{ $st->code }})</span>
|
||||
</label>
|
||||
<span class="text-[9px] font-mono px-2 py-0.5 rounded-md bg-slate-200 text-slate-700 font-bold uppercase flex-shrink-0">
|
||||
{{ str_replace('_', ' ', $st->category_scope) }}
|
||||
<span class="text-[9px] font-mono px-2 py-0.5 rounded-md bg-slate-200 text-slate-700 font-bold uppercase flex-shrink-0" title="{{ $st->category_scope_display }}">
|
||||
{{ $st->category_scope_display }}
|
||||
</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">
|
||||
@@ -802,8 +802,8 @@
|
||||
class="w-4 h-4 rounded text-emerald-700 border-slate-300 focus:ring-emerald-500 flex-shrink-0">
|
||||
<span class="truncate">{{ $st->name }} ({{ $st->code }})</span>
|
||||
</label>
|
||||
<span class="text-[9px] font-mono px-2 py-0.5 rounded-md bg-slate-200 text-slate-700 font-bold uppercase flex-shrink-0">
|
||||
{{ str_replace('_', ' ', $st->category_scope) }}
|
||||
<span class="text-[9px] font-mono px-2 py-0.5 rounded-md bg-slate-200 text-slate-700 font-bold uppercase flex-shrink-0" title="{{ $st->category_scope_display }}">
|
||||
{{ $st->category_scope_display }}
|
||||
</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">
|
||||
|
||||
@@ -146,19 +146,32 @@
|
||||
<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 === 'all')
|
||||
<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>
|
||||
@else
|
||||
<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> {{ str_replace('_', ' ', $st->category_scope) }}
|
||||
</span>
|
||||
@endif
|
||||
<div class="flex flex-wrap items-center gap-1 max-w-xs">
|
||||
@if($st->coversScope('all'))
|
||||
<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 (Universal)
|
||||
</span>
|
||||
@else
|
||||
@php $scopesList = $st->scopes; @endphp
|
||||
@foreach(array_slice($scopesList, 0, 3) as $scope)
|
||||
@if($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> LV
|
||||
</span>
|
||||
@else
|
||||
<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> {{ str_replace('_', ' ', $scope) }}
|
||||
</span>
|
||||
@endif
|
||||
@endforeach
|
||||
@if(count($scopesList) > 3)
|
||||
<span class="inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-bold bg-slate-100 text-slate-600 border border-slate-200"
|
||||
title="{{ implode(', ', array_slice($scopesList, 3)) }}">
|
||||
+{{ count($scopesList) - 3 }} lainnya
|
||||
</span>
|
||||
@endif
|
||||
@endif
|
||||
</div>
|
||||
</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">
|
||||
@@ -219,71 +232,140 @@
|
||||
<!-- 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 class="bg-white rounded-3xl shadow-2xl max-w-3xl w-full p-6 sm:p-7 border border-slate-100 flex flex-col max-h-[92vh] overflow-hidden animate-scale-in">
|
||||
<div class="flex items-center justify-between pb-4 border-b border-slate-100 flex-shrink-0">
|
||||
<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>
|
||||
<p class="text-xs text-slate-500 mt-0.5">Definisikan kategori izin mengemudi dan pilih satu atau lebih cakupan armada.</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">
|
||||
<form action="{{ route('hse.simper_types.store') }}" method="POST" class="flex flex-col flex-1 min-h-0 mt-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 class="overflow-y-auto flex-1 pr-1 pb-2 space-y-4">
|
||||
<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-HAULING"
|
||||
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">Nama Jenis SIMPER <span class="text-rose-500">*</span></label>
|
||||
<input type="text" name="name" required placeholder="Contoh: SIMPER Angkutan Berat & Material"
|
||||
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>
|
||||
|
||||
<!-- Cakupan Kendaraan (Multiple Choice Selection) -->
|
||||
<div class="space-y-2">
|
||||
<div class="flex flex-col sm:flex-row sm:items-center justify-between gap-2 pb-1">
|
||||
<div>
|
||||
<label class="block text-xs font-bold text-slate-800">
|
||||
Cakupan Armada yang Diizinkan <span class="text-rose-500">*</span>
|
||||
</label>
|
||||
<p class="text-[11px] text-slate-500">Centang satu atau lebih jenis armada yang dapat dioperasikan pemegang SIMPER ini.</p>
|
||||
</div>
|
||||
<div class="flex items-center space-x-2">
|
||||
<span id="addScopeSelectedCount" class="text-[11px] font-mono font-bold px-2.5 py-1 rounded-lg bg-emerald-50 text-emerald-800 border border-emerald-200">
|
||||
0 Kategori Dipilih
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Toolbar Filter & Quick Actions -->
|
||||
<div class="flex items-center gap-2">
|
||||
<div class="relative flex-1">
|
||||
<i class="fa-solid fa-magnifying-glass absolute left-3 top-2.5 text-slate-400 text-xs"></i>
|
||||
<input type="text" placeholder="Cari kategori unit (contoh: Dump Truck, Excavator)..."
|
||||
oninput="filterScopeOptions(this.value, 'add')"
|
||||
class="w-full text-xs pl-8 pr-3 py-1.5 rounded-xl border border-slate-200 bg-white text-slate-800 focus:outline-none focus:border-emerald-600">
|
||||
</div>
|
||||
<button type="button" onclick="selectAllHeavyScopes('add')"
|
||||
class="px-2.5 py-1.5 rounded-xl bg-slate-100 hover:bg-slate-200 text-slate-700 text-[11px] font-bold transition whitespace-nowrap">
|
||||
Pilih Semua Alat Berat
|
||||
</button>
|
||||
<button type="button" onclick="clearAllScopes('add')"
|
||||
class="px-2.5 py-1.5 rounded-xl bg-slate-100 hover:bg-slate-200 text-slate-500 text-[11px] font-bold transition">
|
||||
Reset
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Scrollable Checkbox Grid -->
|
||||
<div class="max-h-56 overflow-y-auto pr-1 space-y-3 p-3 rounded-2xl border border-slate-200 bg-slate-50/70">
|
||||
<!-- Pilihan Umum -->
|
||||
<div>
|
||||
<span class="text-[10px] font-extrabold uppercase tracking-wider text-slate-400 block mb-1.5">
|
||||
Kategori Umum
|
||||
</span>
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 gap-2">
|
||||
<label class="add-scope-item flex items-center space-x-2.5 p-2.5 rounded-xl border border-purple-200 bg-purple-50/40 hover:bg-purple-100/60 transition cursor-pointer text-xs" data-name="semua kategori universal all">
|
||||
<input type="checkbox" name="category_scopes[]" value="all" onchange="updateScopeCount('add')" class="add-scope-cb w-4 h-4 rounded text-purple-700 border-purple-300 focus:ring-purple-500 flex-shrink-0">
|
||||
<div>
|
||||
<span class="font-extrabold text-purple-900 block text-xs">Semua Kategori (Universal)</span>
|
||||
<span class="text-[10px] text-purple-600">Mencakup semua armada LV dan Heavy Equipment</span>
|
||||
</div>
|
||||
</label>
|
||||
<label class="add-scope-item flex items-center space-x-2.5 p-2.5 rounded-xl border border-blue-200 bg-blue-50/40 hover:bg-blue-100/60 transition cursor-pointer text-xs" data-name="light vehicle lv mobil operasional">
|
||||
<input type="checkbox" name="category_scopes[]" value="light_vehicle" onchange="updateScopeCount('add')" class="add-scope-cb w-4 h-4 rounded text-blue-700 border-blue-300 focus:ring-blue-500 flex-shrink-0">
|
||||
<div>
|
||||
<span class="font-extrabold text-blue-900 block text-xs">Light Vehicle (LV)</span>
|
||||
<span class="text-[10px] text-blue-600">Khusus kendaraan operasional ringan proyek</span>
|
||||
</div>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Pilihan Heavy Equipment -->
|
||||
@php
|
||||
$generalKeys = ['all', 'light_vehicle'];
|
||||
$heavyScopes = array_diff_key($categoryScopes, array_flip($generalKeys));
|
||||
@endphp
|
||||
<div>
|
||||
<span class="text-[10px] font-extrabold uppercase tracking-wider text-slate-400 block mb-1.5">
|
||||
Kategori Heavy Equipment (Alat Berat)
|
||||
</span>
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-2">
|
||||
@foreach($heavyScopes as $scopeKey => $scopeLabel)
|
||||
<label data-name="{{ strtolower($scopeKey . ' ' . $scopeLabel) }}"
|
||||
class="add-scope-item flex items-center space-x-2 p-2 rounded-xl border border-slate-200 bg-white hover:bg-emerald-50/70 hover:border-emerald-300 transition cursor-pointer text-xs">
|
||||
<input type="checkbox"
|
||||
name="category_scopes[]"
|
||||
value="{{ $scopeKey }}"
|
||||
onchange="updateScopeCount('add')"
|
||||
class="add-scope-cb add-scope-heavy-cb w-4 h-4 rounded text-[#1b5e20] border-slate-300 focus:ring-emerald-500 flex-shrink-0">
|
||||
<span class="font-bold text-slate-800 text-[11px] truncate" title="{{ $scopeKey }}">
|
||||
{{ str_replace('Heavy: ', '', $scopeLabel) }}
|
||||
</span>
|
||||
</label>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</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">
|
||||
<optgroup label="Kategori Umum">
|
||||
<option value="all">Semua Kategori (Universal)</option>
|
||||
<option value="light_vehicle">Light Vehicle (LV)</option>
|
||||
</optgroup>
|
||||
@if(isset($heavyCategories) && count($heavyCategories) > 0)
|
||||
<optgroup label="Kategori Heavy Equipment (Sinkronisasi QMA)">
|
||||
@foreach($heavyCategories as $cat)
|
||||
@php $key = $cat->unit_category ?: $cat->brand_type; @endphp
|
||||
@if($key)
|
||||
<option value="{{ $key }}">{{ $cat->brand_type ?: $key }} ({{ $cat->code }})</option>
|
||||
@endif
|
||||
@endforeach
|
||||
</optgroup>
|
||||
@endif
|
||||
</select>
|
||||
<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>
|
||||
|
||||
<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">
|
||||
<div class="pt-4 border-t border-slate-100 flex items-center justify-end gap-2.5 flex-shrink-0">
|
||||
<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>
|
||||
@@ -299,8 +381,8 @@
|
||||
<!-- 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 class="bg-white rounded-3xl shadow-2xl max-w-3xl w-full p-6 sm:p-7 border border-slate-100 flex flex-col max-h-[92vh] overflow-hidden animate-scale-in">
|
||||
<div class="flex items-center justify-between pb-4 border-b border-slate-100 flex-shrink-0">
|
||||
<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>
|
||||
@@ -313,62 +395,123 @@
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<form id="editSimperTypeForm" action="" method="POST" class="mt-4 space-y-4">
|
||||
<form id="editSimperTypeForm" action="" method="POST" class="flex flex-col flex-1 min-h-0 mt-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 class="overflow-y-auto flex-1 pr-1 pb-2 space-y-4">
|
||||
<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">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>
|
||||
|
||||
<!-- Cakupan Kendaraan (Multiple Choice Selection) -->
|
||||
<div class="space-y-2">
|
||||
<div class="flex flex-col sm:flex-row sm:items-center justify-between gap-2 pb-1">
|
||||
<div>
|
||||
<label class="block text-xs font-bold text-slate-800">
|
||||
Cakupan Armada yang Diizinkan <span class="text-rose-500">*</span>
|
||||
</label>
|
||||
<p class="text-[11px] text-slate-500">Centang satu atau lebih jenis armada yang dapat dioperasikan pemegang SIMPER ini.</p>
|
||||
</div>
|
||||
<div class="flex items-center space-x-2">
|
||||
<span id="editScopeSelectedCount" class="text-[11px] font-mono font-bold px-2.5 py-1 rounded-lg bg-amber-50 text-amber-800 border border-amber-200">
|
||||
0 Kategori Dipilih
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Toolbar Filter & Quick Actions -->
|
||||
<div class="flex items-center gap-2">
|
||||
<div class="relative flex-1">
|
||||
<i class="fa-solid fa-magnifying-glass absolute left-3 top-2.5 text-slate-400 text-xs"></i>
|
||||
<input type="text" placeholder="Cari kategori unit (contoh: Dump Truck, Excavator)..."
|
||||
oninput="filterScopeOptions(this.value, 'edit')"
|
||||
class="w-full text-xs pl-8 pr-3 py-1.5 rounded-xl border border-slate-200 bg-white text-slate-800 focus:outline-none focus:border-amber-600">
|
||||
</div>
|
||||
<button type="button" onclick="selectAllHeavyScopes('edit')"
|
||||
class="px-2.5 py-1.5 rounded-xl bg-slate-100 hover:bg-slate-200 text-slate-700 text-[11px] font-bold transition whitespace-nowrap">
|
||||
Pilih Semua Alat Berat
|
||||
</button>
|
||||
<button type="button" onclick="clearAllScopes('edit')"
|
||||
class="px-2.5 py-1.5 rounded-xl bg-slate-100 hover:bg-slate-200 text-slate-500 text-[11px] font-bold transition">
|
||||
Reset
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Scrollable Checkbox Grid -->
|
||||
<div class="max-h-56 overflow-y-auto pr-1 space-y-3 p-3 rounded-2xl border border-slate-200 bg-slate-50/70">
|
||||
<!-- Pilihan Umum -->
|
||||
<div>
|
||||
<span class="text-[10px] font-extrabold uppercase tracking-wider text-slate-400 block mb-1.5">
|
||||
Kategori Umum
|
||||
</span>
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 gap-2">
|
||||
<label class="edit-scope-item flex items-center space-x-2.5 p-2.5 rounded-xl border border-purple-200 bg-purple-50/40 hover:bg-purple-100/60 transition cursor-pointer text-xs" data-name="semua kategori universal all">
|
||||
<input type="checkbox" name="category_scopes[]" value="all" onchange="updateScopeCount('edit')" class="edit-scope-cb w-4 h-4 rounded text-purple-700 border-purple-300 focus:ring-purple-500 flex-shrink-0">
|
||||
<div>
|
||||
<span class="font-extrabold text-purple-900 block text-xs">Semua Kategori (Universal)</span>
|
||||
<span class="text-[10px] text-purple-600">Mencakup semua armada LV dan Heavy Equipment</span>
|
||||
</div>
|
||||
</label>
|
||||
<label class="edit-scope-item flex items-center space-x-2.5 p-2.5 rounded-xl border border-blue-200 bg-blue-50/40 hover:bg-blue-100/60 transition cursor-pointer text-xs" data-name="light vehicle lv mobil operasional">
|
||||
<input type="checkbox" name="category_scopes[]" value="light_vehicle" onchange="updateScopeCount('edit')" class="edit-scope-cb w-4 h-4 rounded text-blue-700 border-blue-300 focus:ring-blue-500 flex-shrink-0">
|
||||
<div>
|
||||
<span class="font-extrabold text-blue-900 block text-xs">Light Vehicle (LV)</span>
|
||||
<span class="text-[10px] text-blue-600">Khusus kendaraan operasional ringan proyek</span>
|
||||
</div>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Pilihan Heavy Equipment -->
|
||||
<div>
|
||||
<span class="text-[10px] font-extrabold uppercase tracking-wider text-slate-400 block mb-1.5">
|
||||
Kategori Heavy Equipment (Alat Berat)
|
||||
</span>
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-2">
|
||||
@foreach($heavyScopes as $scopeKey => $scopeLabel)
|
||||
<label data-name="{{ strtolower($scopeKey . ' ' . $scopeLabel) }}"
|
||||
class="edit-scope-item flex items-center space-x-2 p-2 rounded-xl border border-slate-200 bg-white hover:bg-emerald-50/70 hover:border-emerald-300 transition cursor-pointer text-xs">
|
||||
<input type="checkbox"
|
||||
name="category_scopes[]"
|
||||
value="{{ $scopeKey }}"
|
||||
onchange="updateScopeCount('edit')"
|
||||
class="edit-scope-cb edit-scope-heavy-cb w-4 h-4 rounded text-emerald-700 border-slate-300 focus:ring-emerald-500 flex-shrink-0">
|
||||
<span class="font-bold text-slate-800 text-[11px] truncate" title="{{ $scopeKey }}">
|
||||
{{ str_replace('Heavy: ', '', $scopeLabel) }}
|
||||
</span>
|
||||
</label>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</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">
|
||||
<optgroup label="Kategori Umum">
|
||||
<option value="all">Semua Kategori (Universal)</option>
|
||||
<option value="light_vehicle">Light Vehicle (LV)</option>
|
||||
</optgroup>
|
||||
@if(isset($heavyCategories) && count($heavyCategories) > 0)
|
||||
<optgroup label="Kategori Heavy Equipment (Sinkronisasi QMA)">
|
||||
@foreach($heavyCategories as $cat)
|
||||
@php $key = $cat->unit_category ?: $cat->brand_type; @endphp
|
||||
@if($key)
|
||||
<option value="{{ $key }}">{{ $cat->brand_type ?: $key }} ({{ $cat->code }})</option>
|
||||
@endif
|
||||
@endforeach
|
||||
</optgroup>
|
||||
@endif
|
||||
<optgroup label="Cakupan Khusus / Legacy">
|
||||
<option value="unit_support_mobile">Heavy Mobile / Dump Truck (Legacy)</option>
|
||||
<option value="unit_support_heavy">Alat Berat Operasional (Legacy)</option>
|
||||
</optgroup>
|
||||
</select>
|
||||
<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>
|
||||
|
||||
<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">
|
||||
<div class="pt-4 border-t border-slate-100 flex items-center justify-end gap-2.5 flex-shrink-0">
|
||||
<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>
|
||||
@@ -466,10 +609,50 @@
|
||||
|
||||
@section('scripts')
|
||||
<script>
|
||||
function updateScopeCount(prefix) {
|
||||
const checked = document.querySelectorAll(`.${prefix}-scope-cb:checked`);
|
||||
const badge = document.getElementById(`${prefix}ScopeSelectedCount`);
|
||||
if (badge) {
|
||||
badge.textContent = `${checked.length} Kategori Dipilih`;
|
||||
}
|
||||
}
|
||||
|
||||
function selectAllHeavyScopes(prefix) {
|
||||
document.querySelectorAll(`.${prefix}-scope-heavy-cb`).forEach(cb => {
|
||||
cb.checked = true;
|
||||
});
|
||||
updateScopeCount(prefix);
|
||||
}
|
||||
|
||||
function clearAllScopes(prefix) {
|
||||
document.querySelectorAll(`.${prefix}-scope-cb`).forEach(cb => {
|
||||
cb.checked = false;
|
||||
});
|
||||
updateScopeCount(prefix);
|
||||
}
|
||||
|
||||
function filterScopeOptions(keyword, prefix) {
|
||||
const q = (keyword || '').toLowerCase().trim();
|
||||
document.querySelectorAll(`.${prefix}-scope-item`).forEach(el => {
|
||||
const text = (el.dataset.name || el.textContent || '').toLowerCase();
|
||||
if (!q || text.includes(q)) {
|
||||
el.classList.remove('hidden');
|
||||
} else {
|
||||
el.classList.add('hidden');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function openAddSimperTypeModal() {
|
||||
document.querySelectorAll('.add-scope-cb').forEach(cb => {
|
||||
cb.checked = (cb.value === 'all');
|
||||
});
|
||||
updateScopeCount('add');
|
||||
|
||||
const modal = document.getElementById('addSimperTypeModal');
|
||||
if (modal) modal.classList.remove('hidden');
|
||||
}
|
||||
|
||||
function closeAddSimperTypeModal() {
|
||||
const modal = document.getElementById('addSimperTypeModal');
|
||||
if (modal) modal.classList.add('hidden');
|
||||
@@ -478,16 +661,33 @@
|
||||
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);
|
||||
|
||||
let targetScopes = [];
|
||||
if (Array.isArray(st.scopes)) {
|
||||
targetScopes = st.scopes;
|
||||
} else if (typeof st.category_scope === 'string') {
|
||||
try {
|
||||
const parsed = JSON.parse(st.category_scope);
|
||||
targetScopes = Array.isArray(parsed) ? parsed : [st.category_scope];
|
||||
} catch(e) {
|
||||
targetScopes = [st.category_scope];
|
||||
}
|
||||
}
|
||||
|
||||
document.querySelectorAll('.edit-scope-cb').forEach(cb => {
|
||||
cb.checked = targetScopes.includes(cb.value);
|
||||
});
|
||||
updateScopeCount('edit');
|
||||
|
||||
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');
|
||||
@@ -501,6 +701,7 @@
|
||||
const modal = document.getElementById('deleteSimperTypeModal');
|
||||
if (modal) modal.classList.remove('hidden');
|
||||
}
|
||||
|
||||
function closeDeleteSimperTypeModal() {
|
||||
const modal = document.getElementById('deleteSimperTypeModal');
|
||||
if (modal) modal.classList.add('hidden');
|
||||
@@ -510,6 +711,7 @@
|
||||
const modal = document.getElementById('simperTypeGuideModal');
|
||||
if (modal) modal.classList.remove('hidden');
|
||||
}
|
||||
|
||||
function closeSimperTypeGuideModal() {
|
||||
const modal = document.getElementById('simperTypeGuideModal');
|
||||
if (modal) modal.classList.add('hidden');
|
||||
|
||||
@@ -238,4 +238,96 @@ class HseSimperTypeTest extends TestCase
|
||||
'category_scope' => 'Excavator',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin HSE dapat membuat jenis SIMPER dengan pilihan multiple kategori kendaraan (multiple choice).
|
||||
*/
|
||||
public function test_admin_hse_can_create_simper_with_multiple_category_scopes(): void
|
||||
{
|
||||
$data = [
|
||||
'code' => 'SIMPER-HAUL-HEAVY',
|
||||
'name' => 'SIMPER Alat Angkut & Gali',
|
||||
'category_scopes' => [
|
||||
'Dump Truck',
|
||||
'Excavator',
|
||||
'Wheel Loader',
|
||||
],
|
||||
'description' => 'Izin mengoperasikan unit angkut dan galian material.',
|
||||
'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');
|
||||
|
||||
$created = SimperType::where('code', 'SIMPER-HAUL-HEAVY')->first();
|
||||
$this->assertNotNull($created);
|
||||
$this->assertCount(3, $created->scopes);
|
||||
$this->assertTrue($created->coversScope('Dump Truck'));
|
||||
$this->assertTrue($created->coversScope('Excavator'));
|
||||
$this->assertTrue($created->coversScope('Wheel Loader'));
|
||||
$this->assertFalse($created->coversScope('Forklift'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Personil pemegang SIMPER multiple category diizinkan mengoperasikan armada yang tercakup.
|
||||
*/
|
||||
public function test_employee_holding_multiple_scope_simper_is_authorized_on_any_covered_category(): void
|
||||
{
|
||||
$simperType = SimperType::create([
|
||||
'code' => 'SIMPER-MULTIPLE-01',
|
||||
'name' => 'SIMPER Galian & Dorong',
|
||||
'category_scope' => json_encode(['Excavator', 'Wheel Loader']),
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
$employee = Employee::create([
|
||||
'nik' => 'OPR-MULTI-01',
|
||||
'name' => 'Operator Multi Alat',
|
||||
'is_operator' => true,
|
||||
'simper_expired_at' => Carbon::now()->addYear(),
|
||||
]);
|
||||
|
||||
EmployeeSimper::create([
|
||||
'employee_id' => $employee->id,
|
||||
'simper_type_id' => $simperType->id,
|
||||
'simper_number' => 'SMP-MULTI-01',
|
||||
'expired_at' => Carbon::now()->addYear(),
|
||||
'status' => 'active',
|
||||
]);
|
||||
|
||||
$vehicleExcavator = \App\Models\Vehicle::create([
|
||||
'code' => 'EX-8881',
|
||||
'brand_type' => 'Komatsu PC200',
|
||||
'category' => 'unit_support',
|
||||
'unit_category' => 'Excavator',
|
||||
'ownership' => 'Perusahaan',
|
||||
'status' => 'Operasional',
|
||||
]);
|
||||
|
||||
$vehicleLoader = \App\Models\Vehicle::create([
|
||||
'code' => 'WL-8882',
|
||||
'brand_type' => 'CAT 950H',
|
||||
'category' => 'unit_support',
|
||||
'unit_category' => 'Wheel Loader',
|
||||
'ownership' => 'Perusahaan',
|
||||
'status' => 'Operasional',
|
||||
]);
|
||||
|
||||
$vehicleForklift = \App\Models\Vehicle::create([
|
||||
'code' => 'FL-8883',
|
||||
'brand_type' => 'Toyota 5 Ton',
|
||||
'category' => 'unit_support',
|
||||
'unit_category' => 'Forklift',
|
||||
'ownership' => 'Perusahaan',
|
||||
'status' => 'Operasional',
|
||||
]);
|
||||
|
||||
$this->assertTrue($employee->hasValidSimperForVehicle($vehicleExcavator));
|
||||
$this->assertTrue($employee->hasValidSimperForVehicle($vehicleLoader));
|
||||
$this->assertFalse($employee->hasValidSimperForVehicle($vehicleForklift));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user