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

        $("#theList.barang tr").hover(
            function() {
                $(this).toggleClass("highlight");
            },
            function() {
                $(this).toggleClass("highlight");
            }
        );
    });	
});

	function pilih(ID){
		var kode = ID;
		
		$.ajax({
			type	: "POST",
			url		: "modul/opname/cari_kode.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#t_kode").val(kode);
				$("#t_tanggal").val(data.tgl);
				$("#form_cari_kodepos").dialog('close');				
			}
		});
	}
</script>

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

$gudang= $_POST['gudang'];

echo "<table id='theList' class='barang' width='100%'>
	<tr>
		<th>Kode</th>			
		<th>Tanggal</th>
		<th>Gudang</th>
		<th>Jml. Item</th>	
		<th>Total Stok</th>	
		<th>Total Fisik</th>	
		<th>Total Selisih</th>
		<th>Nilai Selisih</th>	
		<th>Ambil</th>
	</tr>";
	$query= mysql_query("SELECT kode_op,tanggal,count(kode_st) as item,sum(jml_stok) as tstok,sum(jml_opn) as topn,sum(jml_sls) as tsls,sum(nilai_sls) as tnilai FROM st_opname WHERE gudang='$gudang' AND posting='' GROUP BY kode_op");
	
	$no=1;
	while($r=mysql_fetch_array($query)){
		echo "<tr>					
			<td>$r[kode_op]</td>
			<td>".jin_date_str($r['tanggal'])."</td>
			<td align='center'>$r[gudang]</td>
			<td align='center'>$r[item]</td>
			<td align='right'>".number_format($r['tstok'],2)."</td>
			<td align='right'>".number_format($r['topn'],2)."</td>
			<td align='right'>".number_format($r['tsls'],2)."</td>
			<td align='right'>".number_format($r['tnilai'],2)."</td>			
			<td align='center'>
				<a href='javascript:void(0)' onClick=\"pilih('$r[kode_op]')\">
				<img src='icon/download.gif' border='0' id='tambah_data' title='Tambah' width='12' height='12' >
				</a>					
			</td>
		</tr>";
		$no++;			
	}
	echo "</table>";
?>