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

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

// add a page
$pdf->AddPage('P','A4');
$pdf->setJPEGQuality(100);

$pdf->Image($image, 15, 16, 40, 20, '', '', '', true, 100);

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

$html2="";
// create some HTML content
$html2 .= 
'<table style="table-layout: auto; width: 100%;" border="0" cellpadding="2">
    <tbody>
        <tr>
            <td style="width:100%; text-align:center;border-right:1px solid black;border-left:1px solid black;border-top:1px solid black;"></td>
        </tr>
        <tr>
            <td style="width:100%; text-align:center;border-right:1px solid black;border-left:1px solid black;"></td>
        </tr>
        <tr>
            <td style="width:80%; text-align:center;border-left:1px solid black;"><font size="20"></font></td>
            <td style="width:20%; text-align:center;border-bottom:1px solid black;border-right:1px solid black;border-left:1px solid black;border-top:1px solid black;"><font size="15">ORIGINAL</font></td>
        </tr>
        <tr>
            <td style="width:100%; text-align:center;font-weight: bold; border-right:1px solid black;border-left:1px solid black;"><font size="20">COMMERCIAL INVOICE</font></td>
        </tr>
        <tr>
            <td style="width:100%;border-right:1px solid black;border-bottom:1px solid black;border-left:1px solid black;">
            </td>
        </tr>
        <tr>
            <td style="width:5%;border-left:1px solid black;">To :&nbsp;</td>
            <td style="width:95%;border-right:1px solid black;">'.$rhdr->NmPrshn.'</td>
        </tr>
        <tr>
            <td style="width:5%;border-left:1px solid black;"></td>
            <td style="width:95%;border-right:1px solid black;">'.$rhdr->AlmtPrshn.'</td>
        </tr>
        <tr>
            <td style="width:5%;border-left:1px solid black;"></td>
            <td style="width:95%;border-right:1px solid black;">'.$rhdr->Kota.'</td>
        </tr>
        <tr>
            <td style="width:5%;border-left:1px solid black;"></td>
            <td style="width:95%;border-right:1px solid black;">PHONE : '.$rhdr->tlp.'</td>
        </tr>
        <tr>
            <td style="width:5%;border-left:1px solid black;"></td>
            <td style="width:95%;border-right:1px solid black;">FAX : '.$rhdr->fax.'</td>
        </tr>
        <tr>
            <td style="width:5%;border-left:1px solid black;"></td>
            <td style="width:95%;border-right:1px solid black;">NPWP : '.$rhdr->NpwpPrshn.'</td>
        </tr>
    </tbody>
    <thead>
        <tr>
            <td style="text-align:center;width: 35%;border-right:1px solid black;border-bottom:1px solid black;border-top:1px solid black; border-left:1px solid black">NO. INVOICE</td>
            <td style="text-align:center;width: 20%;border-bottom:1px solid black;border-top:1px solid black; border-right:1px solid black">DATE</td>
            <td style="text-align:center;width: 30%;border-bottom:1px solid black; border-top:1px solid black; border-right:1px solid black">TERM OF PAYMENT</td>
            <td style="text-align:center;width: 15%; border-bottom:1px solid black; border-top:1px solid black; border-right:1px solid black">NO. REF</td>
        </tr>
        <tr>
        
            <td style="text-align:center;width: 35%; border-bottom:1px solid black; border-right:1px solid black; border-left:1px solid black">'.$rhdr->cust_inv.'</td>
            <td style="text-align:center;width: 20%; border-bottom:1px solid black; border-right:1px solid black">'.$rhdr->Fmatout_date.'</td>
            <td style="text-align:center;width: 30%; border-bottom:1px solid black; border-right:1px solid black">TT at 30 days after delivery</td>
            <td style="text-align:center;width: 15%; border-bottom:1px solid black; border-right:1px solid black"></td>
        </tr>
        <tr>
            <td style="text-align:center;width: 5%; border-bottom:1px solid black; border-right:1px solid black; border-left:1px solid black">NO</td>
            <td style="text-align:center;width: 30%; border-bottom:1px solid black; border-right:1px solid black">PART NUMBER</td>
            <td style="text-align:center;width: 20%; border-bottom:1px solid black; border-right:1px solid black">PART NAME</td>
            <td style="text-align:center;width: 15%; border-bottom:1px solid black; border-right:1px solid black">QTY</td>
            <td style="text-align:center;width: 15%; border-bottom:1px solid black ; border-right:1px solid black">UNIT PRICE</td>
            <td style="text-align:center;width: 15%; border-bottom:1px solid black; border-right:1px solid black">AMOUNT</td>
        </tr>
    </thead>
    <tbody border="1">';
