<?php
class Pdf extends PDF_MC_Table{
    //Page header
    public $paper_w = 210, $paper_h = 297;
    function __construct() {
        //set Page 
        parent::__construct('P','mm',array($this->paper_w ,$this->paper_h));
        /*$this->AddFont("tahoma","","tahoma.php");
        $this->AddFont("tahoma","B","tahomabd.php");*/
    }

    function Header(){
        
        if($this->PageNo() != 0){       
                $this->setFont('Courier','B',14);
                $this->setFillColor(255,255,255);
                $this->setTextColor(0,0,0);
                
                $this->cell(190, 5, strtoupper($this->judul), 0, 0, "C");
                $this->Ln(7);

                $this->setFont('Courier','B',11);
                $this->cell(30, 5, "Nama Karyawan", 0, 0, "L");
                $this->cell(5, 5, ":", 0, 0, "L");
                $this->cell(100, 5, $this->upah->nama_pegawai, 0, 0, "L");

                $this->cell(20, 5, "Nomor", 0, 0, "L");
                $this->cell(5, 5, ":", 0, 0, "L");
                $this->cell(30, 5, $this->upah->no_transaksi, 0, 0, "L");
                $this->Ln();

                $this->cell(30, 5, "", 0, 0, "L");
                $this->cell(5, 5, "", 0, 0, "L");
                $this->cell(100, 5, "", 0, 0, "L");

                $this->cell(20, 5, "Tanggal", 0, 0, "L");
                $this->cell(5, 5, ":", 0, 0, "L");
                $this->cell(30, 5, date_db($this->upah->tanggal_transaksi, true), 0, 0, "L");
                $this->Ln(5);
            }
    }
    
