<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 batal_pb(ID){
		var pilih = confirm('Batalkan faktur pembelian kode '+ID+' ?');
		
		if (pilih==true) {
			var kode = ID;	
			$.ajax({
				type	: "POST",
				url	: "spv/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);
					$("#t_kodesup").val(data.kodesup);
					$("#t_namasup").val(data.namasup);
					$("#t_total").val(data.total);
					$("#t_potong").val(data.potong);
					$("#t_bayar").val(data.bayar);
					$("#t_kurang").val(data.kurang);
					$("#pencarian").hide();
					$("#tampil_data").hide();
					$("#info_beli").show();
					$("#tampil_detail").show();
					$("#tampil_detail").load('spv/pembelian/tampil_data_batal.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>Aksi</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 tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND batal='' AND posting='P' GROUP BY kode_pb");
		
		$no=1;
		while($r=mysql_fetch_array($query)){
			$total = $r['total'];
			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=\"batal_pb('$r[kode_pb]')\">
						<img src='icon/thumb_down.png' border='0' id='edit' title='Batal' width='12' height='12' >
					</a>
				</td>
			</tr>";
			$no++;
			$g_total=$g_total+$total;
		}
	echo "</table>";
?>