 <?php
class Pdf extends PDF_MC_Table{
	//Page header
	
    public $height_p = 210;
    public $width_p = 330;
    public $head = 0;
	function __construct() {
		//set Page 
		parent::__construct('P','mm',array($this->height_p , $this->width_p));
		
    }
	function Header(){
        
		if($this->PageNo() != 0){		
                $this->setFont('Arial','B',14);
                $this->setFillColor(255,255,255);

                $pro = '';

                if($this->header['nama_proses'] != ''){
                    $pro = "- ".$this->header['nama_proses'];
                }
                
                $this->cell(0,7,'Laporan Bon Bahan '.$pro,0,0,'L',1);
                $this->Ln(10);
                $this->setFont('Arial','',11);
                
                $pem = '';

                if($this->header['nama_pegawai'] != ''){
                    $pem = $this->header['nama_pegawai'];
                }else if($this->header['nama_rekanan'] != '' || $this->header['nama_kelompok'] != ''){
                    $arr_pemroses[] = $this->header['nama_rekanan'];
                    $arr_pemroses[] = $this->header['nama_kelompok'];

                    $pem = get_stripe($arr_pemroses);
                }else if($this->header['mesin'] != ''){
                    $pem = $this->header['mesin'];
                }

                $this->SetWidths(array($this->width_p*5/100, $this->width_p*2/100, $this->width_p*30/100, $this->width_p*10/100, $this->width_p*13.5/100));
                $this->SetAligns(array("L", "L", "L", "L", "R"));
                $this->Row_noborder(array("Periode", ":", $this->header['tanggal_range'], '', $pem));
                $this->Row_noborder(array("Lokasi", ":", $this->header['nama_lokasi'], '', ''));
                



                $this->Ln();
                $this->setFont('arial','B', 10);

                $this->SetWidths(array($this->width_p*5/100, $this->width_p*10/100, $this->width_p*9/100, $this->width_p*27/100, $this->width_p*10/100));
                $this->SetAligns(array('C', 'C', 'C', 'C', 'C'));
                $this->Row(array("No", "Tanggal", "Nomor Laporan", "Nama Barang", "Qty"), 7);

                if($this->head == 0){
                    $this->setFont('arial', '', 8);
                    $this->SetWidths(array($this->width_p*5/100, $this->width_p*10/100, $this->width_p*9/100, $this->width_p*27/100, $this->width_p*10/100));
                    $this->SetAligns(array('C', 'C', 'C', 'L', 'R'));
                }else if($this->head == 1){
                    $this->setFont('arial', 'B', 9);
                    $this->SetWidths(array($this->width_p*51/100, $this->width_p*10/100));
                    $this->SetAligns(array('C', 'R'));
                }else{
                    
                }
            }
				
	}
	
