<?php
$tahun = $ta['idTahunAjaran'];
$jenis = '';
$kelas = '';
?>
<div class="col-xs-4">
	<div class="box box-success box-solid">
		<div class="box-header with-border">
			<h3 class="box-title"><span class="fa fa-file-text-o"></span> Laporan Kondisi Keuangan Per Tanggal</h3>
		</div><!-- /.box-header -->
		<div class="box-body">
			<form method="GET" action="cetak_rekapitulasi_kondisi_pertanggal.php" role="form" target="_blank">


				<div class="form-group">
					<label for="">Dari Tanggal</label>
					<div class="input-group date">
						<div class="input-group-addon">
							<i class="fa fa-calendar"></i>
						</div>
						<input type="text" name="tgl1" value="<?php echo date('Y-m-d'); ?>" class="form-control pull-right date-picker">
					</div>
				</div>
				<div class="form-group">
					<label for="">Sampai Tanggal</label>
					<div class="input-group date">
						<div class="input-group-addon">
							<i class="fa fa-calendar"></i>
						</div>
						<input type="text" name="tgl2" value="<?php echo date('Y-m-d'); ?>" class="form-control pull-right date-picker">
					</div>
				</div>

				<div class="form-group">
					<label for=""></label>
					<input type="submit" value="Cetak Laporan" class="btn btn-success pull-right">
				</div>
			</form>
		</div><!-- /.box-body -->
	</div><!-- /.box -->
</div>
<div class="col-xs-4">
	<div class="box box-warning box-solid">
		<div class="box-header with-border">
			<h3 class="box-title"><span class="fa fa-file-text-o"></span> Laporan Kondisi Keuangan Perbulan</h3>
		</div><!-- /.box-header -->
		<div class="box-body">
			<form method="GET" action="cetak_rekapitulasi_kondisi_perbulan.php" role="form" target="_blank">
				<div class="form-group">
					<label for="">Tahun Ajaran</label>
					<select id="tahun1" name="tahun" class="form-control" required>
						<?php
						$sqltahun = mysqli_query($conn, "SELECT * FROM tahun_ajaran ORDER BY idTahunAjaran ASC");
						while ($t = mysqli_fetch_array($sqltahun)) {
							$selected = ($t['idTahunAjaran'] == $tahun) ? ' selected="selected"' : "";
							echo "<option value=" . $t['idTahunAjaran'] . " " . $selected . ">" . $t['nmTahunAjaran'] . "</option>";
						}
						?>
					</select>
				</div>

				<div class="form-group">
					<div class="row">
						<div class="col-md-12"><label for="">Dari Bulan</label></div>
						<div class="col-md-8">
							<select id="bulan" name="bulan1" class="form-control" required>
								<?php
								$sqlBulan = mysqli_query($conn, "SELECT * FROM bulan ORDER BY urutan ASC");
								while ($b = mysqli_fetch_array($sqlBulan)) {
									echo "<option value=" . $b['idBulan'] . ">" . $b['nmBulan'] . "</option>";
								}
								?>
							</select>
						</div>
						<div class="col-md-4">
							<select id="tahun1" name="tahun1" class="form-control" required>
								<option value="<?php echo date('Y'); ?>" selected><?php echo date('Y'); ?></option>
								<?php
								for ($i = 2015; $i < date('Y') + 3; $i++) {
									echo "<option value='$i'>$i</option>";
								}
								?>
							</select>
						</div>
					</div>
				</div>
				<div class="form-group">
					<div class="row">
						<div class="col-md-12"><label for="">Sampai Bulan</label></div>
						<div class="col-md-8">
							<select id="bulan" name="bulan2" class="form-control" required>
								<?php
								$sqlBulan = mysqli_query($conn, "SELECT * FROM bulan ORDER BY urutan ASC");
								while ($b = mysqli_fetch_array($sqlBulan)) {
									echo "<option value=" . $b['idBulan'] . ">" . $b['nmBulan'] . "</option>";
								}
								?>
							</select>
						</div>
						<div class="col-md-4">
							<select id="tahun2" name="tahun2" class="form-control" required>
								<option value="<?php echo date('Y') + 1; ?>" selected><?php echo date('Y') + 1; ?></option>
								<?php
								for ($i = 2015; $i < date('Y') + 3; $i++) {
									echo "<option value='$i'>$i</option>";
								}
								?>
							</select>
						</div>
					</div>
				</div>
				<div class="form-group">
					<label for=""></label>
					<input type="submit" value="Cetak Laporan" class="btn btn-primary pull-right">
				</div>
			</form>
		</div><!-- /.box-body -->
	</div><!-- /.box -->
