<?php
include "../../include/config.php";
include "../../function/inc_function.php";
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="data_konversi_subkon_peb'.date('Y-m-d H:i:s').'.xls"');
header('Cache-Control: max-age=0');

$fromdate = $_REQUEST['fromdate'];
$todate = $_REQUEST['todate'];
?>
<table width="100%" border="0">
    <tr>
  		<td colspan="11" align="left"><strong>DATA KONVERSI BARANG</strong></td>
    </tr>
	<tr>
  		<td colspan="11" align="left"><strong>PERIODE : <?=$fromdate;?> s/d <?=$todate;?></strong></td>
    </tr>
</table>	
<table width="100%" border="1">	
  <tr>
    <th align="center" bgcolor="#D1D1D1" rowspan="2">NO</th>
	<th align="center" bgcolor="#D1D1D1" rowspan="2">NOMOR TRANSAKSI</th>
    <th align="center" bgcolor="#D1D1D1" rowspan="2">TANGGAL</th>
	<th align="center" bgcolor="#D1D1D1" colspan="4">BARANG JADI</th>
	<th align="center" bgcolor="#D1D1D1" colspan="4">DETAIL BAHAN BAKU/PENOLONG/WIP</th>
  </tr>
  <tr>
  	<th align="center" bgcolor="#D1D1D1">KODE</th>
	<th align="center" bgcolor="#D1D1D1">NAMA</th>
	<th align="center" bgcolor="#D1D1D1">JUMLAH</th>
	<th align="center" bgcolor="#D1D1D1">SATUAN</th>
	<th align="center" bgcolor="#D1D1D1">KODE</th>
	<th align="center" bgcolor="#D1D1D1">NAMA</th>
	<th align="center" bgcolor="#D1D1D1">JUMLAH</th>
	<th align="center" bgcolor="#D1D1D1">SATUAN</th>
  </tr>
	<?php		
		$qd = mysql_query("SELECT a.kv_no, a.kv_date, b.prod_code hcode, b.prod_name hname, b.prod_sat hsat, a.kv_qty,
		d.prod_code dcode, d.prod_name dname, d.prod_sat dsat, c.kvd_qty 
		FROM konversi_external a INNER JOIN product b ON b.id=a.kv_prodid
		INNER JOIN konversi_external_detail c ON c.kvd_hid=a.id INNER JOIN product d ON d.id=c.kvd_prodid
		WHERE a.kv_date BETWEEN '$fromdate' AND '$todate' AND a.kv_status<>100 AND kv_type='KONVERSI' ORDER BY a.id DESC");
		$no = 1;
		while($dd=mysql_fetch_object($qd)){	
		?> 
		 <tr>
			<td align="center"><?=$no;?></td>
			<td align="center"><?=$dd->kv_no;?></td>
			<td align="center"><?=$dd->kv_date;?></td>
			<td align="left"><?=$dd->hcode;?></td>
			<td align="left"><?=$dd->hname;?></td>
			<td align="right"><?=number_format($dd->kv_qty,2,'.','');?></td>
			<td align="center"><?=$dd->hsat;?></td>
			<td align="left"><?=$dd->dcode;?></td>
			<td align="left"><?=$dd->dname;?></td>
			<td align="right"><?=number_format($dd->kvd_qty,2,'.','');?></td>
			<td align="center"><?=$dd->dsat;?></td>
		  </tr>
      <?php $no++; }  ?>	
</table>