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

    $tgl_d = $_GET['tgl_d'];
    $tgl_s = $_GET['tgl_s'];
    $oleh=$_SESSION['id_kar'];
    
    $cmob = mysqli_query($koneksi,"select * from hutang where norek='$id' ");
    $c = mysqli_fetch_assoc($cmob);
    $jenis = mysqli_query($koneksi,"select * from kdjenis_at where kd='$c[kd]' ");
    $j = mysqli_fetch_assoc($jenis); 
    $nrc = mysqli_query($koneksi,"select * from nawal where noperk='$j[akunt_as]' ");
    $n = mysqli_fetch_assoc($nrc);
    $sewa = mysqli_query($koneksi,"select * from kdjenis_at_sewa where kd='$c[kelompok]' ");
    $s = mysqli_fetch_assoc($sewa); 
    
    $sql4 = mysqli_query($koneksi, "SELECT count(norek) AS tjkode FROM hutang_angs WHERE norek='$id' ");
        list($tjkode) = mysqli_fetch_array($sql4);    

?>              

<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 HISTORI HUTANG</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%">No.Rekg / Nama Hutang</th>
                      <th width="1%">:</th>
                      <td><?php echo $id ?> - <?php echo $c['bank'] ?></td>
                    </tr>
                    <tr>
                      <th>Alamat </th>
                      <th>:</th>
                      <td><?php echo $c['alamat'] ?> </td>
                    </tr>
                    <tr>
                      <th>Pokok Hutang</th>
                      <th>:</th>
                      <td><?php echo "Rp.  " . number_format("$c[pokok]", 0, ",", "."); ?> ,-</td>
                    </tr>
                    <tr>
                      <th>Tanggal Transaksi / Jangka Waktu </th>
                      <th>:</th>
                      <td><?php echo date('d/m/Y', strtotime($c['tanggal'])); ?> / <?php echo $c['jkw'] ?> bulan</td>
                    </tr>
                    <tr>
                      <th>Angsuran Per Bulan </th>
                      <th>: </th>
                      <td><?php echo "Rp.  " . number_format("$c[angsuran]", 0, ",", "."); ?> ,-</td>
                    </tr>

                  </table>
<!-- ////////////////////////// Jor //////////////// -->          
<?php if ($tjkode>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;">Pokok</th>
              <th width="1%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Jasa</th>
              <th width="1%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Jumlah</th>
              <th width="12%" 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;
              //and tanggal>='$tgl_d' and tanggal<='$tgl_s' 
            $jor = mysqli_query($koneksi,"SELECT * FROM hutang_angs WHERE norek=$id ORDER BY id ASC ");
            while($p = mysqli_fetch_array($jor)){
                $byrjumlah=$p['byrpokok']+$p['byrbunga'];
                $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: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 $k['keterangan'] ?></td>
                <td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$p[byrpokok]", 0, ",", "."); ?></td>
                <td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$p[byrbunga]", 0, ",", "."); ?></td>
                <td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$byrjumlah", 0, ",", "."); ?></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 onclick="return confirm('Yakin ingin hapus transaksi No : <?php echo $p['notrans'] ?> <?php echo $k['keterangan'] ?>.....?')" class="btn btn-danger btn-sm" href="@_hutang_trans_hapus.php?notrans=<?php echo $p['notrans'] ?>&oleh=<?php echo $oleh ?>&norek=<?php echo $id ?>">
                            <i class="bi bi-trash"></i>
                    </a>
<!--                  <a onclick="return confirm('Yakin ingin hapus data No <?php echo $d['angg_no']; ?> a/n <?php echo $d['nama']; ?> - <?php echo $d['alamat']; ?> ?')" class="btn btn-danger btn-sm" href="angg_hapus.php?id=<?php echo $d['angg_id'] ?>&oleh=<?php echo $oleh ?>">
                    <i class="bi bi-trash"></i>
                  </a>                          
-->
                </td>           
                </tr>    


  
                        </div>
                      </div>
                    </div>
                  </form>                      
              <?php } ?>
          </tbody>
                        <?php 
                $sql3a = mysqli_query($koneksi, "SELECT sum(byrpokok) AS tbyrpokok,sum(byrbunga) AS tbyrbunga FROM hutang_angs WHERE norek=$id");
                list($tbyrpokok,$tbyrbunga) = mysqli_fetch_array($sql3a); 
                $tbyrjumlah=$tbyrpokok+$tbyrbunga;
                $tsisa=$c['pokok']-$tbyrpokok;
            	        ?>						
							<tr>
						    	<td colspan="4" style="font-weight: bold;text-align: center;">Total </td>	
								<td align='right'><style="font-weight: bold;">
								    <font color='#ff0000'><?php echo "" . number_format("$tbyrpokok", 0, ",", "."); ?></font>
								</td>
								<td align='right'><style="font-weight: bold;">
								    <font color='#ff0000'><?php echo "" . number_format("$tbyrbunga", 0, ",", "."); ?></font>
								</td>
								<td align='right'><style="font-weight: bold;">
								    <font color='#ff0000'><?php echo "" . number_format("$tbyrjumlah", 0, ",", "."); ?></font>
								</td>								
								<td align='right'><style="font-weight: bold;">
								    <?php echo ""; ?>
								</td>
							</tr>       
							<tr>
						    	<td colspan="4" style="font-weight: bold;text-align: center;">SALDO HUTANG </td>	
								<td align='right'><style="font-weight: bold;">
								    <font color='#ff0000'><?php echo "" . number_format("$tsisa", 0, ",", "."); ?></font>
								</td>
								<td align='right'><style="font-weight: bold;">
								    <?php echo ""; ?>
								</td>
								<td align='right'><style="font-weight: bold;">
								    <?php echo ""; ?>
								</td>
								<td align='right'><style="font-weight: bold;">
								    <?php echo ""; ?>
								</td>								
							</tr>       							
        </table>
       </div> 
    </div>    
<!-- ////////////////////////// MEMBUAT FORM ACC  //////////////// -->         
        <?php } else { ?>
                <font color='#ff0000'  style="text-align:left; font-size: 8pt; font-weight:normal;"><i>Aset <?php echo $c['nama'] ?> belum ada transaksi....</i></font><br>
        <?php } ?>
<!-- ////////////////////////// SELESAI PERMOHONAN  //////////////// --> 
                </div>
              </div>
              </div>
            </form>
          </div>
      </div>
    </div>
  </div>
</div>
<?php include 'footer.php'; ?>