<?php 
    include 'header.php'; 
?>            
<div class="container">

  <div class="my-4 border-bottom">
    <h4 class="fw-semibold fs-4">Laporan Buku Kas Per Jenis
    </h4>  
  </div>
  <section class="content">
    <div class="row">
      <section class="col-lg-14">
        <div class="box box-info">
          <div class="box-header">
          <div class="box-body">
            <form method="get" action="">

            </form>
          </div>
        </div>
        
        <div class="box box-info">
          <div class="box-header">
            <h6 class="box-title"></h6>
          </div>
          <div class="box-body">
            <?php 
            //if(isset($_GET['tgl_dr']) && isset($_GET['tgl_sd']) && isset($_GET['tkdj'])) {
              $tgl_d = $_GET['tgl_dr'];
              $tgl_s = $_GET['tgl_sd'];
              $kdj   = $_GET['id'];
            //}
            
                 $sql1 = mysqli_query($koneksi, "SELECT sum(awald) as tn_awal,perk FROM nawal WHERE noperk='$kdj' ");
                    list($tn_awal,$perk) = mysqli_fetch_array($sql1);
                    
                $sql2 = mysqli_query($koneksi, "SELECT sum(debet-kredit) as tj_awal FROM jor WHERE noperk='$kdj' and tanggal<='$tgl_d' ");
                    list($tj_awal) = mysqli_fetch_array($sql2);                    
                
                $tsaldo_awal=$tn_awal+$tj_awal;
                
              ?>

              <div class="row">
                <div class="col-lg-6">
                  <table class="table table-bordered">
                    <tr>
                      <th width="30%">DARI TANGGAL</th>
                      <th width="1%">:</th>
                      <td><?php echo date('d-m-Y', strtotime($tgl_d)); ?></td>
                    </tr>
                    <tr>
                      <th>SAMPAI TANGGAL</th>
                      <th>:</th>
                      <td><?php echo date('d-m-Y', strtotime($tgl_s)); ?></td>
                    </tr>
                    <tr>
                      <th>Jenis</th>
                      <th>:</th>
                      <td><?php echo $kdj; ?> - <?php echo $perk; ?></td>
                    </tr>                                  
                    <tr>
                      <th>Lanjutan </th>
                      <th>:</th>
                      <td>
                        <a href="javascript:history.back()" class="btn btn-info btn-sm pull-right"><i class="bi bi-reply"></i> &nbsp; Mbalik wae lah</a>
                       </td>
                    </tr>                    
                  </table>
                </div>
              </div>

              <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: 9pt; font-weight:normal;">No</th>
              <th width="1%" class="text-center" style="text-align:left; font-size: 9pt; font-weight:normal;">Notrans</th>
              <th width="4%" class="text-center">Tanggal</th>
              <th width="40%" class="text-center">Uraian</th>
              <th width="10%" class="text-center">Tgl Input</th>
              <th width="1%" class="text-center">Akun</th>
              <th width="1%" class="text-center">Masuk</th>
              <th width="1%" class="text-center">Keluar</th>

            </tr>
          </thead>
          <tbody>
            <?php 
              $no   = 1;
              $awal = $tsaldo_awal ;
              $debet  = 0;
              $kredit  = 0;
              
            $data = mysqli_query($koneksi,"SELECT * FROM jor WHERE noperk='$kdj' and tanggal>='$tgl_d' and tanggal<='$tgl_s' ORDER BY tanggal ASC ");
            while($d = mysqli_fetch_array($data)){
                $notrans  =$d['notrans'] ;
                $nid  =$d['id'] ;
                
                $sql3 = mysqli_query($koneksi, "SELECT keterangan,jam FROM kas WHERE notrans='$notrans' ");
                    list($keterangan,$jam) = mysqli_fetch_array($sql3);  
                    
                $jor2 = mysqli_query($koneksi,"select * from jor where notrans='$notrans' and noperk<>'$kdj' ");
                    $j2 = mysqli_fetch_assoc($jor2);  
                    
                	mysqli_query($koneksi, "update jor set akunt='$j2[noperk]' where id='$nid'");
                	
              ?>
              <tr>
                <td><?php echo $no++; ?></td>
                <td style="text-align:left; font-size: 10pt; font-weight:normal;"><?php echo $d['notrans']; ?></td>
                <td style="text-align:left; font-size: 9pt; font-weight:normal;"><?php echo date('d/m/Y', strtotime($d['tanggal'])); ?></td>
                <td style="text-align:left; font-size: 10pt; font-weight:normal;"><?php echo $keterangan; ?></td>
                <td style="text-align:left; font-size: 9pt; font-weight:normal;"><?php echo $jam; ?></td>
                <td style="text-align:left; font-size: 9pt; font-weight:normal;"><?php echo $j2['noperk'] ?></td>
                <td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$d[debet]", 0, ",", "."); ?></td>
                <td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$d[kredit]", 0, ",", "."); ?></td>

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

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

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