<?php 
    session_start();
    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">Rekap Daftar 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>
      
        <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">
      <div class="table-responsive">
        <table class="table table-bordered table-striped" id="table-datatable">
          <thead>
            <tr>
              <th width="1%" class="text-center">KD</th>
              <th width="35%" class="text-center">Kelompok</th>
              <th width="1%" class="text-center">Item</th>
              <th width="1%" class="text-center">Unit</th>
              <th width="1%" class="text-center">Pembelian</th>
              <th width="1%" class="text-center">Penyusutan</th>
              <th width="1%" class="text-center">Nilai Buku</th>
              <th width="1%" class="text-center">Sewa</th>
              <th width="1%" class="text-center">Biaya</th>
              <th width="1%" class="text-center">Jual</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'];
                $sql1 = mysqli_query($koneksi, "SELECT count(kode) AS tjkode,sum(u_beli) AS tju_beli,sum(n_beli) AS tjn_beli FROM cmob_brg WHERE kd='$kd' ");
                    list($tjkode,$tju_beli,$tjn_beli) = mysqli_fetch_array($sql1);   
    
                $sql3 = mysqli_query($koneksi, "SELECT sum(be_ph) AS tjn_be_ph FROM cmob_trans WHERE kd='$kd' and kt='PH' ");
                    list($tjn_be_ph) = mysqli_fetch_array($sql3);                     
                $sql4 = mysqli_query($koneksi, "SELECT sum(pendapatan) AS tjsewa FROM cmob_trans WHERE kd='$kd' and kt='SW' ");
                    list($tjsewa) = mysqli_fetch_array($sql4);     
                $sql5 = mysqli_query($koneksi, "SELECT sum(biaya) AS tjbeaya FROM cmob_trans WHERE kd='$kd' and kt='BI' ");
                    list($tjbeaya) = mysqli_fetch_array($sql5);                 
                $sql6 = mysqli_query($koneksi, "SELECT sum(jual) AS tjjual FROM cmob_trans WHERE kd='$kd' and kt='JL' ");
                    list($tjjual) = mysqli_fetch_array($sql6); 
                    
                $n_buku=$tjn_beli-$tjn_be_ph;
              ?>
              <tr>
                
                <td><?php echo $k['kd']; ?></td>
                <td><?php echo $k['nama']; ?></td>
                <td style="text-align:right; font-size: 10pt; font-weight:normal;"><a data-toggle='tooltip' data-placement='top' title='Lihat Daftar <?php echo $k['nama']; ?>' style='margin-right:3px' class="btn btn-success btn-sm" href="at_daftar_barang.php?kd=<?php echo $k['kd']; ?>&kel=<?php echo $k['nama']; ?>"><?php echo "" . number_format("$tjkode", 0, ",", "."); ?></td>
                <td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$tju_beli", 0, ",", "."); ?>
                <td style="text-align:right; font-size: 10pt; font-weight:normal;"><a data-toggle='tooltip' data-placement='top' title='Lihat Rincian Trans Pembelian <?php echo $k['nama']; ?>' style='margin-right:3px' class="btn btn-warning btn-sm" href="at_daftar_trans.php?kt=BL&kd=<?php echo $k['kd']; ?>"><?php echo "" . number_format("$tjn_beli", 0, ",", "."); ?></td>
                <td style="text-align:right; font-size: 10pt; font-weight:normal;"><a data-toggle='tooltip' data-placement='top' title='Lihat Rincian Trans Penyusutan <?php echo $k['nama']; ?>' style='margin-right:3px' class="btn btn-warning btn-sm" href="at_daftar_trans.php?kt=PH&kd=<?php echo $k['kd']; ?>"><?php echo "" . number_format("$tjn_be_ph", 0, ",", "."); ?></td>
                <td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$n_buku", 0, ",", "."); ?>
                <td style="text-align:right; font-size: 10pt; font-weight:normal;"><a data-toggle='tooltip' data-placement='top' title='Lihat Rincian Trans Penerimaan Sewa <?php echo $k['nama']; ?>' style='margin-right:3px' class="btn btn-warning btn-sm" href="at_daftar_trans.php?kt=SW&kd=<?php echo $k['kd']; ?>"><?php echo "" . number_format("$tjsewa", 0, ",", "."); ?></td>
                <td style="text-align:right; font-size: 10pt; font-weight:normal;"><a data-toggle='tooltip' data-placement='top' title='Lihat Rincian Trans Pengeluaran Biaya <?php echo $k['nama']; ?>' style='margin-right:3px' class="btn btn-warning btn-sm" href="at_daftar_trans.php?kt=BI&kd=<?php echo $k['kd']; ?>"><?php echo "" . number_format("$tjbeaya", 0, ",", "."); ?></td>
                <td style="text-align:right; font-size: 10pt; font-weight:normal;"><a data-toggle='tooltip' data-placement='top' title='Lihat Rincian Trans Penjualan <?php echo $k['nama']; ?>' style='margin-right:3px' class="btn btn-warning btn-sm" href="at_daftar_trans.php?kt=JL&kd=<?php echo $k['kd']; ?>"><?php echo "" . number_format("$tjjual", 0, ",", "."); ?></td>

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

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

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