<script type="text/javascript">
$(document).ready(function() {
    $(function() {
        $("#theList tr:even").addClass("stripe1");
        $("#theList tr:odd").addClass("stripe2");

        $("#theList tr").hover(
            function() {
                $(this).toggleClass("highlight");
            },
            function() {
                $(this).toggleClass("highlight");
            }
        );
    });
});
</script>

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

$tgl_awal	= $_GET['tgl_awal'];
$tgl_akhir	= $_GET['tgl_akhir'];
$gudang		= $_GET['gudang'];

echo "<table id='theList' width='100%'>
		<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>";
		if($gudang=='')
			$query1 = mysql_query("SELECT * FROM st_opname WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' GROUP BY kode_op");
		else
			$query1 = mysql_query("SELECT * FROM st_opname WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND gudang='$gudang' GROUP BY kode_op");
		
		$no=1;
		$tnilai=0;
		$jml=0;
		
		while($data1=mysql_fetch_array($query1)){
			$kodeop = $data1['kode_op'];
			echo "<tr>
				<td></td>
				<td></td>
				<td><b>$data1[kode_op] - ".jin_date_str($data1['tanggal'])."</b></td>
				<td><b>Gudang : $data1[gudang]</b></td>
			</tr>";			
			$query = mysql_query("SELECT * FROM st_opname WHERE kode_op='$kodeop' ORDER BY kode_st");
			$snilai = 0;
			$no=1;
			
			while($data=mysql_fetch_array($query)){
				echo "<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++;
				$jml++;
				$snilai=$snilai+$data['nilai_sls'];
			}
			
			echo "<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;
		}
		echo "<tr></tr>	
		<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>
	</table>
	<table width='100%'>
		<tr>
			<td>Jumlah Data : $jml</td>
		</tr>
	</table>";
?>