


<?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">DATA DONASI</span>
      <buton>
        <a href="index.php" class="btn btn-primary btn-sm"><i class="bi bi-house-fill"></i> &nbsp Home</a> 
        <?php if ($_SESSION['level']<>'ANGGOTA') { ?>
            <a href="javascript:history.go(-1)" class="btn btn-info btn-sm"><i class="bi bi-reply-all"></i> &nbsp Kembali</a>
        <?php } ?>
      </buton>
    </div>
      <div class="table-responsive">
        <table class="table table-bordered table-striped" id="table-datatable1">
          <thead>
            <tr>
                <th Style="text-align:center" colspan="1" bgcolor="#D3D3D3"></th>
                <th Style="text-align:center" colspan="4" bgcolor="#DCDCDC">Donasi</th>
            </tr>                              
            <tr>
              <th width="1%" class="text-center">No.</th>
              <th width="1%" class="text-center">KD</th>
              <th width="30%" class="text-center">Jenis</th>
              <th width="1%" class="text-center">X</th>
              <th width="15%" class="text-center">Jumlah</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 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 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 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 $kdj; ?></td>
                <td><?php echo $result; ?></td>
                <td style="text-align:right; font-size: 11pt; font-weight:normal;"><?php echo "" . number_format("$jorg_s", 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 Detail 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>      
-->                
                
<td style="text-align:right; font-size: 11pt; font-weight:normal;">
  <?php if($tsaldo >= 1) { ?>
    <a data-bs-toggle='tooltip' data-bs-placement='top' title='Lihat Detail Transaksi <?php echo $result; ?>' style='margin-right:3px' class="btn btn-info btn-sm" data-bs-toggle="modal" data-bs-target="#modalDetailTransaksi<?php echo $kdj; ?>">
      <?php echo "" . number_format("$tsaldo", 0, ",", "."); ?>
    </a>
  <?php } ?>
</td>

<!-- Modal Detail Transaksi -->
<div class="modal fade" id="modalDetailTransaksi<?php echo $kdj; ?>" tabindex="-1" aria-labelledby="modalDetailTransaksiLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="modalDetailTransaksiLabel">Detail Transaksi <?php echo $result; ?></h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
        <!-- Isi detail transaksi di sini -->
        <p>Detail transaksi akan ditampilkan di sini...</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Tutup</button>
      </div>
    </div>
  </div>
</div>

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>

              </tr>
              <?php 
            }
            ?>
          </tbody>
                        <?php 
                $sql_2 = mysqli_query($koneksi, "SELECT count(angg_no) AS t_org,sum(masuk-keluar) AS tsaldo FROM anggota_trans WHERE angg_no='$angg_no' ");
                list($t_org,$tsaldo) = mysqli_fetch_array($sql_2);

                $sql_3 = mysqli_query($koneksi, "SELECT count(angg_no) AS t_org3,sum(masuk) AS tsaldo3,sum(keluar) AS ttarik FROM anggota_trans WHERE angg_no='$angg_no' ");
                list($t_org3,$tsaldo3,$ttarik) = mysqli_fetch_array($sql_3);                
                $nol=0 ;
            	        ?>						
							<tr>
						    	<td colspan="3" style="font-weight: bold;text-align: center;">Total </td>																																									

								<td align='right'><style="font-weight: bold;">
								    <?php echo "" . number_format("$t_org", 0, ",", "."); ?>
								</td>    
								<td align='right'><style="font-weight: bold;">
								    <a data-toggle='tooltip' data-placement='top' title='Lihat Detail Transaksi' style='margin-right:3px' class="btn btn-warning btn-sm" href="simp_angg_daftar_per_no_all.php?xid=<?php echo $angg_no ;?>"><?php echo "" . number_format("$tsaldo", 0, ",", "."); ?></i></a> 
								</td>
							</tr>                       
        </table>
      </div>
    </div>
  </div>
</div>


