<?php

if($_COOKIE['sejahtera_role'] == 10)
{
	include_once ("includes/setup_pemohon.inc.php");
}
else
{
	include_once ("includes/setup.inc.php");
}
//*****************************************************
//Get all POST and GET value
//*****************************************************
$sqlOnly = fetch_postget_val('sqlOnly',$_POST, $_GET);
$dun_sc = fetch_postget_val('dun_sc',$_POST, $_GET);
$parlimen_sc = fetch_postget_val('parlimen_sc',$_POST, $_GET);
$daerah_sc = fetch_postget_val('daerah_sc',$_POST, $_GET);
$bangsa_sc = fetch_postget_val('bangsa_sc',$_POST, $_GET);
$poskod_sc = fetch_postget_val('poskod_sc',$_POST, $_GET);
$caramohon_sc = fetch_postget_val('caramohon_sc',$_POST, $_GET);
$carabayar_sc = fetch_postget_val('carabayar_sc',$_POST, $_GET);
$daftar_sc = fetch_postget_val('daftar_sc',$_POST, $_GET);
$terima_sc = fetch_postget_val('terima_sc',$_POST, $_GET);
$sah_sc = fetch_postget_val('sah_sc',$_POST, $_GET);
$pegawai_sc = fetch_postget_val('pegawai_sc',$_POST, $_GET);
$byrkepada_sc = fetch_postget_val('byrkepada_sc',$_POST, $_GET);
$saheft_sc = fetch_postget_val('saheft_sc',$_POST, $_GET);
$id_program = fetch_postget_val('program',$_POST, $_GET);
$flow_type = fetch_postget_val('flow_type',$_POST, $_GET);
$telahbayar_sc = fetch_postget_val('telahbayar_sc',$_POST, $_GET);
$orgtua_sc = fetch_postget_val('orgtua_sc',$_POST, $_GET);
$rmhorgtua_sc = fetch_postget_val('rmhorgtua_sc',$_POST, $_GET);
$tahun_sc = fetch_postget_val('tahun_sc',$_POST, $_GET);
$tahun_sah = fetch_postget_val('tahun_sah',$_POST, $_GET);
$bayaranfasa_sc = fetch_postget_val('bayaranfasa_sc',$_POST, $_GET);
$tkh_lbl = formatDate(fetch_postget_val("tkh_lbl", $_POST, $_GET), "Y-m-d");
$id_peranan = $my_details->user_level;
$name_id_program = $id_program;
if ($id_program < 10 && (!(substr($id_program, 0, 1) === '0')))
{
	$name_id_program = '0'.$id_program;
}

$id_statusmohon = 4;

//*****************************************************
// MAIN TABLE AND JOIN TABLE
// main = main table name in the database,
// sub['name'] = join table name
// sub['sub_id'] = join table identifier
// sub['main_id'] = main table identifier
// sub['main_name'] = main table name (optional), if no set, will use "main table name"
// sub['join_type'] = type of join. Default = 'LEFT'
// sub['aka'] = put alternative name for table
//*****************************************************
$tableArray = array(
	'main' => 'm_pemohon',
	'primary_key' => 'id_pemohon',
	'sub' => array(
		array('name' => 'i_caramohon', 'sub_id' => 'id_caramohon', 'main_id' => 'id_caramohon'),
		array('name' => 'i_carabayar', 'sub_id' => 'id_carabayar', 'main_id' => 'id_carabayar'),
		array('name' => 'i_statushidup', 'sub_id' => 'id_statushidup', 'main_id' => 'id_statushidup'),
		array('name' => 'i_statusmohon', 'sub_id' => 'id_statusmohon', 'main_id' => 'id_statusmohon'),
		array('name' => 'i_dun', 'sub_id' => 'id_dun', 'main_id' => 'id_dun'),
		array('name' => 'i_daerah', 'sub_id' => 'id_daerah', 'main_id' => 'id_daerah', 'main_name'=>'i_dun'),
		array('name' => 'i_parlimen', 'sub_id' => 'id_parlimen', 'main_id' => 'id_parlimen', 'main_name'=>'i_dun'),
		array('name' => 'i_poskod', 'sub_id' => 'id_poskod', 'main_id' => 'id_poskod'),
		array('name' => 'i_bank', 'sub_id' => 'id_bank', 'main_id' => 'id_bank'),
		array('name' => 't_pengguna', 'sub_id' => 'id_pengguna', 'main_id' => 'id_terima', 'aka' => 'peg_terima'),
		array('name' => 't_pengguna', 'sub_id' => 'id_pengguna', 'main_id' => 'id_sah', 'aka' => 'peg_sah'),
		array('name' => 't_pengguna', 'sub_id' => 'id_pengguna', 'main_id' => 'id_saheft'),
		array('name' => 'i_negeri', 'sub_id' => 'id_negeri', 'main_id' => 'id_negeri'),
	),
);

