feat: redesign employee edit modal to spacious 2-column layout, add dedicated edit view, and sync simper scopes with qma heavy categories
This commit is contained in:
@@ -636,6 +636,24 @@ class EmployeeController extends Controller
|
||||
return back()->with('success', "Data karyawan {$validated['name']} berhasil ditambahkan.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Tampilkan halaman khusus edit data personil & SIMPER (View Terpisah).
|
||||
*/
|
||||
public function edit(int $id): View
|
||||
{
|
||||
$employee = Employee::with(['simpers.simperType'])->findOrFail($id);
|
||||
$availableSimperTypes = SimperType::active()->orderBy('name')->get();
|
||||
|
||||
$employeeTypes = Employee::distinct()
|
||||
->whereNotNull('employee_type')
|
||||
->where('employee_type', '!=', '')
|
||||
->pluck('employee_type')
|
||||
->values()
|
||||
->all();
|
||||
|
||||
return view('hse.employees_edit', compact('employee', 'availableSimperTypes', 'employeeTypes'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Perpanjang atau perbarui data karyawan & SIMPER.
|
||||
*/
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Hse;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\SimperType;
|
||||
use App\Models\Vehicle;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -30,9 +31,13 @@ class SimperTypeController extends Controller
|
||||
->orderBy('name')
|
||||
->get();
|
||||
|
||||
$categoryScopes = SimperType::SCOPES;
|
||||
$categoryScopes = SimperType::getAvailableScopes();
|
||||
|
||||
return view('hse.simper_types_index', compact('simperTypes', 'categoryScopes'));
|
||||
$heavyCategories = Vehicle::unitSupportCategories()
|
||||
->orderBy('unit_category')
|
||||
->get(['id', 'code', 'brand_type', 'unit_category']);
|
||||
|
||||
return view('hse.simper_types_index', compact('simperTypes', 'categoryScopes', 'heavyCategories'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,10 +45,12 @@ class SimperTypeController extends Controller
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$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(array_keys(SimperType::SCOPES))],
|
||||
'category_scope' => ['required', 'string', Rule::in($validScopes)],
|
||||
'description' => ['nullable', 'string', 'max:500'],
|
||||
'is_active' => ['nullable', 'boolean'],
|
||||
]);
|
||||
@@ -67,11 +74,12 @@ class SimperTypeController extends Controller
|
||||
public function update(Request $request, int $id): RedirectResponse
|
||||
{
|
||||
$simperType = SimperType::findOrFail($id);
|
||||
$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(array_keys(SimperType::SCOPES))],
|
||||
'category_scope' => ['required', 'string', Rule::in($validScopes)],
|
||||
'description' => ['nullable', 'string', 'max:500'],
|
||||
'is_active' => ['nullable', 'boolean'],
|
||||
]);
|
||||
|
||||
+18
-6
@@ -152,18 +152,30 @@ class Employee extends Model
|
||||
|
||||
// 2. Berdasarkan kategori kendaraan
|
||||
if ($vehicle->isLightVehicle()) {
|
||||
return $this->hasValidSimperForType('SIMPER-LV') || $this->hasValidSimperForScope(SimperType::SCOPE_ALL);
|
||||
}
|
||||
|
||||
if ($vehicle->isUnitSupport() && $vehicle->is_timesheet_mobile) {
|
||||
return $this->hasValidSimperForType('SIMPER-DT')
|
||||
|| $this->hasValidSimperForType('SIMPER-HEAVY')
|
||||
return $this->hasValidSimperForType('SIMPER-LV')
|
||||
|| $this->hasValidSimperForScope('light_vehicle')
|
||||
|| $this->hasValidSimperForScope(SimperType::SCOPE_ALL);
|
||||
}
|
||||
|
||||
if ($vehicle->isUnitSupport()) {
|
||||
// Cek apakah personil memiliki izin SIMPER dengan scope kategori alat berat ini (misal: 'Dump Truck', 'Excavator', dll.)
|
||||
if ($vehicle->unit_category && $this->hasValidSimperForScope($vehicle->unit_category)) {
|
||||
return true;
|
||||
}
|
||||
if ($vehicle->brand_type && $this->hasValidSimperForScope($vehicle->brand_type)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($vehicle->is_timesheet_mobile) {
|
||||
return $this->hasValidSimperForType('SIMPER-DT')
|
||||
|| $this->hasValidSimperForType('SIMPER-HEAVY')
|
||||
|| $this->hasValidSimperForScope('unit_support_mobile')
|
||||
|| $this->hasValidSimperForScope(SimperType::SCOPE_ALL);
|
||||
}
|
||||
|
||||
return $this->hasValidSimperForType('SIMPER-HEAVY')
|
||||
|| $this->hasValidSimperForType('SIMPER-DT')
|
||||
|| $this->hasValidSimperForScope('unit_support_heavy')
|
||||
|| $this->hasValidSimperForScope(SimperType::SCOPE_ALL);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,64 @@ class SimperType extends Model
|
||||
self::SCOPE_ALL => 'Semua Kategori Armada',
|
||||
];
|
||||
|
||||
/**
|
||||
* Dapatkan daftar cakupan armada yang disinkronisasikan langsung
|
||||
* dengan data Master Kategori Heavy Equipment dari modul QMA.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public static function getAvailableScopes(): array
|
||||
{
|
||||
$scopes = [
|
||||
self::SCOPE_ALL => 'Semua Kategori (Universal)',
|
||||
self::SCOPE_LIGHT_VEHICLE => 'Light Vehicle (LV)',
|
||||
];
|
||||
|
||||
// Baseline kategori Heavy Equipment umum
|
||||
$defaultHeavy = [
|
||||
'Dump Truck',
|
||||
'Excavator',
|
||||
'Wheel Loader',
|
||||
'Motor Grader',
|
||||
'Truk Mixer',
|
||||
'Water Truck',
|
||||
'Forklift',
|
||||
'Crane Truck',
|
||||
'Crawler Crane',
|
||||
'Concrete Pump Truck',
|
||||
];
|
||||
foreach ($defaultHeavy as $dh) {
|
||||
$scopes[$dh] = "Heavy: {$dh}";
|
||||
}
|
||||
|
||||
// Sinkronisasi kategori Heavy Equipment dari data master QMA
|
||||
try {
|
||||
$heavyCategories = Vehicle::unitSupportCategories()
|
||||
->orderBy('unit_category')
|
||||
->get();
|
||||
|
||||
foreach ($heavyCategories as $cat) {
|
||||
$key = $cat->unit_category ?: $cat->brand_type;
|
||||
if ($key) {
|
||||
$codeSuffix = !empty($cat->code) ? " ({$cat->code})" : '';
|
||||
$scopes[$key] = "Heavy: {$key}{$codeSuffix}";
|
||||
}
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
// Fallback saat migrasi awal jika tabel belum siap
|
||||
}
|
||||
|
||||
// Dukungan fallback untuk cakupan legacy
|
||||
if (!isset($scopes[self::SCOPE_UNIT_SUPPORT_MOBILE])) {
|
||||
$scopes[self::SCOPE_UNIT_SUPPORT_MOBILE] = 'Heavy Mobile / Dump Truck (Legacy)';
|
||||
}
|
||||
if (!isset($scopes[self::SCOPE_UNIT_SUPPORT_HEAVY])) {
|
||||
$scopes[self::SCOPE_UNIT_SUPPORT_HEAVY] = 'Alat Berat Operasional (Legacy)';
|
||||
}
|
||||
|
||||
return $scopes;
|
||||
}
|
||||
|
||||
protected $fillable = [
|
||||
'code',
|
||||
'name',
|
||||
|
||||
Reference in New Issue
Block a user