<?php
if($_COOKIE['sejahtera_role'] == 10)
{
	include_once ("includes/setup_pemohon.inc.php");
}
else
{
	include_once ("includes/setup.inc.php");
}
$myID = fetch_postget_val('id',$_POST, $_GET);
$id_program = fetch_postget_val('program',$_POST, $_GET);
$dateTimeNow = dateTimeNow();

$indicator_Query = "SELECT A.*,B.desk_program,C.desk_statusmohon, E.desk_khairatkat, F.desk_sahmati, H.desk_aktifmohon, I.desk_statushidup, J.desk_rumahorgtua, K.nama AS nama_keyinmati, L.desk_daerah AS daerah_keyinmati, M.nama AS nama_keysahmati, N.desk_daerah AS daerah_keysahmati, O.nama AS nama_terima, P.desk_dun AS dun_terima, Q.desk_daerah AS daerah_terima, R.nama AS nama_sah, S.desk_dun AS dun_sah, T.desk_daerah AS daerah_sah, U.nama AS nama_saheft, V.desk_dun AS dun_saheft, W.desk_daerah AS daerah_saheft, X.desk_carabayar, Y.desk_bank, Z.desk_sbbtunai, AA.desk_byrkepada, AB.desk_jenisakaun, AC.desk_poskod, AD.desk_negeri, AE.desk_dun AS dun_pemohon, AF.desk_daerah AS daerah_pemohon, AG.desk_warganegara, AH.desk_dun AS dun_pasangan, AI.desk_poskod AS desk_poskodpas, AJ.desk_negeri AS desk_negeripas, AK.desk_caramohon, AL.nama AS nama_daftar, AM.desk_dun AS dun_daftar, AN.desk_daerah AS daerah_daftar
				  FROM m_pemohon A
				  LEFT JOIN i_program B ON B.id_program = A.id_program
				  LEFT JOIN i_statusmohon C ON C.id_statusmohon = A.id_statusmohon
				  LEFT JOIN i_khairatkat E ON E.id_khairatkat = A.id_khairatkat
				  LEFT JOIN i_sahmati F ON F.id_sahmati = A.id_sahmati
				  LEFT JOIN i_aktifmohon H ON H.id_aktifmohon = A.id_aktifmohon
				  LEFT JOIN i_statushidup I ON I.id_statushidup = A.id_statushidup
				  LEFT JOIN i_rumahorgtua J ON J.id_rumahorgtua = A.id_rumahorgtua
				  LEFT JOIN t_pengguna K ON K.id_pengguna = A.id_keyinmati
				  LEFT JOIN i_daerah L ON L.id_daerah = K.id_daerah
				  LEFT JOIN t_pengguna M ON M.id_pengguna = A.id_keysahmati
				  LEFT JOIN i_daerah N ON N.id_daerah = M.id_daerah
				  LEFT JOIN t_pengguna O ON O.id_pengguna = A.id_terima
				  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 t_pengguna R ON R.id_pengguna = A.id_sah
				  LEFT JOIN i_dun S ON S.id_dun = R.id_dun
				  LEFT JOIN i_daerah T ON T.id_daerah = R.id_daerah
				  LEFT JOIN t_pengguna U ON U.id_pengguna = A.id_saheft
				  LEFT JOIN i_dun V ON V.id_dun = U.id_dun
				  LEFT JOIN i_daerah W ON W.id_daerah = U.id_daerah
				  LEFT JOIN i_carabayar X ON X.id_carabayar = A.id_carabayar
				  LEFT JOIN i_bank Y ON Y.id_bank = A.id_bank
				  LEFT JOIN i_sbbtunai Z ON Z.id_sbbtunai = A.id_sbbtunai
				  LEFT JOIN i_byrkepada AA ON AA.id_byrkepada = A.id_byrkepada
				  LEFT JOIN i_jenisakaun AB ON AB.id_jenisakaun = A.id_jenisakaun
				  LEFT JOIN i_poskod AC ON AC.id_poskod = A.id_poskod
				  LEFT JOIN i_negeri AD ON AD.id_negeri = A.id_negeri
				  LEFT JOIN i_dun AE ON AE.id_dun = A.id_dun
				  LEFT JOIN i_daerah AF ON AF.id_daerah = AE.id_daerah
				  LEFT JOIN i_warganegara AG ON AG.id_warganegara = A.id_warganegara
				  LEFT JOIN i_dun AH ON AH.id_dun = A.id_dunpasangan
				  LEFT JOIN i_poskod AI ON AI.id_poskod = A.id_poskodpasangan
				  LEFT JOIN i_negeri AJ ON AJ.id_negeri = A.id_negeripasangan
				  LEFT JOIN i_caramohon AK ON AK.id_caramohon = A.id_caramohon
				  LEFT JOIN t_pengguna AL ON AL.id_pengguna = A.id_daftar
				  LEFT JOIN i_dun AM ON AM.id_dun = AL.id_dun
				  LEFT JOIN i_daerah AN ON AN.id_daerah = AL.id_daerah
				  WHERE A.id_pemohon = ?";
