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

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

	function tampil_pb(ID){
		var kode = ID;	
		$.ajax({
			type	: "POST",
			url		: "modul/pembelian/cari_kode.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#txt_kode").val(kode);
				$("#txt_nomorfk").val(data.nomorfk);
				$("#txt_tanggal").val(data.tgl);
				$("#txt_kodesup").val(data.kodesup);
				$("#txt_namasup").val(data.namasup);
				$("#txt_kodeopb").val(data.kodeopb);
				$("#txt_tanggaljt").val(data.tanggaljt);
				$("#txt_total").val(data.total);
				$("#txt_pot").val(data.potong);
				$("#txt_bayar").val(data.bayar);
				$("#txt_kurang").val(data.kurang);
				$('#form_cari_kodepb').dialog('close');
				$("#info_pbl").hide();
				$("#data_detail").show();
				$("#data_detail").load('modul/pembelian/tampil_data_detail.php?kode='+kode);
				cari_nourut();
				hitung_total();
			}
		});		
	}
	
	function cari_nourut(){
		var kode = $("#txt_kode").val();
				
		$.ajax({
			type	: "POST",
			url		: "modul/pembelian/cari_nourut.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){				
				$("#txt_nourut").val(data.nourut);		
			}
		});
	}
	
	function hitung_total(){
		var kode= $("#txt_kode").val();
		
		$.ajax({
			type	: "POST",
			url		: "modul/pembelian/cari_total.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#txt_total").val(data.total);				
			}
		});
	}
</script>

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

echo "<table id='theList' width='100%'>
		<tr>
			<th>No.</th>
			<th>Kode Pembelian</th>
			<th>Tanggal</th>
			<th>Nomor Faktur</th>
			<th>Supplier</th>
			<th>Total Item</th>
			<th>Total Unit</th>
			<th>Total Harga</th>
			<th>Lihat</th>
		</tr>";
		$query = mysql_query("SELECT kode_pb,tanggal,nomor_fk,nama_sup,count(kode_st) as totitem,sum(jml_unit) as totunit,sum(jumlah) as totjumlah FROM faktur_pb WHERE posting='' AND batal='' GROUP BY kode_pb");
		
		$no=1;
		$total=0;
		while($r=mysql_fetch_array($query)){
			echo "<tr>
				<td align='center'>$no</td>
				<td align='center'>$r[kode_pb]</td>
				<td align='center'>".jin_date_str($r['tanggal'])."</td>
				<td>$r[nomor_fk]</td>
				<td>$r[nama_sup]</td>
				<td align='center'>$r[totitem]</td>
				<td align='right'>$r[totunit]</td>
				<td align='right'>$r[totjumlah]</td>
				<td align='center'>
					<a href='javascript:void(0)' onClick=\"tampil_pb('$r[kode_pb]')\">
						<img src='images/view.png' border='0' id='edit' title='Lihat detail' width='12' height='12' >
					</a>
				</td>
			</tr>";
			$no++;
			$total=$total+$r['totjumlah'];
		}
	echo "</table>";
?>