<?php 
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class PDF extends PDF_MC_Table{

    function Content($dt_all, $header){
        if ($this->PageNo() == 1){
            $this->Ln(3);
            $this->setFont('Arial','B',10);
            $this->setFillColor(255,255,255);
            $this->SetX(40);
            $this->cell(0,6,$header['profile']['nama'],0,1,'L',1); 
            $this->SetX(40);
            $this->cell(0,6,$header['profile']['almt'],0,1,'L',1); 
            $this->SetX(40);
            $this->cell(0,6,$header['profile']['notelp'],0,1,'L',1); 
            $this->image(base_url('assets/img/logo.png'),12,10,26,21);
            $this->Ln(3);
            $this->SetLineWidth(1);
            $this->Line(10,$this->GetY(),200,$this->GetY());
            $this->SetLineWidth(0);

            // Line break
            $this->Ln(3);
            $this->setFont('Arial','B',11);
            $this->setFillColor(255,255,255);
            $this->cell(0,6,'Laporan Penerimaan Kas',0,1,'C',1); 
            $this->setFont('Arial','B',11);
            $this->setFillColor(255,255,255);
            $this->cell(0,6,$header['periode'],0,1,'C',1); 
            $this->Ln(2);
            $this->setFont('Arial','B',9);
            $this->setFillColor(255,255,255);
            $this->cell(35,6,'Tanggal',1,0,'C',1);
            $this->cell(25,6,'Kode Trans',1,0,'C',1);
            $this->cell(35,6,'Pemberi',1,0,'C',1);
            $this->cell(20,6,'Sumber',1,0,'C',1);
            $this->cell(45,6,'Keterangan',1,0,'C',1);
            $this->cell(30,6,'Nominal',1,0,'C',1);

            //jika terdapat transaksi
            if($dt_all)
            {
                $this->Ln();
                $this->setFont('Arial','',9);
                $this->SetWidths(Array(35,25,35,20,45,30));
                $this->SetAligns(Array('C','L','L','L', 'L', 'R'));
                $this->SetLineHeight(5);
                $nominal = 0;
                foreach ($data as $c) {

                    $k = 1;
                    $detail = '';
                    $total_nilai = 0;
                    foreach($c['dt_trans_detail'] as $row_d) {
                        $detail .= $k++.'. '.$row_d['ket']." (".number_format($row_d['nilai'],0,',','.')."), \n";
                        $total_nilai += $row_d['nilai'];
                    }

                    $this->Row(Array(
                        $c['tgl'],
                        'KM-'.$c['code_trans'],
                        $c['nm_receivable'],
                        $c['nm_account'],
                        $detail,
                        number_format($total_nilai,0,',','.')
                    ));
                    $nominal += $total_nilai;
                }
                $this->setFont('Arial','B',9);
                $this->SetWidths(Array(160,30));
                $this->SetAligns(Array('C','R'));
                $this->SetLineHeight(5);
                $this->Row(Array(
                        'Total',
                        number_format($nominal,0,',','.')
                    ));
            } else {
                $this->Ln();
                $this->setFont('Arial','',9);
                $this->cell(190,6,'Tidak Ada Transaksi',1,1,'C',1);
            }

        }

    }
}
 
// Instanciation of inherited class
$pdf = new PDF('L');
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->setTitle('Laporan Barang Masuk',true);
$pdf->Content($dt_All, $header);
$pdf->Output('laporan-barang-masuk['.date('d-M-Y').'].pdf', 'I');

?>