
<?php 
    include 'header.php'; 
    $id     = $_GET['id'];
    $noang  = $_GET['no'];
    $level  = $_SESSION['level'] ;
    $kdc  = $_SESSION['kdc'] ;
    $kel  = $_SESSION['kelurahan'] ;
    
    $tgl_ini= date('d-m-Y') ;
    
        $data = mysqli_query($koneksi, "select * from anggota where angg_id='$id'");
        $d = mysqli_fetch_assoc($data);  
            $noang=$d['angg_no'];

                $sql5 = mysqli_query($koneksi, "SELECT count(angg_no) AS tsimp_no,sum(masuk-keluar) AS tsaldo FROM anggota_trans WHERE angg_no='$noang'");
                list($tsimp_no,$tsaldo) = mysqli_fetch_array($sql5);   

                $sql7 = mysqli_query($koneksi, "SELECT sp AS tsp,kecamatan AS kec, kota AS kota,kanca AS kanca FROM kdkanca WHERE kd=$kdc ");
                list($tsp,$kec,$kota,$kanca) = mysqli_fetch_array($sql7);
                $tsaldo_harus=($tsp-$tsaldo_pkk);
                
    if ($level=='SUP') {
        $kpd='Direktur' ;
    } 
    if ($level=='TOP') {
        $kpd='Supervisor' ;
    } 
    
        $sql5 = mysqli_query($koneksi, "SELECT id AS tkar_id FROM karyawan WHERE jabatan='$kpd'");
            list($tkar_id) = mysqli_fetch_array($sql5);          
        $sql6 = mysqli_query($koneksi, "SELECT hp AS tno_hp FROM karyawan_iden WHERE id='$tkar_id'");
            list($tno_hp) = mysqli_fetch_array($sql6);                      
?>              

<div class="container">
  <div class="my-4 border-bottom">
        <h3 class="fw-semibold fs-6">PROFIL DONATUR - <?php echo $kanca ?></h3>
  </div>
  <div class="row justify-content-center">
    <div class="col-lg-8">
    <div class="card">
    <div class="card-header d-flex justify-content-between">
      <span class="card-title fw-semibold align-self-start mb">IDENTITAS DIRI</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="box-body">
            <form method="get" action="">
              <div class="row">
                <div class="col-lg-12">
                                  
                  <table class="table table-bordered">
                    <tr>
                    <?php if($_SESSION['level']<>'ANGGOTA') { ;?>
                      <th style="font-weight: normal" width="35%">Foto </th>
                    <?php } else { ;?>  
                        <th style="font-weight: normal" width="35%">Foto Diri </th>
                    <?php } ;?>  
                      <th width="1%">:</th>
                      <td>                    
                        <?php if($d['foto_diri'] == ""){ ?>
                          <img src="../gambar/user.png" style="width: 30px;height: auto">  
                        <?php }else{ ?>
                            <a href="#" class="pop">								    
                               <img width="800" height="800" 
                            src="../gambar/diri/<?php echo $d['foto_diri']; ?>" style="width: 100px;height: auto">
                            </a>             
                        <?php } ?>
                      </td>
                    </tr>                      
                    <tr>
                      <th style="font-weight: normal" width="35%">Nomor </th>
                      <th width="1%">:</th>
                      <td style="font-weight: bold" ><?php echo $d['angg_no'] ?></td>
                    </tr>
                    <tr>
                      <th style="font-weight: normal" >Nama </th>
                      <th>:</th>
                      <td style="font-weight: bold" ><?php echo $d['nama'] ?></td>
                    </tr>

                    <tr>
                      <th style="font-weight: normal" >Alamat</th>
                      <th>:</th>
                      <td style="font-weight: bold" ><?php echo $d['alamat'] ?>, RT <?php echo $d['rt'] ?> RW <?php echo $d['rw'] ?>, <?php echo $kel ?>, <?php echo $kec ?>, <?php echo $kota ?></td>
                    </tr>

                    <tr>
                      <th style="font-weight: normal" >Nomor HP </th>
                      <th>:</th>
                      <td style="font-weight: bold" ><?php echo $d['hp'] ?></td>
                    </tr>                      

                    <tr>
                      <th style="font-weight: normal" >Tanggal Daftar </th>
                      <th>:</th>
                      <td style="font-weight: bold" ><?php echo date('d-m-Y', strtotime($d['tglmasuk'])); ?></td>
                    </tr>  

                    <tr>
                      <th style="font-weight: normal" >Lengkapi Data Lain</th>
                      <th>:</th>
                      <td>
                          <a href="angg_isi_data_lain.php?id=<?php echo $id ?>" class="btn btn-info btn-sm"><i class="bi bi-card-list"></i> &nbsp Isi / Edit Data</a> 
<!--                        <a href="!!!!!!!!!!_kode_unik.php?tid=<?php echo $id ?>" class="btn btn-info btn-sm"><i class="bi bi-card-list"></i> &nbsp Kode Unik</a> 

                        <?php if ($_SESSION['level']<>'ANGGOTA') { ?>
                          <a href="angg_ganti_password.php?tid=<?php echo $id ?>" class="btn btn-primary btn-sm"><i class="bi bi-key-fill"></i> &nbsp Reset Password</a> 
                          <a href="angg_wa_ganti_pasword.php?id=<?php echo $id ?>&hp=<?php echo $d['hp'] ?>" class="btn btn-success btn-sm"><i class="bi bi-person-check-fill"></i> &nbsp Kirim WA Reset Password</a> 
                        <?php } ?> 
