<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){				
				$("#mb_tglawal").val(data.tanggal);
				$("#mb_tglakhir").val(data.tanggal);
				$("#ks_tglawal").val(data.tanggal);
				$("#ks_tglakhir").val(data.tanggal);
			}
		});
	}
	
	$('#form_cari_gr').dialog({
		autoOpen: false,
		modal	: true,
		width: 600,
	});
	
	$('#cari_gr').click(function(){		
		$('#form_cari_gr').dialog('open');
		$("#info_gr").load("modul/inventory/tampil_data_grds.php?");
		$("#txt_carigr").focus();
	});
	
	$('#txt_carigr').keyup(function(){		
		var cari	= $("#txt_carigr").val();
		
		$.ajax({
			type	: "GET",
			url		: "modul/inventory/tampil_data_grds.php",
			data	: "cari="+cari,			
			success	: function(data){
				$("#info_gr").html(data);				
			}
		});
	});
		
	$("#t_kodegr").keyup(function(){
		var kode = $("#t_kodegr").val();
		
		if(kode.length>1){
		$.ajax({
			type	: "POST",
			url		: "modul/inventory/cari_grup.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#t_kodegr").val(kode);
				$("#t_namagr").val(data.namagr);
				var nagr = $("#t_namagr").val();
				
				if(nagr.length==0){
					alert('Kode kelompok '+kode+' tidak ditemukan.');
					$("#t_kodegr").focus();
					return (false);
				}
			}
		});
		}
	});
	
	$('#cari_ds').click(function(){
		var cari	= $("#txt_carist").val();
		var kodegr	= $("#t_kodegr").val();
		var status	= $("#t_status").val();
				
		$.ajax({
			type	: "GET",
			url		: "md_gdg/inventory/tampil_data_st.php",
			data	: "cari="+cari+
					"&kodegr="+kodegr+
					"&status="+status,
			success	: function(data){
			    $("#tampil_data_st").show();
				$("#tampil_data_st").html(data);
			}
		});
	});
	
	$('#txt_carist').keyup(function(){
		var cari	= $("#txt_carist").val();
		var kodegr	= $("#t_kodegr").val();
		var status	= $("#t_status").val();
				
		$.ajax({
			type	: "GET",
			url		: "md_gdg/inventory/tampil_data_st.php",
			data	: "cari="+cari+
					"&kodegr="+kodegr+
					"&status="+status,
			success	: function(data){
			    $("#tampil_data_st").show();
				$("#tampil_data_st").html(data);
			}
		});
	});
	
	$("#cetak_ds").click(function(){
		var cari	= $("#txt_carist").val();
		var kodegr	= $("#t_kodegr").val();
		var namagr  = $("#t_namagr").val();
		var status	= $("#t_status").val();
		
		window.location.href='modul/laporan/daftar_stgd.php?cari='+cari+'&kodegr='+kodegr+'&namagr='+namagr+'&status='+status;
	});
	
	$("#refresh_ds").click(function() {
		$(".filter_ds").val('');
		$("#tampil_data_st").hide();
	});
	
	$('#txt_carigr').keyup(function(){
		var cari	= $("#txt_carigr").val();
		
		$.ajax({
			type	: "GET",
			url		: "modul/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_grcb').click(function(){
		$('#form_cari_gr').dialog('open');
		$("#info_gr").load("modul/inventory/tampil_data_grds.php?");
		$("#txt_carigr").focus();
	});
	
	$("#cb_kodegr").keyup(function(){
		var kode = $("#cb_kodegr").val();
		
		if(kode.length>1){
		$.ajax({
			type	: "POST",
			url		: "modul/inventory/cari_grup.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#cb_kodegr").val(kode);
				$("#cb_namagr").val(data.namagr);
				var nagr = $("#cb_namagr").val();
				
				if(nagr.length==0){
					alert('Kode kelompok '+kode+' tidak ditemukan.');
					$("#cb_kodegr").focus();
					return (false);
				}
			}
		});
		}
	});
	
	$('#cari_dscab').click(function(){
		var cari	= $("#txt_caristcab").val();
		var kodegr	= $("#cb_kodegr").val();
		var kodecab = $("#txt_kodecab").val();
		var status	= $("#cb_status").val();
		
		$.ajax({
			type	: "GET",
			url		: "md_gdg/inventory/tampil_data_stcab.php",
			data	: "cari="+cari+
					"&kodegr="+kodegr+
					"&kodecab="+kodecab+
					"&status="+status,
			success	: function(data){
				$("#tampil_data_stcab").html(data);
			}
		});
	});
	
	$('#txt_caristcab').keyup(function(){
		var cari	= $("#txt_caristcab").val();
		var kodegr	= $("#cb_kodegr").val();
		var kodecab = $("#txt_kodecab").val();
		var status	= $("#cb_status").val();
		
		$.ajax({
			type	: "GET",
			url		: "md_gdg/inventory/tampil_data_stcab.php",
			data	: "cari="+cari+
					"&kodegr="+kodegr+
					"&kodecab="+kodecab+
					"&status="+status,
			success	: function(data){
				$("#tampil_data_stcab").html(data);
			}
		});
	});
	
	$("#cetak_dscab").click(function(){
		var cari	= $("#txt_caristcab").val();
		var kodegr	= $("#cb_kodegr").val();
		var namagr  = $("#cb_namagr").val();
		var status	= $("#cb_status").val();
		var kodecab = $("#txt_kodecab").val();
		
		window.location.href='modul/laporan/daftar_stcabgd.php?cari='+cari+'&kodegr='+kodegr+'&namagr='+namagr+'&status='+status+'&kodecab='+kodecab;
	});
	
	$("#refresh_dscab").click(function() {
		$(".filter_dscab").val('');
	});
	
	$("#cari_mb").click(function(){
		var cari	= $("#txt_carimb").val();
		var gudang 	= $("#txt_gudang").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+'&gudang='+gudang+'&tglawal='+tglawal+'&tglakhir='+tglakhir);
	});
	
	$('#txt_carimb').keyup(function(){		
		var cari	= $("#txt_carimb").val();
		var gudang 	= $("#txt_gudang").val();
		var tglawal	= $("#mb_tglawal").val();
		var tglakhir= $("#mb_tglakhir").val();
		
		$.ajax({
			type	: "GET",
			url		: "modul/inventory/tampil_data_mb.php",
			data	: "cari="+cari+
				"&gudang="+gudang+
				"&tglawal="+tglawal+
				"&tglakhir="+tglakhir,
			success	: function(data){
				$("#tampil_data_mb").html(data);
			}
		});
	});
	
	$("#cetak_mb").click(function(){
		var cari	= $("#txt_carimb").val();
		var gudang 	= $("#txt_gudang").val();
		var tglawal = $("#mb_tglawal").val();
		var tglakhir= $("#mb_tglakhir").val();		
		window.location.href='modul/laporan/rekap_mb.php?cari='+cari+'&gudang='+gudang+'&tglawal='+tglawal+'&tglakhir='+tglakhir;
	});
	
	$("#cari_ks").click(function(){
		var cari    = $("#txt_cariks").val();
		var gudang  = $("#t_gudang").val();
		var tglawal = $("#ks_tglawal").val();
		var tglakhir= $("#ks_tglakhir").val();
		 
		$.ajax({
			type	: "GET",
			url		: "modul/inventory/tampil_data_ks.php",
			data	: "cari="+cari+
					"&gudang="+gudang+
					"&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 gudang	= $("#t_gudang").val();
		var tglawal = $("#ks_tglawal").val();
		var tglakhir= $("#ks_tglakhir").val();	
	
		if(cari.length>3){
		$.ajax({
			type	: "GET",
			url		: "modul/inventory/tampil_data_ks.php",
			data	: "cari="+cari+
					"&gudang="+gudang,
			success	: function(data){
				$("#tampil_data_ks").html(data);
			}
		});
		}
	});
	
	$("#cetak_ks").click(function(){
		var kode	= $("#t_kodest").val();
		var gudang	= $("#t_gudang").val();		
		var tglawal = $("#ks_tglawal").val();
		var tglakhir= $("#ks_tglakhir").val();

		window.location.href='modul/laporan/kartu_st.php?kode='+kode+'&gudang='+gudang+'&tglawal='+tglawal+'&tglakhir='+tglakhir;
	});
		
	$("#tutup_ds").click(function(){
		document.location='?module=home';
	});
	
	$("#tutup_dscab").click(function(){
		document.location='?module=home';
	});
	
	$("#tutup_mb").click(function(){
		document.location='?module=home';
	});

	$("#tutup_detail").click(function(){
		$("#info_ks").hide();
		$("#tampil_detail_ks").hide();
		$("#pencarian_ks").show();
		$("#tampil_data_ks").show();
		$("#tampil_data_ks").load('modul/inventory/tampil_data_ks.php?');
	});
	
	$("#tutup_ks").click(function(){
		document.location='?module=home';
	});
	
	$("#refresh_dscab").click(function(){
		$("#tampil_data_stcab").hide();
		$(".filter_dscab").val('');
	});
});
</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_stgb'>Daftar Persediaan Global</a></li>
		   <li><a href='#data_stcb'>Persediaan Cabang</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_stgb'>
		<div id='pencarian_st'>
			<fieldset>
			<legend>Filter Data</legend>
			<table width='100%'>
				<tr>
					<td>Kelompok : <input type='text' id='t_kodegr' size='3' maxlength='3' class='filter_ds'>
						<img src='images/view.png' width='18' height='18' title='Cari grup' id='cari_gr'>
						<input id='t_namagr' size='25' class='filter_ds' readonly/>
					</td>
					<td>Status stok : <select id='t_status' class='filter_ds'>
							<option value='seluruh'>KESELURUHAN</option>
							<option value='ada'>ADA STOK</option>
							<option value='minimal'>STOK MINIMAL</option>
							<option value='expired'>STOK EXPIRED</option>
						</select>
					</td>
					<td>Cari barang : <input type='text' id='txt_carist' class='filter_ds' size='30'></td>
				</tr>
			</table>
			<table width='100%'>
				<tr>
					<td align='center'>
						<button id='cari_ds'>Cari</button>
						<button id='cetak_ds'>Download Excel</button>
						<button id='refresh_ds'>Refresh</button>
						<button 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_stcb'>
		<div id='pencarian_stcb'>
			<fieldset>
			<legend>Filter Data</legend>
			<table width='100%'>
				<tr>
				    <td>Cabang : <select id='txt_kodecab'>";
							$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>Kelompok : <input type='text' id='cb_kodegr' size='3' maxlength='3' class='filter_dscab'>
						<img src='images/view.png' width='18' height='18' title='Cari grup' id='cari_grcb'>
						<input id='cb_namagr' size='25' class='filter_dscab' readonly/>
					</td>
					<td>Status stok : <select id='cb_status' class='filter_dscab'>
							<option value='seluruh'>KESELURUHAN</option>
							<option value='ada'>ADA STOK</option>
							<option value='minimal'>STOK MINIMAL</option>
							<option value='expired'>STOK EXPIRED</option>
						</select>
					</td>
					<td>Cari barang : <input type='text' id='txt_caristcab' class='filter_dscab' size='30'></td>
				</tr>
			</table>
			<table width='100%'>
				<tr>
				    
					<td align='center'>
						<button id='cari_dscab'>Cari</button>
						<button id='cetak_dscab'>Download Excel</button>
						<button id='refresh_dscab'>Refresh</button>
						<button id='tutup_dscab'>Tutup</button>
					</td>
				</tr>			
			</table>
			</fieldset>
		</div><br>
		<div id='tampil_data_stcab' 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 barang : <input type='text' id='txt_carimb' size='30'></td>
					<td>Tanggal : <input type='date' name='mb_tglawal' id='mb_tglawal' size='10' > s/d <input type='date' id='mb_tglakhir' size='10' ></td>
					<td>Gudang : <select id='txt_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>
						<button id='cari_mb'>Cari</button>
						<button id='cetak_mb'>Cetak</button>
						<button 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 />
			
		<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='22' class='input_cari'></td>
						<td>Tanggal : <input type='date' name='ks_tglawal' id='ks_tglawal' size='10' class='input_cari'></td>
						<td>s/d <input type='date' name='ks_tglakhir' id='ks_tglakhir' size='10' class='input_cari'></td>
						<td>Gudang : <select id='t_gudang'>
								<option value='Gudang'>Gudang Pusat</option>";
						        $sql1=mysql_query("SELECT * FROM cabang WHERE 1 ORDER BY kode_cab");
						        while($r1=mysql_fetch_array($sql1)){
						            $kodecab=$r1[kode_cab];
						            echo "<option value='$kodecab'>$r1[nama_cab]</option>";
						        }
							echo "</select>
						</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 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>";

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