Files
rkm-kmh/resources/views/qma/support_timesheet.blade.php

1869 lines
106 KiB
PHP

@extends('layouts.app')
@php
$isHistoryRoute = request()->routeIs('qma.activity.support_timesheet');
@endphp
@section('title', ($isHistoryRoute ? 'History Timesheet Heavy Equipment' : 'Timesheet Heavy Equipment') . ' - Admin QMA | PT Kerinci Merangin Hidro')
@section('content')
<div class="w-full space-y-6">
<!-- Header Judul & Tombol Aksi (Persis Format Standar HSE Employees) -->
<div class="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4">
<div>
<div class="flex items-center space-x-1.5 mb-1">
<span class="text-xs font-bold uppercase tracking-wider text-[#1b5e20]">
MANAJEMEN SISTEM
</span>
<!-- Tombol Info Panduan Halaman Sejajar Kicker -->
<button type="button"
onclick="openGuideModal()"
class="w-3.5 h-3.5 rounded-full bg-slate-200/90 hover:bg-slate-300 text-slate-500 hover:text-slate-800 text-[8px] inline-flex items-center justify-center font-bold transition shadow-2xs cursor-pointer focus:outline-none"
title="Panduan Halaman Timesheet Heavy Equipment">
<i class="fa-solid fa-info"></i>
</button>
</div>
<h2 class="text-3xl sm:text-4xl font-extrabold text-slate-900 tracking-tight">
{{ $isHistoryRoute ? 'History Timesheet' : 'Timesheet Heavy Equipment' }}
</h2>
</div>
<!-- Tombol Aksi Kanan -->
<div class="flex items-center gap-2.5 sm:gap-3 w-full sm:w-auto">
<!-- Dropdown Menu Ekspor Format it.allrole.web.id -->
<div class="relative inline-block w-full sm:w-auto flex-1 sm:flex-none" id="exportDropdownContainer">
<button type="button"
onclick="toggleExportMenu(event)"
id="btnExportTrigger"
class="w-full sm:w-auto border border-emerald-600/30 text-emerald-900 bg-white hover:bg-emerald-50/50 px-3 sm:px-4 py-2.5 rounded-xl text-xs font-bold flex items-center justify-center space-x-2 transition shadow-sm cursor-pointer">
<i class="fa-regular fa-file-excel text-emerald-700 text-sm"></i>
<span class="truncate">Ekspor Timesheet</span>
<i class="fa-solid fa-chevron-down text-[9px] text-slate-400 ml-0.5 sm:ml-1"></i>
</button>
<div id="exportMenu" style="display: none;" class="absolute right-0 mt-2 w-52 bg-white rounded-xl shadow-[0_8px_30px_rgb(0,0,0,0.12)] border border-slate-100 z-50 overflow-hidden">
<a href="{{ route('qma.support_timesheet.export_pdf', request()->query()) }}" target="_blank" class="flex items-center px-4 py-3 text-xs text-slate-700 hover:bg-slate-50 hover:text-[#1b5e20] font-bold transition">
<i class="fa-regular fa-file-pdf text-rose-600 text-sm mr-2.5"></i>
<span>Format PDF (Cetak)</span>
</a>
<div class="h-px bg-slate-100 mx-2"></div>
<a href="{{ route('qma.support_timesheet.export_excel', request()->query()) }}" class="flex items-center px-4 py-3 text-xs text-emerald-700 hover:bg-emerald-50 font-bold transition">
<i class="fa-regular fa-file-excel text-emerald-600 text-sm mr-2.5"></i>
<span>Format Excel (.xlsx)</span>
</a>
</div>
</div>
@if(!$isHistoryRoute)
<!-- Tombol Tambah Timesheet -->
@can('qma.logs.edit_odometer')
<button type="button"
onclick="openAddModal()"
class="w-full sm:w-auto flex-1 sm:flex-none bg-[#1b5e20] hover:bg-[#144919] text-white px-3 sm:px-4 py-2.5 rounded-xl text-xs font-bold flex items-center justify-center space-x-2 transition shadow-sm cursor-pointer whitespace-nowrap"
title="Catat Timesheet Harian Heavy Equipment">
<i class="fa-solid fa-plus text-xs"></i>
<span class="truncate">Catat Timesheet</span>
</button>
@endcan
@endif
</div>
</div>
<!-- KPI Ringkasan Data Timesheet -->
<div class="grid grid-cols-2 lg:grid-cols-4 gap-3.5">
<!-- 1. Total Entri -->
<div class="bg-white p-4 rounded-xl sm:rounded-2xl border border-slate-200 shadow-sm">
<p class="text-[11px] font-bold uppercase tracking-wider text-slate-400">Total Timesheet</p>
<h3 class="text-2xl font-black text-slate-800 mt-1">{{ number_format($totalEntries, 0, ',', '.') }}</h3>
<span class="text-[10px] text-slate-400 font-medium block mt-1">Laporan Operasi</span>
</div>
<!-- 2. Total Jam Operasi (HM) -->
<div class="bg-white p-4 rounded-xl sm:rounded-2xl border border-emerald-200 shadow-sm bg-gradient-to-br from-white to-emerald-50/40">
<p class="text-[11px] font-bold uppercase tracking-wider text-emerald-700">Total Jam Operasi</p>
<h3 class="text-2xl font-black text-emerald-800 mt-1">{{ number_format($totalOperatingHours, 1, ',', '.') }} <span class="text-sm font-bold text-emerald-600">Jam</span></h3>
<span class="text-[10px] text-emerald-600 font-semibold block mt-1">Akumulasi Jam Mesin</span>
</div>
<!-- 3. Unit Aktif -->
<div class="bg-white p-4 rounded-xl sm:rounded-2xl border border-slate-200 shadow-sm">
<p class="text-[11px] font-bold uppercase tracking-wider text-slate-400">Unit Beroperasi</p>
<h3 class="text-2xl font-black text-slate-800 mt-1">{{ number_format($activeUnitsCount, 0, ',', '.') }}</h3>
<span class="text-[10px] text-emerald-600 font-medium block mt-1">Unit Beroperasi</span>
</div>
<!-- 4. Breakdown -->
<div class="bg-white p-4 rounded-xl sm:rounded-2xl border border-slate-200 shadow-sm">
<p class="text-[11px] font-bold uppercase tracking-wider text-slate-400">Kendala Breakdown</p>
<h3 class="text-2xl font-black text-rose-600 mt-1">{{ number_format($breakdownCount, 0, ',', '.') }}</h3>
<span class="text-[10px] text-rose-500 font-medium block mt-1">Status Breakdown</span>
</div>
</div>
<!-- Kotak Pencarian & Filter Status Timesheet -->
<form method="GET" action="{{ url()->current() }}" id="timesheetFilterForm" class="flex flex-col lg:flex-row items-stretch lg:items-center justify-between gap-2.5 sm:gap-3 flex-wrap">
<!-- Pencarian Cepat di Kiri -->
<div class="relative w-full lg:w-72 xl:w-80 flex-shrink-0">
<span class="absolute inset-y-0 left-0 pl-3.5 flex items-center pointer-events-none text-slate-400">
<i class="fa-solid fa-magnifying-glass text-xs"></i>
</span>
<input type="text"
name="search"
id="timesheetSearchInput"
value="{{ request('search') }}"
placeholder="Cari No. TS, nama/NIK operator, lokasi..."
autocomplete="off"
class="w-full text-xs pl-10 pr-4 py-2.5 rounded-xl border border-slate-200 bg-white text-slate-800 placeholder-slate-400 focus:outline-none focus:border-[#1b5e20] focus:ring-2 focus:ring-[#1b5e20]/10 shadow-sm transition">
</div>
<!-- Filter di Kanan -->
<div class="flex flex-wrap items-center justify-start lg:justify-end gap-2 sm:gap-2.5 w-full lg:w-auto">
<!-- Filter Rentang Tanggal Compact -->
<div class="flex items-center gap-1.5 bg-white border border-slate-200 rounded-xl px-2.5 py-2 shadow-sm">
<i class="fa-regular fa-calendar text-slate-400 text-xs flex-shrink-0"></i>
<input type="date"
name="start_date"
value="{{ request('start_date', $startDate) }}"
onchange="this.form.submit()"
class="text-xs bg-transparent text-slate-700 font-semibold focus:outline-none"
title="Dari Tanggal">
<span class="text-slate-300 text-xs">-</span>
<input type="date"
name="end_date"
value="{{ request('end_date', $endDate) }}"
onchange="this.form.submit()"
class="text-xs bg-transparent text-slate-700 font-semibold focus:outline-none"
title="Sampai Tanggal">
</div>
<!-- Filter Heavy Equipment -->
<select name="vehicle_id"
onchange="this.form.submit()"
class="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 max-w-[200px]">
<option value="">Semua Heavy Equipment</option>
@foreach($unitSupports as $u)
<option value="{{ $u->id }}" {{ request('vehicle_id') == $u->id ? 'selected' : '' }}>
{{ $u->code }} - {{ $u->brand_type }}
</option>
@endforeach
</select>
<!-- Filter Shift -->
<select name="shift"
onchange="this.form.submit()"
class="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 Shift</option>
@foreach($shifts as $s)
<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="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>
<!-- Filter Tampilan Per Halaman -->
<select name="per_page"
onchange="this.form.submit()"
class="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="15" {{ request('per_page', '15') == '15' ? 'selected' : '' }}>15 / Hal</option>
<option value="50" {{ request('per_page', '50') == '50' ? 'selected' : '' }}>50 / Hal</option>
<option value="100" {{ request('per_page', '100') == '100' ? 'selected' : '' }}>Semua (100)</option>
</select>
<!-- Tombol Reset Filter -->
<div id="timesheetResetContainer">
@if(request()->anyFilled(['search', 'vehicle_id', 'shift', 'operator_type', 'per_page']) || (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-1">
<i class="fa-solid fa-rotate-left text-[11px]"></i>
<span>Reset Filter</span>
</a>
@endif
</div>
</div>
</form>
<!-- Alert Notifikasi -->
@if(session('success'))
<div class="p-3.5 rounded-xl bg-emerald-50 border border-emerald-200 text-emerald-800 text-xs font-semibold flex items-center justify-between">
<div class="flex items-center space-x-2">
<i class="fa-solid fa-circle-check text-emerald-600 text-sm"></i>
<span>{{ session('success') }}</span>
</div>
<button type="button" onclick="this.parentElement.remove()" class="text-emerald-500 hover:text-emerald-800">
<i class="fa-solid fa-xmark"></i>
</button>
</div>
@endif
@if($errors->any())
<div class="p-3.5 rounded-xl bg-rose-50 border border-rose-200 text-rose-800 text-xs font-semibold flex items-center justify-between">
<div class="flex items-center space-x-2">
<i class="fa-solid fa-triangle-exclamation text-rose-600 text-sm"></i>
<span>Terdapat kesalahan pada isian form: {{ $errors->first() }}</span>
</div>
<button type="button" onclick="this.parentElement.remove()" class="text-rose-500 hover:text-rose-800">
<i class="fa-solid fa-xmark"></i>
</button>
</div>
@endif
<!-- Tabel Data Timesheet Heavy Equipment dengan Header Biru Tua Navy (Pada Mobile: Format Kotak Tanpa Border Radius) -->
<div class="bg-white rounded-none sm:rounded-2xl border border-slate-200 shadow-sm overflow-hidden">
<div class="overflow-x-auto">
<table class="min-w-full text-xs text-left border-collapse">
<!-- Header Tabel Navy Gelap Solid #06213f -->
<thead class="bg-[#06213f] text-white font-bold text-[11px] uppercase tracking-wider">
<tr>
<th class="py-3.5 px-4 text-center w-12">NO</th>
<th class="py-3.5 px-4 whitespace-nowrap">NO TIMESHEET</th>
<th class="py-3.5 px-4 whitespace-nowrap">TANGGAL & SHIFT</th>
<th class="py-3.5 px-4 whitespace-nowrap min-w-[180px]">KODE & TIPE UNIT</th>
<th class="py-3.5 px-4 whitespace-nowrap">OPERATOR</th>
<th class="py-3.5 px-4 text-center whitespace-nowrap">METER AWAL</th>
<th class="py-3.5 px-4 whitespace-nowrap min-w-[200px]">LOKASI & AKTIVITAS</th>
<th class="py-3.5 px-4 text-center whitespace-nowrap">STATUS</th>
<th class="py-3.5 px-4 text-center whitespace-nowrap w-24">AKSI</th>
</tr>
</thead>
<tbody id="timesheetTableBody" class="divide-y divide-slate-100 text-slate-700 bg-white">
@forelse($timesheets as $idx => $ts)
<tr class="timesheet-row hover:bg-slate-50/70 transition">
<!-- No -->
<td class="py-3.5 px-3.5 text-center font-semibold text-slate-400">
{{ $timesheets->firstItem() + $idx }}
</td>
<!-- No Timesheet -->
<td class="py-3.5 px-3.5 whitespace-nowrap">
<span class="font-mono font-bold text-slate-900 bg-slate-100 px-2 py-0.5 rounded border border-slate-200 text-[11px]">
{{ $ts->timesheet_no }}
</span>
</td>
<!-- Tanggal & Shift -->
<td class="py-3.5 px-3.5 whitespace-nowrap">
<div class="font-bold text-slate-800">
{{ $ts->date ? $ts->date->translatedFormat('d M Y') : '-' }}
</div>
<span class="inline-flex items-center text-[10px] font-medium text-slate-500 mt-0.5">
<i class="fa-regular fa-clock mr-1 text-[9px] text-slate-400"></i>
{{ $ts->shift }}
@if($ts->start_time)
<span class="ml-1 text-slate-700 font-bold">• {{ \Carbon\Carbon::parse($ts->start_time)->format('H:i') }}</span>
@endif
</span>
</td>
<!-- Heavy Equipment -->
<td class="py-3.5 px-4">
<div class="flex items-center space-x-2">
<span class="font-mono font-extrabold text-slate-900 text-xs">
{{ $ts->vehicle?->code ?: '-' }}
</span>
</div>
<div class="text-[11px] text-slate-600 line-clamp-1" title="{{ $ts->vehicle?->brand_type }}">
{{ $ts->vehicle?->brand_type ?: '-' }}
</div>
</td>
<!-- Operator -->
<td class="py-3.5 px-4">
<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 ?: '-' }}
</div>
</td>
<!-- Odometer Awal & Akhir -->
<td class="py-3.5 px-4 text-center font-mono whitespace-nowrap">
<div class="text-xs font-bold text-slate-900 bg-slate-100 px-2.5 py-1 rounded-lg border border-slate-200 inline-block">
{{ number_format($ts->start_meter, 1, ',', '.') }} {{ $ts->meter_type }}@if($ts->effective_end_meter) <span class="text-slate-400 font-normal">s/d</span> <span class="text-emerald-700">{{ number_format($ts->effective_end_meter, 1, ',', '.') }} {{ $ts->meter_type }}</span>@endif
</div>
@if($ts->effective_operating_hours !== null && $ts->effective_operating_hours > 0)
<div class="text-[10px] text-emerald-700 font-semibold font-sans mt-0.5">
+{{ number_format($ts->effective_operating_hours, 1, ',', '.') }} Jam Operasi
</div>
@elseif($ts->effective_end_meter)
<div class="text-[10px] text-slate-400 font-sans mt-0.5">0.0 Jam</div>
@else
<div class="text-[10px] text-amber-600 font-sans mt-0.5 flex items-center justify-center gap-1">
<span class="w-1.5 h-1.5 rounded-full bg-amber-500 animate-pulse"></span>
<span>Berjalan (Finish Otomatis)</span>
</div>
@endif
</td>
<!-- Lokasi & Aktivitas -->
<td class="py-3.5 px-4">
<div class="flex items-center space-x-1 font-bold text-slate-900 line-clamp-1">
<i class="fa-solid fa-location-dot text-[#1b5e20] text-[10px] flex-shrink-0"></i>
<span>{{ $ts->location }}</span>
</div>
<div class="text-[11px] text-emerald-700 font-semibold mt-0.5 line-clamp-1">
{{ $ts->activity_type }}
</div>
@if($ts->task_description)
<p class="text-[10px] text-slate-500 mt-0.5 line-clamp-1 italic">
"{{ $ts->task_description }}"
</p>
@endif
</td>
<!-- Status -->
<td class="py-3.5 px-3.5 text-center whitespace-nowrap">
@if($ts->status === 'Operation')
<span class="inline-flex items-center px-2 py-0.5 rounded-full text-[10px] font-bold bg-emerald-50 text-emerald-700 border border-emerald-200">
Operation
</span>
@elseif($ts->status === 'Standby')
<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">
Standby
</span>
@elseif($ts->status === 'Breakdown')
<span class="inline-flex items-center px-2 py-0.5 rounded-full text-[10px] font-bold bg-rose-50 text-rose-700 border border-rose-200">
Breakdown
</span>
@else
<span class="inline-flex items-center px-2 py-0.5 rounded-full text-[10px] font-medium bg-slate-100 text-slate-600">
{{ $ts->status }}
</span>
@endif
</td>
<!-- Aksi -->
<td class="py-3.5 px-3.5 text-center whitespace-nowrap">
<div class="flex items-center justify-center space-x-1.5">
<!-- Tombol Detail (Bisa dilihat di History maupun Operasional) -->
<button type="button"
data-timesheet="{{ json_encode([
'timesheet_no' => $ts->timesheet_no,
'date' => $ts->date ? $ts->date->format('d/m/Y') : '-',
'start_time' => $ts->start_time ? \Carbon\Carbon::parse($ts->start_time)->format('H:i') : null,
'shift' => $ts->shift,
'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' => $ts->effective_end_meter !== null ? number_format($ts->effective_end_meter, 1, ',', '.') : '-',
'meter_type' => $ts->meter_type,
'operating_hours' => $ts->effective_operating_hours !== null ? number_format($ts->effective_operating_hours, 1, ',', '.') : '-',
'standby_hours' => number_format($ts->standby_hours, 1, ',', '.'),
'breakdown_hours' => number_format($ts->breakdown_hours, 1, ',', '.'),
'fuel_liters' => $ts->fuel_liters ? number_format($ts->fuel_liters, 0, ',', '.') : '-',
'location' => $ts->location,
'activity_type' => $ts->activity_type,
'task_description' => $ts->task_description ?: '-',
'status' => $ts->status,
'notes' => $ts->notes ?: '-',
], JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP) }}"
onclick="openDetailModalFromBtn(this)"
class="inline-flex items-center space-x-1 text-slate-500 hover:text-slate-800 hover:bg-slate-100 p-1.5 rounded-lg transition cursor-pointer"
title="Lihat Detail Riwayat">
<i class="fa-regular fa-eye text-xs"></i>
</button>
@can('qma.logs.edit_odometer')
@if(!$isHistoryRoute)
<button type="button"
data-timesheet="{{ json_encode($ts, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP) }}"
onclick="openEditModalFromBtn(this)"
class="inline-flex items-center space-x-1 text-amber-600 hover:text-amber-800 hover:bg-amber-50 p-1.5 rounded-lg transition cursor-pointer"
title="Edit Timesheet">
<i class="fa-regular fa-pen-to-square text-xs"></i>
</button>
<button type="button"
onclick="openDeleteModal('{{ $ts->id }}', '{{ $ts->timesheet_no }}')"
class="inline-flex items-center space-x-1 text-rose-600 hover:text-rose-800 hover:bg-rose-50 p-1.5 rounded-lg transition cursor-pointer"
title="Hapus Timesheet">
<i class="fa-regular fa-trash-can text-xs"></i>
</button>
@else
<!-- Mode History: Opsi Koreksi -->
<button type="button"
data-timesheet="{{ json_encode($ts, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP) }}"
onclick="openEditModalFromBtn(this)"
class="inline-flex items-center space-x-1 text-amber-600 hover:text-amber-800 hover:bg-amber-50 p-1.5 rounded-lg transition cursor-pointer"
title="Koreksi Data Timesheet">
<i class="fa-solid fa-pen-nib text-xs"></i>
</button>
@endif
@endcan
</div>
</td>
</tr>
@empty
<tr>
<td colspan="11" class="py-12 text-center text-slate-400">
<i class="fa-solid fa-clipboard-list text-4xl mb-3 block text-slate-300"></i>
<p class="text-sm font-semibold text-slate-700">Belum ada data timesheet Heavy Equipment</p>
@if(!$isHistoryRoute)
<p class="text-xs text-slate-400 mt-1">Gunakan tombol "Catat Timesheet" di atas untuk menambahkan laporan harian.</p>
@else
<p class="text-xs text-slate-400 mt-1">Tidak ditemukan catatan timesheet yang sesuai dengan kriteria filter saat ini.</p>
@endif
@if(request()->anyFilled(['start_date', 'end_date', 'vehicle_id', 'shift', 'search']))
<div class="mt-4">
<a href="{{ url()->current() }}" class="inline-flex items-center space-x-1.5 px-3.5 py-2 rounded-xl text-xs font-semibold text-rose-600 bg-rose-50 border border-rose-200 hover:bg-rose-100 transition cursor-pointer">
<i class="fa-solid fa-rotate-left text-[11px]"></i>
<span>Reset Filter</span>
</a>
</div>
@endif
</td>
</tr>
@endforelse
</tbody>
</table>
</div>
<!-- Pagination -->
@if($timesheets->hasPages())
<div class="p-4 border-t border-slate-100 flex flex-col sm:flex-row items-center justify-between gap-3 text-xs text-slate-500">
<div>
Menampilkan data <span class="font-bold text-slate-800">{{ $timesheets->firstItem() }}</span> sampai <span class="font-bold text-slate-800">{{ $timesheets->lastItem() }}</span> dari total <span class="font-bold text-slate-800">{{ $timesheets->total() }}</span> timesheet
</div>
<div>
{{ $timesheets->links() }}
</div>
</div>
@endif
</div>
</div>
@if(!$isHistoryRoute)
<!-- ========================================== -->
<!-- 1. MODAL TAMBAH TIMESHEET HEAVY EQUIPMENT -->
<!-- ========================================== -->
<div id="addTimesheetModal" class="hidden fixed inset-0 z-50 overflow-y-auto" style="display: none;">
<div class="fixed inset-0 bg-slate-900/60 backdrop-blur-xs transition-opacity" onclick="closeAddModal()"></div>
<div class="flex min-h-full items-center justify-center p-4">
<div class="relative w-full max-w-2xl bg-white rounded-2xl shadow-xl border border-slate-100 overflow-hidden transform transition-all">
<!-- Modal Header -->
<div class="flex items-center justify-between px-6 py-4 border-b border-slate-100">
<div>
<h3 class="text-sm font-extrabold text-slate-900 flex items-center gap-2">
<span class="w-2 h-2 rounded-full bg-[#1b5e20]"></span>
Catat Timesheet Heavy Equipment
</h3>
<p class="text-xs text-slate-500 mt-0.5">Input laporan kerja alat berat & penugasan operator harian.</p>
</div>
<button type="button" onclick="closeAddModal()" class="w-8 h-8 rounded-lg text-slate-400 hover:text-slate-600 hover:bg-slate-100 flex items-center justify-center transition">
<i class="fa-solid fa-xmark text-sm"></i>
</button>
</div>
<!-- Form Tambah Timesheet -->
<form id="addTimesheetForm" method="POST" action="{{ route('qma.support_timesheet.store') }}" class="p-6 space-y-4">
@csrf
<!-- Baris 1: Lokasi Kerja & Heavy Equipment -->
<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 flex items-center justify-between">
<span>Lokasi Kerja <span class="text-rose-500">*</span></span>
<span class="sr-only">Tentukan Lokasi Dulu</span>
<span class="text-[10px] text-emerald-700 font-semibold">Bisa ketik / pilih</span>
</label>
<div class="relative">
<input type="text"
id="addLocationInput"
name="location"
list="addLocationsDatalist"
required
autocomplete="off"
placeholder="Pilih atau ketik lokasi kerja..."
oninput="onTimesheetLocationTyped(this.value, 'add')"
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-1 focus:ring-[#1b5e20] transition">
<datalist id="addLocationsDatalist">
<option value="[Semua Unit]">[Semua Lokasi / Tampilkan Semua Unit]</option>
@foreach($unitLocations as $locName => $count)
<option value="{{ $locName }}">{{ $locName }} ({{ $count }} Unit Ready)</option>
@endforeach
@foreach($locationSuggestions as $suggLoc)
@if(!isset($unitLocations[$suggLoc]))
<option value="{{ $suggLoc }}">{{ $suggLoc }}</option>
@endif
@endforeach
</datalist>
</div>
<input type="hidden" id="addFinalLocation" value="">
<p class="text-[10px] text-slate-400 mt-1">
Pilih dari daftar atau ketik lokasi baru (otomatis tersimpan ke database).
</p>
</div>
<div>
<label class="block text-xs font-bold text-slate-700 mb-1.5 flex items-center justify-between">
<span>Heavy Equipment <span class="text-rose-500">*</span></span>
<span id="addUnitCounterBadge" class="text-[10px] font-semibold text-emerald-700 bg-emerald-50 px-2 py-0.5 rounded border border-emerald-200 hidden"></span>
</label>
<div class="space-y-1.5">
<div class="relative">
<i class="fa-solid fa-magnifying-glass absolute left-3 top-1/2 -translate-y-1/2 text-slate-400 text-xs"></i>
<input type="text"
id="addVehicleSearch"
placeholder="Ketik untuk filter unit (kode / merek)..."
oninput="filterTimesheetVehicleOptions(this.value, 'add')"
autocomplete="off"
class="w-full pl-8 pr-7 py-2 text-xs rounded-xl border border-slate-200 bg-slate-50 focus:bg-white focus:outline-none focus:border-[#1b5e20] focus:ring-1 focus:ring-[#1b5e20] transition font-medium">
<button type="button" onclick="clearTimesheetVehicleFilter('add')" id="clearAddVehicleSearchBtn" class="hidden absolute right-2.5 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-600 cursor-pointer">
<i class="fa-solid fa-xmark text-xs"></i>
</button>
</div>
<select name="vehicle_id"
id="addVehicleSelect"
required
onchange="onVehicleSelectChanged(this, 'add')"
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-1 focus:ring-[#1b5e20] transition">
<option value="" disabled selected>-- Pilih Lokasi Kerja Terlebih Dahulu --</option>
</select>
</div>
<div id="addVehiclePreview" class="hidden mt-1.5 px-3 py-1.5 rounded-lg bg-emerald-50 border border-emerald-200/80 text-[11px] text-emerald-900 flex items-center justify-between">
<span id="addVehiclePreviewText" class="font-bold"></span>
<span id="addVehicleLastKmText" class="text-emerald-700 font-mono text-[10px]"></span>
</div>
</div>
</div>
<!-- Baris 2: Pengemudi / Operator & Kategori Pekerjaan -->
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
<div>
<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 Heavy Equipment Terlebih Dahulu --</option>
@foreach($operators as $op)
@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: - (Pilih unit terlebih dahulu)</span>
<span class="text-emerald-700 font-semibold" id="addOperatorCurrentFilterText">Filter: Semua</span>
</p>
</div>
<div>
<label class="block text-xs font-bold text-slate-700 mb-1.5">
Kategori Pekerjaan <span class="text-rose-500">*</span>
</label>
<input type="text"
name="activity_type"
id="addActivityType"
list="activityPresetList"
required
placeholder="Contoh: Galian, Loading, Hauling..."
class="w-full text-xs px-3.5 py-2.5 rounded-xl border border-slate-200 bg-white text-slate-800 placeholder-slate-400 focus:outline-none focus:border-[#1b5e20] focus:ring-1 focus:ring-[#1b5e20] transition">
</div>
</div>
<!-- Baris 3: Tanggal & Jam Mulai -->
<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">
Tanggal <span class="text-rose-500">*</span>
</label>
<input type="date"
name="date"
id="addDate"
value="{{ date('Y-m-d') }}"
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">
</div>
<div>
<label class="block text-xs font-bold text-slate-700 mb-1.5">
Jam Mulai <span class="text-rose-500">*</span>
</label>
<input type="time"
name="start_time"
id="addStartTime"
value="{{ date('H:i') }}"
required
class="w-full text-xs px-3.5 py-2.5 rounded-xl border border-slate-200 bg-white text-slate-800 font-mono font-bold focus:outline-none focus:border-[#1b5e20] focus:ring-1 focus:ring-[#1b5e20] transition">
</div>
</div>
<!-- Baris 4: Meter Awal & Meter Akhir (Finish HM) -->
<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">
Meter Awal (Start Meter) <span class="text-rose-500">*</span>
</label>
<div class="relative">
<input type="number"
step="0.01"
name="start_meter"
id="addStartMeter"
required
placeholder="0.00"
class="w-full text-xs pl-3.5 pr-14 py-2.5 rounded-xl border border-slate-200 bg-white text-slate-800 font-mono font-bold focus:outline-none focus:border-[#1b5e20] focus:ring-1 focus:ring-[#1b5e20] transition">
<span id="addMeterUnitLabel" class="absolute right-3.5 top-1/2 -translate-y-1/2 text-xs font-extrabold text-slate-400">HM</span>
</div>
</div>
<div>
<label class="block text-xs font-bold text-slate-700 mb-1.5 flex items-center justify-between">
<span>Meter Akhir (Finish HM/KM)</span>
<span class="text-[10px] text-emerald-700 font-semibold">Otomatis / Opsional</span>
</label>
<div class="relative">
<input type="number"
step="0.01"
name="end_meter"
id="addEndMeter"
placeholder="Dihitung otomatis jika kosong"
class="w-full text-xs pl-3.5 pr-14 py-2.5 rounded-xl border border-slate-200 bg-white text-slate-800 font-mono font-bold focus:outline-none focus:border-[#1b5e20] focus:ring-1 focus:ring-[#1b5e20] transition">
<span id="addEndMeterUnitLabel" class="absolute right-3.5 top-1/2 -translate-y-1/2 text-xs font-extrabold text-slate-400">HM</span>
</div>
<p class="text-[10px] text-slate-400 mt-1">
<i class="fa-solid fa-clock text-emerald-600 mr-0.5"></i> 1 HM = 1 Jam. Dihitung otomatis saat entri berikutnya diinput.
</p>
</div>
</div>
<!-- Baris 4b: Satuan Meteran & Status Akhir Unit -->
<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">
Satuan Meteran <span class="text-rose-500">*</span>
</label>
<select name="meter_type" id="addMeterType" required 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-1 focus:ring-[#1b5e20] transition">
<option value="HM">HM (Hour Meter)</option>
<option value="KM">KM (Odometer)</option>
</select>
</div>
<div>
<label class="block text-xs font-bold text-slate-700 mb-1.5">
Status Akhir Unit <span class="text-rose-500">*</span>
</label>
<select name="status" required 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-1 focus:ring-[#1b5e20] transition">
<option value="Operation">Operation (Siap Jalan)</option>
<option value="Standby">Standby (Tersedia / Siaga)</option>
<option value="Breakdown">Breakdown (Kendala / Rusak)</option>
<option value="Maintenance">Maintenance (Servis Rutin)</option>
</select>
</div>
</div>
<input type="hidden" name="shift" value="Shift Siang">
<!-- Baris 6: Rincian Tugas & Catatan -->
<div>
<label class="block text-xs font-bold text-slate-700 mb-1.5">
Rincian Tugas / Catatan Pekerjaan <span class="text-slate-400 font-normal">(Opsional)</span>
</label>
<textarea name="task_description"
rows="2"
placeholder="Keterangan rincian tugas atau catatan foreman..."
class="w-full text-xs px-3.5 py-2.5 rounded-xl border border-slate-200 bg-white text-slate-800 placeholder-slate-400 focus:outline-none focus:border-[#1b5e20] focus:ring-1 focus:ring-[#1b5e20] transition resize-none"></textarea>
</div>
<!-- Tombol Submit Modal -->
<div class="flex items-center justify-end gap-2.5 pt-3 border-t border-slate-100">
<button type="button" onclick="closeAddModal()" class="px-4 py-2.5 rounded-xl text-xs font-bold text-slate-600 hover:text-slate-800 hover:bg-slate-100 transition cursor-pointer">
Batal
</button>
<button type="submit" class="bg-[#1b5e20] hover:bg-[#144919] text-white px-5 py-2.5 rounded-xl text-xs font-bold transition shadow-xs flex items-center gap-2 cursor-pointer">
<i class="fa-solid fa-floppy-disk text-xs"></i>
<span>Simpan Timesheet</span>
</button>
</div>
</form>
</div>
</div>
</div>
@endif
<!-- ========================================== -->
<!-- MODAL DETAIL TIMESHEET HEAVY EQUIPMENT -->
<!-- ========================================== -->
<div id="detailTimesheetModal" class="hidden fixed inset-0 z-50 overflow-y-auto" style="display: none;">
<div class="fixed inset-0 bg-slate-900/60 backdrop-blur-xs transition-opacity" onclick="closeDetailModal()"></div>
<div class="flex min-h-full items-center justify-center p-4">
<div class="relative w-full max-w-lg bg-white rounded-2xl shadow-2xl border border-slate-100 overflow-hidden transform transition-all">
<!-- Modal Header -->
<div class="flex items-center justify-between px-6 py-4 border-b border-slate-100">
<div>
<h3 class="text-sm font-extrabold text-slate-900 flex items-center gap-2">
<span class="w-2 h-2 rounded-full bg-slate-400"></span>
Detail Riwayat Timesheet
</h3>
<p id="detailTimesheetNo" class="font-mono text-xs text-emerald-700 font-bold mt-0.5"></p>
</div>
<button type="button" onclick="closeDetailModal()" class="w-8 h-8 rounded-lg text-slate-400 hover:text-slate-600 hover:bg-slate-100 flex items-center justify-center transition">
<i class="fa-solid fa-xmark text-sm"></i>
</button>
</div>
<!-- Modal Body (Grid Data Rinci) -->
<div class="p-6 space-y-3 text-xs">
<div class="grid grid-cols-2 gap-3 p-3 bg-slate-50 rounded-xl border border-slate-200/60">
<div>
<span class="text-[10px] font-bold uppercase text-slate-400 block">Tanggal & Shift</span>
<span id="detailDateShift" class="font-bold text-slate-800"></span>
</div>
<div>
<span class="text-[10px] font-bold uppercase text-slate-400 block">Status Operasi</span>
<span id="detailStatus" class="font-bold text-slate-800"></span>
</div>
</div>
<div class="grid grid-cols-2 gap-3 p-3 bg-slate-50 rounded-xl border border-slate-200/60">
<div>
<span class="text-[10px] font-bold uppercase text-slate-400 block">Heavy Equipment</span>
<span id="detailUnit" class="font-bold text-slate-800"></span>
</div>
<div>
<span class="text-[10px] font-bold uppercase text-slate-400 block">Operator Bertugas</span>
<span id="detailOperator" class="font-bold text-slate-800"></span>
</div>
</div>
<div class="grid grid-cols-2 gap-3 p-3 bg-slate-50 rounded-xl border border-slate-200/60">
<div>
<span class="text-[10px] font-bold uppercase text-slate-400 block">Meter Awal (Start Meter)</span>
<span id="detailMeter" class="font-mono font-bold text-slate-800"></span>
</div>
<div>
<span class="text-[10px] font-bold uppercase text-slate-400 block">Jam Mulai Kerja</span>
<span id="detailStartTime" class="font-mono font-bold text-emerald-700 text-sm"></span>
</div>
</div>
<div class="p-3 bg-slate-50 rounded-xl border border-slate-200/60 space-y-2">
<div>
<span class="text-[10px] font-bold uppercase text-slate-400 block">Lokasi & Tipe Aktivitas</span>
<div class="font-bold text-slate-800 flex items-center space-x-1.5 mt-0.5">
<i class="fa-solid fa-location-dot text-[#1b5e20] text-xs"></i>
<span id="detailLocation"></span>
<span class="text-slate-300">&bull;</span>
<span id="detailActivity" class="text-emerald-700 font-semibold"></span>
</div>
</div>
<div>
<span class="text-[10px] font-bold uppercase text-slate-400 block">Uraian Tugas / Catatan</span>
<p id="detailTask" class="text-slate-600 mt-0.5 italic"></p>
</div>
</div>
</div>
<!-- Modal Footer -->
<div class="px-6 py-3.5 bg-slate-50/70 border-t border-slate-100 flex justify-end">
<button type="button" onclick="closeDetailModal()" class="px-4 py-2 rounded-xl text-xs font-bold text-slate-700 bg-white border border-slate-200 hover:bg-slate-100 transition cursor-pointer">
Tutup
</button>
</div>
</div>
</div>
</div>
<!-- ========================================== -->
<!-- 2. MODAL EDIT TIMESHEET HEAVY EQUIPMENT -->
<!-- ========================================== -->
<div id="editTimesheetModal" class="hidden fixed inset-0 z-50 overflow-y-auto" style="display: none;">
<div class="fixed inset-0 bg-slate-900/60 backdrop-blur-xs transition-opacity" onclick="closeEditModal()"></div>
<div class="flex min-h-full items-center justify-center p-4">
<div class="relative w-full max-w-2xl bg-white rounded-2xl shadow-xl border border-slate-100 overflow-hidden transform transition-all">
<!-- Modal Header -->
<div class="flex items-center justify-between px-6 py-4 border-b border-slate-100">
<div>
<h3 class="text-sm font-extrabold text-slate-900 flex items-center gap-2">
<span class="w-2 h-2 rounded-full bg-amber-500"></span>
Edit Timesheet Heavy Equipment
</h3>
<p id="editTimesheetSubtitle" class="text-xs text-slate-500 font-mono mt-0.5">Koreksi data jam kerja atau aktivitas operasional.</p>
</div>
<button type="button" onclick="closeEditModal()" class="w-8 h-8 rounded-lg text-slate-400 hover:text-slate-600 hover:bg-slate-100 flex items-center justify-center transition">
<i class="fa-solid fa-xmark text-sm"></i>
</button>
</div>
<!-- Form Edit Timesheet -->
<form id="editTimesheetForm" method="POST" action="" class="p-6 space-y-4">
@csrf
@method('PUT')
<!-- Baris 1: Lokasi Kerja & Heavy Equipment -->
<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 flex items-center justify-between">
<span>Lokasi Kerja <span class="text-rose-500">*</span></span>
<span class="sr-only">Tentukan Lokasi Dulu</span>
<span class="text-[10px] text-emerald-700 font-semibold">Bisa ketik / pilih</span>
</label>
<div class="relative">
<input type="text"
id="editLocationInput"
name="location"
list="editLocationsDatalist"
required
autocomplete="off"
placeholder="Pilih atau ketik lokasi kerja..."
oninput="onTimesheetLocationTyped(this.value, 'edit')"
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-1 focus:ring-[#1b5e20] transition">
<datalist id="editLocationsDatalist">
<option value="[Semua Unit]">[Semua Lokasi / Tampilkan Semua Unit]</option>
@foreach($unitLocations as $locName => $count)
<option value="{{ $locName }}">{{ $locName }} ({{ $count }} Unit Ready)</option>
@endforeach
@foreach($locationSuggestions as $suggLoc)
@if(!isset($unitLocations[$suggLoc]))
<option value="{{ $suggLoc }}">{{ $suggLoc }}</option>
@endif
@endforeach
</datalist>
</div>
<input type="hidden" id="editFinalLocation" value="">
<p class="text-[10px] text-slate-400 mt-1">
Pilih dari daftar atau ketik lokasi baru (otomatis tersimpan).
</p>
</div>
<div>
<label class="block text-xs font-bold text-slate-700 mb-1.5 flex items-center justify-between">
<span>Heavy Equipment <span class="text-rose-500">*</span></span>
<span id="editUnitCounterBadge" class="text-[10px] font-semibold text-emerald-700 bg-emerald-50 px-2 py-0.5 rounded border border-emerald-200 hidden"></span>
</label>
<div class="space-y-1.5">
<div class="relative">
<i class="fa-solid fa-magnifying-glass absolute left-3 top-1/2 -translate-y-1/2 text-slate-400 text-xs"></i>
<input type="text"
id="editVehicleSearch"
placeholder="Ketik untuk filter unit (kode / merek)..."
oninput="filterTimesheetVehicleOptions(this.value, 'edit')"
autocomplete="off"
class="w-full pl-8 pr-7 py-2 text-xs rounded-xl border border-slate-200 bg-slate-50 focus:bg-white focus:outline-none focus:border-[#1b5e20] focus:ring-1 focus:ring-[#1b5e20] transition font-medium">
<button type="button" onclick="clearTimesheetVehicleFilter('edit')" id="clearEditVehicleSearchBtn" class="hidden absolute right-2.5 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-600 cursor-pointer">
<i class="fa-solid fa-xmark text-xs"></i>
</button>
</div>
<select name="vehicle_id"
id="editVehicleSelect"
required
onchange="onVehicleSelectChanged(this, 'edit')"
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-1 focus:ring-[#1b5e20] transition">
<option value="" disabled selected>-- Pilih Lokasi Kerja Terlebih Dahulu --</option>
</select>
</div>
<div id="editVehiclePreview" class="hidden mt-1.5 px-3 py-1.5 rounded-lg bg-emerald-50 border border-emerald-200/80 text-[11px] text-emerald-900 flex items-center justify-between">
<span id="editVehiclePreviewText" class="font-bold"></span>
<span id="editVehicleLastKmText" class="text-emerald-700 font-mono text-[10px]"></span>
</div>
</div>
</div>
<!-- Baris 2: Pengemudi / Operator & Kategori Pekerjaan -->
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
<div>
<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 Heavy Equipment Terlebih Dahulu --</option>
@foreach($operators as $op)
@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: - (Pilih unit terlebih dahulu)</span>
<span class="text-emerald-700 font-semibold" id="editOperatorCurrentFilterText">Filter: Semua</span>
</p>
</div>
<div>
<label class="block text-xs font-bold text-slate-700 mb-1.5">
Kategori Pekerjaan <span class="text-rose-500">*</span>
</label>
<input type="text"
name="activity_type"
id="editActivityType"
list="activityPresetList"
required
placeholder="Contoh: Galian, Loading, Hauling..."
class="w-full text-xs px-3.5 py-2.5 rounded-xl border border-slate-200 bg-white text-slate-800 placeholder-slate-400 focus:outline-none focus:border-[#1b5e20] focus:ring-1 focus:ring-[#1b5e20] transition">
</div>
</div>
<!-- Baris 3: Tanggal & Jam Mulai -->
<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">
Tanggal <span class="text-rose-500">*</span>
</label>
<input type="date"
name="date"
id="editDate"
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">
</div>
<div>
<label class="block text-xs font-bold text-slate-700 mb-1.5">
Jam Mulai <span class="text-rose-500">*</span>
</label>
<input type="time"
name="start_time"
id="editStartTime"
required
class="w-full text-xs px-3.5 py-2.5 rounded-xl border border-slate-200 bg-white text-slate-800 font-mono font-bold focus:outline-none focus:border-[#1b5e20] focus:ring-1 focus:ring-[#1b5e20] transition">
</div>
</div>
<!-- Baris 4: Meter Awal & Meter Akhir (Finish HM) -->
<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">
Meter Awal (Start Meter) <span class="text-rose-500">*</span>
</label>
<div class="relative">
<input type="number"
step="0.01"
name="start_meter"
id="editStartMeter"
required
placeholder="0.00"
class="w-full text-xs pl-3.5 pr-14 py-2.5 rounded-xl border border-slate-200 bg-white text-slate-800 font-mono font-bold focus:outline-none focus:border-[#1b5e20] focus:ring-1 focus:ring-[#1b5e20] transition">
<span id="editMeterUnitLabel" class="absolute right-3.5 top-1/2 -translate-y-1/2 text-xs font-extrabold text-slate-400">HM</span>
</div>
</div>
<div>
<label class="block text-xs font-bold text-slate-700 mb-1.5 flex items-center justify-between">
<span>Meter Akhir (Finish HM/KM)</span>
<span class="text-[10px] text-emerald-700 font-semibold">Otomatis / Opsional</span>
</label>
<div class="relative">
<input type="number"
step="0.01"
name="end_meter"
id="editEndMeter"
placeholder="Dihitung otomatis jika kosong"
class="w-full text-xs pl-3.5 pr-14 py-2.5 rounded-xl border border-slate-200 bg-white text-slate-800 font-mono font-bold focus:outline-none focus:border-[#1b5e20] focus:ring-1 focus:ring-[#1b5e20] transition">
<span id="editEndMeterUnitLabel" class="absolute right-3.5 top-1/2 -translate-y-1/2 text-xs font-extrabold text-slate-400">HM</span>
</div>
<p class="text-[10px] text-slate-400 mt-1">
<i class="fa-solid fa-clock text-emerald-600 mr-0.5"></i> 1 HM = 1 Jam. Dihitung otomatis saat entri berikutnya diinput.
</p>
</div>
</div>
<!-- Baris 4b: Satuan Meteran & Status Akhir Unit -->
<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">
Satuan Meteran <span class="text-rose-500">*</span>
</label>
<select name="meter_type" id="editMeterType" required 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-1 focus:ring-[#1b5e20] transition">
<option value="HM">HM (Hour Meter)</option>
<option value="KM">KM (Odometer)</option>
</select>
</div>
<div>
<label class="block text-xs font-bold text-slate-700 mb-1.5">
Status Akhir Unit <span class="text-rose-500">*</span>
</label>
<select name="status" id="editStatus" required 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-1 focus:ring-[#1b5e20] transition">
<option value="Operation">Operation (Siap Jalan)</option>
<option value="Standby">Standby (Tersedia / Siaga)</option>
<option value="Breakdown">Breakdown (Kendala / Rusak)</option>
<option value="Maintenance">Maintenance (Servis Rutin)</option>
</select>
</div>
</div>
<!-- Baris 5: Shift (disimpan otomatis) -->
<input type="hidden" name="shift" id="editShift" value="Shift Siang">
<!-- Baris 6: Deskripsi & Catatan -->
<div>
<label class="block text-xs font-bold text-slate-700 mb-1.5">
Rincian Tugas / Catatan Pekerjaan <span class="text-slate-400 font-normal">(Opsional)</span>
</label>
<textarea name="task_description"
id="editTaskDescription"
rows="2"
placeholder="Keterangan rincian tugas atau catatan foreman..."
class="w-full text-xs px-3.5 py-2.5 rounded-xl border border-slate-200 bg-white text-slate-800 placeholder-slate-400 focus:outline-none focus:border-[#1b5e20] focus:ring-1 focus:ring-[#1b5e20] transition resize-none"></textarea>
</div>
<!-- Tombol Submit Edit -->
<div class="flex items-center justify-end gap-2.5 pt-3 border-t border-slate-100">
<button type="button" onclick="closeEditModal()" class="px-4 py-2.5 rounded-xl text-xs font-bold text-slate-600 hover:text-slate-800 hover:bg-slate-100 transition cursor-pointer">
Batal
</button>
<button type="submit" class="bg-amber-600 hover:bg-amber-700 text-white px-5 py-2.5 rounded-xl text-xs font-bold transition shadow-xs flex items-center gap-2 cursor-pointer">
<i class="fa-solid fa-floppy-disk text-xs"></i>
<span>Simpan Perubahan</span>
</button>
</div>
</form>
</div>
</div>
</div>
<!-- ========================================== -->
<!-- 3. MODAL HAPUS TIMESHEET -->
<!-- ========================================== -->
<div id="deleteTimesheetModal" class="hidden fixed inset-0 z-50 overflow-y-auto" style="display: none;">
<div class="fixed inset-0 bg-slate-900/60 backdrop-blur-xs transition-opacity" onclick="closeDeleteModal()"></div>
<div class="flex min-h-full items-center justify-center p-4">
<div class="relative w-full max-w-sm bg-white rounded-2xl shadow-2xl border border-slate-100 p-6 text-center">
<div class="w-12 h-12 rounded-full bg-rose-100 text-rose-600 flex items-center justify-center text-xl mx-auto mb-3">
<i class="fa-solid fa-triangle-exclamation"></i>
</div>
<h3 class="text-sm font-bold text-slate-900 mb-1">Hapus Data Timesheet?</h3>
<p class="text-xs text-slate-500 mb-4">
Apakah Anda yakin ingin menghapus timesheet <span id="deleteTimesheetNo" class="font-mono font-bold text-rose-600">-</span>? Tindakan ini tidak dapat dibatalkan.
</p>
<form id="deleteTimesheetForm" method="POST" action="">
@csrf
@method('DELETE')
<div class="flex items-center justify-center space-x-2">
<button type="button" onclick="closeDeleteModal()" class="px-4 py-2 rounded-xl text-xs font-bold text-slate-600 hover:bg-slate-100 transition">
Batal
</button>
<button type="submit" class="bg-rose-600 hover:bg-rose-700 text-white px-5 py-2 rounded-xl text-xs font-bold transition shadow-xs">
Ya, Hapus
</button>
</div>
</form>
</div>
</div>
</div>
<!-- Datalist Rekomendasi Heavy Equipment -->
<datalist id="unitSupportDatalist">
@foreach($unitSupports as $u)
<option value="{{ $u->code }}">{{ $u->brand_type }} (Terakhir: {{ number_format($u->current_km ?? 0, 1, ',', '.') }})</option>
@endforeach
</datalist>
<!-- Datalist Rekomendasi Kategori Pekerjaan -->
<datalist id="activityPresetList">
@foreach($activityTypes as $act)
<option value="{{ $act }}">
@endforeach
</datalist>
<!-- Datalist Rekomendasi Lokasi Global -->
<datalist id="locationPresetList">
@foreach($locationSuggestions as $loc)
<option value="{{ $loc }}">
@endforeach
</datalist>
<!-- ========================================================================= -->
<!-- MODAL POPUP: PANDUAN HALAMAN (TIMESHEET HEAVY EQUIPMENT) -->
<!-- ========================================================================= -->
<div id="guideModal"
class="hidden fixed inset-0 z-50 bg-slate-900/60 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 transform transition-all my-8">
<!-- Header Modal -->
<div class="flex items-center justify-between pb-4 border-b border-slate-100">
<div class="flex items-center space-x-3">
<div class="w-10 h-10 rounded-2xl bg-emerald-50 text-[#1b5e20] flex items-center justify-center text-lg shadow-2xs">
<i class="fa-solid fa-book-open"></i>
</div>
<div>
<h3 class="text-base font-extrabold text-slate-900 tracking-tight">
Panduan Timesheet Heavy Equipment
</h3>
<p class="text-xs text-slate-500 font-medium">
Tata cara pencatatan jam kerja mesin & operasional alat berat
</p>
</div>
</div>
<button type="button"
onclick="closeGuideModal()"
class="w-8 h-8 rounded-full bg-slate-100 hover:bg-slate-200 text-slate-400 hover:text-slate-600 flex items-center justify-center transition cursor-pointer">
<i class="fa-solid fa-xmark text-sm"></i>
</button>
</div>
<!-- Konten Panduan -->
<div class="py-5 space-y-4 text-xs text-slate-600 leading-relaxed max-h-[60vh] overflow-y-auto pr-1">
<div class="p-3.5 rounded-2xl bg-emerald-50/60 border border-emerald-100/80">
<h4 class="font-bold text-[#1b5e20] text-xs flex items-center mb-1">
<i class="fa-solid fa-stopwatch mr-1.5"></i>
1. Satuan Meter Mesin (HM vs KM)
</h4>
<p class="text-slate-600">
Sistem mendeteksi satuan secara otomatis: Dump Truck (DT) menggunakan satuan Kilometer (<strong>KM</strong>), sedangkan Excavator, Dozer, Crane, dsb. menggunakan Hour Meter (<strong>HM</strong>).
</p>
</div>
<div class="p-3.5 rounded-2xl bg-slate-50 border border-slate-100">
<h4 class="font-bold text-slate-800 text-xs flex items-center mb-1">
<i class="fa-solid fa-filter mr-1.5 text-emerald-600"></i>
2. Filter Lokasi Kerja & Unit Ready
</h4>
<p class="text-slate-600">
Saat menambah timesheet, pilih lokasi kerja terlebih dahulu. Daftar Heavy Equipment akan disaring otomatis menampilkan unit yang berada pada lokasi tersebut.
</p>
</div>
<div class="p-3.5 rounded-2xl bg-slate-50 border border-slate-100">
<h4 class="font-bold text-slate-800 text-xs flex items-center mb-1">
<i class="fa-solid fa-triangle-exclamation mr-1.5 text-amber-500"></i>
3. Status Operasi & Breakdown
</h4>
<p class="text-slate-600">
Pilih status <strong>Operation</strong> untuk unit yang bekerja produktif, <strong>Standby</strong> jika mesin ready namun menunggu arahan, atau <strong>Breakdown</strong> jika mengalami kerusakan.
</p>
</div>
<div class="p-3.5 rounded-2xl bg-slate-50 border border-slate-100">
<h4 class="font-bold text-slate-800 text-xs flex items-center mb-1">
<i class="fa-solid fa-file-export mr-1.5 text-blue-600"></i>
4. Ekspor Data Laporan
</h4>
<p class="text-slate-600">
Gunakan tombol <strong>Ekspor Timesheet</strong> di pojok kanan atas untuk mengunduh laporan rekapitulasi dalam format PDF atau Excel (.xlsx) sesuai filter yang aktif.
</p>
</div>
</div>
<!-- Footer Modal -->
<div class="pt-4 border-t border-slate-100 flex justify-end">
<button type="button"
onclick="closeGuideModal()"
class="bg-[#1b5e20] hover:bg-[#144919] text-white px-5 py-2.5 rounded-xl text-xs font-bold transition shadow-sm cursor-pointer">
Mengerti
</button>
</div>
</div>
</div>
@endsection
@section('scripts')
<script>
window.unitSupportsData = @json($unitSupports);
window.allOperatorsData = @json($operators);
window.unitOperatorsMap = @json($unitOperatorsMap);
// Filter Segmented Operator (Semua / Karyawan / Sukon) & Sinkronisasi Kualifikasi SIMPER Alat Berat
function filterOperatorSelect(type, mode, preserveSelectedId) {
const selectId = mode === 'edit' ? 'editOperatorSelect' : 'addOperatorSelect';
const select = document.getElementById(selectId);
if (!select) return;
type = type || 'all';
select.setAttribute('data-active-filter', type);
// 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 vehSelect = document.getElementById(`${mode}VehicleSelect`);
const selectedVehicleId = vehSelect ? vehSelect.value : null;
const currentVal = preserveSelectedId !== undefined ? String(preserveSelectedId) : select.value;
const options = select.querySelectorAll('option');
let visibleCount = 0;
// 1. Jika belum ada unit Heavy Equipment yang dipilih
if (!selectedVehicleId) {
options.forEach(opt => {
if (!opt.value) {
opt.textContent = '-- Pilih Heavy Equipment Terlebih Dahulu --';
opt.hidden = false;
} else {
opt.hidden = true;
}
});
select.value = '';
const countHelp = document.getElementById(`${mode}OperatorCountHelp`);
if (countHelp) {
const spanFirst = countHelp.querySelector('span:first-child');
if (spanFirst) {
spanFirst.textContent = 'Total personil: - (Pilih unit terlebih dahulu)';
spanFirst.className = 'text-slate-400';
}
}
return;
}
// 2. Dapatkan daftar ID operator yang kualifikasi SIMPER-nya aktif untuk unit ini
const eligibleMap = window.unitOperatorsMap || {};
const eligibleIds = eligibleMap[selectedVehicleId] || [];
const eligibleSet = new Set(eligibleIds.map(String));
if (preserveSelectedId !== undefined && preserveSelectedId !== null && preserveSelectedId !== '') {
eligibleSet.add(String(preserveSelectedId));
}
const hasEligible = eligibleSet.size > 0;
options.forEach(opt => {
if (!opt.value) {
if (!hasEligible) {
opt.textContent = '-- Tidak ada operator dengan SIMPER untuk unit ini --';
} else {
opt.textContent = `-- Pilih Operator (${eligibleSet.size} Memenuhi SIMPER) --`;
}
opt.hidden = false;
return;
}
const opId = String(opt.value);
const isEligible = eligibleSet.has(opId);
const optType = opt.getAttribute('data-type') || 'Karyawan';
let typeMatch = false;
if (type === 'all') {
typeMatch = true;
} else if (type === 'Karyawan') {
typeMatch = optType === 'Karyawan';
} else if (type === 'Sukon') {
typeMatch = optType === 'Sukon';
} else {
typeMatch = optType.toLowerCase() === type.toLowerCase();
}
const match = isEligible && typeMatch;
opt.hidden = !match;
if (match) visibleCount++;
});
// Update total count & status
const countHelp = document.getElementById(`${mode}OperatorCountHelp`);
if (countHelp) {
const spanFirst = countHelp.querySelector('span:first-child');
if (spanFirst) {
if (!hasEligible) {
spanFirst.textContent = 'Total personil: 0 (Tidak ada SIMPER yang cocok)';
spanFirst.className = 'text-rose-600 font-semibold';
} else {
spanFirst.textContent = `Total personil: ${visibleCount} dari ${eligibleSet.size} operator SIMPER aktif`;
spanFirst.className = 'text-slate-500';
}
}
}
// 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 = '';
}
} else {
select.value = '';
}
}
// 1. Dropdown Ekspor
function toggleExportMenu(event) {
event.stopPropagation();
const menu = document.getElementById('exportMenu');
menu.style.display = (menu.style.display === 'none' || menu.style.display === '') ? 'block' : 'none';
}
document.addEventListener('click', function(e) {
const menu = document.getElementById('exportMenu');
const trigger = document.getElementById('btnExportTrigger');
if (menu && menu.style.display === 'block' && trigger && !trigger.contains(e.target)) {
menu.style.display = 'none';
}
});
// 2. Modal Tambah Timesheet
function openAddModal() {
const modal = document.getElementById('addTimesheetModal');
if (modal) {
// Reset form pilihan lokasi & unit
const addLocInput = document.getElementById('addLocationInput');
if (addLocInput) addLocInput.value = '';
const finalLoc = document.getElementById('addFinalLocation');
if (finalLoc) finalLoc.value = '';
const endMeter = document.getElementById('addEndMeter');
if (endMeter) endMeter.value = '';
onTimesheetLocationTyped('', 'add');
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();
const month = String(now.getMonth() + 1).padStart(2, '0');
const day = String(now.getDate()).padStart(2, '0');
const hours = String(now.getHours()).padStart(2, '0');
const minutes = String(now.getMinutes()).padStart(2, '0');
const addDate = document.getElementById('addDate');
if (addDate) addDate.value = `${year}-${month}-${day}`;
const startTime = document.getElementById('addStartTime');
if (startTime) startTime.value = `${hours}:${minutes}`;
modal.classList.remove('hidden');
modal.style.display = 'block';
}
}
function closeAddModal() {
const modal = document.getElementById('addTimesheetModal');
if (modal) {
modal.classList.add('hidden');
modal.style.display = 'none';
}
}
// Modal Detail Riwayat Timesheet
function openDetailModalFromBtn(btn) {
try {
const ts = JSON.parse(btn.getAttribute('data-timesheet'));
document.getElementById('detailTimesheetNo').textContent = ts.timesheet_no;
document.getElementById('detailDateShift').textContent = `${ts.date} • ${ts.shift}`;
document.getElementById('detailUnit').textContent = `${ts.code} - ${ts.brand_type}`;
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) {
detailStartTimeEl.textContent = ts.start_time ? (ts.start_time.substring(0, 5) + ' WIB') : '08:00 WIB';
}
document.getElementById('detailLocation').textContent = ts.location;
document.getElementById('detailActivity').textContent = ts.activity_type;
document.getElementById('detailTask').textContent = ts.task_description !== '-' ? `"${ts.task_description}"` : '-';
document.getElementById('detailStatus').textContent = ts.status;
const modal = document.getElementById('detailTimesheetModal');
modal.classList.remove('hidden');
modal.style.display = 'block';
} catch (err) {
console.error('Failed to parse detail timesheet data:', err);
}
}
function closeDetailModal() {
const modal = document.getElementById('detailTimesheetModal');
if (modal) {
modal.classList.add('hidden');
modal.style.display = 'none';
}
}
// 3. Modal Edit Timesheet
function openEditModalFromBtn(btn) {
try {
const raw = btn.getAttribute('data-timesheet');
const ts = JSON.parse(raw);
openEditModal(ts);
} catch (err) {
console.error('Failed to parse timesheet data:', err);
}
}
function openEditModal(ts) {
const form = document.getElementById('editTimesheetForm');
form.action = `/qma/support-timesheet/${ts.id}`;
const unitCode = ts.vehicle ? ts.vehicle.code : (ts.vehicle_code || '');
document.getElementById('editTimesheetSubtitle').textContent = `No: ${ts.timesheet_no} (${unitCode || '-'})`;
// 1. Sinkronisasi Lokasi Kerja
const locInput = document.getElementById('editLocationInput');
const finalLoc = document.getElementById('editFinalLocation');
const targetLoc = ts.location || '';
if (locInput) locInput.value = targetLoc;
if (finalLoc) finalLoc.value = targetLoc;
// Filter unit pada lokasi ini dengan memilih ts.vehicle_id
onTimesheetLocationTyped(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
const d = ts.date ? ts.date.split('T')[0] : '';
document.getElementById('editDate').value = d;
const startTimeInput = document.getElementById('editStartTime');
if (startTimeInput) {
startTimeInput.value = ts.start_time ? ts.start_time.substring(0, 5) : '08:00';
}
document.getElementById('editShift').value = ts.shift || 'Shift Siang';
document.getElementById('editMeterType').value = ts.meter_type || 'HM';
document.getElementById('editStartMeter').value = ts.start_meter;
const editEndMeter = document.getElementById('editEndMeter');
if (editEndMeter) {
editEndMeter.value = (ts.end_meter && ts.end_meter !== '-') ? ts.end_meter.replace('.', '').replace(',', '.') : '';
}
document.getElementById('editActivityType').value = ts.activity_type;
document.getElementById('editStatus').value = ts.status || 'Operation';
document.getElementById('editTaskDescription').value = ts.task_description || ts.notes || '';
updateMeterUnitLabels('edit');
const modal = document.getElementById('editTimesheetModal');
modal.classList.remove('hidden');
modal.style.display = 'block';
}
function closeEditModal() {
const modal = document.getElementById('editTimesheetModal');
modal.classList.add('hidden');
modal.style.display = 'none';
}
// 4. Modal Hapus Timesheet
function openDeleteModal(id, no) {
document.getElementById('deleteTimesheetForm').action = `/qma/support-timesheet/${id}`;
document.getElementById('deleteTimesheetNo').textContent = no;
const modal = document.getElementById('deleteTimesheetModal');
modal.classList.remove('hidden');
modal.style.display = 'block';
}
function closeDeleteModal() {
const modal = document.getElementById('deleteTimesheetModal');
modal.classList.add('hidden');
modal.style.display = 'none';
}
// 5. Handler saat Lokasi Kerja Diketik / Dipilih via Datalist Input
function onTimesheetLocationTyped(val, prefix, preselectVehicleId = null) {
const trimmed = (val || '').trim();
const finalLoc = document.getElementById(`${prefix}FinalLocation`);
if (finalLoc) {
finalLoc.value = (trimmed === '[Semua Unit]' || trimmed === 'ALL') ? '' : trimmed;
}
onTimesheetLocationChanged(trimmed, prefix, preselectVehicleId);
}
function onTimesheetLocationChanged(selectedLoc, prefix, preselectVehicleId = null) {
const finalLocation = document.getElementById(`${prefix}FinalLocation`);
const vehicleSelect = document.getElementById(`${prefix}VehicleSelect`);
const counterBadge = document.getElementById(`${prefix}UnitCounterBadge`);
const previewEl = document.getElementById(`${prefix}VehiclePreview`);
if (!vehicleSelect) return;
if (finalLocation) {
finalLocation.value = (selectedLoc === 'ALL' || selectedLoc === '[Semua Unit]' || !selectedLoc) ? '' : selectedLoc;
}
const allUnits = window.unitSupportsData || [];
let filteredUnits = [];
if (!selectedLoc || selectedLoc === 'ALL' || selectedLoc === '[Semua Unit]') {
filteredUnits = allUnits;
} else {
const norm = selectedLoc.trim().toLowerCase();
filteredUnits = allUnits.filter(u => {
const uLoc = (u.location || 'Site Kerinci').trim().toLowerCase();
return uLoc === norm || uLoc.includes(norm);
});
// Jika lokasi yang diketik adalah lokasi baru, tetap tampilkan semua unit agar bisa dipilih
if (filteredUnits.length === 0) {
filteredUnits = allUnits;
}
}
// Jika dalam mode edit dan preselectVehicleId tidak ditemukan di lokasi ini, sertakan unit tersebut
if (preselectVehicleId) {
const foundInFiltered = filteredUnits.some(u => String(u.id) === String(preselectVehicleId));
if (!foundInFiltered) {
const extra = allUnits.find(u => String(u.id) === String(preselectVehicleId));
if (extra) filteredUnits.unshift(extra);
}
}
// Update badge counter
if (counterBadge) {
counterBadge.classList.remove('hidden');
counterBadge.textContent = `${filteredUnits.length} Unit Ready`;
}
// Reset input filter unit realtime
const vSearch = document.getElementById(`${prefix}VehicleSearch`);
if (vSearch) vSearch.value = '';
const vClear = document.getElementById(`clear${prefix === 'add' ? 'Add' : 'Edit'}VehicleSearchBtn`);
if (vClear) vClear.classList.add('hidden');
// Render option heavy equipment
vehicleSelect.innerHTML = '';
const defaultPrompt = document.createElement('option');
defaultPrompt.value = '';
defaultPrompt.disabled = true;
defaultPrompt.textContent = filteredUnits.length > 0
? `-- Pilih Heavy Equipment (${filteredUnits.length} Unit Ready) --`
: `-- Tidak ada unit (${allUnits.length} Unit Total) --`;
vehicleSelect.appendChild(defaultPrompt);
let hasSelected = false;
filteredUnits.forEach(u => {
const opt = document.createElement('option');
opt.value = u.id;
opt.setAttribute('data-km', u.current_km ?? 0);
opt.setAttribute('data-code', u.code || '');
opt.setAttribute('data-brand', u.brand_type || '');
opt.setAttribute('data-location', u.location || 'Site Kerinci');
const lastKm = parseFloat(u.current_km) || 0;
const code = (u.code || '').toUpperCase();
const meterType = code.startsWith('DT') ? 'KM' : 'HM';
const kmFormatted = lastKm.toLocaleString('id-ID', {minimumFractionDigits: 1, maximumFractionDigits: 2});
opt.textContent = `${u.code} - ${u.brand_type || ''} (Meter: ${kmFormatted} ${meterType})`;
if (preselectVehicleId && String(u.id) === String(preselectVehicleId)) {
opt.selected = true;
hasSelected = true;
}
vehicleSelect.appendChild(opt);
});
if (hasSelected) {
onVehicleSelectChanged(vehicleSelect, prefix);
} else {
defaultPrompt.selected = true;
if (previewEl) previewEl.classList.add('hidden');
filterOperatorSelect('all', prefix);
}
}
// 6. Handler saat Custom Lokasi Diketik
function onCustomLocationTyped(val, prefix) {
const finalLocation = document.getElementById(`${prefix}FinalLocation`);
if (finalLocation) {
finalLocation.value = val.trim();
}
}
/**
* Filter Realtime Dropdown Heavy Equipment pada Timesheet berdasarkan Ketikan
*/
function filterTimesheetVehicleOptions(query, prefix) {
const select = document.getElementById(`${prefix}VehicleSelect`);
const clearBtn = document.getElementById(`clear${prefix === 'add' ? 'Add' : 'Edit'}VehicleSearchBtn`);
const badge = document.getElementById(`${prefix}UnitCounterBadge`);
if (!select) return;
const q = (query || '').trim().toLowerCase();
if (clearBtn) {
clearBtn.classList.toggle('hidden', !q);
}
let visibleCount = 0;
let firstMatch = null;
Array.from(select.options).forEach(opt => {
if (!opt.value) {
opt.hidden = false;
return;
}
const code = (opt.getAttribute('data-code') || '').toLowerCase();
const brand = (opt.getAttribute('data-brand') || '').toLowerCase();
const loc = (opt.getAttribute('data-location') || '').toLowerCase();
const text = opt.textContent.toLowerCase();
const match = text.includes(q) || code.includes(q) || brand.includes(q) || loc.includes(q);
opt.hidden = !match;
if (match) {
visibleCount++;
if (!firstMatch) firstMatch = opt;
}
});
if (badge) {
badge.classList.remove('hidden');
badge.textContent = q ? `${visibleCount} Unit Cocok` : `${visibleCount} Unit Ready`;
}
if (q && visibleCount === 1 && firstMatch) {
select.value = firstMatch.value;
onVehicleSelectChanged(select, prefix);
}
}
function clearTimesheetVehicleFilter(prefix) {
const input = document.getElementById(`${prefix}VehicleSearch`);
if (input) input.value = '';
filterTimesheetVehicleOptions('', prefix);
}
// 7. Handler saat Heavy Equipment Dipilih
function onVehicleSelectChanged(selectEl, prefix) {
const opt = selectEl.options[selectEl.selectedIndex];
if (!opt || !opt.value) return;
const code = opt.getAttribute('data-code') || '';
const brand = opt.getAttribute('data-brand') || '';
const lastKm = parseFloat(opt.getAttribute('data-km')) || 0;
const unitLocation = opt.getAttribute('data-location') || 'Site Kerinci';
// Tampilkan info preview
const previewEl = document.getElementById(`${prefix}VehiclePreview`);
const previewText = document.getElementById(`${prefix}VehiclePreviewText`);
const lastKmText = document.getElementById(`${prefix}VehicleLastKmText`);
if (previewEl) {
previewEl.classList.remove('hidden');
previewText.textContent = `${code} - ${brand}`;
lastKmText.textContent = `Meter Terakhir: ${lastKm.toLocaleString('id-ID', {minimumFractionDigits: 1, maximumFractionDigits: 2})}`;
}
// Auto-isi start_meter jika kosong atau 0
const startMeterInput = document.getElementById(`${prefix}StartMeter`);
if (startMeterInput && (!startMeterInput.value || parseFloat(startMeterInput.value) === 0)) {
startMeterInput.value = lastKm.toFixed(2);
}
// Auto-deteksi tipe meteran: DT -> KM, selainnya -> HM
const meterTypeSelect = document.getElementById(`${prefix}MeterType`);
if (meterTypeSelect) {
if (code.toUpperCase().startsWith('DT')) {
meterTypeSelect.value = 'KM';
} else {
meterTypeSelect.value = 'HM';
}
updateMeterUnitLabels(prefix);
}
// Jika lokasi kerja dipilih 'ALL' atau kosong, sinkronkan ke lokasi unit
const locInput = document.getElementById(`${prefix}LocationInput`);
const finalLoc = document.getElementById(`${prefix}FinalLocation`);
if (locInput && (!locInput.value || locInput.value === 'ALL' || locInput.value === '[Semua Unit]')) {
locInput.value = unitLocation;
}
if (finalLoc && (!finalLoc.value || finalLoc.value === 'ALL' || finalLoc.value === '[Semua Unit]')) {
finalLoc.value = unitLocation;
}
// Otomatis filter operator sesuai izin SIMPER aktif untuk alat berat ini
const opSelect = document.getElementById(`${prefix}OperatorSelect`);
const currentOpFilter = opSelect ? (opSelect.getAttribute('data-active-filter') || 'all') : 'all';
filterOperatorSelect(currentOpFilter, prefix);
}
function updateMeterUnitLabels(prefix) {
const typeEl = document.getElementById(`${prefix}MeterType`);
const unit = typeEl ? typeEl.value : 'HM';
const label = document.getElementById(`${prefix}MeterUnitLabel`);
if (label) {
label.textContent = unit;
}
const endLabel = document.getElementById(`${prefix}EndMeterUnitLabel`);
if (endLabel) {
endLabel.textContent = unit;
}
}
document.getElementById('addMeterType')?.addEventListener('change', () => updateMeterUnitLabels('add'));
document.getElementById('editMeterType')?.addEventListener('change', () => updateMeterUnitLabels('edit'));
// 8. Pencarian Server-Side Otomatis (Global ke seluruh database)
const timesheetFilterForm = document.getElementById('timesheetFilterForm');
const timesheetSearchInput = document.getElementById('timesheetSearchInput');
let timesheetSearchDebounce = null;
if (timesheetSearchInput && timesheetSearchInput.value) {
timesheetSearchInput.focus();
const len = timesheetSearchInput.value.length;
timesheetSearchInput.setSelectionRange(len, len);
}
timesheetSearchInput?.addEventListener('input', function() {
clearTimeout(timesheetSearchDebounce);
timesheetSearchDebounce = setTimeout(function() {
timesheetFilterForm?.submit();
}, 500);
});
function escapeHtml(str) {
const div = document.createElement('div');
div.textContent = str;
return div.innerHTML;
}
// 9. Modal Panduan Halaman (Data Timesheet Heavy Equipment)
function openGuideModal() {
const modal = document.getElementById('guideModal');
if (modal) {
modal.classList.remove('hidden');
document.documentElement.classList.add('modal-open');
document.body.classList.add('modal-open');
}
}
function closeGuideModal() {
const modal = document.getElementById('guideModal');
if (modal) {
modal.classList.add('hidden');
document.documentElement.classList.remove('modal-open');
document.body.classList.remove('modal-open');
}
}
// 10. Keyboard ESC Listener untuk Semua Modal
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape') {
closeGuideModal();
closeAddModal();
closeEditModal();
closeDetailModal();
closeDeleteModal();
const exportMenu = document.getElementById('exportMenu');
if (exportMenu) exportMenu.style.display = 'none';
}
});
</script>
@endsection