<html>
<head>
<script type="text/javascript">
$(document).ready(function(){
	$("#u_barcode").focus();
	
	$("#u_barcode").keyup(function(){
		var kode = $("#u_barcode").val();
				
		$.ajax({
			type	: "POST",
			url	: "modul/inventory/cari_barcupl.php",
			data	: "kode="+kode,
			dataType	: "json",
			success	: function(data){
				$("#u_kodest").val(data.kodest);
				$("#u_namast").val(data.namast);
				$("#u_foto").val(data.foto);
				tampil_gambar();
			}
		});
	});
	
	function tampil_gambar(){
		var kode = $("#u_kodest").val();
		$("#data_gambar").load("modul/inventory/tampil_gambar.php?kode="+kode);
	}

	$("#u_kodest").keyup(function(){
		var kode = $("#u_kodest").val();
		
		if(kode.length>5){
		$.ajax({
			type	: "POST",
			url	: "modul/inventory/cari_stup.php",
			data	: "kode="+kode,
			dataType	: "json",
			success	: function(data){
				$("#u_barcode").val(data.barcode);
				$("#u_kodest").val(data.kodest);
				$("#u_namast").val(data.namast);
				var namast = $("#u_namast").val();
				
				if(namast.length==0){
					alert('Kode persediaan '+kode+' tidak ditemukan.');
					$("#u_kodest").focus();
					return (false);
				}
				tampil_gambar();
			}
		});
		}
	});
	
	$('#form_cari_brup').dialog({
		autoOpen: false,
		modal	: true,
		width: 800,
	});
	
	$('#u_namast').keyup(function(){
		var cari= $("#u_caribr").val();
		$('#form_cari_brup').dialog('open');
		$("#info_brup").load("modul/inventory/tampil_data_brup.php?cari="+cari);
		$("#u_caribr").focus();
	});
	
	$('#u_caribr').keyup(function(){
		var cari= $("#u_caribr").val();
		
		$.ajax({
			type	: "GET",
			url	: "modul/inventory/tampil_data_brup.php",
			data	: "cari="+cari,
			timeout	: 2000,
			beforeSend	: function(){		
				$("#info_brup").html("<img src='loading.gif' />");
			},
			success	: function(data){
				$("#info_brup").html(data);
			}
		});
	});
	
	$("#tutup_upl").click(function(){
		document.location='?module=home';
	});
});
</script>

<style type="text/css">
#u_kode {
	background:#CCC;
}
.input_detail readonly {
	background:#666;
}
</style>
<body>
<form style="background-color:white" class="navbar-form" name="formUpl" id="formUpl" action="modul/inventory/simpan_upl.php" method="post" enctype="multipart/form-data">
	<table style='font:16px verdana'>
		<tr>
			<td>Barcode</td>
			<td>: <input type='text' name='u_barcode' id='u_barcode' size='15' style='font:16px verdana'></td>
		</tr>
		<tr>
			<td>Kode Persediaan</td>
			<td>: <input type='text' name='u_kodest' id='u_kodest' size='7' maxlength='7' style='font:16px verdana'></td>
		</tr>
		<tr>
			<td>Nama Barang</td>
			<td>: <input type='text' name='u_namast' id='u_namast' size='40' style='font:16px verdana'></td>
		</tr>
		<tr>
			<td>Gambar</td>
			<td>: <input type='file' name='u_foto' id='u_foto' size='30' style='font:16px verdana'></td>
		</tr>
	</table>
	
	<table align='center'>
		<tr>
			<td align='right' colspan='3'><b><input type='submit' name='rekam' value='Upload' class='btn btn-primary' style='font:20px verdana;background-color:green;color:white'></b>
				<button id='tutup_upl' onclick='history.back()' style='font:20px verdana;background-color:green;color:white'>Tutup</button>
			</td></b>
		</tr>
	</table>
	<hr>

	<div align='center' id='data_gambar' style='overflow-x: auto;height: 400px;scroll-behavior: smooth'></div>
	
	<div id='form_cari_brup' title='Pencarian Data Barang'>
		<table width='100%'>
			<td>
				<td>Cari nama barang : <input type='text' name='u_caribr' id='u_caribr' size='40'></td>
			</td>
		</table>
		<div id='info_brup' align='center' style='overflow-x: auto;height: 400px;scroll-behavior: smooth'></div>
	</div>
</form>

<div id="status"></div>
</body>
</head>
</html>