FHM08062601IBL - tambah footer (Validasi Oleh, Printed by, page number), fix table outer border, QR absolute di atas footer

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
sas.fajri
2026-06-09 09:05:24 +07:00
parent fcd125a252
commit 934a779770

View File

@@ -145,9 +145,58 @@ class Rpt_lab_result extends MY_Controller
{
require_once APPPATH . 'third_party/fpdf/fpdf.php';
$pdf = new FPDF('P', 'mm', 'A4');
// Footer data
$validator_name = '';
foreach ($details as $d) {
if (!empty($d['M_StaffName'])) { $validator_name = $d['M_StaffName']; }
}
$lab_number = $this->_s($h['T_OrderHeaderLabNumber'] ?? '');
$print_username = $this->_s($username);
$print_datetime = date('d-m-Y H:i:s');
$pv = $validator_name;
$pu = $print_username;
$pd = $print_datetime;
$pln = $lab_number;
$pdf = new class($pu, $pd, $pln, $pv) extends FPDF {
private $pu, $pd, $pln, $pv;
public function __construct($pu, $pd, $pln, $pv) {
parent::__construct('P', 'mm', 'A4');
$this->pu = $pu; $this->pd = $pd; $this->pln = $pln; $this->pv = $pv;
}
public function Footer() {
$ml = 10; $cw = $this->GetPageWidth() - 20;
$this->SetFont('Arial', '', 8);
// Validasi Oleh (kanan)
$this->SetY(-38);
$this->SetX($ml);
$this->Cell($cw, 5, 'Validasi Oleh', 0, 1, 'R');
$this->Ln(8);
// Garis tanda tangan (kanan 40%)
$this->SetX($ml + $cw * 0.62);
$this->Cell($cw * 0.38, 0.3, '', 'T', 1);
// Nama validator (kanan)
$this->SetX($ml);
$this->Cell($cw, 5, iconv('UTF-8', 'windows-1252//TRANSLIT', (string) $this->pv), 0, 1, 'R');
$this->Ln(2);
// Printed by (kiri)
$printed = 'Printed by : ' . $this->pu . ' / ' . $this->pd . ' / ' . $this->pln;
$this->SetX($ml);
$this->Cell($cw, 5, $printed, 0, 0, 'L');
$this->Ln();
// Page number (tengah)
$this->SetX($ml);
$this->Cell($cw, 5, $this->PageNo() . ' / {nb}', 0, 0, 'C');
}
};
$pdf->AliasNbPages('{nb}');
$pdf->SetMargins(10, 8, 10);
$pdf->SetAutoPageBreak(true, 10);
$pdf->SetAutoPageBreak(true, 42);
$pdf->AddPage();
$pw = $pdf->GetPageWidth(); // 210
@@ -248,7 +297,7 @@ class Rpt_lab_result extends MY_Controller
$pdf->SetFillColor(240, 240, 240);
$pdf->SetX($ml);
foreach ($col as $label => $w) {
$pdf->Cell($w, $row_h + 1, $label, 'LRB', 0, 'C', true);
$pdf->Cell($w, $row_h + 1, $label, '1', 0, 'C', true);
}
$pdf->Ln();
@@ -282,6 +331,8 @@ class Rpt_lab_result extends MY_Controller
$pdf->SetX($ml);
$pdf->SetFont('Arial', 'B', 8);
$pdf->Cell($cw, $row_h, $subgroup, 'LR', 1, 'L');
$pdf->SetX($ml);
$pdf->Cell($cw, 0, '', 'T', 1);
$prev_subgroup = $subgroup;
$prev_subsubgroup = null;
}
@@ -291,6 +342,8 @@ class Rpt_lab_result extends MY_Controller
$pdf->SetX($ml);
$pdf->SetFont('Arial', 'I', 8);
$pdf->Cell($cw, $row_h, ' ' . $this->_s($subsubgroup), 'LR', 1, 'L');
$pdf->SetX($ml);
$pdf->Cell($cw, 0, '', 'T', 1);
$prev_subsubgroup = $subsubgroup;
}
@@ -333,9 +386,9 @@ class Rpt_lab_result extends MY_Controller
$pdf->Cell($cw, 0, '', 'T', 1);
}
// Tutup tabel
// Tutup tabel (outer bottom border)
$pdf->SetX($ml);
$pdf->Cell($cw, 0, '', 'T', 1);
$pdf->Cell($cw, 0, '', 'B', 1);
// ── Catatan ───────────────────────────────────────────────────────────
$pdf->Ln(3);
@@ -350,25 +403,24 @@ class Rpt_lab_result extends MY_Controller
$pdf->SetX($ml);
$pdf->Cell($cw, $row_h, 'Waktu Pengambilan Spesimen', 0, 1, 'L');
foreach ($sampling as $s) {
$bahan = $this->_s($s['T_BahanName'] ?? '');
$tgl = $this->_s($s['sampling_date'] ?? '');
$jam = $this->_s($s['sample_time'] ?? '');
$bahan = $this->_s($s['T_BahanName'] ?? '');
$tgl = $this->_s($s['sampling_date'] ?? '');
$jam = $this->_s($s['sample_time'] ?? '');
$pdf->SetX($ml);
$pdf->Cell(35, $row_h, $bahan, 0, 0, 'L');
$pdf->Cell(4, $row_h, ':', 0, 0, 'C');
$pdf->Cell(35, $row_h, $tgl, 0, 0, 'L');
$pdf->Cell(30, $row_h, $jam, 0, 1, 'L');
}
$pdf->Ln(2);
}
// ── QR code ───────────────────────────────────────────────────────────
// ── QR code (absolute, 20mm di atas footer = -42-3 = -45 dari bawah) ──
if (!empty($qr_url)) {
$pdf->Ln(3);
$tmp = $this->_fetch_image_to_temp($qr_url);
if ($tmp) {
$pdf->SetX($ml);
$pdf->Image($tmp, $ml, $pdf->GetY(), 20, 20);
$page_h = $pdf->GetPageHeight();
$qr_y = $page_h - 42 - 3 - 20; // footer_margin=42, gap=3, qr_h=20
$pdf->Image($tmp, $ml, $qr_y, 20, 20);
@unlink($tmp);
}
}