


<?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">REKAP DONASI</span>
    </div>
      <div class="table-responsive">
        <table class="table table-bordered table-striped" id="table-datatable1">
          <thead>
            <tr>
                <th Style="text-align:center" colspan="2" bgcolor="#DCDCDC">Donasi</th>
                <th Style="text-align:center" colspan="2" bgcolor="#DCDCDC"><?php echo $tahun_ini; ?></th>
                <th Style="text-align:center" colspan="1" bgcolor="#DCDCDC"></th>
            </tr>                              
            <tr>
              <th width="1%" class="text-center">No.</th>
              <th width="30%" class="text-center">Jenis</th>
              <th width="1%" class="text-center">X</th>
              <th width="15%" class="text-center">Setoran</th>
              <th width="1%" class="text-center"></th>
            </tr>
          </thead>
          <tbody>
            <?php 
            $no=1;
            $tgl_skr= date('Y-m-d');
            $data = mysqli_query($koneksi,"SELECT * FROM nawal WHERE kt='D' ORDER BY id ASC");
            while($k = mysqli_fetch_array($data)){
                $kdj=$k['noperk'];
                $perk=$k['perk'];
                $result = preg_replace('/^Pend\. /', '', $perk);
                
                    $sql2 = mysqli_query($koneksi, "SELECT count(angg_no) AS tangg_no_1 FROM anggota_trans_ao WHERE angg_no='$angg_no' ");
                    list($tangg_no_1) = mysqli_fetch_array($sql2);                     

                    $sql3 = mysqli_query($koneksi, "SELECT count(angg_no) AS jorg_s,sum(masuk-keluar) AS tsaldo FROM anggota_trans_ao WHERE kdj='$kdj' and angg_no='$angg_no' ");
                    list($jorg_s,$tsaldo) = mysqli_fetch_array($sql3);   
                    $sql4 = mysqli_query($koneksi, "SELECT count(angg_no) AS jorg, sum(masuk) AS tsetor,sum(keluar) AS ttarik FROM anggota_trans_ao WHERE kdj='$kdj' and angg_no='$angg_no' and year(tanggal)='$tahun_ini' ");
                    list($jorg,$tsetor,$ttarik) = mysqli_fetch_array($sql4);                    
              ?>
              <tr>
                <td><?php echo $no++; ?></td>
                <td><?php echo $result; ?></td>
                <td style="text-align:right; font-size: 11pt; font-weight:normal;"><?php echo "" . number_format("$jorg", 0, ",", "."); ?></td> 
                <td style="text-align:right; font-size: 11pt; font-weight:normal;">
                  <?php if($tsaldo >= 1) { ?>
                    <a data-toggle='tooltip' data-placement='top' title='Lihat Transaksi <?php echo $k['nama']; ?>' style='margin-right:3px' class="btn btn-info btn-sm" href="simp_angg_daftar_per_no.php?xid=<?php echo $angg_no ;?>&kdj=<?php echo $kdj; ?>"><?php echo "" . number_format("$tsaldo", 0, ",", "."); ?></i></a>
                  <?php } ?>
                </td>                 
              </tr>
              <?php 
            }
            ?>
          </tbody>
                        <?php 
                $sql_2 = mysqli_query($koneksi, "SELECT count(angg_no) AS tj_org,sum(masuk-keluar) AS tjsaldo FROM anggota_trans_ao WHERE angg_no='$angg_no' ");
                list($tj_org,$tjsaldo) = mysqli_fetch_array($sql_2);
                $nol=0 ;
            	        ?>						
							<tr>
						    	<td colspan="2" style="font-weight: bold;text-align: center;">Total </td>																																									
								<td align='right'><style="font-weight: bold;">
								    <?php echo "" . number_format("$tj_org", 0, ",", "."); ?>
								</td>    
								<td align='right'><style="font-weight: bold;">
								    <a data-toggle='tooltip' data-placement='top' title='Lihat Transaksi <?php echo $k['nama']; ?>' style='margin-right:3px' class="btn btn-info btn-sm" href="simp_angg_daftar_per_no.php?xid=<?php echo $angg_no ;?>&kdj=<?php echo $kdj; ?>"><?php echo "" . number_format("$tjsaldo", 0, ",", "."); ?></i></a>
								</td>	
							</tr>                       
        </table>
      </div>
    </div>
  </div>
</div>


