<?php
	include '../../inc/inc.koneksi.php';	
	include '../../inc/fungsi_tanggal.php';

	$tgl_awal = $_GET['tgl_awal'];
	$tgl_akhir= $_GET['tgl_akhir'];
	
	$content = "<b><li>DAFTAR STOK OPNAME</li>
		<li>TANGGAL : ".jin_date_str($tgl_awal)." S/D ".jin_date_str($tgl_akhir)."</li></b>
		<br>
	
		<table width='390' 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>Jml. Stok</th>			
			<th>Jml. Opname</th>
			<th>Selisih</th>
			<th>Nilai Selisih</th>
			<th>Posting</th>
		</tr>";
		
		$sql1 = "SELECT * FROM st_opname WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' GROUP BY kode_op";
		$query1 = mysql_query($sql1);
		
		$no=1;
		$tnilai=0;
		
		while($data1=mysql_fetch_array($query1)){
			$kodeop = $data1[kode_op];

			$content .= "<tr>	
				<td></td>
				<td></td>
				<td><b>$data1[kode_op] - ".jin_date_str($data1[tanggal])."</b></td>
				<td><b>Tanki : $data1[gudang]</b></td>
			</tr>";
			
			$sql = "SELECT * FROM st_opname WHERE kode_op='$kodeop' ORDER BY kode_op";
			$query = mysql_query($sql);
			$snilai = 0;
			$no=1;
			
			while($data=mysql_fetch_array($query)){
				
				$content .= "<tr>	
					<td align='center'>$no</td>
					<td align='center'>$data[kode_st]</td>
					<td>$data[nama_st]</td>
					<td>$data[satuan]</td>
					<td align='right'>".number_format($data[hg_beli],0)."</td>
					<td align='right'>".number_format($data[jml_stok],2)."</td>
					<td align='right'>".number_format($data[jml_opn],2)."</td>
					<td align='right'>".number_format($data[jml_sls],2)."</td>					
					<td align='right'>".number_format($data[nilai_sls],0)."</td>
					<td align='center'>$data[posting]</td>
				</tr>";
				$no++;
				$snilai=$snilai+$data[nilai_sls];
			}
			$content .= "<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td align='right'>Jumlah</td>
				<td align='right'>".number_format($snilai,0)."</td>
			</tr>";
			$tnilai=$tnilai+$snilai;
		}
		
		$content .= "<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td align='right'>Total</td>
				<td align='right'>".number_format($tnilai,0)."</td>
			</tr>";
		$content .= "</table>";
		
		header("Content-type: application/x-msdownload");
		header("Content-Disposition: attachment; filename=daftar_so.xls");
		header("Pragma: no-cache");
		header("Expires: 0");
		echo $content;
?>