      
<?php
include '../../../config/koneksi.php';
session_start();
?>
<!DOCTYPE html>
<html>
   
   
    <head>
        <script src="ambildata.js"></script>
        <script src="efekscrol.js"></script>
        <title>Halaman OPD</title>

     
    </head>
    <body>
   
    <div class="content-wrapper">
   
            
        <div class ="wrapper">
        <div class="panel-body"  style ="overflow-x :auto ; overflow-y :auto ">
            

<table width="100%"  id="example1s" class="table table-bordered table-striped">
<thead>
       <tr style="text-align:center ; background-color:lightgrey" >
       <th style="text-align:center ;vertical-align: middle;"  >No</th>
       <th style="text-align:center ;vertical-align: middle;"  >Kode </th>
       <th style="text-align:center ;vertical-align: middle;"   >SKPD</th>
       <th style="text-align:center ;vertical-align: middle;"   >Jumlah <br>Program</th>
       <th style="text-align:center ;vertical-align: middle;"   >Jumlah <br>Kegiatan</th>
       <th style="text-align:center ;vertical-align: middle;"   >Jumlah <br>Sub Kegiatan</th>
      
       <th style="text-align:center ;vertical-align: middle;"  >Pagu </th>
       <?php

$sqlsdh  = mysqli_query($koneksi, "SELECT 
  sumber_dana from renja 
  group by sumber_dana
  order by sumber_dana
    ");
foreach ($sqlsdh as $rowsdh) {


    ?>
 <th style="text-align:center ;vertical-align: middle;"  ><?php echo $rowsdh['sumber_dana'] ?></th>
    <?php
}
    ?>
       </tr>
       </thead>
       <tbody>
<?php
$no=1;
$sqlskpd  = mysqli_query($koneksi, "SELECT 
 a.kode_sub_skpd,a.sub_skpd,jml.total,p.jp,k.jk,sk.jsk
  from((((( sub_skpd as a)
 left join
 (select kode_sub_skpd, count(distinct kode_program) as jp from renja group by kode_sub_skpd) as p on p.kode_sub_skpd=a.kode_sub_skpd)
 left join
 (select kode_sub_skpd, count(distinct kode_kegiatan) as jk from renja group by kode_sub_skpd) as k on k.kode_sub_skpd=a.kode_sub_skpd)
 left join
 (select kode_sub_skpd, count(distinct kode_sub_kegiatan) as jsk from renja group by kode_sub_skpd) as sk on sk.kode_sub_skpd=a.kode_sub_skpd)
 left join 
 (select kode_sub_skpd , sum(rincian) as total from renja group by kode_sub_skpd)as jml on jml.kode_sub_skpd=a.kode_sub_skpd)
  
    ");
foreach ($sqlskpd as $rowskpd) {
   ?>
   <tr>
        <td><?php echo($no++) ?></td>
       <td><?php echo $rowskpd['kode_sub_skpd']  ?></td>
       <td><?php echo $rowskpd['sub_skpd']  ?></td>
       <td style="text-align:right;vertical-align: middle;"><?php echo ($rowskpd['jp']) ?></td>
       <td style="text-align:right;vertical-align: middle;"><?php echo ($rowskpd['jk']) ?></td>
       <td style="text-align:right;vertical-align: middle;"><?php echo ($rowskpd['jsk']) ?></td>
       <td style="text-align:right;vertical-align: middle;"><?php echo ($rowskpd['total']) ?></td>

      <?php

$sqlsd  = mysqli_query($koneksi, "SELECT 
  a.sumber_dana,sd.totrinc from(( renja as a)
  left join 
  (select kode_sub_skpd,sumber_dana, sum(rincian) as totrinc from renja where kode_sub_skpd='$rowskpd[kode_sub_skpd]' group by kode_sub_skpd,sumber_dana) as sd on sd.sumber_dana=a.sumber_dana)
  
  group by a.sumber_dana,sd.totrinc
  order by a.sumber_dana
    ");
foreach ($sqlsd as $rowsd) {


    ?>
 <td style="text-align:right ;vertical-align: middle;"  ><?php echo ($rowsd['totrinc']) ?></td>
    <?php
}
    ?>

   </tr>


    <?php
}

    ?>
       <tr>
    <td></td>
    <td>- T O T A L -</td>
     <td style="text-align:right ;vertical-align: middle;"  >
         <?php

$sqlskpdd  = mysqli_query($koneksi, "SELECT 
  count(distinct a.kode_sub_skpd) as tpr2
  from renja as a inner join sub_skpd as b on a.kode_sub_skpd=b.kode_sub_skpd
  
  
    ");
foreach ($sqlskpdd as $rowskpdd) {


    ?>
 <strong><?php echo ($rowskpdd['tpr2']) ?></strong>
    <?php

}
    ?>
  </td>
    <td style="text-align:right ;vertical-align: middle;"  >
         <?php

$sqlspr  = mysqli_query($koneksi, "SELECT 
  count(distinct kode_program) as tpr2
  from renja as a inner join sub_skpd as b on a.kode_sub_skpd=b.kode_sub_skpd
  
  
    ");
foreach ($sqlspr as $rowpr) {


    ?>
 <strong><?php echo ($rowpr['tpr2']) ?></strong>
    <?php

}
    ?>
  </td>
   <td style="text-align:right ;vertical-align: middle;"  >
         <?php

$sqltkeg  = mysqli_query($koneksi, "SELECT 
  count(distinct kode_kegiatan) as tpr2
  from renja as a
  
  
    ");
foreach ($sqltkeg as $rowkeg) {


    ?>
 <strong><?php echo ($rowkeg['tpr2']) ?></strong>
    <?php

}
    ?>
  </td>
   <td style="text-align:right ;vertical-align: middle;"  >
         <?php

$sqltskeg  = mysqli_query($koneksi, "SELECT 
  count(distinct kode_sub_kegiatan) as tpr2
  from renja as a
  
  
    ");
foreach ($sqltskeg as $rowskeg) {


    ?>
 <strong><?php echo ($rowskeg['tpr2']) ?></strong>
    <?php

}
    ?>
  </td>
     <td style="text-align:right ;vertical-align: middle;"  >
         <?php

$sqltotpag  = mysqli_query($koneksi, "SELECT 
  sum(rincian) as tpr2
  from renja as a
  
  
    ");
foreach ($sqltotpag as $rowtotpag) {


    ?>
 <strong><?php echo ($rowtotpag['tpr2']) ?></strong>
    <?php

}
    ?>
  </td>
      <?php

$sqlsdt  = mysqli_query($koneksi, "SELECT 
  a.sumber_dana,sd.totrinc
  from(( renja as a)
  left join 
  (select sumber_dana, sum(rincian) as totrinc from renja  group by sumber_dana) as sd on sd.sumber_dana=a.sumber_dana)
  
  group by a.sumber_dana,sd.totrinc
  order by a.sumber_dana
    ");
foreach ($sqlsdt as $rowsdt) {


    ?>
    <td style="text-align:right ;vertical-align: middle;"  ><strong><?php echo ($rowsdt['totrinc']) ?></strong></td>
    <?php

}
    ?>

   </tr>
</tbody>
</table>
 
</body>
</html>