<?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.nama AS nama_terima, C.desk_dun AS dun_terima, D.desk_daerah AS daerah_terima, E.nama AS nama_sah, F.desk_dun AS dun_sah, G.desk_daerah AS daerah_sah, H.nama AS nama_saheft, I.desk_dun AS dun_saheft, J.desk_daerah AS daerah_saheft, K.desk_program, L.desk_dun AS dun_pemohon, M.desk_bank, N.emel AS emel_daerah
				  FROM m_pemohon A
				  LEFT JOIN t_pengguna B ON B.id_pengguna = A.id_terima
				  LEFT JOIN i_dun C ON C.id_dun = B.id_dun
				  LEFT JOIN i_daerah D ON D.id_daerah = B.id_daerah
				  LEFT JOIN t_pengguna E ON E.id_pengguna = A.id_sah
				  LEFT JOIN i_dun F ON F.id_dun = E.id_dun
				  LEFT JOIN i_daerah G ON G.id_daerah = E.id_daerah
				  LEFT JOIN t_pengguna H ON H.id_pengguna = A.id_saheft
				  LEFT JOIN i_dun I ON I.id_dun = H.id_dun
				  LEFT JOIN i_daerah J ON J.id_daerah = H.id_daerah
				  LEFT JOIN i_program K ON K.id_program = A.id_program
				  LEFT JOIN i_dun L ON L.id_dun = A.id_dun
				  LEFT JOIN i_bank M ON M.id_bank = A.id_bank
				  LEFT JOIN i_daerah N ON N.id_daerah = L.id_daerah
				  WHERE A.id_pemohon = ? AND A.id_program = ?";
$PDO_stmt = $PDO->prepare($indicator_Query);
$PDO_stmt->bindValue(1, $myID, PDO::PARAM_INT);
$PDO_stmt->bindValue(2, $id_program, PDO::PARAM_INT);
$PDO_stmt->execute();
$indicator_List['m_pemohon'] = $PDO_stmt->fetch(PDO::FETCH_ASSOC);



//var_dump($indicator_List);
//***********************************************************************************************************************
// 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);
	}

	// 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
$TITLE = 'SLIP PENGESAHAN MAKLUMAT AKAUN BANK PROGRAM '.$indicator_List['m_pemohon']['desk_program'].' NEGERI PULAU PINANG';
$FILE_NAME = 'SLIP EFT';
$output_filename = "slipeft_".$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 + 25;
}
//set margins
//$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetMargins(5, $manual_TOP, 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', '', 10); //same font for the whole pdf

$HTML = '<table border="0" style="width:100%;padding:5px;">';
$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:5px;border:none;">';
$HTML .= '<tr>';
$HTML .= '<td style="text-align:left;border:none " colspan="2"><br><h3>Maklumat Pemohon<br></h3></td>';
$HTML .= '</tr>';
$HTML .= '<tr>';
	$HTML .= '<td style="text-align:left;width:30%">
				Nama Pemohon<br>
				No.Kad Pengenalan Baru<br>
				No.Kad Pengenalan Lama<br>
				No. Telefon<br>
				Dun Mengundi<br>
			</td>';
	$HTML .= '<td style="text-align:left;width:5%">
				:<br>
				:<br>
				:<br>
				:<br>
				:<br>
			</td>';
	$HTML .= '<td style="text-align:left;width:65%">
				<b>'.$indicator_List['m_pemohon']['nama_pemohon'].'</b><br>
				<b>'.$indicator_List['m_pemohon']['kpbaru_pemohon'].'</b><br>
				<b>'.$indicator_List['m_pemohon']['kplama_pemohon'].'</b><br>
				<b>'.$indicator_List['m_pemohon']['tel_hp'].'</b><br>
				<b>'.$indicator_List['m_pemohon']['dun_pemohon'].'</b><br>
			</td>';
$HTML .= '</tr>';
$HTML .= '</table>';
$HTML .= '<br><br>';
$pdf->writeHTMLCell(0, 0, '', '', $HTML, 0, 1, 0, true, 'L', false);

			
$bank = $indicator_List['m_pemohon']['desk_bank'];
$no_akaun = $indicator_List['m_pemohon']['no_akaun'];
$kpdwaris = '';
$namabank = 'Nama Bank';
$noakaunbank = 'No. Akaun Bank';

