<?php
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);    

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Kikin Kusumah');
$pdf->SetTitle($title);
$pdf->SetSubject('');
$pdf->SetKeywords('TCPDF, PDF, Kikinsoft');

// remove default header/footer
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

// set margins
$pdf->SetMargins(10, 15, 10);

// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, 10);

// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
	require_once(dirname(__FILE__).'/lang/eng.php');
	$pdf->setLanguageArray($l);
}

// ---------------------------------------------------------

// set font
$pdf->SetFont('helvetica', '', 8);

// add a page
$pdf->AddPage('P','A4');
//$pdf->Cell(0, 1, 'Nama', 1, 0, 'L','','','','','','T');
// writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=false, $align='')
// writeHTMLCell($w, $h, $x, $y, $html='', $border=0, $ln=0, $fill=0, $reseth=true, $align='', $autopadding=true)
$html="";
// create some HTML content
$html .= 
'
<style type="text/css">
  h1 {
    font-family: "Arial";
    font-size:30px;
  }
  
</style>

<h1 style="text-align: center;"><b>INVOICE</b></h1>
<br><br>
<table style="table-layout: auto; width: 100%;" border="0">
    <tbody>

        <tr>
            <td class="block" style="width: 20%;">No. Invoice</td>
            <td class="block" style="width: 2%;">:</td>
            <td class="block" style="width: 20%;">'.$rhdr->cust_inv.'</td>
        </tr>
        <tr>
            <td class="block" style="width: 20%;">No. SPK</td>
            <td class="block" style="width: 2%;">:</td>
            <td class="block" style="width: 20%;">'.$rhdr->matout_no.'</td>
        </tr>
        <tr>
            <td class="block" style="width: 20%;">Surat Persetujuan</td>
            <td class="block" style="width: 2%;">:</td>
            <td class="block" style="width: 20%;"></td>
        </tr>
        <tr>
            <td class="block" style="width: 20%;">No. BPJ</td>
            <td class="block" style="width: 2%;">:</td>
            <td class="block" style="width: 20%;"></td>
        </tr>
        <tr>
            <td class="block" style="width: 20%;">No. Bank Garansi</td>
            <td class="block" style="width: 2%;">:</td>
            <td class="block" style="width: 20%;"></td>
        </tr>
            <tr>
            <td class="block" style="width: 20%;">No. x BC 261</td>
            <td class="block" style="width: 2%;">:</td>
            <td class="block" style="width: 20%;"></td>
        </tr>
        <tr>
            <td class="block" style="width: 20%;">Tgl J.T</td>
            <td class="block" style="width: 2%;">:</td>
            <td class="block" style="width: 20%;">'.$rhdr->Fmatout_date.'</td>
        </tr>
    </tbody>
</table><br><br>


<table style="table-layout: auto; width: 100%;" border="1">
    <thead>
        <tr>
            <td style="width: 3%">No<br></td>
            <td style="width: 10%">Kode Barang</td>
            <td style="width: 10%">Jenis Barang</td>
            <td style="width: 13%">Jumlah Barang</td>
            <td style="width: 7%">Satuan</td>
            <td style="width: 7%">Harga</td>
            <td style="width: 10%">Nilai CIF (RP)</td>
            <td style="width: 10%">Nilai CIF ($)</td>
            <td style="width: 10%">BM (12,5%)</td>
            <td style="width: 10%">ppn (10%)</td>
            <td style="width: 10%">PPH (2,5%)</td>
        </tr>
    </thead>
    <tbody>
    ';
    $no=0;
    foreach($rdet as $r){
      $no++;
      $Fqty = $r->qty;
      $Fqty = number_format("$Fqty",0,",",",");
      $Fprice = $r->price;
      $Fprice = number_format("$Fprice",2,".",".");
      $bm = $r->qty*$r->price/'12.5%';
      $bm = number_format("$bm",2,".",".");
      $ppn = $r->qty*$r->price/'10%';
      $ppn = number_format("$ppn",2,".",".");
      $pph = $r->qty*$r->price/'2.5%';
      $pph = number_format("$pph",2,".",".");
      $cif =$r->amount/'14.003,90';
      $cif = number_format("$cif",2,".",".");

      $totalQty += $r->qty;
      $total_qty = number_format("$totalQty",0,",",",");
      $totalPrc += $r->price;
      $total_prc = number_format("$totalPrc",2,",",",");
      $totalAmn += $r->amount;
      $total_amn = number_format("$totalAmn",2,",",",");
      $totalcif += $cif;
      $total_cif = number_format("$totalcif",2,",",",");
      $totalbm += $bm;
      $total_bm = number_format("$totalbm",2,",",",");
      $totalppn += $ppn;
      $total_ppn = number_format("$totalppn",2,",",",");
      $totalpph += $pph;
      $total_pph = number_format("$totalpph",2,",",",");
    $html.= 
    '		
        <tr>
        <td style="width: 3%">'.$no.'<br></td>
        <td style="width: 10%">'.$r->mat_id.'</td>
        <td style="width: 10%">'.$r->NmBarang.'</td>
        <td style="width: 13%">'.$Fqty.'</td>
        <td style="width: 7%">'.$r->Sat.'</td>
        <td style="width: 7%">'.$Fprice.'</td>
        <td style="width: 10%">'.$r->amount.'</td>
        <td style="width: 10%">'.$cif.'</td>
        <td style="width: 10%">'.$bm.'</td>
        <td style="width: 10%">'.$ppn.'</td>
        <td style="width: 10%">'.$pph.'</td>
        </tr>
        </tbody> ';
    }
    $html.= 
