<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 pilih(ID){
		var kode = ID;	
		$.ajax({
			type	: "POST",
			url		: "modul/pener_bank/cari_kode.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#txt_kode").val(kode);				
				$("#txt_tanggal").val(data.tgl);
				$("#txt_nobank").val(data.nobank);
				$("#txt_namabank").val(data.nabank);
				$("#form_cari_bbm").dialog('close');
				$('#data_detail').show();
				cek_nourut();
				tampil_data_detail();				
			}
		});		
	}
	
	function cek_nourut(){
		var kode 	= $("#txt_kode").val();
		
		$.ajax({
			type	: "POST",
			url		: "modul/pener_bank/cari_nourut.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#txt_nourut").val(data.nourut);
			}
		});
	}
	
	function tampil_data_detail(){
		var kode = $("#txt_kode").val();
		$("#data_detail").load("modul/pener_bank/tampil_data_detail.php?kode="+kode);
		cari_total();
	}
	
	function cari_total(){
		var kode = $("#txt_kode").val();
		
		$.ajax({
			type	: "POST",
			url		: "modul/pener_bank/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';
include '../../inc/fungsi_tanggal.php';

$cari = $_POST['cari'];
echo "<table id='theList' width='100%'>
		<tr>
			<th>No.</th>
			<th>Nomor BBM</th>
			<th>Tanggal</th>
			<th>Akun Bank</th>
			<th>Nama Bank</th>			
			<th>Jml. Item</th>
			<th>Jml. Nominal</th>
			<th>Posting</th>
			<th>Pilih</th>
		</tr>";
		
		if(!empty($cari))
			$query = "SELECT kode_bm,tanggal,nobank,namabank,count(noakun) as totitem,sum(jumlah) as tjumlah,posting FROM jurbm WHERE kode_bm LIKE '%$cari%' AND posting='' GROUP BY kode_bm";
		else
			$query = "SELECT kode_bm,tanggal,nobank,namabank,count(noakun) as totitem,sum(jumlah) as tjumlah,posting FROM jurbm WHERE posting='' GROUP BY kode_bm";
		$sql= mysql_query($query);
				
		$no=1;
		while($r_data=mysql_fetch_array($sql)){
			echo "<tr>
					<td align='center'>$no</td>
					<td align='center'>$r_data[kode_bm]</td>
					<td align='center'>".jin_date_str($r_data[tanggal])."</td>
					<td align='center'>$r_data[nobank]</td>
					<td>$r_data[namabank]</td>					
					<td align='center'>$r_data[totitem]</td>
					<td align='right'>".number_format($r_data[tjumlah],2)."</td>
					<td align='center'>$r_data[posting]</td>
					<td align='center'><a href='javascript:void(0)' onClick=\"pilih('$r_data[kode_bm]')\">
						<img src='images/view.png' border='0' id='edit' title='Pilih Bbm' width='12' height='12' ></a>
					</td>
				</tr>";
			$no++;								
		}

	echo "</table>";
?>
