


<?php 
    $kdc    = $_SESSION['kdc'];
    $oleh   = $_SESSION['id_kar'];
    
    $angg_id    = $_GET['id'];


    $tgl_ini=date('d-m-Y') ;
    $tgl_ini2=date('Y-m-d') ;  
    $tahun_ini = date('Y');
    
    $tanggal_awal_tahun = '01-01-' . $tahun_ini;
    $tanggal_akhir_tahun = $tanggal_awal_tahun-1 ;

    $sql1 = mysqli_query($koneksi, "SELECT kelurahan,kecamatan,kota FROM kdkanca WHERE kd='01' ");
                list($kelurahan,$kecamatan,$kota) = mysqli_fetch_array($sql1);
                
    $angg = mysqli_query($koneksi, "SELECT angg_no AS no FROM anggota WHERE angg_id='$angg_id' ");
                list($no) = mysqli_fetch_array($angg);     
    $angg_no    = $no;            
?>              

<div class="container">
  <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">DATA PERMOHONAN PINJAMAN</span>
      <buton>
        <a href="index.php" class="btn btn-primary btn-sm"><i class="bi bi-house-fill"></i> &nbsp Home</a> 
        <?php if ($_SESSION['level']<>'ANGGOTA') { ?>
            <a href="javascript:history.go(-1)" class="btn btn-info btn-sm"><i class="bi bi-reply-all"></i> &nbsp Kembali</a>
        <?php } ?>
      </buton>
    </div>
      <div class="table-responsive">
        <table class="table table-bordered table-striped" id="table-datatable1">
          <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="1%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Jumlah</th>
              <th width="1%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Jkw</th>
              <th width="38%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Jaminan</th>
              <th width="2%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Isi</th>
              <th width="35%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Tujuan</th>
              <th width="16%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Keterangan</th>
              <th width="4%" class="text-center">OPSI</th>
            </tr>
            </tr>
          </thead>
          <tbody>
            <?php 
            $no=1;
            $permohonan = mysqli_query($koneksi,"SELECT * FROM permohonan WHERE hapus<>'HAPUS' and m_angg_no=$d[angg_no] ");
            while($p = mysqli_fetch_array($permohonan)){
                
                $xx_nomor=$p['m_nomor'] ;
                
                $sql1 = mysqli_query($koneksi, "SELECT count(nomor) AS tnomor1 FROM jam_bpkb WHERE nomor='$p[m_nomor]' and left(add_ket,4)<>'Digg' ");
                list($tnomor1) = mysqli_fetch_array($sql1);
                $sql2 = mysqli_query($koneksi, "SELECT count(nomor) AS tnomor2 FROM jam_sertif WHERE nomor='$p[m_nomor]' and left(add_ket,4)<>'Digg' ");
                list($tnomor2) = mysqli_fetch_array($sql2);
                $sql3 = mysqli_query($koneksi, "SELECT count(nomor) AS tnomor3 FROM jam_lain WHERE nomor='$p[m_nomor]' and left(add_ket,4)<>'Digg'");
                list($tnomor3) = mysqli_fetch_array($sql3);                
                
                if ($tnomor1>0) { ;
                  $ket1 = $tnomor1.' BPKB' ;
                } else {
                  $ket1 = '' ;  
                };
                
                if ($tnomor2>0) { ;
                  $ket2 = $tnomor2.' Sertif' ;
                } else {
                  $ket2 = '' ;  
                };                
                if ($tnomor3>0) { ;
                  $ket3 = $tnomor3.' Lain' ;
                } else {
                  $ket3 = '' ;  
                };     
                
                $ket_jam = $ket1.', '.$ket2.', '.$ket3 ;
                $m_nomor = $p['m_nomor'] ;
                
                $permoh_cair = mysqli_query($koneksi,"select * from permoh_cair where m_nomor='$m_nomor' ");
                $pc = mysqli_fetch_assoc($permoh_cair);
                $pinjaman = mysqli_query($koneksi,"select * from pinjaman where m_nomor='$m_nomor' ");
                $pj = mysqli_fetch_assoc($pinjaman);                
                
                

                $query = "SELECT IF(m_nomor = '$m_nomor', 'SUDAH CAIR', 'BELUM') AS status 
                          FROM pinjaman
                          WHERE m_nomor = '$m_nomor'";
                
                $result = mysqli_query($koneksi, $query);
                
                if (mysqli_num_rows($result) > 0) {
                  $row = mysqli_fetch_assoc($result);
                  //echo "Status: " . $row['status'];
                  $ket=$row['status'];
                } else {
                  //echo "Status: BELUM";
                  $ket=$pc['catatan'];
                }

              ?>
              <tr>
                <td><?php echo $no++; ?></td>
                <td style="text-align:left; font-size: 10pt; font-weight:normal;"><?php echo $p['m_nomor'] ?></td>
                <td style="text-align:left; font-size: 10pt; font-weight:normal;"><?php echo date('d/m/Y', strtotime($p['m_tanggal'])); ?></td>
                <td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$p[m_pokok]", 0, ",", "."); ?></td>
                <td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$p[m_jkw]", 0, ",", "."); ?></td>
                <td style="text-align:left; font-size: 10pt; font-weight:normal;"><?php echo $p['m_jaminan']; ?></td>
                <td> 
                    <?php if($p['m_jaminan']=="BPKB"){ ?>    
                        <a data-toggle='tooltip' data-placement='top' title='Isi data Jaminan BPKB permohonan <?php echo $p['m_nomor'] ?>' style='margin-right:3px' class="btn btn-primary btn-sm" href="jaminan_bpkb_tambah.php?nomor=<?php echo $p['m_nomor'] ?>&noangg=<?php echo $p['m_angg_no'] ?>"><i class="bi bi-truck"></i></a>
                    <?php } ?>
                    
                    <?php if($tnomor2>=1){ ?>    
                        <a data-toggle='tooltip' data-placement='top' title='Lihat Jaminan Sertifikat <?php echo $norek ?> a/n <?php echo $angg_nama; ?>' style='margin-right:3px' class="btn btn-info btn-sm" href="jaminan_sertif_tambah.php?nomor=<?php echo $p['m_nomor'] ?>&noang=<?php echo $p['m_angg_no'] ?>"><i class="bi bi-credit-card-2-front"></i></a>
                    <?php } ?>  
                    
                    <?php if($tnomor3>=1){ ?>    
                        <a data-toggle='tooltip' data-placement='top' title='Lihat Jaminan Lain-lain <?php echo $norek ?> a/n <?php echo $angg_nama; ?>' style='margin-right:3px' class="btn btn-secondary btn-sm" href="jaminan_lain_tambah.php?nomor=<?php echo $p['m_nomor'] ?>&noang=<?php echo $p['m_angg_no'] ?>"><i class="bi bi-grid"></i></a>
                    <?php } ?>                   
                </td>
                <td style="text-align:left; font-size: 10pt; font-weight:normal;"><?php echo $p['m_sektor']; ?></td>
                <td style="text-align:left; font-size: 10pt; font-weight:normal;"><?php echo $ket; ?></td>
                <td>

                    <?php if ($pc['catatan']<>'Siap Cair') {; ?>
                          <a onclick="return confirm('Yakin ingin hapus PERMOHONAN No : <?php echo $p['m_nomor'] ?>.....?')" class="btn btn-danger btn-sm" href="angg_kartu_permohonan_hapus.php?id=<?php echo $angg_id ?>&oleh=<?php echo $oleh ?>&xid=<?php echo $p['m_nomor'] ?>">
                            <i class="bi bi-trash"></i>
                          </a>
                    <?php } ?>                    
                </td>    
              </tr>
              <?php } ?>
          </tbody>
        </table>
      </div>
    </div>
  </div>
</div>
