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

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

	$bulan= $_GET['bulan'];
	$tahun= $_GET['tahun'];
	$laba=0;
	
	if($bulan==1) $nbulan='JANUARI';
	else if($bulan==2) $nbulan='FEBRUARI';
	else if($bulan==3) $nbulan='MARET';
	else if($bulan==4) $nbulan='APRIL';
	else if($bulan==5) $nbulan='MEI';
	else if($bulan==6) $nbulan='JUNI';
	else if($bulan==7) $nbulan='JULI';
	else if($bulan==8) $nbulan='AGUSTUS';
	else if($bulan==9) $nbulan='SEPTEMBER';
	else if($bulan==10) $nbulan='OKTOBER';
	else if($bulan==11) $nbulan='NOVEMBER';
	else $nbulan='DESEMBER';
	
	$sql2		= "SELECT * FROM company";		
	$query2 	= mysql_query($sql2);
		
	while($r2=mysql_fetch_array($query2)){
		$kop1 = $r2[nama1];
		$kop2 = $r2[nama2];
		$kop3 = $r2[alamat];
	}
	
	echo "<table width='100%' style='font:13px arial'><b>
		<tr>
			<td><b>$kop1</b></td>
		</tr>
		<tr>
			<td>$kop2</td>
		</tr>
		<tr>
			<td>$kop3</td>
		</tr>
	</table>
		
	<table width='100%'>
		<tr>
			<td align='center' style='font:16px arial'><b>LAPORAN LABA RUGI USAHA</b></td>
		</tr>
		<tr>
			<td align='center' style='font:16px arial'><b>BULAN $nbulan $tahun</b></td>
		</tr>
	</table>
	<br>
	<table width='100%'>
		<tr>
			<td width='100%' style='border-top:double 2px'> </td>
		</tr>
	</table>
		
	<table width='100%' align='left' style='font:13px arial'>
		<tr>
			<td><b>Pendapatan Usaha</b></td>
		</tr>
	</table>
	<br>";
	
	$sql1= mysql_query("SELECT * FROM akun_bb WHERE nogol='41' AND level='2' ORDER BY noakun");
	echo "<table width='100%' align='left' style='font:13px arial'>";
	
	$subtot	= 0;
	while($r1=mysql_fetch_array($sql1)){
		$noakun=$r1[noakun];

		$sql = mysql_query("SELECT tanggal,noakun,debet,kredit FROM rekapjur WHERE noakun='$noakun' AND month(tanggal)='$bulan' AND year(tanggal)='$tahun' AND batal=''");
				
		$rdebet=0;
		$rkredit=0;
		while($r=mysql_fetch_array($sql)){
			$rdebet=$rdebet+$r[debet];
			$rkredit=$rkredit+$r[kredit];
		}			
		$saldo=$rkredit-$rdebet;
		$subtot=$subtot+$saldo;
			
		echo "<tr>
			<td width='3%'></td>
			<td width='35%'>$r1[naakun]</td>					
			<td width='2%'>Rp</td>
			<td width='20%' align='right'>".number_format($saldo,2)."</td>
			<td width='40%'></td>
		</tr>";
	}
	echo "</table>
	<br>
	
	<table width='100%' align='left' style='font:13px arial'>
		<tr>
			<td width='3%'></td>
			<td width='35%'></td>
			<td width='2%' style='border-bottom:double 2px'></td>
			<td width='20%' style='border-bottom:double 2px'></td>
			<td width='2%'></td>
			<td width='20%'></td>
			<td width='18%'></td>
		</tr>
			
		<tr>
			<td></td>
			<td></td>
			<td></td>
			<td align='right'>Jumlah</td>
			<td style='border-bottom:double 2px'>Rp</td>
			<td align='right' style='border-bottom:double 2px'>".number_format($subtot,2)."</td>
			<td></td>
		</tr>
	</table>
	<br>";
	$laba=$laba+$subtot;
		
