<?php
class Pdf extends PDF_MC_Table{
	//Page header
	//public $kas_masuk,$tgl1,$tgl2;
    public $paper_w = 210, $paper_h = 297;
	function __construct() {
		//set Page 
		parent::__construct('L','mm',array($this->paper_w , $this->paper_h));
		/*$this->AddFont("tahoma","","tahoma.php");
		$this->AddFont("tahoma","B","tahomabd.php");*/
    }
	function Header(){
        
		if($this->PageNo() != 0){		
                $this->setFont('Arial','B',12);
                $this->setFillColor(255,255,255);
                $this->setTextColor(0,0,0);
                
                $this->cell(100, 5, $this->judul, 0, 0, "L");
                $this->Ln();

                $y = $this->getY();

                $this->setFont('Arial','',10);
                $this->cell(20, 5, "Periode", 0, 0, "L");
                $this->cell(5, 5, ":", 0, 0, "L");
                $this->MultiCell(100, 5, $this->periode, "FJ");

                // $this->setXY(115, $y);
                // $this->MultiCell(85, 5, (count($this->data) > 0) ? $this->data[0]->nama.' - '.$this->data[0]->pic:"", 0, "R");

                $this->Ln();

                $this->SetWidths(array(
                    $this->paper_h*5/100, 
                    $this->paper_h*22/100, 
                    $this->paper_h*11/100, 
                    $this->paper_h*11/100, 
                    $this->paper_h*11/100, 
                    $this->paper_h*11/100, 
                    $this->paper_h*11/100,
                    $this->paper_h*11/100
                ));
                $this->SetAligns(array("C", "C", "C", "C", "C", "C", "C", "C"));
                $this->setFont('Arial','B',10);
                $this->Row(array("No", "Penyedia", "Total", "Belum\nJatuh Tempo", "1-30 Hari", "31-60 Hari", "61-90 Hari", ">90 Hari"));
                // $this->setFont('Arial','',10);
                $this->SetAligns(array("C", "L", "R", "R", "R", "R", "R", "R"));

            }
				
	}
	
	function Content()
	{
        if(count($this->data) > 0){
            $hutang_total = 0;
            $hutang_0 = 0;
            $hutang_30 = 0;
            $hutang_60 = 0;
            $hutang_90 = 0;
            $hutang_91 = 0;

            $no = 1;
            foreach($this->data as $d){
                if($d->child['hutang_total']==0) continue;

                $this->setFont('Arial','',10);
                $this->SetAligns(array("C", "L", "R", "R", "R", "R", "R", "R"));

                $this->Row_bawahputus([
                        $no,
                        $d->nama,
                        $this->setNominal($d->child['hutang_total']),
                        $this->setNominal($d->child['hutang_0']),
                        $this->setNominal($d->child['hutang_30']),
                        $this->setNominal($d->child['hutang_60']),
                        $this->setNominal($d->child['hutang_90']),
                        $this->setNominal($d->child['hutang_91'])
                    ]);

                $hutang_total += $d->child['hutang_total'];
                $hutang_0 += $d->child['hutang_0'];
                $hutang_30 += $d->child['hutang_30'];
                $hutang_60 += $d->child['hutang_60'];
                $hutang_90 += $d->child['hutang_90'];
                $hutang_91 += $d->child['hutang_91'];

                $no++;
            }

            $this->setFont('Arial','B',10);
            $this->SetWidths([
                    $this->paper_h*27/100, 
                    $this->paper_h*11/100, 
                    $this->paper_h*11/100, 
                    $this->paper_h*11/100, 
                    $this->paper_h*11/100, 
                    $this->paper_h*11/100,
                    $this->paper_h*11/100
                ]);
            $this->SetAligns(array("R", "R", "R", "R", "R", "R", "R"));
            $this->Row([
                    "Total Hutang",
                    $this->setNominal($hutang_total),
                    $this->setNominal($hutang_0),
                    $this->setNominal($hutang_30),
                    $this->setNominal($hutang_60),
                    $this->setNominal($hutang_90),
                    $this->setNominal($hutang_91),
                ]);
        }

        $this->setFont('Arial','',10);
        $this->setFillColor(255,255,255);
        $this->setTextColor(0,0,0);

        // tanda tangan
        if($this->getY() > 155){
            $this->AddPage();
            $this->ln();   
        }else{
            $this->ln();
        }

        $this->setX(170);
        $this->SetWidths([
                $this->paper_h*18/100,
                $this->paper_h*18/100
            ]);
        $this->SetAligns(['C', 'C']);
        $this->Row_withAligment(['Mengetahui', 'Dilaporkan Oleh :'], 25, ['valign'=>'T']);
        // end : tanda tangan

	}
	
	function Footer()
	{
        $this->SetY(-15);
        $this->SetFont('Arial','',10);
        $this->Cell(0, 10, $this->PageNo(), 0, 0, 'R');
		
	}

    function setNominal($value=0)
    {
        if($value < 0){
            $set = "( ".rupiah2(abs($value))." )";
        }else{
            $set = rupiah2($value);
        }
        return $set;
    }
}
$Pdf = new Pdf();
$Pdf->judul=$data['judul'];
$Pdf->periode=$data['periode'];
$Pdf->data=$data['data'];
$Pdf->SetAutoPageBreak(true ,15);

$Pdf->SetMargins(10,10,10);
$Pdf->AliasNbPages();
$Pdf->AddPage();
$Pdf->SetFont('Arial','',12);
$Pdf->Content();
$Pdf->SetTitle($data['judul']);
$Pdf->Output($data['judul'].".pdf", "I");

?>