<?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_pemohon = fetch_postget_val('kpbaru_pemohon',$_POST, $_GET);

$indicator_Query = "SELECT A.*,
				  B.desk_statusmohon, C.desk_dun, D.desk_daerah, E.desk_program, F.desk_aktifmohon, G.desk_bank, H.desk_carabayar, 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, R.desk_caramohon, S.nama AS nama_daftar, T.desk_dun AS dun_daftar, U.desk_daerah AS daerah_daftar, V.nama AS nama_mati, W.desk_dun AS dun_mati, X.desk_daerah AS daerah_mati, Y.desk_khairatkat
				  FROM m_pemohon A
				  LEFT JOIN i_statusmohon B ON A.id_statusmohon = B.id_statusmohon
				  LEFT JOIN i_dun C ON A.id_dun = C.id_dun
				  LEFT JOIN i_daerah D ON A.id_tempattinggal = D.id_daerah
				  LEFT JOIN i_program E ON A.id_program = E.id_program
				  LEFT JOIN i_aktifmohon F ON A.id_aktifmohon = F.id_aktifmohon
				  LEFT JOIN i_bank G ON A.id_bank = G.id_bank
				  LEFT JOIN i_carabayar H ON A.id_carabayar = H.id_carabayar
				  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
				  LEFT JOIN i_caramohon R ON R.id_caramohon = A.id_caramohon
				  LEFT JOIN t_pengguna S ON S.id_pengguna = A.id_daftar
				  LEFT JOIN i_dun T ON T.id_dun = S.id_dun
				  LEFT JOIN i_daerah U ON U.id_daerah = S.id_daerah
				  LEFT JOIN t_pengguna V ON V.id_pengguna = A.id_keyinmati
				  LEFT JOIN i_dun W ON W.id_dun = V.id_dun
				  LEFT JOIN i_daerah X ON X.id_daerah = V.id_daerah
				  LEFT JOIN i_khairatkat Y ON Y.id_khairatkat = A.id_khairatkat
				  WHERE A.kpbaru_pemohon = ?
				  AND A.id_statushidup = 2
				  AND A.id_sahmati = 1
				  AND A.flag_querymati = 0";
$PDO_stmt = $PDO->prepare($indicator_Query);
$PDO_stmt->bindValue(1, $kpbaru_pemohon, PDO::PARAM_STR);
$PDO_stmt->execute();
$pemohon_List = $PDO_stmt->fetch(PDO::FETCH_ASSOC);