//*****************************************************
// DATATABLE COLUMN
// db = column name in the database,
// dt = DataTables column identifier
// table = database table name
// akaFrom = use if and only if there is aka name for table
//*****************************************************
$columns = array(
	array( 'bil_col' => '', 'dt' => 0),
	array( 'db' => 'nama_pemohon', 'dt' => 1, 'table' => 'm_pemohon' , 'print'=>1 ),
	array( 'db' => 'kpbaru_pemohon', 'dt' => 2, 'table' => 'm_pemohon' , 'print'=>1 ),
	//array( 'db' => 'tkh_sah', 'dt' => 3, 'table' => 'm_pemohon' , 'print'=>1 ),
	array( 'db' => 'tkh_sah', 'dt' => 3, 'table' => 'm_pemohon',
			'formatter' => function( $d, $row ) {
				
				return formatDate($d, 'd M Y');
			}, 'print'=>1 
	),
	array( 'db' => 'desk_caramohon', 'dt' => 4, 'table' => 'i_caramohon' , 'print'=>1 ),
	array( 'db' => 'desk_carabayar', 'dt' => 5, 'table' => 'i_carabayar' , 'print'=>1 ),
	array( 'dt' => 6, 'user_defined' => ''),
	array( 'db' => 'id_pemohon', 'dt' => 7, 'table' => 'm_pemohon' ),
	array( 'db' => 'id_dun', 'dt' => 8, 'table' => 'm_pemohon' ),
	array( 'db' => 'id_carabayar', 'dt' => 9, 'table' => 'm_pemohon' ),
	array( 'db' => 'id_caramohon', 'dt' => 10, 'table' => 'm_pemohon' ),
	array( 'db' => 'flag_saheft', 'dt' => 11, 'table' => 'm_pemohon' ),
	array( 'db' => 'id_statushidup', 'dt' => 12, 'table' => 'm_pemohon' ),
	array( 'db' => 'ulasan_terima', 'dt' => 13, 'table' => 'm_pemohon' ),
	array( 'db' => 'ulasan_sah', 'dt' => 14, 'table' => 'm_pemohon' ),
	array( 'db' => 'id_statusmohon', 'dt' => 15, 'table' => 'm_pemohon' ),
	array( 'db' => 'tkh_saheft', 'dt' => 16, 'table' => 'm_pemohon' ),
	array( 'db' => 'tel_hp', 'dt' => 17, 'table' => 'm_pemohon', 'print'=>1 ),
	array( 'db' => 'desk_dun', 'dt' => 18, 'table' => 'i_dun', 'print'=>1 ),
	array( 'db' => 'alamat', 'dt' => 19, 'table' => 'm_pemohon', 'print'=>1 ),
	array( 'db' => 'alamat2', 'dt' => 20, 'table' => 'm_pemohon', 'print'=>1 ),
	array( 'db' => 'alamat3', 'dt' => 21, 'table' => 'm_pemohon', 'print'=>1 ),
	array( 'db' => 'desk_poskod', 'dt' => 22, 'table' => 'i_poskod', 'print'=>1 ),
	array( 'db' => 'bandar', 'dt' => 23, 'table' => 'm_pemohon', 'print'=>1 ),
	array( 'db' => 'desk_negeri', 'dt' => 24, 'table' => 'i_negeri', 'print'=>1 ),
	array( 'db' => 'desk_bank', 'dt' => 25, 'table' => 'i_bank', 'print'=>1 ),
	array( 'db' => 'no_akaun', 'dt' => 26, 'table' => 'm_pemohon', 'print'=>1, 'isExplicit'=>1 ),
	array( 'db' => 'tkh_daftar', 'dt' => 27, 'table' => 'm_pemohon', 'print'=>1),
	array( 'db' => 'tkh_terima', 'dt' => 28, 'table' => 'm_pemohon', 'print'=>1),
	array( 'db' => 'peg_terimanama', 'dt' => 29, 'table' => 'peg_terima', 'akaFrom' => 'nama', 'print'=>1),
	array( 'db' => 'tkh_sah', 'dt' => 30, 'table' => 'm_pemohon', 'print'=>1),
	array( 'db' => 'peg_sahnama', 'dt' => 31, 'table' => 'peg_sah', 'akaFrom' => 'nama', 'print'=>1),
	array( 'db' => 'tkh_saheft', 'dt' => 32, 'table' => 'm_pemohon', 'print'=>1),
	array( 'db' => 'nama', 'dt' => 33, 'table' => 't_pengguna', 'print'=>1),
	array( 'db' => 'id_byrkepada', 'dt' => 34, 'table' => 'm_pemohon'),
);


