<?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','B',18);
         $this->Cell(0,10,"Tanda Terima Barang",0,"","C");
         $this->Ln();
         $this->Ln();
         $this->SetFont('Arial','B',9);
         $this->cell(120,5,$this->data->no_faktur,'',"","L");
         $this->cell(35,5,'Diterima dari','','R');
         $this->cell(3,5,':','','R');
         $this->cell(15,5,'ABIDIN','',"","R");
         $this->Ln();
         $this->SetFont('Arial','B',9);
         $this->cell(120,5,date_format(date_create($this->data->tanggal),'d-M-Y'),'',"","L");
         $this->cell(35,5,'No. Kendaraan','','R');
         $this->cell(3,5,':','','R');
         $this->cell(15,5,'','',"","R");
         $this->Ln();
         $this->SetFont('Arial','B',9);
         $this->cell(120,5,'','',"","L");
         $this->cell(35,5,'Nama Supir','','R');
         $this->cell(3,5,':','','R');
         $this->cell(15,5,'Pak Awi','',"","R");
         $this->Ln();
         $this->Ln();
         $this->SetFont('Arial','B',9);
         $this->cell(20,5,'','','');
         $this->cell(120,5,'Kami menyatakan bahwa kami telah menerima sejumlah barang dalam kondisi baik dengan','',"","L");
         $this->Ln();
         $this->SetFont('Arial','B',9);
         $this->cell(10,5,'','','');
         $this->cell(10,5,'deskripsi sebagai berikut  :','','L');
         $this->Ln();
         $this->Ln();
         $this->SetFont('Arial','B',12);
         $this->cell(65,6,"Keterangan",1,"","C");
         $this->cell(30,6,"Satuan",1,"","C");
         $this->cell(45,6,"Jumlah",1,"","C");
         $this->cell(45,6,"Catatan",1,"","C");
         $this->Ln();
         $this->SetFont("Arial","",10);

         foreach($this->detail as $key => $row){
         $this->cell(65,6,$row->kode_barang.' - '.$row->nama_barang,1,0,"L");
         $this->cell(30,6,$row->nama_satuan,1,0,"C");
         $this->cell(45,6,number_format($row->total,0,'.',','),1,0,"R");
         $this->cell(45,6,"Catatan",1,1,"C");
         }
         $this->Ln();
         $this->Ln();
         $this->SetFont("Arial","",10);
         $this->cell(48,24,"",1,"","L");
         $this->cell(47,24,"",1,"","C");
         $this->setXY($this->GetX()-90,$this->GetY());
         $this->cell(35,7,'Oleh :',0,0,'C');
         $this->setXY($this->GetX()-18,$this->GetY());
         $this->cell(80,7,'Diterima Oleh :',0,0,'C');
         $this->setXY($this->GetX()+18,$this->GetY());
         $this->cell(30,7,'PO NO :',0,1,'C');
         $this->cell(119,7,'',0,0,'C');
         $this->cell(30,7,'Tanggal :',0,1,'C');
         $this->Ln();
            }
				
	}
	
	function Content()
	{
                
	}
	
	function Footer()
	{
		/*$jumlah=0;
			foreach($this->kas_keluar as $key => $kas){
				$jumlah += $kas['jumlah'];
			}*/
		
		
		
		
		$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->detail=$data['detail'];
$Pdf->data=$data['data'];
$Pdf->SetAutoPageBreak(true ,15);

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


?>