<?php
	$t1=date("Y");$t2=t1+1;
	$th=$t1 . "/" . $t2;

	$id=mysqli_real_escape_string($mysqli,$_GET[id]);
	
	$qry=mysqli_query($mysqli,"SELECT * FROM m_desa WHERE id_desa='$id'");
	$data=mysqli_fetch_array($qry);

	$id_kec=$data["id_kecamatan"];
	
	$qry2=mysqli_query($mysqli,"SELECT * FROM m_kecamatan WHERE id_kecamatan='$id_kec'");
	
	$data2=mysqli_fetch_array($qry2);
	
	$nama_kec=$data2["nama_kecamatan"];
	
	echo "<br/>&nbsp;&nbsp;<a href='index.php?page=list_desa&id_kec=$id_kec'>$nama_kec</a>&nbsp;&gt;&gt;<b><u>$data[nama_desa]</u></b>";
	
	echo "<table width='100%' border='0' style=\"margin: 10px;font-size:10px;\">";
	echo "<tr>";
	echo "<th width='30%'>Nama Desa</th><th width='70%'>: $data[nama_desa]</th>";
	echo "</tr>";
	echo "<tr>";
	echo "<th>Alamat Kantor Desa</th><th>: $data[alamat_kantor]</th>";
	echo "</tr>";
	echo "<tr>";
	echo "<th>No. Telp Kantor Desa</th><th>: $data[telp_kantor]</th>";
	echo "</tr>";
	echo "<tr>";
	echo "<th>No. Fax Kantor Desa</th><th>: $data[fax_kantor]</th>";
	echo "</tr>";
	echo "<tr>";
	echo "<th>Nama Email</th><th>: $data[email_kantor]</th>";
	echo "</tr>";
	echo "</table>";
	

  	echo "<b><font size='2'>Pilih Tahun Anggaran:</font></b>&nbsp;<select name='tahun_anggaran' id='tahun_anggaran' style=\"width:120px;color:#000000; background-color: #ffffff; -moz-border-radius: 5px;-webkit-border-radius: 5px;border: 3px solid #57564B;padding: 3px;\">";
	$awal=$t1-1;
	$batas=$t1+1;
	for($i=$awal;$i<=$batas;$i++){
		$th=$i;
		$s="";
		if(!isset($_GET["ta"])){
			if($i==$t1){
				$s="selected";
			}
		}else{
			if($th==$_GET["ta"]){
				$s="selected";
			}
		}
		echo "<option value='$th' $s>$th</option>";
	}
	echo "</select>&nbsp;&nbsp;<input type='button' value='Tampilkan&gt;&gt;' id='btnTampil' name='btnTampil' onclick=\"window.location='index.php?page=detail_desa&id=$_GET[id]&ta='+document.getElementById('tahun_anggaran').value\" style=\"width:120px; color:#000000; background-color: #ffffff;
  -moz-border-radius: 5px; -webkit-border-radius: 5px; border: 3px solid #57564B; padding: 3px;height:30px;\">";
	echo "<br/>&nbsp;";

	if(isset($_GET[ta])){
		$id=mysqli_real_escape_string($mysqli,$_GET["id"]);
		$ta=mysqli_real_escape_string($mysqli,$_GET["ta"]);
		echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>";
		echo "<tr>
				<th><div align='center'>MELALUI PENYEDIA BARANG/JASA</div></th>
				<th>&nbsp;</th>
		</tr>";
		$qryx=mysqli_query($mysqli,"SELECT * FROM t_anggaran WHERE id_desa='$id' AND keterangan='PENYEDIA' AND tahun_anggaran='$ta' ORDER BY id ASC");
		echo "<table class='datatable'>";
		echo "<tr bgcolor='#C1D5DB'>
				<th width='15%'><div align='center'>Kode</div></th>
				<th width='70%'><div align='center'>Uraian</div></th>
				<th width='15%'><div align='center'>Anggaran (Rp)</div></th>
			  </tr>";
		if(mysqli_num_rows($qryx)>0){
			while($datax=mysqli_fetch_array($qryx)){
				echo "<tr>
						<td valign='top'>$datax[kode_rekening]</td>
						<td valign='top'>$datax[uraian]</td>
						<td valign='top' align='right'>".number_format($datax[anggaran],0,",",".")."</td>
						</tr>";
			}
		}else{
			echo "<tr>
						<td colspan='3'>Tidak ada data</td>
						</tr>";
		}
		echo "</table>";
		echo "</table>";
				
		
		echo "<td valign='top'>"; //swakelola
		echo "<h3 align='center'>MELALUI SWAKELOLA</h3>";
		$qryx=mysqli_query($mysqli,"SELECT * FROM t_anggaran WHERE id_desa='$id' AND keterangan='SWAKELOLA' AND tahun_anggaran='$ta' ORDER BY id ASC");
		echo "<table class='datatable'>";
		echo "<tr bgcolor='#C1D5DB'>
				<th width='15%'><div align='center'>Kode</div></th>
				<th width='70%'><div align='center'>Uraian</div></th>
				<th width='15%'><div align='center'>Anggaran (Rp)</div></th>
			  </tr>";
		if(mysqli_num_rows($qryx)>0){
			while($datax=mysqli_fetch_array($qryx)){
				echo "<tr>
						<td valign='top'>$datax[kode_rekening]</td>
						<td valign='top'>$datax[uraian]</td>
						<td valign='top' align='right'>".number_format($datax[anggaran],0,",",".")."</td>
						</tr>";
			}
		}else{
			echo "<tr>
						<td colspan='3'>Tidak ada data</td>
						
				  </tr>";
		}
		echo "</td>";
		echo "</tr>";
		echo "</table>";
		

		echo "<h3 align='center'>TRANSAKSI PENGADAAN BARANG/JASA DESA</h3>";

	//
	

	

	
		//tampilkan transaksi
		$id=mysqli_real_escape_string($mysqli,$_GET[id]);
		$th=mysqli_real_escape_string($mysqli,$_GET[ta]);
		
		$qryp=mysqli_query($mysqli,"SELECT * FROM transaksi WHERE id_desa='$id' AND tahun_anggaran='$th'");
		echo "<table class='datatable'>";
		echo "<tr bgcolor='#C1D5DB'>
				<th><div align='center'>Kode</div></th>
				<th><div align='center'>Paket</div></th>
				<th><div align='center'>Anggaran<br/>(Rp.)</div></th>
				<th><div align='center'>Nama Penyedia<br/>Pemenang</div></th>
				<th><div align='center'>Harga Penawaran<br/>(Rp.)</div></th>
				<th><div align='center'>Keterangan</div></th>
			  </tr>";
		if(mysqli_num_rows($qryp)>0){
			while($datap=mysqli_fetch_array($qryp)){
				if($datap[harga_penawaran]==0){
					$hrgp="-";
				}else{
					$hrgp=number_format($datap[harga_penawaran],0,",",".");
					
				}
				echo "<tr>
						<td valign='top'>$datap[kode_rekening]</td>
						<td valign='top'>$datap[paket]</td>
						<td valign='top' align='right'>".number_format($datap[anggaran],0,",",".")."</td>
						<td valign='top'>$datap[pemenang]</td>
						<td valign='top' align='right'>$hrgp</td>
						<td valign='top'>$datap[keterangan]</td>
					  </tr>";
			}
		}else{
			echo "<tr>
						<td valign='top' colspan='7'>Data tidak ditemukan...</td>
					  </tr>";
		}
		echo "</table>";
		echo "<br/><br/>&nbsp;";
			
	}else{
		echo "<br/><font color='red'>Silakan pilih Tahun Anggaran dan klik pada tombol Tampilkan...</font><br/><br/>";
	}


	
	
	
	
	
?>