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

                $this->SetWidths(array(
                    $this->paper_h*5/100, 
                    $this->paper_h*35/100, 
                    $this->paper_h*13/100, 
                    $this->paper_h*13/100, 
                    $this->paper_h*13/100, 
                    $this->paper_h*13/100
                ));
                $this->SetAligns(array("C", "C", "C", "C", "C", "C"));
                $this->setFont('Arial','B',10);
                $this->Row(array("No", "Penyedia", "Saldo Awal", "Tagihan", "Pembayaran", "Saldo"));
                // $this->setFont('Arial','',10);
                $this->SetAligns(array("C", "L", "R", "R", "R", "R"));
                

            }
				
	}
	
	function Content()
	{
        $total = 0;
        $total_saldo_awal = 0;
        $total_orderservice = 0;
        $total_pembayaran = 0;
        $no = 1;

        $sub_saldo = 0;
        if(count($this->data) > 0){
            foreach($this->data as $d){
                $this->setFont('Arial','',10);
                $this->SetAligns(array("C", "L", "R", "R", "R", "R"));

                $sub_saldo = $d->saldo_awal+$d->orderservice-$d->pembayaran;
                // $saldo = $sub_saldo;
                $this->Row_bawahputus(array($no, $d->nama_penyedia, rupiah2($d->saldo_awal, 2), rupiah2($d->orderservice, 2), rupiah2($d->pembayaran, 2), rupiah2($sub_saldo, 2)));
                $no++;
                $total_saldo_awal += $d->saldo_awal;
                $total_orderservice += $d->orderservice;
                $total_pembayaran += $d->pembayaran;
                // $total += $saldo;
            }
        }
        $saldo_hutang = $total_saldo_awal+$total_orderservice-$total_pembayaran;
        $this->setFont('Arial','B',10);
        $this->SetWidths(array($this->paper_h*40/100, $this->paper_h*13/100, $this->paper_h*13/100, $this->paper_h*13/100, $this->paper_h*13/100));
        $this->SetAligns(array("R", "R", "R", "R", "R"));
        $this->Row(array("Jumlah", rupiah2($total_saldo_awal, 2), rupiah2($total_orderservice, 2), rupiah2($total_pembayaran, 2), rupiah2($saldo_hutang, 2)));

        $this->setFont('Arial','',10);
        $this->setFillColor(255,255,255);
        $this->setTextColor(0,0,0);

        // tanda tangan
        if($this->getY() > 155){
            $this->AddPage();
            $this->ln();   
        }else{
            $this->ln();
        }

        $this->setX(170);
        $this->SetWidths([
                $this->paper_h*18/100,
                $this->paper_h*18/100
            ]);
        $this->SetAligns(['C', 'C']);
        $this->Row_withAligment(['Mengetahui', 'Dilaporkan Oleh :'], 25, ['valign'=>'T']);
        // end : tanda tangan

        
	}
	
	function Footer()
	{
        $this->SetY(-15);
        $this->SetFont('Arial','',10);
        $this->Cell(0, 10, $this->PageNo(), 0, 0, 'R');
		
	}
}
$Pdf = new Pdf();
$Pdf->judul=$data['judul'];
$Pdf->periode=$data['periode'];
$Pdf->data=$data['data'];
$count = (count($data['data']) > 0) ? $data['data'][0]->nama_penyedia.' ('.$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($data['judul']);
$Pdf->Output($data['judul'].".pdf", "I");

?>