feat(p2h): add single unit inspection review export to pdf and excel

This commit is contained in:
Ray1111-aa
2026-10-20 15:24:11 +07:00
parent 9f9bedebe9
commit cb284a7432
7 changed files with 577 additions and 23 deletions
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Qma;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Models\P2hRecord; use App\Models\P2hRecord;
use App\Models\Vehicle; use App\Models\Vehicle;
use App\Services\P2hInspectionPdfExporter;
use App\Services\QmaTablePdfExporter; use App\Services\QmaTablePdfExporter;
use App\Services\SimpleXlsxExporter; use App\Services\SimpleXlsxExporter;
use Carbon\Carbon; use Carbon\Carbon;
@@ -610,6 +611,110 @@ class P2hInspectionController extends Controller
return view('qma.p2h_show', compact('record', 'groupedItems')); 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. * Approval / Persetujuan lembar P2H oleh Admin QMA.
*/ */
+357
View File
@@ -0,0 +1,357 @@
<?php
namespace App\Services;
use App\Models\P2hRecord;
use Carbon\Carbon;
use FPDF;
class P2hInspectionPdfExporter extends FPDF
{
public P2hRecord $record;
public string $logoPath = '';
public function Header(): void
{
// 1. Logo Perusahaan di Kiri Atas
if (!empty($this->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');
}
}
+9 -1
View File
@@ -182,10 +182,18 @@
@endif @endif
</td> </td>
<td class="py-3.5 px-4 text-center whitespace-nowrap"> <td class="py-3.5 px-4 text-center whitespace-nowrap">
<a href="{{ route('qma.p2h.show', $rec->id) }}" class="inline-flex items-center space-x-1 px-3 py-1.5 rounded-xl text-xs font-bold text-white bg-[#1b5e20] hover:bg-[#144918] shadow-sm transition"> <div class="inline-flex items-center gap-1.5">
<a href="{{ route('qma.p2h.show', $rec->id) }}" class="inline-flex items-center space-x-1 px-2.5 py-1.5 rounded-xl text-xs font-bold text-white bg-[#1b5e20] hover:bg-[#144918] shadow-sm transition" title="Buka Review Detail P2H">
<i class="fa-solid fa-magnifying-glass text-[10px]"></i> <i class="fa-solid fa-magnifying-glass text-[10px]"></i>
<span>Review</span> <span>Review</span>
</a> </a>
<a href="{{ route('qma.p2h.export_single_pdf', $rec->id) }}" target="_blank" class="w-7 h-7 rounded-xl bg-rose-50 hover:bg-rose-100 text-rose-600 flex items-center justify-center transition border border-rose-200 shadow-2xs" title="Download Lembar P2H (PDF)">
<i class="fa-solid fa-file-pdf text-xs"></i>
</a>
<a href="{{ route('qma.p2h.export_single_excel', $rec->id) }}" class="w-7 h-7 rounded-xl bg-emerald-50 hover:bg-emerald-100 text-emerald-700 flex items-center justify-center transition border border-emerald-200 shadow-2xs" title="Download Lembar P2H (Excel)">
<i class="fa-solid fa-file-excel text-xs"></i>
</a>
</div>
</td> </td>
</tr> </tr>
@empty @empty
+29 -2
View File
@@ -5,12 +5,26 @@
@section('content') @section('content')
<div class="w-full space-y-6"> <div class="w-full space-y-6">
<!-- Top Action Bar --> <!-- Top Action Bar -->
<div class="flex items-center justify-between pb-1"> <div class="flex flex-col sm:flex-row sm:items-center justify-between gap-3 pb-1 no-print">
<a href="{{ route('qma.p2h.index') }}" class="inline-flex items-center space-x-1.5 text-xs font-bold text-slate-600 hover:text-[#1b5e20] transition bg-white px-3 py-1.5 rounded-xl border border-slate-200 shadow-sm"> <a href="{{ route('qma.p2h.index') }}" class="inline-flex items-center space-x-1.5 text-xs font-bold text-slate-600 hover:text-[#1b5e20] transition bg-white px-3 py-1.5 rounded-xl border border-slate-200 shadow-sm w-fit">
<i class="fa-solid fa-arrow-left text-[11px]"></i> <i class="fa-solid fa-arrow-left text-[11px]"></i>
<span>Kembali ke P2H Unit Support</span> <span>Kembali ke P2H Unit Support</span>
</a> </a>
<!-- Action Buttons: Ekspor Data & Status Validasi -->
<div class="flex items-center flex-wrap gap-2.5">
<!-- Tombol Ekspor PDF -->
<a href="{{ route('qma.p2h.export_single_pdf', $record->id) }}" target="_blank" class="inline-flex items-center space-x-1.5 text-xs font-bold text-rose-700 bg-rose-50 hover:bg-rose-100 border border-rose-200 px-3 py-1.5 rounded-xl transition shadow-xs">
<i class="fa-solid fa-file-pdf text-[13px] text-rose-600"></i>
<span>Cetak / Ekspor PDF</span>
</a>
<!-- Tombol Ekspor Excel -->
<a href="{{ route('qma.p2h.export_single_excel', $record->id) }}" class="inline-flex items-center space-x-1.5 text-xs font-bold text-emerald-800 bg-emerald-50 hover:bg-emerald-100 border border-emerald-200 px-3 py-1.5 rounded-xl transition shadow-xs">
<i class="fa-solid fa-file-excel text-[13px] text-emerald-600"></i>
<span>Ekspor Excel (.xlsx)</span>
</a>
<!-- Badge Status Validasi --> <!-- Badge Status Validasi -->
<div> <div>
@if($record->isPending()) @if($record->isPending())
@@ -29,6 +43,7 @@
@endif @endif
</div> </div>
</div> </div>
</div>
<!-- Header Transaksi & Metadata --> <!-- Header Transaksi & Metadata -->
<div class="bg-gradient-to-r from-slate-800 to-slate-900 text-white p-6 rounded-2xl shadow-sm border border-slate-700"> <div class="bg-gradient-to-r from-slate-800 to-slate-900 text-white p-6 rounded-2xl shadow-sm border border-slate-700">
@@ -214,4 +229,16 @@
@endforeach @endforeach
</div> </div>
</div> </div>
<style>
@media print {
.no-print, header, nav, aside, #mobileDrawer, #topNavbar, .sidebar-container {
display: none !important;
}
body {
background: #ffffff !important;
color: #000000 !important;
}
}
</style>
@endsection @endsection
+8 -1
View File
@@ -275,7 +275,14 @@
<tr class="p2h-summary-row hover:bg-slate-50/80 transition"> <tr class="p2h-summary-row hover:bg-slate-50/80 transition">
<td class="py-3.5 px-4 text-center text-slate-400 font-medium">{{ $loop->iteration }}</td> <td class="py-3.5 px-4 text-center text-slate-400 font-medium">{{ $loop->iteration }}</td>
<td class="py-3.5 px-4 whitespace-nowrap"> <td class="py-3.5 px-4 whitespace-nowrap">
<span class="font-bold text-slate-900">{{ $us['vehicle']->code ?? '-' }}</span> @if($us['vehicle'])
<a href="{{ route('qma.p2h.index', ['search' => $us['vehicle']->code]) }}" class="font-bold text-[#1b5e20] hover:underline flex items-center space-x-1" title="Lihat Riwayat P2H Unit Ini">
<span>{{ $us['vehicle']->code }}</span>
<i class="fa-solid fa-arrow-up-right-from-square text-[9px] text-slate-400"></i>
</a>
@else
<span class="font-bold text-slate-900">-</span>
@endif
</td> </td>
<td class="py-3.5 px-4"> <td class="py-3.5 px-4">
<span class="text-slate-800 font-semibold block">{{ $us['vehicle']->brand_type ?? '-' }}</span> <span class="text-slate-800 font-semibold block">{{ $us['vehicle']->brand_type ?? '-' }}</span>
+2
View File
@@ -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-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-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}', [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}/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'); Route::post('/p2h-records/{id}/reject', [P2hInspectionController::class, 'reject'])->name('p2h.reject')->middleware('permission:qma.p2h.approve|qma.vehicles.edit');
@@ -219,13 +219,61 @@ class QmaActivityAndP2hExportTest extends TestCase
$this->assertNotEmpty($content); $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 public function test_unauthorized_user_cannot_export_activity_and_p2h(): void
{ {
$record = P2hRecord::first();
$routes = [ $routes = [
route('qma.activity.export_excel'), route('qma.activity.export_excel'),
route('qma.activity.export_pdf'), route('qma.activity.export_pdf'),
route('qma.p2h.export_excel'), route('qma.p2h.export_excel'),
route('qma.p2h.export_pdf'), 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) { foreach ($routes as $routeUrl) {