	function Content()
	{   
        $this->setFont('arial', '', 9);
        $this->SetWidths(array($this->width_p*5/100, $this->width_p*10/100, $this->width_p*9/100, $this->width_p*27/100, $this->width_p*10/100));
        $this->SetAligns(array('C', 'C', 'C', 'L', 'R'));
        
    
        $no = 1;
        $arr = array();
        $jum = array();

        if(count($this->hasil) > 0){
            
            foreach($this->hasil as $h){
                if($h->id_sort_detail == 0){
                    $this->head = 0;

                    $proses = ''; $barang = ''; $motif = '';

                    if(in_array($h->id_proses, setup_corak())){
                        if($h->id_proses == '24'){
                            $motif = $h->nama_motif;
                        }else{
                            $motif = $h->nama_corak;
                        }

                        if($motif == ''){
                            $barang = $h->nama_barang;
                        }
                    }else{
                        $barang = $h->nama_barang;
                    }

                    if($h->id_motif != ''){
                        $motif = $h->nama_motif;
                    }else{
                        $motif = $h->nama_corak;
                    }

                    if($this->header['id_proses'] == ''){
                        $proses = $h->nama_proses;
                    }

                //    $nama_barang = get_stripe([get_empty($proses), get_empty($barang), get_empty($motif)]).get_stripe([get_empty($h->inisial_warna), ($h->id_workorder_barang == '') ? "":$h->no_workorder_barang, ($h->id_kualitas == '') ? "":" Tenun ".$h->nama_kualitas, ($h->id_kualitas_dudul == '') ? "":" Dudulan ".$h->kualitas_dudul, ($h->id_label == '') ? "":$h->nama_label, ($h->id_kemasansatuan == '') ? "":$h->nama_kemasansatuan, ($h->id_kemasansepuluh == '') ? "":$h->nama_kemasansepuluh, ($h->id_kemasanseratus == '') ? "":$h->nama_kemasanseratus]);
                    $nama_barang = get_stripe([get_empty($proses), get_empty($barang), get_empty($motif)]).get_stripe([get_empty($h->inisial_warna)]);  
                    $this->setFont('arial', '', 9);
                    $this->SetWidths(array($this->width_p*5/100, $this->width_p*10/100, $this->width_p*9/100, $this->width_p*27/100, $this->width_p*10/100));
                    $this->SetAligns(array('C', 'C', 'C', 'L', 'R'));

                    $this->Row_bawahputus2(array($no, tgl_full($h->tanggal, ''), $h->noAuto.$h->noAuto_ext, $nama_barang, format_angkav2($h->jum_barang)." ".$h->inisial_satuan));
                    $no++;
                }else if($h->id_sort_detail == 1){
                    $this->head = 1;
                
                    $this->setFont('arial', 'B', 9);
                    $this->SetWidths(array($this->width_p*51/100, $this->width_p*10/100));
                    $this->SetAligns(array('C', 'R'));

                    $this->Row(array(" S u b  T o t a l", format_angkav2($h->jum_barang).get_empty($h->inisial_satuan)), 7);

                    if(isset($jum[$h->id_satuan])){
                        $jum[$h->id_satuan] = ['nama_satuan' => $h->inisial_satuan, 'jumlah' => $jum[$h->id_satuan]['jumlah']+$h->jum_barang];
                    }else{
                        $jum[$h->id_satuan] = ['nama_satuan' => $h->inisial_satuan, 'jumlah' => $h->jum_barang];
                    }
                }
            }
            $this->head = 1;
                
            $this->setFont('arial', 'B', 9);
            $this->SetWidths(array($this->width_p*51/100, $this->width_p*10/100));
            $this->SetAligns(array('C', 'R'));
            foreach($jum as $j){
                $this->Row(array("T o t a l", format_angkav2($j['jumlah']).get_empty($j['nama_satuan'])), 7);   
            }
            //$this->Row(array(" S u b  T o t a l", format_angkav2($h->jumlah).get_empty($h->inisial_satuan)), 7);
        }else{
            $this->Row(array("", "", "", "", ""));
        }

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

    
	}
	
	function Footer()
	{
        $this->Ln();
        $this->SetY(-15);
        $this->SetFont('Arial','',9);
        $this->Cell(0,10, "Dicetak tanggal : ".tgl_full(date("d-m-Y"), 6),0,0,'L');
        
		$this->Ln();
        $this->SetY(-15);
        $this->SetFont('Arial','',9);
        $this->Cell(0,10, $this->PageNo(),0,0,'C');
	}
	
}
$Pdf = new Pdf();
$Pdf->header=$data['induk'];
$Pdf->hasil=$data['detail'];


$Pdf->SetMargins(5,5,5);
$Pdf->AliasNbPages();
$Pdf->AddPage();
$Pdf->SetFont('Arial','',12);
$Pdf->Content();
$Pdf->SetTitle("Laporan Detail Bon Bahan Produksi - ".$data['induk']['nama_proses']."_".$data['induk']['tanggal_range']);
$Pdf->Output("Laporan Detail Bon Bahan Produksi - ".$data['induk']['nama_proses']."_".$data['induk']['tanggal_range']." .pdf", "I");

?>