<?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('helvetica', '', 8);

$filename = '';

// 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 .= 
'
<h4 style="text-align: center;"><strong>'.$cmpy_nm.'</strong></h4>
-<p style="text-align: center; margin-top:-10px;">Jalan Industri Utama Blok RR-10, Kawasan Industri Jababeka Tahap II<br/>
Pasirsari, Cikarang Selatan, Kab, Bekasi, Jawa Barat, 17550, Indonesia</p>
<h4 style="text-align: center; margin-top:-10px;"><strong>INVOICE &amp; PACKING LIST</strong></h4>

<table style="table-layout: auto; width: 100%;" border="0">
    <tbody>
        <tr>
						<td class="block" style="">SOLD TO</td>
            <td class="block" style="width: 2%; ">:</td>						
            <td class="block" style="width: 30%;">'.$rhdr->NmPrshn.'</td>
            <td class="block" style=""></td>
						<td class="block" style="">DATE</td>
            <td class="block" style="width: 2%; ">:</td>						
            <td class="block" style="width: 30%;">'.$rhdr->Fpo_date.'</td>
        </tr>
        <tr>
						<td class="block" style="">CONSIGNEE</td>
            <td class="block" style="">:</td>						
            <td class="block" style="">'.$rhdr->AlmtPrshn.'</td>
            <td class="block" style=""></td>
						<td class="block" style="">DO NO.</td>
            <td class="block" style="">:</td>						
            <td class="block" style="">'.$rhdr->po_no.'</td>
        </tr>
        <tr>
						<td class="block" style="">DELIVERY TO</td>
            <td class="block" style="">:</td>						
            <td class="block" style="">'.$rhdr->NmPrshn.'</td>
            <td class="block" style=""></td>
						<td class="block" style="">PAYMENT TERM</td>
            <td class="block" style="">:</td>						
            <td class="block" style=""></td>
        </tr>
        <tr>
            <td class="block" style=""></td>
            <td class="block" style=""></td>
            <td class="block" style=""></td>
            <td class="block" style=""></td>
						<td class="block" style="">SHIPMENT FROM</td>
            <td class="block" style="">:</td>						
            <td class="block" style="">'.$cmpy_nm.'</td>
        </tr>
        <tr>
            <td class="block" style=""></td>
            <td class="block" style=""></td>
            <td class="block" style=""></td>
            <td class="block" style=""></td>
            <td class="block" style="text-align: right;">TO</td>
            <td class="block" style="">:</td>						
            <td class="block" style="">'.$rhdr->NmPrshn.'</td>
        </tr>
        <tr>
            <td class="block" style=""></td>
            <td class="block" style=""></td>
            <td class="block" style=""></td>
            <td class="block" style=""></td>
						<td class="block" style="">SHIPPED DATE</td>
            <td class="block" style="">:</td>						
            <td class="block" style="">'.$rhdr->Fdlv_date.'</td>
        </tr>
        <tr>
            <td class="block" style=""></td>
            <td class="block" style=""></td>
            <td class="block" style=""></td>
            <td class="block" style=""></td>
						<td class="block" style="">SHIPPED PER</td>
            <td class="block" style="">:</td>						
            <td class="block" style="">BY TRUCK</td>
        </tr>
        <tr>
            <td class="block" style=""></td>
            <td class="block" style=""></td>
            <td class="block" style=""></td>
            <td class="block" style=""></td>
            <td class="block" style=""></td>
            <td class="block" style=""></td>
            <td class="block" style=""></td>
        </tr>
        <tr>
            <td class="block" style=""></td>
            <td class="block" style=""></td>
            <td class="block" style=""></td>
            <td class="block" style=""></td>
            <td class="block" style=""></td>
            <td class="block" colspan="2" style="text-align: center;"></td>
        </tr>
    </tbody>
</table>

<p><br></p>

<table style="table-layout: auto; width: 100%;" border="1">
    <thead>
        <tr>
            <td class="block" style="text-align: center;">WEIGTH<br>(KG)</td>
            <td class="block" style="text-align: center;">C/NO</td>
            <td class="block" style="text-align: center;">QUANTITY PCE</td>
            <td class="block" style="text-align: center;">DESCRIPTION</td>
            <td class="block" style="text-align: center;">S/NO</td>
            <td class="block" style="text-align: center;">P/NO</td>
            <td class="block" style="text-align: center;">UNITPRICE USD</td>
            <td class="block" style="text-align: center;">AMOUNT USD</td>
        </tr>
        
		</thead>
		<tbody border="0">';
