<?php
	include '../../inc/inc.koneksi.php';
	include '../../inc/fungsi_tanggal.php';
	
	$cari	= $_GET[cari];
	$nu=1;
	
	$sql2= mysql_query("SELECT * FROM company");
	while($r2=mysql_fetch_array($sql2)){
		$kop1 = $r2[nama1];
		$kop2 = $r2[nama2];
		$kop3 = $r2[alamat];
	}
	
	if($cari=='')
		$kel='KELOMPOK : Keseluruhan';
		
	else
		$kel='KELOMPOK : $cari';

	$content = "<b><li>$kop1</li></b>
		<li>$kop2</li>
		<li>$kop3</li>
		<br>
		<b><li>BLANGKO STOK OPNAME</li>
		<li>$kel</li></b>
		<br>
	
		<table width='650' border='1' style='border-collapse:collapse'>
		<tr>
			<th>No.</th>
			<th>Kode</th>
			<th>Nama Barang</th>
			<th>Satuan</th>
			<th>Harga Pokok</th>
			<th>Jumlah Stok</th>
			<th>Hasil Opname</th>
		</tr>";
	
		if(!empty($cari))
			$sql = "SELECT * FROM stock WHERE (kode_st LIKE '%$cari%' OR nama_st LIKE '%$cari%') ORDER BY kode_st";
		else
			$sql = "SELECT * FROM stock ORDER BY kode_st";
		$query = mysql_query($sql);		
	
		while($r_data=mysql_fetch_array($query)){
			$nu=$nu+1;
		
			$content .= "<td align='right'>$nu</td>
				<td>$r_data[kode_st]</td>
				<td>$r_data[nama_st]</td>
				<td>$r_data[satuan]</td>
				<td align='right'>".number_format($r_data[hg_beli],2)."</td>
				<td align='right'>".number_format($r_data[jml_stok],2)."</td>
				<td></td>
			<tr>";
		}
		$content .= "</table>";

		header("Content-type: application/x-msdownload");
		header("Content-Disposition: attachment; filename=blangko_so.xls");
		header("Pragma: no-cache");
		header("Expires: 0");
		echo $content;
?>