From 419a2dc18b58f3016eae254820eba6484a780d39 Mon Sep 17 00:00:00 2001 From: Ray1111-aa Date: Wed, 21 Oct 2026 15:14:13 +0700 Subject: [PATCH] feat(qma): add dedicated unit location history page with export, update logo, and clean transfer form labels --- .../Qma/UnitManagementController.php | 198 ++++++++ .../views/qma/unit_location_history.blade.php | 453 ++++++++++++++++++ resources/views/qma/unit_management.blade.php | 12 +- .../views/qma/unit_transfers_create.blade.php | 12 +- .../views/qma/unit_transfers_show.blade.php | 6 +- routes/web.php | 3 + tests/Feature/QmaUnitManagementTest.php | 96 ++++ tests/Feature/QmaUnitTransferTest.php | 1 + 8 files changed, 765 insertions(+), 16 deletions(-) create mode 100644 resources/views/qma/unit_location_history.blade.php diff --git a/app/Http/Controllers/Qma/UnitManagementController.php b/app/Http/Controllers/Qma/UnitManagementController.php index 0501df4..701b3b0 100644 --- a/app/Http/Controllers/Qma/UnitManagementController.php +++ b/app/Http/Controllers/Qma/UnitManagementController.php @@ -262,6 +262,204 @@ class UnitManagementController extends Controller ]); } + /** + * Helper query pencarian riwayat lokasi per unit dengan filter. + */ + protected function getVehicleHistoryQuery(Vehicle $vehicle, Request $request): Builder + { + $query = VehicleLocationHistory::where('vehicle_id', $vehicle->id) + ->with(['user', 'activity.gate']) + ->latest('recorded_at'); + + if ($request->filled('date_from')) { + $query->whereDate('recorded_at', '>=', $request->input('date_from')); + } + + if ($request->filled('date_to')) { + $query->whereDate('recorded_at', '<=', $request->input('date_to')); + } + + if ($request->filled('site_status') && $request->input('site_status') !== 'all') { + $query->where('site_status', $request->input('site_status')); + } + + if ($request->filled('source') && $request->input('source') !== 'all') { + $query->where('source', $request->input('source')); + } + + if ($request->filled('search')) { + $search = trim($request->input('search')); + $query->where(function (Builder $q) use ($search) { + $q->where('location', 'like', "%{$search}%") + ->orWhere('note', 'like', "%{$search}%") + ->orWhere('user_name', 'like', "%{$search}%"); + }); + } + + return $query; + } + + /** + * Tampilan view khusus riwayat pergerakan posisi unit (Halaman Lega & Lengkap). + */ + public function historyView(Request $request, int $id): View + { + $vehicle = Vehicle::trackableUnits()->findOrFail($id); + $query = $this->getVehicleHistoryQuery($vehicle, $request); + + $totalHistories = (clone $query)->count(); + $insideCount = (clone $query)->where('site_status', 'inside_site')->count(); + $outsideCount = (clone $query)->where('site_status', 'outside_site')->count(); + $gateCount = (clone $query)->where('source', 'gate_crossing')->count(); + $transferCount = (clone $query)->where('source', 'transfer')->count(); + $manualCount = (clone $query)->where('source', 'manual')->count(); + + $histories = $query->paginate(20)->withQueryString(); + + return view('qma.unit_location_history', compact( + 'vehicle', + 'histories', + 'totalHistories', + 'insideCount', + 'outsideCount', + 'gateCount', + 'transferCount', + 'manualCount' + )); + } + + /** + * Ekspor riwayat pergerakan posisi unit ke Excel (.xlsx). + */ + public function exportHistoryExcel(Request $request, int $id): Response + { + $vehicle = Vehicle::trackableUnits()->findOrFail($id); + $histories = $this->getVehicleHistoryQuery($vehicle, $request)->get(); + + $metaLines = [ + 'Laporan Riwayat Mutasi Posisi Kendaraan', + "Unit: {$vehicle->code} - {$vehicle->brand_type} (" . ($vehicle->license_plate ?: ($vehicle->serial_number ?: '-')) . ")", + 'Posisi Terkini: ' . ($vehicle->location ?: 'Belum diisi') . ' (' . $vehicle->site_status_label . ')', + 'Waktu Ekspor: ' . Carbon::now()->translatedFormat('d F Y, H:i') . ' WIB', + 'Diekspor Oleh: ' . (auth()->user()?->name ?? 'Admin QMA'), + ]; + + $headers = [ + 'NO' => 6, + 'WAKTU & TANGGAL' => 20, + 'STATUS AREA' => 16, + 'LOKASI TERDATA' => 26, + 'SUMBER MUTASI' => 22, + 'PETUGAS / USER' => 22, + 'KETERANGAN / AUDIT NOTE' => 50, + ]; + + $rows = []; + foreach ($histories as $idx => $h) { + $rows[] = [ + $idx + 1, + $h->recorded_at ? $h->recorded_at->format('d/m/Y H:i') : '-', + $h->site_status_label, + $h->location ?: '-', + $h->source_label, + $h->user_name ?: ($h->user?->name ?? 'Sistem'), + $h->note ?: '-', + ]; + } + + $alignments = [ + 'NO' => 'center', + 'WAKTU & TANGGAL' => 'center', + 'STATUS AREA' => 'center', + 'SUMBER MUTASI' => 'center', + ]; + + $xlsxContent = SimpleXlsxExporter::create( + "Riwayat Posisi {$vehicle->code}", + $headers, + $rows, + $metaLines, + $alignments + ); + + $cleanCode = preg_replace('/[^A-Za-z0-9_-]/', '_', $vehicle->code); + $fileName = 'Riwayat_Posisi_' . $cleanCode . '_' . Carbon::now()->format('Ymd_His') . '.xlsx'; + + return response($xlsxContent, 200, [ + 'Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + 'Content-Disposition' => 'attachment; filename="' . $fileName . '"', + 'Content-Length' => strlen($xlsxContent), + 'Cache-Control' => 'max-age=0', + ]); + } + + /** + * Ekspor riwayat pergerakan posisi unit ke format PDF resmi. + */ + public function exportHistoryPdf(Request $request, int $id): Response + { + $vehicle = Vehicle::trackableUnits()->findOrFail($id); + $histories = $this->getVehicleHistoryQuery($vehicle, $request)->get(); + + $metaLeft = [ + 'Unit' => "{$vehicle->code} ({$vehicle->brand_type})", + 'Identitas' => $vehicle->license_plate ?: ($vehicle->serial_number ?: '-'), + 'Kategori' => $vehicle->isLightVehicle() ? 'Light Vehicle' : 'Unit Support', + 'Posisi Saat Ini' => ($vehicle->location ?: 'Belum diisi') . ' (' . $vehicle->site_status_label . ')', + ]; + + $metaRight = [ + 'Waktu Cetak' => Carbon::now()->translatedFormat('d F Y, H:i') . ' WIB', + 'Dicetak Oleh' => auth()->user()?->name ?? 'Admin QMA', + 'Total Riwayat' => $histories->count() . ' Mutasi', + ]; + + $columns = [ + ['title' => 'NO', 'width' => 10, 'align' => 'C', 'bold' => true], + ['title' => 'WAKTU', 'width' => 32, 'align' => 'C'], + ['title' => 'STATUS', 'width' => 26, 'align' => 'C', 'is_status' => true], + ['title' => 'LOKASI', 'width' => 45, 'align' => 'L', 'max_char' => 28], + ['title' => 'SUMBER', 'width' => 36, 'align' => 'C'], + ['title' => 'PETUGAS', 'width' => 32, 'align' => 'L', 'max_char' => 20], + ['title' => 'KETERANGAN', 'width' => 96, 'align' => 'L', 'max_char' => 64], + ]; + + $rows = []; + foreach ($histories as $idx => $h) { + $rows[] = [ + $idx + 1, + $h->recorded_at ? $h->recorded_at->format('d/m/Y H:i') : '-', + $h->site_status_label, + $h->location ?: '-', + $h->source_label, + $h->user_name ?: ($h->user?->name ?? 'Sistem'), + $h->note ?: '-', + ]; + } + + $title = "Riwayat Posisi Unit {$vehicle->code}"; + $subtitle = "Audit Trail Pergerakan Armada Proyek Kerinci Hydropower (350 MW)"; + + $pdfBinary = QmaTablePdfExporter::generate( + $title, + $subtitle, + 'SISTEM QMA RKM-KMH', + $metaLeft, + $metaRight, + $columns, + $rows + ); + + $cleanCode = preg_replace('/[^A-Za-z0-9_-]/', '_', $vehicle->code); + $fileName = 'Riwayat_Posisi_' . $cleanCode . '_' . Carbon::now()->format('Ymd_His') . '.pdf'; + + return response($pdfBinary, 200, [ + 'Content-Type' => 'application/pdf', + 'Content-Disposition' => 'inline; filename="' . $fileName . '"', + 'Content-Length' => strlen($pdfBinary), + ]); + } + /** * Ekspor data monitoring posisi unit ke format Excel (.xlsx). */ diff --git a/resources/views/qma/unit_location_history.blade.php b/resources/views/qma/unit_location_history.blade.php new file mode 100644 index 0000000..941a175 --- /dev/null +++ b/resources/views/qma/unit_location_history.blade.php @@ -0,0 +1,453 @@ +@extends('layouts.app') + +@section('title', 'Riwayat Posisi ' . $vehicle->code . ' - Admin QMA | PT Kerinci Merangin Hidro') + +@section('content') +
+ + + + +
+
+
+ + + Kembali ke Posisi Unit + + • + + RIWAYAT POSISI & AUDIT TRAIL + +
+

+ Riwayat Posisi: {{ $vehicle->code }} + + {{ $vehicle->isLightVehicle() ? 'Light Vehicle' : 'Unit Support' }} + +

+

+ Jejak pergerakan lokasi unit, riwayat mutasi gerbang, update manual QMA, dan mobilisasi transfer alat berat. +

+
+ + +
+ +
+ + +
+ + @if(!$vehicle->isLightVehicle()) + + + + Pindah Unit Ini (BAST) + + @endif +
+
+ + + + +
+
+ +
+ +
+ @if($vehicle->photo_url) + {{ $vehicle->code }} +
+ +
+ @else + + @endif +
+ + +
+
+ + {{ $vehicle->code }} + + + {{ $vehicle->license_plate ?: ($vehicle->serial_number ?: 'Tanpa Plat/Seri') }} + + + {{ $vehicle->status ?: 'Standby' }} + +
+

+ {{ $vehicle->brand_type ?: 'Unit Tanpa Merek' }} +

+

+ Kepemilikan: {{ $vehicle->ownership ?: 'PT Kerinci Merangin Hidro' }} + @if($vehicle->parent) + • + Tipe Induk: {{ $vehicle->parent->brand_type }} + @endif +

+
+
+ + +
+
+ + Posisi Saat Ini + + + + {{ $vehicle->site_status_label }} + +
+
+ {{ $vehicle->location ?: 'Belum diisi' }} +
+
+ Diperbarui: {{ $vehicle->location_updated_at ? $vehicle->location_updated_at->translatedFormat('d M Y, H:i') : '-' }} + Oleh: {{ $vehicle->location_updated_by ?: '-' }} +
+
+
+
+ + + + +
+ +
+ Total Mutasi +
{{ number_format($totalHistories) }}
+ Rekam jejak +
+ + +
+ Di Dalam Site +
{{ number_format($insideCount) }}
+ Area Proyek KMH +
+ + +
+ Di Luar Site +
{{ number_format($outsideCount) }}
+ Luar Area Kerja +
+ + +
+ Transfer (BAST) +
{{ number_format($transferCount) }}
+ Relokasi Alat Berat +
+ + +
+ Pos Gerbang +
{{ number_format($gateCount) }}
+ Aktivitas Satpam +
+ + +
+ Manual QMA +
{{ number_format($manualCount) }}
+ Input Admin +
+
+ + + + +
+
+
+ +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ +
+ + +
+
+
+ + +
+ + Menampilkan {{ $histories->total() }} riwayat mutasi posisi + +
+ @if(request()->hasAny(['date_from', 'date_to', 'site_status', 'source', 'search'])) + + Reset + + @endif + +
+
+
+
+ + + + +
+
+

+ + Tabel Rinci Riwayat Posisi +

+ Diurutkan dari mutasi paling terbaru +
+ +
+ + + + + + + + + + + + + + @forelse($histories as $idx => $history) + + + + + + + + + + + + + + + + + + + + + + + @empty + + + + @endforelse + +
NoWaktu & TanggalStatus AreaTitik LokasiSumber PembaruanPetugas / PencatatCatatan / Keterangan
+ {{ $histories->firstItem() + $idx }} + +
+ {{ $history->recorded_at ? $history->recorded_at->translatedFormat('d M Y, H:i') : '-' }} WIB +
+
+ {{ $history->recorded_at ? $history->recorded_at->diffForHumans() : '-' }} +
+
+ + + {{ $history->site_status_label }} + + +
+ + {{ $history->location ?: '-' }} +
+
+ @if($history->source === 'gate_crossing') + + + Pos Gerbang + + @elseif($history->source === 'transfer') + + + Transfer BAST + + @else + + + Manual QMA + + @endif + +
+ {{ $history->user_name ?: ($history->user?->name ?? 'Sistem RKM') }} +
+ @if($history->activity) +
+ Trx: {{ $history->activity->transaction_no }} +
+ @endif +
+

+ {{ $history->note ?: '-' }} +

+
+
+
+ +
+

Belum Ada Riwayat Tercatat

+

+ Unit ini belum memiliki riwayat mutasi posisi atau pencarian filter tidak menemukan data yang cocok. +

+ @if(request()->hasAny(['date_from', 'date_to', 'site_status', 'source', 'search'])) + + Reset Semua Filter + + @endif +
+
+
+ + @if($histories->hasPages()) +
+ {{ $histories->links() }} +
+ @endif +
+ +
+ + + + + + + +@endsection diff --git a/resources/views/qma/unit_management.blade.php b/resources/views/qma/unit_management.blade.php index b0559fb..14f7cd2 100644 --- a/resources/views/qma/unit_management.blade.php +++ b/resources/views/qma/unit_management.blade.php @@ -427,14 +427,12 @@ @endcan - + diff --git a/resources/views/qma/unit_transfers_create.blade.php b/resources/views/qma/unit_transfers_create.blade.php index cc6ac94..ec9b9c8 100644 --- a/resources/views/qma/unit_transfers_create.blade.php +++ b/resources/views/qma/unit_transfers_create.blade.php @@ -62,12 +62,12 @@ - +
- +
@@ -93,10 +93,10 @@

Memilih lokasi awal akan memfilter unit alat berat yang berada di titik tersebut.

- +