
<?php 
    include 'header.php'; 
    $id = $_GET['id'];
    $unit = $_GET['unit'];
    if ($unit=='03') {
        $ket='Semua Jenis Transaksi' ;
    } else if ($unit=='01') {
        $ket='Khusus Transaksi Zakat' ;
    } else if ($unit=='02') {
        $ket='Khusus Transaksi Non Zakat' ;
    }
    $nawal = mysqli_query($koneksi,"select * from nawal where noperk='$id'");
    $n = mysqli_fetch_assoc($nawal);  
    $awalk=$n['awalk'];
    $awald=$n['awald'];
    $awal=$awald+$awalk;
    
    $tgl_d='2025-01-01' ;
    $tgl_s=date('Y-m-d') ;
    
    $xn1=substr($n['noperk'],-5,1);
    $xn2=substr($n['noperk'],-5,2);
    $xn3=substr($n['noperk'],-5,3);

    $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='$xn2'");
    $n2 = mysqli_fetch_assoc($n_kode_2);
    $n_kode_3 = mysqli_query($koneksi,"select * from n_kode_3 where kd='$xn3'");
    $n3 = mysqli_fetch_assoc($n_kode_3);    

    $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-12">
       <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'] ?></td>
                    </tr>
                    <tr>
                      <th>Keterangan </th>
                      <th>:</th>
                      <td><?php echo $ket ?></td>
                    </tr>                    
<!--                    
                    <tr>
                      <th>Menu Lanjutan </th>
                      <th>:</th>
                      <td>
                          <a href="!!_view_trans_per_akunt_print.php?id=<?php echo $id ?>&tgl_dr=<?php echo date('Y-m-d', strtotime($tgl_d)); ?>&tgl_sd=<?php echo date('Y-m-d', strtotime($tgl_s)); ?>" target="_blank" class="btn btn-warning btn-sm"><i class="bi bi-printer"></i> &nbsp Print</a>
                          <a href="!!_view_trans_per_akunt_zakat.php?tgl_dr=<?php echo date('Y-m-d', strtotime($tgl_d)); ?>&tgl_sd=<?php echo date('Y-m-d', strtotime($tgl_s)); ?>" class="btn btn-primary btn-sm"><i class="bi bi-eye"></i> &nbsp Lihat Yg ZAKAT</a>
                          <a href="!!_view_trans_per_akunt_nonzakat.php?tgl_dr=<?php echo date('Y-m-d', strtotime($tgl_d)); ?>&tgl_sd=<?php echo date('Y-m-d', strtotime($tgl_s)); ?>" class="btn btn-secondary btn-sm"><i class="bi bi-eye"></i> &nbsp Lihat yg Non Zakat</a>
                          <a href="@_angg_tgl_sd_tgl.php?tgl_dr=<?php echo date('Y-m-d', strtotime($tgl_d)); ?>&tgl_sd=<?php echo date('Y-m-d', strtotime($tgl_s)); ?>" class="btn btn-info btn-sm pull-right"><i class="bi bi-reply"></i> &nbsp; Kembali</a> 
<a href="!!_view_trans_per_akunt_excell.php?tgl_dr=<?php echo date('Y-m-d', strtotime($tgl_d)); ?>&tgl_sd=<?php echo date('Y-m-d', strtotime($tgl_s)); ?>" class="btn btn-success btn-sm"><i class="bi bi-file-word"></i> &nbsp Excell</a>

                      </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="8%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Kd1</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="16%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Opsi</th>
            </tr>
          </thead>
          <tbody>
            <?php 
              $no   = 1;
              $awal = $awal;
              $debet  = 0;
              $kredit  = 0;
            if ($unit=='03') {  
                $jor = mysqli_query($koneksi,"SELECT * FROM jor WHERE noperk=$id ORDER BY id ASC ");
            } else if ($unit=='01') {
                $jor = mysqli_query($koneksi,"SELECT * FROM jor WHERE noperk=$id and unit='01' ORDER BY id ASC ");
            } else {
                $jor = mysqli_query($koneksi,"SELECT * FROM jor WHERE noperk=$id and unit<>'01' 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'] ;                    
                }
                if ($p[unit]=='01') {;
                    $unit='01' ;
                } else { ;
                    $unit='02' ;
                }
                
                $kas = mysqli_query($koneksi,"select * from kas where notrans='$p[notrans]'");
                    $k = mysqli_fetch_assoc($kas);  
                $jor2 = mysqli_query($koneksi,"select * from jor where notrans='$p[notrans]' and noperk<>'$id'");
                    $j2 = mysqli_fetch_assoc($jor2);   
                    
                    
                
              ?>
              <tr>
                <td><?php echo $no++; ?></td>
                <td style="text-align:center; font-size: 10pt; font-weight:normal;"><?php echo $p['notrans'] ?></td>
                <td style="text-align:center; 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:center; font-size: 10pt; font-weight:normal;"><?php echo $j2['noperk'] ?>-<?php echo $k['oleh'] ?>-<?php echo $unit ?></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>                                
<!--                    <a data-toggle='tooltip' data-placement='top' title='Cetak kuitansi <?php echo $t['notrans'] ?> a/n <?php echo $a['nama']; ?>' style='margin-right:3px' class="btn btn-success btn-sm" href="@_angg_kuitansi.php?tid=<?php echo $t['notrans'] ?>&angg_no=<?php echo $noang ?>" target="_blank" ><i class="bi bi-aspect-ratio"></i></a>

-->
                    
                        
                            <?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-aspect-ratio"></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-aspect-ratio"></i></a> 
                            <?php } ;?>
                    <?php if ($k['td']=='01') { ?>     
                          <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'; ?>