
<?php 
    include 'header.php'; 
    $klp=$_GET['kd'];
    $nama=$_GET['kel'];
    
    $level=$_SESSION['level'];
    $thn = date('Y');
    $bln = date('m');   
    $oleh=$_SESSION['id'];
    $kdc=$_SESSION['kdc'];
?>

<div class="container">

 <div class="my-4 border-bottom">
   <h2 class="fw-semibold fs-3"><?php echo $nama; ?></h2>
 </div>
  <div class="row justify-content-center">
    <div class="col-lg-12">
       <div class="card">
        <div class="card-header d-flex justify-content-between"> 
            <span class="card-title fw-semibold align-self-start mb">Kode Kelompok</span> 
            <div>
                <a href="javascript:history.go(-1)" class="btn btn-warning btn-sm"><i class="bi bi-reply-all"></i> &nbsp Kembali</a> 
            </div>
        </div>
    <div class="card-body">
    <div>
      <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="25%" class="text-center">NAMA</th>
              <th width="20%" class="text-center">SUB</th>
              <th width="1%" class="text-center">Unit</th>
              <th width="15%" class="text-center">OPSI</th>
            </tr>
          </thead>
          <tbody>
            <?php 
            $no=1;
            $data = mysqli_query($koneksi,"SELECT * FROM nawal WHERE klp='$klp' ORDER BY noperk ASC");
            while($d = mysqli_fetch_array($data)){
                $id=$d['id'];
                $no_sub=$d['nosub'];
                
                $sql0 = mysqli_query($koneksi, "SELECT count(noperk) AS tjnoperk FROM jor WHERE noperk='$d[noperk]' ");
                list($tjnoperk) = mysqli_fetch_array($sql0); 
                $sql1 = mysqli_query($koneksi, "SELECT nama AS nama_klp FROM n_kode_2 WHERE kd='$d[klp]' ");
                list($nama_klp) = mysqli_fetch_array($sql1);          
                $sql3 = mysqli_query($koneksi, "SELECT nama AS nama_sub FROM n_kode_3 WHERE kd='$d[nosub]' ");
                list($nama_sub) = mysqli_fetch_array($sql3);               
                    /////////// 
              ?>
              <tr>
               <td><?php echo $no++; ?></td>
                <td><?php echo $d['noperk']; ?></td>
                <td><?php echo $d['perk']; ?></td>
                <td align='left'><?php echo $d['nosub']; ?> <?php echo $nama_sub; ?></td>
                <td align='left'><?php echo $d['kdu']; ?></td>
                <td>  
                    <a class="btn btn-warning btn-sm" title="Edit Nama Perkiraan Bu Bes <?php echo $d['noperk'] ?>-<?php echo $d['perk'] ?>" data-bs-toggle="modal" data-bs-target="#edit_akunt_<?php echo $d['id'] ?>"><i class="bi bi-gear"></i></a>                
                    <?php if ($tjnoperk<=0) {?>
                    <a onclick="return confirm('Yakin ingin hapus akunt <?php echo $d['perk']; ?>.....?')" class="btn btn-danger btn-sm" href="kode_akunt_new_hapus.php?id=<?php echo $d['id'] ?>">
                            <i class="bi bi-trash"></i>
                    </a>
                    <?php } ?>     
<!---- FORM EDIT AKUNT   ---------->                  
                  <form action="kode_akunt_new_edit_act.php" method="post">
                    <div class="modal fade" id="edit_akunt_<?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 Akunt <?php echo $d['noperk']; ?> - <?php echo $d['perk']; ?></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 Akunt </label>
                  <input type="hidden" name="oleh" value="<?php echo $oleh ?>" readonly="readonly" class="form-control" >
                  <input type="hidden" name="kdc" value="<?php echo $kdc ?>" readonly="readonly" class="form-control" >
                  <input type="hidden" name="id" value="<?php echo $id ?>" readonly="readonly" class="form-control" >
                  <input type="text" name="nama" required="required" class="form-control" value="<?php echo $d['perk'] ?>">
                </div>
                        	<div class="form-group">
                                <label class="form-label">Sub Kode Kelompok <font color='#ff0000'><i>(pilih Sub Kode Kelompok)</i></font color></label>
                                <select class="form-control" name="nosub" required="required">
                                  <option value="">- Pilih Sub Kode Kelompok -</option>
                                  <?php 
                                  $kode_2 = mysqli_query($koneksi,"select * from n_kode_3 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 class="form-group">
                                <label class="form-label">Unit <font color='#ff0000'><i>(pilih Unit)</i></font color></label>
                                <select class="form-control" name="kdu" required="required">
                                  <option value="">- Pilih Unit -</option>
                                  <?php 
                                  $unit = mysqli_query($koneksi,"select * from kd_unit order by kd ASC");
                                  while($u = mysqli_fetch_array($unit)){
                                    ?>
                                    <option value="<?php echo $u['kd'] ?>"><?php echo $u['kd'] ?> - <?php echo $u['nama'] ?></option>
                                    <?php 
                                  }
                                  ?>
                                </select>
                        	</div>         
                <div class="form-group">
                  <label>Jumlah Saldo Awal (Debet) </label>
                  <input type="text" class="form-control nilai rupiah" id="nilai" name="tawald" required="required" value="<?php echo "" . number_format("$d[awald]", 0, ",", "."); ?>">
                </div>
                <div class="form-group">
                  <label>Jumlah Saldo Awal (Kredit) </label>
                  <input type="text" class="form-control nilai rupiah" id="nilai" name="tawalk" required="required" value="<?php echo "" . number_format("$d[awalk]", 0, ",", "."); ?>">
                </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>
<!---- FORM EDIT AKUNT  ---SELESAI------->                                             
                  </td>
              </tr>
              <?php 
            }
            ?>
          </tbody>
        </table>
      </div>
    </div>

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

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