$PDO_stmt = $PDO->prepare($indicator_Query); 
$PDO_stmt->bindValue(1, $myID, PDO::PARAM_INT);
$PDO_stmt->execute();
$indicator_List['m_pemohon'] = $PDO_stmt->fetch(PDO::FETCH_ASSOC);

$indicator_Query = "SELECT A.*, B.desk_hubungan, C.desk_poskod, D.desk_negeri, E.desk_bank
				  FROM m_waris A
				  LEFT JOIN i_hubungan B ON B.id_hubungan = A.id_hubungan
				  LEFT JOIN i_poskod C ON C.id_poskod = A.id_poskodwaris
				  LEFT JOIN i_negeri D ON D.id_negeri = A.id_negeriwaris
				  LEFT JOIN i_bank E ON E.id_bank = A.id_bankwaris
				  WHERE A.id_pemohon = ? 
				  AND A.status = 1";
$PDO_stmt = $PDO->prepare($indicator_Query); 
$PDO_stmt->bindValue(1, $myID, PDO::PARAM_INT);
$PDO_stmt->execute();
$indicator_List['m_waris'] = $PDO_stmt->fetch(PDO::FETCH_ASSOC);

//***********************************************************************************************************************
// PRINT PDF
//***********************************************************************************************************************
require_once('classes/tcpdf/config/tcpdf_config.php');
require_once('classes/tcpdf/tcpdf.php');
include_once ("classes/phpqrcode/qrlib.php");

$errorCorrectionLevel ='L';
$matrixPointSize = 1;
$url = $indicator_List['m_pemohon']['kpbaru_pemohon'];
$filename = 'qrcodes/'.$indicator_List['m_pemohon']['kpbaru_pemohon'].'.png';
QRcode::png($url, $filename, $errorCorrectionLevel, $matrixPointSize, 1);	

//include_once ("inc/setup.inc.php");
error_reporting(0);

// Extend the TCPDF class to create custom Header and Footer
class MYPDF extends TCPDF {

	private $myHeaderTitle = array();
	public function setHeaderTable($headerArray)
	{
		$this->myHeaderTitle = array();
		for( $num = 0 ; $num < count($headerArray) ; $num++ )
		{
			$this->myHeaderTitle[] = $headerArray[$num];
		}
	}
	
	private $pageTitle = '';
	public function setHeaderTitle($title)
	{
		$this->pageTitle = $title;
	}
	//Page header
	public function Header() {
		
		//$this->setJPEGQuality(90);
		//$this->Image('images/banner.png', 0, 0, 210, 0, 'PNG', '');
				
		//$this->Ln(30);
		//$this->SetFont('helveticaB', '', 14); //CHANGE THIS FOR TITLE FONT
		//$this->MultiCell(0, 0, $this->pageTitle, 0, 'C', 0, 1, '', '', true);
		/*
		$HTML = '<table border="1" style="text-align:center;padding: 6px;">';
		$HTML .= '<tr style="font-weight: bold;">';
		$counter = 1;
		for( $num = 0 ; $num < count($this->myHeaderTitle) ; $num++ )
		{
			if($this->myHeaderTitle[$num][1] > 0)
			{
				$HTML .= '<th style="width:'.$this->myHeaderTitle[$num][1].'%">'.$this->myHeaderTitle[$num][0].'</th>';
			}
		}
		$HTML .= '</tr>';
		$HTML .= '</table>';
		$this->SetFont('helvetica', '', 10); //CHANGE THIS FOR HEADER TITLE FONT
		$this->writeHTMLCell(0, 0, '', 19, $HTML, 0, 0, 0, true, '', false);
		*/
	}

	// Page footer
	public function Footer() {
		
		// Position at 15 mm from bottom
		$this->SetFont('helvetica', '', 8);
		$this->MultiCell(0, 0, 'Muka Surat '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, 'R', 0, 1, '', '', true);
	}
}

// -----------------------------------------------------------------------------
// create new PDF document
$pdf = new MYPDF("P", PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); //P for portrait, L for landscape

$khairat = '';
if($indicator_List['m_pemohon']['id_statushidup'] == 2)
{
	$khairat = 'KHAIRAT KEMATIAN ';
}
$TITLE = 'MAKLUMAT '.$khairat.$indicator_List['m_pemohon']['desk_program'];
$FILE_NAME = 'MAKLUMAT';
$output_filename = "borang_".$indicator_List['NoKPPemohon'].".pdf";
$pdf->setHeaderTitle($TITLE);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('PSUKPP');
$pdf->SetTitle($TITLE);
$pdf->SetSubject($TITLE);
$pdf->SetKeywords('TCPDF, PDF, $TITLE');

// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);

// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

if($manual_TOP <= 0)
{
	$manual_TOP = PDF_MARGIN_TOP;
}
//set margins
//$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetMargins(5, 10, 5);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER - 10);

//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM - 10);

//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

//set some language-dependent strings
$pdf->setLanguageArray($l);

// -----------------------------------------------------------------------------
$pdf->setCellPaddings(0, 0, 0, 0);
$pdf->AddPage();
// MultiCell($w, $h, $txt, $border=0, $align='J', $fill=0, $ln=1, $x='', $y='', $reseth=true, $stretch=0, $ishtml=false, $autopadding=true, $maxh=0)
$pdf->SetFont('helvetica', '', 8.5); //same font for the whole pdf