//*****************************************************
// WHERE SQL
// Array ($table_name, $column_name, $value, $symbol(default : '='))
//*****************************************************
$whereArray = array(
	array('m_pemohon', 'id_program', $id_program),
	array('m_pemohon', 'id_statusmohon', $id_statusmohon),
	array('m_pemohon', 'id_statushidup', 1),
	array('m_pemohon', 'id_aktifmohon', 1),
);

if($dun_sc > 0)
{
	$whereArray[] = array('m_pemohon', 'id_dun', $dun_sc);
}

if($parlimen_sc > 0)
{
	$whereArray[] = array('i_parlimen', 'id_parlimen', $parlimen_sc);
}

if($daerah_sc > 0)
{
	//if($id_program == 4)
	//{
	//	$whereArray[] = array('m_pemohon', 'id_daerahOKU', $daerah_sc);
	//}
	//else
	//{
		$whereArray[] = array('i_daerah', 'id_daerah', $daerah_sc);
	//}
}

if($bangsa_sc == 1)
{
	$whereArray[] = array('m_pemohon', 'id_bangsa', 1);
}
else if($bangsa_sc == 2)
{
	$whereArray[] = array('m_pemohon', 'id_bangsa', 2);
}
else if($bangsa_sc == 3)
{
	$whereArray[] = array('m_pemohon', 'id_bangsa', 3);
}
else if($bangsa_sc == 5)
{	
	$whereArray[] = array(
		array('m_pemohon', 'id_bangsa', 0),
		array('m_pemohon', 'id_bangsa', 3, '>'),
	);
}

if($poskod_sc > 0)
{
	$whereArray[] = array('m_pemohon', 'id_poskod', $poskod_sc);
}

if($caramohon_sc > 0)
{
	$whereArray[] = array('m_pemohon', 'id_caramohon', $caramohon_sc);
}

if($carabayar_sc > 0)
{
	$whereArray[] = array('m_pemohon', 'id_carabayar', $carabayar_sc);
}

if($daftar_sc > 0)
{
	$whereArray[] = array('m_pemohon', 'id_daftar', $daftar_sc);
	$whereArray[] = array('m_pemohon', 'id_caramohon', 1);
}

if($terima_sc > 0)
{
	$whereArray[] = array('m_pemohon', 'id_terima', $terima_sc);
}

if($sah_sc > 0)
{
	$whereArray[] = array('m_pemohon', 'id_sah', $sah_sc);
}

if($pegawai_sc > 0)
{
	$whereArray[] = array('m_pemohon', 'id_saheft', $pegawai_sc);
}

if($pegawai_sc > 0)
{
	$whereArray[] = array('m_pemohon', 'id_saheft', $pegawai_sc);
}

