<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title>Laporan Arus Kas - Sistem Informasi Keuangan</title>
	<style>
		* {
			margin: 0;
			padding: 0;
			box-sizing: border-box;
		}
		
		@media print {
			@page {
				size: A4 portrait;
				margin: 1.5cm;
			}
			body {
				-webkit-print-color-adjust: exact;
				print-color-adjust: exact;
			}
		}
		
		body {
			font-family: 'Georgia', 'Times New Roman', Times, serif;
			font-size: 10pt;
			line-height: 1.4;
			color: #2c3e50;
			background: #fff;
			padding: 15px;
		}
		
		.header {
			text-align: center;
			margin-bottom: 20px;
			border-bottom: 2px solid #95a5a6;
			padding-bottom: 10px;
		}
		
		.header h2 {
			font-size: 18pt;
			font-weight: bold;
			margin-bottom: 5px;
			letter-spacing: 2px;
			color: #34495e;
		}
		
		.header h3 {
			font-size: 13pt;
			font-weight: normal;
			margin-top: 5px;
			color: #7f8c8d;
		}
		
		.info-section {
			margin-bottom: 15px;
		}
		
		.info-table {
			width: 100%;
			border-collapse: collapse;
			margin-bottom: 15px;
		}
		
		.info-table td {
			padding: 5px 10px;
			border: 1px solid #d5d5d5;
		}
		
		.info-table th {
			padding: 6px 10px;
			border: 1px solid #d5d5d5;
			background-color: #f0f0f0;
			text-align: left;
			font-weight: bold;
			width: 30%;
			color: #2c3e50;
		}
		
		.main-table {
			width: 100%;
			border-collapse: collapse;
			margin-bottom: 20px;
			border: 1px solid #bdc3c7;
		}
		
		.main-table th {
			background-color: #ecf0f1 !important;
			border: 1px solid #bdc3c7;
			padding: 10px 6px;
			text-align: center;
			font-weight: bold;
			font-size: 10pt;
			vertical-align: middle;
			color: #2c3e50;
		}
		
		.main-table td {
			border: 1px solid #d5d5d5;
			padding: 8px 6px;
			font-size: 9pt;
			text-align: center;
			color: #2c3e50;
		}
		
		.main-table td.text-left {
			text-align: left;
		}
		
		.main-table td.text-right {
			text-align: right;
		}
		
		.main-table tbody tr:nth-child(even) {
			background-color: #fafafa;
		}
		
		.main-table tbody tr:nth-child(odd) {
			background-color: #ffffff;
		}
		
		.total-row {
			background-color: #e8e8e8 !important;
			font-weight: bold;
			color: #2c3e50;
			border-top: 2px solid #bdc3c7;
		}
		
		.saldo-row {
			background-color: #d5d5d5 !important;
			font-weight: bold;
			font-size: 11pt;
			color: #2c3e50;
			border-top: 2px solid #95a5a6;
		}
		
		.text-right {
			text-align: right;
		}
		
		.text-center {
			text-align: center;
		}
		
		.text-left {
			text-align: left;
		}
		
		.text-bold {
			font-weight: bold;
		}
	</style>
