<?php 
    session_start();
    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'];
    $kdc=$_SESSION['kdc'];
?>            
<div class="container">

  <div class="my-4 border-bottom">
    <h4 class="fw-semibold fs-4">Daftar Warga/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">
                    <label>Jenis</label>
                        <select class="form-control" name="tkdj" required="required">
                          <option value="">- Pilih Akunt Donasi -</option>
                          <?php 
                          $nawal = mysqli_query($koneksi,"select * from nawal Where kt='D' order by perk ASC");
                          while($rj = mysqli_fetch_array($nawal)){
                          ?>
                            <option value="<?php echo $rj['noperk'] ?>"><?php echo $rj['noperk'] ?> - <?php echo $rj['perk'] ?></option>
                          <?php 
                               }
                          ?>
                        </select>                    
                  </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']) && isset($_GET['tkdj'])) {
              $tgl_d = $_GET['tanggal_d'];
              $tgl_s = $_GET['tanggal_s'];
              $kdj   = $_GET['tkdj'];
              
              $tgl_pertama    =strtotime("$tgl_d");
              $tgl_kemarin    =date('Y-m-d', strtotime("-1 day", $tgl_pertama));       
            } else { ;
                $tgl_d    = $tgl_awal;
                $tgl_s    = $_SESSION['tgl_sd'];
                $kdj      ='0000';
            }
              ?>

              <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>Jenis</th>
                      <th>:</th>
                      <td><?php echo $kdj; ?></td>
                    </tr>                    
                    <tr>
                      <th>Menu Lanjutan </th>
                      <th>:</th>
                      <td>
                          <a href="@_angg_lap_infaq_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)); ?>&tkdj=<?php echo $kdj; ?>" target="_blank" class="btn btn-warning btn-sm"><i class="bi bi-printer"></i> &nbsp Print</a>
                          <a href="@_angg_lap_infaq_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)); ?>&tkdj=<?php echo $kdj; ?>" class="btn btn-success btn-sm"><i class="bi bi-file-excel-fill"></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 -->

              <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">x</th>
              <th width="5%" class="text-center">Jumlah</th>
              <th width="12%" class="text-center">OPSI</th>
            </tr>
          </thead>
          <tbody>
            <?php 
            $no=1;
            //WHERE tglmasuk>='$tgl_d' and tglmasuk<='$tgl_s' 
            $data = mysqli_query($koneksi,"SELECT * FROM anggota ");
            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'] ;

               $sql4 = mysqli_query($koneksi, "SELECT count(angg_no) AS t_ang_sim,sum(masuk) AS t_jumlah FROM anggota_trans WHERE angg_no='$noang' and kdj='$kdj' and tanggal>='$tgl_d' and tanggal<='$tgl_s' ");
                       list($t_ang_sim,$t_jumlah) = mysqli_fetch_array($sql4);
              ?>
              <tr>
                <td><?php echo $no++; ?></td>
                <td>
                  <center>
                    <a href="angg_foto_diri.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 $t_ang_sim; ?></td>
                <td style="text-align:right; font-size: 11pt; font-weight:normal;"><?php echo "" . number_format("$t_jumlah", 0, ",", "."); ?></td>
                <td>    
                <a class="btn btn-warning btn-sm" title="Edit Data Donatur <?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>




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

<!---- FORM SETORAN  ---------->     
                </td>
              </tr>
              <?php 
            }
            ?>
          </tbody>
        
        </table>
        
        
              </div>

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

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