<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_ppi(ID){
	var kode = ID;
	
	$.ajax({
		type	: "POST",
		url		: "spv/pener_piut/cari_ppi.php",
		data	: "kode="+kode,
		dataType: "json",
		success	: function(data){
			$("#txt_kode").val(kode);
			$("#txt_tanggal").val(data.tgl);
			$("#txt_kodepl").val(data.kodepl);
			$("#txt_namapl").val(data.namapl);
			$("#txt_tglaw").val(data.tglaw);
			$("#txt_tglak").val(data.tglak);
			$("#txt_tbayar").val(data.tbayar);
			$("#pencarian_bt").hide();
			$("#info_batal").show();
			tampil_detail();
		}
	});
}

function tampil_detail(){
	var kode = $("#txt_kode").val();
	
	$("#tampil_detail").show();
	$("#tampil_detail").load("spv/pener_piut/tampil_data_detail.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'];
$cari      = $_GET['cari'];

echo "<table id='theList' width='100%'>
		<tr>
			<th>No.</th>
			<th>Kode PPI</th>
			<th>Tanggal</th>
			<th>Kode Plg</th>
			<th>Nama Pelanggan</th>
			<th>Periode Penjualan</th>
			<th>Jumlah Dibayar</th>
			<th>Batal</th>
		</tr>";
		
		if(!empty($cari))
			$query = "SELECT kode_ppi,tanggal,kode_pl,nama_pl,tanggal_aw,tanggal_ak,sum(dibayar) as bayar FROM jurppi WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND (kode_pl LIKE '%$cari%' OR nama_pl LIKE '%$cari%') AND batal='' GROUP BY kode_ppi ";
		else
			$query = "SELECT kode_ppi,tanggal,kode_pl,nama_pl,tanggal_aw,tanggal_ak,sum(dibayar) as bayar FROM jurppi WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND batal='' GROUP BY kode_ppi ";
		$data= mysql_query($query);
		
		$tbayar=0;
		$no=1;
		while($r_data=mysql_fetch_array($data)){
			
			echo "<tr>
				<td align='center'>$no</td>
				<td>$r_data[kode_ppi]</td>
				<td>".jin_date_str($r_data[tanggal])."</td>
				<td>$r_data[kode_pl]</td>
				<td>$r_data[nama_pl]</td>
				<td>".jin_date_str($r_data[tanggal_aw])." - ".jin_date_str($r_data[tanggal_ak])."</td>
				<td align='right'>".number_format($r_data[bayar],0)."</td>
				<td align='center'>
					<a href='javascript:void(0)' onClick=\"batal_ppi('$r_data[kode_ppi]')\">
					<img src='icon/thumb_down.png' border='0' id='batal' title='Batal' width='12' height='12' ></a>	
				</td>
			</tr>";
			$no++;
			$tbayar=$tbayar+$r_data[bayar];
		}
						
		echo "<tr></tr>
				<tr>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>					
					<td align='right'>Total</td>
					<td align='right'>".number_format($tbayar,0)."</td>
				</tr>";
		
	echo "</table>";
?>