

<?php 
    include 'header.php'; 

    $level=$_SESSION['level'];
    $thn = date('Y');
    $bln = date('m');   
    $oleh=$_SESSION['id'];
    $kdc=$_SESSION['kdc'];
    
                $sql20 = mysqli_query($koneksi, "SELECT sum(awald) AS tawald,sum(awalk) AS tawalk FROM nawal ");
                list($tawald,$tawalk) = mysqli_fetch_array($sql20);
                $selisih=$tawald-$tawalk;
                
    if ($tawald==$tawalk) { ;
        $ket='AKUNT BUKU BESAR BALANCE';
    } else {
        $ket='NERACA AWAL ANDA TIDAK BALANCE - BEDA : '.number_format("$selisih", 0, ",", ".").'';
    }
?>

<div class="container">

 <div class="my-4 border-bottom">
   <h2 class="fw-semibold fs-3"><?php echo $ket ?></h2>
 </div>

  <div class="row justify-content-center">
    <div class="col-lg-8">
       <div class="card">
        <div class="card-header d-flex justify-content-between"> 
            <span class="card-title fw-semibold align-self-start mb">Kode Sub Kelompok Buku Besar</span> 
            <div>
                <a href="javascript:history.go(-1)" class="btn btn-warning btn-sm"><i class="bi bi-reply-all"></i> &nbsp Kembali</a> 
                <button type="button" class="btn btn-primary btn-sm" data-bs-toggle="modal" data-bs-target="#exampleModal"> 
                    <i class="bi bi-plus"></i> Tambah 
                </button>
            </div>
        </div>
    
    <div class="card-body">


      <!-- Modal -->
      <form action="kode_akunt_new_sub_act.php" method="post">
        <div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
          <div class="modal-dialog">
            <div class="modal-content">
              <div class="modal-header">
                <h1 class="modal-title fs-5" id="exampleModalLabel">Tambah Sub Kelompok Buku Besar</h1>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
              </div>
              <div class="modal-body">
<div style="background-color: <?php echo$_SESSION['warna_bag']; ?>; padding: 15px; border-radius: 15px; box-shadow: 0 0 15px <?php echo$_SESSION['warna_bag']; ?>;">                  

                <div class="form-group">
                  <label>Nama Sub Kelompok </label>
                  <input type="text" name="nama" required="required" class="form-control" placeholder="Isi Nama Kelompok ..">
                </div>                
                        	<div class="form-group">
                                <label class="form-label">Sub Kelompok <font color='#ff0000'><i>(pilih Kode Kelompok)</i></font color></label>
                                <select class="form-control" name="no_klp" required="required">
                                  <option value="">- Pilih Kode Kelompok -</option>
                                  <?php 
                                  $kode_2 = mysqli_query($koneksi,"select * from n_kode_2 order by kd ASC");
                                  while($k = mysqli_fetch_array($kode_2)){
                                    ?>
                                    <option value="<?php echo $k['kd'] ?>"><?php echo $k['kd'] ?> - <?php echo $k['nama'] ?></option>
                                    <?php 
                                  }
                                  ?>
                                </select>
                        	</div>                         
                </div>
              <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Tutup</button>
                <button type="submit" class="btn btn-primary">Simpan</button>
              </div>
            </div>
          </div>
        </div>
