<?php

if($_COOKIE['sejahtera_role'] == 10)
{
	include_once ("includes/setup_pemohon.inc.php");
}
else
{
	include_once ("includes/setup.inc.php");
}
include_once('includes/global.php');
include_once('includes/img.svg.php');
$PDO = SSP::db($sql_details);

$kpbaru_anakemas = fetch_postget_val('kpbaru_anakemas',$_POST, $_GET);

$indicator_Query = "SELECT A.*,
				  B.desk_statusmohon, E.desk_program, G.desk_bank, I.nama AS nama_terima, J.desk_dun AS dun_terima, K.desk_daerah AS daerah_terima, L.nama AS nama_sah, M.desk_dun AS dun_sah, N.desk_daerah AS daerah_sah, O.nama AS nama_saheft, P.desk_dun AS dun_saheft, Q.desk_daerah AS daerah_saheft, C.nama_pemohon, C.tel_hp, D.desk_dun AS dun_pemohon
				  FROM m_anakemas A
				  LEFT JOIN i_statusmohon B ON A.id_statusmohon = B.id_statusmohon
				  LEFT JOIN m_pemohon C ON A.id_pemohon = C.id_pemohon
				  LEFT JOIN i_dun D ON C.id_dun = D.id_dun
				  LEFT JOIN i_program E ON A.id_program = E.id_program
				  LEFT JOIN i_bank G ON A.id_bankanakemas = G.id_bank
				  LEFT JOIN t_pengguna I ON I.id_pengguna = A.id_terima
				  LEFT JOIN i_dun J ON J.id_dun = I.id_dun
				  LEFT JOIN i_daerah K ON K.id_daerah = I.id_daerah
				  LEFT JOIN t_pengguna L ON L.id_pengguna = A.id_sah
				  LEFT JOIN i_dun M ON M.id_dun = L.id_dun
				  LEFT JOIN i_daerah N ON N.id_daerah = L.id_daerah
				  LEFT JOIN t_pengguna O ON O.id_pengguna = A.id_saheft
				  LEFT JOIN i_dun P ON P.id_dun = O.id_dun
				  LEFT JOIN i_daerah Q ON Q.id_daerah = O.id_daerah
				  WHERE A.kpbaru_anakemas = ?
				  AND A.id_statusmohon IN (2,3,4)";
$PDO_stmt = $PDO->prepare($indicator_Query);
$PDO_stmt->bindValue(1, $kpbaru_anakemas, PDO::PARAM_STR);
$PDO_stmt->execute();
$ae_List = $PDO_stmt->fetch(PDO::FETCH_ASSOC);

$id_anakemas = $ae_List['id_anakemas'];
$id_program = $ae_List['id_program'];

