<?php
class Pdf extends PDF_MC_Table{
	//Page header
	//public $kas_masuk,$tgl1,$tgl2;
    private $width=210, $height=297;
	function __construct() {
		//set Page 
		parent::__construct('L','mm',array($this->height ,$this->width ));
		/*$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();

                $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->Ln();

                

            }
				
	}
	
	function Content()
	{   
        $this->SetWidths([
                            $this->height*5/100,
                            $this->height*10/100,
                            $this->height*12/100,
                            $this->height*25/100,
                            $this->height*12/100,
                            $this->height*12/100,
                            $this->height*12/100
                        ]);
        $this->SetAligns([
                            "C",
                            "C",
                            "C",
                            "C",
                            "C",
                            "C",
                            "C"
                        ]);
        $this->setFont('Arial','B',10);
        $this->Row([
                    "No",
                    "Tanggal",
                    "No. Faktur",
                    "Nama Supplier",
                    "Jumlah",
                    "Sisa Tagihan",
                    "Keterangan"
                ]);
                
        $this->setFont('Arial','',9);
        $this->SetAligns(array("C", "C", "L","L", "R", "R", "L"));

        $total = 0;
        $sisa_tagihan = 0;
        if(count($this->data) > 0){
            $no = 1;
            foreach($this->data as $d){
                $set_sisa_tagihan = $d->nominal_netto-$d->total_bayar;
                $this->Row_bawahputus([
                        $no,
                        tgl_full($d->tanggal, ''),
                        nomor_orderbeli($d),
                        $d->nama,
                        number_format($d->nominal_netto, 2, ',', '.'), 
                        number_format($set_sisa_tagihan, 2, ',', '.'), 
                        $d->status_bayar
                    ]);
                $no++;
                $total += $d->nominal_netto;
                $sisa_tagihan += $set_sisa_tagihan;
            }
        }
        // $this->setFont('Arial','B',9);
        // $this->SetWidths([
        //                     $this->height*57/100,
        //                     $this->height*12/100,
        //                     $this->height*12/100,
        //                     $this->height*10/100
        //                 ]);
        // $this->SetAligns(array("R", "R", "R", "L"));
        // $this->Row(array("Total Order Pembelian", number_format($total, 2, ',', '.'), number_format($sisa_tagihan, 2, ',', '.'), ""));

        
	}
	
	function Footer()
	{
	    $this->SetY(-15);
        $this->SetFont('Arial','',9);
        $this->Cell(0,10, $this->PageNo(),0,0,'C');	
	}
}
$Pdf = new Pdf();
$Pdf->judul=$judul;
$Pdf->periode=$periode;
$Pdf->data=$pembelian;

$Pdf->SetAutoPageBreak(true ,15);

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

?>