<?php 
    session_start();
    include 'header.php'; 
            //////////////////////////////////////////////////////////////////////////// 
        $oleh   = $_SESSION['id_kar'];
        $kdc    = $_SESSION['kdc'];
            ////////////////////////////////////////////////////////////////////////////
    $kd=$_GET['kd'];
    $kel=$_GET['kel'];
?>

<div class="container">
  <div class="my-2 border-bottom">
    <h2 class="fw-semibold fs-3"></h2>
  </div>

  <section class="content">
    <div class="row justify-content-center">
      <section class="col-lg-12">       
        <div class="card card-info">

          <div class="card-header justify-content-between d-flex">
            <span class="card-title fw-semibold">DAFTAR ASSET TETAP <?php echo strtoupper($kel) ?> </span>
            <a href="javascript:history.go(-1)" class="btn btn-primary btn-sm"><i class="bi bi-reply-all"></i> &nbsp Kembali</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" style="text-align:left; font-size: 10pt; font-weight:normal;">No</th>
              <th width="3%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Kode</th>
              <th width="1%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Tanggal</th>
              <th width="20%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Nama</th>
              <th width="1%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Unit</th>
              <th width="10%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">H Beli</th>
              <th width="10%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Akum Peny</th>
              <th width="10%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">N Buku</th>
              <th width="15%" class="text-center" style="text-align:left; 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 cmob_brg WHERE kd='$kd' order by id ASC ");
            while($p = mysqli_fetch_array($jjj)){
                $kode   =$p['kode'];
                $id     =$p['id'];
                $sql11 = mysqli_query($koneksi, "SELECT sum(u_beli) AS tu_beli,sum(beli) AS tbeli,sum(be_ph) AS tbe_ph FROM cmob_trans WHERE kode='$kode' ");
                    list($tu_beli,$tbeli,$tbe_ph) = mysqli_fetch_array($sql11); 
                    $nilai_buku=$tbeli-$tbe_ph;
                    
                $query = mysqli_query($mysqli, "UPDATE cmob_brg SET be_ph='$tbe_ph',u_beli='$tu_beli',n_beli='$tbeli' where kode='$kode' ");    
              ?>
              <tr>
                <td><?php echo $no++; ?></td>
                <td style="text-align:left; font-size: 10pt; font-weight:normal;"><?php echo $kode ?></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 $p['nama'] ?></td>
                <td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$tu_beli", 0, ",", "."); ?></td>
                <td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$tbeli", 0, ",", "."); ?></td>
                <td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$tbe_ph", 0, ",", "."); ?></td>
                <td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$nilai_buku", 0, ",", "."); ?></td>
<td>
    <a data-toggle='tooltip' data-placement='top' title='Buka Kartu Inventory <?php echo $p['nama'] ?>' class="btn btn-warning btn-sm" href="at_kartu_per_kode.php?kode=<?php echo $kode ?>"><i class="bi bi-layer-backward"></i></a>
<a class="btn btn-success btn-sm" title="Jual Inventory <?php echo $p['nama'] ?>" data-bs-toggle="modal" data-bs-target="#jual_invent_<?php echo $kode ?>"><i class="bi bi-arrow-up-right-square"></i></a>
<a class="btn btn-primary btn-sm" title="Biaya Service" data-bs-toggle="modal" data-bs-target="#biaya_servis_invent_<?php echo $kode ?>"><i class="bi bi-cash-coin"></i></a>
<a class="btn btn-info btn-sm" title="Penerimaan Jasa" data-bs-toggle="modal" data-bs-target="#penerimaan_jasa_<?php echo $kode ?>"><i class="bi bi-receipt"></i></a>

<!-- FORM MODAL PENJUALAN -->
<div class="modal fade" id="jual_invent_<?php echo $kode ?>" tabindex="-1" aria-labelledby="jualModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="jualModalLabel">Form Penjualan Aset Tetap</h5>
        <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']; ?>;">  
        <form action="at_simpan_act.php" method="post">
          <div class="mb-3">
            <label for="nama" class="form-label">Nama Barang</label>
            <input type="text" class="form-control" id="nama" name="nama" value="<?php echo $p['nama']; ?>" readonly>
                              <input type="hidden" name="aksi" value="insert_jornal_jual_at">
                              <input type="hidden" name="tkd" required="required" class="form-control" value="<?php echo $k['kd']; ?>">
                              <input type="hidden" name="tkdc" required="required" class="form-control" value="<?php echo $kdc ; ?>">
                              <input type="hidden" name="tkode" readonly="readonly" class="form-control" value="<?php echo $kode ; ?>" style="width:100%">            
          </div>
          <div class="mb-3">
            <label for="jumlah" class="form-label">Jumlah</label>
            <input type="text" name="tunit" required="required" class="form-control" value="<?php echo $tu_beli ; ?>" style="width:100%">
          </div>
          <div class="mb-3">
            <label for="harga" class="form-label">Harga</label>
            <input type="text" class="form-control nilai rupiah" id="nilai" name="thjual" required="required" value="<?php echo "" . number_format("$nilai_buku", 0, ",", "."); ?>" >
          </div>
                <div class="form-group">
                   <label class="form-label">Tanggal Transaksi</label>
                   <input type="date" class="form-control" name="ttanggal" required="required" placeholder="Masukkan Tanggal ..">
                </div>          
                <div class="form-group">
                    <label class="form-label">Akunt Lawan<font color='#ff0000'><i>(Pilih Akunt ke mana penjualan diterima)</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 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>
  </div>
</div>

<!-- FORM MODAL BIAYA SERVICE -->
<div class="modal fade" id="biaya_servis_invent_<?php echo $kode ?>" tabindex="-1" aria-labelledby="biayaModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="biayaModalLabel">Form Biaya Aset Tetap</h5>
        <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']; ?>;">  
        <form action="at_simpan_act.php" method="post">
          <div class="mb-3">
            <label for="nama" class="form-label">Nama Barang</label>
            <input type="text" class="form-control" id="nama" name="tnama" value="<?php echo $p['nama']; ?>" readonly>
            <input type="hidden" name="aksi" value="insert_jornal_biaya_service_at">
            <input type="hidden" name="tkd" required="required" class="form-control" value="<?php echo $p['kd']; ?>">
            <input type="hidden" name="tkdc" required="required" class="form-control" value="<?php echo $kdc ; ?>">
            <input type="hidden" name="tkode" readonly="readonly" class="form-control" value="<?php echo $kode ; ?>" style="width:100%">            
          </div>
          <div class="mb-3">
            <label for="keterangan" class="form-label">Keterangan</label>
            <textarea class="form-control" id="keterangan" name="tket" required></textarea>
          </div>          
          <div class="mb-3">
            <label for="harga" class="form-label">Jumlah Biaya</label>
            <input type="text" class="form-control nilai rupiah" id="nilai" name="tbiaya" required="required" >
          </div>
                <div class="form-group">
                   <label class="form-label">Tanggal Transaksi</label>
                   <input type="date" class="form-control" name="ttanggal" required="required" placeholder="Masukkan Tanggal ..">
                </div>          
                <div class="form-group">
                    <label class="form-label">Akunt Lawan <font color='#ff0000'><i>(Pilih Akunt dari mana Biaya 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 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>
  </div>
</div>

<!-- FORM MODAL PENERIMAAN JASA -->
<div class="modal fade" id="penerimaan_jasa_<?php echo $kode ?>" tabindex="-1" aria-labelledby="penerimaanJasaModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="penerimaanJasaModalLabel">Form Penerimaan Jasa</h5>
        <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']; ?>;">  
        <form action="at_simpan_act.php" method="post">
          <div class="mb-3">
            <label for="nama" class="form-label">Nama Barang</label>
            <input type="text" class="form-control" id="nama" name="tnama" value="<?php echo $p['nama']; ?>" readonly>
            <input type="hidden" name="aksi" value="insert_jornal_pendapatan_jasa_at">
            <input type="hidden" name="tkd" required="required" class="form-control" value="<?php echo $p['kd']; ?>">
            <input type="hidden" name="tkdc" required="required" class="form-control" value="<?php echo $kdc ; ?>">
            <input type="hidden" name="tkode" readonly="readonly" class="form-control" value="<?php echo $kode ; ?>" style="width:100%">            
          </div>
          <div class="mb-3">
            <label for="keterangan" class="form-label">Keterangan</label>
            <textarea class="form-control" id="keterangan" name="tket" required></textarea>
          </div>          
          <div class="mb-3">
            <label for="harga" class="form-label">Jumlah Pendapatan</label>
            <input type="text" class="form-control nilai rupiah" id="nilai" name="tjasa" required="required" >
          </div>
                <div class="form-group">
                   <label class="form-label">Tanggal Transaksi</label>
                   <input type="date" class="form-control" name="ttanggal" required="required" placeholder="Masukkan Tanggal ..">
                </div>          
                <div class="form-group">
                    <label class="form-label">Akunt Lawan <font color='#ff0000'><i>(Pilih Akunt ke mana Pendapatan diterima)</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 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>
  </div>
</div>


                </td>           
                </tr>    
                        </div>
                      </div>
                    </div>
                  </form>                      
              <?php } ?>
          </tbody>
                        <?php 
                $sql3a = mysqli_query($koneksi, "SELECT sum(u_beli) AS tu_beli,sum(n_beli) AS tn_beli,sum(be_ph) AS tbe_ph FROM cmob_brg ");
                list($tu_beli,$tn_beli,$tbe_ph) = mysqli_fetch_array($sql3a); 
                $tn_buku=$tn_beli-$tbe_ph;
            	        ?>						
							<tr>
						    	<td colspan="3" 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("$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("$tn_buku", 0, ",", "."); ?></font>
								</td>
								<td align='right'><style="font-weight: bold;">
								    <?php echo ""; ?>
								</td>
							</tr>                   
        </table>
       </div> 
    </div>    
              <div class="alert alert-info text-center">
                SAAT MELAKUKAN TRANSAKSI PENJUALAN ASSET DIWAJIBKAN UNTUK MELAKUKAN PENYUSUTAN SAMPAI DENGAN TANGGAL DIJUAL.
              </div>
     


                  
                      </td>
                    </tr>
                  </table>
                </div>
              </div>
          </div>
        </div>
      </section>
    </div>
  </section>

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