fix(employee): synchronize division & position fields across HSE and Admin, auto-populate Private Guard & Anggota for guards

This commit is contained in:
Ray1111-aa
2026-10-28 08:47:02 +07:00
parent 0642caebc1
commit 49359d1ba1
7 changed files with 319 additions and 21 deletions
+38 -8
View File
@@ -348,7 +348,7 @@
<div>
<label class="block text-xs font-bold text-slate-700 mb-1">Role RBAC *</label>
<select name="role" required 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">
<select name="role" id="create_role" onchange="handleUserRoleChange(this.value, 'create')" required 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">
<option value="">-- Pilih Role --</option>
@foreach($roles as $role)
<option value="{{ $role->name }}">{{ ucwords(str_replace('_', ' ', $role->name)) }}</option>
@@ -369,7 +369,7 @@
<div class="grid grid-cols-2 gap-3">
<div>
<label class="block text-[11px] font-semibold text-slate-600 mb-1">Jenis Personil</label>
<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">
<select name="employee_type" id="create_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="karyawan">Karyawan (Internal KMH)</option>
<option value="sukon">Sukon (Subkontraktor)</option>
</select>
@@ -378,6 +378,7 @@
<label class="block text-[11px] font-semibold text-slate-600 mb-1">Unit Kerja</label>
<input type="text"
name="unit_kerja"
id="create_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...">
@@ -387,11 +388,11 @@
<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">
<input type="text" name="division" id="create_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>
<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" id="create_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>
@@ -479,7 +480,7 @@
<div>
<label class="block text-xs font-bold text-slate-700 mb-1">Role RBAC *</label>
<select id="edit_role" name="role" required onchange="updatePermissionCheckboxes()" 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">
<select id="edit_role" name="role" required onchange="handleUserRoleChange(this.value, 'edit')" 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">
@foreach($roles as $role)
<option value="{{ $role->name }}">{{ ucwords(str_replace('_', ' ', $role->name)) }}</option>
@endforeach
@@ -685,6 +686,30 @@
}
}
function handleUserRoleChange(role, mode) {
if (mode === 'edit') {
updatePermissionCheckboxes();
}
const isGuard = (role === 'gate_officer' || role === 'pg_admin');
const unitEl = document.getElementById(mode + '_unit_kerja');
const divEl = document.getElementById(mode + '_division');
const posEl = document.getElementById(mode + '_position');
const empTypeEl = document.getElementById(mode + '_employee_type');
if (isGuard) {
if (empTypeEl) empTypeEl.value = 'karyawan';
if (unitEl && (!unitEl.value || unitEl.value === 'Umum')) {
unitEl.value = 'Private Guard';
}
if (divEl && (!divEl.value || divEl.value === '-')) {
divEl.value = 'Private Guard';
}
if (posEl && (!posEl.value || posEl.value === '-')) {
posEl.value = (role === 'pg_admin') ? 'Admin PG' : 'Anggota';
}
}
}
function updatePermissionCheckboxes() {
const roleSelect = document.getElementById('edit_role');
const selectedRole = roleSelect ? roleSelect.value : '';
@@ -780,14 +805,19 @@
if (editGateEl) editGateEl.value = user.gate_id || '';
const emp = user.employee || {};
const isGuard = (primaryRole === 'gate_officer' || primaryRole === 'pg_admin');
const defaultUnit = isGuard ? 'Private Guard' : '';
const defaultDivision = isGuard ? 'Private Guard' : '';
const defaultPosition = isGuard ? (primaryRole === 'pg_admin' ? 'Admin PG' : 'Anggota') : '';
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');
if (editUnitKerja) editUnitKerja.value = emp.unit_kerja || '';
if (editUnitKerja) editUnitKerja.value = emp.unit_kerja || defaultUnit;
const editDivision = document.getElementById('edit_division');
if (editDivision) editDivision.value = emp.division || '';
if (editDivision) editDivision.value = (emp.division && emp.division !== '-') ? emp.division : defaultDivision;
const editPosition = document.getElementById('edit_position');
if (editPosition) editPosition.value = emp.position || '';
if (editPosition) editPosition.value = (emp.position && emp.position !== '-') ? emp.position : defaultPosition;
const editIsOperator = document.getElementById('edit_is_operator');
if (editIsOperator) editIsOperator.value = (emp.is_operator ? '1' : '0');
@@ -138,6 +138,28 @@
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">
</div>
<!-- Divisi & Jabatan -->
<div class="grid grid-cols-1 sm:grid-cols-2 gap-3">
<div>
<label class="block text-xs font-bold text-slate-800 mb-1.5">
Divisi <span class="text-rose-500">*</span>
</label>
<input type="text" name="division" required
value="{{ old('division', $employee->division) }}"
placeholder="Contoh: Operasi, Private Guard"
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">
</div>
<div>
<label class="block text-xs font-bold text-slate-800 mb-1.5">
Posisi / Jabatan <span class="text-rose-500">*</span>
</label>
<input type="text" name="position" required
value="{{ old('position', $employee->position) }}"
placeholder="Contoh: Anggota, Driver, Staff"
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">
</div>
</div>
<!-- Status Operator / Driver -->
<div>
<label class="block text-xs font-bold text-slate-800 mb-1.5">
@@ -789,6 +789,24 @@
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-[#1b5e20] transition">
</div>
<!-- Divisi & Jabatan -->
<div class="grid grid-cols-2 gap-2.5">
<div>
<label class="block text-xs font-bold text-slate-800 mb-1">
Divisi <span class="text-rose-500">*</span>
</label>
<input type="text" name="division" id="editDivisionInput" required placeholder="Contoh: Operasi, Private Guard"
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-[#1b5e20] transition">
</div>
<div>
<label class="block text-xs font-bold text-slate-800 mb-1">
Posisi / Jabatan <span class="text-rose-500">*</span>
</label>
<input type="text" name="position" id="editPositionInput" required placeholder="Contoh: Anggota, Driver, Staff"
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-[#1b5e20] transition">
</div>
</div>
<!-- Status Operator -->
<div>
<label class="block text-xs font-bold text-slate-800 mb-1">Status Operator / Driver <span class="text-rose-500">*</span></label>
@@ -1188,6 +1206,14 @@
if (editUnitKerjaInput) {
editUnitKerjaInput.value = emp.unit_kerja || '';
}
const editDivisionInput = document.getElementById('editDivisionInput');
if (editDivisionInput) {
editDivisionInput.value = emp.division || '';
}
const editPositionInput = document.getElementById('editPositionInput');
if (editPositionInput) {
editPositionInput.value = emp.position || '';
}
document.getElementById('editDivisionPositionDisplay').textContent = (emp.division || '-') + ' / ' + (emp.position || '-');
document.getElementById('editOperator').value = emp.is_operator ? '1' : '0';