$HTML = '<table border="0" style="width:100%;padding:5px;">';
$HTML .= '<tr>';
$HTML .= '<td style="text-align:center" colspan="2"><h2>MAKLUMAT '.$khairat.$indicator_List['m_pemohon']['desk_program'].'</h2></td>';
$HTML .= '</tr>';
$HTML .= '<tr>';
$HTML .= '<td>';
$HTML .= '<img src="'.$filename.'" style="width:90px;height:90px">';	
$HTML .= '</td>';
$HTML .= '<td style="text-align: right;">
			No. Siri : <b>'.$indicator_List['m_pemohon']['no_siri'].'</b><br><b>'.$indicator_List['m_pemohon']['nama_pemohon'].'</b><br><b>'.$indicator_List['m_pemohon']['kpbaru_pemohon'].'</b>';
$HTML .= '</td>';
$HTML .= '</tr>';
$HTML .= '</table>';
$pdf->writeHTMLCell(0, 0, '', '', $HTML, 0, 1, 0, true, 'L', false);
	
$HTML = '<table border="0" style="width:100%;padding:0px;border:1px solid black;">';
$HTML .= '<tr>';
$HTML .= '<td style="text-align:left;border:1px solid black" colspan="3"><h4>Maklumat Permohonan</h4></td>';
$HTML .= '</tr>';
$HTML .= '<tr>';
	$HTML .= '<td style="width:30%">No. Siri</td>';
	$HTML .= '<td style="width:2%">:</td>';
	$HTML .= '<td style="width:68%"><b>'.$indicator_List['m_pemohon']['no_siri'].'</b></td>';
$HTML .= '</tr>';
$HTML .= '<tr>';
	$HTML .= '<td style="width:30%">Tarikh Lahir</td>';
	$HTML .= '<td style="width:2%">:</td>';
	$HTML .= '<td style="width:68%"><b>'.formatdate($indicator_List['m_pemohon']['tkh_lahir'],'d M Y').'</b></td>';
$HTML .= '</tr>';

$icno = $indicator_List['m_pemohon']['kpbaru_pemohon'];
$year = substr($icno , 0, 2);
$year = (($year < date('y'))?('20'.$year):('19'.$year));
$month = substr($icno , 2, 2);
$day = substr($icno , 4, 2);		
//$age = dateDifference(date('Y-m-d') , $year.'-'.$month.'-'.$day, '%y' );
$age = date('Y') - $year;
									
$HTML .= '<tr>';
	$HTML .= '<td style="width:30%">Umur</td>';
	$HTML .= '<td style="width:2%">:</td>';
	$HTML .= '<td style="width:68%"><b>'.$age.' Tahun</b></td>';
$HTML .= '</tr>';
$HTML .= '<tr>';
	$HTML .= '<td style="width:30%">Alamat</td>';
	$HTML .= '<td style="width:2%">:</td>';
	$HTML .= '<td style="width:68%"><b>'.$indicator_List['m_pemohon']['alamat'].''.$indicator_List['m_pemohon']['alamat2'].''.$indicator_List['m_pemohon']['alamat3'].','.$indicator_List['m_pemohon']['desk_poskod'].' '.$indicator_List['m_pemohon']['bandar'].','.$indicator_List['m_pemohon']['desk_negeri'].'</b></td>';
$HTML .= '</tr>';
$HTML .= '<tr>';
	$HTML .= '<td style="width:30%">DUN</td>';
	$HTML .= '<td style="width:2%">:</td>';
	$HTML .= '<td style="width:68%"><b>'.$indicator_List['m_pemohon']['dun_pemohon'].'</b></td>';
$HTML .= '</tr>';
$HTML .= '<tr>';
	$HTML .= '<td style="width:30%">Daerah</td>';
	$HTML .= '<td style="width:2%">:</td>';
	$HTML .= '<td style="width:68%"><b>'.$indicator_List['m_pemohon']['daerah_pemohon'].'</b></td>';
$HTML .= '</tr>';
$HTML .= '<tr>';
	$HTML .= '<td style="width:30%">No Tel HP</td>';
	$HTML .= '<td style="width:2%">:</td>';
	$HTML .= '<td style="width:68%"><b>'.$indicator_List['m_pemohon']['tel_hp'].'</b></td>';
$HTML .= '</tr>';
$HTML .= '<tr>';
	$HTML .= '<td style="width:30%">No Tel Rumah</td>';
	$HTML .= '<td style="width:2%">:</td>';
	$HTML .= '<td style="width:68%"><b>'.$indicator_List['m_pemohon']['tel_rumah'].'</b></td>';
$HTML .= '</tr>';
$HTML .= '</table>';
$HTML .= '<br><br>';
$pdf->writeHTMLCell(0, 0, '', '', $HTML, 0, 1, 0, true, 'L', false);

