<?php

include_once ("includes/setup.inc.php");

//***************************************************************
// THIS MUST HAVE 
// 1. $cutoff 
// 2. $cutoff_saheft 
// 3. $tahun_bayar 
//***************************************************************
function
$BELUM_BAYAR_EFT_FROM_QUERY = "
FROM m_pemohon A
LEFT JOIN i_dun ON A.id_dun = i_dun.id_dun 
LEFT JOIN i_daerah ON i_dun.id_daerah = i_daerah.id_daerah 
WHERE 
A.id_carabayar = 2 
AND A.id_statusmohon = 4 
AND A.id_statushidup = 1 
AND A.id_aktifmohon = 1 
AND A.tkh_sah <= '{$cutoff} 23:59:59'
AND A.tkh_saheft != '0000-00-00 00:00:00' 
AND A.tkh_saheft <= '{$cutoff_saheft} 00:00:00'
";

//to check inside all program
$PDO_stmt = $PDO->prepare("
	SELECT *
	FROM i_program
	WHERE aktif = 1
	AND id_program IN (1,2,3,4,7)
");
$PDO_stmt->execute();
while($res = $PDO_stmt->fetch(PDO::FETCH_ASSOC))
{
	$mbayar_table = "m_bayaran_".$res['kod_program'];
	$BELUM_BAYAR_EFT_FROM_QUERY .= ' AND A.id_pemohon NOT IN (SELECT id_pemohon FROM '.$mbayar_table.' WHERE tahun_bayar = '.$tahun_bayar.') ';
}

?>