feat: integrate sukon and employee operator type across hse and qma heavy timesheet
This commit is contained in:
@@ -121,6 +121,18 @@ class EmployeeController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Filter Jenis Personil / Karyawan (Karyawan, Sukon, dll)
|
||||
if ($request->filled('employee_type')) {
|
||||
$empType = trim($request->input('employee_type'));
|
||||
if ($empType === 'Karyawan') {
|
||||
$query->where(function ($q) {
|
||||
$q->where('employee_type', 'Karyawan')->orWhereNull('employee_type');
|
||||
});
|
||||
} else {
|
||||
$query->where('employee_type', $empType);
|
||||
}
|
||||
}
|
||||
|
||||
return $query->orderBy('name');
|
||||
}
|
||||
|
||||
@@ -131,7 +143,20 @@ class EmployeeController extends Controller
|
||||
{
|
||||
$employees = $this->getFilteredEmployees($request)->paginate(20)->withQueryString();
|
||||
|
||||
return view('hse.employees_index', compact('employees'));
|
||||
$employeeTypes = Employee::whereNotNull('employee_type')
|
||||
->where('employee_type', '!=', '')
|
||||
->distinct()
|
||||
->pluck('employee_type')
|
||||
->all();
|
||||
|
||||
if (!in_array('Karyawan', $employeeTypes)) {
|
||||
array_unshift($employeeTypes, 'Karyawan');
|
||||
}
|
||||
if (!in_array('Sukon', $employeeTypes)) {
|
||||
$employeeTypes[] = 'Sukon';
|
||||
}
|
||||
|
||||
return view('hse.employees_index', compact('employees', 'employeeTypes'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -163,6 +188,7 @@ class EmployeeController extends Controller
|
||||
'No' => 6,
|
||||
'NIK' => 16,
|
||||
'Nama Lengkap' => 30,
|
||||
'Jenis' => 16,
|
||||
'Jabatan' => 24,
|
||||
'Unit Kerja' => 20,
|
||||
'Divisi' => 20,
|
||||
@@ -195,6 +221,7 @@ class EmployeeController extends Controller
|
||||
$idx + 1,
|
||||
$emp->nik,
|
||||
$emp->name,
|
||||
$emp->employee_type ?: 'Karyawan',
|
||||
$emp->position ?: '-',
|
||||
$emp->unit_kerja ?: '-',
|
||||
$emp->division ?: '-',
|
||||
@@ -208,6 +235,7 @@ class EmployeeController extends Controller
|
||||
'center', // No
|
||||
'center', // NIK
|
||||
'left', // Nama
|
||||
'center', // Jenis
|
||||
'left', // Jabatan
|
||||
'left', // Unit Kerja
|
||||
'left', // Divisi
|
||||
@@ -383,6 +411,7 @@ class EmployeeController extends Controller
|
||||
'unit_kerja' => null,
|
||||
'division' => null,
|
||||
'position' => null,
|
||||
'employee_type' => null,
|
||||
'is_operator' => null,
|
||||
'simper_expired_at' => null,
|
||||
];
|
||||
@@ -405,6 +434,8 @@ class EmployeeController extends Controller
|
||||
$colMap['division'] = $cIdx;
|
||||
} elseif (str_contains($cellText, 'jabatan') || str_contains($cellText, 'posisi') || str_contains($cellText, 'position')) {
|
||||
$colMap['position'] = $cIdx;
|
||||
} elseif (str_contains($cellText, 'jenis') || str_contains($cellText, 'tipe') || str_contains($cellText, 'sukon')) {
|
||||
$colMap['employee_type'] = $cIdx;
|
||||
} elseif (str_contains($cellText, 'operator') || str_contains($cellText, 'driver')) {
|
||||
$colMap['is_operator'] = $cIdx;
|
||||
} elseif (str_contains($cellText, 'simper') || str_contains($cellText, 'berlaku') || str_contains($cellText, 'expired')) {
|
||||
@@ -452,6 +483,7 @@ class EmployeeController extends Controller
|
||||
$unitKerja = trim((string) ($colMap['unit_kerja'] !== null ? ($row[$colMap['unit_kerja']] ?? 'Umum') : 'Umum'));
|
||||
$division = trim((string) ($colMap['division'] !== null ? ($row[$colMap['division']] ?? '-') : '-'));
|
||||
$position = trim((string) ($colMap['position'] !== null ? ($row[$colMap['position']] ?? '-') : '-'));
|
||||
$employeeType = trim((string) ($colMap['employee_type'] !== null ? ($row[$colMap['employee_type']] ?? 'Karyawan') : 'Karyawan')) ?: 'Karyawan';
|
||||
|
||||
// Deteksi status driver (jika kolom ada dan berisi ya/driver)
|
||||
$operatorRaw = $colMap['is_operator'] !== null ? strtolower(trim((string) ($row[$colMap['is_operator']] ?? ''))) : '';
|
||||
@@ -482,6 +514,7 @@ class EmployeeController extends Controller
|
||||
if ($isExisting) {
|
||||
$isExisting->update([
|
||||
'name' => $name,
|
||||
'employee_type' => $employeeType,
|
||||
'unit_kerja' => $unitKerja ?: 'Umum',
|
||||
'division' => $division ?: '-',
|
||||
'position' => $position ?: '-',
|
||||
@@ -494,6 +527,7 @@ class EmployeeController extends Controller
|
||||
Employee::create([
|
||||
'nik' => $nik,
|
||||
'name' => $name,
|
||||
'employee_type' => $employeeType,
|
||||
'unit_kerja' => $unitKerja ?: 'Umum',
|
||||
'division' => $division ?: '-',
|
||||
'position' => $position ?: '-',
|
||||
@@ -551,6 +585,14 @@ class EmployeeController extends Controller
|
||||
$isOperator = (bool) $validated['is_operator'];
|
||||
$simperExpiredAt = $isOperator ? ($validated['simper_expired_at'] ?? null) : null;
|
||||
|
||||
$employeeType = $request->input('employee_type');
|
||||
if ($employeeType === '__CUSTOM__' && $request->filled('custom_employee_type')) {
|
||||
$employeeType = trim($request->input('custom_employee_type'));
|
||||
}
|
||||
if (empty($employeeType)) {
|
||||
$employeeType = 'Karyawan';
|
||||
}
|
||||
|
||||
$user = User::firstOrCreate(
|
||||
['username' => $validated['nik']],
|
||||
[
|
||||
@@ -574,6 +616,7 @@ class EmployeeController extends Controller
|
||||
Employee::create([
|
||||
'nik' => $validated['nik'],
|
||||
'name' => $validated['name'],
|
||||
'employee_type' => $employeeType,
|
||||
'unit_kerja' => $validated['unit_kerja'],
|
||||
'division' => $validated['division'],
|
||||
'position' => $validated['position'],
|
||||
@@ -611,6 +654,11 @@ class EmployeeController extends Controller
|
||||
$isOperator = (bool) $validated['is_operator'];
|
||||
$simperExpiredAt = $isOperator ? ($validated['simper_expired_at'] ?? $employee->simper_expired_at) : null;
|
||||
|
||||
$employeeType = $request->input('employee_type');
|
||||
if ($employeeType === '__CUSTOM__' && $request->filled('custom_employee_type')) {
|
||||
$employeeType = trim($request->input('custom_employee_type'));
|
||||
}
|
||||
|
||||
$photoPath = $employee->photo_path;
|
||||
if ($request->hasFile('photo')) {
|
||||
ImageCompressionService::deleteIfExists($employee->photo_path);
|
||||
@@ -620,6 +668,7 @@ class EmployeeController extends Controller
|
||||
$employee->update([
|
||||
'nik' => $validated['nik'] ?? $employee->nik,
|
||||
'name' => $validated['name'] ?? $employee->name,
|
||||
'employee_type' => $employeeType ?? $employee->employee_type ?? 'Karyawan',
|
||||
'unit_kerja' => $validated['unit_kerja'] ?? $employee->unit_kerja,
|
||||
'division' => $validated['division'] ?? $employee->division,
|
||||
'position' => $validated['position'] ?? $employee->position,
|
||||
|
||||
@@ -65,6 +65,13 @@ class SupportTimesheetController extends Controller
|
||||
$query->where('operator_id', $request->input('operator_id'));
|
||||
}
|
||||
|
||||
// Filter Jenis Personil / Operator (Karyawan / Sukon / dsb)
|
||||
if ($request->filled('operator_type')) {
|
||||
$query->whereHas('operator', function (Builder $oq) use ($request) {
|
||||
$oq->where('employee_type', $request->input('operator_type'));
|
||||
});
|
||||
}
|
||||
|
||||
// Filter Shift
|
||||
if ($request->filled('shift')) {
|
||||
$query->where('shift', $request->input('shift'));
|
||||
@@ -132,7 +139,7 @@ class SupportTimesheetController extends Controller
|
||||
->get();
|
||||
|
||||
$operators = Employee::orderBy('name')
|
||||
->get(['id', 'nik', 'name', 'position', 'is_operator']);
|
||||
->get(['id', 'nik', 'name', 'position', 'is_operator', 'employee_type', 'simper_expired_at']);
|
||||
|
||||
$shifts = self::SHIFTS;
|
||||
$activityTypes = self::PRESET_ACTIVITIES;
|
||||
@@ -439,6 +446,7 @@ class SupportTimesheetController extends Controller
|
||||
'KODE UNIT' => 14,
|
||||
'MEREK / MODEL' => 26,
|
||||
'OPERATOR' => 24,
|
||||
'JENIS' => 14,
|
||||
'NIK' => 16,
|
||||
'SATUAN' => 10,
|
||||
'START' => 14,
|
||||
@@ -463,6 +471,7 @@ class SupportTimesheetController extends Controller
|
||||
$ts->vehicle?->code ?: '-',
|
||||
$ts->vehicle?->brand_type ?: '-',
|
||||
$ts->operator?->name ?: '-',
|
||||
$ts->operator?->employee_type ?: 'Karyawan',
|
||||
$ts->operator?->nik ?: '-',
|
||||
$ts->meter_type,
|
||||
number_format($ts->start_meter, 2, ',', '.'),
|
||||
@@ -484,6 +493,7 @@ class SupportTimesheetController extends Controller
|
||||
'TANGGAL' => 'center',
|
||||
'SHIFT' => 'center',
|
||||
'KODE UNIT' => 'center',
|
||||
'JENIS' => 'center',
|
||||
'NIK' => 'center',
|
||||
'SATUAN' => 'center',
|
||||
'START' => 'right',
|
||||
@@ -537,8 +547,8 @@ class SupportTimesheetController extends Controller
|
||||
['title' => 'TANGGAL', 'width' => 20, 'align' => 'C'],
|
||||
['title' => 'KODE', 'width' => 18, 'align' => 'C', 'bold' => true],
|
||||
['title' => 'TIPE ALAT', 'width' => 38, 'align' => 'L', 'max_char' => 25],
|
||||
['title' => 'OPERATOR', 'width' => 35, 'align' => 'L', 'max_char' => 22],
|
||||
['title' => 'SHIFT', 'width' => 25, 'align' => 'C'],
|
||||
['title' => 'OPERATOR', 'width' => 40, 'align' => 'L', 'max_char' => 26],
|
||||
['title' => 'SHIFT', 'width' => 23, 'align' => 'C'],
|
||||
['title' => 'START', 'width' => 18, 'align' => 'R'],
|
||||
['title' => 'END', 'width' => 18, 'align' => 'R'],
|
||||
['title' => 'JAM (HM)', 'width' => 18, 'align' => 'R', 'bold' => true],
|
||||
@@ -553,7 +563,7 @@ class SupportTimesheetController extends Controller
|
||||
$ts->date ? $ts->date->format('d/m/Y') : '-',
|
||||
$ts->vehicle?->code ?: '-',
|
||||
$ts->vehicle?->brand_type ?: '-',
|
||||
$ts->operator?->name ?: '-',
|
||||
$ts->operator?->name ? ($ts->operator->name . ' (' . ($ts->operator->employee_type ?: 'Karyawan') . ')') : '-',
|
||||
$ts->shift,
|
||||
number_format($ts->start_meter, 1, ',', '.'),
|
||||
number_format($ts->end_meter, 1, ',', '.'),
|
||||
|
||||
@@ -13,10 +13,14 @@ class Employee extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public const TYPE_KARYAWAN = 'Karyawan';
|
||||
public const TYPE_SUKON = 'Sukon';
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'nik',
|
||||
'name',
|
||||
'employee_type',
|
||||
'unit_kerja',
|
||||
'division',
|
||||
'position',
|
||||
@@ -34,6 +38,29 @@ class Employee extends Model
|
||||
'photo_url',
|
||||
];
|
||||
|
||||
public function isSukon(): bool
|
||||
{
|
||||
return strcasecmp($this->employee_type ?? '', self::TYPE_SUKON) === 0;
|
||||
}
|
||||
|
||||
public function isKaryawan(): bool
|
||||
{
|
||||
return empty($this->employee_type) || strcasecmp($this->employee_type, self::TYPE_KARYAWAN) === 0;
|
||||
}
|
||||
|
||||
public function scopeSukon(Builder $query): Builder
|
||||
{
|
||||
return $query->where('employee_type', self::TYPE_SUKON);
|
||||
}
|
||||
|
||||
public function scopeKaryawan(Builder $query): Builder
|
||||
{
|
||||
return $query->where(function ($q) {
|
||||
$q->where('employee_type', self::TYPE_KARYAWAN)
|
||||
->orWhereNull('employee_type');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Cek apakah SIMPER masih aktif hari ini.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?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('employees', function (Blueprint $table) {
|
||||
$table->string('employee_type', 50)->default('Karyawan')->after('name')->index();
|
||||
});
|
||||
|
||||
DB::table('employees')->whereNull('employee_type')->update(['employee_type' => 'Karyawan']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('employees', function (Blueprint $table) {
|
||||
$table->dropIndex(['employee_type']);
|
||||
$table->dropColumn('employee_type');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -88,6 +88,18 @@
|
||||
<!-- Filter di Kanan (Pada Mobile: Sejajar 2 Kolom di Bawah Search Bar) -->
|
||||
<div class="flex flex-col sm:flex-row items-stretch sm:items-center justify-end gap-2 sm:gap-2.5 w-full sm:w-auto">
|
||||
<div class="grid grid-cols-2 gap-2 sm:flex sm:items-center sm:gap-2.5 w-full sm:w-auto">
|
||||
<!-- Filter Jenis Personil / Karyawan -->
|
||||
<select name="employee_type"
|
||||
onchange="this.form.submit()"
|
||||
class="w-full sm:w-auto text-xs rounded-xl border border-slate-200 bg-white px-2.5 sm:px-3 py-2.5 text-slate-700 font-semibold focus:outline-none focus:border-[#1b5e20] focus:ring-2 focus:ring-[#1b5e20]/10 shadow-sm transition truncate">
|
||||
<option value="">Semua Jenis</option>
|
||||
@if(isset($employeeTypes))
|
||||
@foreach($employeeTypes as $t)
|
||||
<option value="{{ $t }}" {{ request('employee_type') === $t ? 'selected' : '' }}>{{ $t }}</option>
|
||||
@endforeach
|
||||
@endif
|
||||
</select>
|
||||
|
||||
<!-- Filter Status Driver -->
|
||||
<select name="driver_status"
|
||||
onchange="this.form.submit()"
|
||||
@@ -110,7 +122,7 @@
|
||||
|
||||
<!-- Tombol Reset Filter (Sesuai Referensi Merah / Rose Clean Text) -->
|
||||
<div id="simperResetContainer">
|
||||
@if(request()->anyFilled(['search', 'driver_status', 'simper_status']))
|
||||
@if(request()->anyFilled(['search', 'employee_type', 'driver_status', 'simper_status']))
|
||||
<a href="{{ route('hse.employees.index') }}"
|
||||
id="simperResetBtn"
|
||||
class="text-xs text-rose-600 hover:text-rose-700 font-semibold flex items-center justify-center sm:justify-start space-x-1.5 transition whitespace-nowrap py-1 sm:py-0 sm:ml-2">
|
||||
@@ -132,6 +144,7 @@
|
||||
<th class="py-3.5 px-4 text-center w-12">NO</th>
|
||||
<th class="py-3.5 px-4">NIK</th>
|
||||
<th class="py-3.5 px-4">NAMA LENGKAP</th>
|
||||
<th class="py-3.5 px-4 text-center">JENIS</th>
|
||||
<th class="py-3.5 px-4">JABATAN</th>
|
||||
<th class="py-3.5 px-4">UNIT / DIVISI</th>
|
||||
<th class="py-3.5 px-4 text-center">STATUS DRIVER</th>
|
||||
@@ -165,6 +178,23 @@
|
||||
</div>
|
||||
</td>
|
||||
|
||||
<!-- Jenis Personil (Karyawan / Sukon) -->
|
||||
<td class="py-3.5 px-4 text-center whitespace-nowrap">
|
||||
@if($emp->isSukon())
|
||||
<span class="inline-flex items-center px-2 py-0.5 rounded-full text-[10px] font-bold bg-amber-50 text-amber-700 border border-amber-200">
|
||||
Sukon
|
||||
</span>
|
||||
@elseif($emp->isKaryawan())
|
||||
<span class="inline-flex items-center px-2 py-0.5 rounded-full text-[10px] font-bold bg-emerald-50 text-emerald-800 border border-emerald-200">
|
||||
Karyawan
|
||||
</span>
|
||||
@else
|
||||
<span class="inline-flex items-center px-2 py-0.5 rounded-full text-[10px] font-bold bg-slate-100 text-slate-700 border border-slate-200">
|
||||
{{ $emp->employee_type }}
|
||||
</span>
|
||||
@endif
|
||||
</td>
|
||||
|
||||
<!-- Jabatan -->
|
||||
<td class="py-3.5 px-4 text-slate-600">{{ $emp->position ?? '-' }}</td>
|
||||
|
||||
@@ -312,6 +342,31 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Jenis Personil / Karyawan (Karyawan / Sukon / Custom) -->
|
||||
<div>
|
||||
<label class="block text-xs font-bold text-slate-800 mb-1.5">
|
||||
Jenis Personil / Karyawan <span class="text-rose-500">*</span>
|
||||
</label>
|
||||
<select name="employee_type" id="addEmployeeTypeSelect" onchange="toggleCustomEmployeeType(this.value, 'add')" 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">
|
||||
<option value="Karyawan" selected>Karyawan (Internal KMH)</option>
|
||||
<option value="Sukon">Sukon (Subkontraktor)</option>
|
||||
@if(isset($employeeTypes))
|
||||
@foreach($employeeTypes as $t)
|
||||
@if($t !== 'Karyawan' && $t !== 'Sukon')
|
||||
<option value="{{ $t }}">{{ $t }}</option>
|
||||
@endif
|
||||
@endforeach
|
||||
@endif
|
||||
<option value="__CUSTOM__">+ Ketik Jenis Baru...</option>
|
||||
</select>
|
||||
<div id="addCustomEmployeeTypeWrapper" class="hidden mt-2">
|
||||
<input type="text" name="custom_employee_type" id="addCustomEmployeeTypeInput" placeholder="Ketik jenis personil baru (misal: Vendor, Mitra, dll)..."
|
||||
class="w-full text-xs px-3.5 py-2 rounded-xl border border-emerald-300 bg-emerald-50/40 text-slate-800 font-semibold focus:outline-none focus:border-[#1b5e20]">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<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">NIK (Nomor Induk Karyawan) <span class="text-rose-500">*</span></label>
|
||||
@@ -579,6 +634,30 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Jenis Personil / Karyawan (Karyawan / Sukon / Custom) -->
|
||||
<div>
|
||||
<label class="block text-sm font-bold text-slate-800 mb-2">
|
||||
Jenis Personil / Karyawan <span class="text-rose-500">*</span>
|
||||
</label>
|
||||
<select name="employee_type" id="editEmployeeType" onchange="toggleCustomEmployeeType(this.value, 'edit')" required
|
||||
class="w-full text-sm px-4 py-3 rounded-2xl 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">
|
||||
<option value="Karyawan">Karyawan (Internal KMH)</option>
|
||||
<option value="Sukon">Sukon (Subkontraktor)</option>
|
||||
@if(isset($employeeTypes))
|
||||
@foreach($employeeTypes as $t)
|
||||
@if($t !== 'Karyawan' && $t !== 'Sukon')
|
||||
<option value="{{ $t }}">{{ $t }}</option>
|
||||
@endif
|
||||
@endforeach
|
||||
@endif
|
||||
<option value="__CUSTOM__">+ Ketik Jenis Baru...</option>
|
||||
</select>
|
||||
<div id="editCustomEmployeeTypeWrapper" class="hidden mt-2">
|
||||
<input type="text" name="custom_employee_type" id="editCustomEmployeeTypeInput" placeholder="Ketik jenis personil baru (misal: Vendor, Mitra, dll)..."
|
||||
class="w-full text-sm px-4 py-2.5 rounded-2xl border border-emerald-300 bg-emerald-50/40 text-slate-800 font-semibold focus:outline-none focus:border-[#1b5e20]">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Bagian yang Dikelola HSE -->
|
||||
<div>
|
||||
<label class="block text-sm font-bold text-slate-800 mb-2">Operator / Driver <span class="text-rose-500">*</span></label>
|
||||
@@ -715,6 +794,27 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Logika Jenis Personil (Karyawan / Sukon / Custom)
|
||||
function toggleCustomEmployeeType(val, mode) {
|
||||
const wrapper = document.getElementById(mode === 'edit' ? 'editCustomEmployeeTypeWrapper' : 'addCustomEmployeeTypeWrapper');
|
||||
const input = document.getElementById(mode === 'edit' ? 'editCustomEmployeeTypeInput' : 'addCustomEmployeeTypeInput');
|
||||
if (wrapper) {
|
||||
if (val === '__CUSTOM__') {
|
||||
wrapper.classList.remove('hidden');
|
||||
if (input) {
|
||||
input.required = true;
|
||||
input.focus();
|
||||
}
|
||||
} else {
|
||||
wrapper.classList.add('hidden');
|
||||
if (input) {
|
||||
input.required = false;
|
||||
input.value = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Logika Penguncian Input SIMPER jika Bukan Driver
|
||||
function toggleSimperInput(type) {
|
||||
let opSelect, dateInput;
|
||||
@@ -792,6 +892,36 @@
|
||||
}
|
||||
document.getElementById('editSimperDate').value = expDate;
|
||||
|
||||
// Set jenis personil
|
||||
const editTypeSelect = document.getElementById('editEmployeeType');
|
||||
const editCustomWrapper = document.getElementById('editCustomEmployeeTypeWrapper');
|
||||
const editCustomInput = document.getElementById('editCustomEmployeeTypeInput');
|
||||
const empType = emp.employee_type || 'Karyawan';
|
||||
let found = false;
|
||||
if (editTypeSelect) {
|
||||
for (let i = 0; i < editTypeSelect.options.length; i++) {
|
||||
if (editTypeSelect.options[i].value === empType) {
|
||||
editTypeSelect.value = empType;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
editTypeSelect.value = '__CUSTOM__';
|
||||
if (editCustomWrapper) editCustomWrapper.classList.remove('hidden');
|
||||
if (editCustomInput) {
|
||||
editCustomInput.required = true;
|
||||
editCustomInput.value = empType;
|
||||
}
|
||||
} else {
|
||||
if (editCustomWrapper) editCustomWrapper.classList.add('hidden');
|
||||
if (editCustomInput) {
|
||||
editCustomInput.required = false;
|
||||
editCustomInput.value = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Cek status driver untuk mengunci/membuka input SIMPER
|
||||
toggleSimperInput('edit');
|
||||
|
||||
@@ -939,6 +1069,11 @@
|
||||
if (addPhotoPlaceholder) {
|
||||
addPhotoPlaceholder.classList.remove('hidden');
|
||||
}
|
||||
const addTypeSelect = document.getElementById('addEmployeeTypeSelect');
|
||||
if (addTypeSelect) {
|
||||
addTypeSelect.value = 'Karyawan';
|
||||
toggleCustomEmployeeType('Karyawan', 'add');
|
||||
}
|
||||
if (modal) modal.classList.remove('hidden');
|
||||
}
|
||||
function closeAddKaryawanModal() {
|
||||
|
||||
@@ -157,11 +157,20 @@
|
||||
<option value="{{ $s }}" {{ request('shift') === $s ? 'selected' : '' }}>{{ $s }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
|
||||
<!-- Filter Jenis Operator (Karyawan / Sukon) -->
|
||||
<select name="operator_type"
|
||||
onchange="this.form.submit()"
|
||||
class="w-full sm:w-auto text-xs rounded-xl border border-slate-200 bg-white px-2.5 sm:px-3 py-2.5 text-slate-700 font-semibold focus:outline-none focus:border-[#1b5e20] focus:ring-2 focus:ring-[#1b5e20]/10 shadow-sm transition truncate">
|
||||
<option value="">Semua Personil</option>
|
||||
<option value="Karyawan" {{ request('operator_type') === 'Karyawan' ? 'selected' : '' }}>Karyawan</option>
|
||||
<option value="Sukon" {{ request('operator_type') === 'Sukon' ? 'selected' : '' }}>Sukon</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<!-- Tombol Reset Filter -->
|
||||
<div id="timesheetResetContainer">
|
||||
@if(request()->anyFilled(['search', 'vehicle_id', 'shift']) || (request('start_date') && request('start_date') !== now()->toDateString()) || (request('end_date') && request('end_date') !== now()->toDateString()))
|
||||
@if(request()->anyFilled(['search', 'vehicle_id', 'shift', 'operator_type']) || (request('start_date') && request('start_date') !== now()->toDateString()) || (request('end_date') && request('end_date') !== now()->toDateString()))
|
||||
<a href="{{ url()->current() }}"
|
||||
id="timesheetResetBtn"
|
||||
class="text-xs text-rose-600 hover:text-rose-700 font-semibold flex items-center justify-center sm:justify-start space-x-1.5 transition whitespace-nowrap py-1 sm:py-0 sm:ml-2">
|
||||
@@ -259,8 +268,25 @@
|
||||
|
||||
<!-- Operator -->
|
||||
<td class="py-3.5 px-4">
|
||||
<div class="font-bold text-slate-900 line-clamp-1">
|
||||
{{ $ts->operator?->name ?: '-' }}
|
||||
<div class="flex items-center space-x-1.5">
|
||||
<span class="font-bold text-slate-900 line-clamp-1">
|
||||
{{ $ts->operator?->name ?: '-' }}
|
||||
</span>
|
||||
@if($ts->operator)
|
||||
@if($ts->operator->employee_type === 'Sukon')
|
||||
<span class="px-1.5 py-0.5 rounded text-[9px] font-extrabold bg-amber-50 text-amber-700 border border-amber-200 uppercase tracking-wider flex-shrink-0">
|
||||
Sukon
|
||||
</span>
|
||||
@elseif($ts->operator->employee_type && $ts->operator->employee_type !== 'Karyawan')
|
||||
<span class="px-1.5 py-0.5 rounded text-[9px] font-extrabold bg-slate-100 text-slate-700 border border-slate-200 uppercase tracking-wider flex-shrink-0">
|
||||
{{ $ts->operator->employee_type }}
|
||||
</span>
|
||||
@else
|
||||
<span class="px-1.5 py-0.5 rounded text-[9px] font-extrabold bg-emerald-50 text-emerald-700 border border-emerald-200 uppercase tracking-wider flex-shrink-0">
|
||||
Karyawan
|
||||
</span>
|
||||
@endif
|
||||
@endif
|
||||
</div>
|
||||
<div class="font-mono text-[10px] text-slate-400">
|
||||
NIK: {{ $ts->operator?->nik ?: '-' }}
|
||||
@@ -324,6 +350,7 @@
|
||||
'code' => $ts->vehicle?->code ?: '-',
|
||||
'brand_type' => $ts->vehicle?->brand_type ?: '-',
|
||||
'operator_name' => $ts->operator?->name ?: '-',
|
||||
'operator_type' => $ts->operator?->employee_type ?: 'Karyawan',
|
||||
'operator_nik' => $ts->operator?->nik ?: '-',
|
||||
'start_meter' => number_format($ts->start_meter, 1, ',', '.'),
|
||||
'end_meter' => number_format($ts->end_meter, 1, ',', '.'),
|
||||
@@ -499,20 +526,55 @@
|
||||
<!-- Baris 2: Pengemudi / Operator & Kategori Pekerjaan -->
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="block text-xs font-bold text-slate-700 mb-1.5">
|
||||
Pengemudi / Operator <span class="text-rose-500">*</span>
|
||||
</label>
|
||||
<div class="flex items-center justify-between mb-1.5">
|
||||
<label class="block text-xs font-bold text-slate-700">
|
||||
Pengemudi / Operator <span class="text-rose-500">*</span>
|
||||
</label>
|
||||
<!-- Segmented filter buttons operator -->
|
||||
<div class="inline-flex rounded-lg bg-slate-100 p-0.5 border border-slate-200 text-[10px]">
|
||||
<button type="button"
|
||||
onclick="filterOperatorSelect('all', 'add')"
|
||||
id="addOpFilter_all"
|
||||
class="px-2 py-0.5 rounded font-bold transition bg-white text-emerald-800 shadow-2xs">
|
||||
Semua
|
||||
</button>
|
||||
<button type="button"
|
||||
onclick="filterOperatorSelect('Karyawan', 'add')"
|
||||
id="addOpFilter_Karyawan"
|
||||
class="px-2 py-0.5 rounded font-bold transition text-slate-600 hover:text-slate-900">
|
||||
Karyawan
|
||||
</button>
|
||||
<button type="button"
|
||||
onclick="filterOperatorSelect('Sukon', 'add')"
|
||||
id="addOpFilter_Sukon"
|
||||
class="px-2 py-0.5 rounded font-bold transition text-slate-600 hover:text-slate-900">
|
||||
Sukon
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<select name="operator_id"
|
||||
id="addOperatorSelect"
|
||||
required
|
||||
class="w-full text-xs px-3.5 py-2.5 rounded-xl border border-slate-200 bg-white text-slate-800 focus:outline-none focus:border-[#1b5e20] focus:ring-1 focus:ring-[#1b5e20] transition">
|
||||
<option value="">-- Pilih Operator --</option>
|
||||
@foreach($operators as $op)
|
||||
<option value="{{ $op->id }}">
|
||||
{{ $op->name }} ({{ $op->nik }}) {{ $op->is_operator ? '★ Operator' : '' }}
|
||||
@php
|
||||
$opType = $op->employee_type ?: 'Karyawan';
|
||||
$simperTag = '';
|
||||
if ($op->simper_expired_at) {
|
||||
$exp = \Carbon\Carbon::parse($op->simper_expired_at);
|
||||
$simperTag = $exp->isPast() ? '[SIMPER EXPIRED]' : '[SIMPER S/D ' . $exp->format('d/m/y') . ']';
|
||||
}
|
||||
@endphp
|
||||
<option value="{{ $op->id }}" data-type="{{ $opType }}">
|
||||
[{{ $opType }}] {{ $op->name }} ({{ $op->nik }}) {{ $op->is_operator ? '★' : '' }} {{ $simperTag }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
<p id="addOperatorCountHelp" class="text-[10px] text-slate-400 mt-1 flex items-center justify-between">
|
||||
<span>Total personil: {{ count($operators) }}</span>
|
||||
<span class="text-emerald-700 font-semibold" id="addOperatorCurrentFilterText">Filter: Semua</span>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
@@ -796,19 +858,55 @@
|
||||
<!-- Baris 2: Pengemudi / Operator & Kategori Pekerjaan -->
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="block text-xs font-bold text-slate-700 mb-1.5">
|
||||
Pengemudi / Operator <span class="text-rose-500">*</span>
|
||||
</label>
|
||||
<div class="flex items-center justify-between mb-1.5">
|
||||
<label class="block text-xs font-bold text-slate-700">
|
||||
Pengemudi / Operator <span class="text-rose-500">*</span>
|
||||
</label>
|
||||
<!-- Segmented filter buttons operator edit -->
|
||||
<div class="inline-flex rounded-lg bg-slate-100 p-0.5 border border-slate-200 text-[10px]">
|
||||
<button type="button"
|
||||
onclick="filterOperatorSelect('all', 'edit')"
|
||||
id="editOpFilter_all"
|
||||
class="px-2 py-0.5 rounded font-bold transition bg-white text-emerald-800 shadow-2xs">
|
||||
Semua
|
||||
</button>
|
||||
<button type="button"
|
||||
onclick="filterOperatorSelect('Karyawan', 'edit')"
|
||||
id="editOpFilter_Karyawan"
|
||||
class="px-2 py-0.5 rounded font-bold transition text-slate-600 hover:text-slate-900">
|
||||
Karyawan
|
||||
</button>
|
||||
<button type="button"
|
||||
onclick="filterOperatorSelect('Sukon', 'edit')"
|
||||
id="editOpFilter_Sukon"
|
||||
class="px-2 py-0.5 rounded font-bold transition text-slate-600 hover:text-slate-900">
|
||||
Sukon
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<select name="operator_id"
|
||||
id="editOperatorSelect"
|
||||
required
|
||||
class="w-full text-xs px-3.5 py-2.5 rounded-xl border border-slate-200 bg-white text-slate-800 focus:outline-none focus:border-[#1b5e20] focus:ring-1 focus:ring-[#1b5e20] transition">
|
||||
<option value="">-- Pilih Operator --</option>
|
||||
@foreach($operators as $op)
|
||||
<option value="{{ $op->id }}">
|
||||
{{ $op->name }} ({{ $op->nik }})
|
||||
@php
|
||||
$opType = $op->employee_type ?: 'Karyawan';
|
||||
$simperTag = '';
|
||||
if ($op->simper_expired_at) {
|
||||
$exp = \Carbon\Carbon::parse($op->simper_expired_at);
|
||||
$simperTag = $exp->isPast() ? '[SIMPER EXPIRED]' : '[SIMPER S/D ' . $exp->format('d/m/y') . ']';
|
||||
}
|
||||
@endphp
|
||||
<option value="{{ $op->id }}" data-type="{{ $opType }}">
|
||||
[{{ $opType }}] {{ $op->name }} ({{ $op->nik }}) {{ $op->is_operator ? '★' : '' }} {{ $simperTag }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
<p id="editOperatorCountHelp" class="text-[10px] text-slate-400 mt-1 flex items-center justify-between">
|
||||
<span>Total personil: {{ count($operators) }}</span>
|
||||
<span class="text-emerald-700 font-semibold" id="editOperatorCurrentFilterText">Filter: Semua</span>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
@@ -1062,6 +1160,75 @@
|
||||
@section('scripts')
|
||||
<script>
|
||||
window.unitSupportsData = @json($unitSupports);
|
||||
window.allOperatorsData = @json($operators);
|
||||
|
||||
// Filter Segmented Operator (Semua / Karyawan / Sukon)
|
||||
function filterOperatorSelect(type, mode, preserveSelectedId) {
|
||||
const selectId = mode === 'edit' ? 'editOperatorSelect' : 'addOperatorSelect';
|
||||
const select = document.getElementById(selectId);
|
||||
if (!select) return;
|
||||
|
||||
// Update button states
|
||||
const types = ['all', 'Karyawan', 'Sukon'];
|
||||
types.forEach(t => {
|
||||
const btn = document.getElementById(`${mode}OpFilter_${t}`);
|
||||
if (btn) {
|
||||
if (t === type) {
|
||||
btn.className = "px-2 py-0.5 rounded font-bold transition bg-white text-emerald-800 shadow-2xs";
|
||||
} else {
|
||||
btn.className = "px-2 py-0.5 rounded font-bold transition text-slate-600 hover:text-slate-900";
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Update filter help text
|
||||
const filterText = document.getElementById(`${mode}OperatorCurrentFilterText`);
|
||||
if (filterText) {
|
||||
filterText.textContent = `Filter: ${type === 'all' ? 'Semua' : type}`;
|
||||
}
|
||||
|
||||
const currentVal = preserveSelectedId !== undefined ? String(preserveSelectedId) : select.value;
|
||||
const options = select.querySelectorAll('option');
|
||||
let visibleCount = 0;
|
||||
|
||||
options.forEach(opt => {
|
||||
if (!opt.value) {
|
||||
opt.hidden = false;
|
||||
return;
|
||||
}
|
||||
const optType = opt.getAttribute('data-type') || 'Karyawan';
|
||||
let match = false;
|
||||
if (type === 'all') {
|
||||
match = true;
|
||||
} else if (type === 'Karyawan') {
|
||||
match = optType === 'Karyawan';
|
||||
} else if (type === 'Sukon') {
|
||||
match = optType === 'Sukon';
|
||||
} else {
|
||||
match = optType.toLowerCase() === type.toLowerCase();
|
||||
}
|
||||
|
||||
opt.hidden = !match;
|
||||
if (match) visibleCount++;
|
||||
});
|
||||
|
||||
// Update total count
|
||||
const countHelp = document.getElementById(`${mode}OperatorCountHelp`);
|
||||
if (countHelp) {
|
||||
const spanFirst = countHelp.querySelector('span:first-child');
|
||||
if (spanFirst) spanFirst.textContent = `Total personil: ${visibleCount}`;
|
||||
}
|
||||
|
||||
// Restore or reset selection
|
||||
if (currentVal) {
|
||||
const selectedOpt = select.querySelector(`option[value="${currentVal}"]`);
|
||||
if (selectedOpt && !selectedOpt.hidden) {
|
||||
select.value = currentVal;
|
||||
} else if (preserveSelectedId === undefined) {
|
||||
select.value = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 1. Dropdown Ekspor
|
||||
function toggleExportMenu(event) {
|
||||
@@ -1104,6 +1271,11 @@
|
||||
const startMeter = document.getElementById('addStartMeter');
|
||||
if (startMeter) startMeter.value = '';
|
||||
|
||||
// Reset filter operator ke Semua
|
||||
filterOperatorSelect('all', 'add');
|
||||
const addOpSelect = document.getElementById('addOperatorSelect');
|
||||
if (addOpSelect) addOpSelect.value = '';
|
||||
|
||||
// Otomatis tanggal dan jam realtime saat ini
|
||||
const now = new Date();
|
||||
const year = now.getFullYear();
|
||||
@@ -1137,7 +1309,8 @@
|
||||
document.getElementById('detailTimesheetNo').textContent = ts.timesheet_no;
|
||||
document.getElementById('detailDateShift').textContent = `${ts.date} • ${ts.shift}`;
|
||||
document.getElementById('detailUnit').textContent = `${ts.code} - ${ts.brand_type}`;
|
||||
document.getElementById('detailOperator').textContent = `${ts.operator_name} (NIK: ${ts.operator_nik})`;
|
||||
const opTypeLabel = ts.operator_type ? ` [${ts.operator_type}]` : '';
|
||||
document.getElementById('detailOperator').textContent = `${ts.operator_name}${opTypeLabel} (NIK: ${ts.operator_nik})`;
|
||||
document.getElementById('detailMeter').textContent = `${ts.start_meter} ${ts.meter_type}`;
|
||||
const detailStartTimeEl = document.getElementById('detailStartTime');
|
||||
if (detailStartTimeEl) {
|
||||
@@ -1215,6 +1388,24 @@
|
||||
// Filter unit pada lokasi ini dengan memilih ts.vehicle_id
|
||||
onTimesheetLocationChanged(locSelect ? locSelect.value : targetLoc, 'edit', ts.vehicle_id);
|
||||
|
||||
// Cari jenis operator yang sedang diedit untuk mengaktifkan filter yang sesuai
|
||||
let selectedOpType = 'all';
|
||||
if (ts.operator_id && window.allOperatorsData) {
|
||||
const foundOp = window.allOperatorsData.find(o => String(o.id) === String(ts.operator_id));
|
||||
if (foundOp && foundOp.employee_type) {
|
||||
selectedOpType = foundOp.employee_type;
|
||||
}
|
||||
} else if (ts.operator && ts.operator.employee_type) {
|
||||
selectedOpType = ts.operator.employee_type;
|
||||
}
|
||||
|
||||
if (selectedOpType === 'Sukon') {
|
||||
filterOperatorSelect('Sukon', 'edit', ts.operator_id);
|
||||
} else if (selectedOpType === 'Karyawan') {
|
||||
filterOperatorSelect('Karyawan', 'edit', ts.operator_id);
|
||||
} else {
|
||||
filterOperatorSelect('all', 'edit', ts.operator_id);
|
||||
}
|
||||
document.getElementById('editOperatorSelect').value = ts.operator_id;
|
||||
|
||||
// Format tanggal YYYY-MM-DD
|
||||
|
||||
@@ -465,4 +465,86 @@ class QmaSupportTimesheetTest extends TestCase
|
||||
$this->supportUnit->refresh();
|
||||
$this->assertEquals('Quarry Batu KM 12', $this->supportUnit->location);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sinkronisasi data operator Sukon dari database ke dropdown QMA dan tabel timesheet.
|
||||
*/
|
||||
public function test_qma_support_timesheet_syncs_and_filters_sukon_and_karyawan_operators(): void
|
||||
{
|
||||
$sukonOperator = Employee::create([
|
||||
'nik' => 'SKN-999',
|
||||
'name' => 'Budi Sukon Utama',
|
||||
'position' => 'Operator Subcon Dozer',
|
||||
'employee_type' => 'Sukon',
|
||||
'is_operator' => true,
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($this->qmaAdmin)
|
||||
->get(route('qma.support_timesheet.index'));
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('Budi Sukon Utama');
|
||||
$response->assertSee('data-type="Sukon"', false);
|
||||
$response->assertSee('data-type="Karyawan"', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter berdasarkan jenis operator (Sukon vs Karyawan) di tabel timesheet.
|
||||
*/
|
||||
public function test_qma_support_timesheet_filter_by_operator_type(): void
|
||||
{
|
||||
$sukonOperator = Employee::create([
|
||||
'nik' => 'SKN-888',
|
||||
'name' => 'Sukon Operator X',
|
||||
'position' => 'Operator Subcon Excavator',
|
||||
'employee_type' => 'Sukon',
|
||||
'is_operator' => true,
|
||||
]);
|
||||
|
||||
$tsKaryawan = UnitSupportTimesheet::create([
|
||||
'timesheet_no' => 'TS-KARYAWAN-001',
|
||||
'vehicle_id' => $this->supportUnit->id,
|
||||
'operator_id' => $this->operator->id,
|
||||
'date' => Carbon::today()->toDateString(),
|
||||
'shift' => 'Shift Siang',
|
||||
'meter_type' => 'HM',
|
||||
'start_meter' => 100.0,
|
||||
'end_meter' => 108.0,
|
||||
'operating_hours' => 8.0,
|
||||
'location' => 'Adit 1',
|
||||
'activity_type' => 'Galian',
|
||||
'status' => 'Operation',
|
||||
]);
|
||||
|
||||
$tsSukon = UnitSupportTimesheet::create([
|
||||
'timesheet_no' => 'TS-SUKON-001',
|
||||
'vehicle_id' => $this->supportUnit->id,
|
||||
'operator_id' => $sukonOperator->id,
|
||||
'date' => Carbon::today()->toDateString(),
|
||||
'shift' => 'Shift Siang',
|
||||
'meter_type' => 'HM',
|
||||
'start_meter' => 110.0,
|
||||
'end_meter' => 118.0,
|
||||
'operating_hours' => 8.0,
|
||||
'location' => 'Adit 1',
|
||||
'activity_type' => 'Loading',
|
||||
'status' => 'Operation',
|
||||
]);
|
||||
|
||||
// Filter Sukon only
|
||||
$responseSukon = $this->actingAs($this->qmaAdmin)
|
||||
->get(route('qma.support_timesheet.index', ['operator_type' => 'Sukon']));
|
||||
|
||||
$responseSukon->assertStatus(200);
|
||||
$responseSukon->assertSee('TS-SUKON-001');
|
||||
$responseSukon->assertDontSee('TS-KARYAWAN-001');
|
||||
|
||||
// Filter Karyawan only
|
||||
$responseKaryawan = $this->actingAs($this->qmaAdmin)
|
||||
->get(route('qma.support_timesheet.index', ['operator_type' => 'Karyawan']));
|
||||
|
||||
$responseKaryawan->assertStatus(200);
|
||||
$responseKaryawan->assertSee('TS-KARYAWAN-001');
|
||||
$responseKaryawan->assertDontSee('TS-SUKON-001');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user