<script type="text/javascript">	
	window.print();
</script>

<?php
	include '../../inc/inc.koneksi.php';
	include '../../inc/fungsi_tanggal.php';
		
	$norek	    = $_GET['noakun'];
    $tglawal    = $_GET['tglawal'];
    $tglakhir   = $_GET['tglakhir'];

    $query2 = mysql_query("SELECT * FROM akun_bb WHERE noakun='$norek' ORDER BY noakun");
    $r2     = mysql_fetch_assoc($query2);
    $naakun = $r2[naakun];
    $kode	= $r2[kode];
    if($kode=='D')
	    $saldo=$r2[saldo]+$r2[mutasi_db]-$r2[mutasi_kd];
    else 
	    $saldo=$r2[saldo]+$r2[mutasi_kd]-$r2[mutasi_db];

    $query1 = mysql_query("SELECT noakun,sum(debet) as jdebet,sum(kredit) as jkredit FROM rekapjur WHERE tanggal>='$tglawal' AND noakun='$norek' AND batal='' AND (!debet='' OR !kredit='') GROUP BY noakun ");
    $rows	= mysql_num_rows($query2);
    if($rows>0){
        while($r1=mysql_fetch_array($query1)){
	        $jdebet=$r1[jdebet];
	        $jkredit=$r1[jkredit];
        }
    }else{
	    $jdebet=0;
	    $jkredit=0;
    }

    if($kode=='D'){
	    $sdawal=$saldo-$jdebet+$jkredit;
    }else{
	    $sdawal=$saldo-$jkredit+$jdebet;
    }
    $sdakhir=$sdawal;
	
	$query2	= mysql_query("SELECT * FROM company");
	$r2		= mysql_fetch_assoc($query2);
	$kop1 	= $r2[nama1];
	$kop2 	= $r2[nama2];
	$kop3 	= $r2[nama3];
	
	echo "<table width='100%'>
		<tr>
			<td style='font:arial 11px'><b>$kop1</b></td>
		</tr>
		<tr>
			<td style='font:arial 11px'>$kop2</td>
		</tr>
		<tr>
			<td style='font:arial 11px'>$kop3</td>
		</tr>
	</table>
		
	<table width='100%'>
		<tr>
			<td align='center' style='font:arial 14px'><b>LAPORAN BUKU BESAR</b></td>
		</tr>
		<tr>
			<td align='center' style='font:arial 14px'><b>Periode  ".jin_date_str($tglawal)." S/D ".jin_date_str($tglakhir)."</b></td>
		</tr>
	</table>
	<br>
	
	<table>
		<tr>
			<td>Akun : $norek - $naakun</td>
			<td></td>
			<td>Saldo Awal	: Rp ".number_format($sdawal,2)."</td>
		</tr>
	</table>
	
	<table width='100%' border='1' style='border-collapse:collapse;font:12px arial'>
		<tr>				
			<th>Tanggal</th>
			<th>Nomor Bukti</th>
			<th>Kode Trans</th>
			<th>Keterangan</th>
			<th>Debet</th>
			<th>Kredit</th>
			<th>Saldo</th>
		</tr>";
		
		$jdebet =0;
		$jkredit=0;
		$query	= mysql_query("SELECT * FROM rekapjur WHERE tanggal BETWEEN '$tglawal' AND '$tglakhir' AND noakun='$norek' AND batal='' ORDER BY tanggal");
		while($r=mysql_fetch_array($query)){
			if($kode=='D')
				$sdakhir=$sdakhir+$r[debet]-$r[kredit];
			else
				$sdakhir=$sdakhir+$r[kredit]-$r[debet];
			
			echo "<tr>
				<td>".jin_date_str($r[tanggal])."</td>
				<td>$r[no_bukti]</td>
				<td align='center'>$r[kode_tr]</td>
				<td>$r[keterangan]</td>
				<td align='right'>".number_format($r[debet],2)."</td>
				<td align='right'>".number_format($r[kredit],2)."</td>
				<td align='right'>".number_format($sdakhir,2)."</td>
			</tr>";			
			$jdebet=$jdebet+$r[debet];
			$jkredit=$jkredit+$r[kredit];								
		}	
		echo "<tr>
			<td></td>
			<td></td>
			<td></td>
			<td align='right'>Jumlah </td>
			<td align='right'>".number_format($jdebet,2)."</td>
			<td align='right'>".number_format($jkredit,2)."</td>
		</tr>
	</table>";
?>
<script type="text/javascript">	
	history.back();
</script>