<?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('helveticaBI', '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)
$pdf->Cell(0, 0, 'INVOICE', 0, 1, 'C', 0, '', 1);

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

$html ="";
$html .= 
'
<table style="table-layout: auto; width: 100%;" border="0">
<tbody>
        <tr>
			<td class="block" style="width: 70%;">Mesenger / Customer name</td>
			<td class="block" style="width: 8%;">Inv No</td>
			<td style="width: 2%;">:</td>
			<td class="block" style="width: 20%;"><h4>'.$rhdr->inv_no.'</h4></td>
		</tr>
		<tr>
			<td class="block" style="width: 6%;"></td>
			<td class="block" style="width: 62%;"><h4>'.$rhdr->NmPrshn.'</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: 2%;"></td>
        <td class="block" style="width: 62%;"><h4>'.$rhdr->AlmtPrshn.'</h4></td>
        <td class="block" style="width: 6%;"></td>
        <td style="width: 6%;"></td>
        <td class="block" style="width: 22%;"></td>
        </tr>
		<tr>
			<td class="block" style="width: 6%;"></td>
			<td class="block" style="width: 64%;"></td>
			<td class="block" style="width: 8%;">Date</td>
			<td style="width: 2%;">:</td>
			<td class="block" style="width: 20%;"><h4>'.$rhdr->Fdate.'</h4></td>
		</tr>
		<tr>
			<td class="block" style="width: 6%;"></td>
			<td class="block" style="width: 64%;"></td>
			<td class="block" style="width: 6%;"></td>
			<td style="width: 2%;"></td>
			<td class="block" style="width: 20%;"></td>
		</tr>
		<tr>
			<td class="block" style="width: 6%;"></td>
			<td class="block" style="width: 62%;"></td>
			<td class="block" style="width: 8%;"></td>
			<td style="width: 2%;"></td>
			<td class="block" style="width: 20%;"></td>
		</tr>
		</tbody>
	</table>
';

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

$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: 20%;">Quantity</td>
		<td style="text-align: center; width: 25%;">Unit Price</td>
		<td style="text-align: center; width: 25%;">Amount ('.$rhdr->currency.')</td>
	</tr>';
	$i = 1;
    foreach($rdet as $r){
      $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: 20%;">'.$r->Fqty.'/Pcs</td>
			<td style="text-align: center; width: 25%;">'.$rhdr->currency.'.'.$r->Fprice.'</td>
            <td style="text-align: center; width: 25%;">'.$rhdr->currency.'.'.$r->amount.'</td>
        </tr>
';
$jmltax = $rhdr->tax;
$jmlamount = $rhdr->tot_amount;
if($jmltax == 'ppn'){
    $pajak = ($jmlamount/'10%');
    $pajak_format = number_format("$pajak",2,",",".");
}else if($jmltax == 'pph23'){
    $pajak = ($jmlamount/'2%');
    $pajak_format = number_format("$pajak",2,",",".");
}else if($jmltax == 'ppn+pph23'){
    $pajakppn = ($jmlamount*0.01);
    $pajak23 = ($jmlamount*0.02);
    $pajak_formatppn = number_format("$pajakppn",2,",",".");
    $pajak_formatpph23 = number_format("$pajak23",2,",",".");
}else{
    $pajak = '0';
    $pajak_format = number_format("$pajak",2,",",".");
}
$total = $jmlamount+$pajak;
$total_format = number_format("$total",2,",",".");
$totalppn = $jmlamount+$pajak_formatppn;
$totalppn_format = number_format("$totalppn",2,",",".");
$totalpph23 = $totalppn-$pajak_formatpph23;
$totalpph23_format = number_format("$totalpph23",2,",",".");
$total_formatfix = number_format("$totalpph23",2,",",".");
}

if($jmltax == 'ppn+pph23'){
$html3.= 
'           <tr>
                <td style="text-align: center; width: 5%;"></td>
                <td style="text-align: left; width: 25%;">Sub Total</td>
                <td style="text-align: center; width: 20%;"></td>
                <td style="text-align: center; width: 25%;"></td>
                <td style="text-align: center; width: 25%;"><strong>'.$rhdr->currency.'.'.$rhdr->tot_amount.'</strong></td>
            </tr>
            <tr>
                <td style="text-align: center; width: 5%;"></td>
                <td style="text-align: left; width: 25%;">PPN</td>
                <td style="text-align: center; width: 20%;"></td>
                <td style="text-align: center; width: 25%;"></td>
                <td style="text-align: center; width: 25%;">'.$rhdr->currency.'.'.$pajak_formatppn.'</td>
            </tr>
            <tr>
                <td style="text-align: center; width: 5%;"></td>
                <td style="text-align: left; width: 25%;">Sub Total after PPN</td>
                <td style="text-align: center; width: 20%;"></td>
                <td style="text-align: center; width: 25%;"></td>
                <td style="text-align: center; width: 25%;"><strong>'.$rhdr->currency.'.'.$totalppn_format.'</strong></td>
            </tr>
            <tr>
                <td style="text-align: center; width: 5%;"></td>
                <td style="text-align: left; width: 25%;">PPH23</td>
                <td style="text-align: center; width: 20%;"></td>
                <td style="text-align: center; width: 25%;"></td>
                <td style="text-align: center; width: 25%;">'.$rhdr->currency.'.'.$pajak_formatpph23.'</td>
            </tr>
            <tr>
                <td style="text-align: center; width: 5%;"></td>
                <td style="text-align: left; width: 25%;">Sub Total after PPH 23</td>
                <td style="text-align: center; width: 20%;"></td>
                <td style="text-align: center; width: 25%;"></td>
                <td style="text-align: center; width: 25%;"><strong>'.$rhdr->currency.'.'.$totalpph23_format.'</strong></td>
            </tr>
            <tr>
                <td colspan="4" rowspan="" style="text-align: center;"><strong>Total Amount</strong></td>
                <td colspan="1" rowspan="" style="text-align: center;"><br><strong>'.$rhdr->currency.'.'.$total_formatfix.'</strong></td>
            </tr>
        </table>';
}else if($jmltax == 'none'){
$html3.=
        '<tr>
            <td style="text-align: center; width: 5%;"></td>
            <td style="text-align: left; width: 25%;">Sub Total</td>
            <td style="text-align: center; width: 20%;"></td>
            <td style="text-align: center; width: 25%;"></td>
            <td style="text-align: center; width: 25%;"><strong>'.$rhdr->currency.'.'.$rhdr->tot_amount.'</strong></td>
        </tr>
        <tr>
            <td colspan="4" rowspan="" style="text-align: center;"><strong>Total Amount</strong></td>
            <td colspan="1" rowspan="" style="text-align: center;"><br><strong>'.$rhdr->currency.'.'.$total_format.'</strong></td>
        </tr>
        </table>';
}else{
    $html3.=
            '<tr>
                <td style="text-align: center; width: 5%;"></td>
                <td style="text-align: left; width: 25%;">Sub Total</td>
                <td style="text-align: center; width: 20%;"></td>
                <td style="text-align: center; width: 25%;"></td>
                <td style="text-align: center; width: 25%;"><strong>'.$rhdr->currency.'.'.$rhdr->tot_amount.'</strong></td>
            </tr>
            <tr>
                <td style="text-align: center; width: 5%;"></td>
                <td style="text-align: left; width: 25%;">'.$rhdr->tax.'</td>
                <td style="text-align: center; width: 20%;"></td>
                <td style="text-align: center; width: 25%;"></td>
                <td style="text-align: center; width: 25%;"><strong>'.$rhdr->currency.'.'.$pajak_format.'</strong></td>
            </tr>
            <tr>
                <td colspan="4" rowspan="" style="text-align: center;"><strong>Total Amount</strong></td>
                <td colspan="1" rowspan="" style="text-align: center;"><br><strong>'.$rhdr->currency.'.'.$total_format.'</strong></td>
            </tr>
            </table>';
    }

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

$pdf->SetFont('helvetica', '', 9);
$html4="";
// create some HTML content
$html4 .= 
'<table style="table-layout: auto; width: 100%;" border="0">
    <tbody>
        <tr>
			<td class="block" style="width: 35%;">Amount in words :</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%;"><i><h4>'.$rhdr->terbilang.'</h4></i></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%;"></td>
            <td style="width: 35%;"></td>
            <td class="block" style="width: 30%;"></td>
		</tr>
		<tr>
			<td class="block" style="width: 35%;">For the payment, should be transferred to :</td>
            <td style="width: 35%;"></td>
            <td class="block" style="width: 30%;"></td>
		</tr>
        <tr>
            <td style="width: 7%;"></td>
			<td class="block" style="width: 35%;"><h4>PT. KOSTEC INDONESIA</h4></td>
            <td style="width: 35%;"></td>
            <td class="block" style="width: 15%;"></td>
		</tr>
		<tr>
            <td class="block" style="width: 20%;">- BII - Lippo Cikarang</td>
            <td class="block" style="width: 53%;"></td>
            <td class="block" style="width: 27%; text-align: center;"><strong>Best Regards</strong></td>
        </tr>
        <tr>
            <td style="width: 8%;"></td>
			<td class="block" style="width: 15%;">IDR</td>
            <td style="width: 2%;">:</td>
            <td class="block" style="width: 15%;">2.246.02544.9</td>
            <td class="block" style="width: 33%;"></td>
            <td class="block" style="width: 27%; text-align: center;"><h4>PT.KOSTEC INDONESIA</h4></td>
        </tr>
        <tr>
            <td style="width: 8%;"></td>
            <td class="block" style="width: 15%;">USD</td>
            <td style="width: 2%;">:</td>
            <td class="block" style="width: 15%;">2.246.10156.6</td>
        </tr>
        <tr>
            <td class="block" style="width: 2%;">-</td>
            <td class="block" style="width: 20%;">Bank Permata Cikarang</td>
            <td class="block" style="width: 2%;"></td>
            <td class="block" style="width: 20%;"></td>
            <td style="width: 35%;"></td>
            <td class="block" style="width: 15%;"></td>
        </tr>
        <tr>
            <td style="width: 8%;"></td>
            <td class="block" style="width: 15%;">IDR</td>
            <td style="width: 2%;">:</td>
            <td class="block" style="width: 15%;">0.874.995.08.8</td>
        </tr>
        <tr>
            <td class="block" style="width: 2%;">-</td>
            <td class="block" style="width: 20%;">KEB Indonesia - Jakarta</td>
            <td class="block" style="width: 2%;"></td>
            <td class="block" style="width: 20%;"></td>
            <td style="width: 35%;"></td>
            <td class="block" style="width: 15%;"></td>
        </tr>
        <tr>
            <td style="width: 8%;"></td>
            <td class="block" style="width: 15%;">IDR</td>
            <td style="width: 2%;">:</td>
            <td class="block" style="width: 15%;">221-1570</td>
        </tr>
        <tr>
            <td style="width: 8%;"></td>
            <td class="block" style="width: 15%;">USD</td>
            <td style="width: 2%;">:</td>
            <td class="block" style="width: 15%;">25-8101</td>
        </tr>
		<tr>
			<td class="block" style="width: 30%;"></td>
			<td class="block" style="width: 43%;"></td>
			<td class="block" style="width: 27%; text-align: center;"><h4><u>Park Sang Sun</u></h4></td>
        </tr>
        <tr>
			<td class="block" style="width: 30%;"></td>
			<td class="block" style="width: 43%;"></td>
			<td class="block" style="width: 27%; text-align: center;"><h4>Direktur Oprasional</h4></td>
		</tr>
    </tbody>
</table>
';

$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');

?>        