$i = 1;
foreach($rdet as $r){
$html2.= 
'		
            <tr>
            <td style="text-align:center;width: 5%; border-right:1px solid black; border-bottom:1px solid black; border-left:1px solid black">'.$i++.'</td>
            <td style="text-align:center;width: 30%; border-right:1px solid black; border-bottom:1px solid black">'.$r->mat_id.'</td>
            <td style="text-align:center;width: 20%; border-right:1px solid black; border-bottom:1px solid black">'.$r->NmBarang.'</td>
            <td style="text-align:center;width: 15%; border-right:1px solid black; border-bottom:1px solid black">'.$r->Fqty.'</td>
            <td style="text-align:center;width: 15%; border-right:1px solid black; border-bottom:1px solid black">'.$r->Fprice.'</td>
            <td style="text-align:center;width: 15%; border-right:1px solid black; border-bottom:1px solid black; border-right:1px solid black">'.$r->amount.'</td>
        </tr>
';
$totalqty += $r->Fqty;
$totalprice += $r->Fprice;
$totalamount += $r->amount;
$total_amount = number_format("$totalamount",2,",",".");
}
$html2.= 
'
        </tbody>
        <tfoot>
        <tr>						
            <td class="block" colspan="3" style="border-bottom:1px solid black; border-left:1px solid black">SUB TOTAL</td>
            <td class="block" colspan="1" style="text-align:center; border-bottom:1px solid black">'.$totalqty.'</td>
            <td class="block" colspan="1" style="text-align:center; border-right:1px solid black; border-bottom:1px solid black">'.$totalprice.'</td>
            <td class="block" colspan="1" style="text-align:center; border-bottom:1px solid black; border-right:1px solid black">'.$total_amount.'</td>
        </tr>
        <tr>						
            <td class="block" colspan="3" style="border-bottom:1px solid black; border-left:1px solid black">VAT (PPN) 10%</td>
            <td class="block" colspan="1" style="text-align:center; border-bottom:1px solid black"></td>
            <td class="block" colspan="1" style="text-align:center; border-right:1px solid black; border-bottom:1px solid black"></td>
            <td class="block" colspan="1" style="text-align:center; border-bottom:1px solid black; border-right:1px solid black"></td>
        </tr>
        <tr>						
            <td class="block" colspan="3" style="border-bottom:1px solid black; border-left:1px solid black"><strong>TOTAL</strong></td>
            <td class="block" colspan="1" style="text-align:center; border-bottom:1px solid black"></td>
            <td class="block" colspan="1" style="text-align:center; border-right:1px solid black; border-bottom:1px solid black"></td>
            <td class="block" colspan="1" style="text-align:center; border-bottom:1px solid black; border-right:1px solid black">'.$total_amount.'</td>
        </tr>
        </tfoot>
    <tbody>
        <tr>
            <td style="width: 5%; border-left:1px solid black;"></td>
            <td style="width: 50%; "></td>
            <td style="width: 45%; border-right:1px solid black;"></td>
        </tr>
        <tr>
            <td style="width: 5%; border-left:1px solid black;"></td>
            <td style="width: 50%; ">Sesuai Surat Jalan No. 34-OHA/DC-SMI/VIII/2019</td>
            <td style="width: 45%; border-right:1px solid black;"></td>
        </tr>
        <tr>
            <td style="width: 5%; border-left:1px solid black;"></td>
            <td style="width: 50%;"><br>Berdasarkan SKep Nomor 37/MK.10/2019</td>
            <td style="width: 45%; border-right:1px solid black;"></td>
        </tr>
        <tr>
            <td style="width: 5%; border-left:1px solid black;"></td>
            <td style="width: 50%;">Kurs Pajak 1$ : Rp 14.255,-</td>
            <td style="width: 45%; border-right:1px solid black;"></td>
        </tr>
        <tr>
            <td style="width: 5%; border-left:1px solid black;"></td>
            <td style="width: 50%;"></td>
            <td style="width: 45%; border-right:1px solid black;"></td>
        </tr>
        <tr>
            <td style="width: 5%; border-left:1px solid black;"></td>
            <td style="width: 30%;border-top:1px solid black; border-left:1px solid black;border-right:1px solid black">Payment by Telegraphic Transfer to :</td>
            <td style="width: 20%;"></td>
            <td style="width: 20%;"></td>
            <td style="width: 10%;">CIKARANG,</td>
            <td style="width: 15%;border-right:1px solid black">'.$rhdr->Fmatout_date.'</td>
        </tr>
        <tr>
            <td style="width: 5%; border-left:1px solid black;"></td>
            <td style="width: 30%;border-left:1px solid black;border-right:1px solid black">BANK WOORI INDONESIA</td>
            <td style="width: 20%;"></td>
            <td style="width: 45%; border-right:1px solid black;"></td>
        </tr>
        <tr>
            <td style="width: 5%; border-left:1px solid black;"></td>
            <td style="width: 30%;border-left:1px solid black;border-right:1px solid black">Gedung Bursa Efek Jakarta Tower I, Lt.16</td>
            <td style="width: 20%;"></td>
            <td style="width: 45%; border-right:1px solid black;"></td>
        </tr>
        <tr>
            <td style="width: 5%; border-left:1px solid black;"></td>
            <td style="width: 30%;border-left:1px solid black;border-right:1px solid black">Jl. Jend. Sudirman, Kav.52-53 Jakarta 12190</td>
            <td style="width: 20%;"></td>
            <td style="width: 45%; border-right:1px solid black;"></td>
        </tr>
        <tr>
            <td style="width: 5%; border-left:1px solid black;"></td>
            <td style="width: 30%;border-left:1px solid black;border-right:1px solid black">Account No. 100-913-012877 ( USD )</td>
            <td style="width: 20%;"></td>
            <td style="width: 45%; border-right:1px solid black;"></td>
        </tr>
        <tr>
            <td style="width: 5%; border-left:1px solid black;"></td>
            <td style="width: 30%;border-left:1px solid black;border-right:1px solid black">Account No. 150-913-910989 ( IDR )</td>
            <td style="width: 20%;"></td>
            <td style="width: 45%; border-right:1px solid black;"></td>
        </tr>
        <tr>
            <td style="width: 5%; border-left:1px solid black;"></td>
            <td style="width: 30%;border-left:1px solid black;border-right:1px solid black">A/n PT.FURUKAWA AUTOMOTIVE SYSTEMS INDONESIA</td>
            <td style="width: 20%;"></td>
            <td style="width: 23%;"></td>
            <td style="width: 22%;border-right:1px solid black"><u>CHOI KYUNG SOO</u></td>
        </tr>
        <tr>
            <td style="width: 5%; border-left:1px solid black;"></td>
            <td style="width: 30%;border-bottom:1px solid black; border-left:1px solid black;border-right:1px solid black"></td>
            <td style="width: 20%;"></td>
            <td style="width: 26%;"></td>
            <td style="width: 19%; border-right:1px solid black">DIREKTUR</td>
        </tr>
        <tr>
            <td style="width: 5%;border-left:1px solid black; "></td>
            <td style="width: 30%;"></td>
            <td style="width: 20%;"></td>
            <td style="width: 26%;"></td>
            <td style="width: 19%; border-right:1px solid black"></td>
        </tr>
        <tr>
            <td style="width: 30%; border-bottom:1px solid black;border-left:1px solid black;">SMTM-F-08 Rev.00</td>
            <td style="width: 25%; border-bottom:1px solid black"></td>
            <td style="width: 26%; border-bottom:1px solid black"></td>
            <td style="width: 19%; border-right:1px solid black; border-bottom:1px solid black"></td>
        </tr>
    </tbody>
</table>
';

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


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

// Close and output PDF document
// This method has several options, check the source code documentation for more information.
$pdf->Output('kipem'.$rs[$j]->no_kipem.'.pdf', 'I');
?>        