From cb284a7432069a7f7637dcd690c79b8fa82651ce Mon Sep 17 00:00:00 2001 From: Ray1111-aa Date: Tue, 20 Oct 2026 15:24:11 +0700 Subject: [PATCH] feat(p2h): add single unit inspection review export to pdf and excel --- .../Qma/P2hInspectionController.php | 105 ++++++ app/Services/P2hInspectionPdfExporter.php | 357 ++++++++++++++++++ resources/views/qma/p2h_index.blade.php | 16 +- resources/views/qma/p2h_show.blade.php | 63 +++- resources/views/qma/p2h_summary.blade.php | 9 +- routes/web.php | 2 + tests/Feature/QmaActivityAndP2hExportTest.php | 48 +++ 7 files changed, 577 insertions(+), 23 deletions(-) create mode 100644 app/Services/P2hInspectionPdfExporter.php diff --git a/app/Http/Controllers/Qma/P2hInspectionController.php b/app/Http/Controllers/Qma/P2hInspectionController.php index 232f9df..f8d8142 100644 --- a/app/Http/Controllers/Qma/P2hInspectionController.php +++ b/app/Http/Controllers/Qma/P2hInspectionController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Qma; use App\Http\Controllers\Controller; use App\Models\P2hRecord; use App\Models\Vehicle; +use App\Services\P2hInspectionPdfExporter; use App\Services\QmaTablePdfExporter; use App\Services\SimpleXlsxExporter; use Carbon\Carbon; @@ -610,6 +611,110 @@ class P2hInspectionController extends Controller return view('qma.p2h_show', compact('record', 'groupedItems')); } + /** + * Ekspor lembar hasil pemeriksaan P2H tunggal ke format PDF resmi. + */ + public function exportSinglePdf(int $id): Response + { + $record = P2hRecord::with(['vehicle', 'employee', 'template', 'validator', 'items'])->findOrFail($id); + + $pdfBinary = P2hInspectionPdfExporter::generate($record); + $fileName = 'Lembar_P2H_' . ($record->vehicle->code ?? 'Unit') . '_' . $record->transaction_no . '.pdf'; + + return response($pdfBinary, 200, [ + 'Content-Type' => 'application/pdf', + 'Content-Disposition' => 'inline; filename="' . $fileName . '"', + 'Content-Length' => strlen($pdfBinary), + 'Cache-Control' => 'private, max-age=0, must-revalidate', + 'Pragma' => 'public', + ]); + } + + /** + * Ekspor lembar hasil pemeriksaan P2H tunggal ke format Excel (.xlsx). + */ + public function exportSingleExcel(int $id): Response + { + $record = P2hRecord::with(['vehicle', 'employee', 'template', 'validator', 'items'])->findOrFail($id); + + $statusLabel = match($record->validation_status) { + 'approved' => 'Disetujui QMA (Approved)', + 'rejected' => 'Ditolak (Rejected)', + default => 'Menunggu Review QMA (Pending)', + }; + + $conditionLabel = $record->hasDefects() + ? 'Ada Kerusakan (' . $record->defect_count . ' Item Rusak)' + : 'Normal (Laik Operasi)'; + + $printedAt = now()->translatedFormat('d F Y, H:i'); + + $metaLines = [ + 'No. Transaksi: ' . $record->transaction_no . ' | Waktu Pemeriksaan: ' . ($record->inspected_at ? $record->inspected_at->format('d/m/Y H:i') : '-') . ' WIB | Shift: ' . $record->shift, + 'Unit Support: ' . ($record->vehicle->code ?? '-') . ' (' . ($record->vehicle->brand_type ?? '-') . ') | Kategori: ' . ($record->vehicle->unit_category ?? ($record->template->name ?? '-')) . ' | Lokasi: ' . ($record->vehicle->location ?? '-'), + 'Operator: ' . ($record->employee->name ?? '-') . ' (NIK: ' . ($record->employee->nik ?? '-') . ') | SIMPER: ' . ($record->employee?->simper_expired_at ? $record->employee->simper_expired_at->format('d/m/Y') : 'Non-SIMPER'), + 'Hour Meter (HM): ' . number_format($record->start_hm, 1, ',', '.') . ' HM | Kondisi Fisik: ' . $conditionLabel . ' | Status QMA: ' . $statusLabel, + 'Verifikator: ' . ($record->validator->name ?? '-') . ' | Waktu Validasi: ' . ($record->validated_at ? $record->validated_at->format('d/m/Y H:i') . ' WIB' : '-'), + 'Catatan Verifikator: ' . ($record->validation_notes ?: '-') . ' | Catatan Operator: ' . ($record->general_notes ?: '-'), + 'Dicetak pada: ' . $printedAt . ' WIB', + ]; + + $headers = [ + 'No' => 6, + 'Seksi / Komponen' => 26, + 'Butir Pemeriksaan' => 45, + 'Status Kondisi' => 18, + 'Nilai Jawaban' => 20, + 'Catatan / Temuan Kerusakan' => 38, + ]; + + $rows = []; + $idx = 1; + foreach ($record->items as $item) { + $cond = strtolower((string)$item->condition_status); + $condText = match($cond) { + 'baik' => 'BAIK', + 'rusak' => 'RUSAK', + default => '-', + }; + + $rows[] = [ + $idx++, + $item->section ?? '-', + $item->title ?? '-', + $condText, + $item->answer_value ?? '-', + $item->notes ?? '-', + ]; + } + + $alignments = [ + 0 => 'center', + 1 => 'left', + 2 => 'left', + 3 => 'center', + 4 => 'center', + 5 => 'left', + ]; + + $xlsxContent = SimpleXlsxExporter::create( + 'LEMBAR PEMERIKSAAN HARIAN (P2H) UNIT SUPPORT - ' . ($record->vehicle->code ?? 'UNIT'), + $metaLines, + $headers, + $rows, + $alignments + ); + + $fileName = 'P2H_' . ($record->vehicle->code ?? 'Unit') . '_' . $record->transaction_no . '.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', + ]); + } + /** * Approval / Persetujuan lembar P2H oleh Admin QMA. */ diff --git a/app/Services/P2hInspectionPdfExporter.php b/app/Services/P2hInspectionPdfExporter.php new file mode 100644 index 0000000..cb82453 --- /dev/null +++ b/app/Services/P2hInspectionPdfExporter.php @@ -0,0 +1,357 @@ +logoPath) && file_exists($this->logoPath)) { + $this->Image($this->logoPath, 15, 10, 36); + } else { + $this->SetXY(15, 10); + $this->SetFont('Arial', 'B', 13); + $this->SetTextColor(27, 94, 32); + $this->Cell(60, 6, 'KERINCI HYDROPOWER', 0, 0, 'L'); + } + + // 2. Branding Sistem di Kanan Atas + $this->SetXY(100, 10); + $this->SetFont('Arial', 'B', 15); + $this->SetTextColor(27, 94, 32); // #1b5e20 Green + $this->Cell(95, 5, 'RKM - KMH', 0, 1, 'R'); + + $this->SetXY(100, 15.5); + $this->SetFont('Arial', 'B', 7); + $this->SetTextColor(71, 85, 105); // #475569 Slate + $this->Cell(95, 4, 'PT KERINCI MERANGIN HIDRO (350 MW)', 0, 1, 'R'); + + // 3. Banner Navy Header Dokumen + $this->SetY(21); + $this->SetFillColor(6, 33, 63); // #06213f Dark Navy + $this->Rect(15, 21, 180, 13, 'F'); + + // Teks Judul Banner + $this->SetXY(18, 22.5); + $this->SetFont('Arial', 'B', 10); + $this->SetTextColor(255, 255, 255); + $this->Cell(115, 5, 'LEMBAR PEMERIKSAAN HARIAN (P2H) UNIT SUPPORT', 0, 1, 'L'); + + $this->SetXY(18, 27.5); + $this->SetFont('Arial', '', 7); + $this->SetTextColor(203, 213, 225); // #cbd5e1 Slate + $this->Cell(115, 4.5, 'Quality & Maintenance Assets (QMA) - Checklist Kelaikan Alat Berat', 0, 1, 'L'); + + // Nomor Transaksi & Waktu di Kanan Banner + $this->SetXY(125, 22.5); + $this->SetFont('Arial', 'B', 8.5); + $this->SetTextColor(255, 255, 255); + $this->Cell(66, 5, $this->record->transaction_no, 0, 1, 'R'); + + $this->SetXY(125, 27.5); + $this->SetFont('Arial', 'I', 7); + $this->SetTextColor(203, 213, 225); + $this->Cell(66, 4.5, $this->record->inspected_at ? $this->record->inspected_at->format('d/m/Y H:i') . ' WIB' : '-', 0, 1, 'R'); + + $this->SetY(36); + } + + public function Footer(): void + { + $this->SetY(-13); + $this->SetFont('Arial', '', 7); + $this->SetTextColor(148, 163, 184); + + $leftText = 'No: ' . $this->record->transaction_no . ' | Unit: ' . ($this->record->vehicle->code ?? '-') . ' | Dicetak: ' . now()->translatedFormat('d F Y, H:i') . ' WIB'; + $this->Cell(130, 5, $leftText, 0, 0, 'L'); + $this->Cell(50, 5, 'Halaman ' . $this->PageNo() . ' dari {nb}', 0, 0, 'R'); + } + + /** + * Generate Binary PDF String Lembar Pemeriksaan P2H. + */ + public static function generate(P2hRecord $record): string + { + $pdf = new self('P', 'mm', 'A4'); + $pdf->AliasNbPages(); + $pdf->record = $record; + $pdf->logoPath = public_path('images/logo-kerinci.png'); + + $pdf->SetMargins(15, 10, 15); + $pdf->AddPage(); + $pdf->SetAutoPageBreak(true, 15); + + // ------------------------------------------------------------- + // RINGKASAN METADATA UNIT & OPERATOR (Halaman 1) + // ------------------------------------------------------------- + $pdf->SetY(37); + + // Box 1: Identitas Unit Support + $pdf->SetFillColor(248, 250, 252); // #f8fafc + $pdf->SetDrawColor(226, 232, 240); // #e2e8f0 + $pdf->Rect(15, 37, 58, 30, 'DF'); + + $pdf->SetXY(17, 38.5); + $pdf->SetFont('Arial', 'B', 7); + $pdf->SetTextColor(180, 83, 9); // Amber + $pdf->Cell(54, 4, 'UNIT SUPPORT', 0, 1, 'L'); + + $pdf->SetX(17); + $pdf->SetFont('Arial', 'B', 10); + $pdf->SetTextColor(15, 23, 42); + $pdf->Cell(54, 5, $record->vehicle->code ?? '-', 0, 1, 'L'); + + $pdf->SetX(17); + $pdf->SetFont('Arial', '', 7.5); + $pdf->SetTextColor(71, 85, 105); + $pdf->Cell(54, 4, mb_strimwidth($record->vehicle->brand_type ?? '-', 0, 32, '...'), 0, 1, 'L'); + + $pdf->SetX(17); + $pdf->SetFont('Arial', '', 7); + $catText = 'Kat: ' . ($record->vehicle->unit_category ?? ($record->template->name ?? '-')); + $pdf->Cell(54, 4, mb_strimwidth($catText, 0, 34, '...'), 0, 1, 'L'); + + $pdf->SetX(17); + $locText = 'Lokasi: ' . ($record->vehicle->location ?? '-'); + $pdf->Cell(54, 4, mb_strimwidth($locText, 0, 34, '...'), 0, 1, 'L'); + + // Box 2: Identitas Operator + $pdf->Rect(76, 37, 58, 30, 'DF'); + + $pdf->SetXY(78, 38.5); + $pdf->SetFont('Arial', 'B', 7); + $pdf->SetTextColor(4, 120, 87); // Emerald + $pdf->Cell(54, 4, 'OPERATOR (HSE)', 0, 1, 'L'); + + $pdf->SetX(78); + $pdf->SetFont('Arial', 'B', 9.5); + $pdf->SetTextColor(15, 23, 42); + $pdf->Cell(54, 5, mb_strimwidth($record->employee->name ?? '-', 0, 26, '...'), 0, 1, 'L'); + + $pdf->SetX(78); + $pdf->SetFont('Arial', '', 7.5); + $pdf->SetTextColor(71, 85, 105); + $pdf->Cell(54, 4, 'NIK: ' . ($record->employee->nik ?? '-'), 0, 1, 'L'); + + $pdf->SetX(78); + $pdf->SetFont('Arial', '', 7); + $divText = 'Divisi: ' . ($record->employee->division ?? '-'); + $pdf->Cell(54, 4, mb_strimwidth($divText, 0, 34, '...'), 0, 1, 'L'); + + $pdf->SetX(78); + $simperText = 'SIMPER: ' . ($record->employee?->simper_expired_at ? $record->employee->simper_expired_at->format('d/m/Y') : 'Non-SIMPER'); + $pdf->Cell(54, 4, mb_strimwidth($simperText, 0, 34, '...'), 0, 1, 'L'); + + // Box 3: Data Operasional & Validasi QMA + $pdf->Rect(137, 37, 58, 30, 'DF'); + + $pdf->SetXY(139, 38.5); + $pdf->SetFont('Arial', 'B', 7); + $pdf->SetTextColor(2, 132, 199); // Sky blue + $pdf->Cell(54, 4, 'OPERASIONAL & KELAIKAN', 0, 1, 'L'); + + $pdf->SetX(139); + $pdf->SetFont('Arial', 'B', 8.5); + $pdf->SetTextColor(15, 23, 42); + $pdf->Cell(54, 4.5, $record->shift . ' | ' . number_format($record->start_hm, 1, ',', '.') . ' HM', 0, 1, 'L'); + + $pdf->SetX(139); + $pdf->SetFont('Arial', 'B', 7.5); + if ($record->hasDefects()) { + $pdf->SetTextColor(190, 18, 60); // Red + $pdf->Cell(54, 4, 'Kondisi: ' . $record->defect_count . ' Item Rusak', 0, 1, 'L'); + } else { + $pdf->SetTextColor(4, 120, 87); // Green + $pdf->Cell(54, 4, 'Kondisi: LAIK OPERASI (Baik)', 0, 1, 'L'); + } + + $pdf->SetX(139); + $pdf->SetFont('Arial', 'B', 7.5); + if ($record->isApproved()) { + $pdf->SetTextColor(4, 120, 87); + $pdf->Cell(54, 4, 'Status: Disetujui (Approved)', 0, 1, 'L'); + } elseif ($record->isRejected()) { + $pdf->SetTextColor(190, 18, 60); + $pdf->Cell(54, 4, 'Status: Ditolak (Rejected)', 0, 1, 'L'); + } else { + $pdf->SetTextColor(180, 83, 9); + $pdf->Cell(54, 4, 'Status: Menunggu Review QMA', 0, 1, 'L'); + } + + $pdf->SetX(139); + $pdf->SetFont('Arial', '', 7); + $pdf->SetTextColor(100, 116, 139); + $valName = $record->validator?->name ? 'Oleh: ' . mb_strimwidth($record->validator->name, 0, 22, '..') : 'Verifikator: -'; + $pdf->Cell(54, 4, $valName, 0, 1, 'L'); + + // Catatan Verifikator / Catatan Umum (Jika ada) + $nextY = 70; + if ($record->validation_notes || $record->general_notes) { + $notesArr = []; + if ($record->validation_notes) { + $notesArr[] = 'Catatan QMA: ' . $record->validation_notes; + } + if ($record->general_notes) { + $notesArr[] = 'Catatan Operator: ' . $record->general_notes; + } + $notesText = implode(' | ', $notesArr); + + $pdf->SetXY(15, $nextY); + $pdf->SetFillColor(254, 243, 199); // Amber 100 + $pdf->SetDrawColor(251, 191, 36); // Amber 400 + $pdf->SetFont('Arial', 'I', 7.5); + $pdf->SetTextColor(146, 64, 14); // Amber 800 + $pdf->Cell(180, 6, ' ' . mb_strimwidth($notesText, 0, 115, '...'), 1, 1, 'L', true); + $nextY += 8; + } else { + $nextY += 2; + } + + // ------------------------------------------------------------- + // TABEL BUTIR PEMERIKSAAN PRA-HARIAN (P2H) + // ------------------------------------------------------------- + $pdf->SetY($nextY); + $pdf->SetFont('Arial', 'B', 8.5); + $pdf->SetTextColor(15, 23, 42); + $pdf->Cell(180, 5, 'Rincian Lembar Checklist Pemeriksaan Komponen:', 0, 1, 'L'); + + // Header Kolom Tabel + $pdf->SetFillColor(6, 33, 63); // Dark navy + $pdf->SetTextColor(255, 255, 255); + $pdf->SetFont('Arial', 'B', 7.5); + + $pdf->Cell(8, 6.5, 'NO', 0, 0, 'C', true); + $pdf->Cell(38, 6.5, 'SEKSI / KOMPONEN', 0, 0, 'L', true); + $pdf->Cell(68, 6.5, 'BUTIR PEMERIKSAAN', 0, 0, 'L', true); + $pdf->Cell(24, 6.5, 'KONDISI', 0, 0, 'C', true); + $pdf->Cell(42, 6.5, 'CATATAN TEMUAN', 0, 1, 'L', true); + + // Items Loop + $groupedItems = []; + foreach ($record->items as $item) { + $groupedItems[$item->section][] = $item; + } + + $pdf->SetDrawColor(226, 232, 240); + $globalNo = 1; + + foreach ($groupedItems as $sectionTitle => $items) { + // Cek apakah halaman cukup untuk seksi baru + if ($pdf->GetY() > 265) { + $pdf->AddPage(); + } + + // Sub-header Seksi + $pdf->SetFillColor(241, 245, 249); // Slate 100 + $pdf->SetTextColor(30, 41, 59); + $pdf->SetFont('Arial', 'B', 7.5); + $pdf->Cell(180, 5.5, ' [ ' . strtoupper($sectionTitle) . ' ] - ' . count($items) . ' Butir Pemeriksaan', 'TB', 1, 'L', true); + + $fill = false; + foreach ($items as $item) { + if ($pdf->GetY() > 270) { + $pdf->AddPage(); + // Ulangi Header Kolom di halaman baru + $pdf->SetFillColor(6, 33, 63); + $pdf->SetTextColor(255, 255, 255); + $pdf->SetFont('Arial', 'B', 7.5); + $pdf->Cell(8, 6.5, 'NO', 0, 0, 'C', true); + $pdf->Cell(38, 6.5, 'SEKSI / KOMPONEN', 0, 0, 'L', true); + $pdf->Cell(68, 6.5, 'BUTIR PEMERIKSAAN', 0, 0, 'L', true); + $pdf->Cell(24, 6.5, 'KONDISI', 0, 0, 'C', true); + $pdf->Cell(42, 6.5, 'CATATAN TEMUAN', 0, 1, 'L', true); + } + + $pdf->SetFillColor($fill ? 250 : 255, $fill ? 250 : 255, $fill ? 250 : 255); + $pdf->SetTextColor(15, 23, 42); + $pdf->SetFont('Arial', '', 7.5); + + $pdf->Cell(8, 6, $globalNo++, 'B', 0, 'C', $fill); + $pdf->Cell(38, 6, mb_strimwidth($sectionTitle, 0, 24, '...'), 'B', 0, 'L', $fill); + $pdf->Cell(68, 6, mb_strimwidth($item->title, 0, 48, '...'), 'B', 0, 'L', $fill); + + // Kolom Kondisi + $cond = strtolower((string)$item->condition_status); + if ($cond === 'rusak') { + $pdf->SetTextColor(190, 18, 60); // Red + $pdf->SetFont('Arial', 'B', 7.5); + $pdf->Cell(24, 6, 'RUSAK', 'B', 0, 'C', $fill); + } elseif ($cond === 'baik') { + $pdf->SetTextColor(4, 120, 87); // Green + $pdf->SetFont('Arial', 'B', 7.5); + $pdf->Cell(24, 6, 'BAIK', 'B', 0, 'C', $fill); + } else { + $valStr = !empty($item->answer_value) ? $item->answer_value : '-'; + $pdf->SetTextColor(71, 85, 105); + $pdf->SetFont('Arial', '', 7); + $pdf->Cell(24, 6, mb_strimwidth($valStr, 0, 14, '..'), 'B', 0, 'C', $fill); + } + + // Kolom Catatan Temuan + $pdf->SetTextColor(71, 85, 105); + $pdf->SetFont('Arial', $cond === 'rusak' ? 'B' : '', 7); + $noteVal = !empty($item->notes) ? $item->notes : '-'; + $pdf->Cell(42, 6, mb_strimwidth($noteVal, 0, 28, '...'), 'B', 1, 'L', $fill); + + $fill = !$fill; + } + } + + // ------------------------------------------------------------- + // BLOK PENGESAHAN & TANDA TANGAN (3 Kolom) + // ------------------------------------------------------------- + if ($pdf->GetY() > 240) { + $pdf->AddPage(); + } + + $pdf->Ln(6); + $sigY = $pdf->GetY(); + $pdf->SetFont('Arial', 'B', 7.5); + $pdf->SetTextColor(15, 23, 42); + + // Kolom 1: Operator Lapangan + $pdf->SetXY(15, $sigY); + $pdf->Cell(56, 4, 'Diperiksa Oleh (Operator):', 0, 1, 'C'); + $pdf->SetXY(15, $sigY + 16); + $pdf->SetFont('Arial', 'B', 8); + $pdf->Cell(56, 4, '( ' . ($record->employee->name ?? '..................................') . ' )', 0, 1, 'C'); + $pdf->SetFont('Arial', '', 7); + $pdf->SetTextColor(100, 116, 139); + $pdf->Cell(56, 3.5, 'NIK: ' . ($record->employee->nik ?? '-'), 0, 1, 'C'); + + // Kolom 2: Verifikator QMA + $pdf->SetXY(77, $sigY); + $pdf->SetFont('Arial', 'B', 7.5); + $pdf->SetTextColor(15, 23, 42); + $pdf->Cell(56, 4, 'Diverifikasi Oleh (Admin QMA):', 0, 1, 'C'); + $pdf->SetXY(77, $sigY + 16); + $pdf->SetFont('Arial', 'B', 8); + $valName = $record->validator->name ?? 'Admin QMA'; + $pdf->Cell(56, 4, '( ' . $valName . ' )', 0, 1, 'C'); + $pdf->SetFont('Arial', '', 7); + $pdf->SetTextColor(100, 116, 139); + $pdf->Cell(56, 3.5, 'Quality & Maintenance Assets', 0, 1, 'C'); + + // Kolom 3: Pengawas K3 / HSE + $pdf->SetXY(139, $sigY); + $pdf->SetFont('Arial', 'B', 7.5); + $pdf->SetTextColor(15, 23, 42); + $pdf->Cell(56, 4, 'Mengetahui (Pengawas K3/HSE):', 0, 1, 'C'); + $pdf->SetXY(139, $sigY + 16); + $pdf->SetFont('Arial', 'B', 8); + $pdf->Cell(56, 4, '( .............................................. )', 0, 1, 'C'); + $pdf->SetFont('Arial', '', 7); + $pdf->SetTextColor(100, 116, 139); + $pdf->Cell(56, 3.5, 'Safety / HSE Officer', 0, 1, 'C'); + + return $pdf->Output('S'); + } +} diff --git a/resources/views/qma/p2h_index.blade.php b/resources/views/qma/p2h_index.blade.php index ff4e748..9df9aae 100644 --- a/resources/views/qma/p2h_index.blade.php +++ b/resources/views/qma/p2h_index.blade.php @@ -182,10 +182,18 @@ @endif - - - Review - +
+ + + Review + + + + + + + +
@empty diff --git a/resources/views/qma/p2h_show.blade.php b/resources/views/qma/p2h_show.blade.php index 3cd71fd..e444589 100644 --- a/resources/views/qma/p2h_show.blade.php +++ b/resources/views/qma/p2h_show.blade.php @@ -5,28 +5,43 @@ @section('content')
-
- +
+ Kembali ke P2H Unit Support - -
- @if($record->isPending()) - - - Menunggu Approval QMA - - @elseif($record->isApproved()) - - Disetujui (Approved) - - @else - - Ditolak (Rejected) - - @endif + +
+ + + + Cetak / Ekspor PDF + + + + + + Ekspor Excel (.xlsx) + + + +
+ @if($record->isPending()) + + + Menunggu Approval QMA + + @elseif($record->isApproved()) + + Disetujui (Approved) + + @else + + Ditolak (Rejected) + + @endif +
@@ -214,4 +229,16 @@ @endforeach
+ + @endsection diff --git a/resources/views/qma/p2h_summary.blade.php b/resources/views/qma/p2h_summary.blade.php index d4c2fec..97f3a6c 100644 --- a/resources/views/qma/p2h_summary.blade.php +++ b/resources/views/qma/p2h_summary.blade.php @@ -275,7 +275,14 @@ {{ $loop->iteration }} - {{ $us['vehicle']->code ?? '-' }} + @if($us['vehicle']) + + {{ $us['vehicle']->code }} + + + @else + - + @endif {{ $us['vehicle']->brand_type ?? '-' }} diff --git a/routes/web.php b/routes/web.php index efb4f2a..818e93a 100644 --- a/routes/web.php +++ b/routes/web.php @@ -99,6 +99,8 @@ Route::middleware('auth')->group(function () { Route::get('/p2h-summary/export-excel', [P2hInspectionController::class, 'exportSummaryExcel'])->name('p2h.summary.export_excel')->middleware('permission:qma.p2h.view|qma.vehicles.view'); Route::get('/p2h-summary/export-pdf', [P2hInspectionController::class, 'exportSummaryPdf'])->name('p2h.summary.export_pdf')->middleware('permission:qma.p2h.view|qma.vehicles.view'); Route::get('/p2h-records/{id}', [P2hInspectionController::class, 'show'])->name('p2h.show')->middleware('permission:qma.p2h.view|qma.vehicles.view'); + Route::get('/p2h-records/{id}/export-pdf', [P2hInspectionController::class, 'exportSinglePdf'])->name('p2h.export_single_pdf')->middleware('permission:qma.p2h.view|qma.vehicles.view'); + Route::get('/p2h-records/{id}/export-excel', [P2hInspectionController::class, 'exportSingleExcel'])->name('p2h.export_single_excel')->middleware('permission:qma.p2h.view|qma.vehicles.view'); Route::post('/p2h-records/{id}/approve', [P2hInspectionController::class, 'approve'])->name('p2h.approve')->middleware('permission:qma.p2h.approve|qma.vehicles.edit'); Route::post('/p2h-records/{id}/reject', [P2hInspectionController::class, 'reject'])->name('p2h.reject')->middleware('permission:qma.p2h.approve|qma.vehicles.edit'); diff --git a/tests/Feature/QmaActivityAndP2hExportTest.php b/tests/Feature/QmaActivityAndP2hExportTest.php index 82ec164..f969821 100644 --- a/tests/Feature/QmaActivityAndP2hExportTest.php +++ b/tests/Feature/QmaActivityAndP2hExportTest.php @@ -219,13 +219,61 @@ class QmaActivityAndP2hExportTest extends TestCase $this->assertNotEmpty($content); } + public function test_admin_qma_can_export_single_p2h_record_pdf(): void + { + $record = P2hRecord::first(); + + $response = $this->actingAs($this->qmaAdmin) + ->get(route('qma.p2h.export_single_pdf', $record->id)); + + $response->assertStatus(200); + $response->assertHeader('Content-Type', 'application/pdf'); + $this->assertStringContainsString('inline; filename="Lembar_P2H_', (string) $response->headers->get('Content-Disposition')); + + $content = $response->getContent(); + $this->assertStringStartsWith('%PDF-', $content); + $this->assertNotEmpty($content); + } + + public function test_admin_qma_can_export_single_p2h_record_excel(): void + { + $record = P2hRecord::first(); + + $response = $this->actingAs($this->qmaAdmin) + ->get(route('qma.p2h.export_single_excel', $record->id)); + + $response->assertStatus(200); + $response->assertHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); + $this->assertStringContainsString('P2H_', (string) $response->headers->get('Content-Disposition')); + + $content = $response->getContent(); + $this->assertStringStartsWith("PK\x03\x04", $content); + } + + public function test_p2h_show_page_renders_export_buttons(): void + { + $record = P2hRecord::first(); + + $response = $this->actingAs($this->qmaAdmin) + ->get(route('qma.p2h.show', $record->id)); + + $response->assertStatus(200); + $response->assertSee('Cetak / Ekspor PDF'); + $response->assertSee('Ekspor Excel (.xlsx)'); + $response->assertSee(route('qma.p2h.export_single_pdf', $record->id)); + $response->assertSee(route('qma.p2h.export_single_excel', $record->id)); + } + public function test_unauthorized_user_cannot_export_activity_and_p2h(): void { + $record = P2hRecord::first(); $routes = [ route('qma.activity.export_excel'), route('qma.activity.export_pdf'), route('qma.p2h.export_excel'), route('qma.p2h.export_pdf'), + route('qma.p2h.export_single_pdf', $record->id), + route('qma.p2h.export_single_excel', $record->id), ]; foreach ($routes as $routeUrl) {