
<?php 
    include 'header.php'; 
    $id = $_GET['kode'];

    $tgl_d = $_GET['tgl_d'];
    $tgl_s = $_GET['tgl_s'];
    $oleh=$_SESSION['id_kar'];
    
    $cmob = mysqli_query($koneksi,"select * from cmob_brg where kode='$id' ");
    $c = mysqli_fetch_assoc($cmob);
    $jenis = mysqli_query($koneksi,"select * from kdjenis_at where kd='$c[kd]' ");
    $j = mysqli_fetch_assoc($jenis); 
    $nrc = mysqli_query($koneksi,"select * from nawal where noperk='$j[akunt_as]' ");
    $n = mysqli_fetch_assoc($nrc);
    $sewa = mysqli_query($koneksi,"select * from kdjenis_at_sewa where kd='$c[kelompok]' ");
    $s = mysqli_fetch_assoc($sewa); 
    
    $sql4 = mysqli_query($koneksi, "SELECT count(kode) AS tjkode FROM cmob_trans WHERE kode='$id' ");
        list($tjkode) = mysqli_fetch_array($sql4);    

?>              

<div class="container">
  <div class="my-2 border-bottom">
        <h6 class="fw-semibold fs-6"></h6>
  </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">KARTU HISTORI ASET TETAP</span>
      <button type="button" class="btn btn-primary btn-sm align-self-end" data-bs-toggle="modal" data-bs-target="#exampleModal">
        <a href="javascript:history.go(-1)" class="btn btn-primary btn-sm"><i class="bi bi-reply-all"></i> &nbsp Kembali</a> 
      </button>
    </div>
          <div class="box-body">
            <form method="get" action="">
              <div class="row">
                <div class="col-lg-12">
                  <table class="table table-bordered">
                    <tr>
                      <th width="35%">Kode / Nama Aset Tetap</th>
                      <th width="1%">:</th>
                      <td><?php echo $id ?> - <?php echo $c['nama'] ?></td>
                    </tr>
                    <tr>
                      <th>Nama Kelompok Akunt </th>
                      <th>:</th>
                      <td><?php echo $j['akunt_as'] ?> - <?php echo $n['perk'] ?> </td>
                    </tr>
                    <tr>
                      <th>Kelompok</th>
                      <th>:</th>
                      <td><?php echo $s['kd'] ?> - <?php echo $s['nama'] ?></td>
                    </tr>
                    <tr>
                      <th>Tanggal Beli / Taksiran Umur Ekonomis</th>
                      <th>:</th>
                      <td><?php echo date('d/m/Y', strtotime($c['tanggal'])); ?> / <?php echo $c['ph'] ?> tahun</td>
                    </tr>
                    <tr>
                      <th>Unit / Harga Satuan </th>
                      <th>: </th>
                      <td><?php echo "" . number_format("$c[u_beli]", 0, ",", "."); ?> Unit @ <?php echo "Rp.  " . number_format("$c[a_beli]", 0, ",", "."); ?> ,-</td>
                    </tr>

                  </table>