</div>
<div class="col-xs-4">
	<div class="box box-danger box-solid">
		<div class="box-header with-border">
			<h3 class="box-title"><span class="fa fa-file-text-o"></span> Laporan Kondisi Keuangan Pertahun</h3>
		</div><!-- /.box-header -->
		<div class="table-responsive">
			<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;
					$tahun = date('y');
					//$sqlJU = mysqli_query($conn,"SELECT * FROM jurnal_umum WHERE DATE(tgl) BETWEEN '$tgl1' AND '$tgl2' ORDER BY tgl ASC");

					//hitung pemasukan dan pengeluaran dari jurnal umum
					$dPJU = mysqli_fetch_array(mysqli_query($conn, "SELECT  SUM(pengeluaran) AS totalKeluar FROM jurnal_umum WHERE DATE_FORMAT((tgl),'%y') like '%$tahun%'"));

					$totalPengeluaran = $dPJU['totalKeluar'];

					// Hitung Pembayaran Bulanan
					$dBul = mysqli_fetch_array(mysqli_query($conn, "SELECT SUM(jumlahBayar) AS totalBul FROM tagihan_bulanan WHERE statusBayar='1' AND  DATE_FORMAT((tglBayar),'%y') like '%$tahun%'"));
					$totalPendapatanBulanan = $dBul['totalBul'] ;

					// Hitung Pembayaran Bebas
					$dBeb = mysqli_fetch_array(mysqli_query($conn, "SELECT SUM(jumlahBayar) AS totalBeb FROM tagihan_bebas_bayar WHERE  DATE_FORMAT((tglBayar),'%y') like '%$tahun%'"));
					$totalPendapatanBebas = $dBeb['totalBeb'] ;

					?>
					<tr>
						<td align="center">1</td>
						<td>Total Pemasukan</td>
						<td align="right"><?php echo buatRp($totalPendapatanBulanan + $totalPendapatanBebas); ?></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> Saldo Keuangan Tahun Ini</b></td>
						<td align="right"><b><?php echo buatRp(($totalPendapatanBulanan + $totalPendapatanBebas) - $totalPengeluaran); ?></b></td>
					</tr>
				</tbody>
			</table>
			<hr>
			<div class="form-group">
				<label for=""></label>
				<a href="./cetak_rekap_kondisi_keuangan_pertahun.php" class="btn btn-danger pull-right" target="_blank">Cetak Laporan</a>
			</div>
		</div><!-- /.box-body -->
	</div><!-- /.box -->
</div>

<div class="col-xs-12">
	<div class="box box-info box-solid">
		<div class="box-header with-border">
			<h3 class="box-title"><span class="fa fa-file-text-o"></span> Laporan Kondisi Keuangan</h3>
		</div><!-- /.box-header -->
		<div class="table-responsive">
			<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 = mysqli_query($conn,"SELECT * FROM jurnal_umum WHERE DATE(tgl) BETWEEN '$tgl1' AND '$tgl2' ORDER BY tgl ASC");

					//hitung pemasukan dan pengeluaran dari jurnal umum
					$dPJU = mysqli_fetch_array(mysqli_query($conn, "SELECT  SUM(pengeluaran) AS totalKeluar FROM jurnal_umum"));

					$totalPengeluaran = $dPJU['totalKeluar'];

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

					// Hitung Pembayaran Bebas
					$dBeb = mysqli_fetch_array(mysqli_query($conn, "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); ?></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) - $totalPengeluaran); ?></b></td>
					</tr>
				</tbody>
			</table>
			<hr>
			<a href="./cetak_rekap_kondisi_keuangan.php" class="btn btn-danger pull-right" target="_blank"><span class="glyphicon glyphicon-print"></span> Cetak Laporan</a>
		</div><!-- /.box-body -->
	</div><!-- /.box -->
</div>