echo "<table width='100%' align='left' style='font:13px arial'>
		<tr>
			<td><b>Harga Pokok Penjualan</b></td>
		</tr>
	</table>
	<br>";
				
	$query1 = "SELECT * FROM akun_bb WHERE nogol='51' AND level='2' ORDER BY noakun";		
	echo "<table width='100%' align='left' style='font:13px arial'>";
	
	$sql1	= mysql_query($query1);
	$subtot	= 0;
	while($r1=mysql_fetch_array($sql1)){
		$noakun=$r1[noakun];
		
		$sql = mysql_query("SELECT tanggal,noakun,debet,kredit FROM rekapjur WHERE noakun='$noakun' AND month(tanggal)='$bulan' AND year(tanggal)='$tahun' AND batal=''");
				
		$rdebet=0;
		$rkredit=0;
		while($r=mysql_fetch_array($sql)){
			$rdebet=$rdebet+$r[debet];
			$rkredit=$rkredit+$r[kredit];
		}	
		$saldo =$rdebet-$rkredit;
		$subtot=$subtot+$saldo;
			
		echo "<tr>
			<td width='3%'></td>
			<td width='35%'>$r1[naakun]</td>					
			<td width='2%'>Rp</td>
			<td width='20%' align='right'>".number_format($saldo,2)."</td>
			<td width='40%'></td>
		</tr>";
	}
	echo "</table>
	<br>
	
	<table width='100%' align='left' style='font:13px arial'>
		<tr>
			<td width='3%'></td>
			<td width='35%'></td>
			<td width='2%' style='border-bottom:double 2px'></td>
			<td width='20%' align='right' style='border-bottom:double 2px'></td>
			<td width='2%'></td>
			<td width='20%'></td>
			<td width='18%'></td>
		</tr>
			
		<tr>
			<td width='3%'></td>
			<td width='35%'></td>
			<td width='2%'></td>
			<td width='20%' align='right'>Jumlah</td>
			<td width='2%' style='border-bottom:double 2px'>Rp</td>
			<td width='20%' align='right' style='border-bottom:double 2px'>".number_format($subtot,2)."</td>
			<td width='18%'></td>
		</tr>
	</table>
	<br>";
	$laba=$laba-$subtot;
		
	echo "<table width='100%' align='left' style='font:13px arial'>
		<tr>
			<td width='3%'></td>
			<td width='35%'></td>
			<td width='2%'></td>
			<td width='20%' align='right'>Laba Kotor</td>
			<td width='2%' style='border-bottom:double 2px'>Rp</td>
			<td width='20%'align='right' style='border-bottom:double 2px'>".number_format($laba,2)."</td>
			<td width='18%'></td>
		</tr>
	</table>
	<br>";

echo "<table width='100%' align='left' style='font:13px arial'>
		<tr>
			<td><b>Biaya Operasional</b></td>
		</tr>
	</table>
	<br>";

	$sql1= mysql_query("SELECT * FROM akun_bb WHERE nogol='52' AND level='2' ORDER BY noakun");
	echo "<table width='100%' align='left' style='font:13px arial'>";
	
	$subtot	= 0;
	while($r1=mysql_fetch_array($sql1)){
		$noakun=$r1[noakun];

		$sql = mysql_query("SELECT tanggal,noakun,debet,kredit FROM rekapjur WHERE noakun='$noakun' AND month(tanggal)='$bulan' AND year(tanggal)='$tahun' AND batal='' ");
			
		$rdebet=0;
		$rkredit=0;
		while($r=mysql_fetch_array($sql)){
			$rdebet=$rdebet+$r[debet];
			$rkredit=$rkredit+$r[kredit];
		}			
		$saldo =$rdebet-$rkredit;
		$subtot=$subtot+$saldo;
				
		echo "<tr>
			<td width='3%'></td>
			<td width='35%'>$r1[naakun]</td>					
			<td width='2%'>Rp</td>
			<td width='20%' align='right'>".number_format($saldo,2)."</td>
			<td width='40%'></td>
		</tr>";
	}
		
	echo "</table>
	<br>
	
	<table width='100%' align='left' style='font:13px arial'>
		<tr>
			<td width='3%'></td>
			<td width='35%'></td>
			<td width='2%' style='border-bottom:double 2px'></td>
			<td width='20%' align='right' style='border-bottom:double 2px'></td>
			<td width='2%'></td>
			<td width='20%'></td>
			<td width='18%'></td>
		</tr>
			
		<tr>
			<td></td>
			<td></td>
			<td></td>
			<td align='right'>Jumlah</td>
			<td style='border-bottom:double 2px'>Rp</td>
			<td align='right' style='border-bottom:double 2px'>".number_format($subtot,2)."</td>
			<td></td>
		</tr>
	</table>
	<br>";
	$laba=$laba-$subtot;
		