'
        <tfoot>
        <tbody>
        <tr>
        <td style="width: 13%; text-align: center;">Total</td>
        <td style="width: 10%"></td>
        <td style="width: 13%">'.$total_qty.'</td>
        <td style="width: 7%"></td>
        <td style="width: 7%">'.$total_prc.'</td>
        <td style="width: 10%">'.$total_amn.'</td>
        <td style="width: 10%">'.$total_cif.'</td>
        <td style="width: 10%">'.$total_bm.'</td>
        <td style="width: 10%">'.$total_ppn.'</td>
        <td style="width: 10%">'.$total_pph.'</td>
        </tr>
        </tfoot>
    </table>

<p><br></p>

<table style="table-layout: auto; width: 100%;" border="0">
    <tbody>
        <tr>
            <td style="width: 15%; text-align: ">Nilai Valuta</td>
            <td style="width: 2%; text-align: ">:</td>
            <td style="width: 15%; text-align: "></td>
        </tr>
        <tr>
        <td style="width: 15%; text-align: "></td>
        <td style="width: 2%; text-align: "></td>
        <td style="width: 25%; text-align: ">Y</td><br>
    </tr>
    <tr>
        <td style="width: 5%; text-align: "></td>
        <td style="width: 20%; text-align: ">Total BBM</td>
        <td style="width: 15%; text-align: "></td>
    </tr>
    <tr>
        <td style="width: 5%; text-align: "></td>
        <td style="width: 20%; text-align: ">Total PPN</td>
        <td style="width: 15%; text-align: "></td>
    </tr>
    <tr>
        <td style="width: 5%; text-align: "></td>
        <td style="width: 20%; text-align: ">Total PPH</td>
        <td style="width: 15%; text-align: "></td>
    </tr>
    <tr>
        <td style="width: 5%; text-align: "></td>
        <td style="width: 20%; text-align: ">Jumlah Total</td>
        <td style="width: 15%; text-align: "></td>
    </tr>
    <tr>
    <td class="block" style= "text-align: center; font-size:12px; width: 50%; " border="0" ></td>
    <td class="block" style="width: 10%;"></td>
    <td class="block" style="width: 40%; "><h3>PT. FUJI SEIMITSU INDONESIA</h3></td>
    </tr><br/>
    <tr>
    <td class="block" style= "text-align: ; font-size:12px; width: 50%; " border="0"></td>
    <td class="block" style="width: 10%;"></td>
    <td class="block" style="width: 40%;"><br/><br/><br/><br/>
    <h3><u>SUKAMOTO YUKI</u></h3><br/>VICE PRESIDENT DIRECTOR</td>
    </tr>
    </tbody>
</table>

<p><br></p>

<p><br></p>
';

// output the HTML content
$pdf->writeHTML($html, true, false, true, false, '');


// ---------------------------------------------------------    

// Close and output PDF document
// This method has several options, check the source code documentation for more information.
$pdf->Output('BC261-'.$rhdr->matout_no.'.pdf', 'I');
?>        