<?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',12);
                $this->setFillColor(255,255,255);
                $this->setTextColor(0,0,0);
                
                $this->cell(100, 5, "Kartu Persediaan", 0, 0, "L");
                $this->Ln(7);

                $this->setFont('Arial','',10);
                $this->cell(30, 5, "Nama Barang", 0, 0, "L");
                $this->cell(5, 5, ":", 0, 0, "C");
                $this->MultiCell(80, 5, $this->barang, "FJ");

                $this->Ln(0);
                $y = $this->getY();
                $this->cell(30, 5, "Periode", 0, 0, "L");
                $this->cell(5, 5, ":", 0, 0, "C");
                $this->MultiCell(80, 5, $this->periode, "FJ");
                
                $this->setXY(140, $y);
                $this->cell(20, 5, "Satuan", 0, 0, "L");
                $this->cell(5, 5, ":", 0, 0, "C");
                $this->MultiCell(40, 5, $this->satuan, "FJ");

                $this->Ln(7);
                $this->setFont('Arial','B',10);
                $this->SetWidths(array(10, 20, 25, 40, 17, 17, 17, 25, 25));
                $this->SetAligns(array('C', "C", "C", "C", "C", "C", "C", "C", "C"));
                $this->Row(array("No", "Tanggal", "No. Faktur", "Jenis", "Masuk", "Keluar", "Jumlah", "Gudang", "Keterangan"));

                $this->setFont('Arial','',8);
                $this->SetAligns(array('C', "L", "L", "L", "R", "R", "R", "L", "L"));

                $no = 1;
                if(count($this->alur) > 0){
                    foreach($this->alur as $a){
                        $this->Row(array($no, tgl_full($a['tanggal'], ''), $a['ket_1'], $a['ket_3'].' : '.$a['ket_2'], $a['masuk'], $a['keluar'], $a['masuk']-$a['keluar'], $a['nama_gudang'], $a['nama_proses']));
                        $no++;
                    }
                }else{
                    $this->Row(array("", "", "", "", "", "", "", "", ""));
                }

                $this->setFont('Arial','', 9);
                
                $this->SetWidths(array(95, 101));
                $this->SetAligns(array("C", "C"));                                
                $this->setFont('Arial','B',9);
                $this->Row(array("Jumlah di gudang", ""));


                $this->SetWidths(array(95, 17, 17, 17, 25, 25));
                $this->SetAligns(array("C", "R", "R", "R", "L", "L"));
                $this->setFont('Arial','', 8);

                $masuk = 0; $keluar = 0; $ttl = 0;
                if(count($this->groupby) > 0){
                    $no = 1;
                    foreach($this->groupby as $g){
                        $this->Row(array("", $g['persediaan_masuk'], $g['persediaan_keluar'], $g['persediaan_masuk']-$g['persediaan_keluar'], $g['nama_gudang'], $g['nama_proses']));
                        $masuk += $g['persediaan_masuk'];
                        $keluar += $g['persediaan_keluar'];
                        $ttl += ($g['persediaan_masuk']-$g['persediaan_keluar']);
                        $no++;
                    }
                }else{
                    $this->Row(array("", "", "", "", "", ""));    
                }
                
                $this->setFont('Arial','B',9);
                $this->SetWidths(array(95, 17, 17, 17, 50));
                $this->SetAligns(array("C", "R", "R", "R", "C"));
                $this->Row(array("Jumlah Persediaan", $masuk, $keluar, $ttl, ""));
            }
				
	}
	
	function Content()
	{   
        $this->setFont('Arial','',9);
        $this->setFillColor(255,255,255);
        $this->setTextColor(0,0,0);
        $this->SetWidths(array(40, 80, 37, 37));
        $this->SetAligns(array('C', 'L', 'R', 'R'));

        
	}
	
	function Footer()
	{
		
	}
}
$Pdf = new Pdf();
$Pdf->alur=$data['alur'];
$Pdf->periode=$data['periode'];
$Pdf->groupby=$data['groupby'];
$Pdf->satuan=$data['satuan'];
$Pdf->barang=$data['barang'];
$Pdf->SetAutoPageBreak(true ,15);

$Pdf->SetMargins(10,10,10);
$Pdf->AliasNbPages();
$Pdf->AddPage();
$Pdf->SetFont('Arial','',12);
$Pdf->Content();
$Pdf->SetTitle("Kartu Persediaan ".$data['barang']." per ".$data['periode']);
$Pdf->Output("Kartu Persediaan ".$data['barang']." per ".$data['periode'].".pdf", "I");

?>