
<?php 
    include 'header.php'; 

    $kdk = $_GET['kdk'];
    $kab = $_GET['kab'];

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

  <div class="my-4 border-bottom">
    <h4 class="fw-semibold fs-4">Daftar Warga/Jama'ah/Donatur
    </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="">
              <div class="row">
                <div class="col-md-2">
                  <div class="form-group">
                    <label>Dari</label>
                    <input type="date" class="form-control" name="tanggal_d" required="required" placeholder="Tanggal dari ..">
                  </div>
                </div>

                <div class="col-md-2">
                  <div class="form-group">
                    <label>Sampai</label>
                    <input type="date" class="form-control" name="tanggal_s" required="required" placeholder="Sampai tanggal ..">
                  </div>
                </div>

                <div class="col-md-2">
                  <div class="form-group">
                    <br/>
                    <input type="submit" value="TAMPILKAN LAPORAN" class="btn btn-sm btn-primary">
                  </div>
                </div>
              </div>
            </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['tanggal_s']) && isset($_GET['tanggal_d'])){
              $tgl_d = $_GET['tanggal_d'];
              $tgl_s = $_GET['tanggal_s'];
              
              $tgl_pertama    =strtotime("$tgl_d");
              $tgl_kemarin    =date('Y-m-d', strtotime("-1 day", $tgl_pertama));       
            } else { ;
                $tgl_d    = '2025-01-01';
                $tgl_s    = $_SESSION['tgl_sd'];
            }
              ?>

              <div class="row">
                <div class="col-lg-10">
                  <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>Menu Lanjutan </th>
                      <th>:</th>
                      <td>
      <button type="button" class="btn btn-primary btn-sm align-self-end" data-bs-toggle="modal" data-bs-target="#exampleModal">
       <i class="bi bi-plus-lg"></i> Tambah Baru 
      </button>                               
                      <a href="@_angg_tgl_sd_tgl_print.php?tgl_dr=<?php echo date('Y-m-d', strtotime($tgl_d)); ?>&tgl_sd=<?php echo date('Y-m-d', strtotime($tgl_s)); ?>" target="_blank" class="btn btn-warning btn-sm"><i class="bi bi-printer"></i> &nbsp Print</a>
<!--                  <a href="@_angg_tgl_sd_tgl_pdf.php" target="_blank" class="btn btn-info btn-sm"><i class="bi bi-file-earmark-pdf"></i> &nbsp Print PDF</a>
-->
                      <a href="@_angg_tgl_sd_tgl_excell.php?tgl_dr=<?php echo date('Y-m-d', strtotime($tgl_d)); ?>&tgl_sd=<?php echo date('Y-m-d', strtotime($tgl_s)); ?>" class="btn btn-success btn-sm"><i class="bi bi-file-word"></i> &nbsp Excell</a>
                      <a href="index.php" class="btn btn-info btn-sm pull-right"><i class="bi bi-reply"></i> &nbsp; Kembali</a> 
                      
                      </td>
                    </tr>                       
                  </table>
                </div>
              </div>

      <!-- Modal -->
      <form action="@_angg_tambah_act.php" method="post">
        <div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
          <div class="modal-dialog">
            <div class="modal-content">
              <div class="modal-header">
                <h1 class="modal-title fs-5" id="exampleModalLabel">Tambah Data</h1>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
              </div>
              <div class="modal-body">
                  <?php
              // fungsi untuk membuat kode transaksi
                $sql1 = mysqli_query($koneksi, "SELECT right(angg_no,7) as kode3 FROM anggota ORDER BY angg_no DESC LIMIT 1");
                list($kode3) = mysqli_fetch_array($sql1);
              $count3 = mysqli_num_rows($sql1);

              if ($count3 <> 0) {
                  // mengambil data kode transaksi
                  $data_id3 = mysqli_fetch_assoc($sql1);
                  $kode3    = $kode3+1;
                  $no_angg  = $kode3 ;
              } else {
                  $no_angg = '1000001';
              } 
              ?>