if($indicator_List['m_pemohon']['id_program'] == 7)
{	
	$HTML = '<table border="0" style="width:100%;padding:0px;border:1px solid black;">';
	$HTML .= '<tr>';
	$HTML .= '<td style="text-align:left;border:1px solid black" colspan="3"><h4>Maklumat Pasangan</h4></td>';
	$HTML .= '</tr>';
	$HTML .= '<tr>';
		$HTML .= '<td style="width:30%">Nama Pasangan</td>';
		$HTML .= '<td style="width:2%">:</td>';
		$HTML .= '<td style="width:68%"><b>'.$indicator_List['m_pemohon']['nama_pasangan'].'</b></td>';
	$HTML .= '</tr>';
	$HTML .= '<tr>';
		$HTML .= '<td style="width:30%">Warganegara Pasangan</td>';
		$HTML .= '<td style="width:2%">:</td>';
		$HTML .= '<td style="width:68%"><b>'.$indicator_List['m_pemohon']['desk_warganegara'].'</b></td>';
	$HTML .= '</tr>';
	$HTML .= '<tr>';
		$HTML .= '<td style="width:30%">No Kp Baru Pasangan</td>';
		$HTML .= '<td style="width:2%">:</td>';
		$HTML .= '<td style="width:68%"><b>'.$indicator_List['m_pemohon']['kpbaru_pasangan'].'</b></td>';
	$HTML .= '</tr>';
	$HTML .= '<tr>';
		$HTML .= '<td style="width:30%">No Kp Lama/Pasport Pasangan</td>';
		$HTML .= '<td style="width:2%">:</td>';
		$HTML .= '<td style="width:68%"><b>'.$indicator_List['m_pemohon']['kplama_pasangan'].'</b></td>';
	$HTML .= '</tr>';
	$HTML .= '<tr>';
		$HTML .= '<td style="width:30%">DUN Pasangan</td>';
		$HTML .= '<td style="width:2%">:</td>';
		$HTML .= '<td style="width:68%"><b>'.$indicator_List['m_pemohon']['dun_pasangan'].'</b></td>';
	$HTML .= '</tr>';
	$HTML .= '<tr>';
		$HTML .= '<td style="width:30%">No Tel HP Pasangan</td>';
		$HTML .= '<td style="width:2%">:</td>';
		$HTML .= '<td style="width:68%"><b>'.$indicator_List['m_pemohon']['tel_hppasangan'].'</b></td>';
	$HTML .= '</tr>';
	$HTML .= '<tr>';
		$HTML .= '<td style="width:30%">Emel Pasangan</td>';
		$HTML .= '<td style="width:2%">:</td>';
		$HTML .= '<td style="width:68%"><b>'.$indicator_List['m_pemohon']['emel_pasangan'].'</b></td>';
	$HTML .= '</tr>';
	$HTML .= '<tr>';
		$HTML .= '<td style="width:30%">Alamat</td>';
		$HTML .= '<td style="width:2%">:</td>';
		$HTML .= '<td style="width:68%"><b>'.$indicator_List['m_pemohon']['alamat_pasangan'].''.$indicator_List['m_pemohon']['alamat_pasangan2'].''.$indicator_List['m_pemohon']['alamat_pasangan3'].' '.$indicator_List['m_pemohon']['desk_poskodpas'].','.$indicator_List['m_pemohon']['bandar_pasangan'].','.$indicator_List['m_pemohon']['desk_negeripas'].'</b></td>';
	$HTML .= '</tr>';
	$HTML .= '</table>';
	$HTML .= '<br><br>';
	$pdf->writeHTMLCell(0, 0, '', '', $HTML, 0, 1, 0, true, 'L', false);
}

if($indicator_List['m_waris']['id_waris'] > 0)
{
	$HTML = '<table border="0" style="width:100%;padding:0px;border:1px solid black;">';
	$HTML .= '<tr>';
	$HTML .= '<td style="text-align:left;border:1px solid black" colspan="3"><h4>Maklumat Waris</h4></td>';
	$HTML .= '</tr>';
	$HTML .= '<tr>';
		$HTML .= '<td style="width:30%">Nama Waris</td>';
		$HTML .= '<td style="width:2%">:</td>';
		$HTML .= '<td style="width:68%"><b>'.$indicator_List['m_waris']['nama_waris'].'</b></td>';
	$HTML .= '</tr>';
	$HTML .= '<tr>';
		$HTML .= '<td style="width:30%">No Kp Baru Waris</td>';
		$HTML .= '<td style="width:2%">:</td>';
		$HTML .= '<td style="width:68%"><b>'.$indicator_List['m_waris']['kpbaru_waris'].'</b></td>';
	$HTML .= '</tr>';									
	$HTML .= '<tr>';
		$HTML .= '<td style="width:30%">Hubungan</td>';
		$HTML .= '<td style="width:2%">:</td>';
		$HTML .= '<td style="width:68%"><b>'.$indicator_List['m_waris']['desk_hubungan'].'</b></td>';
	$HTML .= '</tr>';
	$HTML .= '<tr>';
		$HTML .= '<td style="width:30%">Alamat Waris</td>';
		$HTML .= '<td style="width:2%">:</td>';
		$HTML .= '<td style="width:68%"><b>'.$indicator_List['m_waris']['alamat_waris'].''.$indicator_List['m_waris']['alamat_waris2'].''.$indicator_List['m_waris']['alamat_waris3'].','.$indicator_List['m_waris']['desk_poskod'].' '.$indicator_List['m_waris']['bandar_waris'].','.$indicator_List['m_waris']['desk_negeri'].'</b></td>';
	$HTML .= '</tr>';
	$HTML .= '<tr>';
		$HTML .= '<td style="width:30%">No Tel HP</td>';
		$HTML .= '<td style="width:2%">:</td>';
		$HTML .= '<td style="width:68%"><b>'.$indicator_List['m_waris']['tel_hpwaris'].'</b></td>';
	$HTML .= '</tr>';
	$HTML .= '<tr>';
		$HTML .= '<td style="width:30%">Emel</td>';
		$HTML .= '<td style="width:2%">:</td>';
		$HTML .= '<td style="width:68%"><b>'.$indicator_List['m_waris']['emel_waris'].'</b></td>';
	$HTML .= '</tr>';
	$HTML .= '<tr>';
		$HTML .= '<td style="width:30%">Bank Waris</td>';
		$HTML .= '<td style="width:2%">:</td>';
		$HTML .= '<td style="width:68%"><b>'.$indicator_List['m_waris']['desk_bank'].'</b></td>';
	$HTML .= '</tr>';
	$HTML .= '<tr>';
		$HTML .= '<td style="width:30%">No Akaun Waris</td>';
		$HTML .= '<td style="width:2%">:</td>';
		$HTML .= '<td style="width:68%"><b>'.$indicator_List['m_waris']['no_akaunwaris'].'</b></td>';
	$HTML .= '</tr>';
	$HTML .= '</table>';
	$HTML .= '<br><br>';
	$pdf->writeHTMLCell(0, 0, '', '', $HTML, 0, 1, 0, true, 'L', false);
}

