<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 pilih(ID){
		var kode = ID;	
		$.ajax({
			type	: "POST",
			url		: "modul/pener_piut/cari_kode.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#txt_kode").val(kode);				
				$("#txt_tanggal").val(data.tgl);
				$("#txt_namapl").val(data.namapl);
				$("#txt_kodepl").val(data.kodepl);
				$("#txt_kodecab").val(data.kodecab);
				$("#form_cari_ppi").dialog('close');
				$('#data_detail').show();
				$("#txt_nofak").focus();
				cek_nourut();
				tampil_data_detail();	
			}
		});
	}
	
	function cek_nourut(){
		var kode 	= $("#txt_kode").val();
		
		$.ajax({
			type	: "POST",
			url		: "modul/pener_piut/cari_nourut.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#txt_nourut").val(data.nourut);
			}
		});
	}
	
	function tampil_data_detail(){
		var kode = $("#txt_kode").val();
		$("#data_detail").load("modul/pener_piut/tampil_data_detail.php?kode="+kode);
	}
	
</script>

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

$cari = $_POST['cari'];
echo "<table id='theList' width='100%'>
		<tr>
			<th>No.</th>
			<th>Nomor PPI</th>
			<th>Tanggal</th>
			<th>Kode Pelanggan</th>
			<th>Nama Pelanggan</th>
			<th>Kode Cabang</th>
			<th>Jumlah Piutang</th>
			<th>Tunai</th>
			<th>Potongan</th>
			<th>Sisa</th>
			<th>Pilih</th>
		</tr>";
		
		if(!empty($cari))
			$query = "SELECT kode_ppi,tanggal,kode_pl,nama_pl,kode_cab,sum(jml_piut) as jpiut,sum(tunai) as jtunai,sum(potongan) as jpot,sum(sisa) as jsisa FROM jurppi WHERE kode_ppi like '%$cari%' AND posting='' GROUP BY kode_ppi ";
		else
			$query = "SELECT kode_ppi,tanggal,kode_pl,nama_pl,kode_cab,sum(jml_piut) as jpiut,sum(tunai) as jtunai,sum(potongan) as jpot,sum(sisa) as jsisa FROM jurppi WHERE posting='' GROUP BY kode_ppi ";
		
		$sql= mysql_query($query);
				
		$no=1;
		while($r=mysql_fetch_array($sql)){
			echo "<tr>
					<td align='center'>$no</td>
					<td align='center'>$r[kode_ppi]</td>
					<td align='center'>".jin_date_str($r['tanggal'])."</td>
					<td align='center'>$r[kode_pl]</td>
					<td>$r[nama_pl]</td>
					<td align='center'>$r[kode_cab]</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=\"pilih('$r[kode_ppi]')\">
						<img src='images/view.png' border='0' id='edit' title='Pilih PPI' width='12' height='12' ></a>
					</td>
				</tr>";
			$no++;
		}

	echo "</table>";
?>