echo "<table width='100%' align='left' style='font:13px arial'>
		<tr>
			<td><b>Biaya Administrasi dan Umum</b></td>
		</tr>
	</table>
	<br>";

	$sql1	= mysql_query("SELECT * FROM akun_bb WHERE nogol='53' AND level='2' ORDER BY noakun");
	echo "<table width='100%' align='left' style='font:13px arial'>";
	
	$subtot	= 0;
	while($r1=mysql_fetch_array($sql1)){
		$noakun=$r1[noakun];

		$sql = mysql_query("SELECT tanggal,noakun,debet,kredit FROM rekapjur WHERE noakun='$noakun' AND month(tanggal)='$bulan' AND year(tanggal)='$tahun' AND batal='' ");

		$rdebet=0;
		$rkredit=0;
		while($r=mysql_fetch_array($sql)){
			$rdebet=$rdebet+$r[debet];
			$rkredit=$rkredit+$r[kredit];
		}
		$saldo =$rdebet-$rkredit;
		$subtot=$subtot+$saldo;
		echo "<tr>
			<td width='3%'></td>
			<td width='35%'>$r1[naakun]</td>					
			<td width='2%'>Rp</td>
			<td width='20%' align='right'>".number_format($saldo,2)."</td>
			<td width='40%'></td>
		</tr>";
	}
		
	echo "</table>
	<br>
	
	<table width='100%' align='left' style='font:13px arial'>
		<tr>
			<td width='3%'></td>
			<td width='35%'></td>
			<td width='2%' style='border-bottom:double 2px'></td>
			<td width='20%' align='right' style='border-bottom:double 2px'></td>
			<td width='2%'></td>
			<td width='20%'></td>
			<td width='18%'></td>
		</tr>

		<tr>
			<td></td>
			<td></td>
			<td></td>
			<td align='right'>Jumlah</td>
			<td style='border-bottom:double 2px'>Rp</td>
			<td align='right' style='border-bottom:double 2px'>".number_format($subtot,2)."</td>
			<td></td>
		</tr>
	</table>
	<br>";
	$laba=$laba-$subtot;
			
	echo "<table width='100%' align='left' style='font:13px arial'>
		<tr>
			<td width='3%'></td>
			<td width='35%'></td>
			<td width='2%'></td>
			<td width='20%' align='right'>Laba Usaha</td>
			<td width='2%' style='border-bottom:double 2px'>Rp</td>
			<td width='20%' align='right' style='border-bottom:double 2px'>".number_format($laba,2)."</td>
			<td width='18%'></td>
		</tr>
	</table>
	<br>";
			
echo "<table width='100%' align='left' style='font:13px arial'>
		<tr>
			<td><b>Pendapatan dan Biaya Non Usaha</b></td>
		</tr>
		<tr>
			<td><b>Pendapatan Non Usaha</b></td>
		</tr>
	</table>
	<br>";
	$labanon=0;

	$sql1	= mysql_query("SELECT * FROM akun_bb WHERE nogol='61' AND level='2' ORDER BY noakun");
	echo "<table width='100%' align='left' style='font:13px arial'>";
	
	$subtot	= 0;
	while($r1=mysql_fetch_array($sql1)){
		$noakun=$r1[noakun];

		$sql = mysql_query("SELECT tanggal,noakun,debet,kredit FROM rekapjur WHERE noakun='$noakun' AND month(tanggal)='$bulan' AND year(tanggal)='$tahun' AND batal='' ");
				
		$rdebet=0;
		$rkredit=0;
		while($r=mysql_fetch_array($sql)){
			$rdebet=$rdebet+$r[debet];
			$rkredit=$rkredit+$r[kredit];
		}			
		$saldo =$rkredit-$rdebet;
		$subtot=$subtot+$saldo;
				
		echo "<tr>
			<td width='3%'></td>
			<td width='35%'>$r1[naakun]</td>					
			<td width='2%'>Rp</td>
			<td width='20%' align='right'>".number_format($saldo,2)."</td>
			<td width='40%'></td>
		</tr>";
	}
		
	echo "</table>
	<br>
	<table width='100%' align='left' style='font:13px arial'>
		<tr>
			<td width='3%'></td>
			<td width='35%'></td>
			<td width='2%' style='border-bottom:double 2px'></td>
			<td width='20%' align='right' style='border-bottom:double 2px'></td>
			<td width='2%'></td>
			<td width='20%'></td>
			<td width='18%'></td>
		</tr>
			
		<tr>
			<td></td>
			<td></td>
			<td></td>
			<td align='right'>Jumlah</td>
			<td style='border-bottom:double 2px'>Rp</td>
			<td align='right' style='border-bottom:double 2px'>".number_format($subtot,2)."</td>
			<td></td>
		</tr>
	</table>
	<br>";
	$labanon=$labanon+$subtot;
	$laba=$laba+$subtot;
			
