<?php 
include "../include/config.php"; 
include "../function/inc_function.php"; 
$obc_id = isset($_REQUEST['obc_id']) ? $_REQUEST['obc_id'] :'';
$hd = mysql_fetch_object(mysql_query("SELECT a.*, b.prod_code, b.prod_name,b.prod_sat
									  FROM outexbc a INNER JOIN product b ON b.id=a.obc_prodid
									  WHERE a.id='$obc_id'"));
$comp = mysql_fetch_object(mysql_query("SELECT prof_city FROM profil"));									  
?>
<html>
<head>
<link rel='stylesheet' type='text/css' href="../include/css/print_styles.css" />	
</head>
<body>
<div id="popup">
<h3 align="center">DATA EXBC</h1>
<h5>Tanggal:<?=DateToIndo($hd->obc_date);?> </h5>
<hr size="3"></hr>
<p id="text1">
	Barang Jadi : <?=$hd->prod_code;?> - <?=$hd->prod_name;?> - <?=$hd->prod_sat;?> : <?=number_format($hd->obc_qty,2,'.',',');?><br>
	Dengan BOM List sebagai berikut:	
</p>
<table width="100%">
	<tr>
	</tr>
	<tr>
		<th>No.</th>
		<th>No Aju</th>
		<th>No Urut</th>
		<th>Jenis</th>
		<th>Nomor</th>
		<th>Tanggal</th>
		<th>Kode Barang</th>
		<th>Nama Barang</th>
		<th>Jumlah</th>
		<th>Satuan</th>
		<th>Harga</th>
		<th>Valuta</th>
		<th>Total</th>
		<th>No Kontrak</th>
		<th>Tgl Kontrak</th>
		<th>HSCode</th>
	</tr>
    <?php
	$no=1;
	$query = mysql_query("SELECT a.*, b.prod_code,b.prod_name,b.prod_sat,b.hscode
						  FROM outexbc_detail a
						  INNER JOIN product b ON b.id=a.obcd_prodid
						  WHERE a.obcd_hid='$obc_id' ORDER BY a.obcd_docdate, b.prod_code ASC");
	while($data=mysql_fetch_object($query)){
		#no aju
		if(empty($data->obcd_noaju)){
			$noaju = mysql_fetch_array(mysql_query("SELECT a.no_aju FROM incoming a INNER JOIN incoming_detail b ON b.incd_hid=a.id 
			          WHERE a.inch_status=20 AND a.inch_doctype='$data->obcd_doctype'
			          AND a.inch_docno='$data->obcd_docno' AND a.inch_docdate='$data->obcd_docdate' AND b.incd_prodid='$data->obcd_prodid'"));
			$no_aju = $noaju['no_aju'];
		}else{
			$no_aju = $data->obcd_noaju;			
		}
		#no urut
		if(empty($data->obcd_nourut)){
			$nourut = mysql_fetch_array(mysql_query("SELECT b.no_urut FROM incoming a INNER JOIN incoming_detail b ON b.incd_hid=a.id 
			          WHERE a.inch_status=20 AND a.inch_doctype='$data->obcd_doctype'
			          AND a.inch_docno='$data->obcd_docno' AND a.inch_docdate='$data->obcd_docdate' AND b.incd_prodid='$data->obcd_prodid'"));
			$no_urut = $nourut['no_urut'];
		}else{
			$no_urut = $data->obcd_nourut;			
		}
		#price/unit
		$prc = mysql_fetch_array(mysql_query("SELECT b.incd_price, b.incd_price_usd, b.incd_qty FROM incoming a INNER JOIN incoming_detail b ON b.incd_hid=a.id 
			          WHERE a.inch_status=20 AND a.inch_doctype='$data->obcd_doctype'
			          AND a.inch_docno='$data->obcd_docno' AND a.inch_docdate='$data->obcd_docdate' AND b.incd_prodid='$data->obcd_prodid'"));
		if($data->obcd_currency=="IDR" || empty($data->obcd_currency)){
			$unitprice = $prc['incd_price']/$prc['incd_qty'];
		}else{
			$unitprice = $prc['incd_price_usd']/$prc['incd_qty'];
		}
		$tprice = $data->obcd_qty*$unitprice;
		#no kontrak
		if(empty($data->no_kontrak)){
			$nokontrak = mysql_fetch_array(mysql_query("SELECT a.no_kontrak FROM incoming a INNER JOIN incoming_detail b ON b.incd_hid=a.id 
			          WHERE a.inch_status=20 AND a.inch_doctype='$data->obcd_doctype'
			          AND a.inch_docno='$data->obcd_docno' AND a.inch_docdate='$data->obcd_docdate' AND b.incd_prodid='$data->obcd_prodid'"));
			$no_kontrak = $nokontrak['no_kontrak'];
		}else{
			$no_kontrak = $data->no_kontrak;			
		}
		#tgl kontrak
		if(empty($data->tgl_kontrak)){
			$tglkontrak = mysql_fetch_array(mysql_query("SELECT a.tgl_kontrak FROM incoming a INNER JOIN incoming_detail b ON b.incd_hid=a.id 
			          WHERE a.inch_status=20 AND a.inch_doctype='$data->obcd_doctype'
			          AND a.inch_docno='$data->obcd_docno' AND a.inch_docdate='$data->obcd_docdate' AND b.incd_prodid='$data->obcd_prodid'"));
			$tgl_kontrak = $tglkontrak['tgl_kontrak'];
		}else{
			$tgl_kontrak = $data->tgl_kontrak;			
		}
	?>
	 <tr>
		<td align="center"><?=$no;?>.</td>
		<td align="center"><?=$no_aju;?></td>
		<td align="center"><?=$no_urut;?></td>
		<td align="center"><?=$data->obcd_doctype;?></td>
		<td align="center"><?=$data->obcd_docno;?></td>
		<td align="center"><?=$data->obcd_docdate;?></td>
		<td><?=$data->prod_code;?></td>
		<td><?=$data->prod_name;?></td>
		<td align="right"><?=number_format($data->obcd_qty,5,'.',',');?></td>
		<td align="center"><?=$data->prod_sat;?></td>
		<td align="right"><?=number_format($unitprice,2,'.',',');?></td>
		<td align="center"><?=$data->obcd_currency;?></td>
		<td align="right"><?=number_format($tprice,2,'.',',');?></td>
		<td align="center"><?=$no_kontrak;?></td>
		<td align="center"><?=$tgl_kontrak;?></td>
		<td align="center"><?=$data->hscode;?></td>
	</tr>	
	<?php $no++;} ?>
</table>
<!--<p id="text1">
	Atas perhatian dan kerjasamanya disampaikan terima kasih.<br>
	<?=$comp->prof_city;?>, <?=DateToIndo($hd->outh_sjdate);?><br>
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Hormat kami <br><br><br><br><br><br>
	(............................................)
	
</p>-->
</div>
</body>
</html>
