Penambahan tombol PDF di Bukubesar, Neraca, Laba rugi, Neraca saldo, dan Data Barang
Format PDF tersimpan di library semua
This commit is contained in:
@@ -0,0 +1,329 @@
|
||||
<?php
|
||||
|
||||
require_once(APPPATH . 'third_party/fpdf/fpdf.php');
|
||||
|
||||
class PDF extends FPDF
|
||||
{
|
||||
// ----------------------------------------------------------------
|
||||
// PROPERTI HEADER
|
||||
// ----------------------------------------------------------------
|
||||
private $nama;
|
||||
private $alamat;
|
||||
private $logo;
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// PROPERTI TABEL
|
||||
// ----------------------------------------------------------------
|
||||
private $isTable = false;
|
||||
private $tableWidth = [];
|
||||
private $tableHeader = [];
|
||||
|
||||
// Konfigurasi tabel A4 Portrait (lebar efektif = 190mm, margin 10+10)
|
||||
// Tanggal : 22 | No Ref : 28 | Keterangan : 60 | Debit : 26 | Kredit : 26 | Saldo : 28 → TOTAL : 190
|
||||
private $colWidths = [22, 28, 60, 26, 26, 28];
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// PROPERTI INFO LAPORAN
|
||||
// ----------------------------------------------------------------
|
||||
private $namaAkun = '';
|
||||
private $periodeStr = '';
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// SETTER
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
public function setHeaderData($nama, $alamat, $logo = '')
|
||||
{
|
||||
$this->nama = $nama;
|
||||
$this->alamat = $alamat;
|
||||
$this->logo = $logo;
|
||||
}
|
||||
|
||||
public function setInfoLaporan($namaAkun, $periodeStr)
|
||||
{
|
||||
$this->namaAkun = $namaAkun;
|
||||
$this->periodeStr = $periodeStr;
|
||||
}
|
||||
|
||||
public function setTableHeader($header, $width)
|
||||
{
|
||||
$this->tableHeader = $header;
|
||||
$this->tableWidth = $width;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// HEADER HALAMAN
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
function Header()
|
||||
{
|
||||
// Lebar halaman A4 Portrait = 210mm (area cetak 10..200)
|
||||
$pageRight = 200;
|
||||
|
||||
// Logo (opsional)
|
||||
if (!empty($this->logo) && file_exists($this->logo)) {
|
||||
$this->Image($this->logo, 10, 6, 18);
|
||||
$this->SetXY(31, 10);
|
||||
} else {
|
||||
$this->SetXY(10, 10);
|
||||
}
|
||||
|
||||
// Nama perusahaan
|
||||
$this->SetFont('Arial', 'B', 12);
|
||||
$this->Cell(0, 6, $this->nama, 0, 1, 'L');
|
||||
|
||||
// Alamat
|
||||
$this->SetFont('Arial', '', 9);
|
||||
$x = !empty($this->logo) && file_exists($this->logo) ? 31 : 10;
|
||||
$this->SetX($x);
|
||||
$this->Cell(0, 5, $this->alamat, 0, 1, 'L');
|
||||
|
||||
// Garis pemisah
|
||||
$this->Ln(2);
|
||||
$this->SetLineWidth(0.6);
|
||||
$this->Line(10, $this->GetY(), $pageRight, $this->GetY());
|
||||
$this->SetLineWidth(0.2);
|
||||
$this->Line(10, $this->GetY() + 1, $pageRight, $this->GetY() + 1);
|
||||
$this->Ln(5);
|
||||
|
||||
// Judul
|
||||
$this->SetFont('Arial', 'B', 13);
|
||||
$this->SetTextColor(245, 140, 0);
|
||||
$this->Cell(0, 7, 'LAPORAN BUKU BESAR', 0, 1, 'C');
|
||||
$this->SetTextColor(0, 0, 0);
|
||||
|
||||
// Periode
|
||||
$this->SetFont('Arial', '', 10);
|
||||
$this->Cell(0, 5, $this->periodeStr, 0, 1, 'C');
|
||||
|
||||
$this->Ln(3);
|
||||
|
||||
// Info akun & tanggal cetak
|
||||
$colLabel = 35;
|
||||
$colSep = 5;
|
||||
$startX = ($this->GetPageWidth() - array_sum($this->colWidths)) / 2;
|
||||
|
||||
$this->SetX($startX);
|
||||
$this->SetFont('Arial', 'B', 10);
|
||||
$this->Cell($colLabel, 6, 'Akun');
|
||||
$this->SetFont('Arial', '', 10);
|
||||
$this->Cell($colSep, 6, ':');
|
||||
$this->Cell(0, 6, $this->namaAkun, 0, 1);
|
||||
|
||||
$this->SetX($startX);
|
||||
$this->SetFont('Arial', 'B', 10);
|
||||
$this->Cell($colLabel, 6, 'Di Cetak Pada');
|
||||
$this->SetFont('Arial', '', 10);
|
||||
$this->Cell($colSep, 6, ':');
|
||||
$this->Cell(0, 6, date('d-m-Y') . ' Jam ' . date('H:i:s'), 0, 1);
|
||||
|
||||
$this->Ln(3);
|
||||
|
||||
if ($this->isTable && !empty($this->tableHeader)) {
|
||||
$this->_drawTableHeader();
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// FOOTER HALAMAN
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
function Footer()
|
||||
{
|
||||
$this->SetY(-10);
|
||||
$this->SetFont('Arial', 'I', 8);
|
||||
$this->Cell(0, 5, 'Halaman ' . $this->PageNo(), 0, 0, 'C');
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// HELPER: Gambar baris header tabel
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
private function _drawTableHeader()
|
||||
{
|
||||
$startX = ($this->GetPageWidth() - array_sum($this->colWidths)) / 2;
|
||||
$this->SetX($startX);
|
||||
$this->SetFillColor(245, 140, 0);
|
||||
$this->SetTextColor(255, 255, 255);
|
||||
$this->SetFont('Arial', 'B', 9);
|
||||
|
||||
foreach ($this->tableHeader as $k => $v) {
|
||||
$this->Cell($this->tableWidth[$k], 8, $v, 1, 0, 'C', true);
|
||||
}
|
||||
|
||||
$this->SetTextColor(0, 0, 0);
|
||||
$this->Ln();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// TABEL BUKU BESAR
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
public function BukuBesarTable($result)
|
||||
{
|
||||
$header = ['Tanggal', 'No Ref', 'Keterangan', 'Debit', 'Kredit', 'Saldo'];
|
||||
|
||||
$this->isTable = true;
|
||||
$this->setTableHeader($header, $this->colWidths);
|
||||
|
||||
// Header halaman pertama
|
||||
$this->_drawTableHeader();
|
||||
|
||||
$startX = ($this->GetPageWidth() - array_sum($this->colWidths)) / 2;
|
||||
$lineH = 5;
|
||||
|
||||
$this->SetFont('Arial', '', 9);
|
||||
|
||||
if (empty($result)) {
|
||||
$this->SetX($startX);
|
||||
$this->SetFont('Arial', 'B', 10);
|
||||
$this->Cell(array_sum($this->colWidths), 8, 'Tidak ada data', 1, 1, 'C');
|
||||
$this->isTable = false;
|
||||
return;
|
||||
}
|
||||
|
||||
$fill = false;
|
||||
|
||||
// Batas bawah A4 Portrait (297mm) dikurangi area footer
|
||||
$pageBreakTrigger = 277;
|
||||
|
||||
foreach ($result as $row) {
|
||||
|
||||
// Hitung tinggi baris berdasar No Ref & Keterangan (keduanya MultiCell)
|
||||
$nbRef = $this->NbLines($this->colWidths[1], $row['no_ref']);
|
||||
$nbKet = $this->NbLines($this->colWidths[2], $row['keterangan']);
|
||||
$nbLines = max(1, $nbRef, $nbKet);
|
||||
$rowH = $nbLines * $lineH;
|
||||
|
||||
// Ganti halaman jika mendekati batas bawah
|
||||
if ($this->GetY() + $rowH > $pageBreakTrigger) {
|
||||
$this->AddPage('P', 'A4');
|
||||
}
|
||||
|
||||
if ($fill) {
|
||||
$this->SetFillColor(245, 245, 245);
|
||||
}
|
||||
|
||||
$x = $startX;
|
||||
$y = $this->GetY();
|
||||
|
||||
// Tanggal
|
||||
$this->SetX($x);
|
||||
$this->Cell($this->colWidths[0], $rowH, date('d-m-Y', strtotime($row['tanggal'])), 1, 0, 'C', $fill);
|
||||
|
||||
// No Ref (MultiCell)
|
||||
$xRef = $this->GetX();
|
||||
$offsetRef = ($rowH - $nbRef * $lineH) / 2;
|
||||
// gambar border kotak dulu
|
||||
$this->Rect($xRef, $y, $this->colWidths[1], $rowH, $fill ? 'DF' : 'D');
|
||||
$this->SetXY($xRef, $y + $offsetRef);
|
||||
$this->MultiCell($this->colWidths[1], $lineH, $row['no_ref'], 0, 'C', false);
|
||||
|
||||
// Keterangan (MultiCell)
|
||||
$xKet = $xRef + $this->colWidths[1];
|
||||
$offsetKet = ($rowH - $nbKet * $lineH) / 2;
|
||||
$this->Rect($xKet, $y, $this->colWidths[2], $rowH, $fill ? 'DF' : 'D');
|
||||
$this->SetXY($xKet, $y + $offsetKet);
|
||||
$this->MultiCell($this->colWidths[2], $lineH, $row['keterangan'], 0, 'L', false);
|
||||
|
||||
// Kolom angka
|
||||
$this->SetXY($xKet + $this->colWidths[2], $y);
|
||||
$this->Cell($this->colWidths[3], $rowH, number_format($row['debit'], 2, ',', '.'), 1, 0, 'R', $fill);
|
||||
$this->Cell($this->colWidths[4], $rowH, number_format($row['kredit'], 2, ',', '.'), 1, 0, 'R', $fill);
|
||||
$this->Cell($this->colWidths[5], $rowH, number_format($row['saldo'], 2, ',', '.'), 1, 0, 'R', $fill);
|
||||
|
||||
$this->SetXY($x, $y + $rowH);
|
||||
|
||||
$fill = !$fill;
|
||||
}
|
||||
|
||||
$this->isTable = false;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// BARIS TOTAL
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
public function BukuBesarTotal($totalDebit, $totalKredit, $saldo)
|
||||
{
|
||||
$startX = ($this->GetPageWidth() - array_sum($this->colWidths)) / 2;
|
||||
$labelWidth = $this->colWidths[0] + $this->colWidths[1] + $this->colWidths[2];
|
||||
|
||||
$this->SetX($startX);
|
||||
$this->SetFillColor(255, 204, 102);
|
||||
$this->SetFont('Arial', 'B', 9);
|
||||
|
||||
$this->Cell($labelWidth, 8, 'TOTAL', 1, 0, 'C', true);
|
||||
$this->Cell($this->colWidths[3], 8, number_format($totalDebit, 2, ',', '.'), 1, 0, 'R', true);
|
||||
$this->Cell($this->colWidths[4], 8, number_format($totalKredit, 2, ',', '.'), 1, 0, 'R', true);
|
||||
$this->Cell($this->colWidths[5], 8, number_format($saldo, 2, ',', '.'), 1, 1, 'R', true);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// TANDA TANGAN
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
public function Pembuat($nama, $jabatan = '')
|
||||
{
|
||||
$signWidth = 70;
|
||||
$signX = 125; // disesuaikan untuk A4 Portrait (210mm)
|
||||
|
||||
$this->Ln(10);
|
||||
$this->SetX($signX);
|
||||
$this->SetFont('Arial', '', 10);
|
||||
$this->Cell($signWidth, 6, 'Mengetahui,', 0, 1, 'C');
|
||||
|
||||
$this->Ln(10);
|
||||
$this->SetX($signX);
|
||||
$this->SetFont('Arial', 'B', 10);
|
||||
$this->Cell($signWidth, 6, $nama, 0, 1, 'C');
|
||||
|
||||
if (!empty($jabatan)) {
|
||||
$this->SetX($signX);
|
||||
$this->SetFont('Arial', '', 9);
|
||||
$this->Cell($signWidth, 5, '(' . $jabatan . ')', 0, 1, 'C');
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// HELPER: Hitung jumlah baris MultiCell
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
private function NbLines($w, $txt)
|
||||
{
|
||||
$cw = &$this->CurrentFont['cw'];
|
||||
if ($w == 0) {
|
||||
$w = $this->w - $this->rMargin - $this->x;
|
||||
}
|
||||
$wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize;
|
||||
$s = str_replace("\r", '', (string)$txt);
|
||||
$nb = strlen($s);
|
||||
if ($nb > 0 && $s[$nb - 1] == "\n") {
|
||||
$nb--;
|
||||
}
|
||||
$sep = -1;
|
||||
$i = 0; $j = 0; $l = 0; $nl = 1;
|
||||
while ($i < $nb) {
|
||||
$c = $s[$i];
|
||||
if ($c == "\n") {
|
||||
$i++; $sep = -1; $j = $i; $l = 0; $nl++;
|
||||
continue;
|
||||
}
|
||||
if ($c == ' ') {
|
||||
$sep = $i;
|
||||
}
|
||||
$l += isset($cw[ord($c)]) ? $cw[ord($c)] : 600;
|
||||
if ($l > $wmax) {
|
||||
if ($sep == -1) {
|
||||
if ($i == $j) $i++;
|
||||
} else {
|
||||
$i = $sep + 1;
|
||||
}
|
||||
$sep = -1; $j = $i; $l = 0; $nl++;
|
||||
} else {
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
return $nl;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
<?php
|
||||
|
||||
require_once(APPPATH.'third_party/fpdf/fpdf.php');
|
||||
|
||||
class PDF extends FPDF
|
||||
{
|
||||
private $nama;
|
||||
private $alamat;
|
||||
private $telepon;
|
||||
private $logo;
|
||||
|
||||
private $isTable = false;
|
||||
private $tableWidth = [];
|
||||
private $tableHeader = [];
|
||||
|
||||
// Lebar kertas A4 Portrait = 210mm, margin kiri+kanan = 10+10 = 20mm
|
||||
// Area cetak efektif = 190mm
|
||||
private $pageWidth = 190;
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// SETTER
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
public function setHeaderData($nama, $alamat, $telepon, $logo = '')
|
||||
{
|
||||
$this->nama = $nama;
|
||||
$this->alamat = $alamat;
|
||||
$this->telepon = $telepon;
|
||||
$this->logo = $logo;
|
||||
}
|
||||
|
||||
public function setTableHeader($header, $width)
|
||||
{
|
||||
$this->tableHeader = $header;
|
||||
$this->tableWidth = $width;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// HEADER HALAMAN
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
function Header()
|
||||
{
|
||||
// Logo (opsional)
|
||||
if (!empty($this->logo) && file_exists($this->logo)) {
|
||||
$this->Image($this->logo, 10, 8, 18);
|
||||
$this->SetXY(31, 10);
|
||||
} else {
|
||||
$this->SetXY(10, 10);
|
||||
}
|
||||
|
||||
// Nama perusahaan
|
||||
$this->SetFont('Arial', 'B', 12);
|
||||
$this->Cell(0, 6, $this->nama, 0, 1, 'L');
|
||||
|
||||
// Alamat
|
||||
$this->SetFont('Arial', '', 9);
|
||||
$x = !empty($this->logo) && file_exists($this->logo) ? 31 : 10;
|
||||
$this->SetX($x);
|
||||
$this->Cell(0, 5, $this->alamat, 0, 1, 'L');
|
||||
|
||||
$this->SetX($x);
|
||||
$this->Cell(0, 5, 'Telp : ' . $this->telepon, 0, 1, 'L');
|
||||
|
||||
// Garis pemisah header (A4 Portrait: dari x=10 s/d x=200)
|
||||
$this->Ln(2);
|
||||
$this->SetLineWidth(0.6);
|
||||
$this->Line(10, $this->GetY(), 200, $this->GetY());
|
||||
$this->SetLineWidth(0.2);
|
||||
$this->Line(10, $this->GetY() + 1, 200, $this->GetY() + 1);
|
||||
|
||||
$this->Ln(5);
|
||||
|
||||
// Judul laporan
|
||||
$this->SetFont('Arial', 'B', 14);
|
||||
$this->SetTextColor(245, 140, 0);
|
||||
$this->Cell(0, 8, 'LAPORAN DATA BARANG', 0, 1, 'C');
|
||||
$this->SetTextColor(0, 0, 0);
|
||||
|
||||
// Tanggal cetak
|
||||
$this->SetFont('Arial', '', 9);
|
||||
$this->Cell(0, 5, 'DIcetak Pada : ' . date('d-m-Y') . ' - ' . date('H:i:s'), 0, 1, 'C');
|
||||
|
||||
$this->Ln(3);
|
||||
|
||||
// Header tabel (muncul otomatis saat ganti halaman)
|
||||
if ($this->isTable && !empty($this->tableHeader)) {
|
||||
$this->_drawTableHeader();
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// FOOTER HALAMAN
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
function Footer()
|
||||
{
|
||||
$this->SetY(-10);
|
||||
$this->SetFont('Arial', 'I', 8);
|
||||
$this->Cell(0, 5, 'Halaman ' . $this->PageNo(), 0, 0, 'C');
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// HELPER: Gambar baris header tabel
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
private function _drawTableHeader()
|
||||
{
|
||||
$this->SetFillColor(245, 140, 0);
|
||||
$this->SetTextColor(255, 255, 255);
|
||||
$this->SetFont('Arial', 'B', 8);
|
||||
|
||||
foreach ($this->tableHeader as $k => $v) {
|
||||
$this->Cell($this->tableWidth[$k], 7, $v, 1, 0, 'C', true);
|
||||
}
|
||||
|
||||
$this->SetTextColor(0, 0, 0);
|
||||
$this->Ln();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// TABEL DATA BARANG
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
public function ItemsTable($data)
|
||||
{
|
||||
/*
|
||||
* Total lebar kolom = 190mm (pas A4 Portrait, margin 10mm kiri & kanan)
|
||||
*
|
||||
* NO : 8
|
||||
* TGL BELI : 22
|
||||
* KODE : 22
|
||||
* NAMA BARANG : 48 ← kolom terpanjang
|
||||
* GUDANG : 35
|
||||
* STOK : 13
|
||||
* HARGA BELI : 21
|
||||
* HARGA JUAL : 21
|
||||
* ----
|
||||
* TOTAL : 190
|
||||
*/
|
||||
$w = [8, 22, 22, 48, 35, 13, 21, 21];
|
||||
|
||||
$header = [
|
||||
'NO',
|
||||
'TGL BELI',
|
||||
'KODE',
|
||||
'NAMA BARANG',
|
||||
'GUDANG',
|
||||
'STOK',
|
||||
'HARGA BELI',
|
||||
'HARGA JUAL',
|
||||
];
|
||||
|
||||
// Daftarkan SEBELUM AddPage() agar Header() sudah tahu isTable=true
|
||||
// ketika halaman berikutnya dibuat (termasuk halaman ke-2, 3, dst.)
|
||||
$this->isTable = true;
|
||||
$this->setTableHeader($header, $w);
|
||||
|
||||
// Gambar header tabel di halaman PERTAMA secara eksplisit,
|
||||
// karena saat AddPage() awal dipanggil isTable masih false.
|
||||
$this->_drawTableHeader();
|
||||
|
||||
// ---- Baris data ----
|
||||
$this->SetFont('Arial', '', 8);
|
||||
$no = 1;
|
||||
|
||||
foreach ($data as $row) {
|
||||
|
||||
// Ganti halaman sebelum batas bawah (A4 Portrait: tinggi efektif ~267mm)
|
||||
if ($this->GetY() > 262) {
|
||||
$this->AddPage('P', 'A4');
|
||||
// _drawTableHeader() sudah dipanggil otomatis oleh Header()
|
||||
}
|
||||
|
||||
// Warna baris selang-seling
|
||||
if ($no % 2 === 0) {
|
||||
$this->SetFillColor(255, 245, 230);
|
||||
$fill = true;
|
||||
} else {
|
||||
$fill = false;
|
||||
}
|
||||
|
||||
$this->Cell($w[0], 6, $no++, 1, 0, 'C', $fill);
|
||||
$this->Cell($w[1], 6, date('d-m-Y', strtotime($row->tanggal_pembelian)), 1, 0, 'C', $fill);
|
||||
$this->Cell($w[2], 6, $row->kode_detail, 1, 0, 'C', $fill);
|
||||
$this->Cell($w[3], 6, mb_substr($row->nama_barang, 0, 45), 1, 0, 'L', $fill);
|
||||
$this->Cell($w[4], 6, mb_substr($row->gudang ?: '-', 0, 30), 1, 0, 'L', $fill);
|
||||
$this->Cell($w[5], 6, number_format($row->stok), 1, 0, 'R', $fill);
|
||||
$this->Cell($w[6], 6, number_format($row->harga_beli, 0, ',', '.'), 1, 0, 'R', $fill);
|
||||
$this->Cell($w[7], 6, number_format($row->harga_jual, 0, ',', '.'), 1, 1, 'R', $fill);
|
||||
}
|
||||
|
||||
$this->isTable = false;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// RINGKASAN & TANDA TANGAN
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
public function TotalBarang($jumlah)
|
||||
{
|
||||
$this->Ln(4);
|
||||
$this->SetFont('Arial', 'B', 10);
|
||||
$this->Cell(0, 7, 'Total Data Barang : ' . $jumlah, 0, 1, 'R');
|
||||
}
|
||||
|
||||
// public function Pembuat($nama)
|
||||
// {
|
||||
// $this->Ln(12);
|
||||
// $this->SetFont('Arial', '', 10);
|
||||
// $this->Cell(0, 6, 'Mengetahui,', 0, 1, 'R');
|
||||
// $this->Ln(18);
|
||||
// $this->SetFont('Arial', 'B', 10);
|
||||
// $this->Cell(0, 6, $nama, 0, 1, 'R');
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,345 @@
|
||||
<?php
|
||||
|
||||
require_once(APPPATH . 'third_party/fpdf/fpdf.php');
|
||||
|
||||
class PDF extends FPDF
|
||||
{
|
||||
// ----------------------------------------------------------------
|
||||
// PROPERTI HEADER
|
||||
// ----------------------------------------------------------------
|
||||
private $nama;
|
||||
private $alamat;
|
||||
private $logo;
|
||||
private $periodeStr = '';
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// KONFIGURASI TABEL
|
||||
// ----------------------------------------------------------------
|
||||
// A4 Portrait efektif = 190mm, margin 10+10
|
||||
// Kolom: Kode 20 | Nama Akun 120 | Saldo 50 → TOTAL 190
|
||||
private $colWidths = [20, 120, 50];
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// SETTER
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
public function setHeaderData($nama, $alamat, $logo = '')
|
||||
{
|
||||
$this->nama = $nama;
|
||||
$this->alamat = $alamat;
|
||||
$this->logo = $logo;
|
||||
}
|
||||
|
||||
public function setInfoLaporan($periodeStr)
|
||||
{
|
||||
$this->periodeStr = $periodeStr;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// HEADER HALAMAN
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
function Header()
|
||||
{
|
||||
// Logo (opsional)
|
||||
if (!empty($this->logo) && file_exists($this->logo)) {
|
||||
$this->Image($this->logo, 10, 6, 18);
|
||||
$this->SetXY(31, 10);
|
||||
} else {
|
||||
$this->SetXY(10, 10);
|
||||
}
|
||||
|
||||
// Nama perusahaan
|
||||
$this->SetFont('Arial', 'B', 12);
|
||||
$this->Cell(0, 6, $this->nama, 0, 1, 'L');
|
||||
|
||||
// Alamat
|
||||
$this->SetFont('Arial', '', 9);
|
||||
$x = !empty($this->logo) && file_exists($this->logo) ? 31 : 10;
|
||||
$this->SetX($x);
|
||||
$this->Cell(0, 5, $this->alamat, 0, 1, 'L');
|
||||
|
||||
// Garis pemisah (A4 Portrait: x=10 s/d x=200)
|
||||
$this->Ln(2);
|
||||
$this->SetLineWidth(0.6);
|
||||
$this->Line(10, $this->GetY(), 200, $this->GetY());
|
||||
$this->SetLineWidth(0.2);
|
||||
$this->Line(10, $this->GetY() + 1, 200, $this->GetY() + 1);
|
||||
$this->Ln(5);
|
||||
|
||||
// Judul
|
||||
$this->SetFont('Arial', 'B', 13);
|
||||
$this->SetTextColor(245, 140, 0);
|
||||
$this->Cell(0, 7, 'LAPORAN LABA RUGI', 0, 1, 'C');
|
||||
$this->SetTextColor(0, 0, 0);
|
||||
|
||||
// Periode
|
||||
$this->SetFont('Arial', '', 10);
|
||||
$this->Cell(0, 5, $this->periodeStr, 0, 1, 'C');
|
||||
|
||||
// Tanggal cetak
|
||||
$this->SetFont('Arial', '', 9);
|
||||
$this->Cell(0, 5, 'Di Cetak Pada : ' . date('d-m-Y') . ' Jam ' . date('H:i:s'), 0, 1, 'C');
|
||||
|
||||
$this->Ln(4);
|
||||
|
||||
// Header kolom tabel
|
||||
$this->_drawTableHeader();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// FOOTER HALAMAN
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
function Footer()
|
||||
{
|
||||
$this->SetY(-10);
|
||||
$this->SetFont('Arial', 'I', 8);
|
||||
$this->Cell(0, 5, 'Halaman ' . $this->PageNo(), 0, 0, 'C');
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// HELPER: posisi X awal — TABEL RATA TENGAH KERTAS
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
private function _startX()
|
||||
{
|
||||
$tableW = array_sum($this->colWidths);
|
||||
return ($this->GetPageWidth() - $tableW) / 2;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// HELPER: Gambar header kolom tabel
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
private function _drawTableHeader()
|
||||
{
|
||||
$startX = $this->_startX();
|
||||
|
||||
$this->SetX($startX);
|
||||
$this->SetFillColor(245, 140, 0);
|
||||
$this->SetTextColor(255, 255, 255);
|
||||
$this->SetFont('Arial', 'B', 9);
|
||||
|
||||
$this->Cell($this->colWidths[0], 8, 'Kode', 1, 0, 'C', true);
|
||||
$this->Cell($this->colWidths[1], 8, 'Nama Akun', 1, 0, 'C', true);
|
||||
$this->Cell($this->colWidths[2], 8, 'Saldo', 1, 1, 'C', true);
|
||||
|
||||
$this->SetTextColor(0, 0, 0);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// HELPER: Gambar baris judul section (PENDAPATAN / BEBAN)
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
private function _drawSectionTitle($title)
|
||||
{
|
||||
if ($this->GetY() + 8 > 270) {
|
||||
$this->AddPage('P', 'A4');
|
||||
}
|
||||
|
||||
$startX = $this->_startX();
|
||||
$tableW = array_sum($this->colWidths);
|
||||
|
||||
$this->SetX($startX);
|
||||
$this->SetFillColor(255, 224, 178);
|
||||
$this->SetFont('Arial', 'B', 9);
|
||||
$this->Cell($tableW, 7, $title, 1, 1, 'L', true);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// HELPER: Gambar baris detail akun (dengan dukungan multiline Nama Akun)
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
private function _drawRow($kode, $namaAkun, $saldo)
|
||||
{
|
||||
$lineH = 6;
|
||||
|
||||
$nbLines = $this->NbLines($this->colWidths[1], $namaAkun);
|
||||
$rowH = max(1, $nbLines) * $lineH;
|
||||
|
||||
if ($this->GetY() + $rowH > 270) {
|
||||
$this->AddPage('P', 'A4');
|
||||
}
|
||||
|
||||
$startX = $this->_startX();
|
||||
$y = $this->GetY();
|
||||
|
||||
$this->SetFont('Arial', '', 9);
|
||||
$this->SetXY($startX, $y);
|
||||
$this->Cell($this->colWidths[0], $rowH, $kode, 1, 0, 'C');
|
||||
|
||||
$xNama = $this->GetX();
|
||||
$this->MultiCell($this->colWidths[1], $lineH, $namaAkun, 1, 'L');
|
||||
|
||||
$this->SetXY($xNama + $this->colWidths[1], $y);
|
||||
$this->Cell($this->colWidths[2], $rowH, number_format($saldo, 0, ',', '.'), 1, 0, 'R');
|
||||
|
||||
$this->SetXY($startX, $y + $rowH);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// HELPER: Gambar baris total section
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
private function _drawSectionTotal($label, $total)
|
||||
{
|
||||
if ($this->GetY() + 7 > 270) {
|
||||
$this->AddPage('P', 'A4');
|
||||
}
|
||||
|
||||
$startX = $this->_startX();
|
||||
|
||||
$this->SetX($startX);
|
||||
$this->SetFillColor(255, 224, 178);
|
||||
$this->SetFont('Arial', 'B', 9);
|
||||
$this->Cell($this->colWidths[0] + $this->colWidths[1], 7, $label, 1, 0, 'L', true);
|
||||
$this->Cell($this->colWidths[2], 7, number_format($total, 0, ',', '.'), 1, 1, 'R', true);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// TABEL LABA RUGI (PENDAPATAN, BEBAN, masing-masing dengan rincian akun)
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
public function LabaRugiTable($pendapatan, $beban, $totalPendapatan, $totalBeban)
|
||||
{
|
||||
// ---- SECTION PENDAPATAN ----
|
||||
$this->_drawSectionTitle('PENDAPATAN');
|
||||
|
||||
if (empty($pendapatan)) {
|
||||
$this->_drawRow('-', 'Tidak ada data', 0);
|
||||
} else {
|
||||
foreach ($pendapatan as $row) {
|
||||
$this->_drawRow($row['kode'], $row['nama'], $row['saldo']);
|
||||
}
|
||||
}
|
||||
|
||||
$this->_drawSectionTotal('TOTAL PENDAPATAN', $totalPendapatan);
|
||||
|
||||
// ---- SECTION BEBAN ----
|
||||
$this->AddPage('P', 'A4');
|
||||
$this->_drawSectionTitle('BEBAN');
|
||||
|
||||
if (empty($beban)) {
|
||||
$this->_drawRow('-', 'Tidak ada data', 0);
|
||||
} else {
|
||||
foreach ($beban as $row) {
|
||||
$this->_drawRow($row['kode'], $row['nama'], $row['saldo']);
|
||||
}
|
||||
}
|
||||
|
||||
$this->_drawSectionTotal('TOTAL BEBAN', $totalBeban);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// RINGKASAN: LABA / RUGI BERSIH
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
public function LabaRugiRingkasan($laba)
|
||||
{
|
||||
if ($this->GetY() + 9 > 270) {
|
||||
$this->AddPage('P', 'A4');
|
||||
}
|
||||
|
||||
$startX = $this->_startX();
|
||||
$tableW = array_sum($this->colWidths);
|
||||
$labelW = $tableW - $this->colWidths[2];
|
||||
|
||||
$this->Ln(2);
|
||||
$this->SetX($startX);
|
||||
$this->SetFont('Arial', 'B', 10);
|
||||
|
||||
if ($laba >= 0) {
|
||||
$this->SetFillColor(198, 239, 206); // hijau, laba
|
||||
$label = 'LABA BERSIH';
|
||||
} else {
|
||||
$this->SetFillColor(255, 199, 206); // merah, rugi
|
||||
$label = 'RUGI BERSIH';
|
||||
}
|
||||
|
||||
$this->Cell($labelW, 8, $label, 1, 0, 'L', true);
|
||||
$this->Cell($this->colWidths[2], 8, number_format($laba, 0, ',', '.'), 1, 1, 'R', true);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// TANDA TANGAN
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
public function Pembuat($nama, $jabatan = '')
|
||||
{
|
||||
$startX = $this->_startX();
|
||||
$tableW = array_sum($this->colWidths);
|
||||
$signWidth = 70;
|
||||
$signX = $startX + $tableW - $signWidth; // sejajar sisi kanan tabel
|
||||
|
||||
$this->Ln(10);
|
||||
$this->SetX($signX);
|
||||
$this->SetFont('Arial', '', 10);
|
||||
$this->Cell($signWidth, 6, 'Mengetahui,', 0, 1, 'R');
|
||||
|
||||
$this->Ln(10);
|
||||
$this->SetX($signX);
|
||||
$this->SetFont('Arial', 'B', 10);
|
||||
$this->Cell($signWidth, 6, $nama, 0, 1, 'R');
|
||||
|
||||
if (!empty($jabatan)) {
|
||||
$this->SetX($signX);
|
||||
$this->SetFont('Arial', '', 9);
|
||||
$this->Cell($signWidth, 5, '(' . $jabatan . ')', 0, 1, 'R');
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// HELPER: Hitung jumlah baris yang dibutuhkan MultiCell
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
private function NbLines($w, $txt)
|
||||
{
|
||||
$cw = &$this->CurrentFont['cw'];
|
||||
if ($w == 0) {
|
||||
$w = $this->w - $this->rMargin - $this->x;
|
||||
}
|
||||
$wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize;
|
||||
$s = str_replace("\r", '', $txt);
|
||||
$nb = strlen($s);
|
||||
if ($nb > 0 && $s[$nb - 1] == "\n") {
|
||||
$nb--;
|
||||
}
|
||||
$sep = -1;
|
||||
$i = 0;
|
||||
$j = 0;
|
||||
$l = 0;
|
||||
$nl = 1;
|
||||
while ($i < $nb) {
|
||||
$c = $s[$i];
|
||||
if ($c == "\n") {
|
||||
$i++;
|
||||
$sep = -1;
|
||||
$j = $i;
|
||||
$l = 0;
|
||||
$nl++;
|
||||
continue;
|
||||
}
|
||||
if ($c == ' ') {
|
||||
$sep = $i;
|
||||
}
|
||||
$l += isset($cw[ord($c)]) ? $cw[ord($c)] : 600;
|
||||
if ($l > $wmax) {
|
||||
if ($sep == -1) {
|
||||
if ($i == $j) {
|
||||
$i++;
|
||||
}
|
||||
} else {
|
||||
$i = $sep + 1;
|
||||
}
|
||||
$sep = -1;
|
||||
$j = $i;
|
||||
$l = 0;
|
||||
$nl++;
|
||||
} else {
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
return $nl;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,296 @@
|
||||
<?php
|
||||
require_once(APPPATH . 'third_party/fpdf/fpdf.php');
|
||||
|
||||
class PDF extends FPDF
|
||||
{
|
||||
private $nama;
|
||||
private $alamat;
|
||||
private $logo;
|
||||
private $periodeStr = '';
|
||||
|
||||
private $colWidths = [15, 47, 23];
|
||||
private $gap = 10;
|
||||
|
||||
public function setHeaderData($nama, $alamat, $logo = '')
|
||||
{
|
||||
$this->nama = $nama;
|
||||
$this->alamat = $alamat;
|
||||
$this->logo = $logo;
|
||||
}
|
||||
|
||||
public function setInfoLaporan($periodeStr)
|
||||
{
|
||||
$this->periodeStr = $periodeStr;
|
||||
}
|
||||
|
||||
function Header()
|
||||
{
|
||||
if (!empty($this->logo) && file_exists($this->logo)) {
|
||||
$this->Image($this->logo, 10, 6, 18);
|
||||
$this->SetXY(31, 10);
|
||||
} else {
|
||||
$this->SetXY(10, 10);
|
||||
}
|
||||
|
||||
$this->SetFont('Arial', 'B', 12);
|
||||
$this->Cell(0, 6, $this->nama, 0, 1, 'L');
|
||||
|
||||
$this->SetFont('Arial', '', 9);
|
||||
$x = !empty($this->logo) && file_exists($this->logo) ? 31 : 10;
|
||||
$this->SetX($x);
|
||||
$this->Cell(0, 5, $this->alamat, 0, 1, 'L');
|
||||
|
||||
$this->Ln(2);
|
||||
$this->SetLineWidth(0.6);
|
||||
$this->Line(10, $this->GetY(), 200, $this->GetY());
|
||||
$this->SetLineWidth(0.2);
|
||||
$this->Line(10, $this->GetY() + 1, 200, $this->GetY() + 1);
|
||||
$this->Ln(5);
|
||||
|
||||
$this->SetFont('Arial', 'B', 13);
|
||||
$this->SetTextColor(245, 140, 0);
|
||||
$this->Cell(0, 7, 'LAPORAN NERACA', 0, 1, 'C');
|
||||
$this->SetTextColor(0, 0, 0);
|
||||
|
||||
$this->SetFont('Arial', '', 10);
|
||||
$this->Cell(0, 5, $this->periodeStr, 0, 1, 'C');
|
||||
|
||||
$this->SetFont('Arial', '', 9);
|
||||
$this->Cell(0, 5, 'Di Cetak Pada : ' . date('d-m-Y') . ' - ' . date('H:i:s'), 0, 1, 'C');
|
||||
|
||||
$this->Ln(4);
|
||||
$this->_drawSectionHeader();
|
||||
}
|
||||
|
||||
function Footer()
|
||||
{
|
||||
$this->SetY(-10);
|
||||
$this->SetFont('Arial', 'I', 8);
|
||||
$this->Cell(0, 5, 'Halaman ' . $this->PageNo(), 0, 0, 'C');
|
||||
}
|
||||
|
||||
private function _drawSectionHeader()
|
||||
{
|
||||
$startX = $this->_startX();
|
||||
$tableW = array_sum($this->colWidths);
|
||||
|
||||
$this->SetX($startX);
|
||||
$this->SetFillColor(245, 140, 0);
|
||||
$this->SetTextColor(255, 255, 255);
|
||||
$this->SetFont('Arial', 'B', 10);
|
||||
$this->Cell($tableW, 7, 'ACTIVA', 1, 0, 'C', true);
|
||||
|
||||
$this->SetX($startX + $tableW + $this->gap);
|
||||
$this->Cell($tableW, 7, 'PASIVA', 1, 1, 'C', true);
|
||||
|
||||
$this->SetFont('Arial', 'B', 8);
|
||||
$this->SetFillColor(255, 224, 178);
|
||||
$this->SetTextColor(0, 0, 0);
|
||||
|
||||
$this->SetX($startX);
|
||||
$this->Cell($this->colWidths[0], 6, 'Kode', 1, 0, 'C', true);
|
||||
$this->Cell($this->colWidths[1], 6, 'Nama Akun', 1, 0, 'C', true);
|
||||
$this->Cell($this->colWidths[2], 6, 'Saldo', 1, 0, 'C', true);
|
||||
|
||||
$this->SetX($startX + $tableW + $this->gap);
|
||||
$this->Cell($this->colWidths[0], 6, 'Kode', 1, 0, 'C', true);
|
||||
$this->Cell($this->colWidths[1], 6, 'Nama Akun', 1, 0, 'C', true);
|
||||
$this->Cell($this->colWidths[2], 6, 'Saldo', 1, 1, 'C', true);
|
||||
}
|
||||
|
||||
private function _startX()
|
||||
{
|
||||
$totalW = (array_sum($this->colWidths) * 2) + $this->gap;
|
||||
return ($this->GetPageWidth() - $totalW) / 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hitung jumlah baris yang dibutuhkan MultiCell untuk teks tertentu
|
||||
* pada lebar kolom $w. Diadaptasi dari contoh resmi FPDF.
|
||||
*/
|
||||
private function _nbLines($w, $txt)
|
||||
{
|
||||
if ($txt === null || $txt === '') return 1;
|
||||
$cw = &$this->CurrentFont['cw'];
|
||||
if ($w == 0) {
|
||||
$w = $this->w - $this->rMargin - $this->x;
|
||||
}
|
||||
$wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize;
|
||||
$s = str_replace("\r", '', (string)$txt);
|
||||
$nb = strlen($s);
|
||||
if ($nb > 0 && $s[$nb - 1] == "\n") $nb--;
|
||||
$sep = -1; $i = 0; $j = 0; $l = 0; $nl = 1;
|
||||
while ($i < $nb) {
|
||||
$c = $s[$i];
|
||||
if ($c == "\n") { $i++; $sep = -1; $j = $i; $l = 0; $nl++; continue; }
|
||||
if ($c == ' ') $sep = $i;
|
||||
$l += isset($cw[$c]) ? $cw[$c] : 0;
|
||||
if ($l > $wmax) {
|
||||
if ($sep == -1) {
|
||||
if ($i == $j) $i++;
|
||||
} else {
|
||||
$i = $sep + 1;
|
||||
}
|
||||
$sep = -1; $j = $i; $l = 0; $nl++;
|
||||
} else {
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
return $nl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render satu baris (kiri+kanan) dengan tinggi sama,
|
||||
* memakai MultiCell untuk kolom Nama Akun.
|
||||
*/
|
||||
private function _drawRow($activaRow, $pasivaRow, $startX, $rightX, $lineH)
|
||||
{
|
||||
$wNama = $this->colWidths[1];
|
||||
|
||||
$nlA = $activaRow ? $this->_nbLines($wNama, $activaRow['nama']) : 1;
|
||||
$nlB = $pasivaRow ? $this->_nbLines($wNama, $pasivaRow['nama']) : 1;
|
||||
$nl = max($nlA, $nlB, 1);
|
||||
$h = $lineH * $nl;
|
||||
|
||||
// page break manual agar baris tidak terpotong
|
||||
if ($this->GetY() + $h > $this->PageBreakTrigger) {
|
||||
$this->AddPage($this->CurOrientation);
|
||||
}
|
||||
|
||||
$y = $this->GetY();
|
||||
|
||||
// ---------- ACTIVA ----------
|
||||
$this->SetXY($startX, $y);
|
||||
if ($activaRow) {
|
||||
// Kode (auto vertical-center karena pakai Cell dengan tinggi $h)
|
||||
$this->Cell($this->colWidths[0], $h, $activaRow['kode'], 1, 0, 'C');
|
||||
|
||||
// Nama (MultiCell) — vertical center manual
|
||||
$xNama = $this->GetX();
|
||||
$this->Rect($xNama, $y, $wNama, $h);
|
||||
$nLines = $this->_nbLines($wNama, $activaRow['nama']);
|
||||
$offsetY = ($h - $lineH * $nLines) / 2;
|
||||
$this->SetXY($xNama, $y + $offsetY);
|
||||
$this->MultiCell($wNama, $lineH, $activaRow['nama'], 0, 'L');
|
||||
|
||||
// Saldo
|
||||
$this->SetXY($xNama + $wNama, $y);
|
||||
$this->Cell($this->colWidths[2], $h, number_format($activaRow['saldo'], 0, ',', '.'), 1, 0, 'R');
|
||||
} else {
|
||||
$this->Cell($this->colWidths[0], $h, '', 1, 0);
|
||||
$this->Cell($wNama, $h, '', 1, 0);
|
||||
$this->Cell($this->colWidths[2], $h, '', 1, 0);
|
||||
}
|
||||
|
||||
// ---------- PASIVA ----------
|
||||
$this->SetXY($rightX, $y);
|
||||
if ($pasivaRow) {
|
||||
$this->Cell($this->colWidths[0], $h, $pasivaRow['kode'], 1, 0, 'C');
|
||||
|
||||
$xNama = $this->GetX();
|
||||
$this->Rect($xNama, $y, $wNama, $h);
|
||||
$nLines = $this->_nbLines($wNama, $pasivaRow['nama']);
|
||||
$offsetY = ($h - $lineH * $nLines) / 2;
|
||||
$this->SetXY($xNama, $y + $offsetY);
|
||||
$this->MultiCell($wNama, $lineH, $pasivaRow['nama'], 0, 'L');
|
||||
|
||||
$this->SetXY($xNama + $wNama, $y);
|
||||
$this->Cell($this->colWidths[2], $h, number_format($pasivaRow['saldo'], 0, ',', '.'), 1, 0, 'R');
|
||||
} else {
|
||||
$this->Cell($this->colWidths[0], $h, '', 1, 0);
|
||||
$this->Cell($wNama, $h, '', 1, 0);
|
||||
$this->Cell($this->colWidths[2], $h, '', 1, 0);
|
||||
}
|
||||
|
||||
// pindah ke baris berikutnya
|
||||
$this->SetXY($startX, $y + $h);
|
||||
}
|
||||
|
||||
|
||||
public function NeracaTable($activa, $pasiva, $totalActiva, $totalPasiva)
|
||||
{
|
||||
$startX = $this->_startX();
|
||||
$tableW = array_sum($this->colWidths);
|
||||
$rightX = $startX + $tableW + $this->gap;
|
||||
$lineH = 5;
|
||||
|
||||
$this->SetFont('Arial', '', 8);
|
||||
|
||||
$maxRow = max(count($activa), count($pasiva));
|
||||
for ($i = 0; $i < $maxRow; $i++) {
|
||||
$this->_drawRow(
|
||||
isset($activa[$i]) ? $activa[$i] : null,
|
||||
isset($pasiva[$i]) ? $pasiva[$i] : null,
|
||||
$startX, $rightX, $lineH
|
||||
);
|
||||
}
|
||||
|
||||
// ---- BARIS TOTAL ----
|
||||
if ($this->GetY() + 8 > $this->PageBreakTrigger) {
|
||||
$this->AddPage('P', 'A4');
|
||||
}
|
||||
|
||||
$y = $this->GetY();
|
||||
$this->SetFont('Arial', 'B', 8);
|
||||
$this->SetFillColor(255, 204, 102);
|
||||
|
||||
$this->SetXY($startX, $y);
|
||||
$this->Cell($this->colWidths[0] + $this->colWidths[1], 7, 'TOTAL ACTIVA', 1, 0, 'C', true);
|
||||
$this->Cell($this->colWidths[2], 7, number_format($totalActiva, 0, ',', '.'), 1, 0, 'R', true);
|
||||
|
||||
$this->SetXY($rightX, $y);
|
||||
$this->Cell($this->colWidths[0] + $this->colWidths[1], 7, 'TOTAL PASIVA', 1, 0, 'C', true);
|
||||
$this->Cell($this->colWidths[2], 7, number_format($totalPasiva, 0, ',', '.'), 1, 1, 'R', true);
|
||||
}
|
||||
|
||||
public function NeracaRingkasan($laba, $selisih)
|
||||
{
|
||||
$startX = $this->_startX();
|
||||
$tableW = array_sum($this->colWidths) * 2 + $this->gap;
|
||||
$labelW = $tableW - 40;
|
||||
|
||||
$this->Ln(4);
|
||||
|
||||
$this->SetX($startX);
|
||||
$this->SetFont('Arial', 'B', 9);
|
||||
$this->Cell($labelW, 7, 'Laba Rugi Berjalan', 1, 0, 'L');
|
||||
$this->SetFont('Arial', '', 9);
|
||||
$this->Cell(40, 7, number_format($laba, 0, ',', '.'), 1, 1, 'R');
|
||||
|
||||
$this->SetX($startX);
|
||||
$this->SetFont('Arial', 'B', 9);
|
||||
if (abs($selisih) < 1) {
|
||||
$this->SetFillColor(198, 239, 206);
|
||||
$label = 'Selisih (Balance)';
|
||||
} else {
|
||||
$this->SetFillColor(255, 199, 206);
|
||||
$label = 'Selisih (Tidak Balance)';
|
||||
}
|
||||
$this->Cell($labelW, 7, $label, 1, 0, 'L', true);
|
||||
$this->Cell(40, 7, number_format($selisih, 0, ',', '.'), 1, 1, 'R', true);
|
||||
}
|
||||
|
||||
public function Pembuat($nama, $jabatan = '')
|
||||
{
|
||||
$startX = $this->_startX();
|
||||
$tableW = array_sum($this->colWidths) * 2 + $this->gap;
|
||||
$signWidth = 70;
|
||||
$signX = $startX + $tableW - $signWidth;
|
||||
|
||||
$this->Ln(15);
|
||||
$this->SetX($signX);
|
||||
$this->SetFont('Arial', '', 10);
|
||||
$this->Cell($signWidth, 6, 'Mengetahui,', 0, 1, 'R');
|
||||
|
||||
$this->Ln(18);
|
||||
$this->SetX($signX);
|
||||
$this->SetFont('Arial', 'B', 10);
|
||||
$this->Cell($signWidth, 6, $nama, 0, 1, 'R');
|
||||
|
||||
if (!empty($jabatan)) {
|
||||
$this->SetX($signX);
|
||||
$this->SetFont('Arial', '', 9);
|
||||
$this->Cell($signWidth, 5, '(' . $jabatan . ')', 0, 1, 'R');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,303 @@
|
||||
<?php
|
||||
|
||||
require_once(APPPATH . 'third_party/fpdf/fpdf.php');
|
||||
|
||||
class PDF extends FPDF
|
||||
{
|
||||
// ----------------------------------------------------------------
|
||||
// PROPERTI HEADER
|
||||
// ----------------------------------------------------------------
|
||||
private $nama;
|
||||
private $alamat;
|
||||
private $logo;
|
||||
private $periodeStr = '';
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// KONFIGURASI TABEL
|
||||
// ----------------------------------------------------------------
|
||||
// A4 Portrait efektif = 190mm, margin 10+10
|
||||
// Kolom: Kode 20 | Nama Akun 90 | Debit 40 | Kredit 40 → TOTAL 190
|
||||
private $colWidths = [20, 90, 40, 40];
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// SETTER
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
public function setHeaderData($nama, $alamat, $logo = '')
|
||||
{
|
||||
$this->nama = $nama;
|
||||
$this->alamat = $alamat;
|
||||
$this->logo = $logo;
|
||||
}
|
||||
|
||||
public function setInfoLaporan($periodeStr)
|
||||
{
|
||||
$this->periodeStr = $periodeStr;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// HEADER HALAMAN
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
function Header()
|
||||
{
|
||||
// Logo (opsional)
|
||||
if (!empty($this->logo) && file_exists($this->logo)) {
|
||||
$this->Image($this->logo, 10, 6, 18);
|
||||
$this->SetXY(31, 10);
|
||||
} else {
|
||||
$this->SetXY(10, 10);
|
||||
}
|
||||
|
||||
// Nama perusahaan
|
||||
$this->SetFont('Arial', 'B', 12);
|
||||
$this->Cell(0, 6, $this->nama, 0, 1, 'L');
|
||||
|
||||
// Alamat
|
||||
$this->SetFont('Arial', '', 9);
|
||||
$x = !empty($this->logo) && file_exists($this->logo) ? 31 : 10;
|
||||
$this->SetX($x);
|
||||
$this->Cell(0, 5, $this->alamat, 0, 1, 'L');
|
||||
|
||||
// Garis pemisah (A4 Portrait: x=10 s/d x=200)
|
||||
$this->Ln(2);
|
||||
$this->SetLineWidth(0.6);
|
||||
$this->Line(10, $this->GetY(), 200, $this->GetY());
|
||||
$this->SetLineWidth(0.2);
|
||||
$this->Line(10, $this->GetY() + 1, 200, $this->GetY() + 1);
|
||||
$this->Ln(5);
|
||||
|
||||
// Judul
|
||||
$this->SetFont('Arial', 'B', 13);
|
||||
$this->SetTextColor(245, 140, 0);
|
||||
$this->Cell(0, 7, 'LAPORAN NERACA SALDO', 0, 1, 'C');
|
||||
$this->SetTextColor(0, 0, 0);
|
||||
|
||||
// Periode
|
||||
$this->SetFont('Arial', '', 10);
|
||||
$this->Cell(0, 5, $this->periodeStr, 0, 1, 'C');
|
||||
|
||||
// Tanggal cetak
|
||||
$this->SetFont('Arial', '', 9);
|
||||
$this->Cell(0, 5, 'Di Cetak Pada : ' . date('d-m-Y') . ' - ' . date('H:i:s'), 0, 1, 'C');
|
||||
|
||||
$this->Ln(4);
|
||||
|
||||
// Header kolom tabel
|
||||
$this->_drawTableHeader();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// FOOTER HALAMAN
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
function Footer()
|
||||
{
|
||||
$this->SetY(-10);
|
||||
$this->SetFont('Arial', 'I', 8);
|
||||
$this->Cell(0, 5, 'Halaman ' . $this->PageNo(), 0, 0, 'C');
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// HELPER: posisi X awal — TABEL RATA TENGAH KERTAS
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
private function _startX()
|
||||
{
|
||||
$tableW = array_sum($this->colWidths);
|
||||
return ($this->GetPageWidth() - $tableW) / 2;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// HELPER: Gambar header kolom tabel
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
private function _drawTableHeader()
|
||||
{
|
||||
$startX = $this->_startX();
|
||||
|
||||
$this->SetX($startX);
|
||||
$this->SetFillColor(245, 140, 0);
|
||||
$this->SetTextColor(255, 255, 255);
|
||||
$this->SetFont('Arial', 'B', 9);
|
||||
|
||||
$this->Cell($this->colWidths[0], 8, 'Kode', 1, 0, 'C', true);
|
||||
$this->Cell($this->colWidths[1], 8, 'Nama Akun', 1, 0, 'C', true);
|
||||
$this->Cell($this->colWidths[2], 8, 'Debit', 1, 0, 'C', true);
|
||||
$this->Cell($this->colWidths[3], 8, 'Kredit', 1, 1, 'C', true);
|
||||
|
||||
$this->SetTextColor(0, 0, 0);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// TABEL NERACA SALDO (mendukung multiline Nama Akun)
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
public function NeracaSaldoTable($rows, $totalDebit, $totalKredit)
|
||||
{
|
||||
$startX = $this->_startX();
|
||||
$lineH = 6;
|
||||
|
||||
$this->SetFont('Arial', '', 9);
|
||||
|
||||
if (empty($rows)) {
|
||||
$this->SetX($startX);
|
||||
$this->SetFont('Arial', 'B', 10);
|
||||
$this->Cell(array_sum($this->colWidths), 8, 'Tidak ada data', 1, 1, 'C');
|
||||
} else {
|
||||
foreach ($rows as $row) {
|
||||
|
||||
$nbLines = $this->NbLines($this->colWidths[1], $row['nama']);
|
||||
$rowH = max(1, $nbLines) * $lineH;
|
||||
|
||||
if ($this->GetY() + $rowH > 270) {
|
||||
$this->AddPage('P', 'A4');
|
||||
}
|
||||
|
||||
$y = $this->GetY();
|
||||
|
||||
$this->SetFont('Arial', '', 9);
|
||||
$this->SetXY($startX, $y);
|
||||
$this->Cell($this->colWidths[0], $rowH, $row['kode'], 1, 0, 'C');
|
||||
|
||||
$xNama = $this->GetX();
|
||||
$this->MultiCell($this->colWidths[1], $lineH, $row['nama'], 1, 'L');
|
||||
|
||||
$this->SetXY($xNama + $this->colWidths[1], $y);
|
||||
$this->Cell($this->colWidths[2], $rowH, $row['saldo_debit'] > 0 ? number_format($row['saldo_debit'], 0, ',', '.') : '-', 1, 0, 'R');
|
||||
$this->Cell($this->colWidths[3], $rowH, $row['saldo_kredit'] > 0 ? number_format($row['saldo_kredit'], 0, ',', '.') : '-', 1, 0, 'R');
|
||||
|
||||
$this->SetXY($startX, $y + $rowH);
|
||||
}
|
||||
}
|
||||
|
||||
// ---- BARIS TOTAL ----
|
||||
if ($this->GetY() + 8 > 270) {
|
||||
$this->AddPage('P', 'A4');
|
||||
}
|
||||
|
||||
$this->SetX($startX);
|
||||
$this->SetFillColor(255, 204, 102);
|
||||
$this->SetFont('Arial', 'B', 9);
|
||||
|
||||
$this->Cell($this->colWidths[0] + $this->colWidths[1], 8, 'TOTAL', 1, 0, 'C', true);
|
||||
$this->Cell($this->colWidths[2], 8, number_format($totalDebit, 0, ',', '.'), 1, 0, 'R', true);
|
||||
$this->Cell($this->colWidths[3], 8, number_format($totalKredit, 0, ',', '.'), 1, 1, 'R', true);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// RINGKASAN: STATUS BALANCE
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
public function NeracaSaldoRingkasan($totalDebit, $totalKredit)
|
||||
{
|
||||
if ($this->GetY() + 9 > 270) {
|
||||
$this->AddPage('P', 'A4');
|
||||
}
|
||||
|
||||
$startX = $this->_startX();
|
||||
$tableW = array_sum($this->colWidths);
|
||||
$labelW = $tableW - $this->colWidths[3];
|
||||
$selisih = $totalDebit - $totalKredit;
|
||||
|
||||
$this->Ln(2);
|
||||
$this->SetX($startX);
|
||||
$this->SetFont('Arial', 'B', 10);
|
||||
|
||||
if (abs($selisih) < 1) {
|
||||
$this->SetFillColor(198, 239, 206); // hijau, balance
|
||||
$label = 'SELISIH (BALANCE)';
|
||||
} else {
|
||||
$this->SetFillColor(255, 199, 206); // merah, tidak balance
|
||||
$label = 'SELISIH (TIDAK BALANCE)';
|
||||
}
|
||||
|
||||
$this->Cell($labelW, 8, $label, 1, 0, 'L', true);
|
||||
$this->Cell($this->colWidths[3], 8, number_format($selisih, 0, ',', '.'), 1, 1, 'R', true);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// TANDA TANGAN
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
public function Pembuat($nama, $jabatan = '')
|
||||
{
|
||||
$startX = $this->_startX();
|
||||
$tableW = array_sum($this->colWidths);
|
||||
$signWidth = 70;
|
||||
$signX = $startX + $tableW - $signWidth; // sejajar sisi kanan tabel
|
||||
|
||||
$this->Ln(3);
|
||||
// $this->SetX($signX);
|
||||
$this->SetFont('Arial', 'I', 9);
|
||||
$this->Cell($signWidth, 6, '*Mengetahui, (Finance Departement)', 0, 1, 'L');
|
||||
// $this->Cell($signWidth, 6, $nama, 0, 1, 'L');
|
||||
// if (!empty($jabatan)) {
|
||||
// $this->Cell($signWidth, 5, '(' . $jabatan . ')', 0, 1, 'L');
|
||||
// }
|
||||
// $this->Ln(0);
|
||||
// $this->SetX($signX);
|
||||
// $this->SetFont('Arial', 'B', 10);
|
||||
// $this->Cell($signWidth, 6, $nama, 0, 1, 'R');
|
||||
|
||||
// if (!empty($jabatan)) {
|
||||
// $this->SetX($signX);
|
||||
// $this->SetFont('Arial', '', 9);
|
||||
// $this->Cell($signWidth, 5, '(' . $jabatan . ')', 0, 1, 'R');
|
||||
// }
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// HELPER: Hitung jumlah baris yang dibutuhkan MultiCell
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
private function NbLines($w, $txt)
|
||||
{
|
||||
$cw = &$this->CurrentFont['cw'];
|
||||
if ($w == 0) {
|
||||
$w = $this->w - $this->rMargin - $this->x;
|
||||
}
|
||||
$wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize;
|
||||
$s = str_replace("\r", '', $txt);
|
||||
$nb = strlen($s);
|
||||
if ($nb > 0 && $s[$nb - 1] == "\n") {
|
||||
$nb--;
|
||||
}
|
||||
$sep = -1;
|
||||
$i = 0;
|
||||
$j = 0;
|
||||
$l = 0;
|
||||
$nl = 1;
|
||||
while ($i < $nb) {
|
||||
$c = $s[$i];
|
||||
if ($c == "\n") {
|
||||
$i++;
|
||||
$sep = -1;
|
||||
$j = $i;
|
||||
$l = 0;
|
||||
$nl++;
|
||||
continue;
|
||||
}
|
||||
if ($c == ' ') {
|
||||
$sep = $i;
|
||||
}
|
||||
$l += isset($cw[ord($c)]) ? $cw[ord($c)] : 600;
|
||||
if ($l > $wmax) {
|
||||
if ($sep == -1) {
|
||||
if ($i == $j) {
|
||||
$i++;
|
||||
}
|
||||
} else {
|
||||
$i = $sep + 1;
|
||||
}
|
||||
$sep = -1;
|
||||
$j = $i;
|
||||
$l = 0;
|
||||
$nl++;
|
||||
} else {
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
return $nl;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user