<?php
class Pdf extends PDF_MC_Table{
	//Page header
	public $paper_w = 210, $paper_h = 330;
    function __construct() {
        //set Page 
        parent::__construct('P','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->setY($y);
            $this->setFont('Arial','B',12);
            $this->cell(0, 5, $this->kategori->nama_kelompok." - ".$this->kategori->nama, 0, 1, "R");

            $this->Ln();
        }
				
	}
	
	function Content()
	{   $this->SetWidths(array(
                    $this->paper_w*10/100, 
                    $this->paper_w*15/100, 
                    $this->paper_w*20/100, 
                    $this->paper_w*15/100,
                    $this->paper_w*15/100,
                    $this->paper_w*15/100,
                ));
                $this->SetAligns(array("C", "C", "C","C", "C","C"));
                $this->setFont('Arial','B',10);
                $this->Row(array("Tanggal", "No Faktur", "Pelanggan", "Penjualan", "Diskon", "Piutang"));
                
                $this->setFont('Arial','',  0);
                $this->SetAligns(array("C", "L", "L", "R", "R", "R"));

                $total = 0;
                $total_penjualan = 0;
                $total_diskon = 0;
                $total_piutang = 0;
                if(count($this->data) > 0){
                    $no = 1;
                    foreach($this->data as $d){

                        $nominal_penjualan = $d->nominal_jumlah+$d->nominal_pajak;
                        $nominal_piutang = $nominal_penjualan-$d->nominal_potongan;
                        $this->Row_bawahputus([
                                date_db($d->tanggal_faktur, true),
                                nomor_penjualan($d),
                                $d->nama_pelanggan,
                                rupiah2($nominal_penjualan, 2),
                                rupiah2($d->nominal_potongan, 2),
                                rupiah2($nominal_piutang, 2)
                            ]);

                        $total += $nominal_piutang;
                        $total_penjualan += $nominal_penjualan;
                        $total_diskon += $d->nominal_potongan;
                        $total_piutang += $nominal_piutang;

                    }
                }
                
                $this->setFont('Arial','B',10);
                $this->SetWidths(array($this->paper_w*45/100, $this->paper_w*15/100, $this->paper_w*15/100, $this->paper_w*15/100));
                $this->SetAligns(array("L", "R", "R", "R"));
                $this->Row(array("Jumlah Keseluruhan", rupiah2($total_penjualan, 2), rupiah2($total_diskon, 2), rupiah2($total_piutang, 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->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");

?>