-->
                        <a href="angg_foto_diri.php?id=<?php echo $id ?>" class="btn btn-warning btn-sm"><i class="bi bi-camera"></i> &nbsp Ganti Foto-foto</a>
                      </td>
                    </tr>

                    <tr>
                      <th style="font-weight: normal" >Lihat Map Domisili </th>
                      <th>:</th>
                      <td>
                        <?php if($d['a_latitude'] == "" && $d['a_longitude'] == ""){ ?>
                          <div class="alert alert-danger">Lokasi g-map belum diisi.</div>
                          <div class="form-group mb-2">
                                  <a href="angg_isi_map.php?id=<?php echo $id ?>" class="btn btn-info btn-sm"><i class="bi bi-geo-alt"></i> &nbsp Isi Kode MAP</a> 
                          </div>                   
                        <?php }else{ ?>
                            <div class="form-group mb-2">
                                <a href="https://www.google.com/search?q=google+map+<?php echo $d['a_latitude'] ?>%2C+<?php echo $d['a_longitude'] ?>" target="_blank" class="btn btn-warning btn-sm pull-right"><i class="bi bi-shop"></i> &nbsp; ke Detail Google Map</a>
                            </div>                
                            <div class="form-group mb-2">
                                <?php if($_SESSION[level]<>'TOP'){ ?>
                                  <a href="angg_isi_map.php?id=<?php echo $id ?>" class="btn btn-danger btn-sm"><i class="bi bi-geo-alt"></i> &nbsp Isi / Ganti Kode MAP</a> 
                                <?php } ?>
                            </div> 
                        <?php } ?>
                      </td>
                    </tr>  
                  </table>
                </div>
              </div>
              </div>
            </form>

<!-- ////////////////////////// SIMPANAN //////////////// -->  
<div>
    <?php if ($tsaldo>0) { ?>

    
<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='$noang' ");
                    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='$noang' ");
                    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='$noang' 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>      
-->                
<?php
// Pastikan Anda telah memasukkan library Bootstrap dan jQuery di dalam halaman Anda
?>
<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>

<td style="text-align:right; font-size: 11pt; font-weight:normal;">
    
  <?php if($tsaldo >= 1) { ?>
  <a class="btn btn-info btn-sm" title="Lihat Detail Transaksi <?php echo $result; ?>" data-bs-toggle="modal" data-bs-target="#detail_transaksi_<?php echo $kdj; ?>"><?php echo "" . number_format("$tsaldo", 0, ",", "."); ?></a>
  <?php } ?>
  
<!-- Modal Detail Transaksi -->
<div class="modal fade" id="detail_transaksi_<?php echo $kdj; ?>" tabindex="-1" aria-labelledby="modalDetailTransaksiLabel" aria-hidden="true">
  <div class="modal-dialog modal-lg">
    <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">
        <table class="table table-striped">
          <thead>
            <tr>
              <th width="1%" class="text-center">No.</th>
              <th width="1%" class="text-center">NoTrans</th>
              <th width="1%" class="text-center">Tanggal</th>
              <th width="50%" class="text-center">Keterangan</th>
              <th width="10%" class="text-center">Jumlah</th>
              
            </tr>
          </thead>
          <tbody>
            <?php
            // Query untuk menampilkan data transaksi
            //$data = mysqli_query($koneksi,"SELECT * FROM nawal WHERE kt='D' ORDER BY id ASC");
            //while($k = mysqli_fetch_array($data)){
                
            $query = "SELECT * FROM anggota_trans WHERE kdj = '$kdj' and angg_no='$noang' ";
            $result = mysqli_query($koneksi, $query);
            $no = 1;
            while ($row = mysqli_fetch_assoc($result)) {
                    $sql2 = mysqli_query($koneksi, "SELECT keterangan AS tketerangan FROM kas WHERE notrans='$row[notrans]' ");
                    list($tketerangan) = mysqli_fetch_array($sql2);                     
              ?>
              <tr>
                <td><?php echo $no++; ?></td>
                <td style="text-align:center; font-size: 9pt; font-weight:normal;"><?php echo $row['notrans']; ?></td>
                <td style="text-align:center; font-size: 9pt; font-weight:normal;"><?php echo date('d/m/Y', strtotime($row[tanggal])); ?></td>
                <td style="text-align:left; font-size: 9pt; font-weight:normal;"><?php echo $tketerangan; ?></td>
                <td style="text-align:right; font-size: 11pt; font-weight:normal;"><?php echo "" . number_format("$row[masuk]", 0, ",", "."); ?></td> 
              </tr>
              <?php
            }
            ?>
          </tbody>
        </table>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Tutup</button>
      </div>
    </div>
  </div>
</div>

</td>



              </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='$noang' ");
                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='$noang' ");
                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;">
								    <?php echo "" . number_format("$tsaldo", 0, ",", "."); ?>
								</td>
							</tr>                       
        </table>
      </div>
    </div>
  </div>
</div>
      
        


<!-- ///////////////////////////SIMPANAN/////////////// -->         
        <?php } else { ?>
                <font color='#ff0000'  style="text-align:left; font-size: 8pt; font-weight:normal;"><i>Tuan <?php echo $d['nama'] ?> belum ada data TRANSAKSI....</i></font><br>
        <?php } ?>
<!-- ////////////////////////// SELESAI SIMPANAN  //////////////// --> 
</div>

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