<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;		
		$.ajax({
			type	: "POST",
			url		: "modul/returbeli/cari_faktur.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#txt_nomorfk").val(data.nofak);
				$("#txt_tanggalfk").val(data.tanggal);
				$("#form_cari_faktur").dialog('close');
				$("#txt_caraby").focus();
			}
		});
	}

</script>
<?php
include '../../inc/inc.koneksi.php';
include '../../inc/fungsi_tanggal.php';

$kodesup= $_POST['kodesup'];
$cari   = $_POST['cari'];

echo "<table id='theList' class='barang' width='100%'>
		<tr>
			<th>No.</th>
			<th>Kode Sup.</th>
			<th>Nama Supplier</th>
			<th>Tanggal</th>
			<th>Nomor Faktur</th>
			<th>Saldo Hutang</th>
			<th>Jatuh Tempo</th>
			<th>Ambil</th>
		</tr>";
		if(!empty($cari))
			$query = mysql_query("SELECT * FROM hutang WHERE kode_sp='$kodesup' AND nofak LIKE '%$cari%' AND !(jumlah=0) ORDER BY tanggal,nofak");
		else
			$query = mysql_query("SELECT * FROM hutang WHERE kode_sp='$kodesup' AND !(jumlah=0) ORDER BY tanggal,nofak");
		
		$no=1;
		while($r=mysql_fetch_array($query)){
			$kode=$r['kode_sp'].';'.$r['nofak'];
			
			echo "<tr>
				<td align='center'>$no</td>
				<td>$r[kode_sp]</td>
				<td>$r[nama]</td>
				<td align='center'>".jin_date_str($r['tanggal'])."</td>
				<td>$r[nofak]</td>
				<td align='right'>".number_format($r['jumlah'],0)."</td>
				<td align='center'>".jin_date_str($r['tanggal_jt'])."</td>
				<td align='center'>
					<a href='javascript:void(0)' onClick=\"pilih('$kode')\">
					<img src='icon/download.gif' border='0' id='tambah_data' title='Pilih' width='12' height='12' >
					</a>
				</td>
			</tr>";
			$no++;			
		}
echo "</table>";
?>