<script type="text/javascript">	
$(document).ready(function() {
	$("#tabs").tabs({selected:0});
	$("#tampil_data_st").load('modul/inventory/tampil_data_st.php');
	$("#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){				
				$("#mb_tglawal").val(data.tanggal);
				$("#mb_tglakhir").val(data.tanggal);
				$("#ks_tglawal").val(data.tanggal);
				$("#ks_tglakhir").val(data.tanggal);
			}
		});
	}
	
	$('#txt_carist').keyup(function(){		
		var cari	= $("#txt_carist").val();
		
		$.ajax({
			type	: "GET",
			url		: "modul/inventory/tampil_data_st.php",
			data	: "cari="+cari,
			timeout	: 3000,
			beforeSend	: function(){		
				$("#tampil_data_st").html("<img src='loading.gif' />");			
			},				  
			success	: function(data){
				$("#tampil_data_st").html(data);
			}
		});
	});
	
	$("#cetak_ds").click(function(){
		var cari= $("#txt_carist").val();
		
		window.location.href='modul/laporan/daftar_st.php?cari='+cari;
	});
	
	$("#cari_mb").click(function(){
		var cari= $("#txt_carist").val();
		var tglawal = $("#mb_tglawal").val();
		var tglakhir = $("#mb_tglakhir").val();
		
		if(tglawal.length == 0){			
			alert("Maaf, Tanggal awal pencarian masih kosong.");
			$("#mb_tglawal").focus();
			return (false);
         }
		 
		if(tglakhir.length == 0){
			alert("Maaf, Tanggal akhir pencarian masih kosong.");
			$("#mb_tglakhir").focus();
		   return (false);
        }
		 
		$("#tampil_data_mb").show();
		$("#tampil_data_mb").load('modul/inventory/tampil_data_mb.php?cari='+cari+'&tglawal='+tglawal+'&tglakhir='+tglakhir);
	});
	
	$('#txt_carimb').keyup(function(){		
		var cari	= $("#txt_carimb").val();
		var tglawal = $("#mb_tglawal").val();
		var tglakhir = $("#mb_tglakhir").val();

		$.ajax({
			type	: "GET",
			url		: "modul/inventory/tampil_data_mb.php",
			data	: "cari="+cari+
					"&tglawal="+tglawal+
					"&tglakhir"+tglakhir,
			timeout	: 2000,
			beforeSend	: function(){		
				$("#tampil_data_mb").html("<img src='loading.gif' />");
			},				  
			success	: function(data){
				$("#tampil_data_mb").html(data);
			}
		});
	});
	
	$("#cetak_mb").click(function(){
		var cari= $("#txt_carimb").val();
		var tglawal = $("#mb_tglawal").val();
		var tglakhir = $("#mb_tglakhir").val();
		
		if(tglawal.length == 0){			
			alert("Maaf, Tanggal awal pencarian masih kosong.");
			$("#mb_tglawal").focus();
			return (false);
         }
		 
		if(tglakhir.length == 0){
			alert("Maaf, Tanggal akhir pencarian masih kosong.");
			$("#mb_tglakhir").focus();
		   return (false);
        }		
		window.location.href='modul/laporan/rekap_mb.php?cari='+cari+'&tglawal='+tglawal+'&tglakhir='+tglakhir;
	});
	
	$("#cari_ks").click(function(){
		var cari= $("#txt_cariks").val();
		 
		$.ajax({
			type	: "GET",
			url		: "modul/inventory/tampil_data_ks.php",
			data	: "cari="+cari,
			timeout	: 2000,
			beforeSend	: function(){		
				$("#tampil_data_ks").html("<img src='loading.gif' />");			
			},				  
			success	: function(data){
				$("#tampil_data_ks").html(data);
			}
		}); 
	});
	
	$("#refresh").click(function() {
		$(".input_cari").val('');
	});
	
	$('#txt_cariks').keyup(function(){		
		var cari	= $("#txt_cariks").val();
		
		$.ajax({
			type	: "GET",
			url		: "modul/inventory/tampil_data_ks.php",
			data	: "cari="+cari,
			timeout	: 1000,
			beforeSend	: function(){		
				$("#tampil_data_ks").html("<img src='loading.gif' />");			
			},				  
			success	: function(data){
				$("#tampil_data_ks").show();
				$("#tampil_data_ks").html(data);
			}
		});
	});
	
	$("#cetak_ks").click(function(){
		var kode	= $("#t_kodest").val();				
		var tglawal = $("#ks_tglawal").val();
		var tglakhir = $("#ks_tglakhir").val();
		
		window.location.href='modul/laporan/kartu_st.php?kode='+kode+'&tglawal='+tglawal+'&tglakhir='+tglakhir;
	});
		
	$("#tutup_ds").click(function(){
		document.location='?module=home';
	});
	
	$("#tutup_mb").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('modul/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
echo "<div id='tabs'>";
echo "<ul >	       
	       <li><a href='#data_st'>Daftar Persediaan</a></li>		   
		   <li><a href='#data_mb'>Rekap Mutasi Barang</a></li>
		   <li><a href='#data_ks'>Kartu Persediaan</a></li>
		</ul>";
		
	echo "<div id='data_st'>
			<div id='pencarian_st'>
			<fieldset>
			<legend>Filter Data</legend>
			<table width='100%'>
				<tr>
					<td width='10%'>Cari Kata</td>
					<td width='2%'>:</td>
					<td><input type='text' name='txt_carist' id='txt_carist' size='50'></td>
					<td colspan='6' align='right'>
						<button name='cetak_ds' id='cetak_ds'>Cetak</button>
						<button name='tutup_ds' id='tutup_ds'>Tutup</button>
					</td>
				</tr>
			</table>
			</fieldset>
			</div><br>
			<div id='tampil_data_st' align='center' style='overflow-x: auto;height: 400px;scroll-behavior: smooth'></div>
		</div>";
		
	echo "<div id='data_mb'>
			<div id='pencarian_mb'>
			<fieldset>
			<legend>Filter Data</legend>
			<table width='100%'>
				<tr>
					<td>Cari kata : <input type='text' name='txt_carimb' id='txt_carimb' size='26'></td>
					<td>Tanggal : <input type='date' name='mb_tglawal' id='mb_tglawal' size='10'> s/d <input type='date' name='mb_tglakhir' id='mb_tglakhir' size='10' ></td>
				</tr>
				<tr>
					<td colspan='12' align='center'>
						<button name='cari_mb' id='cari_mb'>Cari</button>
						<button name='cetak_mb' id='cetak_mb'>Cetak</button>
						<button name='tutup_mb' id='tutup_mb'>Tutup</button>
					</td>
				</tr>
			</table>
			</fieldset>
			</div><br>
			<div id='tampil_data_mb' align='center' style='overflow-x: auto;height: 400px;scroll-behavior: smooth'></div>
		</div>";
	
	echo "<div id='data_ks'>
			<input type='text' name='t_kodest' id='t_kodest' hidden />
			<input type='text' name='t_namast' id='t_namast' hidden />
			<input type='text' name='t_satuan' id='t_satuan' hidden />
			<input type='text' name='t_jmlstok' id='t_jmlstok' hidden />
			<input type='text' name='t_stawal' id='t_stawal' hidden />
			<input type='text' name='t_tglawal' id='t_tglawal' hidden />
			<input type='text' name='t_tglakhir' id='t_tglakhir' hidden />
			
			<div id='pencarian_ks'>
				<fieldset>
					<legend>Filter Data</legend>
					<table width='100%'>
						<tr>
							<td>Cari kata : <input type='text' name='txt_cariks' id='txt_cariks' size='27' class='input_cari'></td>
							<td>Tanggal : <input type='date' name='ks_tglawal' id='ks_tglawal' class='input_cari'> s/d <input type='date' name='ks_tglakhir' id='ks_tglakhir' class='input_cari'></td>
						</tr>
					</table>
					
					<table width='100%'>
						<tr>
							<td align='center'>
								<button name='cari_ks' id='cari_ks'>Cari Data</button>
								<button name='refresh' id='refresh'>Refresh</button>
								<button name='tutup_ks' 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 name='cetak_ks' id='cetak_ks'>Cetak</button>
							<button name='tutup_detail' 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 id='info' align='center'></div>";
echo "</div>";
?>
