<?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() != 0){       
                $this->setFont('Arial','B',12);
                $this->setFillColor(255,255,255);
                $this->setTextColor(0,0,0);
                
                $this->cell(100, 5, "Laporan Penjualan Keseluruhan", 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->Ln();

                $this->SetWidths(array(10, 20, 20, 65, 25, 25, 25));
                $this->SetAligns(array("C", "C", "C","C","C", "C", "C"));
                $this->setFont('Arial','B',10);
                $this->Row(array("No", "Tanggal", "No. Faktur", "Barang", "Penjualan", "Diskon", "Piutang"));
                
                $this->setFont('Arial','',9);
                $this->SetAligns(array("C", "L", "L", "L", "R", "R", "R"));

                $total_penjualan = 0;
                $total_diskon = 0;
                $total_piutang = 0;
                if(count($this->data) > 0){
                    $no = 1;
                    foreach($this->data as $d){
                        $penjualan = $d->harga_satuan*$d->jml_barang;
                        $piutang = ($d->harga_satuan*$d->jml_barang)-$d->potongan;
                        $this->Row(array($no, tgl_full($d->tanggal, ''), $d->no_faktur, $d->nama_pelanggan, rupiah($penjualan), rupiah($d->potongan), rupiah($piutang)));
                        $no++;
                        $total_penjualan += $penjualan;
                        $total_diskon += $d->potongan;
                        $total_piutang += $piutang;
                    }
                }
                $this->setFont('Arial','B',9);
                $this->SetWidths(array(115,25,25,25));
                $this->SetAligns(array("R", "R","R","R"));
                $this->Row(array("Total Penjualan", rupiah($total_penjualan),rupiah($total_diskon),rupiah($total_piutang)));

            }
                
    }
    
    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'));

        
    }
    
    function Footer()
    {
        
    }
}
$Pdf = new Pdf();
$Pdf->periode=$data['periode'];
$Pdf->data=$data['data'];

$Pdf->SetAutoPageBreak(true ,15);

$Pdf->SetMargins(10,10,10);
$Pdf->AliasNbPages();
$Pdf->AddPage();
$Pdf->SetFont('Arial','',12);
$Pdf->Content();
$Pdf->SetTitle("Detail Persediaan Keseluruhan periode".$data['periode']);
$Pdf->AutoPrint(false);
$Pdf->Output("Detail Persediaan Keseluruhan periode".$data['periode'].".pdf", "I");

?>