<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	: "modul/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("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>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(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 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(potongan) as jpot,sum(sisa) as jsisa FROM jurppi WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND batal='' GROUP BY kode_ppi ";
		$data= mysql_query($query);
		
		$tpiut=0;
		$ttunai=0;		
		$tpot=0;
		$tsisa=0;
		$no=1;
		while($r=mysql_fetch_array($data)){
			
			echo "<tr>
				<td align='center'>$no</td>
				<td>$r[kode_ppi]</td>
				<td>".jin_date_str($r['tanggal'])."</td>
				<td>$r[kode_pl]</td>
				<td>$r[nama_pl]</td>
				<td align='right'>".number_format($r['jpiut'],0)."</td>
				<td align='right'>".number_format($r['jtunai'],0)."</td>				
				<td align='right'>".number_format($r['jpot'],0)."</td>
				<td align='right'>".number_format($r['jsisa'],0)."</td>
				<td align='center'>
					<a href='javascript:void(0)' onClick=\"batal_ppi('$r[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['jpiut'];
			$ttunai=$ttunai+$r['jtunai'];
			$tpot=$tpot+$r['jpot'];
			$tsisa=$tsisa+$r['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($tpot,0)."</td>
			<td align='right'>".number_format($tsisa,0)."</td>
		</tr>
	</table>";
?>