Initial commit

This commit is contained in:
root
2026-05-26 08:07:45 +00:00
commit a234e55e64
4263 changed files with 855927 additions and 0 deletions
+255
View File
@@ -0,0 +1,255 @@
<?php
// require_once(APPPATH.'libraries/fpdf/fpdf.php');
require_once(APPPATH.'third_party/fpdf/fpdf.php');
class PDF extends FPDF
{
private $maxWidth = 190;
private $nama;
private $alamat;
private $telepon;
private $logo;
public function setHeaderData($nama, $alamat, $telepon, $logo='')
{
$this->nama = $nama;
$this->alamat = $alamat;
$this->telepon = $telepon;
$this->logo = $logo;
}
function Header()
{
// Logo
$this->Image($this->logo, 10, 8, 22, 22); // Path ke logo Anda, x, y, width
$this->SetXY(35, 11);
$this->SetFont('Arial', 'B', 14);
$this->Cell(0, 6, $this->nama, 0, 1, 'L');
$this->SetFont('Arial', 'I', 10);
$this->SetXY(35, 17);
$this->Cell(0, 6, $this->alamat, 0, 1, 'L');
$this->SetXY(35, 23);
$this->Cell(0, 6, 'Phone: '.$this->telepon, 0, 1, 'L');
$this->Ln(14);
// Garis Horizontal
$this->SetLineWidth(0.8); // Ketebalan garis
$this->Line(10, 33, 200, 33); // x1, y1, x2, y2 (x1, y1 = start; x2, y2 = end)
$this->SetLineWidth(0.4);
$this->Line(10, 34, 200, 34);
$this->SetTextColor(255, 140, 0);
$this->SetFont('Arial', 'B', 20);
$this->Cell(0, -56, 'INVOICE', 0, 1, 'R');
$this->Ln(50);
}
function Footer()
{
$this->SetY(-15);
$this->SetFont('Arial', 'I', 8);
$this->Cell(0, 10, 'Page ' . $this->PageNo(), 0, 0, 'C');
}
function CustomerDetails($customerName, $customerAddress, $invoiceNumber, $invoiceDate, $customerNumber, $invoiceLimit)
{
$this->SetFont('Arial', 'B', 11);
$this->Cell(0, 6, 'Bill To:', 0, 1);
$this->SetFont('Arial', '', 11);
$this->Cell(0, 6, $customerName, 0, 1);
$this->MultiCell(0, 7, $customerAddress);
$this->Cell(0, 6, $customerNumber, 0, 1);
$this->Ln(10);
$this->SetFont('Arial', '', 11);
$this->SetXY(140, 37);
$this->Cell(0, 6, "No Invoice : $invoiceNumber", 0, 1);
$this->SetXY(140, 44);
$this->Cell(0, 6, "Invoice Date : $invoiceDate", 0, 1);
$this->SetXY(140, 51);
$this->Cell(0, 6, "Limit Invoice : $invoiceLimit", 0, 1);
$this->Ln(10);
}
function InvoiceTable($header, $data)
{
// 🔥 7 kolom sekarang
$columnWidths = array(8, 22, 30, 70, 15, 20, 25);
$totalWidth = array_sum($columnWidths);
// scaling biar tetap muat
$scalingFactor = $this->maxWidth / $totalWidth;
// header style
$this->SetFillColor(255, 140, 0);
$this->SetFont('Arial', '', 10);
// ================= HEADER =================
for ($i = 0; $i < count($header); $i++) {
$this->Cell($columnWidths[$i] * $scalingFactor, 8, $header[$i], 1, 0, 'C', true);
}
$this->Ln();
// ================= DATA =================
$this->SetFont('Arial', '', 10);
foreach ($data as $row) {
// hitung multiline
$nbDesc = $this->NbLines($columnWidths[2] * $scalingFactor, $row[2]);
$nbKet = $this->NbLines($columnWidths[3] * $scalingFactor, $row[3]);
$maxHeight = 8 * max($nbDesc, $nbKet);
// pagination
if ($this->GetY() + $maxHeight > $this->PageBreakTrigger) {
$this->AddPage();
$this->SetFillColor(255, 140, 0);
$this->SetFont('Arial', '', 10);
for ($i = 0; $i < count($header); $i++) {
$this->Cell($columnWidths[$i] * $scalingFactor, 8, $header[$i], 1, 0, 'C', true);
}
$this->Ln();
$this->SetFont('Arial', '', 10);
}
$x = $this->GetX();
$y = $this->GetY();
// 1. No
$this->Cell($columnWidths[0] * $scalingFactor, $maxHeight, $row[0], 1, 0, 'C');
// 2. Tanggal
$this->Cell($columnWidths[1] * $scalingFactor, $maxHeight, $row[1], 1, 0, 'C');
// 3. Nama Item (multiline)
$this->SetXY($x + ($columnWidths[0] + $columnWidths[1]) * $scalingFactor, $y);
$this->MultiCell(
$columnWidths[2] * $scalingFactor,
$maxHeight / max(1, $nbDesc),
$row[2],
1,
'L'
);
// 4. Keterangan (multiline)
$this->SetXY($x + ($columnWidths[0] + $columnWidths[1] + $columnWidths[2]) * $scalingFactor, $y);
$this->MultiCell(
$columnWidths[3] * $scalingFactor,
$maxHeight / max(1, $nbKet),
$row[3],
1,
'L'
);
// 5. Qty
$this->SetXY($x + ($columnWidths[0] + $columnWidths[1] + $columnWidths[2] + $columnWidths[3]) * $scalingFactor, $y);
$this->Cell($columnWidths[4] * $scalingFactor, $maxHeight, $row[4], 1, 0, 'C');
// 6. Harga
$this->Cell($columnWidths[5] * $scalingFactor, $maxHeight, $row[5], 1, 0, 'R');
// 7. Subtotal
$this->Cell($columnWidths[6] * $scalingFactor, $maxHeight, $row[6], 1, 0, 'R');
$this->Ln($maxHeight);
}
}
// Fungsi tambahan untuk menghitung jumlah baris Multicell
function NbLines($w, $txt)
{
// Hitung jumlah baris dalam MultiCell
$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 += $cw[$c];
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;
}
function Total($subtotal,$lainnya,$totalAmount,$terbilang,$keteranganlain)
{
$this->Ln(1);
$this->SetFont('Arial', '', 11);
$this->Cell($this->maxWidth - 25, 9, 'Sub Total', 1, 0, 'R');
$this->Cell(25, 9, $subtotal, 1, 1, 'R');
$this->Cell($this->maxWidth - 25, 9, $keteranganlain, 1, 0, 'R');
$this->Cell(25, 9, $lainnya, 1, 1, 'R');
$this->SetFont('Arial', 'B', 11);
$this->Cell($this->maxWidth - 25, 9, 'Total', 1, 0, 'R');
$this->Cell(25, 9, $totalAmount, 1, 1, 'R');
$this->Ln(1);
$this->SetFont('Arial', 'I', 11);
$this->Cell(0, 9, 'Terbilang : ', 0, 1);
$this->SetFont('Arial', 'I', 11);
$this->MultiCell(190, 9, $terbilang, 1, 'L');
}
function Keterangan($Keterangan)
{
$this->Ln(10);
$this->SetFont('Arial', '', 11);
$this->SetFillColor(255, 140, 0);
$this->MultiCell(100, 6, $Keterangan, 0, 'L', true);
}
function Pembuat($Pembuat)
{
$this->Ln(-25);
$this->SetFont('Arial', '', 11);
$this->Cell(300, 6, 'Mengetahui,', 0, 1, 'C');
$this->Ln(18);
$this->SetFont('Arial', 'B', 11);
$this->Cell(300, 6, '( '.$Pembuat.' )', 0, 1, 'C');
$this->SetFont('Arial', 'I', 11);
$this->Cell(300, 6, 'financial department', 0, 1, 'C');
}
}
?>