<?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, "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();

                

            }
				
	}
	
	function Content()
	{   
        // $this->SetWidths(array(10, 20, 25, 55, 15, 10, 30, 30));
        $this->SetWidths([
            $this->paper_w*5/100,
            $this->paper_w*8/100,
            $this->paper_w*10/100,
            $this->paper_w*25/100,
            $this->paper_w*5/100,
            $this->paper_w*5/100,
            $this->paper_w*12/100,
            $this->paper_w*12/100,
            $this->paper_w*12/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", "Barang", "Satuan", "Qty", "Harga Satuan", "PPN", "Jumlah"));
        
        $this->setFont('Arial','',9);
        $this->SetAligns(array("C", "L", "L","L","L", "R", "R", "R", "R"));

        $total = 0;
        if(count($this->data) > 0){
            $no = 1;
            foreach($this->data as $d){
                $temp_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_faktur, $d->kategori.' - '.$d->sub_kategori.' - '.$d->nama_barang, $d->satuan, $d->jml_barang, number_format(($d->harga_satuan), 2, ',', '.'), number_format(($d->nilai_ppn), 2, ',', '.'), number_format($temp_total, 2, ',', '.')));
                $no++;
                $total += $temp_total;
            }
        }
        $this->setFont('Arial','B',9);
        $this->SetWidths([
            $this->paper_w*82/100,
            $this->paper_w*12/100,
        ]);
        $this->SetAligns(array("R", "R"));
        $this->Row(array("Total Pembelian", number_format($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]->nama.' ('.$data['data'][0]->pic.')':"";
$Pdf->SetAutoPageBreak(true ,15);

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

?>