<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 edit_data(ID){
		var kode = ID;
						
		$.ajax({
			type	: "POST",
			url	: "modul/pener_piut/edit.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#txt_nourut").val(data.nourut);
				$("#txt_nofak").val(data.nofak);
				$("#txt_tglfak").val(data.tglfak);
				$("#txt_jmlpiut").val(data.jmlpiut);
				$("#txt_tunai").val(data.tunai);
				$("#txt_potongan").val(data.potongan);
				$("#txt_sisa").val(data.sisa);
			}
		});		
	}

	function hapus_data(ID){
		var pilih = confirm('Data yang akan dihapus kode = '+ID+ '?');
		if (pilih==true) {
		var kode = ID;
		$.ajax({
			type	: "POST",
			url	: "modul/pener_piut/hapus.php",
			data	: "kode="+kode,
			success	: function(data){
				$("#info").html(data);
				tampil_data_detail();
			}
		});
		}
	}
	
	function tampil_data_detail(){
		var	kode=$("#txt_kode").val();
		$("#data_detail").load("modul/pener_piut/tampil_data_detail.php?kode="+kode);
		return (false);
	}
</script>

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

$kode = $_GET['kode'];
echo "<table id='theList' width='100%'>
		<tr>			
			<th>No.Faktur</th>
			<th>Tanggal</th>
			<th>Saldo</th>
			<th>Dibayar</th>
			<th>Potongan</th>
			<th>Sisa</th>
			<th>Aksi</th>
		</tr>";		
		$sql= mysql_query("SELECT * FROM jurppi WHERE kode_ppi='$kode' AND batal=''");
		
		$tpiut=0;
		$ttunai=0;
		$tpot=0;
		$tsisa=0;
		$no=1;
		while($r=mysql_fetch_array($sql)){
			$kode = $r['kode_ppi'].'.'.$r['no_urut'];
			
			echo "<tr>
				<td align='center'>$r[nofak]</td>
				<td align='center'>".jin_date_str($r['tgl_fak'])."</td>
				<td align='right'>".number_format($r['jml_piut'],0)."</td>
				<td align='right'>".number_format($r['tunai'],0)."</td>
				<td align='right'>".number_format($r['potongan'],0)."</td>
				<td align='right'>".number_format($r['sisa'],0)."</td>
				<td align='center'>
					<a href='javascript:void(0)' onClick=\"edit_data('$kode')\">
					<img src='icon/thumb_up.png' border='0' id='edit' title='Edit' width='12' height='12' ></a>					
					<a href='javascript:void(0)' onClick=\"hapus_data('$kode')\">
					<img src='icon/thumb_down.png' border='0' id='hapus' title='Hapus' width='12' height='12' ></a>					
				</td>
			</tr>";
			$no++;
			$tpiut=$tpiut+$r['jml_piut'];
			$ttunai=$ttunai+$r['tunai'];
			$tpot=$tpot+$r['potongan'];
			$tsisa=$tsisa+$r['sisa'];
		}
		echo "<tr>
			<td></td>
			<td>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>";
?>