<?php 
    include 'header.php'; 

    $kd         =$_GET['kd'] ;
    $kdc        =$_SESSION['kdc'] ;
    
    $sql1 = mysqli_query($koneksi, "SELECT kelurahan,kecamatan,kota,kanca FROM kdkanca WHERE kd='$kdc' ");
                list($kelurahan,$kecamatan,$kota,$kanca) = mysqli_fetch_array($sql1);
                
    $sql2 = mysqli_query($koneksi, "SELECT kd AS tkd FROM kdjenis_simp WHERE kd='$kd' ORDER BY kd DESC limit 1 ");
                list($tkd) = mysqli_fetch_array($sql2);
    $no_kd= $tkd+1 ;           
?>

<div class="container">

 <div class="my-2 border-bottom">
   <h4 class="fw-semibold fs-4">Daftar Kelompok Aset Tetap - di <?php echo $kanca; ?></h4>
 </div>
  <div class="row justify-content-center">
    <div class="col-lg-9">
       <div class="card">
    <div class="card-header d-flex justify-content-between">
      <span class="card-title fw-semibold align-self-start mb"> </span>
      
      <button type="button" class="btn btn-success btn-sm align-self-end" data-bs-toggle="modal" data-bs-target="#exampleModal">
       <i class="bi bi-calendar-plus"></i> Tambah Kelompok Aset Tetap
      </button>
      
        <a href="index.php" class="btn btn-primary btn-sm"><i class="bi bi-reply-all"></i> &nbsp Kembali/Home</a> 
      
    </div>
    <div class="card-body">


      <!-- Modal -->
      <form action="at_simpan_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 Data Kelompok Aset Tetap</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">
                <div class="form-group" style="width:100%">
                  <label>Kode Kelompok Aset Tetap <font color='#ff0000'><i>(Masukkan 2 digit angka)</i></font color></label>
                  <input type="hidden" name="aksi" value="insert_kelompok">
                  <input type="text" name="tkd" required="required" class="form-control" placeholder="Kode Kelompok Aset Tetap .." value="<?php echo $d['kd']; ?>" style="width:100%">
                </div>        	    
                <div class="form-group" style="width:100%">
                  <label>Nama Kelompok Aset Tetap </label>
                  <input type="text" name="tnama" required="required" class="form-control" placeholder="Nama Kelompok Aset Tetap .." value="<?php echo $d['nama']; ?>" style="width:100%">
                </div>
            	<div class="form-group">
                    <label class="form-label">Akunt Aset Tetap <font color='#ff0000'><i>(Pilih Akunt Aset)</i></font color></label>
                    <select class="form-control" name="takunt_as" required="required">
                      <option value="">- Pilih Akunt Aset -</option>
                      <?php 
                      $us = mysqli_query($koneksi,"select * from nawal WHERE nosub='131' ORDER BY noperk ASC ");
                      while($u = mysqli_fetch_array($us)){
                        ?>
                        <option value="<?php echo $u['noperk'] ?>"><?php echo $u['noperk'] ?> - <?php echo $u['perk'] ?></option>
                        <?php 
                      }
                      ?>
                    </select>
            	</div>
            	
            	<div class="form-group">
                    <label class="form-label">Akunt Akumpulasi Penyusutan <font color='#ff0000'><i>(Pilih Akumpulasi Penyusutan)</i></font color></label>
                    <select class="form-control" name="takunt_ak" required="required">
                      <option value="">- Pilih Akumpulasi Penyusutan -</option>
                      <?php 
                      $uj = mysqli_query($koneksi,"select * from nawal WHERE nosub='132' ORDER BY noperk ASC ");
                      while($j = mysqli_fetch_array($uj)){
                        ?>
                        <option value="<?php echo $j['noperk'] ?>"><?php echo $j['noperk'] ?> - <?php echo $j['perk'] ?></option>
                        <?php 
                      }
                      ?>
                    </select>
            	</div>       
          	
            	<div class="form-group">
                    <label class="form-label">Akunt Beban Penyusutan <font color='#ff0000'><i>(Pilih Beban Penyusutan)</i></font color></label>
                    <select class="form-control" name="takunt_ph" required="required">
                      <option value="">- Pilih Beban Penyusutan -</option>
                      <?php 
                      $ua = mysqli_query($koneksi,"select * from nawal WHERE left(perk,19)='Beban Penyusutan Ak' ORDER BY noperk ASC ");
                      while($a = mysqli_fetch_array($ua)){
                        ?>
                        <option value="<?php echo $a['noperk'] ?>"><?php echo $a['noperk'] ?> - <?php echo $a['perk'] ?></option>
                        <?php 
                      }
                      ?>
                    </select>
            	</div>                   	
            	<div class="form-group">
                    <label class="form-label">Akunt Laba Jika Dijual <font color='#ff0000'><i>(Pilih Laba Jika Dijual)</i></font color></label>
                    <select class="form-control" name="takunt_lb" required="required">
                      <option value="">- Pilih Laba Jika Dijual -</option>
                      <?php 
                      $ua = mysqli_query($koneksi,"select * from nawal WHERE left(perk,15)='Pend. Laba Penj' ORDER BY noperk ASC ");
                      while($a = mysqli_fetch_array($ua)){
                        ?>
                        <option value="<?php echo $a['noperk'] ?>"><?php echo $a['noperk'] ?> - <?php echo $a['perk'] ?></option>
                        <?php 
                      }
                      ?>
                    </select>
            	</div>        
            	<div class="form-group">
                    <label class="form-label">Akunt Rugi Jika Dijual <font color='#ff0000'><i>(Pilih Rugi Jika Dijual...)</i></font color></label>
                    <select class="form-control" name="takunt_rg" required="required">
                      <option value="">- Pilih Rugi Jika Dijual -</option>
                      <?php 
                      $ua = mysqli_query($koneksi,"select * from nawal WHERE left(perk,15)='Beban Rugi Penj' ORDER BY noperk ASC ");
                      while($a = mysqli_fetch_array($ua)){
                        ?>
                        <option value="<?php echo $a['noperk'] ?>"><?php echo $a['noperk'] ?> - <?php echo $a['perk'] ?></option>
                        <?php 
                      }
                      ?>
                    </select>
            	</div>                    	
        	</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">KD</th>
              <th width="35%" class="text-center">Jenis Aset Tetap</th>
              <th width="1%" class="text-center">Akunt Aset</th>
              <th width="1%" class="text-center">Akunt Akum</th>
              <th width="1%" class="text-center">Akunt Peny</th>
              <th width="1%" class="text-center">Akunt Laba</th>
              <th width="1%" class="text-center">Akunt Rugi</th>
              <th width="1%" class="text-center">Jumlah AT</th>
              <th width="20%" class="text-center">Opsi</th>
            </tr>
          </thead>
          <tbody>
            <?php 
            $no=1;
            $tgl_skr= date('Y-m-d');
            $data = mysqli_query($koneksi,"SELECT * FROM kdjenis_at ORDER BY id ASC");
            while($k = mysqli_fetch_array($data)){
                $kd=$k['kd'];
                $akunt_p=$k['akunt_as'];
                $akunt_j=$k['akunt_ak'];
                $akunt_b=$k['akunt_ph'];
                $akunt_l=$k['akunt_lb'];
                $akunt_r=$k['akunt_rg'];
                

                $sql1 = mysqli_query($koneksi, "SELECT count(kode) AS tjkode FROM cmob_brg WHERE kd='$kd' ");
                    list($tjkode) = mysqli_fetch_array($sql1);                    

                $nawal_p = mysqli_query($koneksi, "SELECT noperk AS tperk_p FROM nawal WHERE noperk='$akunt_p' and hapus<>'HAPUS' ");
                    list($tperk_p) = mysqli_fetch_array($nawal_p);
                $nawal_j = mysqli_query($koneksi, "SELECT noperk AS tperk_j FROM nawal WHERE noperk='$akunt_j' and hapus<>'HAPUS' ");
                    list($tperk_j) = mysqli_fetch_array($nawal_j);
                $nawal_b = mysqli_query($koneksi, "SELECT noperk AS tperk_b FROM nawal WHERE noperk='$akunt_b' and hapus<>'HAPUS' ");
                    list($tperk_b) = mysqli_fetch_array($nawal_b);                    
                $nawal_l = mysqli_query($koneksi, "SELECT noperk AS tperk_l FROM nawal WHERE noperk='$akunt_l' and hapus<>'HAPUS' ");
                    list($tperk_l) = mysqli_fetch_array($nawal_l);  
                $nawal_r = mysqli_query($koneksi, "SELECT noperk AS tperk_r FROM nawal WHERE noperk='$akunt_r' and hapus<>'HAPUS' ");
                    list($tperk_r) = mysqli_fetch_array($nawal_r);                      
              ?>
              <tr>
                <td><?php echo $no++; ?></td>
                <td><?php echo $k['kd']; ?></td>
                <td><?php echo $k['nama']; ?></td>
                <td><?php echo $tperk_p; ?></td>
                <td><?php echo $tperk_j; ?></td>
                <td><?php echo $tperk_b; ?></td>
                <td><?php echo $tperk_l; ?></td>
                <td><?php echo $tperk_r; ?></td>
                <td><?php echo "" . number_format("$tjkode", 0, ",", "."); ?>

                </td> 
                
                
<td>
  <form action="at_simpan_act.php" method="post">
    <input type="hidden" name="aksi" value="<?php echo ($tjkode<=0) ? 'delete_baris_kelompok' : ''; ?>">
    <input type="hidden" name="id" value="<?php echo $k['id']; ?>">
    <?php if ($tjkode<=0) { ?>
      <button onclick="return confirm('Yakin ingin hapus kelompok AT <?php echo $k['nama']; ?> id <?php echo $k['id']; ?> .....?')" class="btn btn-danger btn-sm" type="submit"> 
        <i class="bi bi-trash"></i> 
      </button>
    <?php } ?>
    
    <a class="btn btn-warning btn-sm" title="Edit Jenis Aset <?php echo $k['nama'] ?>" data-bs-toggle="modal" data-bs-target="#edit_jenis_at_<?php echo $k['id'] ?>">
      <i class="bi bi-gear"></i>
    </a>
  </form>
  <!-- Modal edit -->
  <form action="at_simpan_act.php" method="post">
  <div class="modal fade" id="edit_jenis_at_<?php echo $k['id'];?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <!-- Isi modal -->
                      <div class="modal-dialog" role="document">
                        <div class="modal-content">
                          <div class="modal-header">
                            <h1 class="modal-title fs-5" id="exampleModalLabel">Edit Jenis AT : <?php echo $k['nama']; ?> - <?php echo $k['kd']; ?></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" style="width:100%">
                              <label><font color="#000fff">Jenis AT</font></label>
                              <input type="hidden" name="aksi" value="edit_kelompok">
                              <input type="hidden" name="tid" required="required" class="form-control" value="<?php echo $k['id']; ?>">
                              <input type="text" name="tnama" required="required" class="form-control" value="<?php echo $k['nama']; ?>" style="width:100%">
                            </div>
            	<div class="form-group">
                    <label class="form-label">Akunt Aset Tetap <font color='#ff0000'><i>(Pilih Akunt Aset)</i></font color></label>
                    <select class="form-control" name="takunt_as" required="required">
                      <option value="">- Pilih Akunt Aset -</option>
                      <?php 
                      $us = mysqli_query($koneksi,"select * from nawal WHERE nosub='131' ORDER BY noperk ASC ");
                      while($u = mysqli_fetch_array($us)){
                        ?>
                        <option value="<?php echo $u['noperk'] ?>"><?php echo $u['noperk'] ?> - <?php echo $u['perk'] ?></option>
                        <?php 
                      }
                      ?>
                    </select>
            	</div>
            	
            	<div class="form-group">
                    <label class="form-label">Akunt Akumpulasi Penyusutan <font color='#ff0000'><i>(Pilih Akumpulasi Penyusutan)</i></font color></label>
                    <select class="form-control" name="takunt_ak" required="required">
                      <option value="">- Pilih Akumpulasi Penyusutan -</option>
                      <?php 
                      $uj = mysqli_query($koneksi,"select * from nawal WHERE nosub='132' ORDER BY noperk ASC ");
                      while($j = mysqli_fetch_array($uj)){
                        ?>
                        <option value="<?php echo $j['noperk'] ?>"><?php echo $j['noperk'] ?> - <?php echo $j['perk'] ?></option>
                        <?php 
                      }
                      ?>
                    </select>
            	</div>       
          	
            	<div class="form-group">
                    <label class="form-label">Akunt Beban Penyusutan <font color='#ff0000'><i>(Pilih Beban Penyusutan)</i></font color></label>
                    <select class="form-control" name="takunt_ph" required="required">
                      <option value="">- Pilih Beban Penyusutan -</option>
                      <?php 
                      $ua = mysqli_query($koneksi,"select * from nawal WHERE left(perk,19)='Beban Penyusutan Ak' ORDER BY noperk ASC ");
                      while($a = mysqli_fetch_array($ua)){
                        ?>
                        <option value="<?php echo $a['noperk'] ?>"><?php echo $a['noperk'] ?> - <?php echo $a['perk'] ?></option>
                        <?php 
                      }
                      ?>
                    </select>
            	</div>                   	
            	<div class="form-group">
                    <label class="form-label">Akunt Laba Jika Dijual <font color='#ff0000'><i>(Pilih Laba Jika Dijual)</i></font color></label>
                    <select class="form-control" name="takunt_lb" required="required">
                      <option value="">- Pilih Laba Jika Dijual -</option>
                      <?php 
                      $ua = mysqli_query($koneksi,"select * from nawal WHERE left(perk,15)='Pend. Laba Penj' ORDER BY noperk ASC ");
                      while($a = mysqli_fetch_array($ua)){
                        ?>
                        <option value="<?php echo $a['noperk'] ?>"><?php echo $a['noperk'] ?> - <?php echo $a['perk'] ?></option>
                        <?php 
                      }
                      ?>
                    </select>
            	</div>        
            	<div class="form-group">
                    <label class="form-label">Akunt Rugi Jika Dijual <font color='#ff0000'><i>(Pilih Rugi Jika Dijual...)</i></font color></label>
                    <select class="form-control" name="takunt_rg" required="required">
                      <option value="">- Pilih Rugi Jika Dijual -</option>
                      <?php 
                      $ua = mysqli_query($koneksi,"select * from nawal WHERE left(perk,15)='Beban Rugi Penj' ORDER BY noperk ASC ");
                      while($a = mysqli_fetch_array($ua)){
                        ?>
                        <option value="<?php echo $a['noperk'] ?>"><?php echo $a['noperk'] ?> - <?php echo $a['perk'] ?></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>
</td>    

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

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

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