 <?php
class Pdf extends PDF_MC_Table{
	//Page header
	//public $kas_masuk,$tgl1,$tgl2;
	function __construct() {
		//set Page 
		parent::__construct('P','mm',array(110 , 150 ));
		
    }
	function Header(){
        
		if($this->PageNo() == 1){		
                $this->setFont('Arial','B',9);
                $this->setFillColor(255,255,255);
                
                $this->SetWidths(array(54, 18, 30));
                $this->SetAligns(array("L", "L", "L"));
                $this->Row_noborder(array("BON BAHAN ".strtoupper($this->data->nama_proses), "Tanggal ", ": ".tgl_full($this->data->tanggal, '')));

                $p = '';
                $p = ($this->data->id_pegawai != 0) ? $this->data->nama_pegawai:$this->data->nama_rekanan;
                $text_nomor = ''; $isi_nomor = '';
                $this->SetWidths(array(16, 38, 18, 30));
                $this->SetAligns(array("L", "L", "L"));
                if($this->data->id_rekanan != 0){
                    $this->Row_noborder(array("Rekanan ", ": ".$this->data->nama_kelompok, "Nomor ", ": ".$this->data->noAuto.$this->data->noAuto_ext));
                }else{
                    $text_nomor = "Nomor ";
                    $isi_nomor = ": ".$this->data->noAuto.$this->data->noAuto_ext;
                }
                $this->Row_noborder(array("Nama ", ": ".$p, $text_nomor, $isi_nomor));
            
                
                $this->ln();                                            

            }
				
	}
	
	function Content()
	{        
        $this->setFont('arial','',8);
        $this->SetWidths(array(10, 15, 37, 15, 15, 6));
        $this->SetAligns(array('C', 'C', 'C', 'C', 'C', ''));
        $this->Row(array("NO", "ORDER", "KETERANGAN", "QTY", "SATUAN", ''));  

        $this->SetAligns(array('C', 'L', 'L', 'R', 'L', 'L'));

        $no = 1;
        $jumlah = array();
        if(count($this->detail) > 0){
            foreach ($this->detail as $k) {
            //    $nama_barang = get_empty($k->nama_barang).get_empty($k->inisial_komposisi).get_empty($k->nama_kualitas_proses).get_empty($k->nama_corak).get_empty($k->nama_motif).get_empty($k->nama_kualitas).get_empty($k->kualitas_dudul).get_empty($k->nama_kualitas_periksa).get_empty($k->nama_label).get_empty($k->nama_cap).get_empty($k->nama_kemasan).get_empty($k->nama_kemasansatuan).get_empty($k->nama_kemasansepuluh).get_empty($k->nama_kemasanseratus);

            //    $nama_barang = get_empty($k->nama_barang).get_empty($k->inisial_komposisi).get_stripe([get_empty($k->nama_motif), ($k->nama_kualitas == '') ? "":" Tenun ".get_empty($k->nama_kualitas), ($k->kualitas_dudul == '') ? "":" Dudulan ".get_empty($k->kualitas_dudul)]);
                $nama_barang = get_stripe([get_empty($k->nama_barang), get_empty($k->nama_motif)]);

                $this->Row(array($no, $k->no_workorder_barang, $nama_barang, format_angka($k->jumlah), $k->nama_satuan, ''));

                $no++;

                if(isset($jumlah[$k->id_satuan])){
                    $jumlah[$k->id_satuan] = ['nama_satuan' => $k->nama_satuan, 'jumlah' => $jumlah[$k->id_satuan]['jumlah']+$k->jumlah];
                }else{
                    $jumlah[$k->id_satuan] = ['nama_satuan' => $k->nama_satuan, 'jumlah' => $k->jumlah];
                }
            }
        }else{
            $this->Row(array("", "", "", "", "", ""));
        }

        foreach($jumlah as $j){
            $this->SetWidths(array(62, 15, 15, 6));
            $this->SetAligns(array('R', 'R', 'L', 'L'));
            $this->Row(array("Total", format_angka($j['jumlah']), $j['nama_satuan'], ''));    
        }          


        $this->Ln();

        $this->SetWidths(array(49, 49));
        $this->SetAligns(array('C', 'C'));
        $this->Row(array("Mengetahui", "Penerima"));
        $this->Row(array("\n\n\n", ""));
	}
	
	function Footer()
	{
		$this->Ln();
        $this->SetY(-15);
        $this->SetFont('Arial','',9);
        $this->Cell(0,10, $this->PageNo(),0,0,'C');
	}
	
}
$Pdf = new Pdf();
$Pdf->detail=$data['detail'];
$Pdf->data=$data['data'];
$Pdf->SetAutoPageBreak(true ,15);

$Pdf->SetMargins(5,5,5);
$Pdf->AliasNbPages();
$Pdf->AddPage();
$Pdf->SetFont('Arial','',12);
$Pdf->Content();
$Pdf->SetTitle("Bon Bahan - ".$data['data']->noAuto.$data['data']->noAuto_ext); 
$Pdf->Output("Bon Bahan - ".$data['data']->noAuto.$data['data']->noAuto_ext.".pdf", "I"); 

?>