<?php
include "../../include/config.php";
include "../../function/inc_function.php";
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="export_stock_awal'.get_datetime().'.xls"');
header('Cache-Control: max-age=0');
?>
<table width="100%" border="1">
	<thead>
	<tr>
		<th>No.</th>
		<th>Tanggal</th>
		<th>Kode Barang</th>
		<th>Nama Barang</th>
		<th>Satuan</th>
		<th>Jumlah</th>
		<th>Lokasi</th>
		<th>Lokasi Detail</th>
	</tr>
		</thead>
	<tbody>
	<?php		
	  	$no=1;
		$qd = mysql_query("SELECT a.*, b.prod_code, b.prod_name, b.prod_sat, c.prod_cat, d.mw_name FROM stock a INNER JOIN product b ON b.id=a.stock_prodid
		                   INNER JOIN product_category c ON c.id=b.prod_cat LEFT JOIN master_warehouse d ON d.id=a.stock_whid WHERE a.stock_status=10 ORDER BY c.id, b.prod_code ASC");
		while($dd=mysql_fetch_object($qd)){	
			if($dd->stock_loc==1){
				$loc = "Gudang Bahan Baku";
			}elseif($dd->stock_loc==2){
				$loc = "Gudang Produksi/WIP";
			}if($dd->stock_loc==3){
				$loc = "Gudang FG & Scrap";
			}if($dd->stock_loc==4){
				$loc = "Gudang Mesin/Area Produksi";
			}	
		?> 
		   <tr">
			<td align="center"><?=$no;?>.</td>
			<td align="left"><?=$dd->stock_date;?></td>
			<td align="left"><?=$dd->prod_code;?></td>
			<td align="left"><?=$dd->prod_name;?></td>
			<td align="left"><?=$dd->prod_sat;?></td>
			<td align="right"><?=number_format($dd->stock_qty,2,'.','');?></td>
			<td align="left"><?=$loc;?></td>
			<td align="left"><?=$dd->mw_name;?></td>
		  </tr>
      <?php $no++; }  ?>	
	  </tbody>
</table>