 <?php
class Pdf extends PDF_MC_Table{
	
    public $height_p = 140;
    public $width_p = 115;
    public $height = 5;

	function __construct() {
		//set Page 
		parent::__construct('P','mm',array($this->height_p, $this->width_p ));
		/*$this->AddFont("tahoma","","tahoma.php");
		$this->AddFont("tahoma","B","tahomabd.php");*/
    }
	function Header(){
        $this->setFont('Arial','B',10);
        $this->setFillColor(255,255,255);
        
        $this->setFont('Arial','B',12);
        $this->cell(0,$this->height, 'REKAP TRANSFER BARANG ANTAR GUDANG',0, 0,'C',1);
        $this->Ln(8);
		
		// $this->setFillColor(255,255,255);

  //       $y = $this->getY();
  //       $this->setFont('Arial','',8);

  //       $this->SetWidths(array($this->width_p*19/100, $this->width_p*2/100, $this->width_p*65/100));
  //       $this->SetAligns(array('L', 'C', 'L'));
  //       $this->Row_noborder(array("Tanggal Masuk", ":", $this->dataHeader->tanggal_awal. " s/d " . $this->dataHeader->tanggal_akhir), 3);
  //       $this->Row_noborder(array("Gudang Asal", ":", $this->dataHeader->gudang_asal), 3);
  //       $this->Row_noborder(array("Gudang Tujuan", ":", $this->dataHeader->gudang_tujuan), 3);

  //       $this->setFont('arial','B',8);
  //       $this->SetWidths(array($this->width_p*7/100, $this->width_p*47/100, $this->width_p*15/100, $this->width_p*15/100));
  //       $this->SetAligns(array('C', 'C', 'C', 'C'));
  //       $this->Row(array("NO", "KETERANGAN", "QTY", "SATUAN"));

  //       if($this->PageNo() != 0) {
  //       	$this->setFont('Arial','',8);
  //       	$this->SetAligns(array('C', "L", "R", "L"));
  //       } 
	}
	
	function Content()
	{        

        $this->setFillColor(255,255,255);

        $y = $this->getY();
        $this->setFont('Arial','',8);

        $this->SetWidths(array($this->width_p*19/100, $this->width_p*2/100, $this->width_p*65/100));
        $this->SetAligns(array('L', 'C', 'L'));
        $this->Row_noborder(array($this->dataHeader->text_tanggal, ":", $this->dataHeader->tanggal_awal. " s/d " . $this->dataHeader->tanggal_akhir), 3);
        $this->Row_noborder(array("Gudang Asal", ":", $this->dataHeader->gudang_asal), 3);
        $this->Row_noborder(array("Gudang Tujuan", ":", $this->dataHeader->gudang_tujuan), 3);

        $this->setFont('arial','B',8);
        $this->SetWidths(array($this->width_p*7/100, $this->width_p*47/100, $this->width_p*15/100, $this->width_p*15/100));
        $this->SetAligns(array('C', 'C', 'C', 'C'));
        $this->Row(array("NO", "KETERANGAN", "QTY", "SATUAN"));  

        $this->setFont('Arial','',8);
        $this->SetAligns(array('C', "L", "R", "L"));
        
        $no = 1;
        $jumlah = 0;
        $satuan = [];
        if(count($this->data) > 0){
            foreach ($this->data as $k) {
                $ket = '';
                if($k->keterangan != ''){
                    $ket = ' - '.$k->keterangan;
                }
                $nama_barang = barang_byproses($k, 3);
            	//$this->Row(array($no, $nama_barang->concat_nama.$ket, format_angkav2($k->jumlah), $k->nama_satuan));
                $this->Row(array($no, $nama_barang->concat_nama, format_angkav2($k->jumlah), $k->nama_satuan));

            	if (!isset($satuan[$k->nama_satuan])) {
            		$satuan[$k->nama_satuan] = 0;
            	}

            	$satuan[$k->nama_satuan] += $k->jumlah;

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

        $this->setFont('arial','B',8);
        $this->SetWidths(array($this->width_p*54/100, $this->width_p*15/100, $this->width_p*15/100));
        $this->SetAligns(array('C', 'R', 'L'));
        foreach ($satuan as $key => $value) {
        	$this->Row(array("JUMLAH ".strtoupper($key), format_angkav2($value), $key));
        }

        $this->Ln(4);
        $y = $this->getY();

        $this->setFont('arial','', 8);
        $this->SetWidths(array($this->width_p*42/100, $this->width_p*42/100));
        $this->SetAligns(array('L', 'L'));
        $this->Row_noborder(array("Diterima oleh,", "Diserahkan oleh,"));

	}
	
	function Footer()
	{
		$this->Ln();
        $this->SetY(-15);
        $this->SetFont('Arial','',8);
        $this->Cell(0,10, $this->PageNo(),0,0,'C');
	}
	
}
$Pdf = new Pdf();
$Pdf->dataHeader=$data['header'];
$Pdf->data=$data['data'];
$Pdf->SetAutoPageBreak(true ,15);

$Pdf->SetMargins(10,5,5);
$Pdf->AliasNbPages();
$Pdf->AddPage();
$Pdf->SetFont('Arial','',12);
$Pdf->Content();
$Pdf->SetTitle("Rekap Transfer Barang Antar Gudang");
$Pdf->Output("Rekap Transfer Barang Antar Gudang.pdf", "I");
?>