
<?php 
    include 'header.php'; 

    $level=$_SESSION['level'];
    $thn = date('Y');
    $bln = date('m');   
    $oleh=$_SESSION['id'];
    $kdc=$_SESSION['kdc'];
    
                $sql20 = mysqli_query($koneksi, "SELECT sum(awald) AS tawald,sum(awalk) AS tawalk FROM nawal ");
                list($tawald,$tawalk) = mysqli_fetch_array($sql20);
                $selisih=$tawald-$tawalk;
                
    if ($tawald==$tawalk) { ;
        $ket='AKUNT BUKU BESAR BALANCE';
    } else {
        $ket='NERACA AWAL ANDA TIDAK BALANCE - BEDA : '.number_format("$selisih", 0, ",", ".").'';
    }
?>

<div class="container">

 <div class="my-4 border-bottom">
   <h2 class="fw-semibold fs-3"><?php echo $ket ?></h2>
 </div>

              <div class="row">
                <div class="col-lg-12">
                  <table class="table table-bordered">
                    <tr>
                      <th width="20%">Buka Data : </th>
                      <th width="1%">:</th>
                      <td>
                      <a href="kode_akunt_new_kelompok.php" class="btn btn-info btn-sm"><i class="bi bi-eye"></i> &nbsp DATA KELOMPOK</a>
                      <a href="kode_akunt_new_sub.php" class="btn btn-secondary btn-sm"><i class="bi bi-eye"></i> &nbsp DATA SUB</a>
                      <a href="#" class="btn btn-warning btn-sm"><i class="bi bi-eye"></i> &nbsp DATA UNIT </a>
                      <a href="index.php" class="btn btn-primary btn-sm"><i class="bi bi-reply-all"></i> &nbsp Kembali</a> 
                      </td>
                    </tr>   
                  </table>
                </div>
              </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">Kode Akunt Buku Besar</span> 
            <div>
                <button type="button" class="btn btn-primary btn-sm" data-bs-toggle="modal" data-bs-target="#exampleModal"> 
                    <i class="bi bi-plus"></i> Tambah 
                </button>
            </div>
        </div>
    
    <div class="card-body">




      <!-- Modal -->
      <form action="kode_akunt_new_tambah_act.php" method="post">
        <div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
          <div class="modal-dialog">
            <div class="modal-content">
              <div class="modal-header">
                <h1 class="modal-title fs-5" id="exampleModalLabel">Tambah Akunt Buku Besar</h1>
                <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']; ?>;">                  
                <div class="form-group">
                  <label>Nama Akunt </label>
                  <input type="hidden" name="oleh" value="<?php echo $oleh ?>" readonly="readonly" class="form-control" >
                  <input type="hidden" name="id" value="<?php echo $kdc ?>" readonly="readonly" class="form-control" >
                  <input type="hidden" name="kdc" value="<?php echo $kdc ?>" readonly="readonly" class="form-control" >
                  <input type="text" name="nama" required="required" class="form-control" placeholder="Isi Nama Akunt ..">
                </div>
                        	<div class="form-group">
                                <label class="form-label">Sub Kode Kelompok <font color='#ff0000'><i>(pilih Sub Kode Kelompok)</i></font color></label>
                                <select class="form-control" name="nosub" required="required">
                                  <option value="">- Pilih Sub Kode Kelompok -</option>
                                  <?php 
                                  $kode_2 = mysqli_query($koneksi,"select * from n_kode_3 order by kd ASC");
                                  while($k = mysqli_fetch_array($kode_2)){
                                    ?>
                                    <option value="<?php echo $k['kd'] ?>"><?php echo $k['kd'] ?> - <?php echo $k['nama'] ?></option>
                                    <?php 
                                  }
                                  ?>
                                </select>
                        	</div>         
                          <div class="form-group">
                                <label class="form-label">Kelompok Arus Kas <font color='#ff0000'><i>(pilih Kelompok Arus Kas)</i></font color></label>
                                <select class="form-control" name="noak" required="required" value="<?php echo $d['ry'] ;?>" >
                                  <option value="">- Pilih Kelompok Arus Kas -</option>
                                  <?php 
                                  $nakas = mysqli_query($koneksi,"select * from n_arus_kas WHERE yt<>'x' order by kd ASC");
                                  while($ak = mysqli_fetch_array($nakas)){
                                    ?>
                                    <option value="<?php echo $ak['kd'] ?>"<?php if($ak['kd'] == $d['ry']) echo 'selected="selected"'; ?>><?php echo $ak['kd'] ?> - <?php echo $ak['nama'] ?></option>
                                    <?php 
                                  }
                                  ?>
                                </select>
                          </div>          
