<?php
class Pdf extends PDF_MC_Table{
	//Page header
	//public $kas_masuk,$tgl1,$tgl2;
    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('Tahoma','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('Tahoma','',9);
                $this->cell(20, 5, "Periode", 0, 0, "L");
                $this->cell(5, 5, ":", 0, 0, "L");
                $this->MultiCell(100, 5, $this->periode, "FJ");

                $this->Ln();

                $this->setFont('Tahoma','B',9);
                
                $this->cell($this->paper_w*4/100, 5, "No", 1, 0,"C");
                $this->cell($this->paper_w*28/100, 5, "Pegawai", 1, 0,"C");
		        $this->cell($this->paper_w*16/100, 5, "Saldo Awal", 1, 0,"C");
		        $this->cell($this->paper_w*12/100, 5,"Kas Bon", 1, 0,"C");
		        $this->cell($this->paper_w*16/100, 5, "Pembayaran", 1, 0,"C");
		        $this->cell($this->paper_w*16/100, 5, "Saldo", 1, 1,"C");
            }
	}
	
	function Content()
	{           
        $this->setFont('Tahoma','',9);

        $total = 0;
        $total_saldo_awal = 0;
        $total_kasbon = 0;
        $total_pembayaran = 0;
        $no = 1;

        $sub_saldo = 0;
        if(count($this->data) > 0){
            foreach($this->data as $d){
            	$sub_saldo = $d['saldo_awal']+$d['kasbon']-$d['bayar'];
                if ($d['saldo_awal'] != 0 || $d['kasbon'] != 0 || $d['bayar'] != 0) {
                    $this->cell($this->paper_w*4/100, 5, $no, 1, 0,"C");
                    $this->cell($this->paper_w*28/100, 5, (!is_null($d['nomor_pegawai'])) ? $d['nomor_pegawai'].' - '.$d['nama_pegawai'] : $d['nama_pegawai'], 1, 0,"L");
                    $this->cell($this->paper_w*16/100, 5, $this->setNominal($d['saldo_awal']), 1, 0,"R");
                    $this->cell($this->paper_w*12/100, 5, $this->setNominal($d['kasbon']), 1, 0,"R");
                    $this->cell($this->paper_w*16/100, 5, $this->setNominal($d['bayar']), 1, 0,"R");
                    $this->cell($this->paper_w*16/100, 5, $this->setNominal($sub_saldo), 1, 1,"R");
                    $no++;
                    $total_saldo_awal += $d['saldo_awal'];
                    $total_kasbon += $d['kasbon'];
                    $total_pembayaran += $d['bayar'];
                }
            }
        }
        $saldo_hutang = $total_saldo_awal+$total_kasbon-$total_pembayaran;
        $this->setFont('Tahoma','B',9);
        
        $this->cell($this->paper_w*32/100, 5, "Jumlah", 1, 0,"R");
        $this->cell($this->paper_w*16/100, 5, $this->setNominal($total_saldo_awal), 1, 0,"R");
        $this->cell($this->paper_w*12/100, 5, $this->setNominal($total_kasbon), 1, 0,"R");
        $this->cell($this->paper_w*16/100, 5, $this->setNominal($total_pembayaran), 1, 0,"R");
        $this->cell($this->paper_w*16/100, 5, $this->setNominal($saldo_hutang), 1, 1,"R");

        $this->setFont('Tahoma','',9);
        $this->setFillColor(255,255,255);
        $this->setTextColor(0,0,0);
        $this->ln();

        $this->setX($this->paper_w*45/100);
        $this->cell(50, 5, "Mengetahui", "TLR", 0, "C");
        $this->cell(50, 5, "Dilaporkan Oleh : ", "TLR", 1, "C");

        $this->setX($this->paper_w*45/100);
        $this->cell(50, 15, "", "BLR", 0, "C");
        $this->cell(50, 15, "", "BLR", 1, "C");
	}
	
	function Footer()
	{

	}

    function setNominal($value=0)
    {
        if($value < 0){
            $set = "( ".rupiah2(abs($value))." )";
        }else{
            $set = rupiah2($value);
        }
        return $set;
    }
}

$Pdf = new Pdf();
$Pdf->judul 	= $data['judul'];
$Pdf->periode 	= $data['periode'];
$Pdf->data      = $data['data'];

$Pdf->AddFont("Tahoma","","tahoma.php");
$Pdf->AddFont("Tahoma","B","tahomabd.php");
$Pdf->SetAutoPageBreak(true ,15);
$Pdf->SetMargins(10,10,10);
$Pdf->AliasNbPages();
$Pdf->AddPage();
$Pdf->SetFont('Tahoma','',12);
$Pdf->Content();
$Pdf->SetTitle($data['judul']);
$Pdf->Output($data['judul'].".pdf", "I");

?>