<?php 
$po_no = isset($_REQUEST['po_no']) ? $_REQUEST['po_no'] :'';
include "../../include/config.php"; 
include "../../function/inc_function.php"; 
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="data_po_'.$po_no.'.xls"');
header('Cache-Control: max-age=0');


$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>
</head>
<body>
<table border="1">
	<tr>
		<td>
			<table class="tables" style="border:none;">
				<tr>
					<td colspan="2"><img src="../../images/logo_rollstone.png" style="width:200px;"></td>
					<td colspan="10" style="text-align:center; font-size:18px; font-family:Arial Unicode MS;"><b>P U R C H A S E &nbsp; &nbsp; O R D E R</b></td>
				</tr>	
			</table>
			<br><br>
			<table border="0">
				<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;">: </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;">: <?=$hd['po_pic'];?></td>
				</tr>
			</table>
			<br><br><br>
			<table border="1">
				<tr>
					<th style="background-color:#CCCCCC; height:30px;">No.</th>
					<th style="background-color:#CCCCCC;">Nama Barang</th>
					<th style="width:70px; background-color:#CCCCCC;">Spec</th>
					<th style="width:70px; background-color:#CCCCCC;">Color</th>
					<th style="width:50px; background-color:#CCCCCC;">Unit</th>
					<th style="width:50px; background-color:#CCCCCC;">Qty</th>
					<th style="width:50px; background-color:#CCCCCC;">Curr</th>
					<th style="background-color:#CCCCCC;">Price</th>
					<th style="background-color:#CCCCCC;">Amount</th>
					<th style="background-color:#CCCCCC;">Delivery Date</th>
					<th style="background-color:#CCCCCC;">Payment Term</th>
					<th style="background-color:#CCCCCC;">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,
									  CONCAT_WS(' - ', prod_code, prod_name) codename
									  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['codename'],30,"<br>\n");?></td>
					<td><?=$data['prod_spec'];?></td>
					<td><?=$data['prod_color'];?></td>
					<td><?=$data['prod_sat'];?></td>
					<td align="right"><?=number_format($data['pod_qty'],2,'.','');?></td>
					<td><?=$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><?=$hd['po_deldate'];?></td>
					<td><?=$hd['pay_type'];?></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 colspan="6" 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 colspan="3"style="vertical-align:middle;">
						<table border="1">
							<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></td>
								<td></td>
								<td></td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table

</body>
</html>