<script type="text/javascript">	
$(document).ready(function() {
	$("#tabs").tabs({selected:0});	
	$("#info_ks").hide();
	
	cari_tgl();
	
	function cari_tgl(){
		var no = 1;
		$.ajax({
			type	: "POST",
			url		: "modul/report/cari_tanggal.php",
			data	: "no="+no,
			dataType: "json",
			success	: function(data){				
				$("#ks_tglawal").val(data.tanggal);
				$("#ks_tglakhir").val(data.tanggal);
			}
		});
	}
	
	$('#form_cari_gr').dialog({
		autoOpen: false,
		modal	: true,
		width: 600,
	});
	
	$('#cari_grhj').click(function(){
		var cari= $("#txt_carigr").val();
		$('#form_cari_gr').dialog('open');
		$("#info_gr").load("md_kpt/inventory/tampil_data_grds.php?cari="+cari);
		$("#txt_carigr").focus();
	});
	
	$('#txt_carigr').keyup(function(){
		var cari= $("#txt_carigr").val();
		
		$.ajax({
			type	: "GET",
			url		: "md_kpt/inventory/tampil_data_grds.php",
			data	: "cari="+cari,			
			success	: function(data){
				$("#info_gr").html(data);				
			}
		});
	});
		
	$("#x_kodegr").keyup(function(){
		var kode = $("#x_kodegr").val();
		
		if(kode.length>1){
		$.ajax({
			type	: "POST",
			url		: "modul/inventory/cari_grup.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#x_kodegr").val(kode);
				$("#x_namagr").val(data.namagr);
				var nagr = $("#x_namagr").val();
				
				if(nagr.length==0){
					alert('Kode kelompok '+kode+' tidak ditemukan.');
					$("#x_kodegr").focus();
					return (false);
				}
			}
		});
		}
	});
	
	$('#cari_dshj').click(function(){
		var cari	= $("#txt_caristhj").val();
		var kodegr	= $("#x_kodegr").val();
		
		$.ajax({
			type	: "GET",
			url		: "md_kpt/inventory/tampil_data_sthj.php",
			data	: "cari="+cari+
					"&kodegr="+kodegr,
			success	: function(data){
				$("#tampil_data_sthj").html(data);
			}
		});
	});
	
	$('#txt_caristhj').keyup(function(){
		var cari	= $("#txt_caristhj").val();
		var kodegr	= $("#x_kodegr").val();
		var kodesp	= $("#l_kodesp").val();
		var status	= $("#x_status").val();
		
		$.ajax({
			type	: "GET",
			url		: "md_kpt/inventory/tampil_data_sthj.php",
			data	: "cari="+cari+
					"&kodegr="+kodegr+
					"&kodesp="+kodesp+
					"&status="+status,
			success	: function(data){
				$("#tampil_data_sthj").html(data);
			}
		});
	});
	
	$("#refresh_dshj").click(function() {
		$(".filter_dshj").val('');
	});
	
	$("#cari_ks").click(function(){
		var cari    = $("#txt_cariks").val();
		var tglawal = $("#ks_tglawal").val();
		var tglakhir= $("#ks_tglakhir").val();
		 
		$.ajax({
			type	: "GET",
			url		: "md_kpt/inventory/tampil_data_ks.php",
			data	: "cari="+cari+
					"&tglawal="+tglawal+
					"&tglakhir="+tglakhir,
			success	: function(data){				
				$("#tampil_data_ks").html(data);
				$("#tampil_data_ks").show();
			}
		}); 
	});
	
	$("#refresh").click(function(){
		$("#tampil_data_ks").hide();
		$(".input_cari").val('');
	});
	
	$('#txt_cariks').keyup(function(){	
		var cari	= $("#txt_cariks").val();
		var tglawal = $("#ks_tglawal").val();
		var tglakhir= $("#ks_tglakhir").val();	
	
		if(cari.length>3){
		$.ajax({
			type	: "GET",
			url		: "md_kpt/inventory/tampil_data_ks.php",
			data	: "cari="+cari,
			success	: function(data){
				$("#tampil_data_ks").html(data);
			}
		});
		}
	});

	$("#tutup_ds").click(function(){
		document.location='?module=home';
	});
	
	$("#tutup_dshj").click(function(){
		document.location='?module=home';
	});
	
	$("#tutup_detail").click(function(){
	    var cari= $("#txt_cariks").val();
		$("#info_ks").hide();
		$("#tampil_detail_ks").hide();
		$("#pencarian_ks").show();
		$("#tampil_data_ks").show();
		$("#tampil_data_ks").load('md_kpt/inventory/tampil_data_ks.php?cari='+cari);
	});
	
	$("#tutup_ks").click(function(){
		document.location='?module=home';
	});
});
</script>

