<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 noakun = ID;
		var tglawal = $("#mbb_tglawal").val();
		var tglakhir = $("#mbb_tglakhir").val();
						
		$.ajax({
			type	: "POST",
			url		: "modul/akun_bb/cari.php",
			data	: "noakun="+noakun,
			dataType: "json",
			success	: function(data){
				$("#mbb_noakun").val(noakun);
				$("#mbb_naakun").val(data.naakun);
				$("#mbb_kode").val(data.kode);
				$("#pencarian_mbb").hide();
				$("#tampil_data_mbb").hide();
				$("#info_mbb").show();
				$("#tampil_detail_mbb").show();
				$("#tampil_detail_mbb").load("modul/akun_bb/tampil_detail_mbb.php?noakun="+noakun+"&tglawal="+tglawal+"&tglakhir="+tglakhir);
			}
		});
	}
</script>

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

$tgl_aw	= $_GET[tgl_awal];
$tgl_ak	= $_GET[tgl_akhir];
$cari  	= $_GET[cari];

echo "<table id='theList' width='100%'>
		<tr>			
			<th>Kode</th>
			<th>Nama Akun</th>
			<th>Debet</th>
			<th>Kredit</th>
			<th>Pilih</th>
		</tr>";
		if(!empty($cari))
			$query1= "SELECT nogol FROM akun_bb WHERE (naakun LIKE '%$cari%' or noakun LIKE '%$cari%') GROUP BY nogol";
		else
			$query1= "SELECT nogol FROM akun_bb GROUP BY nogol";
		$data1	= mysql_query($query1);
		
		$jml=1;
		$tdebet=0;
		$tkredit=0;
		while($r1=mysql_fetch_array($data1)){
			$nogol=$r1[nogol];

			$sql  = mysql_query("SELECT * FROM gol_akun WHERE nogol='$nogol' ");
			$data = mysql_fetch_assoc($sql);
			$nagol= $data[nagol];

			echo "<tr>
				<td><b>$nogol</b></td>			
				<td><b>$nagol</b></td>
			</tr>";
			if(!empty($cari))
				$query= mysql_query("SELECT * FROM akun_bb WHERE (naakun LIKE '%$cari%' or noakun LIKE '%$cari%') AND nogol='$nogol' AND level='2' ORDER BY noakun");
			else
				$query= mysql_query("SELECT * FROM akun_bb WHERE nogol='$nogol'  AND level='2' ORDER BY noakun");
					
			$sdebet=0;
			$skredit=0;
			while($r=mysql_fetch_array($query)){
				if($r[kode]=='D'){
					$debet=$r[saldo]+$r[mutasi_db]-$r[mutasi_kd];
					$kredit='';
				}else{
					$kredit=$r[saldo]+$r[mutasi_kd]-$r[mutasi_db];
					$debet='';
				}				
				$kode	=$r[kode];
				$noakun	=$r[noakun];
				
				$sql1=mysql_query("SELECT sum(debet) as jdebet,sum(kredit) as jkredit FROM rekapjur WHERE tanggal>'$tgl_ak' AND noakun='$noakun' GROUP BY noakun");				
				$r1	 =mysql_fetch_assoc($sql1);
				if($kode=='D'){
					$mutasi	=$r1[jdebet]-$r1[jkredit];
					$debet	=$debet-$mutasi;
					$sdebet	=$sdebet+$debet;
				}else{
					$mutasi	=$r1[jkredit]-$r1[jdebet];
					$kredit	=$kredit-$mutasi;
					$skredit	=$skredit+$kredit;
				}
				
				echo "<tr>					
					<td>$r[noakun]</td>
					<td>$r[naakun]</td>
					<td align='right'>".number_format($debet,2)."</td>
					<td align='right'>".number_format($kredit,2)."</td>
					<td align='center'>
						<a href='javascript:void(0)' onClick=\"pilih('$r[noakun]')\">
							<img src='images/view.png' border='0' id='lihat' title='Lihat Buku Besar' width='18' height='18'>
						</a>
					</td>
				</tr>";					
			}
			echo "<tr>
				<td></td>
				<td>Jumlah</td>
				<td align='right'>".number_format($sdebet,2)."</td>
				<td align='right'>".number_format($skredit,2)."</td>
			</tr>";
			$tdebet=$tdebet+$sdebet;
			$tkredit=$tkredit+$skredit;
		}
		echo "<tr></tr>			
		<tr>
			<td></td>
			<td>Total</td>
			<td align='right'>".number_format($tdebet,2)."</td>
			<td align='right'>".number_format($tkredit,2)."</td>
		</tr>
	</table>";
?>