<?php 
    if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    
    class PDF extends FPDF{
        // Page header
        function Header(){
            if ($this->PageNo() == 1){
                $this->setFont('Arial','I',9);
                $this->setFillColor(255,255,255);
                $this->cell(90,6,'',0,0,'L',1); 
                $this->cell(100,6,"Printed date : " . date('d-M-Y'),0,1,'R',1); 
                $this->Line(10,$this->GetY(),200,$this->GetY());
                }else{
                $this->setFont('Arial','I',9);
                $this->setFillColor(255,255,255);
                $this->cell(90,6,"Daftar Akun",0,0,'L',1); 
                $this->cell(100,6,"Printed date : " . date('d-M-Y'),0,1,'R',1); 
                $this->Ln(3);
            }
        }
        
        function Content($neraca_saldo_data, $profile){
            // dump($neraca_saldo_data);
            // Kop Laporan
            $this->Ln(3);
            $this->setFont('Arial','B',12);
            $this->setFillColor(255,255,255);
            $this->cell(0,6,$profile['perusahaan'],0,1,'C',1); 
            $this->cell(0,6,'Daftar Akun',0,1,'C',1); 
             
            // Line break
            $this->Ln(3);
            $this->setFont('Arial','B',9);
            $this->setFillColor(255,255,255);
            $this->cell(20,6,'No Akun',1,0,'C',1);
            $this->cell(45,6,'Kelompok',1,0,'C',1);
            $this->cell(125,6,'Nama Akun',1,0,'C',1);
            
            $sum_aset_lancar_debit = 0;
            $sum_aset_lancar_kredit = 0;
            if(isset($neraca_saldo_data))
            {
                foreach ($neraca_saldo_data as $key => $row)
                {
                    
                    
                    $this->Ln();
                    $this->setFont('Arial','',9);
                    $this->setFillColor(255,255,255);   
                    $this->cell(20,6,$row['noakun'],1,0,'C',1);
                    $this->cell(45,6,$row['nama_kel_akun'],1,0,'L',1);
                    $this->cell(125,6,$row['nama'],1,0,'L',1);
                    // $this->cell(45,6,'Rp. '.number_format(abs($row['saldo']),0,',','.'),1,0,'R',1);
                    // $sum_aset_lancar_kredit += $row['saldo'];  
                }
            }
            
            $this->Ln();
            $this->setFont('Arial','B',9);
            $this->setFillColor(255,255,255);   
            // $this->cell(100,6,'Jumlah Total',1,0,'R',1);
            // $this->cell(45,6,'Rp. '.number_format($sum_debit,0,',','.'),1,0,'R',1);
            // $this->cell(45,6,'Rp. '.number_format(abs($sum_kredit),0,',','.'),1,0,'R',1);
            
        }
        
        // Page footer
        function Footer(){
            // Position at 1.5 cm from bottom
            $this->SetY(-15);
            //buat garis horizontal
            $this->Line(10,$this->GetY(),200,$this->GetY());
            //Arial italic 9
            $this->SetFont('Arial','I',9);
            $this->Cell(0,10,'Copyright@'.date('Y'),0,0,'L');
            //nomor halaman
            $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'R');
        }
    }
    
    // Instanciation of inherited class
    $pdf = new PDF();
    $pdf->AliasNbPages();
    $pdf->AddPage();
    $pdf->setTitle('Neraca Saldo '.$profile['perusahaan'],true);
    $pdf->Content($akun, $profile);
    $pdf->Output('neraca-saldo['.date('d-M-Y').'].pdf', 'I');
