Files
accounting_dev/application/libraries/PDF_BarangBawaan.php
T

206 lines
6.3 KiB
PHP

<?php
require_once(APPPATH . 'third_party/fpdf/fpdf.php');
class PDF_BarangBawaan extends FPDF
{
private $noFaktur;
private $tanggal;
private $teknisi;
private $colWidths = [10, 28, 48, 30, 12, 62];
public function __construct($orientation = 'L', $unit = 'mm', $size = 'A5')
{
parent::__construct($orientation, $unit, $size);
$this->SetDisplayMode('fullpage');
}
function SetMargins($left, $top, $right = null)
{
parent::SetMargins(10, $top, 10);
}
public function setFormInfo($noFaktur, $tanggal, $teknisi)
{
$this->noFaktur = $noFaktur;
$this->tanggal = $tanggal;
$this->teknisi = $teknisi;
}
function Header()
{
$this->SetFont('Arial', 'B', 11);
$this->SetTextColor(245, 140, 0);
$this->Cell(0, 6, 'FORM BARANG BAWAAN TEKNISI', 0, 1, 'L');
$this->SetTextColor(0, 0, 0);
$this->Ln(2);
$this->SetFont('Arial', '', 8);
$this->Cell(0, 5, 'Tanggal : ' . $this->tanggal . ' Teknisi : ' . $this->teknisi . ' No. Faktur : ' . $this->noFaktur, 0, 1, 'C');
$this->Ln(2);
$this->_drawTableHeader();
}
function Footer()
{
$this->SetY(-8);
$this->SetFont('Arial', 'I', 7);
$this->Cell(0, 4, 'Hal ' . $this->PageNo(), 0, 0, 'C');
}
private function _drawTableHeader()
{
$startX = $this->lMargin;
$this->SetX($startX);
$this->SetFillColor(245, 140, 0);
$this->SetTextColor(255, 255, 255);
$this->SetFont('Arial', 'B', 7);
$headers = ['No', 'Barcode', 'Nama Barang', 'Serial Number', 'Jumlah', 'Keterangan'];
foreach ($headers as $i => $h) {
$this->Cell($this->colWidths[$i], 7, $h, 1, 0, 'C', true);
}
$this->Ln();
$this->SetTextColor(0, 0, 0);
}
public function BarangBawaanTable($items)
{
$this->SetFont('Arial', '', 7);
$lineH = 5.5;
$minRowH = 8;
$no = 1;
$colsMultiCell = [false, false, true, true, false, true];
$cellAligns = ['C', 'C', 'L', 'L', 'C', 'L'];
foreach ($items as $item) {
$keterangan = isset($item->keterangan) ? $item->keterangan : '';
$namaBarang = $item->nama_barang ?? '-';
$serial = $item->serial_number ?? '-';
$barcode = $item->barcode ?? '-';
$jumlah = isset($item->qty_sisa) ? (int)$item->qty_sisa : 1;
$cellValues = [
(string)$no,
$barcode,
$namaBarang,
$serial,
(string)$jumlah,
$keterangan
];
$maxLines = 1;
foreach ($cellValues as $i => $val) {
if ($colsMultiCell[$i]) {
$lines = $this->NbLines($this->colWidths[$i], $val);
if ($lines > $maxLines) {
$maxLines = $lines;
}
}
}
$rowH = max($minRowH, $maxLines * $lineH);
if ($this->GetY() + $rowH > $this->PageBreakTrigger) {
$this->AddPage();
}
$startX = $this->lMargin;
$startY = $this->GetY();
$currentX = $startX;
foreach ($this->colWidths as $i => $w) {
$this->Rect($currentX, $startY, $w, $rowH);
$currentX += $w;
}
$currentX = $startX;
foreach ($cellValues as $i => $val) {
$this->SetXY($currentX, $startY);
if ($colsMultiCell[$i]) {
$contentH = $maxLines * $lineH;
$offsetY = ($rowH - $contentH) / 2;
$this->SetXY($currentX, $startY + $offsetY);
$this->MultiCell($this->colWidths[$i], $lineH, $val, 0, $cellAligns[$i]);
} else {
$this->Cell($this->colWidths[$i], $rowH, $val, 0, 0, $cellAligns[$i]);
}
$currentX += $this->colWidths[$i];
}
$this->SetXY($startX, $startY + $rowH);
$no++;
}
}
public function SignatureArea()
{
$this->Ln(6);
$sigW = 56;
$gapW = 11;
$blockW = 3 * $sigW + 2 * $gapW;
$startX = $this->lMargin + ($this->w - $this->lMargin - $this->rMargin - $blockW) / 2;
$signatures = [
['title' => 'Admin Gudang', 'name' => 'Gono Soewisto'],
['title' => 'Leader Teknisi', 'name' => 'Chandra Nursani'],
['title' => 'Mengetahui', 'name' => 'Tito Ngudiana'],
];
$sigY = $this->GetY();
foreach ($signatures as $i => $sig) {
$x = $startX + $i * ($sigW + $gapW);
$this->SetXY($x, $sigY);
$this->SetFont('Arial', '', 8);
$this->Cell($sigW, 5, $sig['title'], 0, 1, 'C');
$this->SetX($x);
$this->Ln(10);
$this->SetX($x);
$this->SetFont('Arial', 'U', 8);
$this->Cell($sigW, 5, ' ', 0, 1, 'C');
$this->SetX($x);
$this->SetFont('Arial', 'I', 7);
$this->Cell($sigW, 4, $sig['name'], 0, 1, 'C');
}
$this->SetY($sigY + 5 + 10 + 5 + 4);
}
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;
}
}