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

//echo dirname(dirname(dirname(dirname(__FILE__)))).'/libraries/tcpdf_barcodes_1d_includek.php';
require_once(dirname(dirname(dirname(dirname(__FILE__)))).'/libraries/tcpdf_barcodes_1d_includek.php');

// set the barcode content and type
// $barcodeobj = new TCPDFBarcode('http://www.tcpdf.org', 'C128');


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

// set font
$pdf->SetFont('helveticaB', '', 23);

$filename = '';

// add a page
$pdf->AddPage('P','A4');
$pdf->Cell(220, 0, 'PT. SGP ELEKTRONIK INDONESIATest', 0, 1, 'C', 0, '', 3);
$pdf->SetFont('helveticaB', '', 10);
$pdf->Cell(220, 0, 'Jl. Lingkungan I Ciriung RT. 002 RW. 001 Ciriung Cibinong 16918 Bogor', 0, 1, 'C', 0, '', 1);
$pdf->Cell(220, 0, 'Phone : 021 - 8753680, 8753681 Fax. 021 - 87908859', 0, 1, 'C', 0, '', 1);
$pdf->Ln(3);
$htmll = '';
$htmll .= '<table border="0" cellpadding="1" cellspacing="0">
<tr>
		<td colspan="2">
			<hr style="height:2px">
		</td>
</tr>
</table>';
$pdf->writeHTML($htmll, true, false, true, false, '');

$pdf->setJPEGQuality(100);

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

$pdf->Ln(15);
$pdf->SetFont('helveticaB', '', 20);
//$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)
$pdf->Cell(0, 0, 'INVOICE', 0, 1, 'C', 0, '', 1);

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

// create some HTML content
$subtable = '<table border="0" cellspacing="1" cellpadding="0">
<tr>
<td align="Right">Invoice No  :</td>
<td align="Left">'.$rhdr->supl_inv.'</td>
</tr>
<tr>
<td align="Right">Issued Date :</td>
<td align="Left">'.$rhdr->Fdate.'</td>
</tr>
<tr>
<td align="Right">Shipped Date :</td>
<td align="Left">'.$rhdr->Fdate.'</td>
</tr>
<tr>
<td align="Right">Shipped Per :</td>
<td align="Left"></td>
</tr>
<tr>
<td align="Right">Currency :</td>
<td align="Left">'.$rhdr->currency.'</td>
</tr>
<tr>
<td align="Right">Po No :</td>
<td align="Left">'.$rhdr->matout_no.'</td>
</tr>
<tr>
<td align="Right">Product : </td>
<td align="Left">'.$rdet[0]->Sat2.'</td>
</tr>
</table>';

$html = '<table border="1" cellspacing="1" cellpadding="4">
    <tr>
        <td align="Left" colspan="3"rowspan="">Sold :<br />
        <h3 align="center">'.$rhdr->NmPrshn.'</h3>
        <h3 align="center">'.$rhdr->AlmtPrshn.'</h3><br />
        </td>
        <td align="center" colspan="1" rowspan="2">'.$subtable.'
        </td>
    </tr>
    <tr>
        <td colspan="3">Consignee : </td>
    </tr>
    <tr bgcolor="#CCCCCC" align="center">
        <td colspan="">DESCRIPTION</td>
        <td colspan="">Quantity</td>
        <td colspan="">UNIT PRICE</td>
        <td colspan="">TOTAL AMOUNT</td>
    </tr>';
    foreach($rdet as $r){
      $html.= 
      '
      <tr>
            <td style="text-align: center;">'.$r->NmBarang.'</td>
            <td style="text-align: center;">'.$r->Fqty.'</td>
            <td style="text-align: center;">'.$r->Fprice.'</td>
            <td style="text-align: center;">'.$r->amount.'</td>
			</tr>
';
}$html.= 
'
<tr>
<td colspan="3" rowspan="" style="text-align: right;"><strong>TOTAL</strong><br>VAT 0%</td>
<td colspan="1" rowspan="" style="text-align: center;"><br><strong>'.$rhdr->ftot_amount.'<br>-</strong></td>
</tr>
<tr>
<td colspan="3" class="block" style="text-align: center;"><strong>TOTAL</strong></td>
<td class="block" style="text-align: center;"><br><strong>'.$rhdr->ftot_amount.'</strong></td>
</tr>
</table>';

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