$HTML = '<table border="0" style="width:100%;padding:0px;border:1px solid black;">';
$HTML .= '<tr>';
$HTML .= '<td style="text-align:left;border:1px solid black" colspan="3"><h4>Maklumat Bank (Pembayaran)</h4></td>';
$HTML .= '</tr>';
$HTML .= '<tr>';
	$HTML .= '<td style="width:30%">Cara Pembayaran</td>';
	$HTML .= '<td style="width:2%">:</td>';
	$HTML .= '<td style="width:68%"><b>'.$indicator_List['m_pemohon']['desk_carabayar'].'</b></td>';
$HTML .= '</tr>';
$HTML .= '<tr>';
	$HTML .= '<td style="width:30%">Bank</td>';
	$HTML .= '<td style="width:2%">:</td>';
	$HTML .= '<td style="width:68%"><b>'.$indicator_List['m_pemohon']['desk_bank'].'</b></td>';
$HTML .= '</tr>';									
$HTML .= '<tr>';
	$HTML .= '<td style="width:30%">No Akaun</td>';
	$HTML .= '<td style="width:2%">:</td>';
	$HTML .= '<td style="width:68%"><b>'.$indicator_List['m_pemohon']['no_akaun'].'</b></td>';
$HTML .= '</tr>';
$HTML .= '<tr>';
	$HTML .= '<td style="width:30%">Sebab Tunai</td>';
	$HTML .= '<td style="width:2%">:</td>';
	$HTML .= '<td style="width:68%"><b>'.$indicator_List['m_pemohon']['desk_sbbtunai'].'</b></td>';
$HTML .= '</tr>';
$HTML .= '<tr>';
	$HTML .= '<td style="width:30%">Bayaran Kepada</td>';
	$HTML .= '<td style="width:2%">:</td>';
	$HTML .= '<td style="width:68%"><b>'.$indicator_List['m_pemohon']['desk_byrkepada'].'</b></td>';
$HTML .= '</tr>';
$HTML .= '<tr>';
	$HTML .= '<td style="width:30%">Jenis Akaun</td>';
	$HTML .= '<td style="width:2%">:</td>';
	$HTML .= '<td style="width:68%"><b>'.$indicator_List['m_pemohon']['desk_jenisakaun'].'</b></td>';
$HTML .= '</tr>';
$HTML .= '<tr>';
	$HTML .= '<td style="width:30%">Nama Perkongsian Akaun</td>';
	$HTML .= '<td style="width:2%">:</td>';
	$HTML .= '<td style="width:68%"><b>'.$indicator_List['m_pemohon']['nama_kongsiakaun'].'</b></td>';
$HTML .= '</tr>';
if($indicator_List['m_pemohon']['flag_saheft'] > 0)
{	
	$dun_saheft = '<br>KADUN : '.$indicator_List['m_pemohon']['dun_saheft'];
	$daerah_saheft = '<br>DAERAH : '.$indicator_List['m_pemohon']['daerah_saheft'];
	
	if($indicator_List['m_pemohon']['dun_saheft'] == '')
	{											
		$dun_saheft = '';
	}
	
	if($indicator_List['m_pemohon']['daerah_saheft'] == '')
	{											
		$daerah_saheft = '';
	}
	
	$HTML .= '<tr>';
		$HTML .= '<td style="width:30%">Tarikh Pengesahan EFT</td>';
		$HTML .= '<td style="width:2%">:</td>';
		$HTML .= '<td style="width:68%"><b>'.formatDate($indicator_List['m_pemohon']['tkh_saheft'],'d M Y').'</b></td>';
	$HTML .= '</tr>';		
	$HTML .= '<tr>';
		$HTML .= '<td style="width:30%">Pegawai Pengesahan EFT</td>';
		$HTML .= '<td style="width:2%">:</td>';
		$HTML .= '<td style="width:68%"><b>'.$indicator_List['m_pemohon']['nama_saheft'].$dun_saheft.$daerah_saheft.'</b></td>';
	$HTML .= '</tr>';
}
$HTML .= '</table>';
$HTML .= '<br><br>';
$pdf->writeHTMLCell(0, 0, '', '', $HTML, 0, 1, 0, true, 'L', false);
	
