<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 pilih = confirm('Batalkan penerimaan piutang kode '+ID+' ?');
		
	if (pilih==true){
		var kode = ID;
		$.ajax({
			type	: "POST",
			url		: "md_keu/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);
				$("#pencarian_bt").hide();
				$("#info_batal").show();
				$("#tampil_detail").show();
				$("#tampil_detail").load("md_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>Jumlah Tagihan</th>
			<th>Dibayar Tunai</th>
			<th>Dibayar BG</th>
			<th>Potongan</th>
			<th>Sisa Tagihan</th>
			<th>Batal</th>
		</tr>";
		
		if(!empty($cari))
			$query = "SELECT kode_ppi,tanggal,kode_pl,nama_pl,sum(jml_piut) as jpiut,sum(tunai) as jtunai,sum(jumlah_bg) as jbg,sum(potongan) as jpot,sum(sisa) as jsisa FROM jurppi WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND (kode_pl LIKE '%$cari%' OR nama_pl LIKE '%$cari%') AND posting='P' AND batal='' GROUP BY kode_ppi ";
		else
			$query = "SELECT kode_ppi,tanggal,kode_pl,nama_pl,sum(jml_piut) as jpiut,sum(tunai) as jtunai,sum(jumlah_bg) as jbg,sum(potongan) as jpot,sum(sisa) as jsisa FROM jurppi WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND posting='P' AND batal='' GROUP BY kode_ppi ";
		$data= mysql_query($query);
		
		$tpiut=0;
		$ttunai=0;
		$tbg=0;
		$tpot=0;
		$tsisa=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 align='right'>".number_format($r_data[jpiut],0)."</td>
				<td align='right'>".number_format($r_data[jtunai],0)."</td>
				<td align='right'>".number_format($r_data[jbg],0)."</td>
				<td align='right'>".number_format($r_data[jpot],0)."</td>
				<td align='right'>".number_format($r_data[jsisa],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++;
			$tpiut=$tpiut+$r_data[jpiut];
			$ttunai=$ttunai+$r_data[jtunai];
			$tbg=$tbg+$r_data[jbg];
			$tpot=$tpot+$r_data[jpot];
			$tsisa=$tsisa+$r_data[jsisa];
		}
						
		echo "<tr></tr>
		<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td align='right'>Total</td>
			<td align='right'>".number_format($tpiut,0)."</td>
			<td align='right'>".number_format($ttunai,0)."</td>
			<td align='right'>".number_format($tbg,0)."</td>
			<td align='right'>".number_format($tpot,0)."</td>
			<td align='right'>".number_format($tsisa,0)."</td>
		</tr>";
		
	echo "</table>";
?>