<?php
class Pdf extends FPDF{
	//Page header
	//public $kas_masuk,$tgl1,$tgl2;
	function __construct() {
		//set Page 
		parent::__construct('L','mm',array(215 ,148 ));
		/*$this->AddFont("tahoma","","tahoma.php");
		$this->AddFont("tahoma","B","tahomabd.php");*/
    }
	function Header(){
        /*if($this->PageNo() == 1){
				$this->setFont('arial','',12);
                $this->setFillColor(255,255,255);
				
                $this->setFont('arial','B',12);
                $this->setFillColor(255,255,255);
                $this->cell(125,7,'Wijoyo',0,0,'L',1);
				$this->cell(156,7,'Laporan Kas / Bank Masuk',0,1,'R',1);
				
				$this->setFont('Arial','B',10);
                $this->setFillColor(255,255,255);
                $this->cell(125,4,'',0,0,'L',1);
				$this->setFont('Arial','',10);
                $this->setFillColor(255,255,255);
                $this->cell(156,4,"Tanggal : ",0,1,'R',1);
				
				$this->setFont('Arial','B',10);
                $this->setFillColor(255,255,255);
                $this->cell(100,4,'',0,1,'L',1);
				$this->Ln(5);
        }   
				$this->setFont('Arial','B',9);
				$this->multicell(10,14,'No.',1,0,'C',1);
				$this->SetXY($this->GetX()+10,$this->GetY()-14);
				$this->cell(18,14,'Tanggal',1,0,'C',1);
				$this->cell(25,14,'No. Transaksi',1,0,'C',1);
				$this->cell(60,14,'Kas / Bank',1,0,'C',1);
				$this->cell(168,7,'Rincian Pemasukan',1,1,'C',1);
				$this->SetX($this->GetX()+113);
				$this->cell(65,7,'Nama Perkiraan',1,0,'C',1);
				$this->cell(73,7,'Keterangan',1,0,'C',1);
				$this->cell(30,7,'Jumlah (Rp)',1,1,'C',1);*/  
		if($this->PageNo() == 1){		
                $this->setFont('Arial','',18);
                $this->setFillColor(255,255,255);
                $this->cell(60,7,'',0,0,'L',1);
                $this->cell(100,7,'Bukti Pengeluaran Barang',0,0,'L',1);
                $this->setX($this->GetX());
                $this->Ln();
                $this->line(14,$this->GetY(),205,$this->GetY());
                $this->Ln();
                $this->setY($this->GetY()-2);
                $this->setX($this->GetX()+40);
                $this->setFont('Arial','',9);
                $this->setFillColor(255,255,255);
                $this->cell(100,5,'',0,0,'L',1);
                $this->cell(23,5,'NO.',0,0,'L',1);
                $this->cell(2,5,':',0,0,'L',1);
                $this->cell(2,5,'0',0,0,'L',1);
                $this->Ln();
                $this->setX($this->GetX()+3);
                $this->Cell(10,5,'Untuk',0,0,'L',1);
                $this->Cell(2,5,':',0,0,'L',1);
                $this->Cell(125,5,$this->data->nama_gudang_tujuan,0,0,'L',1);
                /*$this->setX($this->GetX()+105);*/
                $this->Cell(23,5,'Gudang',0,0,'L',1);
                $this->cell(2,5,':',0,0,'L',1);
                $this->cell(2,5,$this->data->nama_gudang_awal,0,0,'L',1);

                $this->Ln();
                $this->Ln();
                $this->setX($this->GetX()+3);
                $this->Cell(10,5,'Kami kirimkan barang - barang tersebut dibawah ini dengan kendaraan ................. No. .................',0,0,'L',1);
                $this->Ln();

                $this->setXY($this->GetX()+4,$this->GetY()+5);
                $this->setFont('arial','B',9);
                $this->cell(60,7,'Banyaknya',1,0,'C',false);
                $this->cell(130,7,'Nama Barang',1,1,'C',false);
                
            }
				
	}
	
	function Content()
	{
                foreach($this->detail as $key => $row){
	           	$this->setX($this->GetX()+4);
                $this->cell(60,7,$row->jumlah,1,0,'C',false);
                $this->cell(130,7,$row->kode_barang.' - '.$row->nama_barang,1,1,'L',false);
                }
                $this->setX($this->GetX()+4);
                $this->cell(60,7,'',1,0,'C',false);
                $this->cell(130,7,'',1,1,'C',false);
                $this->setX($this->GetX()+4);
                $this->cell(60,7,'',1,0,'C',false);
                $this->cell(130,7,'',1,1,'C',false);
                $this->setX($this->GetX()+4);
                $this->cell(60,7,'',1,0,'C',false);
                $this->cell(130,7,'',1,1,'C',false);
                $this->setX($this->GetX()+4);
                $this->cell(60,7,'',1,0,'C',false);
                $this->cell(130,7,'',1,1,'C',false);
                $this->setX($this->GetX()+4);
                $this->cell(60,7,'',1,0,'C',false);
                $this->cell(130,7,'',1,1,'C',false);
                $this->setX($this->GetX()+4);
                $this->cell(60,7,'',1,0,'C',false);
                $this->cell(130,7,'',1,1,'C',false);	

                $this->Ln();
	}
	