<div style="background-color: <?php echo$_SESSION['warna_bag']; ?>; padding: 15px; border-radius: 15px; box-shadow: 0 0 15px <?php echo$_SESSION['warna_bag']; ?>;">                  
                <div class="form-group">
                 <label>Kode Anggota</label>        
                    <input type="hidden" name="tkdc" required="required" class="form-control" value=<?php echo $kdc; ?> readonly required >
                    <input type="hidden" name="tkdk" required="required" class="form-control" value=<?php echo $id; ?> readonly required >
                    <input type="hidden" name="tkab" required="required" class="form-control" value=<?php echo $kab; ?> readonly required >
                    <input type="hidden" name="toleh" required="required" class="form-control" value=<?php echo $oleh; ?> readonly required >
                    <input type="text" name="noang" class="form-control" value=<?php echo $no_angg; ?> readonly required >
                </div>                     
                <div class="form-group">
                  <label> <font color="#000fff">Nama Anggota</font></label>
                  <input type="text" name="nama" required="required" class="form-control" placeholder="Isikan Nama ..">
                </div>
                <div class="form-group">
                  <label><font color="#000fff">Alamat <font color='#ff0000'><i>(Cukup diisi nama Kampung)</i></font color></label>
                  <input type="text" name="alamat" required="required" class="form-control" placeholder="Isikan Alamat ..">
                </div> 
            	<div class="form-group">
                    <label class="form-label">RT <font color='#ff0000'><i>(2 digit pakai NUMERIK misalnya : 01 atau 10)</i></font color></label>
                    <input type="text" minlength="2" maxlength="2" name="rt" required="required" class="form-control" placeholder="Isikan RT ..">
            	</div>                         
            	<div class="form-group">
                    <label class="form-label">RW <font color='#ff0000'><i>(2 digit pakai NUMERIK misalnya : 01 atau 10)</i></font color></label>
                    <input type="text" minlength="2" maxlength="2" name="rw" required="required" class="form-control" placeholder="Isikan RW ..">
            	</div>                                   
            	<div class="form-group">
                    <label class="form-label">Kelurahan <font color='#ff0000'><i>(isi nama Kelurahan)</i></font color></label>
                    <input type="text" name="kel" required="required" class="form-control" placeholder="Isikan Kelurahan ..">
            	</div> 
            	<div class="form-group">
                    <label class="form-label">Kecamatan <font color='#ff0000'><i>(isi nama Kecamatan)</i></font color></label>
                    <input type="text" name="kec" required="required" class="form-control" placeholder="Isikan Kecamatan ..">
            	</div> 
            	<div class="form-group">
                    <label class="form-label">Kab/Kota <font color='#ff0000'><i>(isi nama Kab/Kota)</i></font color></label>
                    <input type="text" name="kab" required="required" class="form-control" placeholder="Isikan Kab/Kota ..">
            	</div>             	
                <div class="form-group">
                  <label><font color="#000fff">Nomor HP</font></label>
                  <input type="text" name="hp" required="required" class="form-control" placeholder="Isikan nomor HP ....">
                </div>
              </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>
        
        </div>
        
                 <?php 
                if(isset($_GET['alert'])){
                  if($_GET['alert'] == "duplikat"){
                    echo "<div class='alert alert-danger'><b>GAGAL!</b> No KK Sudah digunakan anggota <b>".$_GET['siapa']."</b>......!</div>";
                  }
                }
                if(isset($_GET['alert2'])){
                  if($_GET['alert2'] == "duplikat2"){
                    echo "<div class='alert alert-danger'><b>GAGAL!</b> No ANGGOTA Sudah digunakan anggota <b>".$_GET['siapa']."</b>......!</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;">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="1%" class="text-center">Jln/Kampung</th>
              <th width="1%" class="text-center">RT</th>
              <th width="1%" class="text-center">RW</th>
              <th width="1%" class="text-center">Kel</th>
              <th width="1%" class="text-center">Kec</th>
              <th width="1%" class="text-center">Kota/Kab</th>
              <th width="1%" class="text-center">No WA</th>
              <th width="2%" class="text-center">Tanggal</th>
              <th width="20%" class="text-center">OPSI</th>
            </tr>
          </thead>
          <tbody>
            <?php 
            $no=1;
            $data = mysqli_query($koneksi,"SELECT * FROM anggota WHERE tglmasuk>='$tgl_d' and tglmasuk<='$tgl_s' ");
            while($d = mysqli_fetch_array($data)){
                $noang  =$d['angg_no'] ;
                $rt   =$d['rt'] ;
                $rw   =$d['rw'] ;
                $kerja   =$d['pekerjaan'] ;
                $usaha   =$d['usaha'] ;
                $jekel   =$d['jekel'] ;
                if ($jekel=='1') {
                    $lp='L' ;
                } else {
                    $lp='P';
                }
                $no_hp=$d['hp'] ;
                        $foto_diri  =$d['foto_diri'] ;
                        $angg_id    =$d['angg_id'] ;
                        $noang      =$d['angg_no'] ;
 
               $sql2 = mysqli_query($koneksi, "SELECT pekerjaan AS akerjaan FROM kdpekerjaan WHERE id='$kerja' ");
                       list($akerjaan) = mysqli_fetch_array($sql2);     
               $sql3 = mysqli_query($koneksi, "SELECT usaha AS atusaha FROM kdusaha WHERE id='$usaha' ");
                       list($atusaha) = mysqli_fetch_array($sql3);                            
               $sql4 = mysqli_query($koneksi, "SELECT count(angg_no) AS t_ang_sim FROM angg_simp_trans WHERE angg_no='$noang' ");
                       list($t_ang_sim) = mysqli_fetch_array($sql4);
               $sql5 = mysqli_query($koneksi, "SELECT count(m_angg_no) AS t_permoh FROM permohonan WHERE m_angg_no='$noang' ");
                       list($t_permoh) = mysqli_fetch_array($sql5);
                       
               $tno_angg=$t_ang_sim+$t_permoh ;           
                       
              ?>
              <tr>
                <td><?php echo $no++; ?></td>
                <td>
                  <center>
                    <a href="angg_foto_tampil.php?id=<?php echo $angg_id ?>&no=<?php echo $noang ?>" data-placement='top' title='Lihat Detail & Foto <?php echo $d['angg_no'] ?> a/n <?php echo $d['nama']; ?>' >								    
                        <?php if($foto_diri == ""){ ?>
                          <img src="../gambar/user.png" style="width: 20px;height: auto">  
                        <?php }else{ ?>
                          <img src="../gambar/diri/<?php echo $foto_diri ?>" style="width: 20px;height: auto">
                        <?php } ?>                    
                    </a>                                   
                  </center>         
                </td>                 
                <td style="text-align:left; font-size: 8pt; font-weight:normal;"><a data-toggle='tooltip' data-placement='top' title='Lihat Kartu Anggota <?php echo $d['nama']; ?>' style='margin-right:3px' class="btn btn-warning btn-sm" href="angg_kartu.php?id=<?php echo $angg_id; ?>"><?php echo $d['angg_no'] ?></td>
                <td style="text-align:left; font-size: 10pt; 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['rt']; ?></td>
                <td style="text-align:left; font-size: 9pt; font-weight:normal;"><?php echo $d['rw']; ?></td>
                <td style="text-align:left; font-size: 9pt; font-weight:normal;"><?php echo $d['kel']; ?></td>
                <td style="text-align:left; font-size: 9pt; font-weight:normal;"><?php echo $d['kec']; ?></td>
                <td style="text-align:left; font-size: 9pt; font-weight:normal;"><?php echo $d['kab']; ?></td>
                <td style="text-align:left; font-size: 9pt; font-weight:normal;"><?php echo $no_hp; ?></td>
                <td style="text-align:left; font-size: 9pt; font-weight:normal;"><?php echo date('d/m/Y', strtotime($d['tglmasuk'])); ?></td>
                <td>    
                <a data-toggle='tooltip' data-placement='top' title='Reset Password <?php echo $d['angg_no'] ?> a/n <?php echo $d['nama']; ?>' style='margin-right:3px' class="btn btn-primary btn-sm" href="angg_ganti_password.php?tid=<?php echo $d['angg_id'] ?>&no=<?php echo $noang ?>"><i class="bi bi-unlock"></i></a>
                <a data-toggle='tooltip' data-placement='top' title='Kirim WA Reset Password <?php echo $d['angg_no'] ?> a/n <?php echo $d['nama']; ?>' style='margin-right:3px' class="btn btn-success btn-sm" href="angg_wa_ganti_pasword.php?id=<?php echo $d['angg_id'] ?>&hp=<?php echo $d['hp'] ?>"><i class="bi bi-box-arrow-up-right"></i></a>
                <a class="btn btn-warning btn-sm" title="Edit Data Customer <?php echo $d['nama'] ?>" data-bs-toggle="modal" data-bs-target="#edit_custom_<?php echo $d['angg_id'] ?>"><i class="bi bi-gear"></i></a>
                <?php if($tno_angg<=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_edit_act.php" method="post">
                    <div class="modal fade" id="edit_custom_<?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 style="background-color: <?php echo$_SESSION['warna_bag']; ?>; padding: 15px; border-radius: 15px; box-shadow: 0 0 15px <?php echo$_SESSION['warna_bag']; ?>;">
                            <div class="form-group" style="width:100%">
                              <label><font color="#000fff">Nama Anggota</font></label>
                              <input type="hidden" name="tid" required="required" class="form-control" value="<?php echo $d['angg_id']; ?>">
                              <input type="text" name="nama" required="required" class="form-control" placeholder="Nama Anggota .." value="<?php echo $d['nama']; ?>" style="width:100%">
                            </div>
                            <div class="form-group">
                              <label><font color="#000fff">Alamat</font></label>
                              <input type="text" name="alamat" required="required" class="form-control" placeholder="Alamat .." value="<?php echo $d['alamat']; ?>"
                            </div>
            	<div class="form-group">
                    <label class="form-label">RT <font color='#ff0000'><i>(2 digit pakai NUMERIK misalnya : 01 atau 10)</i></font color></label>
                    <input type="text" minlength="2" maxlength="2" name="rt" required="required" class="form-control" placeholder="Isikan RT .." value="<?php echo $d['rt']; ?>">
            	</div>                         
            	<div class="form-group">
                    <label class="form-label">RW <font color='#ff0000'><i>(2 digit pakai NUMERIK misalnya : 01 atau 10)</i></font color></label>
                    <input type="text" minlength="2" maxlength="2" name="rw" required="required" class="form-control" placeholder="Isikan RW .."  value="<?php echo $d['rw']; ?>">
            	</div>                                   
                            <div class="form-group">
                              <label><font color="#000fff">Kelurahan </font></label>
                              <input type="text" name="kel" required="required" class="form-control" value="<?php echo $d['kel']; ?>"
                            </div>
                            <div class="form-group">
                              <label><font color="#000fff">Kecamatan </font></label>
                              <input type="text" name="kec" required="required" class="form-control" value="<?php echo $d['kec']; ?>"
                            </div>
                            <div class="form-group">
                              <label><font color="#000fff">Kota/Kab </font></label>
                              <input type="text" name="kab" required="required" class="form-control" value="<?php echo $d['kab']; ?>"
                            </div>                            
                            <div class="form-group">
                              <label><font color="#000fff">Nomor HP </font></label>
                              <input type="text" name="hp" required="required" class="form-control" value="<?php echo $d['hp']; ?>"
                            </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>
                    </div>
                  </form>
               
<!---- FORM EDIT ANGGOTA  ---------->     
                </td>
              </tr>
              <?php 
            }
            ?>
          </tbody>
        
        </table>
        
        
              </div>

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

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