$id_pemohon = $pemohon_List['id_pemohon'];
$id_program = $pemohon_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</th>';
				echo '<th scope="col">Program</th>';
				echo '<th scope="col">No KP Baru</th>';
				echo '<th scope="col">Tarikh Daftar Kematian</th>';
				echo '<th scope="col">Kategori Khairat</th>';
				echo '<th scope="col">Tarikh Kematian</th>';
				echo '<th scope="col">No Sijil Mati</th>';
			echo '</tr>';
		echo '</thead>';
		echo '<tbody>';
		if($pemohon_List['id_pemohon'] > 0) //wujud
		{
			$sah_btn = '<a class="btn btn-sm btn-clean btn-icon mr-2" onclick="loadMyModal(\'general-khairat_sah.php?id='.$id_pemohon.'&program='.$id_program.'&from=1\', \'#ajax-modal\')" title="Pengesahan"><span class="svg-icon svg-icon-primary svg-icon-2x">'.$File_svg.'</span></a>';	
			
			echo '<tr class="table-success">';
				echo '<td>1.</td>';
				echo '<td>'.$sah_btn.'</td>';
				echo '<td><a href="javascript:;" onclick="loadMyModal(\'general-maklumat.php?id='.$id_pemohon.'&program='.$id_program.'\', \'#ajax-modal\')" title="Maklumat Pemohon">'.$pemohon_List['nama_pemohon'].'</a></td>';
				echo '<td>'.$pemohon_List['desk_program'].'</td>';
				echo '<td>'.$pemohon_List['kpbaru_pemohon'].'</td>';
				echo '<td>'.formatDate($pemohon_List['tkh_keyinmati'],'d M Y').'</td>';
				echo '<td>'.$pemohon_List['desk_khairatkat'].'</td>';
				echo '<td>'.formatDate($pemohon_List['tkh_mati'],'d M Y').'</td>';
				echo '<td>'.$pemohon_List['no_sijilmati'].'</td>';
			echo '</tr>';
		}
		else
		{
			echo '<tr class="table-success">';
				echo '<th colspan="9">Tiada Maklumat Permohonan Khairat untuk disahkan</th>';
			echo '</tr>';				
		}
		echo '</tbody>';
	echo '</table>';
	
	?>	
	
	<table>
		<tbody><br>
			<?php													
				if($pemohon_List['id_pemohon'] > 0)
				{
					createtableLabels('Tarikh Daftar', '10', formatDate($pemohon_List['tkh_daftar'],'d M Y').' ('.$pemohon_List['desk_caramohon'].')');
				}
																		
				if($pemohon_List['id_caramohon'] == 1)
				{
					$dun_daftar = '<br>KADUN : '.$pemohon_List['dun_daftar'];
					$daerah_daftar = '<br>DAERAH : '.$pemohon_List['daerah_daftar'];
					
					if($pemohon_List['dun_daftar'] == '')
					{											
						$dun_daftar = '';
					}
					
					if($pemohon_List['daerah_daftar'] == '')
					{											
						$daerah_daftar = '';
					}										
					createtableLabels('Pegawai Daftar Dokumen', '10', $pemohon_List['nama_daftar'].$dun_daftar.$daerah_daftar);
				}
				
				if($pemohon_List['id_terima'] > 0)
				{
					$dun_terima = '<br>KADUN : '.$pemohon_List['dun_terima'];
					$daerah_terima = '<br>DAERAH : '.$pemohon_List['daerah_terima'];
					
					if($pemohon_List['dun_terima'] == '')
					{											
						$dun_terima = '';
					}
					
					if($pemohon_List['daerah_terima'] == '')
					{											
						$daerah_terima = '';
					}										
					createtableLabels('Tarikh Terima Dokumen', '10', formatDate($pemohon_List['tkh_terima'],'d M Y'));
					createtableLabels('Pegawai Terima Dokumen', '10', $pemohon_List['nama_terima'].$dun_terima.$daerah_terima);
				}
				if($pemohon_List['id_sah'] > 0)
				{
					$dun_sah = '<br>KADUN : '.$pemohon_List['dun_sah'];
					$daerah_sah = '<br>DAERAH : '.$pemohon_List['daerah_sah'];
					
					if($pemohon_List['dun_sah'] == '')
					{											
						$dun_sah = '';
					}
					
					if($pemohon_List['daerah_sah'] == '')
					{											
						$daerah_sah = '';
					}
					createtableLabels('Tarikh Pengesahan', '10', formatDate($pemohon_List['tkh_sah'],'d M Y'));
					createtableLabels('Pegawai Pengesahan', '10', $pemohon_List['nama_sah'].$dun_sah.$daerah_sah);
				}
				if($pemohon_List['id_saheft'] > 0)
				{
					$dun_saheft = '<br>KADUN : '.$pemohon_List['dun_saheft'];
					$daerah_saheft = '<br>DAERAH : '.$pemohon_List['daerah_saheft'];
					
					if($pemohon_List['dun_saheft'] == '')
					{											
						$dun_saheft = '';
					}
					
					if($pemohon_List['daerah_saheft'] == '')
					{											
						$daerah_saheft = '';
					}
					createtableLabels('Tarikh Pengesahan EFT', '10', formatDate($pemohon_List['tkh_saheft'],'d M Y'));
					createtableLabels('Pegawai Pengesahan EFT', '10', $pemohon_List['nama_saheft'].$dun_saheft.$daerah_saheft);
				}				
				if($pemohon_List['id_keyinmati'] > 0)
				{
					$dun_mati = '<br>KADUN : '.$pemohon_List['dun_mati'];
					$daerah_mati = '<br>DAERAH : '.$pemohon_List['daerah_mati'];
					
					if($pemohon_List['dun_mati'] == '')
					{											
						$dun_mati = '';
					}
					
					if($pemohon_List['daerah_mati'] == '')
					{											
						$daerah_mati = '';
					}										
					createtableLabels('Tarikh Daftar Kematian', '10', formatDate($pemohon_List['tkh_keyinmati'],'d M Y'));
					createtableLabels('Pegawai Daftar Kematian', '10', $pemohon_List['nama_mati'].$dun_mati.$daerah_mati);
				}
			?>
		</tbody>
	</table>	
	
	<?php
	
	
echo '</div>';

?>