<?php
class Pdf extends PDF_MC_Table{
	//Page header
	public $paper_w = 330, $paper_h = 210;
    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, 0, "FJ");

                $this->setXY(100, $y);
                $this->MultiCell(($this->paper_w-110), 5, (count($this->data) > 0) ? $this->data[0]->kategori.' '.$this->data[0]->sub_kategori.' '.$this->data[0]->nama_barang:"", 0, "R");

                $this->Ln();

                

            }
				
	}
	
	function Content()
	{   
        // $this->SetWidths(array(10, 20, 25, 50, 15, 10, 30, 30));
        $this->SetWidths([
            $this->paper_w*5/100,
            $this->paper_w*8/100,
            $this->paper_w*10/100,
            $this->paper_w*18/100,
            $this->paper_w*5/100,
            $this->paper_w*5/100,
            $this->paper_w*10/100,
            $this->paper_w*8/100,
            $this->paper_w*10/100,
            $this->paper_w*15/100,
        ]);
        $this->SetAligns(array("C", "C", "C","C","C", "C", "C", "C", "C", "C"));
        $this->setFont('Arial','B',10);
        $this->Row(array("No", "Tanggal", "No. Faktur", "Supplier", "Satuan", "Qty", "Harga Satuan", "PPN", "Jumlah", "Keterangan"));
                
        $this->setFont('Arial','',9);
        $this->SetAligns(array("C", "L", "L","L","L", "R", "R", "R", "R", "L"));

        $total = 0;
        if(count($this->data) > 0){
            $no = 1;
            foreach($this->data as $d){
                $this->Row_bawahputus(array($no, tgl_full($d->tanggal_faktur, ''), $d->no_faktur."".$d->sufix_no_faktur, strtoupper($d->nama), $d->satuan, $d->jml_barang, rupiah2(($d->harga_satuan), 2), rupiah2(($d->nilai_ppn), 2), rupiah2(($d->total), 2), $d->keterangan));
                $no++;
                $total += ($d->total);
            }
        }
        $this->setFont('Arial','B',9);
        $this->SetWidths([
            $this->paper_w*69/100,
            $this->paper_w*10/100,
            $this->paper_w*15/100
        ]);
        $this->SetAligns(array("R", "R"));
        $this->Row(array("Total Pembelian", rupiah2($total, 2), ""));

        
	}
	
	function Footer()
	{
		$this->SetY(-15);
        $this->SetFont('Arial','',9);
        $this->Cell(0,10, $this->PageNo(),0,0,'C');
	}
}
$Pdf = new Pdf();
$Pdf->judul=$data['judul'];
$Pdf->periode=$data['periode'];
$Pdf->data=$data['data'];
$count = (count($data['data']) > 0) ? $data['data'][0]->kategori.' '.$data['data'][0]->sub_kategori.' '.$data['data'][0]->nama_barang:"";
$Pdf->SetAutoPageBreak(true ,15);

$Pdf->SetMargins(10,10,10);
$Pdf->AliasNbPages();
$Pdf->AddPage();
$Pdf->SetFont('Arial','',12);
$Pdf->Content();
$Pdf->SetTitle("Laporan Pembelian per Barang - ".$count );
$Pdf->Output("Laporan Pembelian per Barang - ".$count.".pdf", "I");

?>