<script type="text/javascript">
$(document).ready(function(){
    
	$('#cari_pos').click(function(){
	    var gudang=$("#p_gudang").val();
		$("#detail_posting").show();
		$("#detail_posting").load('spv/st_opname/tampil_data.php?gudang='+gudang);
	});
	
	$('#form_cari_kodepos').dialog({
		autoOpen: false,
		modal	: true,
		width: 700,
	});
		
	$('#cari_kodepos').click(function(){
		$('#form_cari_kodepos').dialog('open');
		var gudang=$("#p_gudang").val();
		
		$.ajax({
			type	: "POST",
			url		: "spv/st_opname/tampil_data_op.php",
			data	: "gudang="+gudang,
			success	: function(data){
				$("#info_kodepos").html(data);
			}
		});
	});
	
	$("#posting").click(function(){
		var kode	= $("#t_kode").val();
		var tanggal	= $("#t_tanggal").val();
		var gudang 	= $("#p_tanggal").val();
				
		if(kode.length == 0){        
			alert("Maaf, Kode stok opname masih kosong, klik icon di samping Kode opname untuk mencari.");
			return (false);
        }

		$.ajax({
			type	: "POST",
			url	    : "spv/st_opname/posting.php",
			data	: "kode="+kode+
				"&tanggal="+tanggal+
				"&gudang="+gudang,
			success	: function(data){
				$("#info").html(data);
				$("#t_kode").val('');
				$("#t_tanggal").val('');
				$("#detail_posting").load("spv/st_opname/tampil_data.php");				
			}
		});		
	});
		
	$("#tutup_pos").click(function(){
		document.location='?module=home';
	});
});
</script>

<style type="text/css">
#txt_kode {
	background:#CCC;
}
.input_detail readonly {
	background:#666;
}
</style>

<?php
include "../../inc/inc.koneksi.php";

echo "<table width='100%'>	
	<tr>
	    <td>Gudang : <select id='p_gudang'>
		        <option value='Gudang'>Gudang Pusat</option>";
		        $sql=mysql_query("SELECT * FROM cabang WHERE 1 ORDER BY kode_cab");
		        while($r=mysql_fetch_array($sql)){
		            $kodecab=$r[kode_cab];
		            echo "<option value='$kodecab'>$r[nama_cab]</option>";
		        }
		    echo "</select>
		</td>
		<td>Kode Opname : <input type='text' name='t_kode' id='t_kode' size='9' class='input_header' readonly />
			<img src='images/view.png' width='18' height='18' title='Cari Kode Opname' id='cari_kodepos'>
		</td>
		<td>Tanggal : <input type='date' id='t_tanggal' size='9' class='input_header' readonly/></td>
		<td>
			<button id='cari_pos'>Cari</button>
			<button id='posting'>Posting</button>
			<button id='tutup_pos'>Tutup</button>
		</td>
	</tr>
	</table>
	<div id='detail_posting' style='overflow-x: auto;height: 400px;scroll-behavior: smooth'></div>";

echo "<div id='form_cari_kodepos' title='Pencarian Kode Opname'>		
		<div id='info_kodepos' align='center' style='overflow-x: auto;height: 400px;scroll-behavior: smooth'></div>
	</div>";
?>