<!-- ////////////////////////// Jor //////////////// -->          
<?php if ($tjkode>0) { ?>
    <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" style="text-align:left; font-size: 10pt; font-weight:normal;">No</th>
              <th width="1%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Nomor</th>
              <th width="1%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Tanggal</th>
              <th width="50%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Keterangan</th>
              <th width="1%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Kd</th>
              <th width="1%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Unit</th>
              <th width="1%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Pembelian</th>
              <th width="1%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Penyusutan</th>
              <th width="1%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Biaya</th>
              <th width="1%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Pendapatan</th>
              <th width="18%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Opsi</th>
            </tr>
          </thead>
          <tbody>
            <?php 
              $no   = 1;
              $awal = $n_awal;
              $debet  = 0;
              $kredit  = 0;
              //and tanggal>='$tgl_d' and tanggal<='$tgl_s' 
            $jor = mysqli_query($koneksi,"SELECT * FROM cmob_trans WHERE kode=$id ORDER BY id ASC ");
            while($p = mysqli_fetch_array($jor)){

                $kas = mysqli_query($koneksi,"select * from kas where notrans='$p[notrans]'");
                    $k = mysqli_fetch_assoc($kas);  
              ?>
              <tr>
                <td><?php echo $no++; ?></td>
                <td style="text-align:left; font-size: 10pt; font-weight:normal;"><?php echo $p['notrans'] ?></td>
                <td style="text-align:left; font-size: 10pt; font-weight:normal;"><?php echo date('d/m/Y', strtotime($p['tanggal'])); ?></td>
                <td style="text-align:left; font-size: 10pt; font-weight:normal;"><?php echo $k['keterangan'] ?></td>
                <td style="text-align:left; font-size: 10pt; font-weight:normal;"><?php echo $p['kt'] ?></td>
                <td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$p[u_beli]", 0, ",", "."); ?></td>
                <td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$p[beli]", 0, ",", "."); ?></td>
                <td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$p[be_ph]", 0, ",", "."); ?></td>
                <td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$p[biaya]", 0, ",", "."); ?></td>
                <td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$p[pendapatan]", 0, ",", "."); ?></td>
                <td>
                    <a data-toggle='tooltip' data-placement='top' title='Buka Jornal Trans <?php echo $p['notrans'] ?>' class="btn btn-primary btn-sm" href="!!_kas_jor_view.php?id=<?php echo $p['notrans'] ?>"><i class="bi bi-layer-backward"></i></a>  
                    
                    <a onclick="return confirm('Yakin ingin hapus transaksi : <?php echo $k['keterangan'] ?>.....?')" class="btn btn-danger btn-sm" href="at_transaksi_hapus.php?id=<?php echo $p['id'] ?>&notrans=<?php echo $p['notrans'] ?>&oleh=<?php echo $oleh ?>&kode=<?php echo $id ?>">
                            <i class="bi bi-trash"></i>
                    </a>
<!--                  <a onclick="return confirm('Yakin ingin hapus data No <?php echo $d['angg_no']; ?> a/n <?php echo $d['nama']; ?> - <?php echo $d['alamat']; ?> ?')" class="btn btn-danger btn-sm" href="angg_hapus.php?id=<?php echo $d['angg_id'] ?>&oleh=<?php echo $oleh ?>">
                    <i class="bi bi-trash"></i>
                  </a>                          
-->
                </td>           
                </tr>    


  
                        </div>
                      </div>
                    </div>
                  </form>                      
              <?php } ?>
          </tbody>
                        <?php 
                $sql3a = mysqli_query($koneksi, "SELECT sum(u_beli) AS tu_beli,sum(beli) AS tn_beli,sum(be_ph) AS tbe_ph,sum(biaya) AS tbiaya,sum(pendapatan) AS tpendapatan FROM cmob_trans WHERE kode=$id");
                list($tu_beli,$tn_beli,$tbe_ph,$tbiaya,$tpendapatan) = mysqli_fetch_array($sql3a); 
                $tn_buku=$tn_beli-$tbe_ph;
            	        ?>						
							<tr>
						    	<td colspan="5" style="font-weight: bold;text-align: center;">Total </td>	
								<td align='right'><style="font-weight: bold;">
								    <font color='#ff0000'><?php echo "" . number_format("$tu_beli", 0, ",", "."); ?></font>
								</td>
								<td align='right'><style="font-weight: bold;">
								    <font color='#ff0000'><?php echo "" . number_format("$tn_beli", 0, ",", "."); ?></font>
								</td>
								<td align='right'><style="font-weight: bold;">
								    <font color='#ff0000'><?php echo "" . number_format("$tbe_ph", 0, ",", "."); ?></font>
								</td>								
								<td align='right'><style="font-weight: bold;">
								    <font color='#ff0000'><?php echo "" . number_format("$tbiaya", 0, ",", "."); ?></font>
								</td>
								<td align='right'><style="font-weight: bold;">
								    <font color='#ff0000'><?php echo "" . number_format("$tpendapatan", 0, ",", "."); ?></font>
								</td>								
								<td align='right'><style="font-weight: bold;">
								    <?php echo ""; ?>
								</td>
							</tr>       
							<tr>
						    	<td colspan="5" style="font-weight: bold;text-align: center;">NILAI BUKU </td>	
								<td align='right'><style="font-weight: bold;">
								    <font color='#ff0000'><?php echo "" ?></font>
								</td>
								<td align='right'><style="font-weight: bold;">
								    <font color='#ff0000'><?php echo "" . number_format("$tn_buku", 0, ",", "."); ?></font>
								</td>
								<td align='right'><style="font-weight: bold;">
								    <font color='#ff0000'><?php echo "" ?></font>
								</td>								
								<td align='right'><style="font-weight: bold;">
								    <font color='#ff0000'><?php echo "" ; ?></font>
								</td>
								<td align='right'><style="font-weight: bold;">
								    <font color='#ff0000'><?php echo "" ; ?></font>
								</td>								
								<td align='right'><style="font-weight: bold;">
								    <?php echo ""; ?>
								</td>
							</tr>       							
        </table>
       </div> 
    </div>    
<!-- ////////////////////////// MEMBUAT FORM ACC  //////////////// -->         
        <?php } else { ?>
                <font color='#ff0000'  style="text-align:left; font-size: 8pt; font-weight:normal;"><i>Aset <?php echo $c['nama'] ?> belum ada transaksi....</i></font><br>
        <?php } ?>
<!-- ////////////////////////// SELESAI PERMOHONAN  //////////////// --> 
                </div>
              </div>
              </div>
            </form>
          </div>
      </div>
    </div>
  </div>
</div>
<?php include 'footer.php'; ?>