 <?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 Tenun Beam',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 Order", "Nama Barang", "Qty"), 7);

            /*    $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'));*/

                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{
                    $this->setFont('arial', 'B', 9);
                    $this->SetWidths(array($this->width_p*61/100));
                    $this->SetAligns(array('L'));
                }
            }
				
	}
	
	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();

        $id_rekanan = '0';
        $no = 1;
        if(count($this->hasil) > 0){
            foreach($this->hasil as $g => $h){
                if($h->id_sort_detail == 0){

                    if($this->head == 1 || $g == 0){
                        $this->head = 2;
                        $this->setFont('arial', 'B', 9);
                        $this->SetWidths(array($this->width_p*61/100));
                        $this->SetAligns(array('L',));

                        $pekerja = "";
                        if($h->id_kelompok != ''){
                            $pekerja = $h->nama_kelompok;
                        }else if($h->id_mesin != ""){
                            $pekerja = $h->nama_mesin;
                        }

                        $this->Row(array($pekerja), 7);
                    }

                    $this->head = 0;
                    $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->no_workorder_barang, get_stripe([$h->nama_motif, $h->inisial_warna]), 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_bawahputus(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);   
            }
        }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 Bon Bahan Tenun Beam - ".$data['induk']['nama_proses']."_".$data['induk']['tanggal_range']);
$Pdf->Output("Laporan Bon Bahan Tenun Beam - ".$data['induk']['nama_proses']."_".$data['induk']['tanggal_range'].".pdf", "I");

?>