<script type="text/javascript">
$(document).ready(function(){
	cari_user();
	
	function cari_user(){
		var no = 1;
		$.ajax({
			type	: "POST",
			url		: "kasir/penjualan/cari_user.php",
			data	: "no="+no,
			dataType: "json",
			success	: function(data){
				$("#l_user").val(data.user);
				$("#mulai_lb").focus();
			}
		});
	}
	
	$("#mulai_lb").click(function(){
		var user = $("#l_user").val();

		$.ajax({
			type	: "POST",
			url		: "modul/inventory/refresh.php",
			data	: "user="+user,
			success	: function(data){
				$("#info_label").html(data);
				$("#txt_caribr").val('');
				tampil_detail();
			}
		});
	});
	
	function tampil_detail(){
		var user = $("#l_user").val();

		$("#data_detail_lb").show();
		$("#data_detail_lb").load("modul/inventory/tampil_data_label.php?user="+user);
		$("#l_barcode").focus();
	}
	
	$('#l_barcode').keyup(function(){
		var barc = $('#l_barcode').val();

		if(barc.length>5){
		$.ajax({
			type	: "POST",
			url		: "modul/inventory/cari_barcode.php",
			data	: "barc="+barc,
			dataType: "json",
			success	: function(data){				
				$("#l_kodest").val(data.kodest);
				$("#l_namaasl").val(data.namast);
				$("#l_namast").val(data.namast);
				$("#l_kodesp").val(data.kodesp);
				$("#l_satuan").val(data.satuan);
				$("#l_hgjual").val(data.hgjual);
				$("#l_kali").focus();
			}
		});
		}
	});
	
	$('#form_cari_label').dialog({
		autoOpen: false,
		modal	: true,
		width: 750,
	});
	
	$('#l_namaasl').click(function(){
		$('#form_cari_label').dialog('open');
		$("#info_barang").show();
		$("#l_caribr").focus();
	});
	
	$('#l_namaasl').keyup(function(){
		$('#form_cari_label').dialog('open');
		$("#info_barang").show();
		$("#l_caribr").focus();
	});
	
	$("#l_caribr").keyup(function(){		
		var cari = $("#l_caribr").val();
		
		if(cari.length>3){
		$.ajax({
			type	: "GET",
			url		: "modul/inventory/tampil_data_barang.php",
			data	: "cari="+cari,
			timeout	: 2000,
			beforeSend	: function(){		
				$("#info_barang").html("<img src='loading.gif' />");			
			},
			success	: function(data){
				$("#info_barang").html(data);
			}
		});
		}
	});

	$("#simpan_lb").click(function(){
		simpan_data();
	});
		
	function simpan_data(){
		var kodest	= $("#l_kodest").val();
		var namast 	= $("#l_namast").val();
		var barcode	= $("#l_barcode").val();
		var hgjual	= $("#l_hgjual").val();
		var kali    = $("#l_kali").val();
		var kodesp	= $("#l_kodesp").val();
		var user    = $("#l_user").val();
		
		if(kodest.length == 0){
           alert("Maaf, data barang yang akan dibuat label belum ada.");
		   $("#l_barcode").focus();
		   return (false);
        }

		$.ajax({
			type	: "POST",
			url		: "modul/inventory/simpan_lb.php",
			data	: "kodest="+kodest+
					"&namast="+namast+
					"&barcode="+barcode+
					"&kodesp="+kodesp+
					"&hgjual="+hgjual+
					"&kali="+kali+
					"&user="+user,	
			timeout	: 2000,
			beforeSend	: function(){		
				$("#info_label").html("<img src='loading.gif' />");
			},				  
			success	: function(data){
				$("#info_label").html(data);
				$(".input_detail").val('');
				tampil_detail();
			}
		});
	}
	
	$("#cetak_lb").click(function(){
		var user  = $("#l_user").val();
		
		window.location.href='modul/laporan/label_harga.php?user='+user;
		$("#mulai_lb").focus();
	});
	
	$("#cetak_lbpl").click(function(){
		var user  = $("#l_user").val();
		
		window.location.href='modul/laporan/label_hargapl.php?user='+user;
		$("#mulai_lb").focus();
	});

	$("#tutup_lb").click(function(){
		document.location='?module=home';
	});
});
</script>

<style type="text/css">
.data_detail{
	font-size:14px;	
}
</style>

<?php

echo "<div id='form_input'>
	<table>
		<tr>
			<th>Barcode</th>
			<th>Nama Barang Asli</th>
			<th>Nama Barang Label</th>
			<th>Kode Brg.</th>
			<th>Kode Sup.</th>
			<th>Satuan</th>
			<th>Harga Jual</th>
			<th>Cetak</th>
			<th></th>
		</tr>		
		<tr>
			<input type='text' id='l_user' hidden/>
			<td align='center'><input type='text' id='l_barcode' class='input_detail' size='15'></td>
			<td align='center'><input type='text' id='l_namaasl' class='input_detail' size='40'></td>
			<td align='center'><input type='text' id='l_namast' class='input_detail' size='40'></td>
			<td align='center'><input type='text' id='l_kodest' class='input_detail' size='6' readonly/></td>
			<td align='center'><input type='text' id='l_kodesp' class='input_detail' size='15' readonly/></td>
			<td><input type='text' id='l_satuan' class='input_detail' size='6' readonly />
			<td align='center'><input type='text' id='l_hgjual' class='input_detail' size='8' readonly/></td>
			<td><select id='l_kali'>
					<option value='3'>3 x</option>
					<option value='6'>6 x</option>
					<option value='9'>9 x</option>
					<option value='12'>12 x</option>
					<option value='15'>15 x</option>
					<option value='18'>18 x</option>
					<option value='21'>21 x</option>
					<option value='24'>24 x</option>
					<option value='27'>27 x</option>
					<option value='30'>30 x</option>
				</select>
			</td>
			<td><button id='simpan_lb'>Rekam</button></td>			
		</tr>
	</table>
	<hr>
	</div>";

echo "<div id='data_detail_lb'></div>";
		
echo "<table width='100%'>
	<tr>
		<td align='center'>
			<button id='mulai_lb'>Mulai</button>
			<button id='cetak_lb'>Cetak Label</button>
			<button id='cetak_lbpl'>Cetak Label Tanpa Harga</button>
			<button id='tutup_lb'>Tutup</button>
		</td>
	</tr>
	</table>";

echo "<div id='form_cari_label' title='Pencarian Data Barang'>
		<table width='100%'>
			<td>
				<td>Cari data barang : <input type='text' name='l_caribr' id='l_caribr' size='40'></td>
			</td>
		</table>
		
		<div id='info_barang' align='center'></div>
	</div>";

echo "<div id='info_label'></div>";
?>