 <?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',12);
                $this->setFillColor(255,255,255);
                $this->cell(100,7,'Laporan Pembelian / Kelompok Barang',0,0,'l',0);
                $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',9);
                $this->cell(25,5,'Dari Tanggal = '.$this->penerima['tanggal_awal']." s/d ".$this->penerima['tanggal_akhir'],0,0,'L',1);
                $this->setX($this->GetX()+115);
                $this->cell(23,5,"PERSEDIAAN BARANG BAKU",0,0,'L',1);
                $this->cell(2,5,"",0,0,'L',1);
                $this->Ln();
                

                                             

            }
				
	}
	
	function Content()
	{          
        $this->setFont('arial','B',9);

        $this->SetWidths(array(20, 25, 30, 21,15, 40, 40));
        $this->SetAligns(array('C', 'C', 'C', 'C', 'C', 'C', 'C',));
        $this->Row(array("Tanggal", "No LPB", "Nama Barang","Satuan","Qty","Harga Satuan","Jumlah" ));

        $this->setFont('arial','',9);
        $this->SetAligns(array('C', 'L', 'L', 'C', 'C', 'R','R'));
        $nomor = 1;
        foreach($this->data as $key => $row){
            $this->Row(array(tgl_full($row->created_at, ''),$row->kode_barang, 
                $row->nama_barang, $row->nama_satuan, $row->jml_barang,
                rupiah2($row->harga_satuan,2),  rupiah2($row->total,2) 
            ));
            $nomor++;
        }
        
       
	}
	
	function Footer()
	{
		$this->Ln();     
		
		
		
		$this->SetY(-15);
		$this->SetFont('Arial','B',9);
        $this->Cell(0,10,'',0,0,'L');
	}
	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['query'];
$Pdf->penerima=$data['data_tanggal'];
$Pdf->SetAutoPageBreak(true ,15);

$Pdf->SetMargins(10,10,10);
$Pdf->AliasNbPages();
$Pdf->AddPage();
$Pdf->SetFont('Arial','',12);
$Pdf->Content();
$Pdf->SetTitle("Laporan Per Kategori");
$Pdf->Output("Laporan Per Kategori".$data['data_tanggal']['tanggal_awal']." sampai ".$data['data_tanggal']['tanggal_akhir'].".pdf", "I");

?>