 <?php
class Pdf extends PDF_MC_Table{
	//Page header
	function __construct() {
		//set Page 
		parent::__construct('P','mm',array(210 ,330 ));

        $this->setup_corak = [24, 25, 26, 27, 28, 29, 30, 31, 32, 33];
    }
	function Header(){
        
		if($this->PageNo() == 1){		
                $this->setFont('Courier','B',12);
                $this->setFillColor(255,255,255);
                $this->cell(100,7,'SLIP UPAH BORONGAN (VIA KAS) '.(isset($this->penerima->nama_proses) ? strtoupper($this->penerima->nama_proses):""),0,0,'l',0); //.strtoupper($this->proses)
                $this->setFont('Courier','B',18);

                $this->setX($this->GetX());
                $this->Ln(10);
                $this->setFont('Courier','B',9);
                $this->setFillColor(255,255,255);

                $this->setY($this->GetY()-2);
                
                $this->setFont('Courier','B',12);
                $set_label = 'CV. KETJUBUNG';
                $this->cell(0,5,$set_label,0,0,'L',1);
                $this->Ln();

                $pemroses = '';
                if(isset($this->penerima->id_pegawai)){
                if($this->penerima->id_pegawai != ''){
                    $pemroses = $this->penerima->nama_pegawai;
                }else{
                    $pemroses = $this->penerima->nama_rekanan;
                }
                }
                $this->setFont('Courier','B',9);
                $this->cell(25,5,'Kepada Yth. '.$pemroses,0,0,'L',1);
                $this->setX($this->GetX()+112);
                $this->Ln();
            }
				
	}
	
	function Content()
	{          
        $this->setFont('Courier','B',12);
        $this->setX(90);
        $this->Line(10,$this->getY(),201,$this->getY());
        $this->Ln();

        $this->setFont('Courier','B',9);

        //$this->SetWidths(array(20, 30, 40, 21, 40, 40));
        //$this->SetAligns(array('C', 'C', 'C', 'C', 'C', 'C',));
        //$this->Row(array("No Urut", "Tanggal", "Keterangan","QTY","Satuan Upah","Jumlah" ));

        $this->cell(17, 5, "No Urut", 1, 0,"C");
        $this->cell(23, 5, "Tanggal", 1, 0,"C");
        $this->cell(30, 5, "Nomor", 1, 0,"C");
        $this->cell(50, 5, "Keterangan", 1, 0,"C");
        $this->cell(11, 5, "QTY", 1, 0,"C");
        $this->cell(30, 5, "Satuan Upah", 1, 0,"C");
        $this->cell(30, 5, "Jumlah", 1, 1,"C");

        $this->setFont('Courier','B',9);
        $this->SetWidths(array(17, 23, 30, 50, 11, 30, 30));
        $this->SetAligns(array('C', 'C', 'C', 'L', 'C', 'R', 'R'));
        $nomor = 1;
        $total1 = 0;
        $total2=0;
        if(count($this->data) > 0){
            foreach($this->data as $key => $row){
                $upah_satuan=$row->upah/$row->jumlah;
                    
                $set_total=$row->upah;
                $total1 += $set_total;
                $nama_barang = '';

                $this->Row(array($nomor, tgl_full($row->tanggal_upah, ''), $row->nomor, $row->keterangan, $row->jumlah, rupiah2($upah_satuan,2), rupiah2($set_total,2)));

                
                    $nomor++;
            }
        }
        $this->setX(131);
        $this->cell(35, 5, 'Sub Jumlah', 0, 0, 0);        
        $this->cell(35, 5, rupiah2($total1,2), 0, 0, 0);
        $this->ln();


        $this->SetWidths(array(17, 23, 121, 30));
        $this->SetAligns(array('C', 'C', 'L', 'R'));
        if(count($this->lain2) > 0){
            $this->setFont('Courier','B',9);
            foreach ($this->lain2 as $key => $value) {
                $jum = 0;
                if($value->tipe == "D"){
                    $total2 += $value->jumlah;
                    $jum = $value->jumlah;
                }else{
                    $total2 -= $value->jumlah;
                    $jum = '-'.$value->jumlah;
                }
                $this->Row(array($nomor, tgl_full($value->tanggal_upah, ''), $value->keterangan, rupiah2($jum)));
                $nomor++; 
            }

           
                $this->setX(131);
                $this->cell(35, 5, 'Sub Jumlah', 0, 0, 0);        
                $this->cell(35, 5, rupiah2($total2,2), 0, 0, 0);
                $this->setFont('Courier','B',9);
        } 

        $this->Ln();
        $this->Line(10,$this->getY(),201,$this->getY());
        $this->setY($this->getY()+1);
        $this->setX(131);
        $this->cell(35, 5, 'Total Jumlah', 0, 0, 0);        
        $this->cell(35, 5, rupiah2($total1+$total2 ,2), 0, 0, 0);
        $this->setFont('Courier','B',9);

        $this->setX(10);
        $this->cell(30,5,'Mengetahui', 1, 0, 'C');        
        $this->cell(30,5,'Kasir', 1, 0, 'C');
        $this->cell(30,5,'Penerima', 1, 1, 'C');

        $this->cell(30,15,'', 1, 0, 0);
        $this->cell(30,15,'', 1, 0, 0);
        $this->cell(30,15,'', 1, 0, 0);



        $y = $this->getY();
       

        $x = $this->getX();
        $y = $this->getY();
        
        

        $this->Ln();
        $this->SetXY(150, $y);
       
	}
	
