<?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() == 1){		
                $this->setFont('Arial','',10);
                $this->setFillColor(0,0,0);
                $this->setTextColor(255,255,255);
                $x_kanan = 150;

                $this->setX($x_kanan);
                $this->cell(55,5,'KEPADA YTH.', 1, 0,'C', 1);

                $this->Ln();
                $this->setX($x_kanan);
                $this->setFillColor(255,255,255);
                $this->setTextColor(0,0,0);

                $this->setFont('Arial','',10);
                $this->MultiCell(55, 5, $this->jual['nama_pelanggan'], "LRT", "FJ");
                
                $y = $this->getY();

                $this->setX($x_kanan);
                $this->MultiCell(55, 5, $this->jual['alamat_pelanggan'], "LRB", "FJ");

                $this->setFont('Arial','B',16);
                $this->SetY($y);
                $this->cell(20, 5, "NOTA", 0, 0, 'L');

                $this->setFillColor(0,0,0);
                $this->setTextColor(255,255,255);
                $this->setFont('Arial','',10);
                $this->cell(7, 5, "No.", 1, 0, 'L', 1);

                $this->setFillColor(255,255,255);
                $this->setTextColor(0,0,0);
                $this->cell(40, 5, nomor_penjualan($this->jual), 1, 0, 'L');

                $this->Ln(7);
                $this->setFillColor(0,0,0);
                $this->setTextColor(255,255,255);
                $this->setFont('Arial','',10);
                $this->cell(10, 5, "TGL.", 1, 0, 'L', 1);
                
                $this->setFillColor(255,255,255);
                $this->setTextColor(0,0,0);
                $this->cell(57, 5, $this->jual['tgl_faktur'], 1, 0, 'L'); 

                $this->Ln(10);
                $this->setFillColor(0,0,0);
                $this->setTextColor(255,255,255);
                $this->setFont('Arial','',10);
                $this->cell(40, 5, "Banyaknya", 1, 0, 'C', 1);
                $this->cell(80, 5, "NAMA BARANG", 1, 0, 'C', 1);
                $this->cell(37, 5, "Harga @ Rp", 1, 0, 'C', 1);
                $this->cell(37, 5, "Jumlah Rp", 1, 0, 'C', 1);

                $this->Ln(6);
            }
				
	}
	
	function Content()
	{   
        $this->setFont('Arial','',9);
        $this->setFillColor(255,255,255);
        $this->setTextColor(0,0,0);
        $this->SetWidths(array(40, 80, 37, 37));
        $this->SetAligns(array('C', 'L', 'R', 'R'));
        $potongan = 0;
        if(count($this->detail) > 0){
            $no = 1;
            $total = 0;
            foreach($this->detail as $d){
                $total += $d['total'];
                $potongan += $d['potongan'];
                $this->Row(array($d['jumlah_barang'].' '.$d['nama_satuan'], $d['kategori'].' '.$d['sub_kategori'].' '.$d['nama_barang'], rupiah2($d['harga_satuan'], 2), rupiah2($d['total'], 2)));    
                $no++;
            }

            $this->Row(array('', "Diskon Penjualan", "", rupiah2($potongan, 2)));    
        }else{
            $this->Row(array('', '', '', ''));
        }
                

        $y = $this->getY();
        $this->setX(130);
        $this->setFillColor(255,255,255);
        $this->setTextColor(0,0,0);
        $this->cell(37, 10, "Total Rp", 0, 0, 'R');
        $this->MultiCell(37, 10, rupiah2($total-$potongan, 2), "LRB", 'R');

        $this->SetY($y+5);
        $this->cell(40, 5, "Tanda Terima", 0, 0, 'C');

        $x = $this->getX();
        $this->setFillColor(0,0,0);
        $this->setTextColor(255,255,255);
        $this->setX($x+20);
        $this->cell(50, 5, "Perhatian", 1, 0, 'C', 1);

        $this->Ln();
        $this->setX(70);
        $this->setFillColor(255,255,255);
        $this->setTextColor(0,0,0);
        $this->MultiCell(50, 5, "Barang-barang yang sudah dibeli tidak dapat ditukar / dikembalikan kecuali ada perjanjian", "LBR", "FJ");
	}
	
	function Footer()
	{
		
	}
}
$Pdf = new Pdf();
$Pdf->detail=$data['detail'];
$Pdf->jual=$data['jual'];

$Pdf->SetAutoPageBreak(true ,15);

$Pdf->SetMargins(10,10,10);
$Pdf->AliasNbPages();
$Pdf->AddPage();
$Pdf->SetFont('Arial','',12);
$Pdf->Content();
$Pdf->SetTitle("Laporan Penjualan - ".$data['jual']['no_faktur']);
$Pdf->AutoPrint(false);
$Pdf->Output("Laporan Penjualan - ".$data['jual']['no_faktur'], "I");

?>