<style type="text/css">
#info {
	font-size:12px;
	font-weight:bold;
	color:#F00;
}
</style>

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

echo "<div id='tabs'>";
echo "<ul >
	   <li><a href='#data_sthj'>Daftar Persediaan</a></li>
	   <li><a href='#data_ks'>Kartu Persediaan</a></li>
	</ul>";
	
	echo "<div id='data_sthj'>
		<div id='pencarian_st'>
			<fieldset>
    			<legend>Filter Data</legend>
	    		<table width='100%'>
		    		<tr>
			    		<td>Kelompok : <input type='text' id='x_kodegr' size='3' maxlength='3' class='filter_dshj'>
				    		<img src='images/view.png' width='18' height='18' title='Cari grup' id='cari_grhj'>
					    	<input id='x_namagr' size='25' class='filter_dshj' readonly />
    					</td>
	    				<td>Cari barang : <input type='text' id='txt_caristhj' size='30' class='filter_dshj'></td>
		    			<td>
			    			<button id='cari_dshj'>Cari</button>
				    		<button id='refresh_dshj'>Refresh</button>
					    	<button id='tutup_dshj'>Tutup</button>
    					</td>
	    			</tr>
		    	</table>
			</fieldset>
		</div><br>
		<div id='tampil_data_sthj' align='center' style='overflow-x: auto;height: 400px;scroll-behavior: smooth'></div>
	</div>";

	echo "<div id='data_ks'>
		<div id='pencarian_ks'>
			<fieldset>
				<legend>Filter Data</legend>
				<table width='100%'>
					<tr>
						<td>Tanggal : <input type='date' id='ks_tglawal' size='10' class='input_cari'> sampai dengan <input type='date' id='ks_tglakhir' size='10' class='input_cari'></td>
						<td>Cari Barang : <input type='text' id='txt_cariks' size='30' class='input_cari'></td>
						<td>
							<button id='cari_ks'>Cari Data</button>
							<button id='refresh'>Refresh</button>
							<button id='tutup_ks'>Tutup</button>
						</td>									
					</tr>				
				</table>
			</fieldset>
		</div><br>
			
		<div id='tampil_data_ks' align='center' style='overflow-x: auto;height: 400px;scroll-behavior: smooth'></div>
			
		<div id='info_ks'>
			<table width='100%'>					
				<tr>
					<td align='right'>
						<button id='tutup_detail'>Tutup Detail</button>
					</td>					
				</tr>
			</table>							
		</div>
		<div id='tampil_detail_ks' align='center' style='overflow-x: auto;height: 400px;scroll-behavior: smooth'></div>
	</div>";
	
echo "</div>";

echo "<div id='form_cari_gr' title='Pencarian grup'>
	<table width='100%'>
		<td>
			<td>Cari Kelompok : <input type='text' id='txt_carigr' size='40'></td>
		</td>
	</table>
	<div id='info_gr' align='center' style='overflow-x: auto;height: 400px;scroll-behavior: smooth'></div>
</div>";
	
echo "<div id='info' align='center'></div>";
?>