<?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 ));
		/*$this->AddFont("tahoma","","tahoma.php");
		$this->AddFont("tahoma","B","tahomabd.php");*/
    }
	function Header(){        
		if($this->PageNo() != 0 AND $this->PageNo()==1){	

            $spacing = 5;
            $kolom_1 = 40;
            $kolom_2 = 20;
            $kolom_3 = 5;
            $kolom_4 = 50;
            $ln = 3;

            $kanan_1 = 30;
            $kanan_2 = 5;
            $kanan_3 = 35;
            $x = $kolom_1+15;

                $this->setFont('Arial','B',12);
                $this->setFillColor(255,255,255);
                $this->setTextColor(0,0,0);
                

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

                if(count($this->rekanan_kelompok) > 0){
                $this->MultiCell($kolom_1, $spacing, $this->rekanan_kelompok->nama, 1, "C");
                }else{
                $this->MultiCell($kolom_1, $spacing, $this->masuk->nama_pegawai, 1, "C");
                }
                $this->Ln();
                $this->setFont('Arial','',20);
                $this->MultiCell($kolom_1, 10, $this->masuk->noAuto.$this->masuk->noAuto_ext, 1, "C");

                $this->setFont('Arial','',10);
                $this->setXY($x, $y);

                $this->SetWidths(array($kolom_2, $kolom_3, $kolom_4, $kanan_1, $kanan_2, $kanan_3));
                $this->SetAligns(array('L', "C", "L", "L", "C", "L" ));
                 if($this->masuk->id_pegawai != '0'){
                    $this->Row_noborder(array("Nama", ":", $this->masuk->nama_pegawai, "BNG KTG NO.", ":", $this->masuk_tenun->nama_barang));
                }else if($this->masuk->id_rekanan != '0'){
                    $this->Row_noborder(array("Nama", ":", $this->masuk->nama_rekanan, "BNG KTG NO.", ":", $this->masuk_tenun->nama_barang));
                }else if($this->masuk->id_mesin != '0'){
                    $this->Row_noborder(array("Nama", ":", $this->masuk->nama_rekanan, "BNG KTG NO.", ":", $this->masuk_tenun->nama_barang));
                }

                $this->setX($x);
                $this->SetWidths(array($kolom_2, $kolom_3, $kolom_4+$kanan_1+$kanan_2+$kanan_3));
                $this->SetAligns(array('L', "C", "L"));
                $this->Row_noborder(array("Warna", ":", $this->isi_sekir->nama_komposisi));

                $this->setX($x);
                $this->SetWidths(array($kolom_2, $kolom_3, $kolom_4+$kanan_1+$kanan_2+$kanan_3));
                $this->SetAligns(array('L', "C", "L"));
                $this->Row_noborder(array("Isi", ":", $this->isi_sekir->jumlah_rencana));

                $this->setX($x);
                $this->SetWidths(array($kolom_2, $kolom_3, $kolom_4, $kanan_1, $kanan_2, $kanan_3));
                $this->SetAligns(array('L', "C", "L", "L", "C", "L" ));
                /*if($this->isi_sekir->id_pegawai != 0 || $this->isi_sekir->id_pegawai != ''){
                $this->Row_noborder(array("Disekir", ":", $this->isi_sekir->nama_pegawai." (pegawai)", "Tgl.", ":", tgl_full($this->masuk->tanggal_selesai,'')));
                }else if($this->isi_sekir->id_rekanan != '0' || $this->isi_sekir->id_rekanan != ''){
                $this->Row_noborder(array("Disekir", ":", $this->isi_sekir->nama_rekanan." (rekanan)", "Tgl.", ":", tgl_full($this->masuk->tanggal_selesai,'')));
                }*/
                $this->Row_noborder(array("Disekir", ":", "", "Tgl.", ":", tgl_full($this->masuk->tanggal_selesai,'')));

                $this->setX($x);
                $this->SetWidths(array($kolom_2, $kolom_3, $kolom_4, $kanan_1, $kanan_2, $kanan_3));
                $this->SetAligns(array('L', "C", "L", "L", "C", "L" ));
                $this->Row_noborder(array("Motif", ":", $this->masuk_tenun->nama_motif, "PAT No.", ":", ""));

                $this->Ln();


            }
				
	}
	
	function Content()
	{   
        /*--------------------- Page 1 ---------------------------------*/
        if($this->pageNo()==1){
                $x1 = 10;
                $this->Cell(10, 10, 'No', 1, 0, "C");
               
                $this->Cell(40, 5, 'Terima', 1, 0, "C");
                $this->Cell(40, 5, 'Setor', 1, 0, "C");
                $y = $this->getY()+5;
                
                $this->Cell(15, 10, 'Jml', 1, 0, "C");
                $this->Cell(40, 10, 'Keterangan', 1, 0, "C");
                $this->Cell(10, 10, 'KWT', 1, 0, "C");
                $this->Cell(10, 10, 'L', 1, 0, "C");
                $this->Cell(10, 10, 'TT', 1, 0, "C");
                $this->Cell(10, 10, 'KPR', 1, 0, "C");
                $this->Cell(10, 10, 'PICK', 1, 0, "C");

                $this->setXY($x1+10, $y);
                $this->Cell(20, 5, 'Tgl', 1, 0, "C");
                $this->Cell(20, 5, 'Pakan', 1, 0, "C");

                $this->setXY($x1+50, $y);
                $this->Cell(20, 5, 'Tgl', 1, 0, "C");
                $this->Cell(20, 5, 'Srg', 1, 0, "C");

                $this->Ln();
                $this->setFont('Arial','',8);
                
                $this->SetWidths(array(10, 20, 20, 20, 20, 15, 40, 10, 10, 10, 10, 10));
                $this->SetAligns(array('C', "L", "R", "L", "R", "R", "C", "L", "R", "R", "R", "R" ));
                /*if(count($this->detail_tenun) > count($this->detail_tenun_keluar)){
                $count = count($this->detail_tenun);
                }else{
                $count = count($this->detail_tenun_keluar);
                }
                $jum_row = 24-$count;
                $no = 1;*/

                foreach($this->detail_tenun_keluar as $d){
                    $tenun['tanggal_keluar'][] = $d->tanggal;
                    if($d->nama_satuan == 'Beam'){
                        $tenun['jumlah_keluar'][] = $d->jumlah;
                    }else{
                        $tenun['jumlah_keluar_nonBeam'][] = 88;
                    }
                }
                foreach($this->detail_tenun as $d){
                /*    $tenun['tanggal_masuk'][] = $d->tanggal;
                    $tenun['jumlah_masuk'][] = $d->jumlah;
                    $tenun['keterangan_masuk'][] = $d->keterangan;
                    $tenun['lebar_masuk'][] = $d->lebar;
                    $tenun['pick_masuk'][] = $d->pick;
                    $tenun['kualitas_masuk'][] = $d->nama_kualitas;*/

                    if($d->jumlah > 1){
                        for($a = 1; $a <= $d->jumlah; $a++){
                            $tenun['tanggal_masuk'][] = $d->tanggal;
                            $tenun['jumlah_masuk'][] = 1;
                            $tenun['keterangan_masuk'][] = $d->keterangan;
                            $tenun['lebar_masuk'][] = $d->lebar;
                            $tenun['pick_masuk'][] = $d->pick;
                            $tenun['kualitas_masuk'][] = $d->nama_kualitas;
                        }
                    }else{
                        $tenun['tanggal_masuk'][] = $d->tanggal;
                        $tenun['jumlah_masuk'][] = $d->jumlah;
                        $tenun['keterangan_masuk'][] = $d->keterangan;
                        $tenun['lebar_masuk'][] = $d->lebar;
                        $tenun['pick_masuk'][] = $d->pick;
                        $tenun['kualitas_masuk'][] = $d->nama_kualitas;
                    }
                }

                /*foreach($this->detail_tenun as $d){ 
                    $this->Row(array($no, "", "", $d->tanggal, $d->jumlah, $d->jumlah, $d->keterangan, "", $d->lebar, "", "", $d->pick));
                    $no++;
                    }
                for($i = $no; $i <= 24; $i++){
                    $this->Row(array($i, "", "", "", "", "", "", "", "", "", "", ""));
                }*/
                $jum_pakan = 0;
                $jum_nonBeam = 0;
                for($i = 0; $i <= 23; $i++){
                    $tanggal_keluar = '';
                    $jumlah_keluar = '';
                    $tanggal_masuk = '';
                    $jumlah_masuk = '';
                    $keterangan_masuk = '';
                    $lebar_masuk = '';
                    $pick_masuk = '';
                    $kualitas_masuk = '';
                    $jumlah_nonBeam = '';

                    if(isset($tenun['tanggal_keluar'][$i])){
                        $tanggal_keluar = $tenun['tanggal_keluar'][$i];
                    }
                    if(isset($tenun['jumlah_keluar'][$i])){
                        $jumlah_keluar = $tenun['jumlah_keluar'][$i];
                    }
                    if(isset($tenun['tanggal_masuk'][$i])){
                        $tanggal_masuk = $tenun['tanggal_masuk'][$i];
                    }
                    if(isset($tenun['jumlah_masuk'][$i])){
                        $jumlah_masuk = $tenun['jumlah_masuk'][$i];
                    }
                    if(isset($tenun['keterangan_masuk'][$i])){
                        $keterangan_masuk = $tenun['keterangan_masuk'][$i];
                    }
                    if(isset($tenun['lebar_masuk'][$i])){
                        $lebar_masuk = $tenun['lebar_masuk'][$i];
                    }
                    if(isset($tenun['pick_masuk'][$i])){
                        $pick_masuk = $tenun['pick_masuk'][$i];
                    }
                    if(isset($tenun['kualitas_masuk'][$i])){
                        $kualitas_masuk = $tenun['kualitas_masuk'][$i];
                    }
                    if(isset($tenun['jumlah_keluar_nonBeam'])){
                        $jumlah_nonBeam = $tenun['jumlah_keluar_nonBeam'][$i];
                    }
                    
                    $this->Row(array($i+1, $tanggal_keluar, ($jumlah_keluar=='') ? '':format_angka($jumlah_keluar), $tanggal_masuk, ($jumlah_masuk=='') ? '':format_angka($jumlah_masuk), ($jumlah_masuk=='') ? '':format_angka($jumlah_masuk), $keterangan_masuk, $kualitas_masuk, $lebar_masuk, "", "", $pick_masuk));

                    $jum_pakan += $jumlah_keluar; 
                    $jum_nonBeam += $jumlah_nonBeam;
                }

                $this->Ln();
                $y = $this->getY();
                $this->setFont('Arial','B',12);
                $this->SetWidths(array(50));
                $this->SetAligns(array('C'));
                $this->Row(array("NO. ORDER BOM"));
                $this->Row(array($this->masuk->no_workorder_barang), 20);

                $this->setXY(90, $y);
                $this->Cell(20, 10, 'TGL', 1, 0, "C");
                $this->setFont('Arial','',10);
                for($i = 0; $i < 4; $i++){
                    $this->Cell(20, 5, '', 1, 0, "C");
                }
                $this->Ln();
                $this->setXY(110, $y+5);
                for($i = 0; $i < 4; $i++){
                    $this->Cell(20, 5, '', 1, 0, "C");
                }

                $this->Ln();
                $this->setXY(90, $this->getY());
                $this->SetWidths(array(20, 20, 20, 20, 20));
                $this->SetAligns(array('L', 'L', 'L', 'L', 'L'));
                
                for($i = 0; $i < 4; $i++){
                    $this->setXY(90, $this->getY());
                    $this->Row(array("", "", "", "", ""));
                }


                $this->Ln();
                $this->setFont('Arial','BU',12);
                $y = $this->getY();
                $this->Cell(120, '5', "KET. WARNA BENANG SONGKET", 0, 0, "C");
                
                $this->Ln(10);
                $this->setFont('Arial','',10);
                $this->SetWidths(array(20, 20, 20, 20, 20, 20));
                $this->SetAligns(array('C', 'L', 'L', 'L', 'L', 'L'));
                $this->Row(array("No", "", "", "", "", ""), 10);
                $this->Row(array("Warna", "", "", "", "", ""), 10);

                $this->setFont('Arial','BU',12);
                $this->setXY(150, $y);
                $this->Cell(30, '5', "KET", 0, 0, "C");

                $this->Ln(10);
                $this->setXY(150, $this->getY());
                $this->SetWidths(array(40));
                $this->SetAligns(array('L'));
                $this->Row_noborder(array(""), 10);
        }

        /*---------------------------------- END PAGE 1 --------------------------------*/

        /*---------------------------------- PAGE 2 --------------------------------*/
        $this->AddPage();
        if($this->pageNo()==2){
        $this->setFont('Arial','BU',12);
        $this->setFillColor(255,255,255);
        $this->setTextColor(0,0,0);
        $this->setXY($this->getX(),$this->getY()+60);
        $this->Cell(190,10,'PERSENAN PEROLEHAN SARUNG',0,0,'C');

        $this->Ln();
        $this->setX(35);
        $this->setFont('Arial','BI',12);
        $this->Cell(140,'10',' BAIK = ',1,0,'L');
        $this->setXY(77,$this->GetY());
        $this->Cell(50,'10','X Rp. ',0,0,'L');
        $this->setXY(125,$this->GetY());
        $this->Cell(50,'10','= Rp. ',0,1,'L');

        $this->Ln(5);
        $this->setX(35);
        $this->Cell(140,60,'',1,1,'C');
        $this->SetXY(37,$this->getY()-60);
        $this->setFont('Arial','',12);
        $this->SetWidths(array(20, 5, 30, 5, 35, 5, 20));
        $this->SetAligns(array('L', 'L', 'L', 'L', 'L', 'L','L'));
        $this->Row_noborder(array('Pakan','=',$jum_pakan.' Beam','','','=',''),15);
        $this->SetX(37);
        $this->Row_noborder(array('Ambil','=',$jum_pakan.' Beam','x',$jum_nonBeam,'=',''),5);
        $this->SetX(35);
        $this->SetWidths(array(22, 5, 70, 5, 38));
        $this->Row_atasbawah(array('  Kembali','=','','=',''),6);
        $this->SetX(35);
        $this->Row_noborder(array('','','','',''),3);
        $this->SetX(57);
        $this->SetWidths(array(25, 5, 20,5,20, 5, 38));
        $this->Row_noborder(array('Sisa','','','','','=',''));
        $this->SetX(57);
        $this->Row_atasbawah(array('Jadi Sarung','=','','x','','=',''));
        $this->SetX(77);
        $this->setFont('Arial','',12);
        $this->SetWidths(array(55, 5, 20));
        $this->Row_noborder(array('','',''),10);
        $this->SetX(77);
        $this->Row_noborder(array('Lebih / Kurang','=',''));


        $this->Ln(5);
        $this->SetXY(65,$this->GetY()+20);
        $this->cell(40,20,'',1,0,'C');
        $this->cell(40,20,'',1,0,'C');
        $this->setX(65);
        $this->cell(40,5,'MENGETAHUI',0,0,'C');
        $this->cell(40,5,'MAKELAR',0,0,'C');
        $this->setXY(65,$this->GetY()+15);
        $this->setFont('Arial','BU',10);
        $this->Cell(40,5,'MISMAN',0,0,'C');
        $this->Cell(40,5,'......................',0,0,'C');
        }
        /*---------------------------------- END PAGE 2 --------------------------------*/

        
	}
	
	function Footer()
	{
		
	}
}
$Pdf = new Pdf();
$Pdf->masuk = $data['masuk'];
$Pdf->detail = $data['barang'];
$Pdf->setor = $data['setor'];
$Pdf->isi_sekir = $data['isi_sekir'];
$Pdf->rekanan_kelompok = $data['rekanan_kelompok'];
$Pdf->masuk_tenun = $data['masuk_tenun'];
$Pdf->detail_tenun = $data['barang_tenun'];
$Pdf->detail_tenun_keluar = $data['barang_tenun_keluar'];
$Pdf->SetAutoPageBreak(true ,15);

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

?>