<?php
class Pdf extends PDF_MC_Table{
    //Page header
    public $paper_w = 210, $paper_h = 297;
    function __construct() {
        //set Page 
        parent::__construct('L','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('Arial','B',12);
                $this->setFillColor(255,255,255);
                $this->setTextColor(0,0,0);
                
                $this->cell(100, 5, $this->judul, 0, 0, "L");
                $this->Ln();

                $this->setFont('Arial','',10);
                $this->cell(20, 5, "Periode", 0, 0, "L");
                $this->cell(5, 5, ":", 0, 0, "L");
                $this->MultiCell(100, 5, $this->periode, "FJ");

                $this->cell(20, 5, "Pemroses", 0, 0, "L");
                $this->cell(5, 5, ":", 0, 0, "L");
                $this->MultiCell(100, 5, $this->pemroses, "FJ");
                $this->Ln();

                

            }
                
    }
    
    function Content()
    {
        $this->SetWidths(array(
            $this->paper_h*5/100,
            $this->paper_h*20/100,
            $this->paper_h*12/100,
            $this->paper_h*20/100,
            $this->paper_h*15/100,
            $this->paper_h*5/100,
            $this->paper_h*15/100,
                ));
        $this->SetAligns(array("C", "C", "C", "C", "C", "C", "C"));
        $this->setFont('Arial','B',10);
        $this->Row(array("No", "Pemroses", "Proses", "Keterangan", "Upah Satuan", "Qty", "Total"));

        $set_total = 0;
        if(sizeof($this->upah_barang) > 0 ){
            $no = 1;
            $temp_key = "";
            foreach ($this->upah_barang as $key => $value) {
                $set_subtotal = 0;
                foreach ($value as $id => $item) {
                    $set_no = $no;
                    $set_pemroses = ($item->id_rekanan==0 ? $item->nama_pegawai : $item->nama_rekanan);
                    $set_proses = $item->nama_proses;
                    if($temp_key==$key){
                        $set_no = "";
                        $set_pemroses = "";
                        $set_proses = "";
                    }
                    $this->SetAligns(array("C", "L", "L", "L", "R", "R", "R"));
                    $this->setFont('Arial','B',10);
                    $keterangan = $item->kode_barang." ".$item->nama_barang." ".$item->nama_motif." ".$item->motif_keterangan;
                    $this->Row_bawahputus([$set_no, $set_pemroses, $set_proses, $keterangan, rupiah2($item->upah_satuan, 2), $item->jumlah_barang_sum, rupiah2($item->upah_total_sum, 2)]);
                    $set_subtotal += $item->upah_total_sum;
                    $temp_key = $key;
                }

                if(isset($this->upah_lain[$key])){
                    foreach ($this->upah_lain[$key] as $id => $item) {
                        $set_no = "";
                        $set_pemroses = "";
                        $set_proses = "";
                        $this->SetAligns(array("C", "L", "L", "L", "R", "R", "R"));
                        $this->setFont('Arial','B',10);
                        $keterangan = $item->jenis;
                        $this->Row_bawahputus([$set_no, $set_pemroses, $set_proses, $keterangan, rupiah2($item->jumlah, 2), 1, rupiah2($item->jumlah, 2)]);
                        $set_subtotal += $item->jumlah;
                    }

                }
        
                // $this->SetWidths(array(
                //     $this->paper_h*77/100,
                //     $this->paper_h*15/100,
                //         ));
                // $this->SetAligns(array("R", "R"));
                // $this->setFont('Arial','B',10);
                // $this->Row(["Sub Total", rupiah2($set_subtotal, 2)]);
                $set_total += $set_subtotal;
                $no++;
            }
        }
        
            $this->SetWidths(array(
                $this->paper_h*77/100,
                $this->paper_h*15/100,
                    ));
            $this->SetAligns(array("R", "R"));
            $this->setFont('Arial','B',10);
            $this->Row(["Total", rupiah2($set_total, 2)], 5);
        
    }
    
    function Footer()
    {
        $this->SetY(-15);
        $this->SetFont('Arial','',9);
        $this->Cell(0,10, $this->PageNo(),0,0,'C'); 
    }
}
$Pdf = new Pdf();
$Pdf->judul=$judul;
$Pdf->periode=$periode;
$Pdf->pemroses=$pemroses;
$Pdf->upah_barang=$upah_barang;
$Pdf->upah_lain=$upah_lain;

$Pdf->SetAutoPageBreak(true ,15);

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

?>