if($tahun_sah > 0)
{
	$tahun_mula = $tahun_sah.'-01-01 00:00:00';
	$tahun_tamat = $tahun_sah.'-12-31 23:59:59';
	
	//$whereArray[] = array('m_pemohon', 'tkh_sah', '\''.$tahun_tamat.'\'',' BETWEEN \''.$tahun_mula.'\' AND '),
	//$whereArray[] = array('m_pemohon', 'tkh_sah', '\'%'.$tahun_sah.'\'%', 'LIKE'),
	$whereArray[] = array('m_pemohon', 'tkh_sah', '\'%'.$tahun_sah.'%\'', 'LIKE');
}

if($orgtua_sc == 1)
{
	$whereArray[] = array('m_pemohon', 'id_rumahorgtua', 0);
}
else if($orgtua_sc == 2)
{
	if($rmhorgtua_sc == 0)
	{
		$whereArray[] = array('m_pemohon', 'id_rumahorgtua', 0, '>');
	}
	else
	{
		$whereArray[] = array('m_pemohon', 'id_rumahorgtua', $rmhorgtua_sc);		
	}
}

if($byrkepada_sc > 0)
{
	$whereArray[] = array('m_pemohon', 'id_byrkepada', $byrkepada_sc);
}

if($saheft_sc == 1)
{
	//$whereArray[] = array('m_pemohon', 'id_carabayar', 2);
	$whereArray[] = array('m_pemohon', 'flag_saheft', 0);
}
else if($saheft_sc == 2)
{
	//$whereArray[] = array('m_pemohon', 'id_carabayar', 2);
	$whereArray[] = array('m_pemohon', 'flag_saheft', 1);
}

