 <?php
class Pdf extends PDF_MC_Table{
	//Page header
	function __construct() {
		//set Page 
		parent::__construct('P','mm',array(210 ,330 ));
    }
	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) '.$this->penerima->nama_proses,0,0,'l',0);
                $this->setFont('Courier','B',18);

                $this->setX($this->GetX());
                // $this->Ln();
                // $this->line(10,$this->GetY(),205,$this->GetY());
                $this->Ln(10);
                $this->setFont('Courier','',9);
                $this->setFillColor(255,255,255);

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

                $this->setFont('Courier','B',9);
                if($this->penerima->id_pegawai==0){
                    $this->cell(25,5,'Kepada Yth. '  .$this->penerima->nama_rekanan ,0,0,'L',1);
                }else{
                    $this->cell(25,5,'Kepada Yth. ' .$this->penerima->nama_pegawai ,0,0,'L',1);
                } 
                $this->setX($this->GetX()+112);
                $this->cell(23,5,'Nomor',0,0,'L',1);
                $this->cell(2,5,':',0,0,'L',1);
                $this->cell(2,5, $this->penerima->nomor,0,0,'L',1); 
                $this->Ln();
                
                $this->Cell(137,5,'',0,0,'L',1);
                
                $this->Cell(23,5,'Tanggal',0,0,'L',1);
                $this->cell(2,5,':',0,0,'L',1);
                $this->cell(2,5, tgl_full($this->penerima->tanggal_bayar, ''),0,0,'L',1);

                $this->Ln();
                $this->Ln();                  

            }
				
	}
	
	function Content()
	{          
        $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->setFont('Courier','B',9);
        $this->SetAligns(array('C', 'C', 'L', 'C', 'R', 'R'));
        $nomor = 1;
        $total1 = 0;
        $total2=0;
        
        foreach($this->data as $key => $row){
            $upah_satuan=$row->upah/$row->jumlah;
            $set_total=$row->upah;
            $total1 += $set_total;
            $this->Row(array($nomor, tgl_full($this->penerima->tanggal_bayar, ''), $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->setFont('Courier','B',9);
        $this->ln();
        
        if(count($this->lain2) > 0){
            foreach ($this->lain2 as $key => $value) {
                $jumlah = 0;
                if($value->tipe == "D"){
                    $jumlah = $value->jumlah;
                    $total2 += $value->jumlah;
                }else{
                    $jumlah = '-'.$value->jumlah;
                    $total2 -= $value->jumlah;
                }
                $this->Row(array($nomor, tgl_full($this->penerima->tanggal_bayar, ''), $value->keterangan, '', '',rupiah2($jumlah,2)));
                $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('Courier','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');
	}
}
$Pdf = new Pdf();
$Pdf->data=$data['detail'];
$Pdf->penerima=$data['parent'];
$Pdf->lain2=$data['lain'];
$Pdf->SetAutoPageBreak(true ,15);

$Pdf->SetMargins(10,10,10);
$Pdf->AliasNbPages();
$Pdf->AddPage();
$Pdf->SetFont('Arial','',12);
$Pdf->Content();
$Pdf->SetTitle("Upah Borongan ".$data['parent']->nomor);
$Pdf->AutoPrint(false);
$Pdf->Output("Upah Borongan ".$data['parent']->nomor.".pdf", "I");


?>