</div>        
      </form>
      <div class="table-responsive">
        <table class="table table-bordered table-striped" id="table-datatable">
          <thead>
            <tr>
              <th width="1%" class="text-center">No</th>
              <th width="1%" class="text-center">Kode</th>
              <th width="20%" class="text-center">NAMA</th>
              <th width="1%" class="text-center">Akunt</th>
              <th width="1%" class="text-center">Awal D</th>
              <th width="1%" class="text-center">Awal K</th>
              <th width="15%" class="text-center">OPSI</th>
            </tr>
          </thead>
          <tbody>
            <?php 

            $no=1;
            $data = mysqli_query($koneksi, "SELECT * FROM n_kode_3 ORDER BY kd ASC");
            $jumlah_data = mysqli_num_rows($data);
            echo "Jumlah data: $jumlah_data";
            while($d = mysqli_fetch_array($data)){
            
                $id=$d['id'];
                $nosub=$d['kd'];
                
                $sql0 = mysqli_query($koneksi, "SELECT count(noperk) AS jxnoperk,count(nosub) AS jxnosub,sum(awald) AS jxawald,sum(awalk) AS jxawalk FROM nawal WHERE nosub='$nosub' ");
                list($jxnoperk,$jxnosub,$jxawald,$jxawalk) = mysqli_fetch_array($sql0); 
              ?>
              <tr>
               <td><?php echo $no++; ?></td>
                <td><?php echo $d['kd']; ?></td>
                <td><?php echo $d['nama']; ?></td>
                <td align='right'><?php echo "" . number_format("$jxnoperk", 0, ",", "."); ?></td> 
                <td align='right'><?php echo "" . number_format("$jxawald", 0, ",", "."); ?></td>                
                <td align='right'><?php echo "" . number_format("$jxawalk", 0, ",", "."); ?></td>  
                <td>    
                    <a class="btn btn-warning btn-sm" title="Lihat <?php echo $d['kd'] ?>-<?php echo $d['nama'] ?>" href="kode_akunt_new_sub_lihat.php?kd=<?php echo $d['kd'] ?>&kel=<?php echo $d['nama'] ?>"><i class="bi bi-eye"></i></a>
                    <a class="btn btn-primary btn-sm" title="Edit / Ganti Kode Kelompok <?php echo $d['kd']; ?> <?php echo $d['nama']; ?>" data-bs-toggle="modal" data-bs-target="#edit_kelompok_<?php echo $d['kd']; ?><?php echo $d['id']; ?>"><i class="bi bi-gear"></i></a>
                    <?php if ($jxnoperk<=0) {?>
                    <a onclick="return confirm('Yakin ingin hapus sub kelompok <?php echo $d['kd']; ?> - <?php echo $d['nama']; ?>.....?')" class="btn btn-danger btn-sm" href="kode_akunt_new_sub_hapus.php?id=<?php echo $d['id'] ?>">
                            <i class="bi bi-trash"></i>
                    </a>
                    <?php } ?>     
   
                    
<!---- FORM EDIT NOSUB ---------->                  
                  <form action="kode_akunt_new_sub_edit_act.php" method="post">
                    <div class="modal fade" id="edit_kelompok_<?php echo $d['kd']; ?><?php echo $d['id']; ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                      <div class="modal-dialog" role="document">
                        <div class="modal-content">
                          <div class="modal-header">
                            <h1 class="modal-title fs-5" id="exampleModalLabel">Edit Nama Sub Kelompok <?php echo $d['kd']; ?> <?php echo $d['nama']; ?></h1>
                            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                          </div>
                          <div class="modal-body">
                <div style="background-color: <?php echo$_SESSION['warna_bag']; ?>; padding: 15px; border-radius: 15px; box-shadow: 0 0 15px <?php echo$_SESSION['warna_bag']; ?>;">
                <div class="form-group">
                    <label><font color="#000fff">Kode Sub Kelompok</font></label>
                    <input type="text" name="tid" readonly="readonly" class="form-control" value="<?php echo $d['id']; ?>">
                </div>
  
                <div class="form-group" style="width:100%">
                  <label><font color="#000fff">Nama Sub Kelompok</font></label>
                  <input type="text" name="tnama" required="required" class="form-control" value="<?php echo $d['nama']; ?>" style="width:100%">
                </div>
                
                
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Tutup</button>
                    <button type="submit" class="btn btn-primary">Simpan</button>
                </div>
                </div>
              </div>
            </div>
            </div>                    
            </form>
<!---- FORM EDIT NOSUB ---SELESAI ------->     
                  </td>
<!---- FORM EDIT KELOMPOK  ----------> 

              </tr>
              <?php 
            }
            ?>
          </tbody>

                        <?php 
                $sql2 = mysqli_query($koneksi, "SELECT sum(awald) AS tawald,sum(awalk) AS tawalk FROM nawal ");
                list($tawald,$tawalk) = mysqli_fetch_array($sql2);
            	        ?>						
                <tr>
                    <td colspan="4" style="font-weight: bold;text-align: center;background-color: <?php echo$_SESSION['warna_bag']; ?>;">Total</td>
                    <td align='right' style="font-weight: bold;background-color: <?php echo$_SESSION['warna_bag']; ?>;"><?php echo "" . number_format("$tawald", 0, ",", "."); ?></td>
                    <td align='right' style="font-weight: bold;background-color: <?php echo$_SESSION['warna_bag']; ?>;"><?php echo "" . number_format("$tawalk", 0, ",", "."); ?></td>
                    <td align='right' style="font-weight: bold;background-color: <?php echo$_SESSION['warna_bag']; ?>;"><?php echo "" ; ?></td>
                </tr>	
                
        </table>
      </div>
    </div>

  </div>
    </div>
  </div>

</div>
<?php include 'foot_ku.php'; ?>