<?php
class Pdf extends PDF_MC_Table{
    //Page header
    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();

                $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(array(
            $this->paper_h*5/100,
            $this->paper_h*8/100,
            $this->paper_h*10/100,
            $this->paper_h*15/100,
            $this->paper_h*15/100,
            $this->paper_h*5/100,
            $this->paper_h*5/100,
            $this->paper_h*10/100,
            $this->paper_h*10/100,
            $this->paper_h*10/100
                ));
        $this->SetAligns(array("C", "C", "C", "C", "C", "C", "C", "C", "C"));
        $this->setFont('Arial','B',10);
        $this->Row(array("No", "Tanggal", "No. Order", "Penyedia", "Nama Barang", "Satuan", "Qty", "Harga Satuan", "PPN", "Jumlah"));
                
        $this->setFont('Arial','',9);
        $this->SetAligns(array("C", "L", "L", "L", "L", "L", "R", "R", "R", "R"));

        $total = 0;
        if(count($this->data) > 0){
            $no = 1;
            foreach($this->data as $d){
                $set_nama_barang = $d->kategori.' '.$d->sub_kategori.' '.$d->nama_barang;
                if($d->id_kelompok==4){
                            $set_nama_barang = $d->nama_barang;
                }
                $sub_total = $d->jml_barang*(($d->harga_satuan)+($d->nilai_ppn));
                $this->Row_bawahputus(array($no, tgl_full($d->tanggal, ''), $d->no_faktur."".$d->sufix_no_order, $d->nama, $set_nama_barang, $d->satuan, $d->jml_barang, rupiah2(($d->harga_satuan), 2), rupiah2(($d->nilai_ppn), 2), rupiah2($sub_total, 2)));
                $no++;
                $total += $sub_total;
            }
        }
        $this->setFont('Arial','B',9);
        $this->SetWidths(array($this->paper_h*83/100, $this->paper_h*10/100));
        $this->SetAligns(array("R", "R"));
        $this->Row(array("Total Order 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'];

$Pdf->SetAutoPageBreak(true ,15);

$Pdf->SetMargins(10,10,10);
$Pdf->AliasNbPages();
$Pdf->AddPage();
$Pdf->SetFont('Arial','',12);
$Pdf->Content();
$Pdf->SetTitle("Laporan Order Pembelian Per Kategori");
$Pdf->Output("Laporan Order Pembelian Per Kategori - ".$data['periode'].".pdf", "I");

?>