<?php
class Pdf extends PDF_MC_Table{
	//Page header
	//public $kas_masuk,$tgl1,$tgl2;
	function __construct() {
		//set Page 
		parent::__construct('P','mm',array(210 ,330 ));
		/*$this->AddFont("tahoma","","tahoma.php");
		$this->AddFont("tahoma","B","tahomabd.php");*/
    }
	function Header(){
        
		if($this->PageNo() != 0){
                $this->setFont('Arial','B',11);
                $this->setFillColor(255,255,255);
                $this->setTextColor(0,0,0);
                
                $this->cell(193, 5, strtoupper($this->judul), 0, 1, "C");

                $this->setFont('Arial','',11);
                $this->cell(193, 5, strtoupper(strtolower("Bulan : ".$this->periode)), 0, 1, "C");
                $this->Ln();

                $this->SetWidths(array(10, 26, 27, 45, 30, 20, 35));
                $this->SetAligns(array("C","C","C","C","C","C","C"));
                $this->setFont('Arial','',9);
                $this->Row(array("NO", "TANGGAL\nPENGAMBILAN", "NO. FAKTUR", "NAMA PELANGGAN", "JUMLAH", "TANGGAL\nJATUH\nTEMPO", "KETERANGAN"));
                

            }
				
	}
	
	function Content()
	{
        $this->setFont('Arial','',9);
        $this->SetAligns(array("C", "C", "L","L","R", "C", "L"));

        $total = 0;
        if(count($this->data) > 0){
            $no = 1;
            foreach($this->data as $d){
                // if($d->total_bayar==$d->nominal_netto) continue;
                $selisih = (float)$d->piutang-(float)$d->total_bayar;
                if($selisih==0){
                    continue;
                }
                $this->Row(array($no, date_db($d->tanggal_faktur, true), $d->no_faktur."".$d->sufix_no_faktur, $d->nama_pelanggan, number_format($selisih, 2, ',', '.'), date_db($d->tanggal_tempo, true), $d->keterangan));
                $no++;
                $total += $selisih;
            }
        }
        $this->setFont('Arial','B',10);
        $this->SetWidths(array(108, 30, 55));
        $this->SetAligns(array("R", "R", "L"));
        $this->Row(array("TOTAL", number_format($total, 2, ',', '.'), ""));
        $this->ln();

        $set_y = $this->getY();

        if($set_y > 300){
            $this->AddPage();
        }

        $this->setY($set_y);
        $set_y = $this->getY();
        $this->setFont('Arial','',9);
        $this->cell(70, 5, "Mengetahui,", "LRT", 1, "C");
        $this->cell(70, 20, "", "LRB", 0, "C");

        $this->setXY(133, $set_y);
        $this->setFont('Arial','',9);
        $this->cell(70, 5, "Dibuat Oleh :", "LRT", 1, "C");
        $this->setX(133);
        $this->cell(70, 20, "", "LRB", 0, "C");


	}
	
	function Footer()
	{
		
	}
}
$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 Jatuh Tempo Penjualan".$data['periode']);
$Pdf->AutoPrint(false);
$Pdf->Output("Laporan Jatuh Tempo Penjualan periode".$data['periode'].".pdf", "I");

?>