 <?php
class Pdf extends PDF_MC_Table{
    //Page header
    //public $kas_masuk,$tgl1,$tgl2;
    function __construct() {
        //set Page 
        parent::__construct('P','mm',array(210 , 330 ));
        
    }
    function Header(){
        
        if($this->PageNo() != 0){       
                $this->setFont('Arial','B',14);
                $this->setFillColor(255,255,255);
                
                $this->cell(0,7,'MUTASI KARTU STOK',0,0,'C',1);
                $this->Ln(10);
                $this->setFont('Arial','',11);
                
                $this->ln();
                $this->SetWidths(array(30, 5, 60, 30, 5, 60));
                $this->SetAligns(array("L", "L", "L"));
                $barang = "Semua Barang";
                
                if(count($this->induk['barang']) > 0){
                //    $barang = $this->induk['barang']->nama_kategori." - ".$this->induk['barang']->nama_sub." - ".$this->induk['barang']->nama_barang;
                    $barang = $this->induk['barang']->nama_barang;
                }              

                $this->Row_noborder(array("Nama Barang", ": ", $barang, "Nama Proses", ":", ($this->induk['nama_proses'] != '') ? $this->induk['nama_proses']:"Semua Proses")); //

                $tgl = '';
                if($this->induk['tanggal_awal'] != '' && $this->induk['tanggal_akhir'] != ''){
                    $tgl = date_range($this->induk['tanggal_awal'], $this->induk['tanggal_akhir']);
                }

                $this->Row_noborder(array("Periode", ": ", $tgl, "Warna", ":", ($this->induk['nama_komposisi'] != '') ? $this->induk['nama_komposisi']:"Semua Warna"));
                /*$this->Row_noborder(array("Gudang", ": ", ($this->induk['nama_gudang'] != '') ? $this->induk['nama_gudang']:"-", "Lokasi", ":", ($this->induk['nama_lokasi'] != '') ? $this->induk['nama_lokasi']:$this->induk['lokasi_gudang']));*/
                $this->Row_noborder(array("Motif", ": ", ($this->induk['nama_motif'] != '') ? $this->induk['nama_motif']:"-", "Lokasi", ":", ($this->induk['nama_lokasi'] != '') ? $this->induk['nama_lokasi']:$this->induk['lokasi_gudang']));
                $arr_pemroses = array();
                $pemroses = '';
                if($this->induk['kelompok'] != ''){
                    $arr_pemroses[] = $this->induk['kelompok'];
                    $arr_pemroses[] = $this->induk['rekanan'];

                    $pemroses = get_stripe($arr_pemroses);
                }else if($this->induk['mesin'] != ''){
                    $pemroses = $this->induk['mesin'];
                }
                $this->Row_noborder(array("Corak", ": ", ($this->induk['nama_corak'] != '') ? $this->induk['nama_corak']:"-", "Pemroses", ":", $pemroses));



                $this->Ln();
                $this->setFont('arial','B', 8);
                
                $y = $this->getY();
                $this->Cell(10, 7, "NO", 1, 0, "C", 1);
                $this->Cell(80, 7, "KET. BARANG", 1, 0, "C", 1);
                $this->Cell(30, 7, "SISA", 1, 0, "C", 1);
                $this->Cell(30, 7, "BIAYA SATUAN", 1, 0, "C", 1);
                $this->Cell(30, 7, "BIAYA", 1, 0, "C", 1);

                $this->Ln();

                $this->SetWidths(array(10, 80, 30, 30, 30));
                $this->setFont('arial','',8);
                $this->SetAligns(array('C', 'L', 'R', 'R', 'R'));
            }
                
    }
    
