<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	    : "modul/pengel_bank/edit.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#txt_nourut").val(data.nourut);
				$("#txt_noakun").val(data.noakun);
				$("#txt_nobp").val(data.nobp);
				$("#txt_nopol").val(data.nopol);
				$("#txt_naakun").val(data.naakun);				
				$("#txt_ket").val(data.ket);				
				$("#txt_jumlah").val(data.jumlah);
			}
		});		
	}

	function hapus_data(ID){
		var pilih = confirm('Data yang akan dihapus kode = '+ID+ '?');
		if (pilih==true) {
		var kode = ID;
		$.ajax({
			type	: "POST",
			url	    : "modul/pengel_bank/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/pengel_kas/tampil_data_detail.php?kode="+kode);
		cari_total();
	}
	
	function cari_total(){
		var kode = $("#txt_kode").val();
		
		$.ajax({
			type	: "POST",
			url	: "modul/pengel_kas/cari_total.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#txt_total").val(data.total);
				terbilang();
			}
		});
	}
	
	function terbilang(){
		var total = $("#txt_total").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_total").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_total").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_total").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_total").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_total").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_total").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_total").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_total").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_total").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';
$kode	= $_GET[kode];
echo "<table id='theList' class='detail' width='100%'>
		<tr>
			<th>No.</th>
			<th>Kode Akun</th>
			<th>Nama Akun</th>
			<th>Kode BP</th>
			<th>Nama Buku Pembantu</th>
			<th>No.Polisi</th>
			<th>Keterangan</th>
			<th>Jumlah</th>
			<th>Posting</th>
			<th>Aksi</th>
		</tr>";

		$query = mysql_query("SELECT * FROM jurbk WHERE kode_bk='$kode' ORDER BY kode_bk");
		$no=1;
		$total=0;
		while($r_data=mysql_fetch_array($query)){
			$kode  = $r_data[kode_bk].'-'.$r_data[no_urut];
			$total = $total+$r_data[jumlah];
			echo "<tr>
					<td align='center'>$no</td>
					<td align='center'>$r_data[noakun]</td>
					<td>$r_data[naakun]</td>
					<td align='center'>$r_data[nobp]</td>
					<td>$r_data[namabp]</td>
					<td align='center'>$r_data[nopol]</td>
					<td>$r_data[keterangan]</td>					
					<td align='right'>".number_format($r_data[jumlah],2)."</td>
					<td>$r_data[posting]</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++;			
		}
		echo "<tr>				
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td align='right'>Total </td>
				<td align='right'>".number_format($total,2)."</td>
			</tr>";
			
	echo "</table>";	
?>