	function Footer()
	{
		$this->Ln();
		
		
		
		$this->SetY(-15);
		//buat garis horizontal
		
		//Arial italic 9
		$this->SetFont('Arial','B',9);
        $this->Cell(0,10,'',0,0,'L');
		//nomor halaman
		//$this->SetFont('tahoma','',9);
		//$this->Cell(0,10,'Halaman '.$this->PageNo().' dari {nb}',0,0,'R');
	}
	function MultiCells($w, $h, $txt, $border=0, $ln=0, $align='J', $fill=false)
    {
        // Custom Tomaz Ahlin
        if($ln == 0) {
            $current_y = $this->GetY();
            $current_x = $this->GetX();
        }

        // Output text with automatic or explicit line breaks
        $cw = &$this->CurrentFont['cw'];
        if($w==0)
            $w = $this->w-$this->rMargin-$this->x;
        $wmax = ($w-2*$this->cMargin)*1000/$this->FontSize;
        $s = str_replace("\r",'',$txt);
        $nb = strlen($s);
        if($nb>0 && $s[$nb-1]=="\n")
            $nb--;
        $b = 0;
        if($border)
        {
            if($border==1)
            {
                $border = 'LTRB';
                $b = 'LRT';
                $b2 = 'LR';
            }
            else
            {
                $b2 = '';
                if(strpos($border,'L')!==false)
                    $b2 .= 'L';
                if(strpos($border,'R')!==false)
                    $b2 .= 'R';
                $b = (strpos($border,'T')!==false) ? $b2.'T' : $b2;
            }
        }
        $sep = -1;
        $i = 0;
        $j = 0;
        $l = 0;
        $ns = 0;
        $nl = 1;
        while($i<$nb)
        {
            // Get next character
            $c = $s[$i];
            if($c=="\n")
            {
                // Explicit line break
                if($this->ws>0)
                {
                    $this->ws = 0;
                    $this->_out('0 Tw');
                }
                $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);
                $i++;
                $sep = -1;
                $j = $i;
                $l = 0;
                $ns = 0;
                $nl++;
                if($border && $nl==2)
                    $b = $b2;
                continue;
            }
            if($c==' ')
            {
                $sep = $i;
                $ls = $l;
                $ns++;
            }
            $l += $cw[$c];
            if($l>$wmax)
            {
                // Automatic line break
                if($sep==-1)
                {
                    if($i==$j)
                        $i++;
                    if($this->ws>0)
                    {
                        $this->ws = 0;
                        $this->_out('0 Tw');
                    }
                    $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);
                }
                else
                {
                    if($align=='J')
                    {
                        $this->ws = ($ns>1) ?     ($wmax-$ls)/1000*$this->FontSize/($ns-1) : 0;
                        $this->_out(sprintf('%.3F Tw',$this->ws*$this->k));
                    }
                    $this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill);
                    $i = $sep+1;
                }
                $sep = -1;
                $j = $i;
                $l = 0;
                $ns = 0;
                $nl++;
                if($border && $nl==2)
                    $b = $b2;
            }
            else
                $i++;
        }
        // Last chunk
        if($this->ws>0)
        {
            $this->ws = 0;
            $this->_out('0 Tw');
        }
        if($border && strpos($border,'B')!==false)
            $b .= 'B';
        $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);
        $this->x = $this->lMargin;

        // Custom Tomaz Ahlin
        if($ln == 0) {
            $this->SetXY($current_x + $w, $current_y);
        }
    }
}
$Pdf = new Pdf();
$Pdf->data=$data['detail'];
$Pdf->lain2=$data['lain'];
$Pdf->penerima=$data['parent'];
$Pdf->SetAutoPageBreak(true ,15);

$pemroses = '';
if(isset($data['parent']->id_pegawai)){
    if($data['parent']->id_pegawai != ''){
        $pemroses = $data['parent']->nama_pegawai;
    }else{
        $pemroses = $data['parent']->nama_rekanan;
    }
}

$Pdf->SetMargins(10,10,10);
$Pdf->AliasNbPages();
$Pdf->AddPage();
$Pdf->SetFont('Courier','B',12);
$Pdf->Content();
$Pdf->SetTitle("Upah Borongan _".$pemroses."_".(isset($data['parent']->nama_proses) ? $data['parent']->nama_proses:"")."_".$data['date_range']);
$Pdf->SetAuthor("Aplikasi Ketjubung");
$Pdf->SetSubject('SLIP UPAH BORONGAN (VIA KAS) '.(isset($data['parent']->nama_proses) ? $data['parent']->nama_proses:"")."_".$data['date_range']);
$Pdf->SetKeywords('SLIP UPAH BORONGAN (VIA KAS) '.(isset($data['parent']->nama_proses) ? $data['parent']->nama_proses:"")."_".$data['date_range']);
$Pdf->SetCreator("CV. KETJUBUNG");
$Pdf->AutoPrint(false);
$Pdf->Output("Upah Borongan _".$pemroses.(isset($data['parent']->nama_proses) ? $data['parent']->nama_proses:"")."_".$data['date_range']. ".pdf", "I");


?>