<?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


$filename = '';

// add a page
$pdf->AddPage('P','A4');
$pdf->setCellMargins(20, 0, 0, 0);
$pdf->SetFont('helveticaB', '', 16);
$pdf->SetTextColor(0, 0, 255);
$pdf->Cell(220, 0, 'PT. KOSTEC INDONESIA', 0, 1, 'L', 0, '', 3);
$pdf->SetFont('helveticaB', '', 8);
$pdf->Cell(220, 0, 'Kawasan Jababeka I. Jl. Jababeka XI Blok K no.4 D.Cikarang – Bekasi', 0, 1, 'L', 0, '', 1);
$pdf->SetTextColor(0, 0, 0);
$pdf->Cell(220, 0, 'Telp. 021 – 8983 3182/4. Fax 021 – 893 4349 e - mail : ptkostec@hotmail.com', 0, 1, 'L', 0, '', 1);
$pdf->Ln(3);
$pdf->setCellMargins(0, 3, 0, 0);
$htmll = '';
$htmll .= '<table border="0" cellpadding="2" 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, 10, 15, 20, 20, '', '', '', true, 100);
$pdf->Image($image2, 156, 15, 20, 20, '', '', '', true, 100);
$pdf->Image($image3, 178, 15, 20, 20, '', '', '', true, 100);

$pdf->setCellMargins(0, 0, 0, 0);

$pdf->SetFont('helveticaB', 'U', 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)
$judul = $this->title;
$pdf->Cell(0, 0, $judul, 0, 1, 'C', 0, '', 1);

$pdf->SetFont('helvetica', 'B', 10);
$pdf->Ln(2);
// create some HTML content

$html ="";
$html .= 
'<font size="8">
<table style="table-layout: auto; width: 100%;" border="0">
<tbody>
        <tr>
			<td class="block" style="width: 6%;">Seller</td>
            <td style="width: 2%;">:</td>
			<td class="block" style="width: 62%;"><h4>'.$rhdr->NmPrshn.'</h4></td>
			<td class="block" style="width: 8%;">Date</td>
			<td style="width: 2%;">:</td>
			<td class="block" style="width: 20%;"><h4>'.$rhdr->po_date.'</h4></td>
		</tr>
		<tr>
			<td class="block" style="width: 6%;"></td>
            <td style="width: 2%;"></td>
			<td class="block" style="width: 62%;"><h4></h4></td>
			<td class="block" style="width: 6%;"></td>
			<td style="width: 2%;"></td>
			<td class="block" style="width: 22%;"></td>
		</tr>
		<tr>
			<td class="block" style="width: 6%;">Attn</td>
            <td style="width: 2%;">:</td>
			<td class="block" style="width: 62%;">'.$rhdr->attn.'</td>
			<td class="block" style="width: 8%;">P/O NO</td>
			<td style="width: 2%;">:</td>
			<td class="block" style="width: 20%;"><h4>'.$rhdr->po_no.'</h4></td>
		</tr>
		<tr>
			<td class="block" style="width: 6%;"></td>
            <td style="width: 2%;"></td>
			<td class="block" style="width: 62%;"></td>
			<td class="block" style="width: 6%;"></td>
			<td style="width: 2%;"></td>
			<td class="block" style="width: 22%;"></td>
		</tr>
		<tr>
			<td class="block" style="width: 6%;">Cc</td>
            <td style="width: 2%;">:</td>
			<td class="block" style="width: 62%;">'.$rhdr->attn.'</td>
			<td class="block" style="width: 8%;"></td>
			<td style="width: 2%;"></td>
			<td class="block" style="width: 20%;"></td>
		</tr>
		</tbody>
	</table>
	</font>
';

