<?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 .= '
<table border="0" cellpadding="2" cellspacing="0">
	<tr>
		<td colspan="4">
			<font size="+2"><b>'.$cmpy_nm.'</b></font>
			<hr style="height:2px">
			<br>
		</td>
	</tr>	
	<tr>
		<td colspan="4" align="center"><font size="+1"><b>'.$this->title.'</b></font><br></td>
	</tr>
</table>
<table border="0" cellpadding="2" cellspacing="0">
	<tr>
		<td width="80">Incoming No</td>
		<td width="10">:</td>
		<td width="100">'.$rhdr->matin_no.'</td>
		<td width="100">Incoming Date</td>
		<td width="10">:</td>
		<td width="150">'.$rhdr->Fmatin_date.'</td>
		<td width="100">Type</td>
		<td width="10">:</td>
		<td width="110">'.$rhdr->matin_name.'</td>
	</tr>
	<tr>
		<td>PO No.</td>
		<td>:</td>
		<td>'.$rhdr->po_no.'</td>
		<td>Shipper</td>
		<td>:</td>
		<td>'.$rhdr->NmPrshn.'</td>
		<td>DO Shipper No.</td>
		<td>:</td>
		<td>'.$rhdr->supl_do.'</td>
	</tr>
	<tr>
		<td>INV No.</td>
		<td>:</td>
		<td>'.$rhdr->inv_no.'</td>
		<td>Currency</td>
		<td>:</td>
		<td>'.$rhdr->currency.'</td>
		<td>Kurs</td>
		<td>:</td>
		<td>'.$rhdr->kurs.'</td>
	</tr>
	<tr>
		<td>Jenis BC</td>
		<td>:</td>
		<td>'.$rhdr->UrJnsDok.'</td>
		<td>No. Dok. Pabean </td>
		<td>:</td>
		<td>'.$rhdr->NoDaf.'</td>
		<td>Tgl. Dok. Pabean</td>
		<td>:</td>
		<td>'.$rhdr->FTgDaf.'</td>
	</tr>
</table><br><br>
<table border="1" cellpadding="2" cellspacing="0" style="border-collapse:collapse">
<thead>	
	<tr>
		<td width="100" align="center"><b>Item Code</b></td>
		<td width="270" align="center"><b>Item Description</b></td>
		<td width="80" align="center"><b>Qty.</b></td>
		<td width="40" align="center"><b>UOM</b></td>
		<td width="80" align="center"><b>Unit Price</b></td>
		<td width="100" align="center"><b>Amount</b></td>
	</tr>
</thead>
<tbody>';
//for($i=0;$i<20;$i++){
//print_r($rdet);
foreach($rdet as $r){
	$html .= '<tr>
				<td width="100">'.$r->mat_id.'</td>
				<td width="270">'.$r->NmBarang.'</td>
				<td width="80" align="right">'.$r->Fqty.'</td>
				<td width="40" align="center">'.$r->Sat.'</td>
				<td width="80" align="right">'.$r->Fprice.'</td>
				<td width="100" align="right">'.$r->amount.'</td>
			</tr>';	
}
//}
	
$html .= '</tbody>
</table>
<br><br>
Notes : '.$rhdr->notes.'<br><br>
';
	
// 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('kipem'.$rs[$j]->no_kipem.'.pdf', 'I');
?>        