</head>
<body>

	<div class="header">
		<h2>LAPORAN ARUS KAS</h2>
		<h3>SISTEM INFORMASI KEUANGAN</h3>
	</div>

	<?php 
	if(isset($_GET['tanggal_sampai']) && isset($_GET['tanggal_dari']) && isset($_GET['kategori'])){
		$tgl_dari = $_GET['tanggal_dari'];
		$tgl_sampai = $_GET['tanggal_sampai'];
		$kategori = $_GET['kategori'];
		?>
		
		<div class="info-section">
			<table class="info-table">
				<tr>
					<th>DARI TANGGAL</th>
					<td><?php echo date('d-m-Y',strtotime($tgl_dari)); ?></td>
				</tr>
				<tr>
					<th>SAMPAI TANGGAL</th>
					<td><?php echo date('d-m-Y',strtotime($tgl_sampai)); ?></td>
				</tr>
				<tr>
					<th>KATEGORI</th>
					<td>
						<?php 
						include '../koneksi.php';
						if($kategori == "semua"){
							echo "SEMUA KATEGORI";
						}else{
							$k = mysqli_query($koneksi,"select * from kategori where kategori_id='$kategori'");
							$kk = mysqli_fetch_assoc($k);
							echo $kk['kategori'];
						}
						?>
					</td>
				</tr>
			</table>
		</div>

		<table class="main-table">
			<thead>
				<tr>
					<th width="3%" rowspan="2">NO</th>
					<th width="10%" rowspan="2">TANGGAL</th>
					<th width="15%" rowspan="2">KATEGORI</th>
					<th width="25%" rowspan="2">KETERANGAN</th>
					<th width="23%" colspan="2">JENIS TRANSAKSI</th>
				</tr>
				<tr>
					<th width="11.5%">PEMASUKAN</th>
					<th width="11.5%">PENGELUARAN</th>
				</tr>
			</thead>
			<tbody>
				<?php 
				include '../koneksi.php';
				$no=1;
				$total_pemasukan=0;
				$total_pengeluaran=0;
				if($kategori == "semua"){
					$data = mysqli_query($koneksi,"SELECT * FROM transaksi,kategori where kategori_id=transaksi_kategori and date(transaksi_tanggal)>='$tgl_dari' and date(transaksi_tanggal)<='$tgl_sampai' ORDER BY transaksi_tanggal ASC, transaksi_id ASC");
				}else{
					$data = mysqli_query($koneksi,"SELECT * FROM transaksi,kategori where kategori_id=transaksi_kategori and kategori_id='$kategori' and date(transaksi_tanggal)>='$tgl_dari' and date(transaksi_tanggal)<='$tgl_sampai' ORDER BY transaksi_tanggal ASC, transaksi_id ASC");
				}
				while($d = mysqli_fetch_array($data)){

					if($d['transaksi_jenis'] == "Pemasukan"){
						$total_pemasukan += $d['transaksi_nominal'];
					}elseif($d['transaksi_jenis'] == "Pengeluaran" || $d['transaksi_jenis'] == "pengeluaran"){
						$total_pengeluaran += $d['transaksi_nominal'];
					}
					?>
					<tr>
						<td class="text-center"><?php echo $no++; ?></td>
						<td class="text-center"><?php echo date('d-m-Y', strtotime($d['transaksi_tanggal'])); ?></td>
						<td class="text-left"><?php echo $d['kategori']; ?></td>
						<td class="text-left"><?php echo $d['transaksi_keterangan']; ?></td>
						<td class="text-right">
							<?php 
							if($d['transaksi_jenis'] == "Pemasukan"){
								echo "Rp. ".number_format($d['transaksi_nominal'], 0, ',', '.').",-";
							}else{
								echo "-";
							}
							?>
						</td>
						<td class="text-right">
							<?php 
							if($d['transaksi_jenis'] == "Pengeluaran" || $d['transaksi_jenis'] == "pengeluaran"){
								echo "Rp. ".number_format($d['transaksi_nominal'], 0, ',', '.').",-";
							}else{
								echo "-";
							}
							?>
						</td>
					</tr>
					<?php 
				}
				?>
				<tr class="total-row">
					<td colspan="4" class="text-right text-bold">TOTAL</td>
					<td class="text-right text-bold">Rp. <?php echo number_format($total_pemasukan, 0, ',', '.'); ?>,-</td>
					<td class="text-right text-bold">Rp. <?php echo number_format($total_pengeluaran, 0, ',', '.'); ?>,-</td>
				</tr>
				<tr class="saldo-row">
					<td colspan="4" class="text-right text-bold">SALDO</td>
					<td colspan="2" class="text-center text-bold">Rp. <?php echo number_format($total_pemasukan - $total_pengeluaran, 0, ',', '.'); ?>,-</td>
				</tr>
			</tbody>
		</table>

		<?php 
	}else{
		?>
		<div style="text-align:center; padding:20px; font-family: Georgia, serif;">
			Silahkan Filter Laporan Terlebih Dulu.
		</div>
		<?php
	}
	?>

	<script>
		window.print();
	</script>

</body>
</html>
