
<?php 
    include 'header.php'; 

    $kdk  = $_GET['kdk'];
    $kab = $_GET['kab'];
    $kdc = $_GET['kdc'];   

    $tgl_ini=date('d-m-Y') ;
    $tgl_ini2=date('Y-m-d') ; 
    
    $oleh   =$_SESSION['id_kar'];
    $kdc    =$_SESSION['kdc'];
?>              


<div class="container">
 <div class="my-2 border-bottom">
   <h5 class="fw-semibold fs-3">Daftar Akunt Kas & Banke</h5>
 </div>
  <div class="row justify-content-center">
    <div class="col-lg-12">
       <div class="card">
    <div class="card-header d-flex justify-content-between">
      <span class="card-title fw-semibold align-self-start mb">Silahkan klik (+)hijau untuk menambah D atau klik (+)merah untuk menambah K </span>
      <buton>
       <a href="index.php" class="btn btn-primary btn-sm"><i class="bi bi-reply-all"></i> &nbsp Kembali</a> 
      </buton>
    </div>
    <div class="card-body">
      <div class="table-responsive">

        <table class="table table-bordered table-striped" id="table-datatable1">
          <thead>
             <tr>
                <th Style="text-align:center" colspan="3" bgcolor="#D3D3D3">Akunt Buku Besar</th>
                <th Style="text-align:center" colspan="2" bgcolor="#DCDCDC">Saldo Awal</th>
                <th Style="text-align:center" colspan="4" bgcolor="#DCDCDC">Mutasi</th>
                <th Style="text-align:center" colspan="2" bgcolor="#DCDCDC">Saldo Akhir</th>
                <th width="6%" Style="text-align:center" colspan="1" rowspan="2" bgcolor="#DCDCDC">Opsi</th>
             </tr>                
            <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="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;">Debet</th>
              <th width="1%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Kredit</th>
              <th width="1%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">PENERIMAAN</th>
              <th width="1%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">x</th>
              <th width="1%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">PENGELUARAN</th>
              <th width="1%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">x</th>
              <th width="1%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Debet</th>
              <th width="1%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Kredit</th>
            </tr>
          </thead>
          <tbody>
            <?php 
            $no=1;
            //WHERE nosub<'113' 
            $data = mysqli_query($koneksi,"SELECT noperk,perk,awald,awalk,nosub FROM nawal ");
            while($d = mysqli_fetch_array($data)){
                $noperk=$d['noperk'];
                $jor = mysqli_query($koneksi, "SELECT sum(debet) AS tdebet,sum(kredit) AS tkredit FROM jor WHERE noperk='$noperk' ");
                list($tdebet,$tkredit) = mysqli_fetch_array($jor);
                $saldo=($d['awald']+$tdebet)-$tkredit ;
                if ($saldo>=1) {
                    $akhir_d=$saldo ;
                    $akhir_k=0 ;
                } else {
                    $akhir_d=0 ;
                    $akhir_k=$saldo ;                    
                }
              ?>
              <tr>
                <td><?php echo $no++; ?></td>
                <td style="text-align:left; font-size: 10pt; font-weight:normal;"><?php echo $noperk ?></td>
                <td style="text-align:left; font-size: 10pt; font-weight:normal;"><?php echo $d['perk']; ?></td>
                <td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$d[awald]", 0, ",", "."); ?></td>
                <td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$d[awalk]", 0, ",", "."); ?></td>
                <td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$tdebet", 0, ",", "."); ?></td>
                <td>
                  <a data-toggle='tooltip' data-placement='top' title='Tambah Trans DEBET pada <?php echo $d['perk'] ?>' style='margin-right:3px' class="btn btn-success btn-sm" data-bs-toggle="modal" data-bs-target="#trans_kas_masuk<?php echo $d['noperk'] ?>"><i class="bi bi-plus-circle"></i></a>
                  <form action="!!_kas_tambah_m_act.php" method="post">
                    <div class="modal fade" id="trans_kas_masuk<?php echo $d['noperk'] ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                      <div class="modal-dialog" role="document">
                        <div class="modal-content">
                          <div class="modal-header">
                            <h1 class="modal-title fs-5" id="exampleModalLabel">Tambah Trans DEBET pada <?php echo $d['perk'] ?></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%">
                              <label>Nomor Akunt</label>
                              <input type="text" name="tnoperk" readonly="readonly" class="form-control" value="<?php echo $d['noperk']; ?>">
                              <input type="hidden" name="toleh" readonly="readonly" class="form-control" value="<?php echo $oleh; ?>" style="width:100%">
                              <input type="hidden" name="tkdc" readonly="readonly" class="form-control" value="<?php echo $kdc; ?>" style="width:100%">
                            </div>
                            <div class="form-group mb-2">
                                <label class="form-label"><font color="#000fff">Keterangan (Maks 150 karakter)</font></label>
                                <textarea class="form-control" rows="2" name="tket"> </textarea> 
                            </div>    

                            <div class="form-group" style="width:100%">
                              <label>Jumlah </label>
                              <input type="text" class="form-control nilai rupiah" id="nilai" name="tjumlah" required="required" placeholder="Masukkan nominal ..">
                            </div>  
                        	<div class="form-group" style="width:100%">
                        	    <label class="form-label">Akunt Kredit <font color='#ff00ff'><i>(pilih akunt)</i></font color></label>
                                <?php
                                $query = mysqli_query($koneksi, "SELECT * FROM nawal Where noperk<>'$d[noperk]' order by perk ASC");
                                
                                // Membuat array untuk menyimpan data
                                $data = array();
                                while ($row = mysqli_fetch_assoc($query)) {
                                  $data[] = $row;
                                }
                                ?>
                                  <input class="form-control" type="text" name="takunt" list="options">
                                  <datalist id="options">
                                    <?php foreach ($data as $row) { ?>
                                      <option value="<?php echo $row['noperk']; ?> - <?php echo $row['perk']; ?>"><?php echo $row['noperk']; ?> - <?php echo $row['perk']; ?></option>
                                    <?php } ?>
                                  </datalist>
        	                </div>                        	
                          <div class="form-group" style="width:100%">
                            <label class="form-label">Tanggal Masuk</label> 
                            <input type="date" class="form-control" name="ttgl" required="required" value="<?php echo date('d/m/Y', strtotime($d['tglmasuk'])); ?>">
                          </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>
                  </form>                  
                
                
                <td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$tkredit", 0, ",", "."); ?></td>
                
                
                <td>    
                  <a data-toggle='tooltip' data-placement='top' title='Tambah Trans KREDIT pada <?php echo $d['perk'] ?>' style='margin-right:3px' class="btn btn-danger btn-sm" data-bs-toggle="modal" data-bs-target="#trans_kas_keluar<?php echo $d['noperk'] ?>"><i class="bi bi-plus-circle"></i></a>
                  <form action="!!_kas_tambah_k_act.php" method="post">
                    <div class="modal fade" id="trans_kas_keluar<?php echo $d['noperk'] ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                      <div class="modal-dialog" role="document">
                        <div class="modal-content">
                          <div class="modal-header">
                            <h1 class="modal-title fs-5" id="exampleModalLabel">Tambah Trans KREDIT pada <?php echo $d['perk'] ?></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%">
                              <label>Nomor Akunt</label>
                              <input type="text" name="tnoperk" readonly="readonly" class="form-control" value="<?php echo $d['noperk']; ?>">
                              <input type="hidden" name="toleh" readonly="readonly" class="form-control" value="<?php echo $oleh; ?>" style="width:100%">
                              <input type="hidden" name="tkdc" readonly="readonly" class="form-control" value="<?php echo $kdc; ?>" style="width:100%">
                            </div>
                            <div class="form-group mb-2">
                              <label class="form-label"><font color="#000fff">Keterangan (Maks 150 karakter)</font></label>
                              <textarea class="form-control" rows="2" name="tket"> </textarea> 
                            </div>    

                            <div class="form-group">
                              <label>Jumlah </label>
                              <input type="text" class="form-control nilai rupiah" id="nilai" name="tjumlah" required="required" placeholder="Masukkan nominal ..">
                            </div>         
                	        <div class="form-group" style="width:100%">
                	            <label class="form-label">Akunt Kredit <font color='#ff00ff'><i>(pilih akunt)</i></font color></label>
                                <?php
                                $query = mysqli_query($koneksi, "SELECT * FROM nawal Where noperk<>'$d[noperk]' order by perk ASC");
                        
                                // Membuat array untuk menyimpan data
                                $data = array();
                                while ($row = mysqli_fetch_assoc($query)) {
                                    $data[] = $row;
                                    }
                                ?>
                                <input class="form-control" type="text" name="takunt" list="options">
                                <datalist id="options">
                                    <?php foreach ($data as $row) { ?>
                                    <option value="<?php echo $row['noperk']; ?> - <?php echo $row['perk']; ?>"><?php echo $row['noperk']; ?> - <?php echo $row['perk']; ?></option>
                                    <?php } ?>
                                </datalist>
	                        </div>                                 
                            <div class="form-group mb-2">
                                <label class="form-label">Tanggal Masuk</label> 
                                <input type="date" class="form-control" name="ttgl" required="required" value="<?php echo date('d/m/Y', strtotime($d['tglmasuk'])); ?>">
                            </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>
                  </form>                                      
                </td>
                <td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$akhir_d", 0, ",", "."); ?></td>
                <td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$akhir_k", 0, ",", "."); ?></td>
                <td>  
                    <a data-toggle='tooltip' data-placement='top' title='Buka Data Trans <?php echo $d['perk'] ?>' class="btn btn-primary btn-sm" href="!!_view_trans_per_akunt.php?id=<?php echo $d['noperk'] ?>"><i class="bi bi-eye"></i></a>                                
                </td>
                </tr>   
            <?php };?>  
          </tbody>
        </table>
      </div>
    </div>
  </div>
    </div>
  </div>
</div>

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