	<?php
	if($_POST['bulan']== $_POST['bulanakh']){
		$ketperiode= monthFull($_POST['bulan']);
	}else{
		$ketperiode= monthFull($_POST['bulan'])." sd ".monthFull($_POST['bulanakh']);
	}
	
	ini_set("max_execution_time", 0);
	header("Content-Disposition: attachment; filename=\"Laba-rugi Periode  ". $ketperiode." ".$_POST['tahun'].".xls\"");
	header("Content-type: application/vnd.ms-excel");  
	?>
	<!--img src="images/logo-3x3.jpg"-->
	<h3 align="center"> RS.INSAN PERMATA <br>LAPORAN LABA(RUGI)<?php //echo $rekening;?></h3>	
	<h4 align="center">Periode <?php echo $ketperiode;?> Tahun <?php echo $_POST['tahun'];?></h4>
	<table border="1" align="center">
		<thead>
			<tr>
				<th style="background-color:#00238c;color:#eeeeee;">Kode Akun</th>
				<th style="background-color:#00238c;color:#eeeeee;">Nama Akun</th>
				<th style="background-color:#00238c;color:#eeeeee;">Saldo</th>				
			</tr>
		</thead>
		<tbody>
		<tr><td align="center" colspan="3" style="background-color:#ffff00;"><strong>Pendapatan Operasional</strong></td></tr>
		<?php $no=1;$saldopo=0;$rekening=array('4','5','6');
		$tpopera=0;
		foreach($resultpo as $dtkpo){ 
			
		if(isset($debitzrealpo[trim($dtkpo->kd_rek)])){
			$debitxzrealpo=$debitzrealpo[trim($dtkpo->kd_rek)];
		}else{
			$debitxzrealpo=0;
		}
		if(isset($kreditzrealpo[trim($dtkpo->kd_rek)])){
			$kreditxzrealpo=$kreditzrealpo[trim($dtkpo->kd_rek)];
		}else{
			$kreditxzrealpo=0;
		}
		
		if(isset($debitzpo[trim($dtkpo->kd_rek)])){
			$debitxzpo=$debitzpo[trim($dtkpo->kd_rek)];
		}else{
			$debitxzpo=0;
		}												
		if(isset($kreditzpo[trim($dtkpo->kd_rek)])){
			$kreditxzpo=$kreditzpo[trim($dtkpo->kd_rek)];
		}else{
			$kreditxzpo=0;
		}
		
		if(!in_array(substr($dtkpo->kd_rek,0,1),$rekening)){	
			if(isset($balancezpo[trim($dtkpo->kd_rek)]) AND $balancezpo[trim($dtkpo->kd_rek)]=='D'){
				$saldoawlpo=$saldozpo[trim($dtkpo->kd_rek)]+$debitxzpo - $kreditxzpo;
			}else if(isset($balancezpo[trim($dtkpo->kd_rek)]) AND $balancezpo[trim($dtkpo->kd_rek)]=='K'){
				
				$saldoawlpo=$saldozpo[trim($dtkpo->kd_rek)]-$debitxzpo + $kreditxzpo;
			}else{
				$saldoawlpo=0;
			}
		} else{
			$saldoawlpo=0;
		} 	
			
		if($dtkpo->balance=='D'){
			$saldoakhpo=$saldoawlpo+$debitxzrealpo - $kreditxzrealpo;
		}else{
			$saldoakhpo=$saldoawlpo-$debitxzrealpo + $kreditxzrealpo;
		}
		?>
		<?php												 
		$tpopera=$tpopera+$saldoakhpo;
		?>
			<tr>
				<td><?php echo $dtkpo->kd_rek;?></td>
				<td><?php echo $dtkpo->nm_rek;?></td>		
				<td align="right"><?php echo number_exc_koma($saldoakhpo);?></td>
			</tr>
		<?php  } ?>
		<tr style="background-color:#ffffbf;"><td colspan="2"><strong>Jumlah Pendapatan Operasional</strong></td><td align="right"><strong><?php echo number_exc_koma($tpopera);?></strong></td></tr>	
		
		<tr><td colspan="3" style="background-color:#ffff00;" align="center"><strong>Beban Operasional</strong></td></tr>
		
		<?php $nobo=1;$saldobo=0;$rekeningbo=array('4','5','6');
		$tbopera=0;
		foreach($resultbo as $dtkbo){ 
			
		if(isset($debitzrealbo[trim($dtkbo->kd_rek)])){
			$debitxzrealbo=$debitzrealbo[trim($dtkbo->kd_rek)];
		}else{
			$debitxzrealbo=0;
		}
		if(isset($kreditzrealbo[trim($dtkbo->kd_rek)])){
			$kreditxzrealbo=$kreditzrealbo[trim($dtkbo->kd_rek)];
		}else{
			$kreditxzrealbo=0;
		}
		
		if(isset($debitzbo[trim($dtkbo->kd_rek)])){
			$debitxzbo=$debitzbo[trim($dtkbo->kd_rek)];
		}else{
			$debitxzbo=0;
		}												
		if(isset($kreditzbo[trim($dtkbo->kd_rek)])){
			$kreditxzbo=$kreditzbo[trim($dtkbo->kd_rek)];
		}else{
			$kreditxzbo=0;
		}
		
	if(!in_array(substr($dtkbo->kd_rek,0,1),$rekening)){	
		if(isset($balancezbo[trim($dtkbo->kd_rek)]) AND $balancezbo[trim($dtkbo->kd_rek)]=='D'){
			$saldoawlbo=$saldozbo[trim($dtkbo->kd_rek)]+$debitxzbo - $kreditxzbo;
		}else if(isset($balancezbo[trim($dtkbo->kd_rek)]) AND $balancezbo[trim($dtkbo->kd_rek)]=='K'){
			
			$saldoawlbo=$saldozbo[trim($dtkbo->kd_rek)]-$debitxzbo + $kreditxzbo;
		}else{
			$saldoawlbo=0;
		}
	} else{
		$saldoawlbo=0;
	} 	
			
		if($dtkbo->balance=='D'){
			$saldoakhbo=$saldoawlbo+$debitxzrealbo - $kreditxzrealbo;
		}else{
			$saldoakhbo=$saldoawlbo-$debitxzrealbo + $kreditxzrealbo;
		}
		?>
		<?php												 
		$tbopera=$tbopera+$saldoakhbo;
		?>
			<tr>
				<td><?php echo $dtkbo->kd_rek;?></td>
				<td><?php echo $dtkbo->nm_rek;?></td>		
				<td align="right"><?php echo number_exc_koma($saldoakhbo);?></td>
			</tr>
		<?php  } ?>
		<tr style="background-color:#ffffbf;"><td colspan="2"><strong>Jumlah Beban Operasional</strong></td><td align="right"><strong><?php echo number_exc_koma($tbopera);?></strong></td></tr>
		<?php $labapera=$tpopera - $tbopera; ?>
		<tr style="background-color:#265cff;color:#fdfdff;"><td colspan="2"><strong>Laba(Rugi) Operasional </strong></td><td align="right"><strong><?php echo number_exc_koma($labapera);//number_format($labapera,0,".","."));?></strong></td></tr>
		
		<!-- PL-->
		<tr><td colspan="3" style="background-color:#80ff00;" align="center"><strong>Pendapatan Lain-lain</strong></td></tr>
		<?php $nopl=1;$saldopl=0;$rekeningpl=array('4','5','6');
		$tplain=0;
		foreach($resultpl as $dtkpl){ 
			
		if(isset($debitzrealpl[trim($dtkpl->kd_rek)])){
			$debitxzrealpl=$debitzrealpl[trim($dtkpl->kd_rek)];
		}else{
			$debitxzrealpl=0;
		}
		if(isset($kreditzrealpl[trim($dtkpl->kd_rek)])){
			$kreditxzrealpl=$kreditzrealpl[trim($dtkpl->kd_rek)];
		}else{
			$kreditxzrealpl=0;
		}
		
		if(isset($debitzpl[trim($dtkpl->kd_rek)])){
			$debitxzpl=$debitzpl[trim($dtkpl->kd_rek)];
		}else{
			$debitxzpl=0;
		}												
		if(isset($kreditzpl[trim($dtkpl->kd_rek)])){
			$kreditxzpl=$kreditzpl[trim($dtkpl->kd_rek)];
		}else{
			$kreditxzpl=0;
		}
		
	if(!in_array(substr($dtkpl->kd_rek,0,1),$rekeningpl)){	
		if(isset($balancezpl[trim($dtkpl->kd_rek)]) AND $balancezpl[trim($dtkpl->kd_rek)]=='D'){
			$saldoawlpl=$saldozpl[trim($dtkpl->kd_rek)]+$debitxzpl - $kreditxzpl;
		}else if(isset($balancezpl[trim($dtkpl->kd_rek)]) AND $balancezpl[trim($dtkpl->kd_rek)]=='K'){
			
			$saldoawlpl=$saldozpl[trim($dtkpl->kd_rek)]-$debitxzpl + $kreditxzpl;
		}else{
			$saldoawlpl=0;
		}
	} else{
		$saldoawlpl=0;
	} 	
			
		if($dtkpl->balance=='D'){
			$saldoakhpl=$saldoawlpl+$debitxzrealpl - $kreditxzrealpl;
		}else{
			$saldoakhpl=$saldoawlpl-$debitxzrealpl + $kreditxzrealpl;
		}
		?>
		<?php												 
		$tplain=$tplain+$saldoakhpl;
		?>
			<tr>
				<td><?php echo $dtkpl->kd_rek;?></td>
				<td><?php echo $dtkpl->nm_rek;?></td>		
				<td align="right"><?php echo number_exc_koma($saldoakhpl);?></td>
			</tr>
		<?php  } ?>
		<tr style="background-color:#cfffbf;"><td colspan="2"><strong>Jumlah Pendapatan Lain-lain</strong></td><td align="right"><strong><?php echo number_exc_koma($tplain);?></strong></td></tr>
		
		<!-- BL-->
		<tr><td colspan="3" style="background-color:#40ff00;" align="center"><strong>Beban Lain-lain</strong></td></tr>
		<?php $nobl=1;$saldobl=0;$rekeningbl=array('4','5','6');
		$tblain=0;
		foreach($resultbl as $dtkbl){ 
			
		if(isset($debitzrealbl[trim($dtkbl->kd_rek)])){
			$debitxzrealbl=$debitzrealbl[trim($dtkbl->kd_rek)];
		}else{
			$debitxzrealbl=0;
		}
		if(isset($kreditzrealbl[trim($dtkbl->kd_rek)])){
			$kreditxzrealbl=$kreditzrealbl[trim($dtkbl->kd_rek)];
		}else{
			$kreditxzrealbl=0;
		}
		
		if(isset($debitzbl[trim($dtkbl->kd_rek)])){
			$debitxzbl=$debitzbl[trim($dtkbl->kd_rek)];
		}else{
			$debitxzbl=0;
		}												
		if(isset($kreditzbl[trim($dtkbl->kd_rek)])){
			$kreditxzbl=$kreditzbl[trim($dtkbl->kd_rek)];
		}else{
			$kreditxzbl=0;
		}
		
	if(!in_array(substr($dtkbl->kd_rek,0,1),$rekeningbl)){	
		if(isset($balancezbl[trim($dtkbl->kd_rek)]) AND $balancezbl[trim($dtkbl->kd_rek)]=='D'){
			$saldoawlbl=$saldozbl[trim($dtkbl->kd_rek)]+$debitxzbl - $kreditxzbl;
		}else if(isset($balancezbl[trim($dtkbl->kd_rek)]) AND $balancezbl[trim($dtkbl->kd_rek)]=='K'){
			
			$saldoawlbl=$saldozbl[trim($dtkbl->kd_rek)]-$debitxzbl + $kreditxzbl;
		}else{
			$saldoawlbl=0;
		}
	} else{
		$saldoawlbl=0;
	} 	
			
		if($dtkbl->balance=='D'){
			$saldoakhbl=$saldoawlbl+$debitxzrealbl - $kreditxzrealbl;
		}else{
			$saldoakhbl=$saldoawlbl-$debitxzrealbl + $kreditxzrealbl;
		}
		?>
		<?php												 
		$tblain=$tblain+$saldoakhbl;
		?>
			<tr>
				<td><?php echo $dtkbl->kd_rek;?></td>
				<td><?php echo $dtkbl->nm_rek;?></td>		
				<td align="right"><?php echo number_exc_koma($saldoakhbl);?></td>
			</tr>
		<?php  } ?>
		<tr style="background-color:#cfffbf;"><td colspan="2"><strong>Jumlah Beban Lain-lain</strong></td><td align="right"><strong><?php echo number_exc_koma($tblain);?></strong></td></tr>
		<?php $jmlPBl=$tplain - $tblain; ?>
		<tr style="background-color:#265cff;color:#fdfdff;"><td colspan="2"><strong>Jumlah Pendapatan(Beban) Lain-lain</strong></td><td align="right"><strong><?php echo number_exc_koma($jmlPBl);?></strong></td></tr>
		<?php $labanonpajak=$labapera + $jmlPBl; ?>
		<tr style="background-color:#26ffff;"><td colspan="2"><strong>Laba(Rugi) Sebelum Pajak </strong></td><td align="right"><strong><?php echo number_exc_koma($labanonpajak);?></strong></td></tr>
		</tbody>
											
	</table>