    function Content()
    {   
        $this->SetWidths(array(10, 80, 30, 30, 30));
        $this->setFont('arial','',8);
        $this->SetAligns(array('C', 'L', 'R', 'R', 'R'));
        
    
        $no = 1;
        $arr = array();        
        $jumlah = array();
        if(count($this->detail) > 0){
            $key = '';
            
            foreach ($this->detail as $k) {
                $nama_proses = ($this->induk['nama_proses'] != '') ? get_empty($k->nama_proses):'';
                $nama_komposisi = ($this->induk['nama_komposisi'] != '') ? '':get_empty($k->inisial_warna);

                $garis = '';
                $garis_proses = '';
                if($k->nama_corak != '' || $nama_komposisi){
                    $garis = " -";
                }
                
                $nama_barang = get_stripe([$k->nama_motif, $nama_komposisi, $k->no_workorder_barang]);
                
                if($k->sisa > 0){
                    $this->Row(array($no, $nama_barang, format_angkav2($k->sisa)." ".$k->inisial_satuan, format_angkav2($k->harga_satuan), format_angkav2($k->jumlah_harga) ));
                    $no++;
                    if(isset($jumlah[$k->id_satuan])){
                        $jumlah[$k->id_satuan] = ['nama_satuan' => $k->inisial_satuan, 'sisa' => $jumlah[$k->id_satuan]['sisa']+$k->sisa, "harga" => $jumlah[$k->id_satuan]['harga']+$k->jumlah_harga];
                    }else{
                        $jumlah[$k->id_satuan] = ['nama_satuan' => $k->inisial_satuan, 'sisa' => $k->sisa, 'harga' => $k->jumlah_harga];
                    }
                }

            //    $this->Row(array($no, $nama_barang, $k->awal, $k->masuk, $k->keluar, $k->sisa, $k->nama_satuan ));
            //    $no++; 
            
                  

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

        $jum = array_merge($jumlah, array());
        $jumlah_total = 0;
        if($jumlah > 0){
            //for($i=0; $i<count($jumlah); $i++){
            foreach($jumlah as $j){
                $this->SetWidths(array(120, 30, 30));
                $this->SetAligns(array('R', 'R', 'R'));
                $this->Row(array("TOTAL", format_angkav2($j['sisa'])." ".$j['nama_satuan'], format_angkav2($j['harga'])));
            }
        }else{
            foreach($jumlah as $j){
                $this->SetWidths(array(120, 30, 30));
                $this->SetAligns(array('R', 'R', 'R'));
                $this->Row(array("TOTAL", format_angkav2($j['sisa'])." ".$j['nama_satuan'], ""));    
            }  
        }

        $this->Ln(5);
        $this->setFont('arial','',9);
        $ttd = get_ttdproduksi();
        $p = 210;
        $arr_width = array(); $arr_align = array(); $arr_isi = array(); $arr_ttd = array();
        if(count($ttd) > 0){
            $width = 210/count($ttd);

            for($i = 0; $i < count($ttd); $i++){
                $arr_width[] = $width;
                $arr_align[] = "C";
                $arr_isi[] = $ttd[$i]['nama'];
                $arr_ttd[] = ($ttd[$i]['ttd'] == '') ? "_____________":$ttd[$i]['ttd'];
            }

            $this->SetWidths($arr_width);
            $this->SetAligns($arr_align);
            $this->Row_noborder($arr_isi);
            $this->Ln(15);
            $this->Row_noborder($arr_ttd);
        }
        
        $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->induk=$data['induk'];
$Pdf->detail=$data['detail'];
$Pdf->SetAutoPageBreak(true ,15);
$barang = 'Semua Barang';

if($data['induk']['barang'] != false){
    $barang = $data['induk']['barang']->nama_barang;
}

$Pdf->SetMargins(5,5,5);
$Pdf->AliasNbPages();
$Pdf->AddPage();
$Pdf->SetFont('Arial','',12);
$Pdf->Content();
$Pdf->SetTitle("Mutasi Rekap Dalam Proses Tenun _".$data['induk']['nama_gudang']."_".$barang."_".date_range($data['induk']['tanggal_awal'], $data['induk']['tanggal_akhir']));
$Pdf->Output("Mutasi Rekap Dalam Proses Tenun _".$data['induk']['nama_gudang']."_".$barang."_".date_range($data['induk']['tanggal_awal'], $data['induk']['tanggal_akhir']).".pdf", "I");

?>