feat(admin): sync flexible unit kerja, employee type, and static backdrops with super admin user management
This commit is contained in:
@@ -60,7 +60,11 @@ class UserController extends Controller
|
|||||||
$gates = Gate::where('is_active', true)->orderBy('name')->get();
|
$gates = Gate::where('is_active', true)->orderBy('name')->get();
|
||||||
$modules = config('rbac_permissions.modules', []);
|
$modules = config('rbac_permissions.modules', []);
|
||||||
|
|
||||||
return view('admin.users.index', compact('users', 'roles', 'gates', 'modules', 'rolePermissionsMap'));
|
$distinctUnits = Employee::query()->whereNotNull('unit_kerja')->where('unit_kerja', '!=', '')->distinct()->pluck('unit_kerja')->toArray();
|
||||||
|
$defaultUnits = ['Pembangkit', 'Bendungan', 'Teknik', 'Umum', 'Logistik', 'HSE', 'QMA'];
|
||||||
|
$unitKerjaList = array_values(array_unique(array_filter(array_merge($defaultUnits, $distinctUnits))));
|
||||||
|
|
||||||
|
return view('admin.users.index', compact('users', 'roles', 'gates', 'modules', 'rolePermissionsMap', 'unitKerjaList'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -76,6 +80,7 @@ class UserController extends Controller
|
|||||||
'role' => ['required', 'string', 'exists:roles,name'],
|
'role' => ['required', 'string', 'exists:roles,name'],
|
||||||
'gate_id' => ['nullable', 'exists:gates,id'],
|
'gate_id' => ['nullable', 'exists:gates,id'],
|
||||||
'photo' => ['nullable', 'image', 'mimes:jpeg,png,jpg,webp', 'max:10240'],
|
'photo' => ['nullable', 'image', 'mimes:jpeg,png,jpg,webp', 'max:10240'],
|
||||||
|
'employee_type' => ['nullable', 'string', 'in:karyawan,sukon,Karyawan,Sukon'],
|
||||||
'unit_kerja' => ['nullable', 'string', 'max:100'],
|
'unit_kerja' => ['nullable', 'string', 'max:100'],
|
||||||
'division' => ['nullable', 'string', 'max:100'],
|
'division' => ['nullable', 'string', 'max:100'],
|
||||||
'position' => ['nullable', 'string', 'max:100'],
|
'position' => ['nullable', 'string', 'max:100'],
|
||||||
@@ -134,6 +139,7 @@ class UserController extends Controller
|
|||||||
'user_id' => $user->id,
|
'user_id' => $user->id,
|
||||||
'nik' => $user->username,
|
'nik' => $user->username,
|
||||||
'name' => $user->name,
|
'name' => $user->name,
|
||||||
|
'employee_type' => !empty($validated['employee_type']) ? ucfirst(strtolower($validated['employee_type'])) : ($emp?->employee_type ?? 'Karyawan'),
|
||||||
'unit_kerja' => $validated['unit_kerja'] ?? ($emp?->unit_kerja ?? 'Umum'),
|
'unit_kerja' => $validated['unit_kerja'] ?? ($emp?->unit_kerja ?? 'Umum'),
|
||||||
'division' => $validated['division'] ?? ($emp?->division ?? '-'),
|
'division' => $validated['division'] ?? ($emp?->division ?? '-'),
|
||||||
'position' => $validated['position'] ?? ($emp?->position ?? ($isEmployeeRole ? 'Driver Operasional' : '-')),
|
'position' => $validated['position'] ?? ($emp?->position ?? ($isEmployeeRole ? 'Driver Operasional' : '-')),
|
||||||
@@ -184,6 +190,7 @@ class UserController extends Controller
|
|||||||
'role' => ['required', 'string', 'exists:roles,name'],
|
'role' => ['required', 'string', 'exists:roles,name'],
|
||||||
'gate_id' => ['nullable', 'exists:gates,id'],
|
'gate_id' => ['nullable', 'exists:gates,id'],
|
||||||
'photo' => ['nullable', 'image', 'mimes:jpeg,png,jpg,webp', 'max:10240'],
|
'photo' => ['nullable', 'image', 'mimes:jpeg,png,jpg,webp', 'max:10240'],
|
||||||
|
'employee_type' => ['nullable', 'string', 'in:karyawan,sukon,Karyawan,Sukon'],
|
||||||
'unit_kerja' => ['nullable', 'string', 'max:100'],
|
'unit_kerja' => ['nullable', 'string', 'max:100'],
|
||||||
'division' => ['nullable', 'string', 'max:100'],
|
'division' => ['nullable', 'string', 'max:100'],
|
||||||
'position' => ['nullable', 'string', 'max:100'],
|
'position' => ['nullable', 'string', 'max:100'],
|
||||||
@@ -249,6 +256,9 @@ class UserController extends Controller
|
|||||||
'nik' => $user->username,
|
'nik' => $user->username,
|
||||||
'photo_path' => $user->photo_path ?: $emp?->photo_path,
|
'photo_path' => $user->photo_path ?: $emp?->photo_path,
|
||||||
];
|
];
|
||||||
|
if (array_key_exists('employee_type', $validated) && $validated['employee_type'] !== null) {
|
||||||
|
$empData['employee_type'] = ucfirst(strtolower($validated['employee_type']));
|
||||||
|
}
|
||||||
if (array_key_exists('unit_kerja', $validated) && $validated['unit_kerja'] !== null) {
|
if (array_key_exists('unit_kerja', $validated) && $validated['unit_kerja'] !== null) {
|
||||||
$empData['unit_kerja'] = $validated['unit_kerja'];
|
$empData['unit_kerja'] = $validated['unit_kerja'];
|
||||||
}
|
}
|
||||||
@@ -269,6 +279,7 @@ class UserController extends Controller
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$empData['user_id'] = $user->id;
|
$empData['user_id'] = $user->id;
|
||||||
|
$empData['employee_type'] = $empData['employee_type'] ?? 'Karyawan';
|
||||||
$empData['unit_kerja'] = $empData['unit_kerja'] ?? 'Umum';
|
$empData['unit_kerja'] = $empData['unit_kerja'] ?? 'Umum';
|
||||||
$empData['division'] = $empData['division'] ?? '-';
|
$empData['division'] = $empData['division'] ?? '-';
|
||||||
$empData['position'] = $empData['position'] ?? ($isEmployeeRole ? 'Driver Operasional' : '-');
|
$empData['position'] = $empData['position'] ?? ($isEmployeeRole ? 'Driver Operasional' : '-');
|
||||||
|
|||||||
@@ -737,10 +737,18 @@ class EmployeeController extends Controller
|
|||||||
if (!$employee->user_id) {
|
if (!$employee->user_id) {
|
||||||
$employee->update(['user_id' => $linkedUser->id]);
|
$employee->update(['user_id' => $linkedUser->id]);
|
||||||
}
|
}
|
||||||
$linkedUser->update([
|
$userData = [
|
||||||
'name' => $employee->name,
|
'name' => $employee->name,
|
||||||
|
'username' => $employee->nik,
|
||||||
'photo_path' => $photoPath,
|
'photo_path' => $photoPath,
|
||||||
]);
|
];
|
||||||
|
if (str_ends_with($linkedUser->email, '@kmh.co.id')) {
|
||||||
|
$newCleanEmail = strtolower(str_replace(['-', ' '], '', $employee->nik)) . '@kmh.co.id';
|
||||||
|
if (!User::where('email', $newCleanEmail)->where('id', '!=', $linkedUser->id)->exists()) {
|
||||||
|
$userData['email'] = $newCleanEmail;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$linkedUser->update($userData);
|
||||||
}
|
}
|
||||||
|
|
||||||
return back()->with('success', "Data SIMPER untuk {$employee->name} berhasil diperbarui.");
|
return back()->with('success', "Data SIMPER untuk {$employee->name} berhasil diperbarui.");
|
||||||
|
|||||||
@@ -25,10 +25,13 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
|
|
||||||
// Super Admin bypass: secara otomatis memiliki izin untuk semua ability
|
// Super Admin bypass: secara otomatis memiliki izin untuk semua ability
|
||||||
Gate::before(function ($user, $ability) {
|
Gate::before(function ($user, $ability) {
|
||||||
if ($user->role === 'super_admin' || $user->role === 'admin') {
|
if (in_array($user->role, ['super_admin', 'superadmin', 'admin'])) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
if (method_exists($user, 'isSuperAdmin') && $user->isSuperAdmin()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return $user->hasRole('super_admin') ? true : null;
|
return $user->hasRole('super_admin') ? true : null;
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -290,7 +290,7 @@
|
|||||||
<!-- ========================================================================= -->
|
<!-- ========================================================================= -->
|
||||||
<!-- MODAL: TAMBAH PENGGUNA BARU -->
|
<!-- MODAL: TAMBAH PENGGUNA BARU -->
|
||||||
<!-- ========================================================================= -->
|
<!-- ========================================================================= -->
|
||||||
<div id="createUserModal" class="fixed inset-0 z-50 hidden overflow-y-auto bg-slate-900/60 backdrop-blur-sm flex items-center justify-center p-4">
|
<div id="createUserModal" data-backdrop="static" class="fixed inset-0 z-50 hidden overflow-y-auto bg-slate-900/60 backdrop-blur-sm flex items-center justify-center p-4">
|
||||||
<div class="bg-white rounded-2xl max-w-lg w-full shadow-2xl overflow-hidden animate-scale-in">
|
<div class="bg-white rounded-2xl max-w-lg w-full shadow-2xl overflow-hidden animate-scale-in">
|
||||||
<div class="px-6 py-4 border-b border-slate-100 flex items-center justify-between">
|
<div class="px-6 py-4 border-b border-slate-100 flex items-center justify-between">
|
||||||
<h3 class="text-sm font-bold text-slate-800 flex items-center gap-2">
|
<h3 class="text-sm font-bold text-slate-800 flex items-center gap-2">
|
||||||
@@ -368,29 +368,33 @@
|
|||||||
|
|
||||||
<div class="grid grid-cols-2 gap-3">
|
<div class="grid grid-cols-2 gap-3">
|
||||||
<div>
|
<div>
|
||||||
<label class="block text-[11px] font-semibold text-slate-600 mb-1">Unit Kerja</label>
|
<label class="block text-[11px] font-semibold text-slate-600 mb-1">Jenis Personil</label>
|
||||||
<select name="unit_kerja" class="w-full px-3 py-2 bg-slate-50 border border-slate-200 rounded-xl text-xs focus:ring-2 focus:ring-indigo-500 focus:bg-white text-slate-700">
|
<select name="employee_type" class="w-full px-3 py-2 bg-slate-50 border border-slate-200 rounded-xl text-xs focus:ring-2 focus:ring-indigo-500 focus:bg-white text-slate-700">
|
||||||
<option value="">-- Pilih Unit Kerja --</option>
|
<option value="karyawan">Karyawan (Internal KMH)</option>
|
||||||
<option value="Pembangkit">Pembangkit</option>
|
<option value="sukon">Sukon (Subkontraktor)</option>
|
||||||
<option value="Bendungan">Bendungan</option>
|
|
||||||
<option value="Teknik">Teknik</option>
|
|
||||||
<option value="Umum">Umum</option>
|
|
||||||
<option value="Logistik">Logistik</option>
|
|
||||||
<option value="HSE">HSE</option>
|
|
||||||
<option value="QMA">QMA</option>
|
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label class="block text-[11px] font-semibold text-slate-600 mb-1">Divisi</label>
|
<label class="block text-[11px] font-semibold text-slate-600 mb-1">Unit Kerja</label>
|
||||||
<input type="text" name="division" class="w-full px-3 py-2 bg-slate-50 border border-slate-200 rounded-xl text-xs focus:ring-2 focus:ring-indigo-500 focus:bg-white text-slate-700" placeholder="Contoh: Operasi / Keuangan">
|
<input type="text"
|
||||||
|
name="unit_kerja"
|
||||||
|
list="adminUnitKerjaSuggestions"
|
||||||
|
class="w-full px-3 py-2 bg-slate-50 border border-slate-200 rounded-xl text-xs focus:ring-2 focus:ring-indigo-500 focus:bg-white text-slate-700"
|
||||||
|
placeholder="Ketik atau pilih unit kerja...">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="grid grid-cols-2 gap-3">
|
<div class="grid grid-cols-2 gap-3">
|
||||||
|
<div>
|
||||||
|
<label class="block text-[11px] font-semibold text-slate-600 mb-1">Divisi</label>
|
||||||
|
<input type="text" name="division" class="w-full px-3 py-2 bg-slate-50 border border-slate-200 rounded-xl text-xs focus:ring-2 focus:ring-indigo-500 focus:bg-white text-slate-700" placeholder="Contoh: Operasi / Keuangan">
|
||||||
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label class="block text-[11px] font-semibold text-slate-600 mb-1">Posisi / Jabatan</label>
|
<label class="block text-[11px] font-semibold text-slate-600 mb-1">Posisi / Jabatan</label>
|
||||||
<input type="text" name="position" class="w-full px-3 py-2 bg-slate-50 border border-slate-200 rounded-xl text-xs focus:ring-2 focus:ring-indigo-500 focus:bg-white text-slate-700" placeholder="Contoh: Driver / Staff Finance">
|
<input type="text" name="position" class="w-full px-3 py-2 bg-slate-50 border border-slate-200 rounded-xl text-xs focus:ring-2 focus:ring-indigo-500 focus:bg-white text-slate-700" placeholder="Contoh: Driver / Staff Finance">
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label class="block text-[11px] font-semibold text-slate-600 mb-1">Operator / Driver</label>
|
<label class="block text-[11px] font-semibold text-slate-600 mb-1">Operator / Driver</label>
|
||||||
<select name="is_operator" class="w-full px-3 py-2 bg-slate-50 border border-slate-200 rounded-xl text-xs focus:ring-2 focus:ring-indigo-500 focus:bg-white text-slate-700">
|
<select name="is_operator" class="w-full px-3 py-2 bg-slate-50 border border-slate-200 rounded-xl text-xs focus:ring-2 focus:ring-indigo-500 focus:bg-white text-slate-700">
|
||||||
@@ -399,7 +403,6 @@
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</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">
|
||||||
<button type="button" onclick="closeCreateUserModal()" class="px-4 py-2 bg-slate-100 hover:bg-slate-200 text-slate-600 rounded-xl text-xs font-bold transition">
|
<button type="button" onclick="closeCreateUserModal()" class="px-4 py-2 bg-slate-100 hover:bg-slate-200 text-slate-600 rounded-xl text-xs font-bold transition">
|
||||||
@@ -416,7 +419,7 @@
|
|||||||
<!-- ========================================================================= -->
|
<!-- ========================================================================= -->
|
||||||
<!-- MODAL: EDIT PENGGUNA -->
|
<!-- MODAL: EDIT PENGGUNA -->
|
||||||
<!-- ========================================================================= -->
|
<!-- ========================================================================= -->
|
||||||
<div id="editUserModal" class="fixed inset-0 z-50 hidden overflow-y-auto bg-slate-900/60 backdrop-blur-sm flex items-center justify-center p-4">
|
<div id="editUserModal" data-backdrop="static" class="fixed inset-0 z-50 hidden overflow-y-auto bg-slate-900/60 backdrop-blur-sm flex items-center justify-center p-4">
|
||||||
<div class="bg-white rounded-2xl max-w-lg w-full shadow-2xl overflow-hidden animate-scale-in">
|
<div class="bg-white rounded-2xl max-w-lg w-full shadow-2xl overflow-hidden animate-scale-in">
|
||||||
<div class="px-6 py-4 border-b border-slate-100 flex items-center justify-between">
|
<div class="px-6 py-4 border-b border-slate-100 flex items-center justify-between">
|
||||||
<h3 class="text-sm font-bold text-slate-800 flex items-center gap-2">
|
<h3 class="text-sm font-bold text-slate-800 flex items-center gap-2">
|
||||||
@@ -495,29 +498,34 @@
|
|||||||
|
|
||||||
<div class="grid grid-cols-2 gap-3">
|
<div class="grid grid-cols-2 gap-3">
|
||||||
<div>
|
<div>
|
||||||
<label class="block text-[11px] font-semibold text-slate-600 mb-1">Unit Kerja</label>
|
<label class="block text-[11px] font-semibold text-slate-600 mb-1">Jenis Personil</label>
|
||||||
<select id="edit_unit_kerja" name="unit_kerja" class="w-full px-3 py-2 bg-slate-50 border border-slate-200 rounded-xl text-xs focus:ring-2 focus:ring-indigo-500 focus:bg-white text-slate-700">
|
<select id="edit_employee_type" name="employee_type" class="w-full px-3 py-2 bg-slate-50 border border-slate-200 rounded-xl text-xs focus:ring-2 focus:ring-indigo-500 focus:bg-white text-slate-700">
|
||||||
<option value="">-- Pilih Unit Kerja --</option>
|
<option value="karyawan">Karyawan (Internal KMH)</option>
|
||||||
<option value="Pembangkit">Pembangkit</option>
|
<option value="sukon">Sukon (Subkontraktor)</option>
|
||||||
<option value="Bendungan">Bendungan</option>
|
|
||||||
<option value="Teknik">Teknik</option>
|
|
||||||
<option value="Umum">Umum</option>
|
|
||||||
<option value="Logistik">Logistik</option>
|
|
||||||
<option value="HSE">HSE</option>
|
|
||||||
<option value="QMA">QMA</option>
|
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label class="block text-[11px] font-semibold text-slate-600 mb-1">Divisi</label>
|
<label class="block text-[11px] font-semibold text-slate-600 mb-1">Unit Kerja</label>
|
||||||
<input type="text" id="edit_division" name="division" class="w-full px-3 py-2 bg-slate-50 border border-slate-200 rounded-xl text-xs focus:ring-2 focus:ring-indigo-500 focus:bg-white text-slate-700" placeholder="Contoh: Operasi / Keuangan">
|
<input type="text"
|
||||||
|
id="edit_unit_kerja"
|
||||||
|
name="unit_kerja"
|
||||||
|
list="adminUnitKerjaSuggestions"
|
||||||
|
class="w-full px-3 py-2 bg-slate-50 border border-slate-200 rounded-xl text-xs focus:ring-2 focus:ring-indigo-500 focus:bg-white text-slate-700"
|
||||||
|
placeholder="Ketik atau pilih unit kerja...">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="grid grid-cols-2 gap-3">
|
<div class="grid grid-cols-2 gap-3">
|
||||||
|
<div>
|
||||||
|
<label class="block text-[11px] font-semibold text-slate-600 mb-1">Divisi</label>
|
||||||
|
<input type="text" id="edit_division" name="division" class="w-full px-3 py-2 bg-slate-50 border border-slate-200 rounded-xl text-xs focus:ring-2 focus:ring-indigo-500 focus:bg-white text-slate-700" placeholder="Contoh: Operasi / Keuangan">
|
||||||
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label class="block text-[11px] font-semibold text-slate-600 mb-1">Posisi / Jabatan</label>
|
<label class="block text-[11px] font-semibold text-slate-600 mb-1">Posisi / Jabatan</label>
|
||||||
<input type="text" id="edit_position" name="position" class="w-full px-3 py-2 bg-slate-50 border border-slate-200 rounded-xl text-xs focus:ring-2 focus:ring-indigo-500 focus:bg-white text-slate-700" placeholder="Contoh: Driver / Staff Finance">
|
<input type="text" id="edit_position" name="position" class="w-full px-3 py-2 bg-slate-50 border border-slate-200 rounded-xl text-xs focus:ring-2 focus:ring-indigo-500 focus:bg-white text-slate-700" placeholder="Contoh: Driver / Staff Finance">
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label class="block text-[11px] font-semibold text-slate-600 mb-1">Operator / Driver</label>
|
<label class="block text-[11px] font-semibold text-slate-600 mb-1">Operator / Driver</label>
|
||||||
<select id="edit_is_operator" name="is_operator" class="w-full px-3 py-2 bg-slate-50 border border-slate-200 rounded-xl text-xs focus:ring-2 focus:ring-indigo-500 focus:bg-white text-slate-700">
|
<select id="edit_is_operator" name="is_operator" class="w-full px-3 py-2 bg-slate-50 border border-slate-200 rounded-xl text-xs focus:ring-2 focus:ring-indigo-500 focus:bg-white text-slate-700">
|
||||||
@@ -526,7 +534,6 @@
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Accordion: Izin Tambahan Khusus (Direct Permissions) -->
|
<!-- Accordion: Izin Tambahan Khusus (Direct Permissions) -->
|
||||||
<div class="border border-slate-200 rounded-xl overflow-hidden bg-slate-50/50">
|
<div class="border border-slate-200 rounded-xl overflow-hidden bg-slate-50/50">
|
||||||
@@ -773,6 +780,8 @@
|
|||||||
if (editGateEl) editGateEl.value = user.gate_id || '';
|
if (editGateEl) editGateEl.value = user.gate_id || '';
|
||||||
|
|
||||||
const emp = user.employee || {};
|
const emp = user.employee || {};
|
||||||
|
const editEmployeeType = document.getElementById('edit_employee_type');
|
||||||
|
if (editEmployeeType) editEmployeeType.value = (emp.employee_type ? emp.employee_type.toLowerCase() : 'karyawan');
|
||||||
const editUnitKerja = document.getElementById('edit_unit_kerja');
|
const editUnitKerja = document.getElementById('edit_unit_kerja');
|
||||||
if (editUnitKerja) editUnitKerja.value = emp.unit_kerja || '';
|
if (editUnitKerja) editUnitKerja.value = emp.unit_kerja || '';
|
||||||
const editDivision = document.getElementById('edit_division');
|
const editDivision = document.getElementById('edit_division');
|
||||||
@@ -866,4 +875,13 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<!-- Datalist Rekomendasi Unit Kerja (Sinkron Master HSE) -->
|
||||||
|
<datalist id="adminUnitKerjaSuggestions">
|
||||||
|
@if(isset($unitKerjaList))
|
||||||
|
@foreach($unitKerjaList as $uk)
|
||||||
|
<option value="{{ $uk }}"></option>
|
||||||
|
@endforeach
|
||||||
|
@endif
|
||||||
|
</datalist>
|
||||||
@endsection
|
@endsection
|
||||||
|
|||||||
@@ -496,4 +496,64 @@ class SuperAdminRbacTest extends TestCase
|
|||||||
$this->assertTrue($targetUser->fresh()->can('employee.dashboard'));
|
$this->assertTrue($targetUser->fresh()->can('employee.dashboard'));
|
||||||
$this->assertTrue($targetUser->fresh()->can('qma.vehicles.view'));
|
$this->assertTrue($targetUser->fresh()->can('qma.vehicles.view'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_super_admin_user_management_syncs_flexible_unit_kerja_and_employee_type(): void
|
||||||
|
{
|
||||||
|
$superAdmin = User::where('username', 'superadmin')->first();
|
||||||
|
|
||||||
|
// 1. Cek UserController@index menyediakan $unitKerjaList dan datalist suggestions
|
||||||
|
$indexResponse = $this->actingAs($superAdmin)->get(route('admin.users.index'));
|
||||||
|
$indexResponse->assertOk();
|
||||||
|
$indexResponse->assertViewHas('unitKerjaList');
|
||||||
|
$indexResponse->assertSee('adminUnitKerjaSuggestions');
|
||||||
|
$indexResponse->assertSee('data-backdrop="static"', false);
|
||||||
|
|
||||||
|
// 2. Super Admin membuat user baru dengan unit_kerja fleksibel dan employee_type sukon
|
||||||
|
$response = $this->actingAs($superAdmin)->post(route('admin.users.store'), [
|
||||||
|
'name' => 'Budi Santoso',
|
||||||
|
'username' => 'BUDI-SUKON-001',
|
||||||
|
'email' => '[email protected]',
|
||||||
|
'password' => 'password123',
|
||||||
|
'role' => 'employee',
|
||||||
|
'employee_type' => 'sukon',
|
||||||
|
'unit_kerja' => 'Subkontraktor Sipil PT ABC',
|
||||||
|
'division' => 'Proyek Terowongan',
|
||||||
|
'position' => 'Driver Mixer',
|
||||||
|
'is_operator' => '1',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertRedirect(route('admin.users.index'));
|
||||||
|
$response->assertSessionHas('success');
|
||||||
|
|
||||||
|
$user = User::where('username', 'BUDI-SUKON-001')->first();
|
||||||
|
$this->assertNotNull($user);
|
||||||
|
|
||||||
|
// Verifikasi data Employee terkait tersinkron otomatis
|
||||||
|
$employee = \App\Models\Employee::where('user_id', $user->id)->first();
|
||||||
|
$this->assertNotNull($employee);
|
||||||
|
$this->assertEquals('Subkontraktor Sipil PT ABC', $employee->unit_kerja);
|
||||||
|
$this->assertEquals('Sukon', $employee->employee_type);
|
||||||
|
$this->assertEquals('Driver Mixer', $employee->position);
|
||||||
|
$this->assertTrue((bool)$employee->is_operator);
|
||||||
|
|
||||||
|
// 3. Super Admin memperbarui unit_kerja ke nilai kustom lain
|
||||||
|
$updateResponse = $this->actingAs($superAdmin)->post(route('admin.users.update', $user->id), [
|
||||||
|
'name' => 'Budi Santoso Baru',
|
||||||
|
'username' => 'BUDI-SUKON-001',
|
||||||
|
'email' => '[email protected]',
|
||||||
|
'role' => 'employee',
|
||||||
|
'employee_type' => 'karyawan',
|
||||||
|
'unit_kerja' => 'Pembangkit Unit 2 Baru',
|
||||||
|
'division' => 'Operasi Generator',
|
||||||
|
'position' => 'Operator Turbin',
|
||||||
|
'is_operator' => '0',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$updateResponse->assertRedirect(route('admin.users.index'));
|
||||||
|
$employee->refresh();
|
||||||
|
$this->assertEquals('Pembangkit Unit 2 Baru', $employee->unit_kerja);
|
||||||
|
$this->assertEquals('Karyawan', $employee->employee_type);
|
||||||
|
$this->assertEquals('Operator Turbin', $employee->position);
|
||||||
|
$this->assertFalse((bool)$employee->is_operator);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user