<?php 
ob_start();
include "../../include/config.php"; 
include "../../function/inc_function.php"; 
$po_no = isset($_REQUEST['po_no']) ? $_REQUEST['po_no'] :'';
$hd = mysql_fetch_array(mysql_query("SELECT a.*, b.sup_name, b.sup_address, b.sup_city, c.cust_name, c.cust_address, c.cust_city, d.bbt_tipe, e.pay_type 
	 FROM purchase_order a 
	 LEFT JOIN supplier b ON b.id=a.po_idsupp 
	 LEFT JOIN customer c ON c.id=a.po_idcust 
	 LEFT JOIN buku_besar_tipe d ON d.id=a.po_ptype
	 LEFT JOIN payment_type e ON a.po_ptype=e.id
	 WHERE a.po_no='$po_no'"));
	 if($hd['po_type']=="Purchasing"){
		 $nama   = $hd['sup_name'];
		 $alamat = $hd['sup_address'];
		 $kota   = $hd['sup_city'];
	 }else{
		 $nama   = $hd['cust_name'];
		 $alamat = $hd['cust_address'];
		 $kota   = $hd['cust_city'];
	 }
$comp = mysql_fetch_array(mysql_query("SELECT * FROM profil"));	
?>
<html>
<head>
<link rel='stylesheet' type='text/css' href="../../include/css/printdoc_styles.css" />	
<style>
	.tables td {
		height:none;
		border-top:true;
		border-bottom:true;
	}
  </style>
</head>
<body>
<table class="tables" style="border:none;">
	<tr>
		<td style="width:300px; border:none;"><img src="../../images/logo_rollstone.png" style="width:200px;"></td>
		<td  style="width:500px; border:none; text-align:center; font-size:20px; font-style:bold;">PURCHASE ORDER</td>
	</tr>	
</table>
<br><br>
<table class="tables">
	<tr>
		<td colspan="2" style="border:none;"><b><?=$comp['prof_name'];?></b></td>
	</tr>
	<tr>
		<td colspan="2" style="border:none;">Kawasan Berikat Nusantara - Cakung</td>
	</tr>
	<tr>
		<td colspan="2" style="border:none;">Jl. Jawa 14 Blok A.06, Jakarta, 14140</td>
	</tr>
	<tr>
		<td colspan="2" style="border:none;"><br></td>
	</tr>
	<tr>
		<td style="border:none;">P/O No.</td>
		<td style="border:none;">: <?=$hd['po_no'];?></td>
	</tr>
	<tr>
		<td style="border:none;">P/O Date</td>
		<td style="border:none;">: <?=$hd['po_date'];?></td>
	</tr>
	<tr>
		<td style="border:none;">Issue By</td>
		<td style="border:none;">: <?=$hd['po_pic'];?></td>
	</tr>	
	<tr>
		<td style="border:none;">Supplier</td>
		<td style="border:none;">: <?=$hd['sup_name'];?></td>
	</tr>
	<tr>
		<td style="border:none;">Attention</td>
		<td style="border:none;">: </td>
	</tr>
</table>
<br><br><br>
<table border="1" class="tables">
	<tr>
		<th>No.</th>
		<th style="width:200px;">Nama Barang</th>
		<th style="width:70px;">Spec</th>
		<th style="width:70px;">Color</th>
		<th style="width:50px;">Unit</th>
		<th style="width:50px;">Qty</th>
		<th style="width:50px;">Curr</th>
		<th>Price</th>
		<th>Amount</th>
		<th>Delivery Date</th>
		<th>Payment Term</th>
		<th style="width:140px;">Deskripsi Pemakaian</th>
	</tr>
    <?php
	$no=0; $tqty=0; $tamount=0;
	$query = mysql_query("SELECT a.id,a.pod_qty,a.pod_price,a.pod_amount,b.prod_code,b.prod_name,b.prod_sat, a.pod_desc, b.prod_spec, b.prod_color
						  FROM purchase_order_detail a
						  INNER JOIN product b ON b.id=a.pod_prodid
						  WHERE a.po_no='$hd[po_no]' AND a.pod_status=10 ORDER BY a.id ASC ");
	while($data=mysql_fetch_array($query)){
		$no++;
		$tqty    = $tqty+$data['pod_qty'];
		$tamount = $tamount+$data['pod_amount'];
	?>
	 <tr>
		<td align="center"><?=$no;?></td>
		<td><?=wordwrap($data['prod_name'],30,"<br>\n");?></td>
		<td><?=$data['prod_spec'];?></td>
		<td><?=$data['prod_color'];?></td>
		<td align="center"><?=$data['prod_sat'];?></td>
		<td align="right"><?=number_format($data['pod_qty'],2,'.',',');?></td>
		<td align="center"><?=$hd['po_currency'];?></td>
		<td align="right"><?=number_format($data['pod_price'],2,'.',',');?></td>
		<td align="right"><?=number_format($data['pod_amount'],2,'.',',');?></td>
		<td align="center"><?=$hd['po_deldate'];?></td>
		<td><?=$hd['bbt_tipe'];?></td>
		<td><?=wordwrap($data['pod_desc'],30,"<br>\n");?></td>
	</tr>
	<?php } ?>
	<tr>
		<td colspan="5" style="text-align:right;"><b>Grand Total</b></td>
		<td><?=number_format($tqty,2,'.',',');?></td>
		<td colspan="2"></td>
		<td><?=number_format($tamount,2,'.',',');?></td>
		<td colspan="3"></td>
	</tr>
</table>
<br><br><br><br>
<table class="tables">
	<tr>
		<td style="width:680px; border:none;">
			<b>REQUIREMENTS :</b><br>
			Please confirm received purchase order as soon as possible by email<br>
			Please Mentioned Purchase order number on Delivery order and Invoice<br>
			Please supply material or item in good quality<br>
			All order must be strictly follow our delivery request<br>
			Please send sample item for special item and necessary item<br>
			Please provide and share Surat Jalan , Invoice and Packing List by email in order to create SPPB & BC 4.0
		</td>
		<td style="vertical-align:middle; border:none;">
			<table>
				<tr>
					<td style="width:100px; text-align:center;"><b>Applicant</b></td>
					<td style="width:100px; text-align:center;"><b>Dept Head</b></td>
					<td style="width:100px; text-align:center;"><b>Presdir</b></td>
				</tr>
				<tr>
					<td><br><br><br><br><br><br><br></td>
					<td></td>
					<td></td>
				</tr>
			</table>
		</td>
	</tr>
</table>

</body>
</html>
<?php  
	 #PDF
	 $filename="$po_no.pdf";   
	 $content = ob_get_clean();  
	 //$content = '<page style="font-family: Arial;">'.nl2br($content).'</page>';  
	 require_once('../../function/html2pdf/html2pdf.class.php');  
	 try  
	 {  
	  //$html2pdf = new HTML2PDF('P',array(240,280),'en', false, 'ISO-8859-15',array(0, 0, 0, 0));  
	  $html2pdf = new HTML2PDF('L','A4','en', false, 'ISO-8859-15',array(0, 5, 5, 5));
	  $html2pdf->setDefaultFont('Arial');  
	  $html2pdf->writeHTML($content, isset($_GET['vuehtml']));  
	  $html2pdf->Output($filename);  
	 }  
	 catch(HTML2PDF_exception $e
	 ) { echo $e; } 
?> 