
<?php 
    include 'header.php'; 

    $kdc = $_GET['id'];   

    $tgl_ini=date('d-m-Y') ;
    $tgl_ini2=date('Y-m-d') ; 
    
    $oleh=$_SESSION['id_kar'];
    
?>              


<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 Customer Kanca <?php echo $kdc ?> </span>
      <button type="button" class="btn btn-primary btn-sm align-self-end" data-bs-toggle="modal" data-bs-target="#exampleModal">
       <a href="angg_rkp_adm.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-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;">Foto</th>
              <th width="1%" class="text-center" style="text-align:left; font-size: 9pt; font-weight:normal;">NoAng</th>
              <th width="16%" class="text-center">NAMA</th>
              <th width="21%" class="text-center">Alamat</th>
              <th width="10%" class="text-center">KTP</th>
              <th width="10%" class="text-center">KK</th>
              <th width="4%" class="text-center">Msk</th>
              <th width="4%" class="text-center">Pinj</th>
              <th width="1%" class="text-center" style="text-align:left; font-size: 8pt; font-weight:normal;">X</th>
              <th width="24%" class="text-center">OPSI</th>
            </tr>
          </thead>
          <tbody>
            <?php 
            $no=1;
            
                $data = mysqli_query($koneksi,"SELECT * FROM anggota WHERE kdc='$kdc' and hapus <>'HAPUS' ORDER BY angg_no DESC LIMIT 2000");

            
            while($d = mysqli_fetch_array($data)){
                $noang=$d['angg_no'] ;

                $sql2 = mysqli_query($koneksi, "SELECT count(pinj_angg_no) AS tno_pinj FROM pinjaman WHERE pinj_angg_no='$noang' ");
                list($tno_pinj) = mysqli_fetch_array($sql2);
                
                $sql3 = mysqli_query($koneksi, "SELECT SUM(simp_d) AS tmut_d, SUM(simp_k) AS tmut_k FROM simpanan WHERE angg_no='$noang'");
                list($tmut_d,$tmut_k) = mysqli_fetch_array($sql3); 
                $s_simp=($tmut_d-$tmut_k) ;
                
                $sql4 = mysqli_query($koneksi, "SELECT count(angg_no) AS tno_angg FROM simpanan WHERE angg_no='$noang' and left(jam,7)='Migrasi' ");
                list($tno_angg) = mysqli_fetch_array($sql4); 
                           

               mysqli_query($koneksi, "UPDATE anggota SET saldo_s='$s_simp' WHERE angg_no='$noang'")or die(mysqli_errno());
 //               $so_pinj=$d['saldo_p'] ;
              ?>
              <tr>
                <td><?php echo $no++; ?></td>
                <td>
                  <center>
                    <?php if($d['foto_diri'] == ""){ ?>
                      <img src="../gambar/user.png" style="width: 30px;height: auto">  
                    <?php }else{ ?>
                        <a href="#" class="pop">								    
                           <img width="80" height="80" 
                        src="../gambar/diri/<?php echo $d['foto_diri'] ?>" style="width: 30px;height: auto">
                        </a>             
                    <?php } ?>
                  </center>                    
                </td>                 
                <td style="text-align:left; font-size: 9pt; font-weight:normal;"><?php echo $d['angg_no'] ?></td>
                <td style="text-align:left; font-size: 9pt; font-weight:normal;"><?php echo $d['nama']; ?></td>
                <td style="text-align:left; font-size: 9pt; font-weight:normal;"><?php echo $d['alamat']; ?></td>
                <td style="text-align:left; font-size: 9pt; font-weight:normal;"><?php echo $d['ktp']; ?></td>
                <td style="text-align:left; font-size: 9pt; font-weight:normal;"><?php echo $d['kk']; ?></td>
                <td style="text-align:left; font-size: 9pt; font-weight:normal;"><?php echo date('d/m/Y', strtotime($d['tglmasuk'])); ?></td>
                <td style="text-align:right; font-size: 9pt; font-weight:normal;"><?php echo "" . number_format("$d[saldo_p]", 0, ",", "."); ?></td>
                <td style="text-align:center; font-size: 7pt; font-weight:normal;"><?php echo "" . number_format("$tno_pinj", 0, ",", "."); ?></td>
                <td>    
                    <a data-toggle='tooltip' data-placement='top' title='Kartu Histori <?php echo $d['angg_no'] ?> a/n <?php echo $d['nama']; ?>' style='margin-right:3px' class="btn btn-primary btn-sm" href="angg_kartu.php?id=<?php echo $d['angg_id'] ?>&no=<?php echo $noang ?>"><i class="bi bi-person-square"></i></a>
                    <a data-toggle='tooltip' data-placement='top' title='Lihat / Upload Foto <?php echo $d['angg_no'] ?> a/n <?php echo $d['nama']; ?>' style='margin-right:3px' class="btn btn-info btn-sm" href="angg_foto_tampil.php?id=<?php echo $d['angg_id'] ?>&no=<?php echo $noang ?>"><i class="bi bi-camera-fill"></i></a>
<!--           
                  <button type="button" class="btn btn-warning btn-sm" data-bs-toggle="modal" data-bs-target="#edit_kelas_<?php echo $d['angg_id'] ?>">
                    <i class="bi bi-gear"></i>
                  </button>
-->
                <a class="btn btn-warning btn-sm" title="Edit Data Customer <?php echo $d['nama'] ?>" data-bs-toggle="modal" data-bs-target="#edit_kelas_<?php echo $d['angg_id'] ?>"><i class="bi bi-gear"></i></a>
                <?php if($tno_pinj<=0) {;?>
                  <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>
                <?php };?>  
                
<!---- FORM EDIT ANGGOTA  ---------->                  
                  <form action="angg_update_act.php" method="post">
                    <div class="modal fade" id="edit_kelas_<?php echo $d['angg_id'] ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                      <div class="modal-dialog" role="document">
                        <div class="modal-content">
                          <div class="modal-header">
                            <h1 class="modal-title fs-5" id="exampleModalLabel">Edit Data Customer Id <?php echo $d['angg_id']; ?> NoCust <?php echo $d['angg_no']; ?></h1>
                            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                          </div>
                          <div class="modal-body">
                            <div class="form-group" style="width:100%">
                              <label>Nama Anggota</label>
                              <input type="hidden" name="tid" required="required" class="form-control" value="<?php echo $id; ?>">
                              <input type="hidden" name="tkab" required="required" class="form-control" value="<?php echo $kab; ?>">
                              <input type="hidden" name="tkdc" required="required" class="form-control" value="<?php echo $kdc; ?>">
                              <input type="hidden" name="eid" required="required" class="form-control" value="<?php echo $d['angg_id']; ?>">
                              <input type="text" name="enama" required="required" class="form-control" placeholder="Nama Anggota .." value="<?php echo $d['nama']; ?>" style="width:100%">
                            </div>
                            <div class="form-group">
                              <label>Alamat</label>
                              <input type="text" name="ealamat" required="required" class="form-control" placeholder="Alamat .." value="<?php echo $d['alamat']; ?>"
                            </div>
                            <div class="form-group">
                              <label>Tempat Tgl Lahir</label>
                              <input type="text" name="etempat" required="required" class="form-control" placeholder="tempat .." value="<?php echo $d['tpt_tgl_lhr']; ?>"
                            </div>
                            <div class="form-group">
                              <label>Umur (Th)</label>
                              <input type="text" name="eumur" required="required" class="form-control" placeholder="Umur .." value="<?php echo $d['umur']; ?>"
                            </div>                            
                            <div class="form-group">
                              <label>No. KTP</label>
                              <input type="text" name="ektp" required="required" class="form-control" placeholder="Nomor KTP .." value="<?php echo $d['ktp']; ?>"
                            </div>                
                        
                            <div class="form-group">
                              <label>No KK</label>
                              <input type="text" name="ekk" required="required" class="form-control" placeholder="Nomor KK .." value="<?php echo $d['kk']; ?>"
                            </div>                
                            <div class="form-group">
                              <label>Nama Suami/Istri/Orang Tua</label>
                              <input type="text" name="esuami" required="required" class="form-control" value="<?php echo $d['suami']; ?>"
                            </div>              
                            <div class="form-group">
                              <label>Janis Kelamin</label>
                              <input type="text" name="ejekel" required="required" class="form-control" value="<?php echo $d['jekel']; ?>"
                            </div>              
                            <div class="form-group">
                              <label>Pekerjaan</label>
                              <input type="text" name="epekerjaan" required="required" class="form-control" value="<?php echo $d['pekerjaan']; ?>"
                            </div>              
                            <div class="form-group">
                              <label>Status Marital</label>
                              <input type="text" name="emarital" required="required" class="form-control" value="<?php echo $d['marital']; ?>"
                            </div>                                          
                          </div>
                          <div class="modal-footer">
                            <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Tutup</button>
                            <button type="submit" class="btn btn-primary">Simpan</button>
                          </div>
                        </div>
                      </div>
                    </div>
                  </form>
<!---- FORM EDIT ANGGOTA  ---------->     
                </td>
              </tr>
              <?php 
            }
            ?>
          </tbody>
        </table>
      </div>
    </div>

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

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