<script type="text/javascript">
$(document).ready(function() {
    $(function() {
        $("#theList.barang tr:even").addClass("stripe1");
        $("#theList.barang tr:odd").addClass("stripe2");

        $("#theList.barang tr").hover(
            function() {
                $(this).toggleClass("highlight");
            },
            function() {
                $(this).toggleClass("highlight");
            }
        );
    });	
});

	function pilih(ID){
		var kode 	= ID;
	    var kodecab = $('#txt_kodecab').val();
	    var kategori= $('#txt_kategori').val();
		
		$.ajax({
			type	: "POST",
			url		: "kasir/penjualan/cari_barang.php",
			data	: "kode="+kode+
					"&kodecab="+kodecab,
			dataType: "json",
			success	: function(data){
				$("#txt_kodest").val(kode);
				$("#txt_namast").val(data.namast);
				$("#txt_barcode").val(data.barcode);
				$("#txt_satuan").val(data.satuan);
				$("#t_hgjual").val(data.hgjual);
				$("#txt_hgjual").val(data.hgjual);
				$("#txt_hgresep").val(data.hgresep);
				$("#txt_hgparam").val(data.hgparam);
				$("#txt_hgbeli").val(data.hgbeli);
				$("#txt_kodesp").val(data.kodesp);
				$("#txt_jmlstok").val(data.jmlstok);
				$("#txt_kodegr").val(data.kodegr);
				$("#form_cari_barang").dialog('close');
				$("#txt_caribr").val('');
				var namast =$("#txt_namast").val();
				var kodedt =$("#txt_kodedt").val();
				var kodepl =$("#txt_kodepl").val();
				var hgresep=$("#txt_hgresep").val();
				var hgparam=$("#txt_hgparam").val();
				
				if(!kodedt=='') $("#txt_hgjual").val(hgresep);
				if(!kodepl=='') $("#txt_hgjual").val(hgparam);
				
				if(kategori=='PARAMEDIS') $("#txt_hgjual").val(hgparam);
				if(kategori=='RESEP') $("#txt_hgjual").val(hgresep);
				
				if(namast.length>2) $("#txt_jmlunit").focus();
			}
		});
	}
	
	function tampil_gambar(){
		var kode = $("#txt_kodest").val();
		$("#tampil_gambar").show();
		$("#tampil_gambar").load("kasir/penjualan/tampil_gambar.php?kode="+kode);
	}
</script>
<?php
include '../../inc/inc.koneksi.php';

$cari	= $_GET['cari'];
$kodecab= $_GET['kodecab'];

echo "<table id='theList' class='barang' width='100%'>
		<tr>
			<th>No.</th>
			<th>Kode</th>
			<th>Nama Barang</th>
			<th>Barcode</th>
			<th>Satuan</th>
			<th>Harga Umum</th>
			<th>Harga Resep</th>
			<th>Hg. Paremedis</th>
			<th>Jml. Stok</th>
			<th>Ambil</th>
		</tr>";
		if (!empty($cari))
			$sql = "SELECT * FROM stock WHERE (kode_st LIKE '%$cari%' OR nama_st LIKE '%$cari%') AND kode_cab='$kodecab'  ORDER BY kode_st";
		else
			$sql = "SELECT * FROM stock WHERE kode_cab='$kodecab' ORDER BY kode_st";
		$query = mysql_query($sql);
		
		$no=1;
		while($r=mysql_fetch_array($query)){
/*
		    $kodest=$r['kode_st'];
		    $sql1=mysql_query("SELECT * FROM stock WHERE kode_st='$kodest' AND kode_cab='01'");
		    $r1=mysql_fetch_assoc($sql1);
		    $jmlstokb=$r1['jml_stokb'];
*/		    
			echo "<tr>
				<td align='center'>$no</td>
				<td>$r[kode_st]</td>
				<td>$r[nama_st]</td>
				<td>$r[barcode]</td>
				<td>$r[satuan]</td>
				<td>$r[hg_jual]</td>
				<td>$r[hg_resep]</td>
				<td>$r[hg_param]</td>
				<td align='right'>$r[jml_stok]</td>
				<td align='center'>
					<a href='javascript:void(0)' onClick=\"pilih('$r[kode_st]')\">
						<img src='icon/download.gif' border='0' id='tambah_data' title='Tambah' width='20' height='20'>
					</a>					
				</td>
			</tr>";
			$no++;			
		}
	echo "</table>";
?>