<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/pengel_kas/cari_kode.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#txt_kode").val(kode);				
				$("#txt_tanggal").val(data.tgl);
				$("#txt_nokas").val(data.nokas);
				$("#txt_namakas").val(data.nakas);
				$("#txt_pener").val(data.pener);
				$("#form_cari_bkk").dialog('close');
				$('#data_detail').show();
				$("#txt_naakun").focus();
				cek_nourut();
				tampil_data_detail();
			}
		});		
	}
	
	function cek_nourut(){
		var kode 	= $("#txt_kode").val();
		
		$.ajax({
			type	: "POST",
			url		: "modul/pengel_kas/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/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);				
			}
		});
	}	
</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 BKK</th>
			<th>Tanggal</th>
			<th>Akun Kas</th>
			<th>Nama Kas</th>
			<th>Penerima</th>
			<th>Jml. Item</th>
			<th>Jml. Nominal</th>
			<th>Posting</th>
			<th>Pilih</th>
		</tr>";
		
		if(!empty($cari))
			$query = "SELECT kode_kk,tanggal,nokas,namakas,penerima,count(noakun) as totitem,sum(jumlah) as tjumlah,posting FROM jurkk WHERE kode_kk LIKE '%$cari%' AND posting='' GROUP BY kode_kk ";
		else
			$query = "SELECT kode_kk,tanggal,nokas,namakas,penerima,count(noakun) as totitem,sum(jumlah) as tjumlah,posting FROM jurkk WHERE posting='' GROUP BY kode_kk ";
		
		$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_kk]</td>
					<td align='center'>".jin_date_str($r_data[tanggal])."</td>
					<td align='center'>$r_data[nokas]</td>
					<td>$r_data[namakas]</td>
					<td>$r_data[penerima]</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_kk]')\">
						<img src='images/view.png' border='0' id='edit' title='Pilih BKK' width='12' height='12' ></a>
					</td>
				</tr>";
			$no++;								
		}
	echo "</table>";
?>