
<?php 
    session_start();
    include 'header.php'; 
    $id = $_GET['id'];

    $nawal = mysqli_query($koneksi,"select * from nawal where noperk='$id'");
    $n = mysqli_fetch_assoc($nawal);  
    $awalk=$n['awalk'];
    $awald=$n['awald'];
    $klp=$n['klp'];
    $nosub=$n['nosub'];
    
    $n_awal=$awald+$awalk;
    $n_akhir=$n['akhird'];+$n['akhirk'];
    
    
    $xn1=substr($n['noperk'],-5,1);

    $n_kode_1 = mysqli_query($koneksi,"select * from n_kode_1 where kd1='$xn1'");
    $n1 = mysqli_fetch_assoc($n_kode_1); 
    $n_kode_2 = mysqli_query($koneksi,"select * from n_kode_2 where kd='$klp'");
    $n2 = mysqli_fetch_assoc($n_kode_2);
    $n_kode_3 = mysqli_query($koneksi,"select * from n_kode_3 where kd='$nosub'");
    $n3 = mysqli_fetch_assoc($n_kode_3);    

//$kalimat = "Belajar PHP di Duniailkom";
//$sub_kalimat = substr($kalimat,-10,-3);
//echo $sub_kalimat;
// Duniail

    $tgl_d = $_GET['tgl_d'];
    $tgl_s = $_GET['tgl_s'];
    
    $sql1 = mysqli_query($koneksi, "SELECT count(noperk) AS tnoperk,sum(debet) AS tdbt,sum(kredit) AS tkrd FROM jor WHERE noperk='$id' ");
        list($tnoperk,$tdbt,$tkrd) = mysqli_fetch_array($sql1);

?>              

<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 TRANSAKSI PER AKUNT</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%">Nama Akunt</th>
                      <th width="1%">:</th>
                      <td><?php echo $n['perk'] ?></td>
                    </tr>
                    <tr>
                      <th>Nama Kelompok Akunt </th>
                      <th>:</th>
                      <td><?php echo $n1['nama'] ?> / <?php echo $n2['nama'] ?> / <?php echo $n3['nama'] ?> </td>
                    </tr>
                    <tr>
                      <th>No. Akunt</th>
                      <th>:</th>
                      <td><?php echo $n['noperk'] ?> - <?php echo $n['klp'] ?> - <?php echo $n['ry'] ?></td>
                    </tr>
                    <tr>
                      <th>Dari Tanggal s/d Tanggal</th>
                      <th>:</th>
                      <td><?php echo date('d/m/Y', strtotime($tgl_d)); ?> s/d <?php echo date('d/m/Y', strtotime($tgl_s)); ?></td>
                    </tr>
<!--                    
                    <tr>
                      <th>Saldo Awal (per <?php echo date('d/m/Y', strtotime($tgl_d)); ?>) </th>
                      <th>: </th>
                      <td><?php echo "Rp.  " . number_format("$n_awal", 0, ",", "."); ?> ,-</td>
                    </tr>
                    <tr>
                      <th>Saldo Akhir (per <?php echo date('d/m/Y', strtotime($tgl_s)); ?>) </th>
                      <th>: </th>
                      <td><?php echo "Rp.  " . number_format("$n_akhir", 0, ",", "."); ?> ,-</td>
                    </tr>
-->
                  </table>
<!-- ////////////////////////// Jor //////////////// -->          
<?php if ($tnoperk>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;">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;">Saldo</th>
              <th width="14%" 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;
            $jor = mysqli_query($koneksi,"SELECT * FROM jor WHERE noperk=$id and tanggal>='$tgl_d' and tanggal<='$tgl_s' ORDER BY id ASC ");
            while($p = mysqli_fetch_array($jor)){
                if (($n['klp']<='20') or ($n['klp']>='50')) { ;
                    $kredit=$p['kredit'] ;
                    $debet=$p['debet'] ;                    
                } else {
                    $debet=$p['kredit'] ;
                    $kredit=$p['debet'] ;                    
                }
                $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 $p['keterangan'] ?></td>
                <td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$p[debet]", 0, ",", "."); ?></td>
                <td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$p[kredit]", 0, ",", "."); ?></td>
                <td align='right' style="font-weight: bold;">
                        <?php 
                            // SALDO                      
                        if($kredit-$debet>0){
                          $awal = $awal - ($kredit-$debet);
                        }else if($debet-$kredit>0){
                          $awal = $awal + ($debet-$kredit);
                        } 
                        echo "" . number_format("$awal", 0, ",", ".")."";
                        ?>	
                                    <?php   
                                    // DEBIT  
                                    if($kredit-$debet>0){
                                        $deb = $deb +($kredit-$debet);
                                    }   
                                    ?>

                                    <?php   
                                    // KREDIT  
                                    if($debet-$kredit>0){
                                        $kre = $kre + ($debet-$kredit);
                                    }
                                    ?>

                </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>                                
                 
                    <?php if ($k['td']=='01') { ?> 
                        <?php if ($p['kredit']>=1) { ;?> 
                            <a data-toggle='tooltip' data-placement='top' title='Cetak Bukti Kas Keluar <?php echo $p['notrans']; ?> senilai <?php echo "Rp." . number_format("$p[kredit]", 0, ",", "."); ?>' style='margin-right:3px' class="btn btn-success btn-sm" href="@@_kuit_kk.php?notrans=<?php echo $p[notrans] ?>" target="_blank" ><i class="bi bi-printer"></i></a> 
                        <?php } else { ; ?>
                            <a data-toggle='tooltip' data-placement='top' title='Cetak Bukti Kas Masuk <?php echo $p['notrans']; ?> senilai <?php echo "Rp." . number_format("$p[debet]", 0, ",", "."); ?>' style='margin-right:3px' class="btn btn-success btn-sm" href="@@_kuit_km.php?notrans=<?php echo $p[notrans] ?>" target="_blank" ><i class="bi bi-printer"></i></a> 
                        <?php } ;?>
                          <a onclick="return confirm('Yakin ingin hapus transaksi : <?php echo $p['keterangan'] ?>.....?')" class="btn btn-danger btn-sm" href="!!_kas_trans_hapus.php?id=<?php echo $p['notrans'] ?>&oleh=<?php echo $oleh ?>&noperk=<?php echo $id ?>">
                            <i class="bi bi-trash"></i>
                          </a>
                    <?php } ?>

                </td>           
                </tr>    


  
                        </div>
                      </div>
                    </div>
                  </form>                      
              <?php } ?>
          </tbody>
        </table>
       </div> 
    </div>    
<!-- ////////////////////////// MEMBUAT FORM ACC  //////////////// -->         
        <?php } else { ?>
                <font color='#ff0000'  style="text-align:left; font-size: 8pt; font-weight:normal;"><i>Akunt <?php echo $n['perk'] ?> belum ada transaksi....</i></font><br>
        <?php } ?>
<!-- ////////////////////////// SELESAI PERMOHONAN  //////////////// --> 
                </div>
              </div>
              </div>
            </form>
          </div>
      </div>
    </div>
  </div>
</div>
<?php include 'footer.php'; ?>