<?php 
session_start();
error_reporting(0);
include "config/koneksi.php";
include "config/library.php";
include "config/fungsi_indotgl.php";
include "config/fungsi_seo.php";
if (isset($_SESSION[id])){
	if ($_SESSION['level']=='admin'){
		$iden = mysql_fetch_array(mysql_query("SELECT * FROM users where username='$_SESSION[id]'"));
		$nama =  $iden['nama_lengkap'];
		$level = 'Administrator';
		$foto = 'dist/img/user.png';
	}

	$idt = mysql_fetch_array(mysql_query("SELECT * FROM identitas"));
	$dBayar=mysql_fetch_array(mysql_query("SELECT * FROM jenis_bayar WHERE idJenisBayar='$_GET[jenisBayar]'"));
	?>
	<!DOCTYPE html>
	<html>
	<head>
		<title>Cetak - Rekapitulasi Pembayaran Siswa</title>
		<link rel="stylesheet" href="bootstrap/css/printer.css">
	</head>
	<body>
		<?php
		$tgl1=$_GET['tgl1'];
		$tgl2=$_GET['tgl2'];
		?>
		<div class="col-xs-12">
			<table width="100%">
				<tr>
					<td width="100px" align="left"><img src="./gambar/logo/<?php echo $idt['logo_kiri']; ?>" height="60px"></td>
					<td valign="top">
						<h3 align="center" style="margin-bottom:8px ">
							<?php echo $idt['nmSekolah']; ?> 
						</h3>
						<center><?php echo $idt['alamat']; ?></center>
					</td>
					<td width="100px" align="right"><img src="./gambar/logo/<?php echo $idt['logo_kanan']; ?>" height="60px"></td>
				</tr>
			</table>
			<hr>
			<h4 align="center">
				REKAPITULASI KONDISI KEUANGAN (SALDO KEUANGAN SEKOLAH)
			</h4>
			<div class="box box-info box-solid">
				<div class="box-header with-border">
					<!--<h3 class="box-title">Tanggal : <?php echo tgl_raport($tgl1); ?> s/d <?php echo tgl_raport($tgl2); ?></h3>-->
				</div><!-- /.box-header -->
				<div class="box-body">
					<table class="table table-bordered table-striped">
						<thead>
							<tr>
								<th width="40px">No.</th>
								<th>Uraian (Keterangan)</th>
								<th>Sub Total</th>
							</tr>
						</thead>
						<tbody>
							<?php
							$total = 0;
					//$sqlJU = mysql_query("SELECT * FROM jurnal_umum WHERE DATE(tgl) BETWEEN '$tgl1' AND '$tgl2' ORDER BY tgl ASC");

					//hitung pemasukan dan pengeluaran dari jurnal umum
							$dPJU = mysql_fetch_array(mysql_query("SELECT SUM(penerimaan) AS totalMasuk, SUM(pengeluaran) AS totalKeluar FROM jurnal_umum"));
							$totalPemasukan = $dPJU['totalMasuk'];
							$totalPengeluaran = $dPJU['totalKeluar'];

					// Hitung Pembayaran Bulanan
							$dBul = mysql_fetch_array(mysql_query("SELECT SUM(jumlahBayar) AS totalBul FROM tagihan_bulanan WHERE statusBayar='1'"));
							$totalPendapatanBulanan = $dBul['totalBul'];

					// Hitung Pembayaran Bebas
							$dBeb = mysql_fetch_array(mysql_query("SELECT SUM(jumlahBayar) AS totalBeb FROM tagihan_bebas_bayar"));
							$totalPendapatanBebas = $dBeb['totalBeb'];

							?>
							<tr>
								<td align="center">1</td>
								<td>Total Pemasukan</td>
								<td align="right"><?php echo buatRp($totalPendapatanBulanan+$totalPendapatanBebas+$totalPemasukan); ?></td>
							</tr>
							<tr>
								<td align="center">2</td>
								<td>Total Pengeluaran</td>
								<td align="right"><?php echo buatRp($totalPengeluaran); ?></td>
							</tr>
							<tr>
								<td colspan="2" align="center"><b>Sisa Saldo Keuangan</b></td>
								<td align="right"><b><?php echo buatRp(($totalPendapatanBulanan+$totalPendapatanBebas+$totalPemasukan)-$totalPengeluaran); ?></b></td>
							</tr>
						</tbody>
					</table>
				</div><!-- /.box-body -->
			</div><!-- /.box -->
		</div>
		<br/>
		<table width="100%">
			<tr>
				<td align="center"></td>
				<td align="center" width="400px">
					<?php echo $idt['kabupaten']; ?>, <?php echo tgl_raport(date("Y-m-d")); ?>
					<br/>Bendahara,<br/><br/><br/><br/>
					<b><u><?php echo $idt['nmBendahara']; ?></u><br/><?php echo $idt['nipBendahara']; ?></b>
				</td>
			</tr>
		</table>
	</body>
	<script>
		window.print()
	</script>
	</html>
	<?php 
}else{
	include "login.php";
}
?>