<?php 
    include 'header.php'; 
?>

<div class="container">
    
<style>
  .table th {
    font-weight: normal;
  }
</style>

  <div class="my-2 border-bottom">
    <h5 class="fw-semibold fs-5"></h5>
  </div>
      <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">TRANSAKSI 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>
  <section class="content">
    <div class="row">
      <section class="col-lg-12">
        <div class="box box-info">
          <div class="box-header">
          <div class="box-body">
            <form method="get" action="">

            </form>
          </div>
        </div>
        
        <div class="box box-info">
          <div class="box-header">
            <h6 class="box-title"></h6>
          </div>
          <div class="box-body">
            <?php 
            if(isset($_GET['kt']) && isset($_GET['kd'])){
              $kt    = $_GET['kt'];
              $kd    = $_GET['kd'];
              $oleh  =$_SESSION['id_kar'];
              
                    $sql11  = mysqli_query($koneksi, "SELECT kd AS tkd,nama AS tnama FROM kdjenis_at WHERE kd='$kd' ");
                    list($tkd,$tnama) = mysqli_fetch_array($sql11);
                    $sql12  = mysqli_query($koneksi, "SELECT kd AS xkd,nama AS xnama FROM kdjenis_at_trans WHERE kd='$kt' ");
                    list($xkd,$xnama) = mysqli_fetch_array($sql12);                    
            ?>
<div class="row"> 
  <div class="col-lg-6"> 
    <table class="table table-bordered"> 
      <tr> 
        <th width="30%">Transaksi </th> 
        <th width="1%">:</th> 
        <td><b><?php echo strtoupper($xnama) ?></b></td> 
      </tr> 
      <tr> 
        <th>Jenis/Kelompok </th> 
        <th>:</th> 
        <td><b><?php echo strtoupper($tnama) ?></b></td> 
      </tr> 
    </table> 
  </div> 
</div>
<!--
      <button type="button" class="btn btn-warning btn-sm align-self-end" data-bs-toggle="modal" data-bs-target="#exampleModal">
        <a href="!!!!3_lap_trans_all_bln_view.php?bulan=<?php echo $bulane ; ?>&tahun=<?php echo $tahune ; ?>&kode=<?php echo $kase ; ?>&kas=<?php echo $refe ; ?>" class="btn btn-warning btn-sm"><i class="bi bi-emoji-expressionless"></i> &nbsp View (untuk REKAP dan atau EDIT AKUNT) </a> 
      </button> 
-->
    <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:center; font-size: 10pt; font-weight:normal;">NoTrans</th>
              <th width="6%" class="text-center" style="text-align:center; font-size: 10pt; font-weight:normal;">Tanggal</th>
              <th width="40%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Uraian</th>
              <th width="10%" class="text-center" style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo $xnama ?></th>              
              <th width="12%" class="text-center" style="text-align:center; font-size: 10pt; font-weight:normal;">Opsi</th>
            </tr>
          </thead>
          <tbody>
            <?php 
              $no   = 1;
              $awal = $awale;
              $debet  = 0;
              $kredit  = 0;
              //WHERE kd='$kase' and month(tanggal)='$bulane' and year(tanggal)='$tahune'
            $jjj = mysqli_query($koneksi,"SELECT * FROM kas WHERE td='$kd' and tr='$kt' and hapus<>'HAPUS' order by id ASC ");
            while($p = mysqli_fetch_array($jjj)){
                $kode   =$p['kode'];
                $peny   =$p['be_ph'];
                $notrans=$p['notrans'];
                
                $dft = mysqli_query($koneksi,"select * from cmob_brg where kode='$kode' ");
                    $n = mysqli_fetch_assoc($dft);  
                $sql10 = mysqli_query($koneksi, "SELECT akunt_ph FROM kdjenis_at WHERE kd='$kase' ");
                    list($akunt_ph) = mysqli_fetch_array($sql10);
                $sql11 = mysqli_query($koneksi, "SELECT kode AS tkode FROM cmob_trans WHERE notrans='$notrans' ");
                    list($tkode) = mysqli_fetch_array($sql11);   
                    
                $sql12 = mysqli_query($koneksi, "SELECT keterangan,jumlah FROM kas WHERE notrans='$notrans' ");
                    list($keterangan,$jumlah) = mysqli_fetch_array($sql12);                       
              ?>
              <tr>
                <td style="text-align:left; font-size: 10pt; font-weight:normal;"><?php echo $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: 8pt; font-weight:normal;"><?php echo $keterangan ?></td>
                <td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$jumlah", 0, ",", "."); ?></td>
                <td>
                    <a data-toggle='tooltip' data-placement='top' title='Buka Kartu Inventory <?php echo $n['nama'] ?>' class="btn btn-warning btn-sm" href="at_kartu_per_kode.php?kode=<?php echo $tkode ?>"><i class="bi bi-layer-backward"></i></a>                                
                    <a onclick="return confirm('Yakin ingin hapus transaksi : <?php echo $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 ?>&kt=<?php echo $kt ?>">
                            <i class="bi bi-trash"></i>
                    </a>
                </td>           
                </tr>    
                        </div>
                      </div>
                    </div>
                  </form>                      
              <?php } ?>
          </tbody>
                        <?php 
                $sql3a = mysqli_query($koneksi, "SELECT sum(be_ph) AS tbe_ph FROM $tabel_tujuan ");
                list($tbe_ph) = mysqli_fetch_array($sql3a);                
            	        ?>						
							<tr>
						    	<td colspan="2" style="font-weight: bold;text-align: center;">Total </td>																																									
								<td align='right'><style="font-weight: bold;">
								    <?php echo ""; ?>
								</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;">
								    <?php echo ""; ?>
								</td>
							</tr>                   
        </table>
       </div> 
    </div>    
            <?php if($tbe_ph>=1) {; ?>
<div class="row">
    <div class="col-lg-6">
        <table class="table table-bordered">
            <tr>
                <th width="60%">Total Penyusutan yg telah diinput </th>
                <th width="1%">:</th>
                <td><font color='#ff0000'><?php echo "" . number_format("$tbe_ph", 0, ",", "."); ?></font></td>
            </tr>
            <tr>
                <th>Simpan sebagai Transaksi Akuntansi </th>
                <th>:</th>
                <td>
                    <a class="btn btn-success btn-sm me-2" title="Simpan Sebagai Jornal " data-bs-toggle="modal" data-bs-target="#jornal_penyusutan_<?php echo $tbe_ph ?>">
                        <i class="bi bi-download"></i>
                    </a>
                </td>
            </tr>
        </table>
    </div>
</div>
     
<!-- Modal -->
<div class="modal fade" id="jornal_penyusutan_<?php echo $tbe_ph ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <form action="at_simpan_act.php" method="post">
                <div class="modal-header">
                    <h1 class="modal-title fs-5" id="exampleModalLabel">Simpan Jornal <?php echo $tnama ?> Bulan <?php echo $bulan ; ?> - <?php echo $tahune ; ?></h1>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                
                <div class="modal-body">
                    <div class="form-group" style="width:100%">
                        <input type="hidden" name="aksi" value="simpan_jornal_penyusutan">
                        <input type="text" name="tkd" required="required" class="form-control" value="<?php echo $kase ?>">
                        <input type="text" name="tbln" required="required" class="form-control" value="<?php echo $bulan ; ?>">
                        <input type="text" name="tthn" required="required" class="form-control" value="<?php echo $tahune ; ?>">
                        <input type="text" name="tkdc" required="required" class="form-control" value="<?php echo $kdc ; ?>">
                        <input type="text" name="toleh" required="required" class="form-control" value="<?php echo $oleh ; ?>">
                    </div>
                    <div class="form-group" style="width:100%">
                        <label class="form-label"><font color="#000fff">Jumlah Penyusutan </font></label>
                        <input type="text" class="form-control nilai rupiah" id="nilai" name="tnilai" value="<?php echo "" . number_format("$tbe_ph", 0, ",", "."); ?>">
                    </div>
                    <div class="form-group" style="width:100%">
                        <label class="form-label"><font color="#000fff">Tanggal Penyusutan</font></label>
                        <input type="date" class="form-control" name="ttanggal" required="required" placeholder="Masukkan Tanggal ..">
                    </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>
            </form>
        </div>
    </div>
</div>

                  
                      </td>
                    </tr>
                  </table>
                </div>
              </div>
              
              
            <?php }; ?>
              <?php 
            }else{
              ?>

              <div class="alert alert-info text-center">
                Silahkan Filter Laporan Terlebih Dulu.
              </div>

              <?php
            }
            ?>

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

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