echo "<table width='100%' align='left' style='font:13px arial'>
		<tr>
			<td><b>Biaya Non Usaha</b></td>
		</tr>
	</table>
	<br>";

	$sql1= mysql_query("SELECT * FROM akun_bb WHERE nogol='62' AND level='2' ORDER BY noakun");
	echo "<table width='100%' align='left' style='font:13px arial'>";
	
	$subtot	= 0;
	while($r1=mysql_fetch_array($sql1)){
		$noakun=$r1[noakun];

		$sql = mysql_query("SELECT tanggal,noakun,debet,kredit FROM rekapjur WHERE noakun='$noakun' AND month(tanggal)='$bulan' AND year(tanggal)='$tahun' AND batal='' ");
				
		$rdebet=0;
		$rkredit=0;
		while($r=mysql_fetch_array($sql)){
			$rdebet=$rdebet+$r[debet];
			$rkredit=$rkredit+$r[kredit];
		}			
		$saldo =$rdebet-$rkredit;
		$subtot=$subtot+$saldo;
				
		echo "<tr>
			<td width='3%'></td>
			<td width='35%'>$r1[naakun]</td>					
			<td width='2%'>Rp</td>
			<td width='20%' align='right'>".number_format($saldo,2)."</td>
			<td width='40%'></td>
		</tr>";
	}
		
	echo "</table>
	<br>
	
	<table width='100%' align='left' style='font:13px arial'>
		<tr>
			<td width='3%'></td>
			<td width='35%'></td>
			<td width='2%' style='border-bottom:double 2px'></td>
			<td width='20%' align='right' style='border-bottom:double 2px'></td>
			<td width='2%'></td>
			<td width='20%'></td>
			<td width='18%'></td>
		</tr>
		
		<tr>
			<td></td>
			<td></td>
			<td></td>
			<td align='right'>Jumlah</td>
			<td style='border-bottom:double 2px'>Rp</td>
			<td align='right' style='border-bottom:double 2px'>".number_format($subtot,2)."</td>
			<td></td>
		</tr>";
		$labanon=$labanon-$subtot;
		$laba=$laba-$subtot;
		
	echo "</table>
	<br>
	<table align='left' style='font:13px arial'>
		<tr>
			<td width='3%'></td>
			<td width='35%'></td>
			<td width='2%'></td>
			<td width='20%' align='right'>Laba Non Usaha</td>
			<td width='2%' style='border-bottom:double 2px'>Rp</td>
			<td width='20%' align='right' style='border-bottom:double 2px'>".number_format($labanon,2)."</td>
			<td width='18%'></td>
		</tr>
		
		<tr>
			<td></td>
			<td></td>
			<td></td>
			<td align='right'>Laba Bersih</td>
			<td style='border-bottom:double 2px'>Rp</td>
			<td align='right' style='border-bottom:double 2px'>".number_format($laba,2)."</td>
			<td></td>
		</tr>
	</table>
	<br>
	
	<table width='100%'>
		<tr>
			<td width='100%' style='border-top:double 2px'> </td>
		</tr>
	</table>";
?>
<script type="text/javascript">	
	history.back();
</script>