<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_nofak").val(kode);
				$("#txt_tglfak").val(data.tglfak);
				$("#txt_nopol").val(data.nopol);				
				$("#txt_jmlpiut").val(data.jmlpiut);
				$("#txt_dibayar").val(data.dibayar);
				$("#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/batal.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#txt_tbayar").val(data.tbayar);
				tampil_detail();
			}
		});
		}
	}
	
	function tampil_detail(){
		$("#data_detail").show();
		$("#data_detail").load("modul/pener_piut/tampil_data_tmp.php?");
		$("#txt_nofak").focus();
	}
</script>

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

echo "<table id='theList' width='100%'>
		<tr>			
			<th>No. Faktur</th>
			<th>Tanggal</th>
			<th>No. Polisi</th>
			<th>Jml.Liter</th>
			<th>Nominal</th>
			<th>Dibayar</th>
			<th>Sisa</th>
			<th>Action</th>
		</tr>";
		
		$query = "SELECT * FROM jurppi_tmp WHERE batal=''";
		$sql= mysql_query($query);
		$tpiut=0;
		$tbayar=0;
		$tsisa=0;
		$no=1;
		while($r=mysql_fetch_array($sql)){
			
			echo "<tr>
					<td align='center'>$r[nofak]</td>
					<td align='center'>".jin_date_str($r[tgl_fak])."</td>
					<td align='center'>$r[nopol]</td>
					<td align='right'>".number_format($r[jml_liter],2)."</td>
					<td align='right'>".number_format($r[jml_piut],0)."</td>
					<td align='right'>".number_format($r[dibayar],0)."</td>
					<td align='right'>".number_format($r[sisa],0)."</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++;
			$tpiut=$tpiut+$r[jml_piut];
			$tbayar=$tbayar+$r[dibayar];
			$tsisa=$tsisa+$r[sisa];
		}
		echo "<tr>
				<td></td>
				<td></td>
				<td></td>
				<td>Total</td>
				<td align='right'>".number_format($tpiut,0)."</td>
				<td align='right'>".number_format($tbayar,0)."</td>
				<td align='right'>".number_format($tsisa,0)."</td>
			</tr>
		</table>";
?>