if($telahbayar_sc == 1 && $tahun_sc > 0) //belum bayar tunai
{
	$indicator_Query = "SELECT A.*
					  FROM i_kawalan A
					  WHERE A.id_program = ?";
	$PDO_stmt = $PDO->prepare($indicator_Query);
	$PDO_stmt->bindValue(1, $id_program, PDO::PARAM_INT);
	$PDO_stmt->execute();
	$kawalan_List = $PDO_stmt->fetch(PDO::FETCH_ASSOC);	
	
	$cutoff = $kawalan_List['tkh_cutoff_tunai'];
	$cutoff_saheft = $kawalan_List['tkh_cutoff_sah_EFT'];
	$cutoff_aktif = $kawalan_List['tkh_cutoff_aktifmohon'];
	if($my_details->user_level <= 3)
	{
		//$cutoff = $tkh_lbl;								
	}
	
	if($id_program != 4)
	{
		$whereArray[] = array('m_pemohon', 'id_dun', 0, '!=');
	}
	$whereArray[] = array('m_pemohon', 'id_rumahorgtua', 0);
	$whereArray[] = array(
						array('m_pemohon', 'tkh_aktifmohon', "'0000-00-00 00:00:00'"),
						array('m_pemohon', 'tkh_aktifmohon', "'".$cutoff_aktif." 23:59:59'", '<=')
						);
	$whereArray[] = array('m_pemohon', 'tkh_sah', "'".$cutoff." 23:59:59'", '<=');
	$whereArray[] = array(
						array('m_pemohon', 'tkh_saheft', "'0000-00-00 00:00:00'"),
						array('m_pemohon', 'tkh_saheft', "'".$cutoff_saheft." 23:59:59'", '>')
						);
	
	//to check inside all program
	/*$PDO_stmt = $PDO->prepare("
		SELECT *
		FROM i_program
		WHERE aktif = 1
		AND id_program IN (1,2,4,7)
	");
	$PDO_stmt->execute();
	while($res = $PDO_stmt->fetch(PDO::FETCH_ASSOC))
	{
		$mbayar_table = "m_bayaran_".$res['kod_program'];
		$whereArray[] = array('m_pemohon', 'id_pemohon', ' (SELECT id_pemohon FROM '.$mbayar_table.' WHERE tahun_bayar = '.$tahun_sc.') ', 'NOT IN');
	}*/
	
	$whereArray[] = array('m_pemohon', 'id_pemohon', ' (SELECT id_pemohon FROM l_penerima) ', 'NOT IN');
}
else if($telahbayar_sc == 2 && $tahun_sc > 0) //belum bayar eft
{
	$indicator_Query = "SELECT A.*
					  FROM i_kawalan A
					  WHERE A.id_program = ?";
	$PDO_stmt = $PDO->prepare($indicator_Query);
	$PDO_stmt->bindValue(1, $id_program, PDO::PARAM_INT);
	$PDO_stmt->execute();
	$kawalan_List = $PDO_stmt->fetch(PDO::FETCH_ASSOC);	
	
	$cutoff = $kawalan_List['tkh_cutoff_tunai'];
	$cutoff_saheft = $kawalan_List['tkh_cutoff_sah_EFT'];
	$cutoff_aktif = $kawalan_List['tkh_cutoff_aktifmohon'];
	if($my_details->user_level <= 3)
	{
		//$cutoff = $tkh_lbl;								
	}
	
	if($id_program != 4)
	{
		$whereArray[] = array('m_pemohon', 'id_dun', 0, '!=');
	}
	$whereArray[] = array('m_pemohon', 'id_rumahorgtua', 0);
	//$whereArray[] = array('m_pemohon', 'id_carabayar', 2);
	$whereArray[] = array(
						array('m_pemohon', 'id_carabayar', 2),
						array('m_pemohon', 'id_byrkepada', 2)
						);
	$whereArray[] = array(
						array('m_pemohon', 'tkh_aktifmohon', "'0000-00-00 00:00:00'"),
						array('m_pemohon', 'tkh_aktifmohon', "'".$cutoff_aktif." 23:59:59'", '<=')
						);
	$whereArray[] = array('m_pemohon', 'tkh_sah', "'".$cutoff." 23:59:59'", '<=');
	$whereArray[] = array('m_pemohon', 'tkh_saheft', "'0000-00-00 00:00:00'", '!=');
	$whereArray[] = array('m_pemohon', 'tkh_saheft', "'".$cutoff_saheft." 23:59:59'", '<=');
	
	//to check inside all program
	/*$PDO_stmt = $PDO->prepare("
		SELECT *
		FROM i_program
		WHERE aktif = 1
		AND id_program IN (1,2,4,7)
	");
	$PDO_stmt->execute();
	while($res = $PDO_stmt->fetch(PDO::FETCH_ASSOC))
	{
		$mbayar_table = "m_bayaran_".$res['kod_program'];
		$whereArray[] = array('m_pemohon', 'id_pemohon', ' (SELECT id_pemohon FROM '.$mbayar_table.' WHERE tahun_bayar = '.$tahun_sc.') ', 'NOT IN');
	}*/
	
	$whereArray[] = array('m_pemohon', 'id_pemohon', ' (SELECT id_pemohon FROM l_penerima) ', 'NOT IN');
}
else if($telahbayar_sc == 4 && $tahun_sc > 0) //belum bayar oku
{
	$whereArray[] = array('m_pemohon', 'id_dun', 0, '!=');	
	$whereArray[] = array('m_pemohon', 'id_pemohon', ' (SELECT id_pemohon FROM l_penerima) ', 'NOT IN');
}
else if($telahbayar_sc == 3 && $tahun_sc > 0) //telah bayar
{
	/*$PDO_stmt = $PDO->prepare("
		SELECT *
		FROM i_program
		WHERE id_program = ? 
		AND id_program IN (1,2,3,4,7)
	");
	$PDO_stmt->bindValue(1, $id_program, PDO::PARAM_INT);
	$PDO_stmt->execute();
	$program_List = $PDO_stmt->fetch(PDO::FETCH_ASSOC);

	$mbayar_table = "m_bayaran_".$program_List['kod_program'];
	
	$definefasa = '';
	if($bayaranfasa_sc > 0) //telah bayar
	{
		$definefasa = 'AND id_bayaranfasa = '.$bayaranfasa_sc;
	}
	
	$whereArray[] = array('m_pemohon', 'id_pemohon', ' (SELECT id_pemohon FROM '.$mbayar_table.' WHERE tahun_bayar = '.$tahun_sc.' '.$definefasa.') ', 'IN');*/	
	$whereArray[] = array('m_pemohon', 'id_pemohon', ' (SELECT id_pemohon FROM l_penerima) ', 'IN');
}

