<?php 
$sql = "select KDOUTPUT, sum(TOTNILMAK) as real_output from {$table} WHERE THANG='{$th}' and KDSATKER='{$kdsatker}' and KDGIAT='{$kdgiat}' and KDOUTPUT = '{$kdoutput}' group by KDOUTPUT order by KDOUTPUT";
$aOutput = mysql_query($sql);
while ($Output = mysql_fetch_array($aOutput)) {
    ?>
    <tr class="<?php 
    echo $class;
    ?>
"> 
      <td align="center"><font color="#FF0000"><?php 
    echo $kdgiat . '.' . $Output['KDOUTPUT'];
    ?>
</font></td>
      <td colspan="5" align="left"><font color="#FF0000"><?php 
    echo nm_output_th($th, $kdgiat . $kdoutput);
    ?>
&nbsp;</font></td>
      <td align="right"><font color="#FF0000"><?php 
    echo number_format($Output['real_output'], "0", ",", ".");
    ?>
</font></td>
    </tr>
    <?php 
    $sql = "select NOSPM,TGSPM,NOSP2D,TGSP2D, sum(TOTNILMAK) as real_spm from {$table} WHERE THANG='{$th}' and KDSATKER='{$kdsatker}' and KDOUTPUT='{$kdoutput}' group by concat(NOSPM,NOSP2D) order by NOSPM,TGSPM";
    $aSPM = mysql_query($sql);
    while ($SPM = mysql_fetch_array($aSPM)) {
        ?>
    <tr class="<?php 
        echo $class;
        ?>
    $aGiat = mysql_query($sql);
    $Giat = mysql_fetch_array($aGiat);
    $sql = "select kdoutput, sum(totnilmak) as real_output from {$table_1} WHERE thang='{$th}' and kdsatker='{$kdsatker}' and kdgiat='{$kdgiat}' group by kdoutput order by kdoutput";
    $aOutput = mysql_query($sql);
    while ($Output = mysql_fetch_array($aOutput)) {
        ?>
    <tr class="<?php 
        echo $class;
        ?>
"> 
      <td align="center"><font color="#FF0000"><?php 
        echo $kdgiat . '.' . $Output['kdoutput'];
        ?>
</font></td>
      <td colspan="3" align="left"><font color="#FF0000"><?php 
        echo nm_output_th($th, $kdgiat . $Output['kdoutput']);
        ?>
&nbsp;</font></td>
      <td align="right"><font color="#FF0000"><?php 
        echo number_format($Output['real_output'], "0", ",", ".");
        ?>
</font></td>
    </tr>
    <?php 
        $sql = "select nospm,tgspm, sum(totnilmak) as real_spm from {$table_1} WHERE thang = '{$th}' and kdsatker = '{$kdsatker}' and kdoutput = '{$Output['kdoutput']}' group by nospm order by nospm ";
        $aSPM = mysql_query($sql);
        while ($SPM = mysql_fetch_array($aSPM)) {
            ?>
    <tr class="<?php 
            echo $class;
            ?>
            $sql = "select KDOUTPUT, sum(JUMLAH) as pagu_output from d_item WHERE KDDEPT = '{$kddept}' AND KDUNIT = '{$kdunit}' AND THANG = '{$th}' and KDSATKER = '{$kdsatker}' AND KDGIAT = '{$Giat['KDGIAT']}' GROUP BY KDOUTPUT ORDER BY KDOUTPUT";
            $aOutput = mysql_query($sql);
            while ($Output = mysql_fetch_array($aOutput)) {
                $real_output_spm = real_output_spm($th, $kdsatker, $Giat['KDGIAT'], $Output['KDOUTPUT']);
                $real_output_sp2d = real_output_sp2d($th, $kdsatker, $Giat['KDGIAT'], $Output['KDOUTPUT']);
                ?>
    <tr class="<?php 
                echo $class;
                ?>
">
      <td align="center" valign="top"><font color="#993333"><?php 
                echo $Output['KDOUTPUT'];
                ?>
</font></td>
      <td align="left" valign="top"><font color="#993333"><?php 
                echo nm_output_th($th, $Giat['KDGIAT'] . $Output['KDOUTPUT']);
                ?>
</font></td>
      <td align="right" valign="top"><font color="#993333"><?php 
                echo number_format($Output['pagu_output'], "0", ",", ".");
                ?>
</font></td>
      <td align="right" valign="top"><font color="#993333"><?php 
                echo number_format($real_output_spm, "0", ",", ".");
                ?>
		<?php 
                if ($real_output_spm != 0) {
                    ?>
		<br>
		<a href="index.php?p=627&kdsatker=<?php 
                    echo $kdsatker;
    </tr>
    <?php 
$sql = "select KDOUTPUT, sum(JUMLAH) as pagu_output, sum(RPHBLOKIR) as blokir_output from {$table} WHERE THANG='{$th}' and KDSATKER='{$kdsatker}' and KDGIAT='{$kdgiat}' group by KDOUTPUT";
$aOutput = mysql_query($sql);
while ($Output = mysql_fetch_array($aOutput)) {
    ?>
    <tr class="<?php 
    echo $class;
    ?>
"> 
      <td align="center"><font color="#FF0000"><?php 
    echo $Output['KDOUTPUT'];
    ?>
</font></td>
      <td colspan="2" align="left"><font color="#FF0000"><?php 
    echo nm_output_th($th, $kdgiat . $Output['KDOUTPUT']);
    ?>
&nbsp;</font></td>
      <td align="right"><font color="#FF0000"><?php 
    echo number_format($Output['pagu_output'], "0", ",", ".");
    ?>
</font></td>
      <td align="right"><font color="#FF0000"><?php 
    echo number_format($Output['blokir_output'], "0", ",", ".");
    ?>
</font></td>
    </tr>
    <?php 
    $sql = "select KDSOUTPUT, sum(JUMLAH) as pagu_soutput, sum(RPHBLOKIR) as blokir_soutput from {$table} WHERE THANG='{$th}' and KDSATKER='{$kdsatker}' and KDGIAT='{$kdgiat}' and KDOUTPUT='{$Output['KDOUTPUT']}' group by KDSOUTPUT";
    $aSOutput = mysql_query($sql);
    while ($SOutput = mysql_fetch_array($aSOutput)) {
}
?>

<table width="551" cellspacing="1" class="admintable">
	
	<tr>
		<td width="115" class="key">Kegiatan</td>
		<td width="427"><textarea name="" cols="70" rows="2" readonly><?php 
echo nm_giat($value[3]);
?>
</textarea></td>
	</tr>
	<tr>
		<td class="key">Output</td>
		<td><textarea readonly="readonly" cols="70" rows="3"><?php 
echo nm_output_th($value[1], $value[3] . $value[4]);
?>
</textarea></td>
	</tr>
	
	<tr>
		<td>&nbsp;</td>
		<td>
			<form name="form" method="post" action="index.php?p=<?php 
echo $_GET['p'];
?>
">				
				<div class="button2-right">
					<div class="prev">
						<a onclick="Back('index.php?p=<?php 
echo $p_next;
        }
        ?>
				<tr class="<?php 
        echo $class;
        ?>
">
					<td align="center"><?php 
        echo $k + 1;
        ?>
</td>
					<td align="center"><?php 
        echo $col[1][$k];
        ?>
</td>
					<td align="left"><?php 
        echo nm_output_th($th, $kdgiat . $col[1][$k]);
        ?>
</td>
					<td align="center"><?php 
        echo $col[2][$k] . ' ' . sat_output_th($th, $kdgiat . $col[1][$k]);
        ?>
</td>
					<td align="right"><?php 
        echo number_format($col[4][$k], "0", ",", ".");
        ?>
</td>
					<td align="center" valign="top">
						<a href="index.php?p=453&u=<?php 
        echo $u;
        ?>
&g=<?php