$filename = $rhdr->po_no;
// output the HTML content
$pdf->writeHTML($html, true, false, true, false, '');
$pdf->Ln(5);
$pdf->SetFont('helvetica', '', 10);
$html2 ="";
$html2 .= '
<font size="8">
<table table style="table-layout: auto; width: 100%;" border="0">
<tbody>
<tr>
<td class="block" style="width: 50%;">We take pleasure placing order to terms and condition mentioned bellow :</td>
<td class="block" style="width: 50%;"></td>
</tr>
<tr>
<td class="block" style="width: 12%;"></td>
<td class="block" style="width: 2%;"></td>
<td class="block" style="width: 50%;"></td>
</tr>
<tr>
<td class="block" style="width: 12%;">Delivery time</td>
<td class="block" style="width: 2%;">:</td>
<td class="block" style="width: 50%;">'.$rhdr->Fdlv_date.'</td>
</tr>
<tr>
<td class="block" style="width: 12%;"></td>
<td class="block" style="width: 2%;"></td>
<td class="block" style="width: 50%;"></td>
</tr>
<tr>
<td class="block" style="width: 12%;">Destination</td>
<td class="block" style="width: 2%;">:</td>
<td class="block" style="width: 50%;">JL. Jababeka XI Blok K 4-D Cikarang</td>
</tr>
<tr>
<td class="block" style="width: 12%;"></td>
<td class="block" style="width: 2%;"></td>
<td class="block" style="width: 50%;"></td>
</tr>
<tr>
<td class="block" style="width: 12%;">Payment terms</td>
<td class="block" style="width: 2%;">:</td>
<td class="block" style="width: 50%;">'.$rhdr->terms.'</td>
</tr>
</tbody>
</table>
</font>';

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

$html3="";
$html3 = '<table border="1" cellspacing="1" cellpadding="4">
    <tr>
        <td style="text-align: center; width: 5%;">NO</td>
		<td style="text-align: center; width: 25%;">Description</td>
		<td style="text-align: center; width: 10%;">UOM</td>
		<td style="text-align: center; width: 10%;">Weight</td>
		<td style="text-align: center; width: 20%;">Price/Kg</td>
		<td style="text-align: center; width: 20%;">Amount</td>
		<td style="text-align: center; width: 10%;">Remark</td>
	</tr>';
	$i = 1;
    foreach($rdet as $r){
		$format_fqty = number_format("$r->qty",2,",",".");
		$format_fprice = number_format("$r->price",2,",",".");
		$amount = ($r->qty * $r->price);
		$format_amount = number_format("$amount",2,",",".");
      $html3.= 
      '
      <tr>
            <td style="text-align: center; width: 5%;">'.$i++.'</td>
			<td style="text-align: center; width: 25%;">'.$r->NmBarang.'</td>
			<td style="text-align: center; width: 10%;">'.$r->Sat.'</td>
			<td style="text-align: center; width: 10%;">'.$format_fqty.'</td>
			<td style="text-align: center; width: 20%;">'.$rhdr->currency.'. '.$format_fprice.'</td>
            <td style="text-align: center; width: 20%;">'.$rhdr->currency.'. '.$format_amount.'</td>
            <td style="text-align: center; width: 10%;">'.$rhdr->notes.'</td>
			</tr>
';
$total += ($r->qty * $r->price);
$format_total = number_format("$total",2,",",".");
$total_qty += $r->qty;
$total_price += $r->price;
$format_qty = number_format("$total_qty",2,",",".");
$format_price = number_format("$total_price",2,",",".");
}$html3.= 
'
<tr>
<td colspan="3" rowspan="" style="text-align: center;"><strong>TOTAL</strong></td>
<td colspan="1" rowspan="" style="text-align: center;"><br><strong>'.$format_qty.'</strong></td>
<td colspan="1" rowspan="" style="text-align: center;"><br><strong>'.$rhdr->currency.'. '.$format_price.'</strong></td>
<td colspan="1" rowspan="" style="text-align: center;"><br><strong>'.$rhdr->currency.'. '.$format_total.'</strong></td>
<td colspan="2" rowspan="" style="text-align: center;"><br><strong></strong></td>
</tr>
</table>';

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