echo '<div class="card-body table-responsive" style="padding-top:10px">';
	echo '<table class="table table-sm table-bordered table-striped">';
		echo '<thead class="thead-dark">';
			echo '<tr>';
				echo '<th scope="col">Bil</th>';
				echo '<th scope="col">Tindakan</th>';
				echo '<th scope="col">Nama Anak Emas</th>';
				echo '<th scope="col">Program</th>';
				echo '<th scope="col">No MyKid</th>';
				echo '<th scope="col">Nama Pemohon</th>';
				echo '<th scope="col">No Telefon</th>';
				echo '<th scope="col">Bank</th>';
				echo '<th scope="col">No Akaun</th>';
				echo '<th scope="col">DUN</th>';
				echo '<th scope="col">Status Permohonan</th>';
			echo '</tr>';
		echo '</thead>';
		echo '<tbody>';
		if($ae_List['id_anakemas'] > 0) //wujud
		{
			$terima_btn = '<a class="btn btn-sm btn-default btn-text-primary btn-hover-primary btn-icon mr-2" onclick="loadMyModal(\'general-terima_tind_sub.php?id='.$id_anakemas.'&program='.$id_program.'&pass=1\', \'#ajax-modal\')" title="Terima Dokumen"><span class="svg-icon svg-icon-primary svg-icon-2x">'.$Check_svg.'</span></a>';
			
			$sah_btn = '<a class="btn btn-sm btn-default btn-text-primary btn-hover-primary btn-icon mr-2" onclick="loadMyModal(\'general-sah_tind_sub.php?id='.$id_anakemas.'&program='.$id_program.'&pass=1\', \'#ajax-modal\')" title="Pengesahan Permohonan"><span class="svg-icon svg-icon-primary svg-icon-2x">'.$Check_svg.'</span></a>';
			
			$tindakan = '-';			
			
			if($my_details->user_level <= 4 && $ae_List['id_statusmohon'] == 2)
			{
				$tindakan = $terima_btn;					
			}
			else if(($my_details->user_level == 1 || $my_details->user_level == 3 || $my_details->user_level == 5) && $ae_List['id_statusmohon'] == 3)
			{
				$tindakan = $sah_btn;					
			}
			
			echo '<tr class="table-success">';
				echo '<td>1.</td>';
				echo '<td>'.$tindakan.'</td>';
				echo '<td><a href="javascript:;" onclick="loadMyModal(\'general-maklumat_sub.php?id='.$id_anakemas.'&program='.$id_program.'\', \'#ajax-modal\')" title="Maklumat Anak Emas">'.$ae_List['nama_anakemas'].'</a></td>';
				echo '<td>'.$ae_List['desk_program'].'</td>';
				echo '<td>'.$ae_List['kpbaru_anakemas'].'</td>';
				echo '<td>'.$ae_List['nama_pemohon'].'</td>';
				echo '<td>'.$ae_List['tel_hp'].'</td>';
				echo '<td>'.$ae_List['desk_bank'].'</td>';
				echo '<td>'.$ae_List['no_akaunanakemas'].'</td>';
				echo '<td>'.$ae_List['dun_pemohon'].'</td>';
				echo '<td>'.$ae_List['desk_statusmohon'].'</td>';
			echo '</tr>';
		}
		else
		{
			echo '<tr class="table-success">';
				echo '<th colspan="12">Tiada Maklumat</th>';
			echo '</tr>';				
		}
		echo '</tbody>';
	echo '</table>';
	
	?>	
	
	<table>
		<tbody><br>
			<?php
				if($ae_List['id_anakemas'] > 0 && $ae_List['id_aktifmohon'] == 1 && $ae_List['id_statushidup'] == 1) //wujud
				{
					createtableLabels('Tarikh Daftar', '10', formatDate($ae_List['tkh_daftar'],'d M Y'));
				}
				
				if($ae_List['id_terima'] > 0)
				{
					$dun_terima = '<br>KADUN : '.$ae_List['dun_terima'];
					$daerah_terima = '<br>DAERAH : '.$ae_List['daerah_terima'];
					
					if($ae_List['dun_terima'] == '')
					{											
						$dun_terima = '';
					}
					
					if($ae_List['daerah_terima'] == '')
					{											
						$daerah_terima = '';
					}										
					createtableLabels('Tarikh Terima Dokumen', '10', formatDate($ae_List['tkh_terima'],'d M Y'));
					createtableLabels('Pegawai Terima Dokumen', '10', $ae_List['nama_terima'].$dun_terima.$daerah_terima);
				}
				if($ae_List['id_sah'] > 0)
				{
					$dun_sah = '<br>KADUN : '.$ae_List['dun_sah'];
					$daerah_sah = '<br>DAERAH : '.$ae_List['daerah_sah'];
					
					if($ae_List['dun_sah'] == '')
					{											
						$dun_sah = '';
					}
					
					if($ae_List['daerah_sah'] == '')
					{											
						$daerah_sah = '';
					}
					createtableLabels('Tarikh Pengesahan', '10', formatDate($ae_List['tkh_sah'],'d M Y'));
					createtableLabels('Pegawai Pengesahan', '10', $ae_List['nama_sah'].$dun_sah.$daerah_sah);
				}
				if($ae_List['id_saheft'] > 0)
				{
					$dun_saheft = '<br>KADUN : '.$ae_List['dun_saheft'];
					$daerah_saheft = '<br>DAERAH : '.$ae_List['daerah_saheft'];
					
					if($ae_List['dun_saheft'] == '')
					{											
						$dun_saheft = '';
					}
					
					if($ae_List['daerah_saheft'] == '')
					{											
						$daerah_saheft = '';
					}
					createtableLabels('Tarikh Pengesahan EFT', '10', formatDate($ae_List['tkh_saheft'],'d M Y'));
					createtableLabels('Pegawai Pengesahan EFT', '10', $ae_List['nama_saheft'].$dun_saheft.$daerah_saheft);
				}
			?>
		</tbody>
	</table>	
	
	<?php
	
	
echo '</div>';

?>