<?php
// header("Content-type: application/vnd-ms-excel");
// header("Content-Disposition: attachment; filename=Laporan_Bidang_perTriwulan_".$periode_thn.".xls");
?>
<!DOCTYPE html>
<html>
<head>
	<title></title>
		<style type="text/css">
	body{
		font-family: sans-serif;
	}
	#tb{
		margin: 20px auto;
		border-collapse: collapse;
	}
	#tb th,
	#tb td{
		border: 1px solid #3c3c3c;
	}
	#tb td{
		vertical-align: top;
	}
	a{
		background: blue;
		color: #fff;
		padding: 8px 10px;
		text-decoration: none;
		border-radius: 2px;
	}
	.text{
		padding: 3px 100px 3px 3px;
	}
	.number{
		padding: 3px 3px 3px 100px;
	}
	.bg-coklat{
		background-color: #993300;
		color: white;
	}
	</style>
</head>
<body>
	<h2 style="text-align: center;">Laporan Rekap PKA Pertriwulan Periode <?=$periode_thn?></h2>
	<table style="margin-left: 0;border:0">
		<tr>
			<td>Triwulan</td><td>:</td><td><?=$triwulan=="all"?"Semua Triwulan":"Triwulan ".$triwulan?></td>
		</tr>
		<tr>
			<td>Unit Misioner</td><td>:</td><td><?=$unit_misioner=="all"?"Semua Unit Misioner":$unit_misioner?></td>
		</tr>
	</table>
<table id="tb">
	<thead>
		<tr>
			<th>No</th>
			<th>KMA</th>
			<th>Jenis Kegiatan</th>
			<th>Unit Misioner</th>
			<th>Bidang</th>
			<th>Nama Kegiatan</th>
			<th>Tujuan Kegiatan</th>
			<th>Bulan Kegiatan</th>
			<th>Pencapaian</th>
			<th>Analisa Terhadap Pencapaian</th>
			<th>Target Kualitatif</th>
			<th>Realisasi Kualitatif</th>
			<th>Target Penerimaan</th>
			<th>Realisasi Penerimaan</th>
			<th>Target Pengeluaran</th>
			<th>Realisasi Pengeluaran</th>
			<th>Triwulan</th>
			<th>Analisa Keuangan</th>
			<th>Terlaksana</th>
		</tr>
	</thead>
	<tbody>
		<?php
		$no =1;
		foreach($result as $data){
		?>
		<tr><td style="text-align: center;">
				<?=$no++?>
			</td>
			<td style="text-align: center;">
				<?=$data['kma']?>
			</td>
			<!-- <td style="text-align: right;">`
			</td> -->
			<td style="text-align: left;">
				 <?=$data['nm_jk']?>
			</td>
			<td style="text-align: left;">
				 <?=$data['nm_um']?>
			</td>
			<td style="text-align: left;">
				 <?=$data['nm_bd']?>
			</td>
			<td style="text-align: center;">
				 <?=$data['nama_kegiatan']?>
			</td>
			<td style="text-align: left;">
				<?=$data['tujuan_kegiatan']?>
			</td>
			<td style="text-align: left;">
				<?php 
				if($data['bulan_kegiatan']!=""){
					foreach(json_decode($data['bulan_kegiatan'], true) as $d){
						$lastKey = array_key_last(json_decode($data['bulan_kegiatan'], true));
						$lastElement = json_decode($data['bulan_kegiatan'], true)[$lastKey];
						if($lastElement == $d){
							echo $d;
						}else{
							echo $d.",";
						}
						
					}
				}
				
				?>
			</td>
			<td style="text-align: left;">
				<?=$data['pencapaian']?>
			</td>
			<td style="text-align: left;">
				<?=$data['atp']?>
			</td>
			<td style="text-align: left;">
				<?=$data['indikator_kualitatif']?>
			</td>
			<td style="text-align: left;">
				<?=$data['realisasi_kualitatif']?>
			</td>
			<td style="text-align: right;">
				Rp <?=number_format($data['pen'],0,",",".")?>
			</td>
			<td style="text-align: right;">
				Rp <?=number_format($data['realisasi_penerimaan'],0,",",".")?>
			</td>
			<td style="text-align: right;">
				Rp <?=number_format($data['peng'],0,",",".")?>
			</td>
			<td style="text-align: right;">
				Rp <?=number_format($data['realisasi_pengeluaran'],0,",",".")?>
			</td>
			<td style="text-align: left;">
				Triwulan <?=$data['triwulan_evaluasi']?>
			</td>
			<td style="text-align: left;">
				<?=$data['analisa_keuangan']?>
			</td>
			<td style="text-align: center;">
				<?=$data['terlaksana']=="0"?"Tidak":"Ya"?>
			</td>
		</tr>
		<?php
		}
		?>
	</tbody>
	<tfoot>
	</tfoot>
</table>
</body>
</html>