$html="";
// create some HTML content
$html .= 
'<font size="7">
<b>
<table style="table-layout: auto; width: 100%;" border="0">
    <tbody>
        <tr>
						<td class="block" style="width: 35%; border-left:1px solid black; border-right:1px solid black; border-top:1px solid black">Distribution</td>
            <td style="width: 35%;"></td>
            <td class="block" style="width: 30%;"></td>
        </tr>
        <tr>
						<td class="block" style="width: 18%; border-left:1px solid black;"></td>
            <td style="width: 17%; border-right:1px solid black">Customer copy</td>
            <td style="width: 35%;"></td>
            <td class="block" style="width: 30%; text-align: center;">For an on behalf of</td>
        </tr>
        <tr>
						<td class="block" style="width: 18%; border-left:1px solid black;"></td>
            <td style="width: 17%; border-right:1px solid black">Local bills copy</td>
            <td style="width: 35%;"></td>
            <td class="block" style="width: 30%; text-align: center;">PT. SGP ELEKTRONIK INDONESIA</td>
        </tr>
        <tr>
						<td class="block" style="width: 18%; border-left:1px solid black;"></td>
            <td style="width: 17%; border-right:1px solid black">Accounts dept copy</td>
            <td style="width: 35%;"></td>
            <td class="block" style="width: 30%;"></td>
        </tr>
        <tr>
						<td class="block" style="width: 18%; border-left:1px solid black; border-bottom:1px solid black"></td>
            <td style="width: 17%; border-right:1px solid black; border-bottom:1px solid black"></td>
            <td style="width: 35%;"></td>
            <td class="block" style="width: 30%;"></td>
        </tr>
        <tr>
            <td style="width: 35%;"></td>
            <td class="block" style="width: 35%;"></td>
        </tr>
        <tr>
            <td class="block" style="width:50%;"><u>REMITANCE BY TT TO OUR BANK:</u></td>
            <td style="width: 50%;"></td>
        </tr>
        <tr>
        <td style="width: 2%;"></td>
        <td class="block" style="width: 13%;">Banker</td>
        <td style="width: 2%;">:</td>
        <td class="block" style="width: 15%;">BANK CIMB NIAGA</td>
        </tr>
        <tr>
        <td style="width: 2%;"></td>
        <td class="block" style="width: 13%;">Branch</td>
        <td  style="width: 2%;">:</td>
        <td class="block" style="width: 15%;">CIBINONG</td>
        </tr>
        <tr>
        <td style="width: 2%;"></td>
        <td class="block" style="width: 13%;">Bank Address</td>
        <td style="width: 2%;">:</td>
        <td class="block" style="width: 25%;">JL.MAYOR OKING NO.27, BLOK A5-6</td>
        <td class="block" style="width: 28%;"></td>
        <td class="block" style="width: 30%; text-align: center;"><strong><u>ADE BUDIMAN</u></strong></td>
        </tr>
        <tr>
        <td style="width: 2%;"></td>
        <td class="block" style="width: 13%;"></td>
        <td style="width: 2%;"></td>
        <td class="block" style="width: 25%;">CIBINONG, BOGOR, INDONESIA</td>
        </tr>
        <tr>
        <td style="width: 2%;"></td>
        <td class="block" style="width: 13%;">Telp</td>
        <td style="width: 2%;">:</td>
        <td class="block" style="width: 25%;">+62-21-8753680 / 8753681</td>
        </tr>
        <tr>
        <td style="width: 2%;"></td>
        <td class="block" style="width: 13%;">Account Number</td>
        <td style="width: 2%;">:</td>
        <td class="block" style="width: 15%;">800114283240 (USD)</td>
        </tr>
        <tr>
        <td style="width: 2%;"></td>
        <td class="block" style="width: 13%;">Account Number</td>
        <td style="width: 2%;">:</td>
        <td class="block" style="width: 15%;">80011426100 (IDR)</td>
        </tr>
        <tr>
        <td style="width: 2%;"></td>
        <td class="block" style="width: 13%;">Account Name</td>
        <td style="width: 2%;">:</td>
        <td class="block" style="width: 25%;">PT SGP ELEKTRONIK INDONESIA</td>
        </tr>
        <tr>
        <td style="width: 2%;"></td>
        <td class="block" style="width: 13%;">SWIFT Code</td>
        <td style="width: 2%;">:</td>
        <td class="block" style="width: 15%;">BNIAIDJA</td>
        </tr>
    </tbody>
</table>
</b>
</font>
';

$filename = $rhdr->po_no;
// 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($rs[$j]->po_no.'.pdf', 'I');
$pdf->Output($filename.'.pdf', 'I');

?>        