penambahan fitur ekspor di hse, qma, dan pg

This commit is contained in:
Ray1111-aa
2026-10-16 11:02:28 +07:00
parent a54f80a45e
commit 6e5ae727f9
34 changed files with 4964 additions and 169 deletions
+207
View File
@@ -0,0 +1,207 @@
<?php
namespace App\Services;
use FPDF;
class PgTablePdfExporter extends FPDF
{
public string $reportTitle = 'Laporan Modul Private Guard';
public string $subtitle = '';
public string $systemTitle = 'MODUL PRIVATE GUARD (PG) - RKM-KMH';
public array $metaLeft = [];
public array $metaRight = [];
public array $columns = []; // [['title' => 'NO', 'width' => 10, 'align' => 'C', 'bold' => true, 'max_char' => 20, 'is_status' => true], ...]
public int $totalRows = 0;
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, 44);
} else {
$this->SetXY(15, 10);
$this->SetFont('Arial', 'B', 14);
$this->SetTextColor(27, 94, 32);
$this->Cell(60, 8, 'KERINCI HYDROPOWER', 0, 0, 'L');
}
// 2. Branding Sistem di Kanan Atas
$this->SetXY(170, 10);
$this->SetFont('Arial', 'B', 18);
$this->SetTextColor(27, 94, 32); // #1b5e20 Green
$this->Cell(112, 6, 'RKM-KMH', 0, 1, 'R');
$this->SetXY(170, 16);
$this->SetFont('Arial', 'B', 7.5);
$this->SetTextColor(71, 85, 105); // #475569 Slate
$this->Cell(112, 4, 'KERINCI HYDROPOWER 350 MW', 0, 1, 'R');
// 3. Banner Biru Gelap Navy (#06213f)
$this->SetY(24);
$this->SetFillColor(6, 33, 63);
$this->Rect(15, 24, 267, 16, 'F');
// Teks Judul di Kiri Banner
$this->SetXY(18, 26);
$this->SetFont('Arial', 'B', 13);
$this->SetTextColor(255, 255, 255);
$this->Cell(140, 6, $this->reportTitle, 0, 1, 'L');
$this->SetXY(18, 32);
$this->SetFont('Arial', '', 8);
$this->SetTextColor(203, 213, 225); // #cbd5e1 Slate
$this->Cell(140, 5, $this->subtitle, 0, 1, 'L');
// Teks Sub-sistem di Kanan Banner
$this->SetXY(160, 26);
$this->SetFont('Arial', 'B', 9);
$this->SetTextColor(255, 255, 255);
$this->Cell(119, 6, $this->systemTitle, 0, 1, 'R');
$this->SetXY(160, 32);
$this->SetFont('Arial', 'I', 7.5);
$this->SetTextColor(203, 213, 225);
$this->Cell(119, 5, 'Dicetak otomatis dari sistem', 0, 1, 'R');
// 4. Bagian Ringkasan Metadata (2 Kolom)
$metaY = 44;
$this->SetTextColor(51, 65, 85);
// Kolom Kiri
foreach ($this->metaLeft as $k => $v) {
$this->SetXY(15, $metaY);
$this->SetFont('Arial', '', 8);
$this->Cell(32, 4.5, $k, 0, 0);
$this->Cell(5, 4.5, ':', 0, 0);
$this->SetFont('Arial', 'B', 8);
$this->Cell(85, 4.5, (string) $v, 0, 1);
$metaY += 5;
}
// Kolom Kanan
$metaY2 = 44;
foreach ($this->metaRight as $k => $v) {
$this->SetXY(165, $metaY2);
$this->SetFont('Arial', '', 8);
$this->Cell(34, 4.5, $k, 0, 0);
$this->Cell(5, 4.5, ':', 0, 0);
$this->SetFont('Arial', 'B', 8);
$this->Cell(78, 4.5, (string) $v, 0, 1);
$metaY2 += 5;
}
// Garis Pembatas Tipis
$divY = max($metaY, $metaY2) + 2;
$this->SetDrawColor(226, 232, 240);
$this->Line(15, $divY, 282, $divY);
// 5. Header Tabel Solid Navy
$tableY = $divY + 3;
$this->SetXY(15, $tableY);
$this->SetFillColor(6, 33, 63);
$this->SetTextColor(255, 255, 255);
$this->SetFont('Arial', 'B', 7.5);
foreach ($this->columns as $col) {
$this->Cell($col['width'], 7.5, $col['title'], 0, 0, $col['align'] ?? 'L', true);
}
$this->Ln();
}
public function Footer(): void
{
$this->SetY(-12);
$this->SetFont('Arial', '', 7.5);
$this->SetTextColor(148, 163, 184);
$this->Cell(
180,
5,
'Menampilkan ' . $this->totalRows . ' data - Dokumen ini digenerate secara otomatis oleh Sistem RKM-KMH pada ' . now()->translatedFormat('d F Y') . '.',
0,
0,
'L'
);
$this->Cell(87, 5, 'Halaman ' . $this->PageNo() . ' dari {nb}', 0, 0, 'R');
}
/**
* Helper pembuatan file PDF seragam untuk seluruh modul tabel PG.
*/
public static function generate(
string $title,
string $subtitle,
string $systemTitle,
array $metaLeft,
array $metaRight,
array $columns,
array $rows
): string {
$pdf = new self('L', 'mm', 'A4');
$pdf->AliasNbPages();
$pdf->reportTitle = $title;
$pdf->subtitle = $subtitle;
$pdf->systemTitle = $systemTitle;
$pdf->metaLeft = $metaLeft;
$pdf->metaRight = $metaRight;
$pdf->columns = $columns;
$pdf->totalRows = count($rows);
$pdf->logoPath = public_path('images/logo-kerinci.png');
$pdf->SetMargins(15, 10, 15);
$pdf->AddPage();
$pdf->SetAutoPageBreak(true, 15);
$fill = false;
foreach ($rows as $r) {
$pdf->SetFillColor(248, 250, 252);
$pdf->SetDrawColor(241, 245, 249);
$pdf->SetTextColor(15, 23, 42);
foreach ($columns as $idx => $col) {
$val = (string) ($r[$idx] ?? '-');
$align = $col['align'] ?? 'L';
$width = $col['width'];
$isBold = !empty($col['bold']);
$isStatus = !empty($col['is_status']);
if ($isStatus) {
$valLower = strtolower($val);
if (str_contains($valLower, 'nonaktif')) {
$pdf->SetTextColor(100, 116, 139); // Slate Gray #64748b
} elseif (str_contains($valLower, 'disetujui') || str_contains($valLower, 'approved') || str_contains($valLower, 'aktif') || str_contains($valLower, 'masuk') || $valLower === 'in') {
$pdf->SetTextColor(4, 120, 87); // Emerald Green #047857
} elseif (str_contains($valLower, 'menunggu') || str_contains($valLower, 'pending') || str_contains($valLower, 'regu 2')) {
$pdf->SetTextColor(180, 83, 9); // Amber #b45309
} elseif (str_contains($valLower, 'ditolak') || str_contains($valLower, 'rejected')) {
$pdf->SetTextColor(190, 18, 60); // Rose Red #be123c
} elseif (str_contains($valLower, 'keluar') || $valLower === 'out' || str_contains($valLower, 'regu 1')) {
$pdf->SetTextColor(29, 78, 216); // Blue #1d4ed8
} elseif (str_contains($valLower, 'regu 3')) {
$pdf->SetTextColor(126, 34, 206); // Purple #7e22ce
} else {
$pdf->SetTextColor(100, 116, 139);
}
$pdf->SetFont('Arial', 'B', 7.5);
} else {
$pdf->SetTextColor(15, 23, 42);
$pdf->SetFont('Arial', $isBold ? 'B' : '', 7.5);
}
$maxChar = !empty($col['max_char']) ? $col['max_char'] : 0;
if ($maxChar > 0 && mb_strlen($val) > $maxChar) {
$val = mb_strimwidth($val, 0, $maxChar, '...');
}
$displayVal = ($align === 'L' && !empty($val) && $val !== '-') ? ' ' . $val : $val;
$pdf->Cell($width, 6.5, $displayVal, 'B', 0, $align, $fill);
}
$pdf->Ln();
$fill = !$fill;
}
return $pdf->Output('S');
}
}
+207
View File
@@ -0,0 +1,207 @@
<?php
namespace App\Services;
use FPDF;
class QmaTablePdfExporter extends FPDF
{
public string $reportTitle = 'Laporan Sistem QMA';
public string $subtitle = '';
public string $systemTitle = 'SISTEM QMA RKM-KMH';
public array $metaLeft = [];
public array $metaRight = [];
public array $columns = []; // [['title' => 'NO', 'width' => 10, 'align' => 'C', 'bold' => true, 'max_char' => 20, 'is_status' => true], ...]
public int $totalRows = 0;
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, 44);
} else {
$this->SetXY(15, 10);
$this->SetFont('Arial', 'B', 14);
$this->SetTextColor(27, 94, 32);
$this->Cell(60, 8, 'KERINCI HYDROPOWER', 0, 0, 'L');
}
// 2. Branding Sistem di Kanan Atas
$this->SetXY(170, 10);
$this->SetFont('Arial', 'B', 18);
$this->SetTextColor(27, 94, 32); // #1b5e20 Green
$this->Cell(112, 6, 'RKM-KMH', 0, 1, 'R');
$this->SetXY(170, 16);
$this->SetFont('Arial', 'B', 7.5);
$this->SetTextColor(71, 85, 105); // #475569 Slate
$this->Cell(112, 4, 'KERINCI HYDROPOWER 350 MW', 0, 1, 'R');
// 3. Banner Biru Gelap Navy
$this->SetY(24);
$this->SetFillColor(6, 33, 63); // #06213f Dark Navy
$this->Rect(15, 24, 267, 16, 'F');
// Teks Judul di Kiri Banner
$this->SetXY(18, 26);
$this->SetFont('Arial', 'B', 13);
$this->SetTextColor(255, 255, 255);
$this->Cell(140, 6, $this->reportTitle, 0, 1, 'L');
$this->SetXY(18, 32);
$this->SetFont('Arial', '', 8);
$this->SetTextColor(203, 213, 225); // #cbd5e1 Slate
$this->Cell(140, 5, $this->subtitle, 0, 1, 'L');
// Teks Sub-sistem di Kanan Banner
$this->SetXY(160, 26);
$this->SetFont('Arial', 'B', 9);
$this->SetTextColor(255, 255, 255);
$this->Cell(119, 6, $this->systemTitle, 0, 1, 'R');
$this->SetXY(160, 32);
$this->SetFont('Arial', 'I', 7.5);
$this->SetTextColor(203, 213, 225);
$this->Cell(119, 5, 'Dicetak otomatis dari sistem', 0, 1, 'R');
// 4. Bagian Ringkasan Metadata (2 Kolom)
$metaY = 44;
$this->SetTextColor(51, 65, 85);
// Kolom Kiri
foreach ($this->metaLeft as $k => $v) {
$this->SetXY(15, $metaY);
$this->SetFont('Arial', '', 8);
$this->Cell(32, 4.5, $k, 0, 0);
$this->Cell(5, 4.5, ':', 0, 0);
$this->SetFont('Arial', 'B', 8);
$this->Cell(85, 4.5, (string) $v, 0, 1);
$metaY += 5;
}
// Kolom Kanan
$metaY2 = 44;
foreach ($this->metaRight as $k => $v) {
$this->SetXY(165, $metaY2);
$this->SetFont('Arial', '', 8);
$this->Cell(34, 4.5, $k, 0, 0);
$this->Cell(5, 4.5, ':', 0, 0);
$this->SetFont('Arial', 'B', 8);
$this->Cell(78, 4.5, (string) $v, 0, 1);
$metaY2 += 5;
}
// Garis Pembatas Tipis
$divY = max($metaY, $metaY2) + 2;
$this->SetDrawColor(226, 232, 240);
$this->Line(15, $divY, 282, $divY);
// 5. Header Tabel Solid Navy
$tableY = $divY + 3;
$this->SetXY(15, $tableY);
$this->SetFillColor(6, 33, 63);
$this->SetTextColor(255, 255, 255);
$this->SetFont('Arial', 'B', 7.5);
foreach ($this->columns as $col) {
$this->Cell($col['width'], 7.5, $col['title'], 0, 0, $col['align'] ?? 'L', true);
}
$this->Ln();
}
public function Footer(): void
{
$this->SetY(-12);
$this->SetFont('Arial', '', 7.5);
$this->SetTextColor(148, 163, 184);
$this->Cell(
180,
5,
'Menampilkan ' . $this->totalRows . ' data - Dokumen ini digenerate secara otomatis oleh Sistem RKM-KMH pada ' . now()->translatedFormat('d F Y') . '.',
0,
0,
'L'
);
$this->Cell(87, 5, 'Halaman ' . $this->PageNo() . ' dari {nb}', 0, 0, 'R');
}
/**
* Helper pembuatan file PDF seragam untuk seluruh modul tabel QMA.
*/
public static function generate(
string $title,
string $subtitle,
string $systemTitle,
array $metaLeft,
array $metaRight,
array $columns,
array $rows
): string {
$pdf = new self('L', 'mm', 'A4');
$pdf->AliasNbPages();
$pdf->reportTitle = $title;
$pdf->subtitle = $subtitle;
$pdf->systemTitle = $systemTitle;
$pdf->metaLeft = $metaLeft;
$pdf->metaRight = $metaRight;
$pdf->columns = $columns;
$pdf->totalRows = count($rows);
$pdf->logoPath = public_path('images/logo-kerinci.png');
$pdf->SetMargins(15, 10, 15);
$pdf->AddPage();
$pdf->SetAutoPageBreak(true, 15);
$fill = false;
foreach ($rows as $r) {
$pdf->SetFillColor(248, 250, 252);
$pdf->SetDrawColor(241, 245, 249);
$pdf->SetTextColor(15, 23, 42);
foreach ($columns as $idx => $col) {
$val = (string) ($r[$idx] ?? '-');
$align = $col['align'] ?? 'L';
$width = $col['width'];
$isBold = !empty($col['bold']);
$isStatus = !empty($col['is_status']);
if ($isStatus) {
$valLower = strtolower($val);
if (str_contains($valLower, 'disetujui') || str_contains($valLower, 'approved') || str_contains($valLower, 'operation') || str_contains($valLower, 'normal') || str_contains($valLower, 'baik')) {
$pdf->SetTextColor(4, 120, 87); // Green #047857
} elseif (str_contains($valLower, 'menunggu') || str_contains($valLower, 'pending') || str_contains($valLower, 'standby')) {
$pdf->SetTextColor(180, 83, 9); // Amber #b45309
} elseif (str_contains($valLower, 'ditolak') || str_contains($valLower, 'rejected') || str_contains($valLower, 'breakdown') || str_contains($valLower, 'rusak') || str_contains($valLower, 'defect')) {
$pdf->SetTextColor(190, 18, 60); // Rose Red #be123c
} elseif (str_contains($valLower, 'masuk') || $valLower === 'in') {
$pdf->SetTextColor(4, 120, 87); // Green
} elseif (str_contains($valLower, 'keluar') || $valLower === 'out') {
$pdf->SetTextColor(29, 78, 216); // Blue #1d4ed8
} elseif (str_contains($valLower, 'maintenance')) {
$pdf->SetTextColor(2, 132, 199); // Sky blue
} else {
$pdf->SetTextColor(100, 116, 139);
}
$pdf->SetFont('Arial', 'B', 7.5);
} else {
$pdf->SetTextColor(15, 23, 42);
$pdf->SetFont('Arial', $isBold ? 'B' : '', 7.5);
}
$maxChar = !empty($col['max_char']) ? $col['max_char'] : 0;
if ($maxChar > 0 && mb_strlen($val) > $maxChar) {
$val = mb_strimwidth($val, 0, $maxChar, '...');
}
$displayVal = ($align === 'L' && !empty($val) && $val !== '-') ? ' ' . $val : $val;
$pdf->Cell($width, 6.5, $displayVal, 'B', 0, $align, $fill);
}
$pdf->Ln();
$fill = !$fill;
}
return $pdf->Output('S');
}
}
+227
View File
@@ -0,0 +1,227 @@
<?php
namespace App\Services;
use FPDF;
use Illuminate\Support\Collection;
class SimperPdfExporter extends FPDF
{
public string $reportTitle = 'Laporan Data SIMPER';
public string $subtitle = '';
public array $metaLeft = [];
public array $metaRight = [];
public int $totalRows = 0;
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, 44);
} else {
$this->SetXY(15, 10);
$this->SetFont('Arial', 'B', 14);
$this->SetTextColor(27, 94, 32);
$this->Cell(60, 8, 'KERINCI HYDROPOWER', 0, 0, 'L');
}
// 2. Branding Sistem di Kanan Atas
$this->SetXY(170, 10);
$this->SetFont('Arial', 'B', 18);
$this->SetTextColor(27, 94, 32); // #1b5e20 Green
$this->Cell(112, 6, 'RKM-KMH', 0, 1, 'R');
$this->SetXY(170, 16);
$this->SetFont('Arial', 'B', 7.5);
$this->SetTextColor(71, 85, 105); // #475569 Slate
$this->Cell(112, 4, 'KERINCI HYDROPOWER 350 MW', 0, 1, 'R');
// 3. Banner Biru Gelap Navy (Sesuai Referensi it.allrole.web.id)
$this->SetY(24);
$this->SetFillColor(6, 33, 63); // #06213f Dark Navy
$this->Rect(15, 24, 267, 16, 'F');
// Teks Judul di Kiri Banner
$this->SetXY(18, 26);
$this->SetFont('Arial', 'B', 13);
$this->SetTextColor(255, 255, 255);
$this->Cell(140, 6, $this->reportTitle, 0, 1, 'L');
$this->SetXY(18, 32);
$this->SetFont('Arial', '', 8);
$this->SetTextColor(203, 213, 225); // #cbd5e1 Slate
$this->Cell(140, 5, $this->subtitle, 0, 1, 'L');
// Teks Sub-sistem di Kanan Banner
$this->SetXY(160, 26);
$this->SetFont('Arial', 'B', 9);
$this->SetTextColor(255, 255, 255);
$this->Cell(119, 6, 'SISTEM KENDARAAN RKM-KMH', 0, 1, 'R');
$this->SetXY(160, 32);
$this->SetFont('Arial', 'I', 7.5);
$this->SetTextColor(203, 213, 225);
$this->Cell(119, 5, 'Dicetak otomatis dari sistem', 0, 1, 'R');
// 4. Bagian Ringkasan Metadata (2 Kolom)
$metaY = 44;
$this->SetTextColor(51, 65, 85);
// Kolom Kiri
foreach ($this->metaLeft as $k => $v) {
$this->SetXY(15, $metaY);
$this->SetFont('Arial', '', 8);
$this->Cell(28, 4.5, $k, 0, 0);
$this->Cell(5, 4.5, ':', 0, 0);
$this->SetFont('Arial', 'B', 8);
$this->Cell(85, 4.5, $v, 0, 1);
$metaY += 5;
}
// Kolom Kanan
$metaY2 = 44;
foreach ($this->metaRight as $k => $v) {
$this->SetXY(175, $metaY2);
$this->SetFont('Arial', '', 8);
$this->Cell(28, 4.5, $k, 0, 0);
$this->Cell(5, 4.5, ':', 0, 0);
$this->SetFont('Arial', 'B', 8);
$this->Cell(74, 4.5, $v, 0, 1);
$metaY2 += 5;
}
// Garis Pembatas Tipis
$divY = max($metaY, $metaY2) + 2;
$this->SetDrawColor(226, 232, 240);
$this->Line(15, $divY, 282, $divY);
// 5. Header Tabel Solid Navy
$tableY = $divY + 3;
$this->SetXY(15, $tableY);
$this->SetFillColor(6, 33, 63);
$this->SetTextColor(255, 255, 255);
$this->SetFont('Arial', 'B', 7.5);
$cols = [
['NO', 10, 'C'],
['NIK', 30, 'C'],
['NAMA KARYAWAN', 62, 'L'],
['JABATAN', 45, 'L'],
['UNIT / DIVISI', 40, 'L'],
['STATUS DRIVER', 26, 'C'],
['MASA BERLAKU', 26, 'C'],
['STATUS SIMPER', 28, 'C'],
];
foreach ($cols as $col) {
$this->Cell($col[1], 7.5, $col[0], 0, 0, $col[2], true);
}
$this->Ln();
}
public function Footer(): void
{
$this->SetY(-12);
$this->SetFont('Arial', '', 7.5);
$this->SetTextColor(148, 163, 184);
$this->Cell(
180,
5,
'Menampilkan ' . $this->totalRows . ' data - Dokumen ini digenerate secara otomatis oleh Sistem RKM-KMH pada ' . now()->translatedFormat('d F Y') . '.',
0,
0,
'L'
);
$this->Cell(87, 5, 'Halaman ' . $this->PageNo() . ' dari {nb}', 0, 0, 'R');
}
/**
* Generate real PDF binary string.
*/
public static function generate(Collection $employees, array $metaLeft, array $metaRight, string $subtitle): string
{
$pdf = new self('L', 'mm', 'A4');
$pdf->AliasNbPages();
$pdf->reportTitle = 'Laporan Data SIMPER';
$pdf->subtitle = $subtitle;
$pdf->metaLeft = $metaLeft;
$pdf->metaRight = $metaRight;
$pdf->totalRows = $employees->count();
$pdf->logoPath = public_path('images/logo-kerinci.png');
$pdf->SetMargins(15, 10, 15);
$pdf->AddPage();
$pdf->SetAutoPageBreak(true, 15);
$pdf->SetFont('Arial', '', 7.5);
$fill = false;
$soon = now()->addDays(30);
foreach ($employees as $idx => $emp) {
$isDriver = $emp->is_operator;
$expDate = $emp->simper_expired_at ? $emp->simper_expired_at->format('d/m/Y') : '-';
if (! $isDriver) {
$statusText = 'Bukan Driver';
} elseif (! $emp->simper_expired_at) {
$statusText = 'Belum Ada SIMPER';
} elseif ($emp->simper_expired_at->isPast() && ! $emp->simper_expired_at->isToday()) {
$statusText = 'Kedaluwarsa';
} elseif ($emp->simper_expired_at->lte($soon)) {
$statusText = 'Segera Habis';
} else {
$statusText = 'Masih Berlaku';
}
$pdf->SetFillColor(248, 250, 252);
$pdf->SetDrawColor(241, 245, 249);
$pdf->SetTextColor(15, 23, 42);
// Kolom 1: No
$pdf->SetFont('Arial', '', 7.5);
$pdf->Cell(10, 6.5, (string) ($idx + 1), 'B', 0, 'C', $fill);
// Kolom 2: NIK (Bold)
$pdf->SetFont('Arial', 'B', 7.5);
$pdf->Cell(30, 6.5, $emp->nik, 'B', 0, 'C', $fill);
// Kolom 3: Nama Lengkap (Bold, Truncate jika > 36 karakter)
$nama = mb_strimwidth($emp->name, 0, 36, '...');
$pdf->Cell(62, 6.5, ' ' . $nama, 'B', 0, 'L', $fill);
// Kolom 4: Jabatan
$pdf->SetFont('Arial', '', 7.5);
$jabatan = mb_strimwidth($emp->position ?: '-', 0, 26, '...');
$pdf->Cell(45, 6.5, ' ' . $jabatan, 'B', 0, 'L', $fill);
// Kolom 5: Unit / Divisi
$unit = mb_strimwidth($emp->unit_kerja ?: ($emp->division ?: '-'), 0, 24, '...');
$pdf->Cell(40, 6.5, ' ' . $unit, 'B', 0, 'L', $fill);
// Kolom 6: Status Driver
$pdf->Cell(26, 6.5, $isDriver ? 'Driver' : 'Non-Driver', 'B', 0, 'C', $fill);
// Kolom 7: Masa Berlaku
$pdf->Cell(26, 6.5, $expDate, 'B', 0, 'C', $fill);
// Kolom 8: Status SIMPER (Berwarna)
if ($statusText === 'Masih Berlaku') {
$pdf->SetTextColor(4, 120, 87); // #047857 Green
} elseif ($statusText === 'Segera Habis') {
$pdf->SetTextColor(180, 83, 9); // #b45309 Amber
} elseif ($statusText === 'Kedaluwarsa' || $statusText === 'Belum Ada SIMPER') {
$pdf->SetTextColor(190, 18, 60); // #be123c Rose
} else {
$pdf->SetTextColor(100, 116, 139); // #64748b Slate
}
$pdf->SetFont('Arial', 'B', 7.5);
$pdf->Cell(28, 6.5, $statusText, 'B', 0, 'C', $fill);
$pdf->Ln();
$fill = ! $fill;
}
return $pdf->Output('S');
}
}
+203
View File
@@ -0,0 +1,203 @@
<?php
namespace App\Services;
use ZipArchive;
class SimpleXlsxExporter
{
/**
* Generate standard OpenXML XLSX binary string.
*
* @param string $title
* @param array $metaLines e.g. ['Filter: Semua', 'Tanggal Cetak: 16-10-2026 09:30']
* @param array $headers e.g. ['No' => 6, 'NIK' => 16, 'Nama Lengkap' => 28, ...]
* @param array $rows Array of associative or index arrays
* @param array $alignments Optional per-column alignment: 'center' or 'left'
* @return string Raw zip content
*/
public static function create(string $title, array $metaLines, array $headers, array $rows, array $alignments = []): string
{
$numCols = count($headers);
$lastColLetter = self::colLetter($numCols);
// Build sheetData XML
$sheetXml = '<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">';
$sheetXml .= '<sheetPr><outlinePr summaryBelow="1" summaryRight="1" /><pageSetUpPr /></sheetPr>';
$totalRows = 4 + count($metaLines) + count($rows);
$sheetXml .= '<dimension ref="A1:' . $lastColLetter . $totalRows . '" />';
$sheetXml .= '<sheetViews><sheetView workbookViewId="0"><selection activeCell="A1" sqref="A1" /></sheetView></sheetViews>';
$sheetXml .= '<sheetFormatPr baseColWidth="8" defaultRowHeight="16" />';
// Column widths
$sheetXml .= '<cols>';
$colIdx = 1;
foreach ($headers as $name => $width) {
$sheetXml .= '<col min="' . $colIdx . '" max="' . $colIdx . '" width="' . (is_numeric($width) ? $width : 15) . '" customWidth="1" />';
$colIdx++;
}
$sheetXml .= '</cols>';
$sheetXml .= '<sheetData>';
// Row 1: Title
$rowNum = 1;
$sheetXml .= '<row r="' . $rowNum . '" ht="26" customHeight="1">';
$sheetXml .= '<c r="A1" s="1" t="inlineStr"><is><t>' . htmlspecialchars($title, ENT_XML1) . '</t></is></c>';
$sheetXml .= '</row>';
// Meta lines (Sub-titles)
foreach ($metaLines as $meta) {
$rowNum++;
$sheetXml .= '<row r="' . $rowNum . '" ht="18" customHeight="1">';
$sheetXml .= '<c r="A' . $rowNum . '" s="2" t="inlineStr"><is><t>' . htmlspecialchars($meta, ENT_XML1) . '</t></is></c>';
$sheetXml .= '</row>';
}
// Blank spacer row
$rowNum++;
$sheetXml .= '<row r="' . $rowNum . '" ht="10" customHeight="1"></row>';
// Table Header Row
$rowNum++;
$headerRowNum = $rowNum;
$sheetXml .= '<row r="' . $headerRowNum . '" ht="24" customHeight="1">';
$cIdx = 1;
foreach ($headers as $name => $width) {
$cellRef = self::colLetter($cIdx) . $headerRowNum;
$sheetXml .= '<c r="' . $cellRef . '" s="3" t="inlineStr"><is><t>' . htmlspecialchars($name, ENT_XML1) . '</t></is></c>';
$cIdx++;
}
$sheetXml .= '</row>';
// Table Data Rows
$alignKeys = array_values($alignments);
foreach ($rows as $rData) {
$rowNum++;
$sheetXml .= '<row r="' . $rowNum . '" ht="20" customHeight="1">';
$cIdx = 1;
$vals = is_array($rData) ? array_values($rData) : [];
for ($i = 0; $i < $numCols; $i++) {
$val = $vals[$i] ?? '';
$cellRef = self::colLetter($cIdx) . $rowNum;
$align = $alignKeys[$i] ?? ($cIdx === 1 ? 'center' : 'left');
$styleId = ($align === 'center') ? 4 : 5;
if (is_numeric($val) && strlen($val) > 0 && !str_starts_with((string)$val, '0')) {
$sheetXml .= '<c r="' . $cellRef . '" s="' . $styleId . '" t="n"><v>' . $val . '</v></c>';
} else {
$sheetXml .= '<c r="' . $cellRef . '" s="' . $styleId . '" t="inlineStr"><is><t>' . htmlspecialchars((string)$val, ENT_XML1) . '</t></is></c>';
}
$cIdx++;
}
$sheetXml .= '</row>';
}
$sheetXml .= '</sheetData>';
// Merge cells for title and meta lines
$sheetXml .= '<mergeCells count="' . (1 + count($metaLines)) . '">';
$sheetXml .= '<mergeCell ref="A1:' . $lastColLetter . '1" />';
for ($m = 2; $m <= 1 + count($metaLines); $m++) {
$sheetXml .= '<mergeCell ref="A' . $m . ':' . $lastColLetter . $m . '" />';
}
$sheetXml .= '</mergeCells>';
$sheetXml .= '<pageMargins left="0.5" right="0.5" top="0.75" bottom="0.75" header="0.3" footer="0.3" />';
$sheetXml .= '</worksheet>';
// Stylesheet with KMH Brand Colors (Navy / Forest Green)
$stylesXml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
<fonts count="4">
<font><name val="Arial" /><sz val="10" /></font>
<font><name val="Arial" /><sz val="14" /><b val="1" /><color rgb="FF0F172A" /></font>
<font><name val="Arial" /><sz val="9" /><i val="1" /><color rgb="FF64748B" /></font>
<font><name val="Arial" /><sz val="10" /><b val="1" /><color rgb="FFFFFFFF" /></font>
</fonts>
<fills count="3">
<fill><patternFill patternType="none" /></fill>
<fill><patternFill patternType="gray125" /></fill>
<fill><patternFill patternType="solid"><fgColor rgb="FF06213F" /><bgColor rgb="FF06213F" /></patternFill></fill>
</fills>
<borders count="2">
<border><left /><right /><top /><bottom /></border>
<border>
<left style="thin"><color rgb="FFE2E8F0" /></left>
<right style="thin"><color rgb="FFE2E8F0" /></right>
<top style="thin"><color rgb="FFE2E8F0" /></top>
<bottom style="thin"><color rgb="FFE2E8F0" /></bottom>
</border>
</borders>
<cellStyleXfs count="1">
<xf numFmtId="0" fontId="0" fillId="0" borderId="0" />
</cellStyleXfs>
<cellXfs count="6">
<xf numFmtId="0" fontId="0" fillId="0" borderId="0" />
<xf numFmtId="0" fontId="1" fillId="0" borderId="0" applyAlignment="1"><alignment horizontal="center" vertical="center" /></xf>
<xf numFmtId="0" fontId="2" fillId="0" borderId="0" applyAlignment="1"><alignment horizontal="center" vertical="center" /></xf>
<xf numFmtId="0" fontId="3" fillId="2" borderId="1" applyAlignment="1"><alignment horizontal="center" vertical="center" wrapText="1" /></xf>
<xf numFmtId="0" fontId="0" fillId="0" borderId="1" applyAlignment="1"><alignment horizontal="center" vertical="center" /></xf>
<xf numFmtId="0" fontId="0" fillId="0" borderId="1" applyAlignment="1"><alignment horizontal="left" vertical="center" /></xf>
</cellXfs>
</styleSheet>';
$workbookXml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<workbook xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
<sheets>
<sheet name="Data SIMPER" sheetId="1" r:id="rId1" />
</sheets>
</workbook>';
$workbookRelsXml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet1.xml" />
<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml" />
</Relationships>';
$relsXml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml" />
</Relationships>';
$contentTypesXml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml" />
<Default Extension="xml" ContentType="application/xml" />
<Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml" />
<Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml" />
<Override PartName="/xl/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml" />
</Types>';
// Build ZIP
$tmpFile = tempnam(sys_get_temp_dir(), 'xlsx_');
$zip = new ZipArchive();
$zip->open($tmpFile, ZipArchive::OVERWRITE);
$zip->addFromString('[Content_Types].xml', $contentTypesXml);
$zip->addFromString('_rels/.rels', $relsXml);
$zip->addFromString('xl/workbook.xml', $workbookXml);
$zip->addFromString('xl/_rels/workbook.xml.rels', $workbookRelsXml);
$zip->addFromString('xl/styles.xml', $stylesXml);
$zip->addFromString('xl/worksheets/sheet1.xml', $sheetXml);
$zip->close();
$content = file_get_contents($tmpFile);
unlink($tmpFile);
return $content;
}
private static function colLetter(int $colIndex): string
{
$letter = '';
while ($colIndex > 0) {
$p = ($colIndex - 1) % 26;
$letter = chr(65 + $p) . $letter;
$colIndex = intval(($colIndex - $p) / 26);
}
return $letter ?: 'A';
}
}
+199
View File
@@ -0,0 +1,199 @@
<?php
namespace App\Services;
use FPDF;
class VehiclePdfExporter extends FPDF
{
public string $reportTitle = 'Laporan Data Kendaraan';
public string $subtitle = '';
public array $metaLeft = [];
public array $metaRight = [];
public array $columns = []; // [['title' => 'NO', 'width' => 10, 'align' => 'C'], ...]
public int $totalRows = 0;
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, 44);
} else {
$this->SetXY(15, 10);
$this->SetFont('Arial', 'B', 14);
$this->SetTextColor(27, 94, 32);
$this->Cell(60, 8, 'KERINCI HYDROPOWER', 0, 0, 'L');
}
// 2. Branding Sistem di Kanan Atas
$this->SetXY(170, 10);
$this->SetFont('Arial', 'B', 18);
$this->SetTextColor(27, 94, 32); // #1b5e20 Green
$this->Cell(112, 6, 'RKM-KMH', 0, 1, 'R');
$this->SetXY(170, 16);
$this->SetFont('Arial', 'B', 7.5);
$this->SetTextColor(71, 85, 105); // #475569 Slate
$this->Cell(112, 4, 'KERINCI HYDROPOWER 350 MW', 0, 1, 'R');
// 3. Banner Biru Gelap Navy (Sesuai Format it.allrole.web.id)
$this->SetY(24);
$this->SetFillColor(6, 33, 63); // #06213f Dark Navy
$this->Rect(15, 24, 267, 16, 'F');
// Teks Judul di Kiri Banner
$this->SetXY(18, 26);
$this->SetFont('Arial', 'B', 13);
$this->SetTextColor(255, 255, 255);
$this->Cell(140, 6, $this->reportTitle, 0, 1, 'L');
$this->SetXY(18, 32);
$this->SetFont('Arial', '', 8);
$this->SetTextColor(203, 213, 225); // #cbd5e1 Slate
$this->Cell(140, 5, $this->subtitle, 0, 1, 'L');
// Teks Sub-sistem di Kanan Banner
$this->SetXY(160, 26);
$this->SetFont('Arial', 'B', 9);
$this->SetTextColor(255, 255, 255);
$this->Cell(119, 6, 'SISTEM KENDARAAN RKM-KMH', 0, 1, 'R');
$this->SetXY(160, 32);
$this->SetFont('Arial', 'I', 7.5);
$this->SetTextColor(203, 213, 225);
$this->Cell(119, 5, 'Dicetak otomatis dari sistem', 0, 1, 'R');
// 4. Bagian Ringkasan Metadata (2 Kolom)
$metaY = 44;
$this->SetTextColor(51, 65, 85);
// Kolom Kiri
foreach ($this->metaLeft as $k => $v) {
$this->SetXY(15, $metaY);
$this->SetFont('Arial', '', 8);
$this->Cell(28, 4.5, $k, 0, 0);
$this->Cell(5, 4.5, ':', 0, 0);
$this->SetFont('Arial', 'B', 8);
$this->Cell(85, 4.5, (string) $v, 0, 1);
$metaY += 5;
}
// Kolom Kanan
$metaY2 = 44;
foreach ($this->metaRight as $k => $v) {
$this->SetXY(175, $metaY2);
$this->SetFont('Arial', '', 8);
$this->Cell(28, 4.5, $k, 0, 0);
$this->Cell(5, 4.5, ':', 0, 0);
$this->SetFont('Arial', 'B', 8);
$this->Cell(74, 4.5, (string) $v, 0, 1);
$metaY2 += 5;
}
// Garis Pembatas Tipis
$divY = max($metaY, $metaY2) + 2;
$this->SetDrawColor(226, 232, 240);
$this->Line(15, $divY, 282, $divY);
// 5. Header Tabel Solid Navy
$tableY = $divY + 3;
$this->SetXY(15, $tableY);
$this->SetFillColor(6, 33, 63);
$this->SetTextColor(255, 255, 255);
$this->SetFont('Arial', 'B', 7.5);
foreach ($this->columns as $col) {
$this->Cell($col['width'], 7.5, $col['title'], 0, 0, $col['align'] ?? 'L', true);
}
$this->Ln();
}
public function Footer(): void
{
$this->SetY(-12);
$this->SetFont('Arial', '', 7.5);
$this->SetTextColor(148, 163, 184);
$this->Cell(
180,
5,
'Menampilkan ' . $this->totalRows . ' data - Dokumen ini digenerate secara otomatis oleh Sistem RKM-KMH pada ' . now()->translatedFormat('d F Y') . '.',
0,
0,
'L'
);
$this->Cell(87, 5, 'Halaman ' . $this->PageNo() . ' dari {nb}', 0, 0, 'R');
}
/**
* Helper pembuatan file PDF seragam untuk modul armada kendaraan.
*/
public static function generate(
string $title,
string $subtitle,
array $metaLeft,
array $metaRight,
array $columns,
array $rows
): string {
$pdf = new self('L', 'mm', 'A4');
$pdf->AliasNbPages();
$pdf->reportTitle = $title;
$pdf->subtitle = $subtitle;
$pdf->metaLeft = $metaLeft;
$pdf->metaRight = $metaRight;
$pdf->columns = $columns;
$pdf->totalRows = count($rows);
$pdf->logoPath = public_path('images/logo-kerinci.png');
$pdf->SetMargins(15, 10, 15);
$pdf->AddPage();
$pdf->SetAutoPageBreak(true, 15);
$fill = false;
foreach ($rows as $r) {
$pdf->SetFillColor(248, 250, 252);
$pdf->SetDrawColor(241, 245, 249);
$pdf->SetTextColor(15, 23, 42);
foreach ($columns as $idx => $col) {
$val = (string) ($r[$idx] ?? '-');
$align = $col['align'] ?? 'L';
$width = $col['width'];
$isBold = !empty($col['bold']);
$isStatus = !empty($col['is_status']);
if ($isStatus) {
if ($val === 'Operation') {
$pdf->SetTextColor(4, 120, 87); // Green
} elseif ($val === 'Standby') {
$pdf->SetTextColor(180, 83, 9); // Amber
} elseif ($val === 'Breakdown') {
$pdf->SetTextColor(190, 18, 60); // Red
} elseif ($val === 'Maintenance') {
$pdf->SetTextColor(2, 132, 199); // Sky blue
} else {
$pdf->SetTextColor(100, 116, 139);
}
$pdf->SetFont('Arial', 'B', 7.5);
} else {
$pdf->SetTextColor(15, 23, 42);
$pdf->SetFont('Arial', $isBold ? 'B' : '', 7.5);
}
$maxChar = !empty($col['max_char']) ? $col['max_char'] : 0;
if ($maxChar > 0 && mb_strlen($val) > $maxChar) {
$val = mb_strimwidth($val, 0, $maxChar, '...');
}
$displayVal = ($align === 'L' && !empty($val) && $val !== '-') ? ' ' . $val : $val;
$pdf->Cell($width, 6.5, $displayVal, 'B', 0, $align, $fill);
}
$pdf->Ln();
$fill = !$fill;
}
return $pdf->Output('S');
}
}