<?php
	include '../../inc/inc.koneksi.php';	
	
	$cari = $_GET['cari'];
	$jml = 0;
	$tgllap =date('d-m-Y');
	if (!empty($cari)){
		$grup='KELOMPOK : '.$cari;
	}else{
		$grup='KESELURUHAN';
	}
		
	$content = "<b><li>DAFTAR PERSEDIAAN BARANG DAGANGAN</li>
		<li>$grup</li>
		<li>PER TANGGAL $tgllap</li></b>
		<br>
	
		<table width='390' border='1' style='border-collapse:collapse'>
		<tr>
			<th>No.</th>
			<th>Kode</th>
			<th>Nama Barang</th>
			<th>Barcode</th>
			<th>Satuan</th>
			<th>Satuan 1</th>
			<th>Konversi</th>
			<th>Harga Jual</th>
			<th>Jumlah Stok</th>			
		</tr>";
	
		if (!empty($cari)){			
			$query2	= "SELECT * FROM st_group WHERE (nama_gr LIKE '%$cari%' or kode_gr LIKE '%$cari%') ORDER BY kode_gr";
		}
		else{
			$query2	= "SELECT * FROM st_group ORDER BY kode_gr";
		}		
		$data2	= mysql_query($query2);
		
		$tnilai=0;
		while($r2=mysql_fetch_array($data2)){
			$kodegr=$r2['kode_gr'];
		
			$content .= "<tr>	
				<td></td>
				<td><b>$r2[kode_gr]</b></td>				
				<td><b>$r2[nama_gr]</b></td>
			</tr>";
		
			$sql = "SELECT * FROM stock WHERE kode_gr='$kodegr' ORDER BY kode_st ";		
			$query = mysql_query($sql);
		
			$no=1;
			while($r=mysql_fetch_array($query)){			
				$content .= "<tr>	
					<td>$no</td>
					<td>$r[kode_st]</td>
					<td>$r[nama_st]</td>
					<td>$r[barcode]</td>
					<td>$r[satuan]</td>
					<td>$r[satuan1]</td>
					<td align='center'>$r[konversi]</td>
					<td align='right'>$r[hg_jual]</td>				
					<td align='right'>$r[jml_stok]</td>
				</tr>";			
				$no++;
				$jml++;
			}
		}		
		$content .= "</table>";
		
		$content .= "<table>
			<tr>
				<td>Jumlah Data : $jml</td>
			</tr>
			</table>";
				
		header("Content-type: application/x-msdownload");
		header("Content-Disposition: attachment; filename=daftar_stkas.xls");
		header("Pragma: no-cache");
		header("Expires: 0");
		echo $content;
?>