      
<?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 ">
              
     <button onclick="excelcetak()" class="fas fa-file-excel bg-green btn" style="border-radius: 14px;float: right;"> Excel</button>
       <?php


$sqlsskpd  = mysqli_query($koneksi, "SELECT kode_sub_skpd, sub_skpd from sub_skpd
    ");
foreach ($sqlsskpd as $rowsskpd) {

    ?>
             <strong><?php echo $rowsskpd['kode_sub_skpd'] . ' '. $rowsskpd['sub_skpd']?></strong>


<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;"  >Kode </th>
       <th colspan="7" style="text-align:center ;vertical-align: middle;"   >Urusan/SKPD/Sub SKPD/Bidang/program/Kegiatan/Sub_Kegiatan <br>/Akun</th>
      
       <th style="text-align:center ;vertical-align: middle;"  >Jumlah </th>


  <?php
    $sqlsub = mysqli_query($koneksi, "SELECT 
    e.kode_sub_kegiatan,e.sub_kegiatan,
    i.sumber_dana,
    sum(i.rincian) as sumber,
    count(distinct a.kode_urusan)as cu,
    count(distinct b.kode_bidang_urusan)as cb,
    count(distinct c.kode_program)as cp,
    count(distinct d.kode_kegiatan)as ck,
    count(distinct e.kode_sub_kegiatan)as cs,
    count(distinct f.id_renja)as cr,
    sum(f.rincian) as total
  
    from urusan as a
    inner join bidang_urusan as b on a.kode_urusan=b.kode_urusan
    inner join program as c on b.kode_bidang_urusan=c.kode_bidang_urusan
    inner join kegiatan as d on c.kode_program=d.kode_program
    inner join sub_kegiatan as e on d.kode_kegiatan=e.kode_kegiatan
    inner join renja as f on e.kode_sub_kegiatan=f.kode_sub_kegiatan
    inner join sub_skpd as g on f.kode_sub_skpd=g.kode_sub_skpd
    inner join skpd as h on g.kode_skpd=h.kode_skpd
    inner join renja as i on f.kode_sub_skpd=i.kode_skpd and f.kode_sub_kegiatan=i.kode_sub_kegiatan
    
    group by e.kode_sub_kegiatan,e.sib_kegiatan,i.sumber_dana
    order by e.kode_sub_kegiatan
    ");
foreach ($sqlsub as $rowsub) {

    ?>
    <tr>
        <td><?php echo $rowsub["kode_sub_kegiatan"]; ?></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        
<td><?php echo $rowsub["sub_kegiatan"]; ?></td>
<td><?php echo $rowsub["sumber_dana"]; ?></td>
<td style="text-align:right;"><?php echo number_format($rowsub["sumber"],2); ?></td>
</tr>
   
     
        <?php
 
    
    
}

?>




 </tbody>
  </table>
  <table style="width:35%"  class="table table-bordered table-striped">
    <th style="text-align:center">Sumber Dana</th>
    <th style="text-align:center">Total</th>

      <?php

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

    ?>
    <tr>
        <td style="text-align:right;"><strong><?php echo ($rowsumber_dana['sumber_dana']); ?></strong> </td>
<td style="text-align:right;"><strong><?php echo number_format($rowsumber_dana['sumber']); ?></strong> </td>
     </tr>
     <?php
 }
     ?>

           <?php

$sqlsumberdanatot  = mysqli_query($koneksi, "SELECT 
     sum(a.rincian) as sumber from
      renja as a
  
      where a.kode_sub_skpd='$rowsskpd[kode_sub_skpd]' 
  group by a.kode_sub_skpd
  
   
    ");
foreach ($sqlsumberdanatot as $rowsumber_danatot) {

    ?>
    <tr>
        <td style="text-align:center;"><strong>Total<br><hr></strong> </td>
<td style="text-align:right;"><strong><?php echo number_format($rowsumber_danatot['sumber']); ?><br><hr></strong> </td>
     </tr>
     <?php
 }
     ?>
  </table>
<br>
<br>

<?php
}
mysqli_close($koneksi);
?> 
  
          <script>
              $(document).ready(function () {
                 $(".selubah").on('click', function () {
                    
                    var currentRow = $(this).closest("tr");
              
                      var col0 = currentRow.find("td:eq(0)").html();
                      var col1 = currentRow.find("td:eq(1)").html();
                      var col2 = currentRow.find("td:eq(2)").html();
                      var col3 = currentRow.find("td:eq(3)").html();
                      
                      col1 = col1.replace(/^\s+|\s+$/g, '');
                      col2 = col2.replace(/^\s+|\s+$/g, '');
                      col3 = col3.replace(/^\s+|\s+$/g, '');
                     
                      
                    
                      $("#id_opdu").val(col1);
                      $("#kode_opdu").val(col2);
                      $("#opdu").val(col3);
                     

                      
                          });
                
                  $(".selhapus").on('click', function () {
                    var currentRow = $(this).closest("tr");
                       var col0 = currentRow.find("td:eq(0)").html();
                      var col1 = currentRow.find("td:eq(1)").html();
                      var col2 = currentRow.find("td:eq(2)").html();
                      var col3 = currentRow.find("td:eq(3)").html();
                      
                      col1 = col1.replace(/^\s+|\s+$/g, '');
                      col2 = col2.replace(/^\s+|\s+$/g, '');
                      col3 = col3.replace(/^\s+|\s+$/g, '');
                     
                      
                    
                      $("#id_opdh").val(col1);
                      $("#kode_opdh").val(col2);
                      $("#opdh").val(col3);
                    
                  });
                  
                                        


                  });

                  





                
           
</script>

<script type="text/javascript">
      function loadul(){
    
        $('#tumbsi').summernote(
        {
            placeholder:'input data anda',
            height:200,
            toolbar: [
['style', []],
['font', []],
['color', []],
['para', []],
['table', []],
['insert', ['picture']],
['view', ['fullscreen']]
]
        });


       
   
 }
</script>
        <script>

  $(function () {
    // Summernote
    $('#summernote1').summernote(
        {
            placeholder:'input data anda',
            height:200,
        });

   
   $('#tumbsi').summernote(
        {
            placeholder:'input data anda',
            height:200,
            toolbar: [
['style', []],
['font', []],
['color', []],
['para', []],
['table', []],
['insert', ['picture']],
['view', ['fullscreen']]
]
        });

   

   
    CodeMirror.fromTextArea(document.getElementById("beritai"), {
      mode: "htmlmixed",
      theme: "monokai"
    });


  })
</script>
          
         <script>
            $(function () {
                $("#example1").DataTable({
                    "responsive": true,
                    "lengthChange": true,
                    "autoWidth": true,
                    "buttons": ["copy", "csv", "excel", "pdf", "print"]
                }).buttons().container().appendTo('#example1_wrapper .col-md-6:eq(0)');
                $('#example2').DataTable({
                    "paging": true,
                    "lengthChange": false,
                    "searching": false,
                    "ordering": true,
                    "info": true,
                    "autoWidth": false,
                    "responsive": true,
                });
            });
</script>
 
</body>
</html>