<?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-10">
       <div class="card">
    <div class="card-header d-flex justify-content-between">
      <span class="card-title fw-semibold align-self-start mb"> </span>
      
      <buton>
       <a href="javascript:history.go(-1)" class="btn btn-primary btn-sm"><i class="bi bi-reply-all"></i> &nbsp Kembali/Home</a> 
      </buton>
    </div>
    <div class="card-body">
      <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="25%" class="text-center">Jenis Aset Tetap</th>
              <th width="1%" class="text-center">Unit</th>
              <th width="10%" class="text-center">Pembelian</th>
              <th width="10%" class="text-center">Penyusutan</th>
              <th width="10%" class="text-center">Penjualan</th>
              <th width="10%" class="text-center">N. Buku</th>
              <th width="12%" 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 jtkode,sum(beli) AS jtbeli,sum(be_ph) AS jtbe_ph,sum(jual) AS jtjual FROM cmob_trans WHERE kd='$kd' ");
                    list($jtkode,$jtbeli,$jtbe_ph,$jtjual) = mysqli_fetch_array($sql1);
                $so_buku=$jtbeli-$jtbe_ph ;    

              ?>
              <tr>
                <td><?php echo $no++; ?></td>
                <td><?php echo $k['kd']; ?></td>
                <td><?php echo $k['nama']; ?></td>
                <td style="text-align:right; font-size: 9pt; font-weight:normal;"><?php echo "" . number_format("$jtkode", 0, ",", "."); ?>
                <td style="text-align:right; font-size: 9pt; font-weight:normal;"><?php echo "" . number_format("$jtbeli", 0, ",", "."); ?>
                <td style="text-align:right; font-size: 9pt; font-weight:normal;"><?php echo "" . number_format("$jtbe_ph", 0, ",", "."); ?>
                <td style="text-align:right; font-size: 9pt; font-weight:normal;"><?php echo "" . number_format("$jtjual", 0, ",", "."); ?>
                <td style="text-align:right; font-size: 9pt; font-weight:normal;"><?php echo "" . number_format("$so_buku", 0, ",", "."); ?>
                
                
                  <?php if($tangg_no_1 >= 1) { ?>
                    <a data-toggle='tooltip' data-placement='top' title='Lihat Daftar AT <?php echo $k['nama']; ?>' style='margin-right:3px' class="btn btn-info btn-sm" href="angg_rkp_adm_daftar_usaha.php?id=<?php echo $k['kd']; ?>"><i class="bi bi-chat-left-text-fill">  Lihat Angg</i></a>
                  <?php } ?>
                </td> 
                
                
