	<?php
	ini_set("max_execution_time", 0);
	header("Content-Disposition: attachment; filename=\"Buku Besar ".$rekening." ".tgl_id_short($_POST['tglawal'])."-".tgl_id_short($_POST['tglakhir']).".xls\"");
	header("Content-type: application/vnd.ms-excel");  
	?>
	<h3 align="center">Buku Besar <?php echo $rekening;?></h3>
	<h4 align="center">Periode <?php echo tgl_id_short($_POST['tglawal']);?> s/d <?php echo tgl_id_short($_POST['tglakhir']);?></h4>
	<table border="1">
		<thead>
			<tr>
				<th>#</th>
				<th>Tgl Jurnal</th>
				<th>No Jurnal</th>
				<th>No Bukti</th>
				<th>Keterangan</th>
				<th>Detail</th>
				<th>Saldo Awal</th>														
				<th>Mutasi Debit</th>														
				<th>Mutasi Kredit</th>														
				<th>Saldo Akhir</th>					
			</tr>
		</thead>
		
		<?php $no=1; $saldoakhir=0; $saldoawal=	0; $totdebit=0;$totkredit=0;	
		foreach($resulte as $dtk){ 	
			if(empty($dtk->ket_harian) AND !empty($dtk->ket_pesan)){
				$detail= $dtk->ket_pesan;
			}else if(!empty($dtk->ket_harian) AND empty($dtk->ket_pesan)){
				$detail= $dtk->ket_harian;
			}else{
				$detail="";
			}
			if(isset($debitz[trim($dtk->no_jurnal)])){
				$debitxz=$debitz[trim($dtk->no_jurnal)];
			}else{
				$debitxz=0;
			}
		
			if(isset($kreditz[trim($dtk->no_jurnal)])){
				$kreditxz=$kreditz[trim($dtk->no_jurnal)];
			}else{
				$kreditxz=0;
			}
			
			if($dtk->balance=='D'){
				if($saldoawal==0){
					$saldoawal=$sald;														
					$saldoakhir=$sald + $debitxz - $kreditxz;														
				}else{														
					$saldoakhir=$saldoawal + $debitxz - $kreditxz;														
				}
			}else{
				if($saldoawal==0){
					$saldoawal=$sald;														
					$saldoakhir=$sald - $debitxz + $kreditxz;
				}else{														
					$saldoakhir=$saldoawal - $debitxz + $kreditxz;
				}
			}
			
			$totdebit=$totdebit + $debitxz;
			$totkredit=$totkredit + $kreditxz;
		?>
			<tr>
				<td><?php echo $no;?></td>
				<td><?php echo $dtk->tgl_jurnal;?></td>
				<td><?php echo $dtk->no_jurnal;?></td>
				<td><?php echo $dtk->no_bukti;?></td>
				<td><?php echo $dtk->keterangan;?></td>
				<td><?php echo $detail;?></td>
				<td><?php echo number_format($saldoawal,0,",",",");?></td>
				<td align="right"><?php echo number_format($debitxz,0,",",",");?></td>
				<td align="right"><?php echo number_format($kreditxz,0,",",",");?></td>
				<td align="right"><?php echo number_format($saldoakhir,0,",",",");?></td>	

			</tr>
		<?php $no++; $saldoawal=$saldoakhir; $sald=$saldoakhir; } ?>
			<tr>
				<td colspan="6"></td>
				<td></td>
				<td><?php echo number_format($totdebit,0,",",",");?></td>
				<td><?php echo number_format($totkredit,0,",",",");?></td>
				<td></td>
			</tr>
	</table>