 <?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() == 1){
                $this->setFont('Arial','B',18);
                $this->setFillColor(255,255,255);
                $this->cell(60,7,'',0,0,'L',1);
                $this->cell(100,7, $this->judul,0,0,'L',1);
                $this->setFont('Arial','',18);

                $this->setX($this->GetX());
                // $this->Ln();
                // $this->line(10,$this->GetY(),205,$this->GetY());
                $this->Ln(10);
                $this->setFont('Arial','',9);
                $this->setFillColor(255,255,255);

                $this->setY($this->GetY()-2);
                
                $this->setFont('Arial','B',12);
                $set_label = '';
                $this->cell(0,5,$set_label,0,0,'L',1);
                $this->Ln();

                $this->setFont('Arial','',9);
                $this->cell(20,5,'Penerima ',0,0,'L',1);
                $this->cell(2,5,':',0,0,'L',1);
                $this->cell(2,5, $this->kasbon->nama_penerima,0,0,'L',1);

                $set_xr = $this->GetX();
                $this->setX($set_xr+100);
                $this->cell(23,5,'Nomor',0,0,'L',1);
                $this->cell(2,5,':',0,0,'L',1);
                $this->cell(2,5, $this->kasbon->nomor_transaksi,0,1,'L',1);
                
                // $this->Cell(137,5,'',0,0,'L',1);
                
                $this->setX($set_xr+100);
                $this->Cell(23,5,'Tanggal',0,0,'L',1);
                $this->cell(2,5,':',0,0,'L',1);
                $this->cell(2,5, date_db($this->kasbon->tanggal_transaksi, true),0,1,'L',1);

                $this->Ln();
                
                // $this->Cell(10,5,'Mohon dapat dipenuhi kebutuhan kami atas barang dengan jumlah, kondisi serta spesifikasi sebagai berikut :',0,0,'L',1);
                $this->line($this->getX(), $this->getY(), 200, $this->getY());
                $this->Ln(7);

                                             

            }
				
	}
	
	function Content()
	{
        $this->setFont('Arial','',10);
        $this->setFillColor(255,255,255);

        $this->Cell(30,5,'Jumlah',0,0,'L',1);
        $this->Cell(2,5,':',0,0,'L',1);
        $this->Cell(0,5, "Rp".number_format($this->kasbon->nominal, 2, ',', '.'),0,1,'L',1);

        $this->ln();

        $this->Cell(30,5,'Untuk keperluan',0,0,'L',1);
        $this->Cell(2,5,':',0,0,'L',1);
        $this->MultiCells(0,5, $this->kasbon->keterangan,0,1,'L',1);

        $this->ln();

        $this->Cell(30,5,'Terbilang',0,0,'L',1);
        $this->Cell(2,5,':',0,0,'L',1);
        $this->MultiCells(0,5, terbilang($this->kasbon->nominal),0,1,'L',1);

        $this->ln(10);
        $this->SetWidths(array(47, 47, 47, 47));
        $this->SetAligns(array('C', 'C', 'C', 'C'));
        $this->Row(array("Mengetahui", "Menyetujui", "Kasir", "Penerima"));
        /* paraf */
        $this->SetWidths(array(47, 47, 47, 47));
        $this->SetAligns(array('C', 'C', 'C', 'C'));
        $this->Row(array("", "", "", ""), 20);
	}
	
	function Footer()
	{

	}

	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=$OrderService;
$Pdf->judul=$judul;
$Pdf->kasbon=$kasbon;
$Pdf->SetAutoPageBreak(true ,15);

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

?>