//echo SSP::myComplex($_POST, $sql_details, buildSelectQuery($columns), buildFromQuery($tableArray), $tableArray['main'].'.'.$tableArray['primary_key'], $columns, 1, buildWhereQuery($whereArray));
//echo "whereArray = ".count($whereArray);
//exit(0);
//*****************************************************
// SSP GET JSON
// No need to modify below
//*****************************************************
if($sqlOnly == 1)
{
	//LEAVE EMPTY FOR FUTURE USAGE 
}
else
{	
	$temp_result = SSP::myComplex($_POST, $sql_details, buildSelectQuery($columns), buildFromQuery($tableArray), $tableArray['main'].'.'.$tableArray['primary_key'], $columns, 0, buildWhereQuery($whereArray));
	for($num = 0; $num < count($temp_result['data']); $num++)
	{
		$start_index = 7;
		$id_pemohon = $temp_result['data'][$num][$start_index];	
		$id_dun = $temp_result['data'][$num][$start_index + 1];
		$id_carabayar = $temp_result['data'][$num][$start_index + 2];
		$id_caramohon = $temp_result['data'][$num][$start_index + 3];
		$flag_saheft = $temp_result['data'][$num][$start_index + 4];
		$id_statushidup = $temp_result['data'][$num][$start_index + 5];
		$ulasan_terima = $temp_result['data'][$num][$start_index + 6];
		$ulasan_sah = $temp_result['data'][$num][$start_index + 7];
		$id_statusmohon = $temp_result['data'][$num][$start_index + 8];
		$tkh_saheft = $temp_result['data'][$num][$start_index + 9];
		$bank = $temp_result['data'][$num][$start_index + 18];
		$no_akaun = $temp_result['data'][$num][$start_index + 19];
		$id_byrkepada = $temp_result['data'][$num][$start_index + 27];
				
		$temp_result['data'][$num][1] = '<a href="javascript:;" onclick="loadMyModal(\'general-maklumat.php?id='.$id_pemohon.'&program='.$id_program.'\', \'#ajax-modal\')" title="Maklumat Pemohon">'.$temp_result['data'][$num][1].'</a>';
		
		$temp_result['data'][$num][$start_index + 12] = $temp_result['data'][$num][$start_index + 12].$temp_result['data'][$num][$start_index + 13].$temp_result['data'][$num][$start_index + 14].$temp_result['data'][$num][$start_index + 15].$temp_result['data'][$num][$start_index + 16].$temp_result['data'][$num][$start_index + 17];
		
		$terima_btn = '';
		if($my_details->user_level <= 4 || $my_details->user_level == 6 || $my_details->user_level == 15 || $my_details->user_level == 8)
		{
			$terima_btn = '<a class="btn btn-sm btn-default btn-text-primary btn-hover-primary btn-icon mr-2" onclick="loadMyModal(\'general-terima_tind.php?id='.$id_pemohon.'&program='.$id_program.'\', \'#ajax-modal\')" title="Terima Dokumen"><span class="svg-icon svg-icon-primary svg-icon-2x">'.$Check_svg.'</span></a>';
		}
		
		$sah_btn = '';
		if($my_details->user_level == 1 || $my_details->user_level == 3 || $my_details->user_level == 5 || $my_details->user_level == 7 || $my_details->user_level == 16 || $my_details->user_level == 9)
		{
			$sah_btn = '<a class="btn btn-sm btn-default btn-text-primary btn-hover-primary btn-icon mr-2" onclick="loadMyModal(\'general-sah_tind.php?id='.$id_pemohon.'&program='.$id_program.'\', \'#ajax-modal\')" title="Pengesahan Permohonan"><span class="svg-icon svg-icon-primary svg-icon-2x">'.$Check_svg.'</span></a>';
		}
		
		$sah_eft = '';
		if($my_details->user_level <= 5)
		{
			$sah_eft = '<a class="btn btn-sm btn-default btn-text-primary btn-hover-primary btn-icon mr-2" onclick="loadMyModal(\'general-sah_eft.php?id='.$id_pemohon.'&program='.$id_program.'\', \'#ajax-modal\')" title="Pengesahan EFT"><span class="svg-icon svg-icon-primary svg-icon-2x">'.$Check_svg.'</span></a>';
		}
		
		$log_btn = '<a class="btn btn-sm btn-default btn-text-primary btn-hover-primary btn-icon mr-2" onclick="loadMyModal(\'general-log.php?id='.$id_pemohon.'\', \'#ajax-modal\')" title="Log Permohonan"><span class="svg-icon svg-icon-primary svg-icon-2x">'.$Log_svg.'</span></a>';
		
		$papar_btn = '<a class="btn btn-sm btn-default btn-text-primary btn-hover-primary btn-icon mr-2" onclick="paparBorang('.$id_pemohon.', \''.$name_id_program.'\')" title="Papar"><span class="svg-icon svg-icon-primary svg-icon-2x">'.$File_svg.'</span></a>';
		
		$kemaskini_btn = '';
		//$kemaskini_btn = '<a class="btn btn-sm btn-default btn-text-primary btn-hover-primary btn-icon mr-2" onclick="editBorang('.$id_pemohon.', \''.$name_id_program.'\')" title="Kemaskini"><span class="svg-icon svg-icon-primary svg-icon-2x">'.$Edit_svg.'</span></a>';
		
		//only show + button if single daerah, tahun & fasa
		$tambah_btn = '';
		if(((($telahbayar_sc == 1 && $tahun_sc > 0 && $dun_sc > 0 && $flag_saheft == 0) || ($telahbayar_sc == 1 && $tahun_sc > 0 && $orgtua_sc == 2)) && $my_details->user_level <= 5) || ($telahbayar_sc == 4 && $id_program == 4 && ($my_details->user_level = 1 || $my_details->user_level = 8 || $my_details->user_level = 9)))
		{
			$tambah_btn = '<a class="btn btn-sm btn-default btn-text-primary btn-hover-primary btn-icon mr-2" id="tambahBtn_'.$id_pemohon.'" onclick="tambah(this, '.$id_pemohon.', 0)" title="Tambah"><span class="svg-icon svg-icon-success svg-icon-2x">'.$Plus_svg.'</span></a>';
		}
		
		if($id_byrkepada == 2)
		{
			$indicator_Query = "SELECT A.nama_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, $id_pemohon, PDO::PARAM_STR);
			$PDO_stmt->execute();
			$waris_List = $PDO_stmt->fetch(PDO::FETCH_ASSOC);

			$bank = 'WARIS - '.$waris_List['desk_bank'];
			$no_akaun = $waris_List['no_akaunwaris'];
		}
		
		$eftstatus = '';
		if(($id_carabayar == 2 || $id_byrkepada == 2) && $flag_saheft == 0)
		{
			if($id_program != 4)
			{
				$eftstatus = ' - <b>BELUM DISAHKAN</b><br>'.$bank.'<br>'.$no_akaun;
			}
			$paparcarabayar = $temp_result['data'][$num][5].$eftstatus;
		}
		else if(($id_carabayar == 2 || $id_byrkepada == 2) && $flag_saheft == 1)
		{	
			if($id_program != 4)
			{	
				//$eftstatus = '<br>TELAH DISAHKAN';	
				$eftstatus = '<br>'.$bank.'<br>'.$no_akaun;	
			}
			$sah_eft = '';
			$paparcarabayar = $temp_result['data'][$num][5].$eftstatus;
		}
		else if($id_carabayar == 1)
		{				
			$sah_eft = '';
			$paparcarabayar = $temp_result['data'][$num][5];
		}
				
		if($id_program == 4)
		{			
			$sah_eft = '';
		}
		$temp_result['data'][$num][$start_index - 1] = $sah_eft.$log_btn.$kemaskini_btn.$tambah_btn;	
		
		$temp_result['data'][$num][5] = $paparcarabayar;
	
	}
	echo json_encode(
		$temp_result
	);
}
?>