      
<?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>

       <title></title>

<link rel="stylesheet" href="../../../plugins/fontawesome-free/css/all.min.css">
  <!-- SweetAlert2 -->
  <link rel="stylesheet" href="../../../dist/css/adminlte.min.css">

    </head>
    <body>
   
   
 <table class="table table-bordered table-striped" >  
 <tr>
    <th colspan="3" style="vertical-align: middle; text-align: center;">Kode</th>
    <th colspan="4" style="vertical-align: middle; text-align: center;">Uraian</th>
    <th  style="vertical-align: middle; text-align: center;">Pagu</th>
    <th  style="vertical-align: middle; text-align: center;">Realisasi</th>
    <th  style="vertical-align: middle; text-align: center;">Sisa Saldo</th>
 </tr>         
       <?php
$kode_sub_skpd=$_GET['kode_sub_skpd'];
$kode_kegiatan=$_GET['kode_kegiatan'];
$sqlbku  = mysqli_query($koneksi, "SELECT 
distinct a.kode_sub_kegiatan,a.sub_kegiatan,a.kode_sub_skpd,
ri.rincian2,rl.realisasi2,
(ri.rincian2 - rl.realisasi2) as sisa 
from ((( renja as a)
left join 
(select kode_sub_skpd,kode_sub_kegiatan, sum(rincian) as rincian2 from renja group by kode_sub_skpd,kode_sub_kegiatan) as ri on ri.kode_sub_skpd=a.kode_sub_skpd and ri.kode_sub_kegiatan=a.kode_sub_kegiatan)
left join 
(select kode_sub_skpd,kode_sub_kegiatan, sum(realisasi) as realisasi2 from realisasi group by kode_sub_skpd,kode_sub_kegiatan) as rl on ri.kode_sub_skpd=a.kode_sub_skpd and rl.kode_sub_kegiatan=a.kode_sub_kegiatan)
where   a.kode_kegiatan='$kode_kegiatan'and a.kode_sub_skpd='$kode_sub_skpd' order by a.kode_sub_kegiatan
    ");
foreach ($sqlbku as $rowsubkeg) {
    ?>
<tr>
    <td colspan="3"><strong><?php echo $rowsubkeg['kode_sub_kegiatan']; ?></strong></td>
    <td colspan="4"><strong><?php echo $rowsubkeg['sub_kegiatan']; ?></strong></td>
    <td style="text-align:right;" ><strong><?php echo number_format($rowsubkeg['rincian2']); ?></strong></td>
    <td style="text-align:right; "><strong><?php echo number_format($rowsubkeg['realisasi2']); ?></strong></td>
    <td style="text-align: right;"><strong><?php if (!empty($rowsubkeg['realisasi2'])){echo number_format($rowsubkeg['sisa']);} else{echo number_format($rowsubkeg['rincian2']);}  ?></strong></td>
</tr>
       <?php
$sqlrek  = mysqli_query($koneksi, "SELECT 
distinct a.kode_rekening,a.rekening,ri.rincian2,rl.realisasi2,
(ri.rincian2-rl.realisasi2) as sisa 
from ((( renja as a)
left join
( select kode_rekening, kode_sub_kegiatan,kode_sub_skpd,sum(rincian) as rincian2 from renja group by kode_rekening, kode_sub_kegiatan,kode_sub_skpd) as ri on ri.kode_rekening=a.kode_rekening and ri.kode_sub_kegiatan=a.kode_sub_kegiatan and ri.kode_sub_skpd=a.kode_sub_skpd )

left join
( select kode_rekening, kode_sub_kegiatan,kode_sub_skpd,sum(realisasi) as realisasi2 from realisasi group by kode_rekening, kode_sub_kegiatan,kode_sub_skpd) as rl on rl.kode_rekening=a.kode_rekening and rl.kode_sub_kegiatan=a.kode_sub_kegiatan and rl.kode_sub_skpd=a.kode_sub_skpd )

where   a.kode_sub_kegiatan='$rowsubkeg[kode_sub_kegiatan]'and a.kode_sub_skpd='$rowsubkeg[kode_sub_skpd]'
group by a.kode_rekening,a.rekening,ri.rincian2,rl.realisasi2
    ");
foreach ($sqlrek as $rowrek) {
    ?>
<tr>
    <td></td>
    <td colspan="3"><strong><?php echo $rowrek['kode_rekening']; ?></strong></td>
    <td></td>
    
    <td colspan="2"><strong><?php echo $rowrek['rekening']; ?></strong></td>
    <td style="text-align: right;"><strong><?php echo number_format($rowrek['rincian2']); ?></strong></td>
    <td style="text-align: right;"><strong><?php echo number_format($rowrek['realisasi2']); ?></strong></td>
    <td style="text-align: right;"><strong><?php if (!empty($rowrek['realisasi2'])){echo number_format($rowrek['sisa']);} else{echo number_format($rowrek['rincian2']);}  ?></strong></td>
</tr>
<?php
$balance = $rowrek['rincian2']; 
$sqlreal  = mysqli_query($koneksi, "SELECT 
distinct a.kode_rekening,a.rekening,a.realisasi,a.keterangan_dokumen,a.kode_sub_skpd,a.nomor_sp2d,a.tanggal_sp2d,
sp2d.nama_penerima,sp2d2.nama_penerima2,sp2d2.nomor_sp2d2,sp2d2.tanggal_sp2d2
from ((( realisasi as a)
left join
(select nomor_sp2d, nama_penerima from sp2d ) as sp2d on sp2d.nomor_sp2d=a.nomor_sp2d)
left join
(select keterangan,nomor_sp2d as nomor_sp2d2, nama_penerima as nama_penerima2,tanggal_sp2d as tanggal_sp2d2 from sp2d ) as sp2d2 on sp2d2.keterangan=a.keterangan_dokumen)

where   a.kode_sub_kegiatan='$rowsubkeg[kode_sub_kegiatan]'and a.kode_sub_skpd='$rowsubkeg[kode_sub_skpd]' and a.kode_rekening='$rowrek[kode_rekening]'
order by a.nomor_sp2d
    ");
foreach ($sqlreal as $rowreal) {
    $balance =   $balance- $rowreal['realisasi']  ; 
    ?>
<tr>
    <td></td>
    <td></td>
    <td><?php if(($rowreal['nomor_sp2d']=='null')) {echo $rowreal['tanggal_sp2d2'];} else { ?> <?php echo $rowreal['tanggal_sp2d2'];} ?>
    
</td>
    <td></td>
    <td></td>

    <td><?php if(($rowreal['nomor_sp2d'])=='null'){ echo 'di Reg SP2D '. $rowreal['nama_penerima2'];} else { ?> <?php echo $rowreal['nama_penerima'];} ?></td>
    
    <td><?php echo $rowreal['keterangan_dokumen']; ?><br>Nomor&nbspSP2D&nbsp
        <?php if(($rowreal['nomor_sp2d'])=='null'){ ?> <h6 style="color : red"> <?php echo 'di Reg SP2D '. $rowreal['nomor_sp2d2']; ?> </h6><?php } else{ ?>
<?php echo $rowreal['nomor_sp2d'];} ?></td>
    <td style="text-align: right;"></td>
    <td style="text-align: right;"><?php echo number_format($rowreal['realisasi']); ?></td>
    <td style="text-align: right;"><?php



     echo number_format($balance); ?></td>
</tr>
<?php
}
}
}
mysqli_close($koneksi);
?> 
  </table>
          <script>
              $(document).ready(function () {
                 $(".selkegiatan").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();
                      
                      col0 = col0.replace(/^\s+|\s+$/g, '');
                      col1 = col1.replace(/^\s+|\s+$/g, '');
                      col2 = col2.replace(/^\s+|\s+$/g, '');
                      col3 = col3.replace(/^\s+|\s+$/g, '');
                     
                      
                    
                      $("#kode_kegiatan").val(col0);
                      $("#x").val(col1);
                      $("#x").val(col2);
                      $("#x").val(col3);
                      bku2();
                     

                      
                          });
                
                  $(".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>