<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_nofakkw").val(kode);
				$("#txt_tglfakkw").val(data.tglfak);
				$("#txt_nopolkw").val(data.nopol);
				$("#txt_jmlliterkw").val(data.jmlliter);
				$("#txt_jmlpiutkw").val(data.jmlpiut);
				$("#txt_dibayarkw").val(data.dibayar);				
				$("#txt_sisakw").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_tagihan").val(data.tbayar);
				tampil_detail();
				terbilang();
			}
		});
		}
	}
	
	function tampil_detail(){
		$("#data_detailkw").show();
		$("#data_detailkw").load("modul/pener_piut/tampil_data_kwt.php?");		
	}
	
	function terbilang(){
		var total = $("#txt_tagihan").val();
		
		if(total.length==1)
			konversi1();
		else if(total.length==2)
			konversi2();
		else if(total.length==3)
			konversi3();
		else if(total.length==4)
			konversi4();
		else if(total.length==5)
			konversi5();
		else if(total.length==6)
			konversi6();
		else if(total.length==7)
			konversi7();
		else if(total.length==8)
			konversi8();
		else if(total.length==9)
			konversi9();
	}
	
	function konversi1(){
		var	total= $("#txt_tagihan").val();
		
		$.ajax({
			type	: "POST",	
			url		: "modul/konversi/konversi1.php",
			data	: "total="+total,
			dataType: "json",
			success	: function(data){				
				$("#txt_terbilang").val(data.terbilang);				
			}
		});
	}
	
	function konversi2(){
		var	total = $("#txt_tagihan").val();
		
		$.ajax({
			type	: "POST",
			url	: "modul/konversi/konversi2.php",
			data	: "total="+total,
			dataType	: "json",
			success	: function(data){				
				$("#txt_terbilang").val(data.terbilang);
			}
		});
	}
	
	function konversi3(){
		var	total = $("#txt_tagihan").val();
		
		$.ajax({
			type	: "POST",
			url	: "modul/konversi/konversi3.php",
			data	: "total="+total,
			dataType	: "json",
			success	: function(data){
				$("#txt_terbilang").val(data.terbilang);				
			}
		});		
	}
	
	function konversi4(){
		var	total = $("#txt_tagihan").val();
		
		$.ajax({
			type	: "POST",
			url		: "modul/konversi/konversi4.php",
			data	: "total="+total,
			dataType: "json",
			success	: function(data){				
				$("#txt_terbilang").val(data.terbilang);				
			}
		});
	}
	
	function konversi5(){
		var	total = $("#txt_tagihan").val();
		
		$.ajax({
			type	: "POST",
			url		: "modul/konversi/konversi5.php",
			data	: "total="+total,
			dataType: "json",
			success	: function(data){				
				$("#txt_terbilang").val(data.terbilang);				
			}
		});
	}
	
	function konversi6(){
		var	total = $("#txt_tagihan").val();
		
		$.ajax({
			type	: "POST",
			url		: "modul/konversi/konversi6.php",
			data	: "total="+total,
			dataType: "json",
			success	: function(data){
				$("#txt_terbilang").val(data.terbilang);
			}
		});		
	}
	
	function konversi7(){
		var	total = $("#txt_tagihan").val();
		
		$.ajax({
			type	: "POST",
			url		: "modul/konversi/konversi7.php",
			data	: "total="+total,
			dataType: "json",
			success	: function(data){				
				$("#txt_terbilang").val(data.terbilang);				
			}
		});
	}
	
	function konversi8(){
		var	total = $("#txt_tagihan").val();
				
		$.ajax({
			type	: "POST",
			url		: "modul/konversi/konversi8.php",
			data	: "total="+total,
			dataType: "json",
			success	: function(data){				
				$("#txt_terbilang").val(data.terbilang);				
			}
		});
	}
	
	function konversi9(){
		var	total = $("#txt_tagihan").val();
		
		$.ajax({
			type	: "POST",
			url		: "modul/konversi/konversi9.php",
			data	: "total="+total,
			dataType: "json",
			success	: function(data){				
				$("#txt_terbilang").val(data.terbilang);				
			}
		});		
	}
</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>";
?>