<td>
    <a class="btn btn-primary btn-sm me-2" title="Buka Daftar AT <?php echo $k['nama'] ?>" href="!!_kas_jor_view.php?id=<?php echo $d['notrans'] ?>">
      <i class="bi bi-bricks"></i>
    </a>
    
    <a class="btn btn-success btn-sm" title="Tambah (Pembelian) Aset <?php echo $k['nama'] ?>" data-bs-toggle="modal" data-bs-target="#tambah_beli_at_<?php echo $k['kd'] ?>">
      <i class="bi bi-calendar-plus"></i>
    </a>
  </form>
  <!-- Modal edit -->
  <form action="at_simpan_act.php" method="post">
  <div class="modal fade" id="tambah_beli_at_<?php echo $k['kd'];?>" 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">Pembelian AT Jenis : <?php echo $k['nama']; ?> - <?php echo $k['kd']; ?></h1>
                            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                          </div>
                         <?php
                  // fungsi untuk membuat kode transaksi
                    $sql1 = mysqli_query($koneksi, "SELECT right(kode,5) as kode3 FROM cmob_brg WHERE kd='$k[kd]' ORDER BY kode DESC LIMIT 1");
                    list($kode3) = mysqli_fetch_array($sql1);
                  $count3 = mysqli_num_rows($sql1);
    
                  if ($count3 <> 0) {
                      // mengambil data kode transaksi
                      $data_id3 = mysqli_fetch_assoc($sql1);
                      $kode3x    = $kode3+1;
                      $no_kode  = $kode3x ;
                  } else {
                      $no_kode = $kd.'001';
                  }     
                    ?>                          
                          <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">Kode Aset Tetap (AT)</font></label>
                              <input type="hidden" name="aksi" value="insert_jornal_beli">
                              <input type="hidden" name="tkd" required="required" class="form-control" value="<?php echo $k['kd']; ?>">
                              <input type="text" name="tkode" readonly="readonly" class="form-control" value="<?php echo $no_kode; ?>" style="width:100%">
                            </div>
            	<div class="form-group">
                    <label class="form-label"><font color="#000fff">Nama Aset Tetap </font><font color='#ff0000'><i>(Sebut nama khusus yg menandai barang tsb)</i></font color></label>
                    <input type="text" name="tnama" required="required" class="form-control" placeholder="Nama Barang .." style="width:100%">
            	</div>
            	
            	<div class="form-group">
                    <label class="form-label"><font color="#000fff">Jumlah (Kuantum) Aset Tetap </font><font color='#ff0000'><i> </i></font color></label>
                    <input type="text" name="tunit" required="required" class="form-control" placeholder="...." style="width:100%">
            	</div>
          	
            	<div class="form-group">
                    <label class="form-label"><font color="#000fff">Harga Satuan </font><font color='#ff0000'><i> </i></font color></label>
                    <input type="text" class="form-control nilai rupiah" id="nilai" name="thbeli" required="required" placeholder="Masukkan jumlah harga beli ..">
            	</div>
            	<div class="form-group">
                    <label class="form-label"><font color="#000fff">Usia Aset Tetap </font><font color='#ff0000'><i>(taksiran masa pakai dengan satuan tahun) </i></font color></label>
                    <input type="text" name="tumur" required="required" class="form-control" placeholder="...." style="width:100%">
            	</div>
<!--            	
            	<div class="form-group">
                    <label class="form-label"><font color="#000fff">AT Sewa </font><font color='#ff0000'><i>(Pilih apakah aset akan disewakan atau tidak...)</i></font color></label>
                    <select class="form-control" name="tsewa" required="required">
                      <option value="">- Pilih sewa -</option>
                      <?php 
                      $ue = mysqli_query($koneksi,"select * from kdjenis_at_sewa ");
                      while($e = mysqli_fetch_array($ue)){
                        ?>
                        <option value="<?php echo $e['kd'] ?>"><?php echo $e['nama'] ?></option>
                        <?php 
                      }
                      ?>
                    </select>
            	</div>                      	
-->
                <div class="form-group" style="width:100%">
                   <label class="form-label"><font color="#000fff">Tanggal Pembelian</font></label>
                   <input type="date" class="form-control" name="ttanggal" required="required" placeholder="Masukkan Tanggal ..">
                </div>
                
            	<div class="form-group">
                    <label class="form-label"><font color="#000fff">Akunt Lawan </font><font color='#ff0000'><i>(Pilih Akunt dari mana pembelian dibayar)</i></font color></label>
                    <select class="form-control" name="takunt" required="required">
                      <option value="">- Pilih Akunt -</option>
                      <?php 
                      $ua = mysqli_query($koneksi,"select * from nawal WHERE nosub<'113' 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 class="form-group">
                   <label class="form-label"><font color="##ff0000"><i>1. Satu kode AT hanya bisa dijual 1 kali atau hanya disewakan dalam 1 paket, karena itu perhatikan dan pertimbangkan pada saat pengisian JUMLAH KUANTUM aset yg dibeli.</i></font></label>
                </div>
                <div class="form-group">
                   <label class="form-label"><font color="##ff0000"><i>2. Jika pembelian secara Kredit (Hutang) maka lakukan PEMBUKUAN HUTANG terlebih dahulu, kemudian baru melakukan PEMBELIAN AT ini, dengan AKUNT LAWAN yg sama.</i></font></label>
                </div>         
-->
      </div>
    </div>

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

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