$html4="";
// create some HTML content
$html4 .= 
'<font size="-1">
<table style="table-layout: auto; width: 100%;" border="0">
    <tbody>
        <tr>
			<td class="block" style="width: 35%;">Remark :</td>
            <td style="width: 35%;"></td>
            <td class="block" style="width: 30%;"></td>
		</tr>
		<tr>
			<td class="block" style="width: 35%;"></td>
            <td style="width: 35%;"></td>
            <td class="block" style="width: 30%;"></td>
		</tr>
		<tr>
			<td class="block" style="width: 35%;">Thank,s for your attention and cooperation.</td>
            <td style="width: 35%;"></td>
            <td class="block" style="width: 30%;"></td>
		</tr>
		<tr>
			<td class="block" style="width: 35%;">Please re fax after your sign and stamp.</td>
            <td style="width: 35%;"></td>
            <td class="block" style="width: 30%;"></td>
		</tr>
		<tr>
			<td class="block" style="width: 35%;"></td>
            <td style="width: 35%;"></td>
            <td class="block" style="width: 30%;"></td>
		</tr>
		<tr>
			<td class="block" style="width: 30%; border-bottom: 1px solid black;"></td>
			<td class="block" style="width: 25%;"></td>
			<td class="block" style="width: 45%; border-bottom: 1px solid black;"></td>
		</tr>';
		
        $html4 .='<tr>
			<td class="block" style="width: 30%; border-left:1px solid black; border-right:1px solid black"><h4>Content all of the raw material</h4></td>
			<td class="block" style="width: 25%; border-right:1px solid black"></td>
			<td class="block" style="width: 15%; text-align: center; border-bottom: 1px solid black; border-right: 1px solid black;">Prepared<br></td>
			<td class="block" style="width: 15%; text-align: center; border-bottom: 1px solid black; border-right: 1px solid black;">Approved<br></td>
			<td class="block" style="width: 15%; text-align: center; border-bottom: 1px solid black; border-right: 1px solid black;">Approved<br></td>
		</tr>
		<tr>
			<td class="block" style="width: 30%; border-left:1px solid black; border-right:1px solid black"><h4>which we order must be followed</h4></td>
			<td class="block" style="width: 25%; border-right: 1px solid black;">ROHS standard</td>
			<td class="block" style="width: 15%; text-align: center; border-right: 1px solid black;"></td>
			<td class="block" style="width: 15%; text-align: center; border-right: 1px solid black;"></td>
			<td class="block" style="width: 15%; text-align: center; border-right: 1px solid black;"></td>
		</tr>
		<tr>
			<td class="block" style="width: 30%; border-top: 1px solid black;"></td>
			<td class="block" style="width: 25%; border-right: 1px solid black;"></td>
			<td class="block" style="width: 15%; text-align: center; border-right: 1px solid black;"></td>
			<td class="block" style="width: 15%; text-align: center; border-right: 1px solid black;"></td>
			<td class="block" style="width: 15%; text-align: center; border-right: 1px solid black;"></td>
		</tr>
		<tr>
			<td class="block" style="width: 30%; "></td>
			<td class="block" style="width: 25%; border-right: 1px solid black;"></td>
			<td class="block" style="width: 15%; text-align: center; border-right: 1px solid black;"></td>
			<td class="block" style="width: 15%; text-align: center; border-right: 1px solid black;"></td>
			<td class="block" style="width: 15%; text-align: center; border-right: 1px solid black;"></td>
		</tr>
		<tr>
			<td class="block" style="width: 30%; "></td>
			<td class="block" style="width: 25%; border-right: 1px solid black;"></td>
			<td class="block" style="width: 45%; text-align: center; border-right: 1px solid black;"><img src= "'.$image4.'" width="300" style="margin-top:10px" /></td>
        </tr>
        <tr>
        <td class="block" style="width: 15%;"></td>
		<td class="block" style="width: 15%;"></td>
		<td class="block" style="width: 25%;"></td>
		<td class="block" style="width: 15%; text-align: center; border-left: 1px solid black;border-right: 1px solid black;"></td>
		<td class="block" style="width: 15%; text-align: center; border-right: 1px solid black;"></td>
		<td class="block" style="width: 15%; text-align: center; border-right: 1px solid black;"></td>
		</tr>
		<tr>
        <td class="block" style="width: 15%;"></td>
		<td class="block" style="width: 15%;"></td>
		<td class="block" style="width: 25%;"></td>
		<td class="block" style="width: 15%; text-align: center; border-left: 1px solid black;border-right: 1px solid black;"></td>
		<td class="block" style="width: 15%; text-align: center; border-right: 1px solid black;"></td>
		<td class="block" style="width: 15%; text-align: center; border-right: 1px solid black;"></td>
		</tr>
		<tr>
        <td class="block" style="width: 15%;"></td>
		<td class="block" style="width: 15%;"></td>
		<td class="block" style="width: 25%;"></td>
		<td class="block" style="width: 15%; border-left: 1px solid black;border-bottom: 1px solid black; border-right: 1px solid black;"></td>
		<td class="block" style="width: 15%; border-bottom: 1px solid black; border-right: 1px solid black;"></td>
		<td class="block" style="width: 15%; border-bottom: 1px solid black; border-right: 1px solid black;"></td>
		</tr>
		<tr>
        <td class="block" style="width: 15%;"></td>
		<td class="block" style="width: 15%;"></td>
		<td class="block" style="width: 25%;"></td>
		<td class="block" style="width: 15%; text-align: center; border-left: 1px solid black;border-bottom: 1px solid black; border-right: 1px solid black;">Siti Nurhasyanah<br>
		</td>
		<td class="block" style="width: 15%; text-align: center;border-bottom: 1px solid black; border-right: 1px solid black;">Park Sang Sun<br>
		</td>
		<td class="block" style="width: 15%; text-align: center; border-bottom: 1px solid black; border-right: 1px solid black;">Jhong Young Kyu<br>
		</td>
        </tr>
        <tr>
		<td class="block" style="width: 30%;"><h4>'.$rhdr->NmPrshn.'</h4></td>
        <td class="block" style="width: 30%;"></td>
		</tr>
		<tr>
		<td class="block" style="width: 30%;"></td>
        <td class="block" style="width: 30%;"></td>
		</tr>
		<tr>
		<td class="block" style="width: 30%;"></td>
		<td class="block" style="width: 30%;"></td>
		<td class="block" style="width: 10%;"></td>
		<td class="block" style="width: 10%; text-align: center; border-top: 1px solid black; border-left: 1px solid black; border-right: 1px solid black">NEW</td>
		<td class="block" style="width: 10%; text-align: center; border-top: 1px solid black; border-right: 1px solid black">REPEAT</td>
		<td class="block" style="width: 10%; text-align: center; border-top: 1px solid black; border-right: 1px solid black">OTHERS</td>
		</tr>
		<tr>
		<td class="block" style="width: 30%;"></td>
		<td class="block" style="width: 30%;"></td>
		<td class="block" style="width: 10%; border-right: 1px solid black; text-align: center;"></td>
		<td class="block" style="width: 10%; border-right: 1px solid black; border-top: 1px solid black; text-align: center;"></td>
		<td class="block" style="width: 10%; border-right: 1px solid black; border-top: 1px solid black; text-align: center;"></td>
		<td class="block" style="width: 10%; border-right: 1px solid black; border-top: 1px solid black; text-align: center;"></td>
		</tr>
		<tr>
		<td class="block" style="width: 30%;"></td>
		<td class="block" style="width: 30%;"></td>
		<td class="block" style="width: 10%; border-right: 1px solid black; text-align: center;"></td>
		<td class="block" style="width: 10%; border-right: 1px solid black; text-align: center;"></td>
		<td class="block" style="width: 10%; border-right: 1px solid black; text-align: center;"><img src= "'.$image5.'" width="30" style="margin-top:10px" /></td>
		<td class="block" style="width: 10%; border-right: 1px solid black; text-align: center;"></td>
		</tr>
		<tr>
		<td class="block" style="width: 30%;"></td>
		<td class="block" style="width: 30%;"></td>
		<td class="block" style="width: 10%; border-right: 1px solid black; text-align: center;"></td>
		<td class="block" style="width: 10%; border-right: 1px solid black; border-bottom: 1px solid black; text-align: center;"></td>
		<td class="block" style="width: 10%; border-right: 1px solid black; border-bottom: 1px solid black; text-align: center;"></td>
		<td class="block" style="width: 10%; border-right: 1px solid black; border-bottom: 1px solid black; text-align: center;"></td>
		</tr>
		<tr>
		<td class="block" style="width: 30%;"></td>
        <td class="block" style="width: 30%;"></td>
		</tr>
		<tr>
		<td class="block" style="width: 30%;">(..........................................................)</td>
        <td class="block" style="width: 30%;"></td>
		</tr>
    </tbody>
</table>
</font>
';

$filename = $rhdr->po_no;
// output the HTML content
$pdf->writeHTML($html4, 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');

?>        