<script type="text/javascript">
$(document).ready(function(){
	$("#txt_kodegr").focus();
	
	$('#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_gr.php?");
		$("#txt_carigr").focus();		
		return false;
	});
	
	$('#txt_carigr').keyup(function(){		
		var cari	= $("#txt_carigr").val();
		
		$.ajax({
			type	: "GET",
			url	: "modul/inventory/tampil_data_gr.php",
			data	: "cari="+cari,			
			timeout	: 2000,
			beforeSend	: function(){		
				$("#info_gr").html("<img src='loading.gif' />");
			},				  
			success	: function(data){
				$("#info_gr").html(data);				
			}
		});
	});
		
	$("#txt_kodegr").keyup(function(){
		var kode 	= $("#txt_kodegr").val();
		
		if(kode.length==2){
		$.ajax({
			type	: "POST",
			url		: "modul/inventory/cari_grup.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#txt_kodegr").val(kode);
				$("#txt_namagr").val(data.namagr);
				var nagr = $("#txt_namagr").val();
				
				if(nagr.length==0){
					alert('Kode kelompok '+kode+' tidak ditemukan.');
					return (false);
				}
				tampil_data_detail();
			}
		});
		}
	});
	
	$('#form_cari_br').dialog({
		autoOpen: false,
		modal	: true,
		width: 600,
	});
	
	$('#cari_br').click(function(){		
		$('#form_cari_br').dialog('open');
		$("#info_br").load("modul/inventory/tampil_data_br.php?");
		$("#txt_caribr").focus();		
		return false;
	});
	
	$('#txt_caribr').keyup(function(){
		var cari= $("#txt_caribr").val();
		var kode= $("#txt_kodegr").val();
		
		$.ajax({
			type	: "GET",
			url	: "modul/inventory/tampil_data_br.php",
			data	: "cari="+cari+
					"&kode="+kode,
			timeout	: 2000,
			beforeSend	: function(){		
				$("#info_br").html("<img src='loading.gif' />");
			},
			success	: function(data){
				$("#info_br").html(data);
			}
		});
	});
	
	function tampil_data_detail(){
		var kode = $("#txt_kodegr").val();
		
		$("#data_detail").show();
		$("#data_detail").load("modul/inventory/tampil_data_detail.php?kode="+kode);
		cari_nomor();
	}
	
	$("#tutup").click(function(){	
		document.location='?module=home';
	});
});
</script>

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

<?php
echo "<table>
	<tr>
		<td>Kode Kelompok</td>
		<td>:</td>
		<td><input name='txt_kodegr' id='txt_kodegr' size='2' maxlength='2' >
		<img src='images/view.png' width='18' height='18' title='Cari grup' id='cari_gr'></td>
		<td width='20%'>Nama Kelompok</td>
		<td>:</td>
		<td><input name='txt_namagr' id='txt_namagr' size='25' readonly />
	</tr>
	</table>
	<hr>";
	
echo "<table>
		<tr>
			<th>Kode</th>
			<th></th>
			<th>Nama Barang</th>
			<th>Barcode Pcs</th>
			<th>Barcode Pak</th>
			<th>Satuan</th>
			<th>Harga Beli</th>			
		</tr>		
		<tr>
			<input type='text' id='txt_jmlstok' class='input_detail' hidden/>
			<td align='center'><input type='text' name='txt_kodest' id='txt_kodest' class='input_detail' size='6' maxlength='6' class='input_detail' readonly /></td>
			<td><img src='images/view.png' width='18' height='18' title='Cari data barang' id='cari_br'></td>
			<td align='center'><input type='text' name='txt_namast' id='txt_namast' class='input_detail' size='30' readonly /></td>
			<td align='center'><input type='text' name='txt_barcode' id='txt_barcode' class='input_detail' size='13' readonly /></td>
			<td align='center'><input type='text' name='txt_barcode1' id='txt_barcode1' class='input_detail' size='13' readonly /></td>
			<td align='center'><input type='text' name='txt_satuan' id='txt_satuan' class='input_detail' size='7' readonly /></td>						
			<td align='center'><input type='text' name='txt_hgbeli' id='txt_hgbeli' class='input_detail' size='8' readonly /></td>			
		</tr>
		<tr>
			<th>Qty S/D</th>
			<th></th>
			<th>Harga Jual</th>
			<th>Quantity</th>
			<th>Harga Jual</th>
			<th>Qty ></th>
			<th>Harga Jual</th>
		</tr>		
		<tr>
			<td align='center'><input type='text' name='txt_ungros' id='txt_ungros' class='input_detail' size='4' readonly /></td>
			<td></td>
			<td align='center'><input type='text' name='txt_hgjual' id='txt_hgjual' class='input_detail' size='8' readonly /></td>
			<td align='center'><input type='text' name='t_ungros' id='t_ungros' class='input_detail' size='4' readonly /> - <input type='text' name='txt_ungros1' id='txt_ungros1' class='input_detail' size='4' readonly /></td>
			<td align='center'><input type='text' name='txt_hggros1' id='txt_hggros1' class='input_detail' size='8' readonly /></td>
			<td align='center'><input type='text' name='t_ungros1' id='t_ungros1' class='input_detail' size='6' readonly /></td>
			<td align='center'><input type='text' name='txt_hggros2' id='txt_hggros2' class='input_detail' size='8' readonly /></td>			
		</tr>
	</table>
	
	<table width='100%'>
	<tr>
		<td>Satuan 1 : <input type='text' name='txt_satuan1' id='txt_satuan1' class='input_detail' size='7' readonly /></td>
		<td>Konversi : <input type='text' name='txt_konversi' id='txt_konversi' class='input_detail' size='7' readonly /></td>
		<td>Harga Jual : <input type='text' name='txt_hgjual1' id='txt_hgjual1' class='input_detail' size='8' readonly /></td>
		<td></td>
	</tr>
	<tr>
		<td>Satuan 2 : <input type='text' name='txt_satuan2' id='txt_satuan2' class='input_detail' size='7' readonly /></td>
		<td>Konversi : <input type='text' name='txt_konversi1' id='txt_konversi1' class='input_detail' size='7' readonly /></td>
		<td>Harga Jual : <input type='text' name='txt_hgjual2' id='txt_hgjual2' class='input_detail' size='8' readonly /></td>
		<td></td>
	</tr>
	<tr>
		<td>Satuan 3 : <input type='text' name='txt_satuan3' id='txt_satuan3' class='input_detail' size='7' readonly /></td>
		<td>Konversi : <input type='text' name='txt_konversi2' id='txt_konversi2' class='input_detail' size='7' readonly /></td>
		<td>Harga Jual : <input type='text' name='txt_hgjual3' id='txt_hgjual3' class='input_detail' size='8' readonly /></td>
		<td>Jumlah Stok : <input type='text' name='txt_jmlstok' id='txt_jmlstok' class='input_detail' size='8' readonly /></td>
		<td colspan='3' align='right'>			
			<button name='tutup' id='tutup'>Tutup</button>
		</td>
	</tr>
	</table>";
	
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'></div>
	</div>";

echo "<div id='form_cari_br' title='Pencarian Data Barang'>
		<table width='100%'>
			<td>
				<td width='20%'>Cari Barang</td>
				<td width='2%'>:</td>
				<td><input type='text' name='txt_caribr' id='txt_caribr' size='40'</td>
			</td>
		</table>
		<div id='tampil_data_br' align='center'></div>
		<div id='info_br' align='center'></div>
	</div>";
	
echo "<div id='data_detail'></div>";
?>