if($indicator_List['m_pemohon']['id_byrkepada'] == 2)
{
	$indicator_Query = "SELECT A.nama_waris, A.kpbaru_waris, A.id_bankwaris, A.no_akaunwaris, B.desk_bank
					  FROM m_waris A
					  LEFT JOIN i_bank B ON B.id_bank = A.id_bankwaris
					  WHERE A.id_pemohon = ?
					  AND A.status = 1";
	$PDO_stmt = $PDO->prepare($indicator_Query);
	$PDO_stmt->bindValue(1, $indicator_List['m_pemohon']['id_pemohon'], PDO::PARAM_STR);
	$PDO_stmt->execute();
	$waris_List = $PDO_stmt->fetch(PDO::FETCH_ASSOC);

	$bank = $waris_List['nama_waris'].' ('.$waris_List['kpbaru_waris'].')';
	$no_akaun = $waris_List['desk_bank'].'<br>'.$waris_List['no_akaunwaris'];
	$kpdwaris = ' - MELALUI WARIS';
	$namabank = 'Waris';
	$noakaunbank = 'Nama & No. Akaun Bank';
}
		
$HTML = '<table border="0" style="width:100%;padding:0px;border:none;">';
$HTML .= '<tr>';
$HTML .= '<td style="text-align:left;border:none " colspan="2"><br><h3>Maklumat Akaun Bank (Pemilihan Kaedah Bayaran secara EFT'.$kpdwaris.')<br></h3></td>';
$HTML .= '</tr>';
$HTML .= '<tr>';
	$HTML .= '<td style="text-align:left;width:30%">
				'.$namabank.'<br>
				'.$noakaunbank.'<br>
			</td>';
	$HTML .= '<td style="text-align:left;width:5%">
				:<br>
				:<br>
			</td>';
	$HTML .= '<td style="text-align:left;width:65%">
				<b>'.$bank.'</b><br>
				<b>'.$no_akaun.'</b><br>
			</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:none;">';
$HTML .= '<tr class="border_bottom">';
$HTML .= '<td style="border-bottom: 1px solid black;"></td>';
$HTML .= '</tr>';
$HTML .= '<tr>';
$HTML .= '<td style="text-align:left;border-bottom: 1px solid black;">
			<b>PENGESAHAN AKAUN BANK PEMOHON (KAEDAH BAYARAN EFT)</b><br><br>Pemohon <b>DIWAJIBKAN</b> untuk menyertakan salinan pengesahan akaun bank/ penyata online/ penyata mini yang jelas memaparkan nombor akaun dan nama pemilik
			</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:5px;border:none;">';
$HTML .= '<tr>';
$HTML .= '<td style="text-align:left;border:none " colspan="2"><h3>Pengesahan Maklumat<br></h3></td>';
$HTML .= '</tr>';
$HTML .= '<tr>';
$HTML .= '<td style="text-align:justify;border:none " colspan="2">Saya telah menyemak maklumat akaun dan mengaku bahawa segala keterangan yang diberikan di atas adalah benar dan betul. Saya juga akan menyertakan salinan penyata akaun bank/ penyata online/ penyata mini yang jelas memaparkan nombor akaun dan nama saya / nama pemilik akaun bersama sebagai pengesahan kepada Pejabat Daerah secara emel berikutan Perintah Kawalan Pergerakan (PKP) yang sedang dilaksanakan.<br><br>Sila emel ke alamat emel berikut : <b>'.$indicator_List['m_pemohon']['emel_daerah'].'</b>
		</td>';
$HTML .= '</tr>';
$HTML .= '<tr>';
$HTML .= '<td style="text-align:left;width:50%">
			Nama : '.$indicator_List['m_pemohon']['nama_pemohon'].'<br>
			Tarikh : '.formatdate($dateTimeNow,'d M Y').'<br>
		</td>';
$HTML .= '</tr>';
$HTML .= '</table>';
$HTML .= '<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
//***********************************************************************************************************************

?>