<script type="text/javascript">
$(document).ready(function() {
    $(function() {
        $("#theList.detail tr:even").addClass("stripe1");
        $("#theList.detail tr:odd").addClass("stripe2");

        $("#theList.detail tr").hover(
            function() {
                $(this).toggleClass("highlight");
            },
            function() {
                $(this).toggleClass("highlight");
            }
        );
    });	
});

	function edit_data(ID){
		var kode = ID;
						
		$.ajax({
			type	: "POST",
			url		: "spv/piutang_dg/cari_fak.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#txt_nofak").val(kode);
				$("#txt_tanggal").val(data.tanggal);
				$("#txt_nopol").val(data.nopol);
				$("#txt_jmlliter").val(data.jmlliter);
				$("#txt_jumlah").val(data.jumlah);
				$("#txt_tanggaljt").val(data.tanggaljt);
			}
		});
	}

	function hapus_data(ID){
		var pilih = confirm('Piutang yang akan dihapus no.faktur = '+ID+ '?');
		if (pilih==true) {
		var kode = ID;
		$.ajax({
			type	: "POST",
			url		: "spv/piutang_dg/hapus.php",
			data	: "kode="+kode,
			success	: function(data){
				$("#info").html(data);
				tampil_detail();
			}
		});
		}
	}
	
	function tampil_detail(){
		var kode = $("#txt_kodepl").val();
		$("#data_detail").load("spv/piutang_dg/tampil_data_detail.php?kode="+kode);
	}
</script>

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

$kode	= $_GET[kode];
echo "<table id='theList' class='detail' width='100%'>
		<tr>
			<th>No.</th>
			<th>No.Faktur</th>
			<th>Tanggal Faktur</th>
			<th>No.Polisi</th>
			<th>Liter</th>
			<th>Saldo</th>
			<th>Jatuh Tempo</th>
			<th>Aksi</th>
		</tr>";
		$query = mysql_query("SELECT * FROM piutang WHERE kode_pl='$kode' ORDER BY kode_pl");		
		$no=1;
		$total=0;
		while($r=mysql_fetch_array($query)){			
			$total	= $total+$r[jumlah];
			
			echo "<tr>
				<td align='center'>$no</td>
				<td align='center'>$r[nofak]</td>
				<td align='center'>".jin_date_str($r[tanggal])."</td>
				<td>$r[nopol]</td>
				<td align='right'>".number_format($r[jml_liter],2)."</td>
				<td align='right'>".number_format($r[jumlah],0)."</td>
				<td align='center'>".jin_date_str($r[tanggal_jt])."</td>
				<td align='center'>
					<a href='javascript:void(0)' onClick=\"edit_data('$r[nofak]')\">
					<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('$r[nofak]')\">
					<img src='icon/thumb_down.png' border='0' id='hapus' title='Hapus' width='12' height='12' ></a>					
				</td>
			</tr>";
			$no++;			
		}
	echo "<tr>		
		<td></td>
		<td></td>
		<td></td>
		<td align='right'>Total</td>
		<td align='right'>".number_format($total,0)."</td>			
	</tr>
</table>";
?>