<!--                     	
                        	<div class="form-group">
                                <label class="form-label">Unit <font color='#ff0000'><i>(pilih Unit)</i></font color></label>
                                <select class="form-control" name="kdu" required="required">
                                  <option value="">- Pilih Unit -</option>
                                  <?php 
                                  $unit = mysqli_query($koneksi,"select * from kd_unit order by kd ASC");
                                  while($u = mysqli_fetch_array($unit)){
                                    ?>
                                    <option value="<?php echo $u['kd'] ?>"><?php echo $u['kd'] ?> - <?php echo $u['nama'] ?></option>
                                    <?php 
                                  }
                                  ?>
                                </select>
                        	</div>         
-->
                </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>
</div>        
      </form>

    <div>
      <div class="table-responsive">
        <table class="table table-bordered table-striped" id="table-datatable">
          <thead>
            <tr>
              <th width="1%" class="text-center">No</th>
              <th width="1%" class="text-center">Kode</th>
              <th width="25%" class="text-center">NAMA</th>
              <th width="15%" class="text-center">KELOMPOK</th>
              <th width="20%" class="text-center">SUB</th>
              <th width="1%" class="text-center">U</th>
              <th width="1%" class="text-center">Ak</th>
              <th width="1%" class="text-center">Awal D</th>
              <th width="1%" class="text-center">Awal K</th>
              <th width="1%" class="text-center">Anggaran</th>
              <th width="15%" class="text-center">OPSI</th>
            </tr>
          </thead>
          <tbody>
            <?php 
            $no=1;
            $data = mysqli_query($koneksi,"SELECT * FROM nawal ORDER BY noperk ASC");
            while($d = mysqli_fetch_array($data)){
                $id=$d['id'];
                $no_sub=$d['nosub'];
                
                $sql0 = mysqli_query($koneksi, "SELECT count(noperk) AS tjnoperk FROM jor WHERE noperk='$d[noperk]' ");
                list($tjnoperk) = mysqli_fetch_array($sql0); 
                $sql1 = mysqli_query($koneksi, "SELECT nama AS nama_klp FROM n_kode_2 WHERE kd='$d[klp]' ");
                list($nama_klp) = mysqli_fetch_array($sql1);          
                $sql3 = mysqli_query($koneksi, "SELECT nama AS nama_sub FROM n_kode_3 WHERE kd='$d[nosub]' ");
                list($nama_sub) = mysqli_fetch_array($sql3);               
                    /////////// 
                //mysqli_query($koneksi, "UPDATE nawal SET unit='$d[kdu]' WHERE id='$id'")or die(mysqli_errno());


              ?>
              <tr>
               <td><?php echo $no++; ?></td>
                <td><?php echo $d['noperk']; ?></td>
                <td><?php echo $d['perk']; ?></td>
                <td align='left'> <?php echo $d['klp']; ?> <?php echo $nama_klp; ?></td>
                <td align='left'><?php echo $d['nosub']; ?> <?php echo $nama_sub; ?></td>
                <td align='center'><?php echo $d['kdu']; ?></td>
                <td align='center'><?php echo $d['ry']; ?></td>
                <td align='right'><?php echo "" . number_format("$d[awald]", 0, ",", "."); ?></td>                
                <td align='right'><?php echo "" . number_format("$d[awalk]", 0, ",", "."); ?></td>  
                <td align='right'><?php echo "" . number_format("$d[anggar]", 0, ",", "."); ?></td>  
                <td>    
                    <a class="btn btn-warning btn-sm" title="Edit Nama Perkiraan Bu Bes <?php echo $d['noperk'] ?>-<?php echo $d['perk'] ?>" data-bs-toggle="modal" data-bs-target="#edit_akunt_<?php echo $d['id'] ?>"><i class="bi bi-gear"></i></a>
                    <a class="btn btn-primary btn-sm" title="Edit / Ganti Kode Nosub <?php echo $d['nosub']; ?> <?php echo $nama_sub; ?>" data-bs-toggle="modal" data-bs-target="#edit_nosub_<?php echo $d['nosub']; ?><?php echo $d['noperk']; ?>"><i class="bi bi-gear"></i></a>
                    <?php if ($tjnoperk<=0) {?>
                    <a onclick="return confirm('Yakin ingin hapus akunt <?php echo $d['perk']; ?>.....?')" class="btn btn-danger btn-sm" href="kode_akunt_new_hapus.php?id=<?php echo $d['id'] ?>">
                            <i class="bi bi-trash"></i>
                    </a>
                    <?php } ?>     
<!---- FORM EDIT AKUNT   ---------->                  
                  <form action="kode_akunt_new_edit_act.php" method="post">
                    <div class="modal fade" id="edit_akunt_<?php echo $d['id'] ?>" 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">Edit Nama Akunt <?php echo $d['noperk']; ?> - <?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 style="background-color: <?php echo$_SESSION['warna_bag']; ?>; padding: 15px; border-radius: 15px; box-shadow: 0 0 15px <?php echo$_SESSION['warna_bag']; ?>;">
                <div class="form-group">
                  <label>Nama Akunt </label>
                  <input type="hidden" name="oleh" value="<?php echo $oleh ?>" readonly="readonly" class="form-control" >
                  <input type="hidden" name="kdc" value="<?php echo $kdc ?>" readonly="readonly" class="form-control" >
                  <input type="text" name="id" value="<?php echo $id ?>" readonly="readonly" class="form-control" >
                  <input type="text" name="nama" required="required" class="form-control" value="<?php echo $d['perk'] ?>">
                </div>
                        	<div class="form-group">
                                <label class="form-label">Sub Kode Kelompok <font color='#ff0000'><i>(pilih Sub Kode Kelompok)</i></font color></label>
                                <select class="form-control" name="nosub" required="required" value="<?php echo $d['nosub'] ;?>" >
                                  <option value="">- Pilih Sub Kode Kelompok -</option>
                                  <?php 
                                  $kode_2 = mysqli_query($koneksi,"select * from n_kode_3 order by kd ASC");
                                  while($k = mysqli_fetch_array($kode_2)){
                                    ?>
                                    <option value="<?php echo $k['kd'] ?>"<?php if($k['kd'] == $d['nosub']) echo 'selected="selected"'; ?>><?php echo $k['kd'] ?> - <?php echo $k['nama'] ?></option>
                                    <?php 
                                  }
                                  ?>
                                </select>
                        	</div>         
                          <div class="form-group">
                                <label class="form-label">Kelompok Arus Kas <font color='#ff0000'><i>(pilih Kelompok Arus Kas)</i></font color></label>
                                <select class="form-control" name="noak" required="required" value="<?php echo $d['ry'] ;?>" >
                                  <option value="">- Pilih Kelompok Arus Kas -</option>
                                  <?php 
                                  $nakas = mysqli_query($koneksi,"select * from n_arus_kas WHERE yt<>'x' order by kd ASC");
                                  while($ak = mysqli_fetch_array($nakas)){
                                    ?>
                                    <option value="<?php echo $ak['kd'] ?>"<?php if($ak['kd'] == $d['ry']) echo 'selected="selected"'; ?>><?php echo $ak['kd'] ?> - <?php echo $ak['nama'] ?></option>
                                    <?php 
                                  }
                                  ?>
                                </select>
                          </div>          
         <!--            	
                        	<div class="form-group">
                                <label class="form-label">Unit <font color='#ff0000'><i>(pilih Unit)</i></font color></label>
                                <select class="form-control" name="kdu" required="required" value="<?php echo $d['kdu'] ;?>" >
                                  <option value="">- Pilih Unit -</option>
                                  <?php 
                                  $unit = mysqli_query($koneksi,"select * from kd_unit order by kd ASC");
                                  while($u = mysqli_fetch_array($unit)){
                                    ?>
                                    <option value="<?php echo $u['kd'] ?>"<?php if($u['kd'] == $d['kdu']) echo 'selected="selected"'; ?>><?php echo $u['kd'] ?> - <?php echo $u['nama'] ?></option>
                                    <?php 
                                  }
                                  ?>
                                </select>
                        	</div>       
        -->                	
                <div class="form-group">
                  <label>Jumlah Saldo Awal (Debet) </label>
                  <input type="text" class="form-control nilai rupiah" id="nilai" name="tawald" required="required" value="<?php echo "" . number_format("$d[awald]", 0, ",", "."); ?>">
                </div>
                <div class="form-group">
                  <label>Jumlah Saldo Awal (Kredit) </label>
                  <input type="text" class="form-control nilai rupiah" id="nilai" name="tawalk" required="required" value="<?php echo "" . number_format("$d[awalk]", 0, ",", "."); ?>">
                </div>                
                <div class="form-group">
                  <label>Jumlah Anggaran (Tahunan) </label>
                  <input type="text" class="form-control nilai rupiah" id="nilai" name="tanggar" required="required" value="<?php echo "" . number_format("$d[anggar]", 0, ",", "."); ?>">
                </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>
            </div>                    
            </form>

<!---- FORM EDIT AKUNT  ---SELESAI------->                         
                    
<!---- FORM EDIT NOSUB ---------->                  
                  <form action="kode_akunt_new_sub_edit_act.php" method="post">
                    <div class="modal fade" id="edit_nosub_<?php echo $d['nosub']; ?><?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">Edit Keterangan <?php echo $d['nosub']; ?> <?php echo $nama_sub; ?></h1>
                            <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']; ?>;">
                                  <?php 
                                  $kode_2 = mysqli_query($koneksi,"select * from n_kode_3 where kd='$d[nosub]' order by id ASC");
                                  while($k = mysqli_fetch_array($kode_2)){
                                      $id_sud=$k['id'] ;
                                  }  
                                    ?>                    
                <div class="form-group">
                    <label><font color="#000fff">Kode Sub</font></label>
                    <input type="text" name="tid" readonly="readonly" class="form-control" value="<?php echo $id_sud; ?>">
                    <input type="text" name="tnosub" required="required" class="form-control" value="<?php echo $d['nosub']; ?>">
                </div>
  
                <div class="form-group" style="width:100%">
                  <label><font color="#000fff">Nama Sub</font></label>
                  <input type="text" name="tnamasub" required="required" class="form-control" value="<?php echo $nama_sub; ?>" style="width:100%">
                </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>
            </div>                    
            </form>
<!---- FORM EDIT NOSUB ---SELESAI ------->     
                  </td>
<!---- FORM EDIT KELOMPOK  ----------> 

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

                        <?php 
                $sql2 = mysqli_query($koneksi, "SELECT sum(awald) AS tawald,sum(awalk) AS tawalk,sum(anggar) AS tanggar FROM nawal ");
                list($tawald,$tawalk,$tanggar) = mysqli_fetch_array($sql2);

            	        ?>						
                <tr>
                    <td colspan="7" style="font-weight: bold;text-align: center;background-color: <?php echo$_SESSION['warna_bag']; ?>;">Total</td>
                    <td align='right' style="font-weight: bold;background-color: <?php echo$_SESSION['warna_bag']; ?>;"><?php echo "" . number_format("$tawald", 0, ",", "."); ?></td>
                    <td align='right' style="font-weight: bold;background-color: <?php echo$_SESSION['warna_bag']; ?>;"><?php echo "" . number_format("$tawalk", 0, ",", "."); ?></td>
                    <td align='right' style="font-weight: bold;background-color: <?php echo$_SESSION['warna_bag']; ?>;"><?php echo "" . number_format("$tanggar", 0, ",", "."); ?></td>
                    <td align='right' style="font-weight: bold;background-color: <?php echo$_SESSION['warna_bag']; ?>;"><?php echo "" ; ?></td>
                </tr>	
                
        </table>
      </div>
    </div>

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

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