fix report fpdf
This commit is contained in:
@@ -40,6 +40,110 @@ class PaymentVoucherFpdf extends FPDF
|
||||
$this->Cell($colSide, 4, 'Tgl Print : ' . $this->printDate, 0, 0, 'L');
|
||||
$this->Cell($colCenter + $colSide, 4, '', 0, 1, 'L');
|
||||
}
|
||||
|
||||
// Properties untuk tabel multiline
|
||||
public $widths;
|
||||
public $aligns;
|
||||
|
||||
public function SetWidths($w)
|
||||
{
|
||||
$this->widths = $w;
|
||||
}
|
||||
|
||||
public function SetAligns($a)
|
||||
{
|
||||
$this->aligns = $a;
|
||||
}
|
||||
|
||||
public function Row($data, $fill = false, $h = 6)
|
||||
{
|
||||
// Hitung tinggi maksimum baris berdasarkan multiline
|
||||
$nb = 0;
|
||||
for ($i = 0; $i < count($data); $i++) {
|
||||
$nb = max($nb, $this->NbLines($this->widths[$i], $data[$i]));
|
||||
}
|
||||
$rowH = $h * $nb;
|
||||
|
||||
// Cek apakah perlu ganti halaman secara otomatis
|
||||
$this->CheckPageBreak($rowH);
|
||||
|
||||
// Gambar cell pada baris
|
||||
for ($i = 0; $i < count($data); $i++) {
|
||||
$w = $this->widths[$i];
|
||||
$a = isset($this->aligns[$i]) ? $this->aligns[$i] : 'L';
|
||||
|
||||
$x = $this->GetX();
|
||||
$y = $this->GetY();
|
||||
|
||||
// Gambar border dan background
|
||||
$this->Rect($x, $y, $w, $rowH, $fill ? 'DF' : 'D');
|
||||
// Tulis teks menggunakan MultiCell
|
||||
$this->MultiCell($w, $h, $data[$i], 0, $a);
|
||||
// Geser posisi X ke kanan untuk cell berikutnya
|
||||
$this->SetXY($x + $w, $y);
|
||||
}
|
||||
// Pindah baris
|
||||
$this->Ln($rowH);
|
||||
}
|
||||
|
||||
public function CheckPageBreak($h)
|
||||
{
|
||||
// Jika tinggi baris melewati batas, buat halaman baru
|
||||
if ($this->GetY() + $h > $this->PageBreakTrigger) {
|
||||
$this->AddPage($this->CurOrientation);
|
||||
}
|
||||
}
|
||||
|
||||
public function NbLines($w, $txt)
|
||||
{
|
||||
// Menghitung jumlah baris yang akan dihasilkan oleh 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;
|
||||
}
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
@@ -123,12 +227,15 @@ class Rpt_payment_voucher extends MY_Controller
|
||||
pv.*,
|
||||
cs.coaAccountNo,
|
||||
cs.coaDescription,
|
||||
ct.coaAccountNo AS coaTempAccountNo,
|
||||
ct.coaDescription AS coaTempDescription,
|
||||
b.M_BranchName,
|
||||
IFNULL(uCr.M_UserUsername, '') AS CreatedByName,
|
||||
IFNULL(uPd.M_UserUsername, '') AS PaidByName,
|
||||
IFNULL(uRc.M_UserUsername, '') AS PaidReceiveByName
|
||||
FROM payment_voucher pv
|
||||
LEFT JOIN coa cs ON cs.coaID = pv.PaymentVoucherCoaSourceID
|
||||
LEFT JOIN coa ct ON ct.coaID = pv.PaymentVoucherCoaTemporaryID
|
||||
LEFT JOIN m_branch b ON b.M_BranchCode = pv.PaymentVoucherM_BranchCode
|
||||
LEFT JOIN m_user uCr ON uCr.M_UserID = pv.PaymentVoucherUserID
|
||||
LEFT JOIN m_user uPd ON uPd.M_UserID = pv.PaymentVoucherPaidUserID
|
||||
@@ -145,22 +252,27 @@ class Rpt_payment_voucher extends MY_Controller
|
||||
return $qry->row_array();
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// DATABASE: Ambil data detail
|
||||
// =========================================================================
|
||||
private function _get_detail($id)
|
||||
{
|
||||
$sql = "
|
||||
SELECT
|
||||
pvd.*,
|
||||
prd.PurchaseRequestDirectNumber,
|
||||
prd.PurchaseRequestDirectDescription,
|
||||
prd.PurchaseRequestDirectNote
|
||||
prdd.PurchaseRequestDirectDescription AS ItemDescription,
|
||||
prdd.PurchaseRequestDirectDetailAccount AS ExpenseAccount,
|
||||
prdd.PurchaseRequestDirectDetailTotalRealitationPrice,
|
||||
prdd.PurchaseRequestDirectDetailTotalEstimationPrice,
|
||||
pdc.PurchaseDirectCategoryName,
|
||||
c.coaDescription AS ExpenseAccountName
|
||||
FROM payment_voucher_detail pvd
|
||||
LEFT JOIN purchase_request_direct prd ON prd.PurchaseRequestDirectID = pvd.PaymentVoucherDetailPurchaseRequestDirectID
|
||||
JOIN purchase_request_direct prd ON prd.PurchaseRequestDirectID = pvd.PaymentVoucherDetailPurchaseRequestDirectID
|
||||
JOIN purchase_request_direct_detail prdd ON prdd.PurchaseRequestDirectDetailPurchaseRequestDirectID = prd.PurchaseRequestDirectID
|
||||
AND prdd.PurchaseRequestDirectDetailIsActive = 'Y'
|
||||
LEFT JOIN purchase_direct_category pdc ON pdc.PurchaseDirectCategoryID = prdd.PurchaseRequestDirectDetailPurchaseRequestDirectCategoryID
|
||||
LEFT JOIN coa c ON c.coaAccountNo = prdd.PurchaseRequestDirectDetailAccount AND c.coaIsActive = 'Y'
|
||||
WHERE pvd.PaymentVoucherDetailIsActive = 'Y'
|
||||
AND pvd.PaymentVoucherDetailPaymentVoucherID = ?
|
||||
ORDER BY pvd.PaymentVoucherDetailID ASC
|
||||
ORDER BY pvd.PaymentVoucherDetailID ASC, prdd.PurchaseRequestDirectDetailID ASC
|
||||
";
|
||||
$qry = $this->db->query($sql, array($id));
|
||||
return $qry ? $qry->result_array() : array();
|
||||
@@ -196,24 +308,42 @@ class Rpt_payment_voucher extends MY_Controller
|
||||
$coaSource = $header['coaAccountNo'] . ' - ' . $header['coaDescription'];
|
||||
}
|
||||
|
||||
$coaTemp = '';
|
||||
if (!empty($header['coaTempAccountNo'])) {
|
||||
$coaTemp = $header['coaTempAccountNo'] . ' - ' . $header['coaTempDescription'];
|
||||
}
|
||||
|
||||
$leftItems = array(
|
||||
array('Nomor', $header['PaymentVoucherNumber'], true),
|
||||
array('Tanggal', $this->_fmt_datetime($header['PaymentVoucherDate']), false),
|
||||
array('Tanggal', $this->_fmt_date($header['PaymentVoucherDate']), false),
|
||||
array('Sumber Dana', $coaSource, false),
|
||||
array('Status', $header['PaymentVoucherStatus'] ?: '-', false),
|
||||
);
|
||||
|
||||
if ($coaTemp !== '') {
|
||||
$leftItems[] = array('Akun Transit', $coaTemp, false);
|
||||
}
|
||||
|
||||
foreach ($leftItems as $item) {
|
||||
$pdf->SetX(15);
|
||||
$pdf->SetFont('Arial_Narrow', '', 9);
|
||||
$pdf->Cell($lblW, 5, $item[0], 0, 0, 'L');
|
||||
$pdf->Cell(4, 5, ':', 0, 0, 'C');
|
||||
if ($item[2]) {
|
||||
$pdf->SetFont('Arial_Narrow', 'B', 9);
|
||||
} else {
|
||||
$pdf->SetFont('Arial_Narrow', '', 9);
|
||||
}
|
||||
$pdf->Cell($valW, 5, $item[1], 0, 1, 'L');
|
||||
$pdf->Cell($lblW, 5, $item[0], 0, 0, 'L');
|
||||
$pdf->Cell(4, 5, ':', 0, 0, 'C');
|
||||
|
||||
if ($item[2]) {
|
||||
$pdf->SetFont('Arial_Narrow', 'B', 9);
|
||||
} else {
|
||||
$pdf->SetFont('Arial_Narrow', '', 9);
|
||||
}
|
||||
|
||||
if ($item[0] === 'Sumber Dana' || $item[0] === 'Akun Transit') {
|
||||
$pdf->MultiCell($valW, 5, $item[1], 0, 'L');
|
||||
} else {
|
||||
$pdf->Cell($valW, 5, $item[1], 0, 1, 'L');
|
||||
}
|
||||
}
|
||||
|
||||
// Keterangan / Paid Note langsung di bawah Status (tanpa spasi vertikal)
|
||||
@@ -232,10 +362,8 @@ class Rpt_payment_voucher extends MY_Controller
|
||||
|
||||
$rightItems = array(
|
||||
array('Cabang', $header['M_BranchName'] ?: '-'),
|
||||
array('Tgl Pembayaran', $this->_fmt_datetime($header['PaymentVoucherPaidDate'])),
|
||||
array('Tgl Pembayaran', $this->_fmt_date($header['PaymentVoucherPaidDate'])),
|
||||
array('Dibuat Oleh', $header['CreatedByName'] ?: '-'),
|
||||
array('Dibayar Oleh', $header['PaidByName'] ?: '-'),
|
||||
array('Diterima Oleh', $header['PaidReceiveByName'] ?: '-'),
|
||||
);
|
||||
|
||||
foreach ($rightItems as $item) {
|
||||
@@ -263,13 +391,13 @@ class Rpt_payment_voucher extends MY_Controller
|
||||
|
||||
// ── Definisi kolom: [label, lebar, align] ─────────────────────────────
|
||||
// Total lebar = 180mm (A4 portrait: 210 - margin 15 kiri - 15 kanan)
|
||||
// 8 + 42 + 55 + 45 + 30 = 180
|
||||
// 8 + 45 + 30 + 72 + 25 = 180
|
||||
$cols = array(
|
||||
array('No', 8, 'C'),
|
||||
array('No. Request Direct', 42, 'L'),
|
||||
array('Deskripsi', 55, 'L'),
|
||||
array('Catatan PR', 45, 'L'),
|
||||
array('Nominal Bayar', 30, 'R'),
|
||||
array('No. Request Direct', 45, 'L'),
|
||||
array('Kategori', 30, 'L'),
|
||||
array('Deskripsi', 72, 'L'),
|
||||
array('Nominal Bayar', 25, 'R'),
|
||||
);
|
||||
|
||||
// Header kolom
|
||||
@@ -282,6 +410,10 @@ class Rpt_payment_voucher extends MY_Controller
|
||||
}
|
||||
$pdf->Ln();
|
||||
|
||||
// Set lebar dan alignment kolom untuk metode Row()
|
||||
$pdf->SetWidths(array_column($cols, 1));
|
||||
$pdf->SetAligns(array_column($cols, 2));
|
||||
|
||||
// Baris data
|
||||
$pdf->SetLineWidth(0.2); // border lebih tipis di data
|
||||
$pdf->SetFont('Arial_Narrow', '', 8);
|
||||
@@ -290,14 +422,22 @@ class Rpt_payment_voucher extends MY_Controller
|
||||
$totalPay = 0;
|
||||
|
||||
foreach ($details as $d) {
|
||||
$pdf->Cell($cols[0][1], 6, $no, 1, 0, 'C');
|
||||
$pdf->Cell($cols[1][1], 6, $d['PurchaseRequestDirectNumber'] ?: '-', 1, 0, 'L');
|
||||
$pdf->Cell($cols[2][1], 6, $d['PurchaseRequestDirectDescription'] ?: '-', 1, 0, 'L');
|
||||
$pdf->Cell($cols[3][1], 6, $d['PurchaseRequestDirectNote'] ?: '-', 1, 0, 'L');
|
||||
$pdf->Cell($cols[4][1], 6, $this->_fmt_rp($d['PaymentVoucherDetailTotal']), 1, 0, 'R');
|
||||
$pdf->Ln();
|
||||
$amount = floatval($d['PurchaseRequestDirectDetailTotalRealitationPrice']);
|
||||
if ($amount <= 0) {
|
||||
$amount = floatval($d['PurchaseRequestDirectDetailTotalEstimationPrice']);
|
||||
}
|
||||
|
||||
$totalPay += floatval($d['PaymentVoucherDetailTotal']);
|
||||
$row_data = array(
|
||||
$no,
|
||||
$d['PurchaseRequestDirectNumber'] ?: '-',
|
||||
$d['PurchaseDirectCategoryName'] ?: '-',
|
||||
$d['ItemDescription'] ?: '-',
|
||||
$this->_fmt_rp($amount),
|
||||
);
|
||||
|
||||
$pdf->Row($row_data);
|
||||
|
||||
$totalPay += $amount;
|
||||
$no++;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user