 <?php
class Pdf extends PDF_MC_Table{
	
	function __construct() {
		
		parent::__construct('P','mm',array(210 ,330 ));
    }
	function Header(){
        
		if($this->PageNo() == 1){		
            $spacing = 5;
            $kolom_1 = 40;
            $kolom_2 = 5;
            $kolom_3 = 40;
            $ln = 3;

            $indent_1 = $kolom_1+$kolom_2+$kolom_3+20;

                $this->setFont('Arial','B',14);
                $this->setFillColor(255,255,255);
                $this->setTextColor(0,0,0);
                
                $this->cell(0, 5, "Laporan Hasil - ".$this->data->nama_proses, 0, 0, "C");
                $this->Ln(10);

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

                $text_pemroses = ''; $isi_pemroses = '';
                $text_kelompok = ''; $isi_kelompok = '';
                if($this->data->id_rekanan != 0){
                    $text_pemroses = "Rekanan";
                    $isi_pemroses = $this->data->nama_kelompok;
                    $text_kelompok = "Pemroses";
                    $isi_kelompok = ($this->data->nama_pegawai != '') ? $this->data->nama_pegawai:$this->data->nama_rekanan;
                }else{
                    $text_pemroses = "Pemroses";
                    $isi_pemroses = ($this->data->nama_pegawai != '') ? $this->data->nama_pegawai:$this->data->nama_rekanan;
                }

                $this->setX($indent_1);
                $this->cell($kolom_1, $spacing, $text_pemroses, 0, 0, "L");
                $this->cell($kolom_2, $spacing, ":", 0, 0, "C");
                $this->MultiCell($kolom_3, $spacing, $isi_pemroses, "FJ");

                $this->Ln($ln);
                $this->SetY($y);
                $this->cell($kolom_1, $spacing, "Tanggal Pengambilan", 0, 0, "L");
                $this->cell($kolom_2, $spacing, ":", 0, 0, "C");
                $this->MultiCell($kolom_3, $spacing, tgl_full($this->data->tanggal, '0'), "FJ");

                $this->Ln($ln);
                $y = $this->getY();
                $this->cell($kolom_1, $spacing, "Tanggal Perkiraan", 0, 0, "L");
                $this->cell($kolom_2, $spacing, ":", 0, 0, "C");
                $this->MultiCell($kolom_3, $spacing, tgl_full($this->data->tanggal_perkiraan, '0'), "FJ");

                if($this->data->id_rekanan != 0){
                    $this->setXY($indent_1, $y);
                    $this->cell($kolom_1, $spacing, $text_kelompok, 0, 0, "L");
                    $this->cell($kolom_2, $spacing, ":", 0, 0, "C");
                    $this->MultiCell($kolom_3, $spacing, $isi_kelompok, "FJ");
                }

                $this->Ln($ln);
                $this->cell($kolom_1, $spacing, "Tanggal Selesai", 0, 0, "L");
                $this->cell($kolom_2, $spacing, ":", 0, 0, "C");
                $this->MultiCell($kolom_3, $spacing, tgl_full($this->data->tanggal_selesai, '0'), "FJ");
    
                $this->Ln(10);

                                             

            }
				
	}
	
	function Content()
	{   
        $this->setFont('Arial','B',10);
        $this->cell(0, 5, "Barang Diambil", 0, 0, "L");
        $this->Ln(10);

        $this->setFont('Arial','B',9);
        $this->SetWidths(array(10, 15, 15, 80, 20, 20, 20, 10));
        $this->SetAligns(array('C', 'C', 'C', 'C', 'C'));
        $this->Row(array("No", "Kode", "Order", "Nama Barang", "Gudang", "Jumlah", "Satuan", ""));  

        $this->setFont('Arial','',8);
        $this->SetAligns(array('C', "L", "L", "L", "L", "R", "L", "C"));



        $no = 1;
        $jumlah = array();
        if(count($this->keluar) > 0){
            foreach ($this->keluar 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->kode_barang, $k->no_workorder_barang, $nama_barang, $k->nama_gudang, 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(140, 20, 20, 10));
            $this->SetAligns(array('R', 'R', 'L', 'L'));
            $this->Row(array("Total", format_angka($j['jumlah']), $j['nama_satuan'], ''));        
        }


        $this->Ln(5);
        $this->setFont('Arial','B',10);
        $this->cell(0, 5, "Barang Disetor", 0, 0, "L");

        $this->Ln(10);
        $this->setFont('arial','B',9);
        $this->SetWidths(array(10, 15, 15, 80, 20, 20, 20, 10));
        $this->SetAligns(array('C', 'C', 'C', 'C', 'C'));
        $this->Row(array("No", "Kode", "Order", "Nama Barang", "Gudang", "Jumlah", "Satuan", ""));  

        $this->setFont('Arial','',8);
        $this->SetAligns(array('C', "L", "L", "L", "L", "R", "L", "C"));

        $no = 1;
        $jumlah = array();
        if(count($this->detail) > 0){
            foreach ($this->detail as $k) {
            
                $nama_barang = get_stripe([get_empty($k->nama_barang), get_empty($k->nama_motif)]);
                $this->Row(array($no, $k->kode_barang, $k->no_workorder_barang, $nama_barang, $k->nama_gudang, 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(140, 20, 20, 10));
            $this->SetAligns(array('R', 'R', 'L', 'L'));
            $this->Row(array("Total", format_angka($j['jumlah']), $j['nama_satuan'], ''));    
        }

        if(count($this->sisa) > 0){
            $this->Ln(5);
            $this->setFont('Arial','B',10);
            $this->cell(0, 5, "Barang Belum Disetor", 0, 0, "L");

            $this->Ln(10);
            $this->setFont('arial','B',9);
            $this->SetWidths(array(10, 15, 15, 80, 20, 20, 20, 10));
            $this->SetAligns(array('C', 'C', 'C', 'C', 'C'));
            $this->Row(array("No", "Kode", "Order", "Nama Barang", "Gudang", "Jumlah", "Satuan", ""));  

            $this->setFont('Arial','',8);
            $this->SetAligns(array('C', "L", "L", "L", "L", "R", "L", "C"));

            $no = 1;
            $jumlah_sisa = array();
            if(count($this->sisa) > 0){
                foreach ($this->sisa as $k) {
                
                    $nama_barang = get_stripe([get_empty($k->nama_barang), get_empty($k->nama_motif)]);
                    $this->Row(array($no, $k->kode_barang, "", $nama_barang, "", format_angka($k->stok), $k->nama_satuan, ""));

                    $no++;

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

            foreach($jumlah_sisa as $j){
                $this->SetWidths(array(140, 20, 20, 10));
                $this->SetAligns(array('R', 'R', 'L', 'L'));
                $this->Row(array("Total", format_angka($j['jumlah']), $j['nama_satuan'], ''));    
            }
        }

        $this->Ln();
        $this->setX(330*30/100);
        $this->cell(51, 5, "Mengetahui", "TLR", 0, "C");
        $this->cell(50, 5, "Penerima", "TLR", 1, "C");

        $this->setX(330*30/100);
        $this->cell(51, 15, "", "BLR", 0, "C");
        $this->cell(50, 15, "", "BLR", 1, "C");
	}
	
	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->keluar=$data['keluar'];
$Pdf->sisa=$data['sisa'];
$Pdf->SetAutoPageBreak(true ,15);

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


?>