<?php
class Pdf extends PDF_MC_Table{
	//Page header
	public $paper_w = 210, $paper_h = 297;
    function __construct() {
        //set Page 
        parent::__construct('P','mm',array($this->paper_w ,$this->paper_h));
    }

	function Header(){
        
		if($this->PageNo() != 0){		
            $this->setFont('Arial','B',12);
            
            $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->setY($y);
            $this->setFont('Arial','B',12);
            $this->cell(0, 5, $this->kategori->nama_kelompok." - ".$this->kategori->nama, 0, 1, "R");

            $this->Ln();

            $this->setFont('Arial','B',10);

            $x = $this->GetX();
            $y = $this->GetY();

            $this->MultiCell(21, 7, "Nomor", 1, "C", 0);

            $this->SetXY($x+21, $y);
            $this->MultiCell(32, 7, "No Barang", 1, "C", 0);

            $this->SetXY($x+53, $y);
            $this->MultiCell(105, 7, "Nama Barang", 1, "C", 0);

            $this->SetXY($x+158, $y);
            $this->MultiCell(31, 7, "Qty", 1, "C", 0);
        }
				
	}
	
	function Content()
	{   

                $this->setFont('Arial','B',10);

                $x = $this->GetX();
                $y = $this->GetY();
                
                $this->setFont('Arial','',  0);
                $this->SetAligns(array("C", "L", "L", "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;
                        }

                        $this->cell(21, 5, $no ,1, 0,'C');
                        $this->cell(32, 5, $d->kode_barang, 1, 0,'C');
                        $this->cell(105, 5, $set_nama_barang, 1, 0,'L');
                        // $this->cell(31, 5, $d->jumlah_qty.' '.$d->nama_satuan, 1, 1, 'R');
                        $this->cell(31, 5, $d->jumlah_qty.' Pt', 1, 1, 'R');
                        $no++;
                        $total += $d->jumlah_qty;
                        $nama_satuan = $d->nama_satuan;
                    }
                }
                $this->setFont('Arial','B',10);

                $this->cell(158,7,"Jumlah Keseluruhan",1,0,'R');
                // $this->cell(31,7,$total.' '.$nama_satuan,1,0,'R');
                $this->cell(31,7,$total.' Pt',1,0,'R');
        
	}
	
	function Footer()
	{
		$this->SetY(-15);
        $this->SetFont('Arial','I',9);
        $this->Cell(0,10, "Halaman ".$this->PageNo(),0,0,'R');
	}
}
$Pdf = new Pdf();
$Pdf->judul=$data['judul'];
$Pdf->periode=$data['periode'];
$Pdf->kategori=$data['kategori'];
$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] ".$data['periode']);
$Pdf->AutoPrint(false);
$Pdf->Output("$data[judul] ".$data['periode'].".pdf", "I");

?>