$HTML = '<table border="0" style="width:100%;padding:0px;border:1px solid black;">';
$HTML .= '<tr>';
$HTML .= '<td style="text-align:left;border:1px solid black" colspan="3"><h4>Maklumat Pengesahan</h4></td>';
$HTML .= '</tr>';
$HTML .= '<tr>';
	$HTML .= '<td style="width:30%">Tarikh Daftar</td>';
	$HTML .= '<td style="width:2%">:</td>';
	$HTML .= '<td style="width:68%"><b>'.formatDate($indicator_List['m_pemohon']['tkh_daftar'],'d M Y').' ('.$indicator_List['m_pemohon']['desk_caramohon'].')</b></td>';
$HTML .= '</tr>';

if($indicator_List['m_pemohon']['id_caramohon'] == 1)
{						
	$dun_daftar = '<br>KADUN : '.$indicator_List['m_pemohon']['dun_daftar'];
	$daerah_daftar = '<br>DAERAH : '.$indicator_List['m_pemohon']['daerah_daftar'];			
	if($indicator_List['m_pemohon']['dun_daftar'] == '')
	{											
		$dun_daftar = '';
	}			
	if($indicator_List['m_pemohon']['daerah_daftar'] == '')
	{											
		$daerah_daftar = '';
	}
			
	$HTML .= '<tr>';
		$HTML .= '<td style="width:30%">Pegawai Daftar Dokumen</td>';
		$HTML .= '<td style="width:2%">:</td>';
		$HTML .= '<td style="width:68%"><b>'.$indicator_List['m_pemohon']['nama_daftar'].$dun_daftar.$daerah_daftar.'</b></td>';
	$HTML .= '</tr>';
}
	
$tkh_terima = $indicator_List['m_pemohon']['tkh_terima'];
if($tkh_terima == '0000-00-00 00:00:00' && $indicator_List['m_pemohon']['tkh_sah'] == '0000-00-00 00:00:00')
{
	$tkh_terima = 'Dokumen Belum Diterima';										
}
else if($tkh_terima == '0000-00-00 00:00:00' && $indicator_List['m_pemohon']['tkh_sah'] != '0000-00-00 00:00:00')
{
	$tkh_terima = formatDate($indicator_List['m_pemohon']['tkh_daftar'],'d M Y');										
}
else
{
	$tkh_terima = formatDate($indicator_List['m_pemohon']['tkh_terima'],'d M Y');										
}

$HTML .= '<tr>';
	$HTML .= '<td style="width:30%">Tarikh Terima Dokumen</td>';
	$HTML .= '<td style="width:2%">:</td>';
	$HTML .= '<td style="width:68%"><b>'.$tkh_terima.'</b></td>';
$HTML .= '</tr>';

if($indicator_List['m_pemohon']['id_terima'] > 0)
{						
	$dun_terima = '<br>KADUN : '.$indicator_List['m_pemohon']['dun_terima'];
	$daerah_terima = '<br>DAERAH : '.$indicator_List['m_pemohon']['daerah_terima'];			
	if($indicator_List['m_pemohon']['dun_terima'] == '')
	{											
		$dun_terima = '';
	}			
	if($indicator_List['m_pemohon']['daerah_terima'] == '')
	{											
		$daerah_terima = '';
	}
			
	$HTML .= '<tr>';
		$HTML .= '<td style="width:30%">Pegawai Terima Dokumen</td>';
		$HTML .= '<td style="width:2%">:</td>';
		$HTML .= '<td style="width:68%"><b>'.$indicator_List['m_pemohon']['nama_terima'].$dun_terima.$daerah_terima.'</b></td>';
	$HTML .= '</tr>';
}
if($indicator_List['m_pemohon']['id_sah'] > 0)
{	
	$dun_sah = '<br>KADUN : '.$indicator_List['m_pemohon']['dun_sah'];
	$daerah_sah = '<br>DAERAH : '.$indicator_List['m_pemohon']['daerah_sah'];
	
	if($indicator_List['m_pemohon']['dun_sah'] == '')
	{											
		$dun_sah = '';
	}
	
	if($indicator_List['m_pemohon']['daerah_sah'] == '')
	{											
		$daerah_sah = '';
	}
	
	$HTML .= '<tr>';
		$HTML .= '<td style="width:30%">Tarikh Pengesahan</td>';
		$HTML .= '<td style="width:2%">:</td>';
		$HTML .= '<td style="width:68%"><b>'.formatDate($indicator_List['m_pemohon']['tkh_sah'],'d M Y').'</b></td>';
	$HTML .= '</tr>';		
	$HTML .= '<tr>';
		$HTML .= '<td style="width:30%">Pegawai Pengesahan</td>';
		$HTML .= '<td style="width:2%">:</td>';
		$HTML .= '<td style="width:68%"><b>'.$indicator_List['m_pemohon']['nama_sah'].$dun_sah.$daerah_sah.'</b></td>';
	$HTML .= '</tr>';
}
$HTML .= '</table>';
$HTML .= '<br><br>';
$pdf->writeHTMLCell(0, 0, '', '', $HTML, 0, 1, 0, true, 'L', false);