foreach($rdet as $r){
$html.= 
'		
				<tr>
            <td style="text-align: center;"></td>
            <td style="text-align: center;">'.$r->mat_id.'</td>
            <td style="text-align: center;">'.$r->Fqty.'</td>
            <td style="text-align: center;">'.$r->NmBarang.'</td>
            <td style="text-align: center;">'.$rhdr->ref_no.'</td>
            <td style="text-align: center;">'.$r->npo_id.'</td>
            <td style="text-align: center;">'.$r->Fprice.'</td>
            <td style="text-align: center;">'.$r->amount.'</td>
				</tr>
';
$total += $r->qty*$r->price;
$total_format = number_format("$total",2,",",".");
}
$html.= 
'
		</tbody>
		<tfoot>
        <tr>
            <td class="block" style="text-align: center;"><br></td>
            <td class="block" style="text-align: center;"><br></td>
            <td class="block" style="text-align: center;"><br></td>
            <td class="block" style="text-align: center;"><br></td>
            <td class="block" style="text-align: center;"><br></td>
            <td class="block" style="text-align: center;"><br></td>
            <td class="block" style="text-align: center;"><strong>TOTAL</strong></td>
            <td class="block" style="text-align: center;"><br>'.$total_format.'</td>
        </tr>
    </tfoot>
</table>
<font size="-1">
<table style="table-layout: auto; width: 100%;" border="0">
    <tbody>
        <tr>
						<td class="block" style="width: 18%;">Surat Jalan No</td>
            <td class="block" style="width: 2%; ">:</td>
            <td colspan="5" style="width: 50%;">'.$rhdr->po_no.'</td>
            <td class="block" style="width: 1%;"></td>
            <td class="block" style="width: 30%;"></td>
        </tr>
        <tr>
						<td class="block">Balance</td>
            <td class="block" style="width: 2%; ">:</td>
            <td colspan="5" style="width: 50%;"></td>
            <td class="block" style="width: 1%;"></td>
            <td class="block" style="width: 30%;">For an on behalf of</td>
        </tr>
        <tr>
						<td class="block">MEASUREMENT</td>
            <td class="block" style="width: 2%; ">:</td>
            <td colspan="5" style="width: 50%;"></td>
            <td class="block" style="width: 1%;"></td>
            <td class="block" style="width: 30%;">PT. FUJI SEIMITSU INDONESIA</td>
        </tr>
        <tr>
						<td class="block"></td>
            <td class="block" style="width: 2%; ">:</td>						
            <td class="block" style="width: 8%; ">LENGTH</td>
            <td class="block" style="width: 4%; ">X</td>
            <td class="block" style="width: 8%; ">WIDTH</td>
            <td class="block" style="width: 4%; ">X</td>
            <td class="block" style="width: 8%; ">HEIGHT</td>
            <td class="block" style="width: 1%;"></td>
            <td class="block" style="width: 30%;"></td>
        </tr>
        <tr>
						<td class="block"></td>
            <td class="block" style="width: 2%; ">:</td>						
            <td class="block"></td>
            <td class="block">X</td>
            <td class="block"></td>
            <td class="block">X</td>
            <td class="block"></td>
            <td class="block" style="width: 1%;"></td>
            <td class="block" style="width: 30%;"></td>
        </tr>
        <tr>
						<td class="block"></td>
            <td class="block" style="width: 2%; ">:</td>						
            <td colspan="5" style="width: 50%;"></td>
						<td class="block" style="width: 1%;"></td>
            <td class="block"></td>						
        </tr>
        <tr>
            <td colspan="9"></td>
        </tr>
        <tr>
            <td colspan="9"></td>
        </tr>
				<tr>
						<td class="block"></td>
						<td class="block" style="width: 2%; "></td>						
						<td colspan="5" style="width: 50%;"></td>
						<td class="block" style="width: 1%;"></td>
            <td class="block" style="text-align: center;"><strong><u>SAKAMOTO YUKI</u></strong></td>
        </tr>
    </tbody>
</table>
</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');

?>        