	function Footer()
	{
		/*$jumlah=0;
			foreach($this->kas_keluar as $key => $kas){
				$jumlah += $kas['jumlah'];
			}*/
		$this->setFont('arial','B',9);
        $this->setFillColor(255,255,255);
		$this->setXY($this->GetX()+130,$this->GetY()-2);
		$this->cell(27.5,6,"Gresik, ".date_format(date_create($this->data->tanggal),'d M Y'),0,0,'C',1);
        $this->Ln();
		$this->setXY($this->GetX()+4,$this->GetY()+2);
		$this->cell(40,18,"Terbilang :",1,0,'C',1);
		$this->cell(10,18,"",0,0,'L',1);
        $this->cell(40,18,"Terbilang :",1,0,'C',1);
        $this->cell(10,18,"",0,0,'L',1);
        $this->cell(40,18,"Terbilang :",1,0,'C',1);
        $this->cell(10,18,"",0,0,'L',1);
        $this->cell(40,18,"Terbilang :",1,1,'C',1);
        $this->cell(10,18,"",0,0,'L',1);
		
		
		
		$this->SetY(-15);
		//buat garis horizontal
		
		//Arial italic 9
		$this->SetFont('Arial','B',9);
        $this->Cell(0,10,'',0,0,'L');
		//nomor halaman
		//$this->SetFont('tahoma','',9);
		//$this->Cell(0,10,'Halaman '.$this->PageNo().' dari {nb}',0,0,'R');
	}
	function MultiCells($w, $h, $txt, $border=0, $ln=0, $align='J', $fill=false)
{
    // Custom Tomaz Ahlin
    if($ln == 0) {
        $current_y = $this->GetY();
        $current_x = $this->GetX();
    }

    // Output text with automatic or explicit line breaks
    $cw = &$this->CurrentFont['cw'];
    if($w==0)
        $w = $this->w-$this->rMargin-$this->x;
    $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize;
    $s = str_replace("\r",'',$txt);
    $nb = strlen($s);
    if($nb>0 && $s[$nb-1]=="\n")
        $nb--;
    $b = 0;
    if($border)
    {
        if($border==1)
        {
            $border = 'LTRB';
            $b = 'LRT';
            $b2 = 'LR';
        }
        else
        {
            $b2 = '';
            if(strpos($border,'L')!==false)
                $b2 .= 'L';
            if(strpos($border,'R')!==false)
                $b2 .= 'R';
            $b = (strpos($border,'T')!==false) ? $b2.'T' : $b2;
        }
    }
    $sep = -1;
    $i = 0;
    $j = 0;
    $l = 0;
    $ns = 0;
    $nl = 1;
    while($i<$nb)
    {
        // Get next character
        $c = $s[$i];
        if($c=="\n")
        {
            // Explicit line break
            if($this->ws>0)
            {
                $this->ws = 0;
                $this->_out('0 Tw');
            }
            $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);
            $i++;
            $sep = -1;
            $j = $i;
            $l = 0;
            $ns = 0;
            $nl++;
            if($border && $nl==2)
                $b = $b2;
            continue;
        }
        if($c==' ')
        {
            $sep = $i;
            $ls = $l;
            $ns++;
        }
        $l += $cw[$c];
        if($l>$wmax)
        {
            // Automatic line break
            if($sep==-1)
            {
                if($i==$j)
                    $i++;
                if($this->ws>0)
                {
                    $this->ws = 0;
                    $this->_out('0 Tw');
                }
                $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);
            }
            else
            {
                if($align=='J')
                {
                    $this->ws = ($ns>1) ?     ($wmax-$ls)/1000*$this->FontSize/($ns-1) : 0;
                    $this->_out(sprintf('%.3F Tw',$this->ws*$this->k));
                }
                $this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill);
                $i = $sep+1;
            }
            $sep = -1;
            $j = $i;
            $l = 0;
            $ns = 0;
            $nl++;
            if($border && $nl==2)
                $b = $b2;
        }
        else
            $i++;
    }
    // Last chunk
    if($this->ws>0)
    {
        $this->ws = 0;
        $this->_out('0 Tw');
    }
    if($border && strpos($border,'B')!==false)
        $b .= 'B';
    $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);
    $this->x = $this->lMargin;

    // Custom Tomaz Ahlin
    if($ln == 0) {
        $this->SetXY($current_x + $w, $current_y);
    }
}
}
$Pdf = new Pdf();
$Pdf->data=$data['data'];
$Pdf->detail=$data['detail'];
$Pdf->SetAutoPageBreak(true ,15);

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


?>