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

$indicator_Query = "SELECT A.*
				  FROM i_statusmohon A
				  WHERE A.aktif = 1 AND id_statusmohon IN (2, 3, 4)
				  ORDER BY A.susunan";
$PDO_stmt = $PDO->prepare($indicator_Query);
$PDO_stmt->execute();
$statusMohonList = [];
while($result = $PDO_stmt->fetch(PDO::FETCH_ASSOC))
{
	$statusMohonList[] = $result;
}
$indicator_Query = "SELECT A.*
				  FROM i_program A
				  WHERE A.aktif = 1
				  AND A.id_program != 5
				  ORDER BY A.susunan";
$PDO_stmt = $PDO->prepare($indicator_Query);
$PDO_stmt->execute();
$programList = [];
while($result = $PDO_stmt->fetch(PDO::FETCH_ASSOC))
{
	$programList[] = $result;
}

for($num = 0; $num < count($programList); $num++)
{
	$displayList = [];
	for($mohonNum = 0; $mohonNum < count($statusMohonList); $mohonNum++)
	{
		$indicator_Query = "SELECT COUNT(A.id_pemohon) as bil
						  FROM m_pemohon A
						  WHERE A.id_statusmohon = ?
						  AND A.id_statushidup = 1
						  AND A.id_aktifmohon = 1
						  AND A.id_program = ?";
		$PDO_stmt = $PDO->prepare($indicator_Query); 
		$PDO_stmt->bindValue(1, $statusMohonList[$mohonNum]['id_statusmohon'], PDO::PARAM_INT);
		$PDO_stmt->bindValue(2, $programList[$num]['id_program'], PDO::PARAM_INT);
		$PDO_stmt->execute();
		$resultlist = $PDO_stmt->fetch(PDO::FETCH_ASSOC);
		$displayList[] = $resultlist['bil'].' '.$statusMohonList[$mohonNum]['desk_statusmohon'];
	}
	
	$indicator_Query = "SELECT COUNT(A.id_pemohon) as bil
					  FROM m_pemohon A
					  WHERE 
					  A.id_statusmohon = 4
					  AND A.id_carabayar = 2
					  AND A.flag_saheft = 0
					  AND A.id_statushidup = 1
					  AND A.id_aktifmohon = 1
					  AND A.id_program = ?";
	$PDO_stmt = $PDO->prepare($indicator_Query); 
	$PDO_stmt->bindValue(1, $programList[$num]['id_program'], PDO::PARAM_INT);
	$PDO_stmt->execute();
	$resultlist = $PDO_stmt->fetch(PDO::FETCH_ASSOC);
	if($programList[$num]['id_program'] != 4)
	{
		$displayList[] = $resultlist['bil'].' EFT BELUM DISAHKAN';
	}
	
	echo '<div class="d-flex align-items-center mb-9 bg-light-warning rounded p-5">';
		echo $Dashboard_svg;
		echo '<div class="d-flex flex-column flex-grow-1 mr-2">';
			echo '<a href="#" class="font-weight-bold text-dark-75 text-hover-primary font-size-lg mb-1">'.$programList[$num]['desk_program'].'</a>';
		echo '</div>';
		echo '<span class="font-weight-bolder text-warning py-1 font-size-lg">';
		echo join('<br>', $displayList);
		echo '</span>';
	echo '</div>';
}
?>