if($indicator_List['m_pemohon']['id_statushidup'] == 2)
{							
	$indicator_Query = "SELECT A.*, B.desk_bayaranfasa, C.desk_bayaranjenis, D.desk_bayarankat, E.nama AS namasah, F.nama AS namadaftar, G.desk_daerah, H.desk_dun, I.desk_carabayar, J.desk_bank
					  FROM m_bayaran_KH A
					  LEFT JOIN i_bayaranfasa B ON B.id_bayaranfasa = A.id_bayaranfasa
					  LEFT JOIN i_bayaranjenis C ON C.id_bayaranjenis = A.id_bayaranjenis
					  LEFT JOIN i_bayarankat D ON D.id_bayarankat = A.id_bayarankat
					  LEFT JOIN t_pengguna E ON E.id_pengguna = A.id_sah
					  LEFT JOIN t_pengguna F ON F.id_pengguna = A.id_daftar
					  LEFT JOIN i_daerah G ON G.id_daerah = A.id_daerah
					  LEFT JOIN i_dun H ON H.id_dun = A.id_dun
					  LEFT JOIN i_carabayar I ON I.id_carabayar = A.id_carabayar
					  LEFT JOIN i_bank J ON J.id_bank = A.id_bank
					  WHERE A.id_pemohon = ?
					  ORDER BY A.tahun_bayar ASC";
	$PDO_stmt = $PDO->prepare($indicator_Query);
	$PDO_stmt->bindValue(1, $myID, PDO::PARAM_INT);
	$PDO_stmt->execute();

	$pembayaran_KH_List = array();
	while($result = $PDO_stmt->fetch(PDO::FETCH_ASSOC))
	{
		$pembayaran_KH_List[] = $result;
	}

	$statusbyrkhairat = 'BELUM DIBAYAR';
	if(count($pembayaran_KH_List) > 0)
	{
		$statusbyrkhairat = 'TELAH DIBAYAR';												
	}
	
	$HTML = '<table border="0" style="width:100%;padding:0px;border:1px solid black;">';
	$HTML .= '<tr>';
	$HTML .= '<td style="text-align:left;border:1px solid black" colspan="3"><h4>Khairat Kematian</h4></td>';
	$HTML .= '</tr>';
	$HTML .= '<tr>';
		$HTML .= '<td style="width:30%">Pendaftar</td>';
		$HTML .= '<td style="width:2%">:</td>';
		$HTML .= '<td style="width:68%"><b>'.$indicator_List['m_pemohon']['nama_keyinmati'].' ('.$indicator_List['m_pemohon']['daerah_keyinmati'].')</b></td>';
	$HTML .= '</tr>';
	$HTML .= '<tr>';
		$HTML .= '<td style="width:30%">Tarikh Daftar Kematian</td>';
		$HTML .= '<td style="width:2%">:</td>';
		$HTML .= '<td style="width:68%"><b>'.formatDate($indicator_List['m_pemohon']['tkh_keyinmati'],'d M Y').'</b></td>';
	$HTML .= '</tr>';
	if($indicator_List['m_pemohon']['id_keysahmati'] > 0)
	{
		$HTML .= '<tr>';
			$HTML .= '<td style="width:30%">Pengesah</td>';
			$HTML .= '<td style="width:2%">:</td>';
			$HTML .= '<td style="width:68%"><b>'.$indicator_List['m_pemohon']['nama_keysahmati'].' ('.$indicator_List['m_pemohon']['daerah_keysahmati'].')</b></td>';
		$HTML .= '</tr>';
		$HTML .= '<tr>';
			$HTML .= '<td style="width:30%">Tarikh Pengesahan</td>';
			$HTML .= '<td style="width:2%">:</td>';
			$HTML .= '<td style="width:68%"><b>'.formatDate($indicator_List['m_pemohon']['tkh_keysahmati'],'d M Y').'</b></td>';
		$HTML .= '</tr>';
	}
	$HTML .= '<tr>';
		$HTML .= '<td style="width:30%">Status Khairat</td>';
		$HTML .= '<td style="width:2%">:</td>';
		$HTML .= '<td style="width:68%"><b>'.$indicator_List['m_pemohon']['desk_sahmati'].'</b></td>';
	$HTML .= '</tr>';
	$HTML .= '<tr>';
		$HTML .= '<td style="width:30%">Kategori Khairat</td>';
		$HTML .= '<td style="width:2%">:</td>';
		$HTML .= '<td style="width:68%"><b>'.$indicator_List['m_pemohon']['desk_khairatkat'].'</b></td>';
	$HTML .= '</tr>';
	$HTML .= '<tr>';
		$HTML .= '<td style="width:30%">Tarikh Kematian</td>';
		$HTML .= '<td style="width:2%">:</td>';
		$HTML .= '<td style="width:68%"><b>'.formatDate($indicator_List['m_pemohon']['tkh_mati'],'d M Y').'</b></td>';
	$HTML .= '</tr>';
	$HTML .= '<tr>';
		$HTML .= '<td style="width:30%">No Sijil Kematian</td>';
		$HTML .= '<td style="width:2%">:</td>';
		$HTML .= '<td style="width:68%"><b>'.$indicator_List['m_pemohon']['no_sijilmati'].'</b></td>';
	$HTML .= '</tr>';
	$HTML .= '<tr>';
		$HTML .= '<td style="width:30%">Ulasan</td>';
		$HTML .= '<td style="width:2%">:</td>';
		$HTML .= '<td style="width:68%"><b>'.$indicator_List['m_pemohon']['ulasan_mati'].'</b></td>';
	$HTML .= '</tr>';
	$HTML .= '<tr>';
		$HTML .= '<td style="width:30%">Status Pembayaran</td>';
		$HTML .= '<td style="width:2%">:</td>';
		$HTML .= '<td style="width:68%"><b>'.$statusbyrkhairat.'</b></td>';
	$HTML .= '</tr>';
	if(count($pembayaran_KH_List) > 0)
	{
		for($num2 = 0; $num2 < count($pembayaran_KH_List); $num2++)
		{
			$HTML .= '<tr>';
				$HTML .= '<td style="width:30%">Tarikh Bayaran</td>';
				$HTML .= '<td style="width:2%">:</td>';
				$HTML .= '<td style="width:68%"><b>'.formatDate($pembayaran_KH_List[$num2]['tkh_bayar'],'d M Y').'</b></td>';
			$HTML .= '</tr>';
			$HTML .= '<tr>';
				$HTML .= '<td style="width:30%">Cara Bayaran</td>';
				$HTML .= '<td style="width:2%">:</td>';
				$HTML .= '<td style="width:68%"><b>'.$pembayaran_KH_List[$num2]['desk_carabayar'].'</b></td>';
			$HTML .= '</tr>';
			$HTML .= '<tr>';
				$HTML .= '<td style="width:30%">Nama Bank</td>';
				$HTML .= '<td style="width:2%">:</td>';
				$HTML .= '<td style="width:68%"><b>'.$pembayaran_KH_List[$num2]['desk_bank'].'</b></td>';
			$HTML .= '</tr>';
			$HTML .= '<tr>';
				$HTML .= '<td style="width:30%">No akaun</td>';
				$HTML .= '<td style="width:2%">:</td>';
				$HTML .= '<td style="width:68%"><b>'.$pembayaran_KH_List[$num2]['no_akaun'].'</b></td>';
			$HTML .= '</tr>';
		}
	}
	$HTML .= '</table>';
	$HTML .= '<br><br>';
	$pdf->writeHTMLCell(0, 0, '', '', $HTML, 0, 1, 0, true, 'L', false);
}

