<?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));
        /*$this->AddFont("tahoma","","tahoma.php");
        $this->AddFont("tahoma","B","tahomabd.php");*/
    }

	function Header(){
        
		if($this->PageNo() != 0){		
            $this->setFont('Arial','B',12);
            
            $this->cell(100, 5, $this->judul, 0, 0, "L");
            $this->Ln();

            $this->setFont('Arial','',10);
            $this->cell(25, 5, "Akun", 0, 0, "L");
            $this->cell(5, 5, ":", 0, 0, "L");
            $this->MultiCell(100, 5, $this->akun, "FJ");
            // $this->Ln();
            $this->cell(25, 5, "Periode", 0, 0, "L");
            $this->cell(5, 5, ":", 0, 0, "L");
            $this->MultiCell(100, 5, $this->periode, "FJ");

            $this->Ln();

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

            $this->SetWidths([
                $this->paper_h*8/100, 
                $this->paper_h*15/100, 
                $this->paper_h*28/100,
                $this->paper_h*15/100
            ]);
            $this->SetAligns(["C", "C", "C", "C"]);
            $this->Row_atasbawah(["Tanggal", "Perkiran", "Keterangan", "Jumlah"], 7);
        }
        $this->SetAligns(["L", "L", "L", "R"]);
        $this->setFont('Arial','',8);
                    $this->SetWidths([
                        $this->paper_h*6/100, 
                        $this->paper_h*21/100, 
                        $this->paper_h*22/100,
                        $this->paper_h*15/100
                    ]);
	}
	
	function Content()
	{
        $x = $this->GetX();
        $y = $this->GetY();

        $total_penerimaan 	= 0;
        $total_pengeluaran 	= 0;
        $saldo_akhir 		= 0;

        $this->setFont('Arial','B',9);
        $this->SetWidths([
            $this->paper_h*8/100, 
            $this->paper_h*15/100, 
            $this->paper_h*28/100,
            $this->paper_h*15/100
        ]);
        $this->SetAligns(["L", "L", "L", "R"]);
        $this->Row_atasbawah([
            "",
            "Saldo Awal",
            "",
            setNominal($this->saldo_awal, 2)
        ], 7);

        if(count($this->data) > 0) {
        	$this->Row_atasbawah([
	            "Penerimaan",
	            "",
	            "",
	            ""
	        ], 7);
            foreach($this->data AS $key=>$value){
            	if ($value->tipe_id_akun=="D") {
            		$this->setFont('Arial','',8);
	                $this->SetWidths([
	                    $this->paper_h*6/100, 
                        $this->paper_h*21/100, 
                        $this->paper_h*22/100,
                        $this->paper_h*15/100
	                ]);
	                $this->SetAligns(["L", "L", "L", "R"]);
	                $this->Row_noborder([
	                    date_db($value->tanggal_transaksi, true),
	                    "(".$value->kode_perkiraan_dariakun.") ".$value->nama_perkiraan_dariakun,
	                    $value->keterangan,
	                    setNominal($value->nominal_transaksi, 2)
	                ], 4);

	                $total_penerimaan += $value->nominal_transaksi;
            	}
            }

            $this->setFont('Arial','B',9);
            $this->SetWidths([
	            $this->paper_h*50/100, 
	            $this->paper_h*15/100
	        ]);
	        $this->SetAligns(["C","R"]);
            $this->Row_atasbawah([
	            "Total Penerimaan",
	            setNominal($total_penerimaan, 2)
	        ], 7);

	        $this->SetWidths([
	            $this->paper_h*8/100, 
	            $this->paper_h*15/100, 
	            $this->paper_h*28/100,
	            $this->paper_h*15/100
	        ]);
	        $this->SetAligns(["L", "L", "L", "R"]);
            $this->Row_atasbawah([
	            "Pengeluaran",
	            "",
	            "",
	            ""
	        ], 7);
            foreach($this->data AS $key=>$value){
            	if ($value->tipe_id_akun=="K") {
            		$this->setFont('Arial','',8);
	                $this->SetWidths([
	                    $this->paper_h*6/100, 
                        $this->paper_h*21/100, 
                        $this->paper_h*22/100,
                        $this->paper_h*15/100
	                ]);
	                $this->SetAligns(["L", "L", "L", "R"]);
	                $this->Row_noborder([
	                    date_db($value->tanggal_transaksi, true),
	                    "(".$value->kode_perkiraan_keakun.") ".$value->nama_perkiraan_keakun,
	                    $value->keterangan,
	                    setNominal($value->nominal_transaksi, 2)
	                ], 4);

	                $total_pengeluaran += $value->nominal_transaksi;
            	}
            }

            $this->setFont('Arial','B',9);
            $this->SetWidths([
	            $this->paper_h*50/100, 
	            $this->paper_h*15/100
	        ]);
	        $this->SetAligns(["C","R"]);
            $this->Row_atasbawah([
	            "Total Pengeluaran",
	            setNominal($total_pengeluaran, 2)
	        ], 7);
        }

        $saldo_akhir += ($this->saldo_awal+$total_penerimaan)-$total_pengeluaran;

        $this->setFont('Arial','B',9);
        $this->SetWidths([
            $this->paper_h*8/100, 
            $this->paper_h*15/100, 
            $this->paper_h*28/100,
            $this->paper_h*15/100
        ]);
        $this->SetAligns(["L", "L", "L", "R"]);
        $this->Row_atasbawah([
            "",
            "Saldo Akhir",
            "",
            setNominal($saldo_akhir, 2)
        ], 7);

        $this->Ln(2);
        $this->setX(111);

        $getY = $this->getY();

        $this->drawTextBox2("Pemeriksa", $this->paper_h*15/100, 15, "C");

        $this->setY($getY);
        $this->setX(155.4);
        $this->drawTextBox2("Kasir", $this->paper_h*15/100, 15, "C");
	}
	
	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->akun=$data['akun'];
$Pdf->data=$data['data'];
$Pdf->saldo_awal=$data['saldo_awal'];

$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");

?>