<?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){	

            $spacing = 5;
            $kolom_1 = 40;
            $kolom_2 = 5;
            $kolom_3 = 40;
            $ln = 3;

            $indent_1 = $kolom_1+$kolom_2+$kolom_3+20;

                $this->setFont('Arial','B',12);
                $this->setFillColor(255,255,255);
                $this->setTextColor(0,0,0);                
                $this->cell(0, 5, $this->judul.' '.ucwords($this->sub_header), 0, 0, "L");                

                $this->Ln(5);

                $this->setFont('Arial','',10);
                $this->setFillColor(255,255,255);
                $this->setTextColor(0,0,0);
                $this->cell($kolom_1, $spacing, "Periode", 0, 0, "L");
                $this->cell($kolom_2, $spacing, ":", 0, 0, "C");
                $this->Cell(20, $spacing, $this->tanggal ,0,0,'L');
                $this->Ln(10);
                $this->Ln();

                $this->setFont('Arial','B',8);
                $this->SetWidths(array(20, 70, 25, 25, 25, 25));
                $this->SetAligns(array("C", "C", "C", "C", "C", "C"));
                $this->Row(array("Perk.", "Nama Barang", "Awal", "Terima", "Keluar", "Akhir"));
                
                
                $this->SetAligns(array("L", "L", "R","R", "R", "R"));
            }
				
	}
	
	function Content()
	{                  
        $this->setFont('Arial','',8);
                

                /*if(count($this->detail) > 0){
                    foreach($this->detail as $k){
                       $nama_barang = get_empty($k['nama_barang']).get_empty($k['nama_komposisi']).get_empty($k['nama_kualitas_proses']).get_empty($k['nama_corak']).get_empty($k['nama_motif']).get_empty($k['nama_kualitas']).get_empty($k['kualitas_dudul']).get_empty($k['nama_kualitas_periksa']).get_empty($k['nama_label']).get_empty($k['nama_cap']).get_empty($k['nama_kemasan']).get_empty($k['nama_kemasansatuan']).get_empty($k['nama_kemasansepuluh']).get_empty($k['nama_kemasanseratus']).'-'.get_empty($k['tanggal']);

                       $this->Row(array($k['kode_barang'], $nama_barang, '', '', '', ''));
                    }
                }else{
                    $this->Row(array("", "", "", "", "", ""));
                }*/
        

                /*$sum_awal = 0;
                $sum_akhir = 0;
                $sum_terima = 0;
                $sum_keluar = 0;
                if(count($this->detail) > 0){
                    foreach ($this->detail as $k) {
                        $nama_barang = get_empty($k['nama_barang']).get_empty($k['nama_komposisi']).get_empty($k['nama_kualitas_proses']).get_empty($k['nama_corak']).get_empty($k['nama_motif']).get_empty($k['nama_kualitas']).get_empty($k['kualitas_dudul']).get_empty($k['nama_kualitas_periksa']).get_empty($k['nama_label']).get_empty($k['nama_cap']).get_empty($k['nama_kemasan']).get_empty($k['nama_kemasansatuan']).get_empty($k['nama_kemasansepuluh']).get_empty($k['nama_kemasanseratus']);

                        $sum_terima += $k['masuk'];
                        $sum_keluar += $k['keluar'];
                        if(count($this->awal) > 0){
                        foreach($this->awal as $d){
                        $akhir = ($k['masuk']-$k['keluar'])-0;                       
                            if($d['id_barang']==$k['id_barang'] && $d['id_gudang']==$k['id_gudang']){
                            $sum_awal += $d['stok']; 
                            $akhir += ($d['masuk']-$d['keluar'])-$d['stok'];
                            $this->Row(array($k['kode_barang'], $nama_barang, format_angka($sum_awal), format_angka($k['masuk']), format_angka($k['keluar']), format_angka($akhir)));
                            } 

                        }  
                        }else{
                        $sum_awal += 0;
                        $akhir = ($k['masuk']-$k['keluar'])-0;
                            $this->Row(array($k['kode_barang'], $nama_barang, format_angka(0), format_angka($k['masuk']), format_angka($k['keluar']), format_angka($akhir)));
                        }
                        $sum_akhir += $akhir;

                    }
                }else{
                    $this->Row(array("", "", "", "", "", ""));
                }                       
                

                $this->setFont('Arial','B',8);
                $this->SetWidths(array(90, 25, 25, 25,25));
                $this->SetAligns(array('L', "R", "R", "R", "R"));
                $this->Row(array("Jumlah Keseluruhan", format_angka($sum_awal), format_angka($sum_terima), format_angka($sum_keluar),format_angka($sum_akhir)));
                $this->Ln();

                $this->Ln();*/

                $sum_awal = 0;
                $sum_akhir = 0;
                $sum_terima = 0;
                $sum_keluar = 0;
                if(count($this->detail2) > 0){
                    foreach ($this->detail2 as $k) {
                        $nama_barang = get_empty($k->nama_barang).get_empty($k->nama_komposisi).get_empty($k->nama_kualitas_proses).get_empty($k->nama_corak).get_empty($k->nama_motif).get_empty($k->nama_kualitas).get_empty($k->kualitas_dudul).get_empty($k->nama_kualitas_periksa).get_empty($k->nama_label).get_empty($k->nama_cap).get_empty($k->nama_kemasan).get_empty($k->nama_kemasansatuan).get_empty($k->nama_kemasansepuluh).get_empty($k->nama_kemasanseratus);
                        $sum_terima += $k->a_masuk;
                        $sum_keluar += $k->a_keluar;
                        $sum_awal += $k->a_saldo_awal;
                        $akhir = ($k->a_masuk+$k->a_saldo_awal)-$k->a_keluar;
                        $sum_akhir += $akhir;
                        $this->Row(array($k->kode_barang, $nama_barang, format_angka($k->a_saldo_awal), format_angka($k->a_masuk), format_angka($k->a_keluar), format_angka($sum_akhir)));    
                        }                    
                        
                }else{
                    $this->Row(array("", "", "", "", "", ""));
                }                       
                

                $this->setFont('Arial','B',8);
                $this->SetWidths(array(90, 25, 25, 25,25));
                $this->SetAligns(array('L', "R", "R", "R", "R"));
                $this->Row(array("Jumlah Keseluruhan", format_angka($sum_awal), format_angka($sum_terima), format_angka($sum_keluar),format_angka($sum_akhir)));
                $this->Ln();

                $this->Ln();

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


        $x = $this->getX();
        $y = $this->getY();
        $this->setFillColor(0,0,0);
        $this->setTextColor(255,255,255);
        $this->setX($x+90);
        $this->cell(50, 5, "Mengetahui", 1, 0, 'C', 1);

        $this->Ln();
        $this->setX(100);
        $this->setFillColor(255,255,255);
        $this->setTextColor(0,0,0);
        $this->MultiCell(50, 5, "", "LBR", "FJ");

        $this->setY($y+0);
        $this->setFillColor(0,0,0);
        $this->setTextColor(255,255,255);
        $this->setX($x+140);
        $this->cell(50, 5, "Bag. Gudang", 1, 0, 'C', 1);

        $this->Ln();
        $this->setX(150);
        $this->setFillColor(255,255,255);
        $this->setTextColor(0,0,0);
        $this->MultiCell(50, 5, "", "LBR", "FJ");

        
	}
	
	function Footer()
	{
        if($this->isFinished){
        
    }
	}	
	
}
$Pdf = new Pdf();
$Pdf->isFinished = true;
$Pdf->judul = $data['header'];
$Pdf->sub_header = $data['sub_header'];
$Pdf->tanggal = $data['tanggal'];
/*$Pdf->detail = $data['detail2'];
$Pdf->awal = $data['awal'];*/
$Pdf->detail2 = $data['detail3'];
$Pdf->SetAutoPageBreak(true ,15);

$Pdf->SetMargins(10,10,10);
$Pdf->AliasNbPages();
$Pdf->AddPage();
$Pdf->SetFont('Arial','',12);
$Pdf->Content();
$Pdf->SetTitle("Laporan Hasil ");
$Pdf->Output("Laporan Hasil.pdf", "I");

?>