


<?php include 'header.php'; ?>
<?php 
    include '../koneksi.php';
    $kata_cari = $_POST['kata_cari_p'];
    $rand = rand();

if (!empty($kata_cari))
{
?>
<div class="container">
 <div class="my-2 border-bottom">
   <h2 class="fw-semibold fs-3"></h2>
 </div>
  <div class="row justify-content-center">
    <div class="col-lg-12">
        
        <?php 
        /////////////////////   ALERT   ////////////////////////
        if(isset($_GET['alert'])){
          if($_GET['alert'] == "sukses"){
            echo "<div class='alert alert-success'>Data anggota berhasil diganti!</div>";
          }
        }
        ?>
        
       <div class="card">
    <div class="card-header d-flex justify-content-between">
      <span class="card-title fw-semibold align-self-start mb">Daftar Peminjam  </span>
      <button type="button" class="btn btn-primary btn-sm align-self-end" data-bs-toggle="modal" data-bs-target="#exampleModal">
       <a href="!!!_cari_peminjam.php" class="btn btn-primary btn-sm"><i class="bi bi-reply-all"></i> &nbsp Kembali</a> 
      </button>
    </div>
    <div class="card-body">
      <div class="table-responsive">
        <table class="table table-bordered table-striped" id="table-datatable1">
                  <thead>
                    <tr>
                    <th Style="text-align:center" colspan="8" bgcolor="#D3D3D3">PINJAMAN</th>
                    <th Style="text-align:center" colspan="4" bgcolor="#DCDCDC">BAYAR ANGSURAN</th>
                    <th Style="text-align:center" colspan="3" bgcolor="#DCDCDC">SALDO PINJAMAN</th>
                    <th Style="text-align:center" colspan="4" bgcolor="#DCDCDC">TUNGGAKAN </th>
                    
                 </tr>                
                <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;">Fo</th>
                  <th width="20%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Nama</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;">Pokok</th>
                  <th width="1%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">X</th>
                  <th width="1%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Angs/bl</th>
                  <th width="1%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Tg JT</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;">Bunga</th>
                  <th width="1%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Lain</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;">Pokok</th>
                  <th width="1%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Bunga</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;">Hr</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;">Bunga</th>
                  <th width="1%" class="text-center" style="text-align:left; font-size: 10pt; font-weight:normal;">Jumlah</th>
                </tr>
                  </thead>
          <tbody>
            <?php 
            $no=1;
                // jika yang diklik kolom NIM
            //    if ($_GET['by'] == "noang") $orderBy = "noang";
                // jika yang diklik kolom NAMA MHS
            //    else if ($_GET['by'] == "nama") $orderBy = "nama";
                // jika tidak ada yang diklik (default)
            //    else $orderBy = "nama";

            $query = mysqli_query($mysqli, "SELECT * FROM pinjaman WHERE nama like '%".$kata_cari."%' OR kol like '%".$kata_cari."%' OR norek like '%".$kata_cari."%' ")
                                            or die('Ada kesalahan pada query tampil data user: '.mysqli_error($mysqli));
                while($d = mysqli_fetch_array($query)){
                    
                    $angs_per_bl    =($d['pokok']+$d['bungarp'])/$d['jkw'] ;
                    $krgjumlah      =($d['krgpokok']+$d['krgbunga']) ;
                    $byr_jm         =($d['byrpokok']+$d['byrbunga']+$d['byrlain']) ;
                    $tgl_jth_tmp    = $d['tgl_jt'];
                    $tanggal_1      = date_create($d['tanggal']);
                    $tanggal_3      = date_create($tgl_jth_tmp);
                    $jkw_diff       = date_diff( $tanggal_1, $tanggal_3 );
                    $jkw_hari       = $jkw_diff->days;
                    $telate         = $d['telat_hr'] ;
                    $angs_harus_pk_per_hari   = ($d['pokok'])/$jkw_hari ;
                    $angs_harus_bg_per_hari   = ($d['bungarp'])/$jkw_hari ;

                    $target_jm=$d['telat_pk']+$d['telat_pk'];

                    $sql2 = mysqli_query($koneksi, "SELECT angg_id,angg_no,nama,foto_diri FROM anggota where angg_no='$d[angg_no]'");
                    list($angg_id,$angg_no,$nama,$foto_diri) = mysqli_fetch_array($sql2);

              ?>
                  <tr>
                    <td><?php echo $no++; ?></td>
                    <td>
                      <center>
                        <a href="a1_pinj_kart_per_norek.php?id=<?php echo $d['norek'] ?>&noang=<?php echo $angg_no ?>" data-placement='top' title='Lihat Histori Pinjaman <?php echo $d['norek'] ?> a/n <?php echo $nama; ?>' >  
                            <?php if($foto_diri == ""){ ?>
                              <img src="../gambar/user.png" style="width: 20px;height: auto">  
                            <?php }else{ ?>
                                <img width="80" height="80" 
                                src="../gambar/diri/<?php echo $foto_diri ?>" style="width: 20px;height: auto">
                            <?php } ?>
                        </a>
                      </center>
                    </td>                 
                    <td style="text-align:left; font-size: 10pt; font-weight:normal;"><?php echo $nama; ?></td>
                    <td style="text-align:left; font-size: 10pt; font-weight:normal;"><?php echo date('d/m/Y', strtotime($d['tanggal'])); ?></td>
                    <td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$d[pokok]", 0, ",", "."); ?></td>
                    <td style="text-align:center; font-size: 10pt; font-weight:normal;"><?php echo $d['jkw']; ?></td>
                    <td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$angs_per_bl", 0, ",", "."); ?></td>
                    <td style="text-align:left; font-size: 10pt; font-weight:normal;"><?php echo date('d/m/Y', strtotime($d['tgl_jt'])); ?></td>
                    
                    
                    <td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$d[byrpokok]", 0, ",", "."); ?></td>
                    <td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$d[byrbunga]", 0, ",", "."); ?></td>
                    <td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$d[byrlain]", 0, ",", "."); ?></td>
                    <td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$byr_jm", 0, ",", "."); ?></td>
                    
                    <td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$d[krgpokok]", 0, ",", "."); ?></td>
                    <td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$d[krgbunga]", 0, ",", "."); ?></td>
                    <td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$krgjumlah", 0, ",", "."); ?></td>

                    <td style="text-align:center; font-size: 10pt; font-weight:normal;"><?php echo $telate; ?></td>
                    <td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$d[telat_pk]", 0, ",", "."); ?></td>
                    <td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$d[telat_bg]", 0, ",", "."); ?></td>
                    <td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$target_jm", 0, ",", "."); ?></td>
                </td>    
              </tr>
              <?php 
            }
            ?>
          </tbody>
                        <?php 

                            $data = mysqli_query($koneksi,"SELECT sum(pokok) as tpokok,sum(byrpokok) as tbyrpokok,sum(byrbunga) as tbyrbunga,sum(byrlain) as tbyrlain,sum(krgpokok) as tkrgpokok,sum(krgbunga) as tkrgbunga,sum(telat_pk) as ttelat_pk,sum(telat_bg) as ttelat_bg FROM pinjaman WHERE tanggal<='$tgl_s' and kdc='$kdc' ");
            	            $j = mysqli_fetch_array($data);
            	            
            	            $nol    =0 ;
            	            $byrjumlah=$j['tbyrpokok']+$j['tbyrbunga']+$j['tbyrlain'] ;
            	            $krgjumlah=$j['tkrgpokok']+$j['tkrgbunga'] ;
            	            $telatjumlah=$j['ttelat_pk']+$j['ttelat_bg'] ;
            	            
            	        ?>			
            	        
							<tr>
						    	<td colspan="4" style="font-weight: bold;text-align: center;">Total </td>																																									
								<td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$j[tpokok]", 0, ",", "."); ?></td>
								<td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" ; ?></td>
								<td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" ; ?></td>
								<td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" ; ?></td>
								<td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$j[tbyrpokok]", 0, ",", "."); ?></td>
								<td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$j[tbyrbunga]", 0, ",", "."); ?></td>
								<td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$j[tbyrlain]", 0, ",", "."); ?></td>
								<td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$byrjumlah", 0, ",", "."); ?></td>
								<td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$j[tkrgpokok]", 0, ",", "."); ?></td>
								<td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$j[tkrgbunga]", 0, ",", "."); ?></td>
								<td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$krgjumlah", 0, ",", "."); ?></td>
								<td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" ; ?></td>	
								<td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$j[ttelat_pk]", 0, ",", "."); ?></td>
								<td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$j[ttelat_bg]", 0, ",", "."); ?></td>
								<td style="text-align:right; font-size: 10pt; font-weight:normal;"><?php echo "" . number_format("$telatjumlah", 0, ",", "."); ?></td>								
							</tr>       
        </table>
      </div>
    </div>

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

</div>
<?php include 'foot_ku.php'; ?>
<?php
}
else
{
   die("Maaf, Anda harus mengisi kata kunci");
}
?>
<?php include 'footer.php'; ?>