    function Content()
    {
        $this->SetWidths(array(
            $this->paper_h*28/100,
            $this->paper_h*10/100,
            $this->paper_h*11/100,
            $this->paper_h*15/100
                ));
        $this->SetAligns(array("C", "C", "C", "C"));
        $this->setFont('Courier','B',11);
        $this->Row(array("Keterangan", "Waktu Kerja", "Tarif Upah", "Jumlah"), 7);

        $this->SetAligns(array("L", "C", "R", "R"));
        $this->setFont('Courier','B',11);

        $tot_upah_perhari = 0;
        $tot_upah_lembur_jam = 0;
        $tot_upah_lembur_hari = 0;
        $tot_um_lembur_jam = 0;
        $tot_um_lembur_hari = 0;
        $tot_um_desa = 0;
        $tot_um_kediri = 0;
        $tot_potongan_keterlambatan = 0;
        $tot_potongan_kas_bon = 0;
        $row = 0;
        if ($this->upah->upah_perhari != 0) {
        	$tot_upah_perhari += (float)$this->upah->upah_perhari*(float)$this->upah->hari_kerja;
        	$this->RowBorderCustom(array(
        	        	strtoupper("UPAH HARIAN ".$this->upah->nama_pegawai),
        	        	number_format($this->upah->hari_kerja, 2),
        	        	rupiah2($this->upah->upah_perhari),
        	        	rupiah2($tot_upah_perhari)
        	        ), 6, "LR");
            $row++;
        }

        if ($this->upah->upah_lembur_jam != 0) {
        	$tot_upah_lembur_jam += (float)$this->upah->upah_lembur_jam*(float)$this->upah->jumlah_jam_lembur;
        	$this->RowBorderCustom(array(
        	        	strtoupper("UPAH LEMBUR (JAM)"),
        	        	number_format($this->upah->jumlah_jam_lembur, 2),
        	        	rupiah2($this->upah->upah_lembur_jam),
        	        	rupiah2($tot_upah_lembur_jam)
        	        ), 6, "LR");
            $row++;
        }

        if ($this->upah->upah_lembur_hari != 0) {
        	$tot_upah_lembur_hari += (float)$this->upah->upah_lembur_hari*(float)$this->upah->jumlah_hari_lembur;
        	$this->RowBorderCustom(array(
        	        	strtoupper("UPAH LEMBUR (HARI)"),
        	        	number_format($this->upah->jumlah_hari_lembur, 2),
        	        	rupiah2($this->upah->upah_lembur_hari),
        	        	rupiah2($tot_upah_lembur_hari)
        	        ), 6, "LR");
            $row++;
        }

        if ($this->upah->um_lembur_jam != 0) {
        	$tot_um_lembur_jam += (float)$this->upah->um_lembur_jam*(float)$this->upah->jumlah_jam_um_lembur;
        	$this->RowBorderCustom(array(
        	        	strtoupper("UM. LEMBUR (JAM)"),
        	        	number_format($this->upah->jumlah_jam_um_lembur, 2),
        	        	rupiah2($this->upah->um_lembur_jam),
        	        	rupiah2($tot_um_lembur_jam)
        	        ), 6, "LR");
            $row++;
        }

        if ($this->upah->um_lembur_hari != 0) {
        	$tot_um_lembur_hari += (float)$this->upah->um_lembur_hari*(float)$this->upah->jumlah_hari_um_lembur;
        	$this->RowBorderCustom(array(
        	        	strtoupper("UM. LEMBUR (HARI)"),
        	        	number_format($this->upah->jumlah_hari_um_lembur, 2),
        	        	rupiah2($this->upah->um_lembur_hari),
        	        	rupiah2($tot_um_lembur_hari)
        	        ), 6, "LR");
            $row++;
        }

        if ($this->upah->um_desa != 0) {
        	$tot_um_desa += (float)$this->upah->um_desa*(float)$this->upah->jumlah_hari_um_desa;
        	$this->RowBorderCustom(array(
        	        	strtoupper("UM. KE DESA"),
        	        	number_format($this->upah->jumlah_hari_um_desa, 2),
        	        	rupiah2($this->upah->um_desa),
        	        	rupiah2($tot_um_desa)
        	        ), 6, "LR");
            $row++;
        }

        if ($this->upah->um_kediri != 0) {
        	$tot_um_kediri += (float)$this->upah->um_kediri*(float)$this->upah->jumlah_hari_um_kediri;
        	$this->RowBorderCustom(array(
        	        	strtoupper("UM. KE KEDIRI"),
        	        	number_format($this->upah->jumlah_hari_um_kediri, 2),
        	        	rupiah2($this->upah->um_kediri),
        	        	rupiah2($tot_um_kediri)
        	        ), 6, "LR");
            $row++;
        }

        if ($this->upah->potongan_keterlambatan != 0) {
        	$tot_potongan_keterlambatan += (float)$this->upah->potongan_keterlambatan*(float)$this->upah->jumlah_jam_keterlambatan;
        	$this->RowBorderCustom(array(
        	        	strtoupper("POT. KETERLAMBATAN"),
        	        	number_format($this->upah->jumlah_jam_keterlambatan, 2),
        	        	rupiah2($this->upah->potongan_keterlambatan),
        	        	"-".rupiah2($tot_potongan_keterlambatan)
        	        ), 6, "LR");
            $row++;
        }

        if ($this->upah->potongan_kas_bon != 0) {
        	$tot_potongan_kas_bon += (float)$this->upah->potongan_kas_bon;
        	$this->RowBorderCustom(array(
        	        	strtoupper("POT. KAS BON"),
        	        	"",
        	        	"",
        	        	"-".rupiah2($tot_potongan_kas_bon)
        	        ), 6, "LR");
            $row++;
        }

        if ($this->upah->pembulatan != 0) {
        	$this->RowBorderCustom(array(
        	        	strtoupper("(PEMBULATAN UPAH)"),
        	        	"",
        	        	"",
        	        	rupiah2($this->upah->pembulatan)
        	        ), 6, "LR");
            $row++;
        }

        if ($row < 4) {
            if ($row == 1) {
                for ($i=1; $i < 3; $i++) { 
                    $this->RowBorderCustom(array(
                        "",
                        "",
                        "",
                        ""
                    ), 6, "LR");
                }
            } else if ($row == 2) {
                for ($i=1; $i < 2; $i++) { 
                    $this->RowBorderCustom(array(
                        "",
                        "",
                        "",
                        ""
                    ), 6, "LR");
                }
            } else if ($row == 3) {
                $this->RowBorderCustom(array(
                        "",
                        "",
                        "",
                        ""
                    ), 6, "LR");
            }
        }

        $this->SetWidths(array(
            $this->paper_h*49/100,
            $this->paper_h*15/100
                ));
        $this->SetAligns(array("R", "R"));
        $this->setFont('Courier','B',11);
        $this->Row(array("Jumlah Pembayaran", rupiah2($this->upah->upah_terima)), 7);

        $this->Ln(2);
        $this->setX(111);

        $getY = $this->getY();

        $this->drawTextBox2("Kasir", $this->paper_h*15/100, 15, "C");

        $this->setY($getY);
        $this->setX(155.4);
        $this->drawTextBox2("Penerima", $this->paper_h*15/100, 15, "C");
    }
    
    function Footer()
    {
        $this->SetY(-15);
        $this->SetFont('Courier','',9);
        // $this->Cell(0,10, $this->PageNo(),0,0,'C'); 
    }
}
$Pdf = new Pdf();
$Pdf->judul=$data['judul'];
$Pdf->upah=$data['upah'];

$Pdf->SetAutoPageBreak(true ,15);

$Pdf->SetMargins(10,10,10);
$Pdf->AliasNbPages();
$Pdf->AddPage();
$Pdf->SetFont('Courier','',12);
$Pdf->Content();
$Pdf->SetTitle($data['judul']);
$Pdf->Output($data['judul']." - ".strtoupper($data['upah']->nama_pegawai).".pdf", "I");

?>