<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){
				$("#t_kodepb").val(kode);
				$("#t_nomorfk").val(data.nomorfk);
				$("#t_tanggal").val(data.tgl);
				$("#pencarian").hide();
				$("#tampil_data").hide();
				$("#info_beli").show();
				$("#tampil_detail").show();
				$("#tampil_detail").load('modul/pembelian/tampil_data_pb.php?kode='+kode);
			}
		});		
	}
</script>

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

$tgl_awal= $_GET['tgl_awal'];
$tgl_akhir= $_GET['tgl_akhir'];

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>";
		$sql = "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 tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND batal='' GROUP BY kode_pb";

		$query = mysql_query($sql);
		
		$no=1;
		while($r_data=mysql_fetch_array($query)){
			$total = $r_data[total];
			echo "<tr>
					<td align='center'>$no</td>
					<td align='center'>$r_data[kode_pb]</td>
					<td align='center'>".jin_date_str($r_data[tanggal])."</td>
					<td>$r_data[nomor_fk]</td>
					<td>$r_data[nama_sup]</td>
					<td align='center'>$r_data[totitem]</td>
					<td align='right'>$r_data[totunit]</td>
					<td align='right'>$r_data[totjumlah]</td>
					<td align='center'>
					<a href='javascript:void(0)' onClick=\"tampil_pb('$r_data[kode_pb]')\">
						<img src='images/view.png' border='0' id='edit' title='Lihat detail' width='12' height='12' >
					</a>
					</td>
					</tr>";
			$no++;
			$g_total=$g_total+$total;
		}
		
	echo "</table>";
?>