$HTML = '<table border="0" style="width:100%;padding:0px;border:1px solid black;">';
$HTML .= '<tr>';
$HTML .= '<td style="text-align:left;border:1px solid black" colspan="3"><h4>Maklumat Status Permohonan & Status Aktif</h4></td>';
$HTML .= '</tr>';
$HTML .= '<tr>';
	$HTML .= '<td style="width:30%">Status Permohonan</td>';
	$HTML .= '<td style="width:2%">:</td>';
	$HTML .= '<td style="width:68%"><b>'.$indicator_List['m_pemohon']['desk_statusmohon'].'</b></td>';
$HTML .= '</tr>';
$HTML .= '<tr>';
	$HTML .= '<td style="width:30%">Status Hidup</td>';
	$HTML .= '<td style="width:2%">:</td>';
	$HTML .= '<td style="width:68%"><b>'.$indicator_List['m_pemohon']['desk_statushidup'].'</b></td>';
$HTML .= '</tr>';	
$HTML .= '<tr>';
	$HTML .= '<td style="width:30%">Status Aktif</td>';
	$HTML .= '<td style="width:2%">:</td>';
	$HTML .= '<td style="width:68%"><b>'.$indicator_List['m_pemohon']['desk_aktifmohon'].'</b></td>';
$HTML .= '</tr>';	
if($indicator_List['m_pemohon']['ulasan_aktifmohon'] != '')
{	
	$HTML .= '<tr>';
		$HTML .= '<td style="width:30%">Ulasan Aktif</td>';
		$HTML .= '<td style="width:2%">:</td>';
		$HTML .= '<td style="width:68%"><b>'.$indicator_List['m_pemohon']['ulasan_aktifmohon'].'</b></td>';
	$HTML .= '</tr>';
}
$HTML .= '</table>';
$HTML .= '<br><br>';
$pdf->writeHTMLCell(0, 0, '', '', $HTML, 0, 1, 0, true, 'L', false);

//Close and output PDF document
ob_end_clean();
$pdf->Output($FILE_NAME.'.pdf', 'I');

//***********************************************************************************************************************
// END PRINT PDF
//***********************************************************************************************************************

?>