<div class="content-header">
        <div>
          <h4 class="content-title"><?php echo $title; ?></h4>
        </div>
      </div><!-- content-header -->
      <div class="content-body">
      	<?php if($this->session->flashdata('flash')): ?>
	<div class="alert alert-success"><?php echo $this->session->flashdata('flash'); ?></div>
	<?php endif; ?>
	<div class="mb-2">
		<a href="admin/galang-dana/new" class="btn btn-primary">
			<i class="fas fa-plus"></i>
		</a>
	</div>
      	<table id="example1" class="table">
	        <thead>
	          <tr>
	          	<th class="wd-5p">No</th>
				<th class="wd-5p">Tgl</th>
				<th class="wd-5p">Judul</th>
				<th class="wd-5p">Kategori</th>
				<th class="wd-5p">Dibutuhkan</th>
				<th class="wd-5p">Terkumpul</th>
				<th class="wd-5p">Sisa</th>
				<th class="wd-5p">Waktu</th>
				<th class="wd-5p">Foto</th>
				<th class="wd-15p">Opsi</th>
	          </tr>
	        </thead>
	        <tbody>
	        	<?php $i = 1; ?>
				<?php foreach($galangdana as $gdan): ?>
<?php 
$terkumpul = 0;

$this->db->select('donasi_gdid, SUM(donasi_jml) as terkumpul');
$this->db->where('donasi_status', 2);
$this->db->where('donasi_gdid', $gdan['gd_id']);
$query = $this->db->get('tb_donasi');

if ($query->row()->terkumpul > 0) {
$terkumpul = $query->row()->terkumpul;
}
?>
					<?php $sisa = $gdan['gd_dana'] - $terkumpul; ?>
				<tr>
					<td><?php echo $i; ?>.</td>	
					<td><?php echo date('d-m-Y', strtotime($gdan['gd_tgl'])); ?></td>
					<td><?php echo $gdan['gd_judul']; ?></td>
					<td><?php echo $gdan['kacam_nama']; ?></td>
					<td><?php echo number_format($gdan['gd_dana'],0,',','.'); ?></td>
					<td>
						<?php if($terkumpul == $gdan['gd_dana']) { ?>
							<span class="badge badge-success"><?php echo number_format($terkumpul,0,',','.'); ?></span>
						<?php }else { ?>
							<?php echo number_format($terkumpul,0,',','.'); ?>
						<?php } ?>
					</td>
					<td><?php echo number_format($sisa,0,',','.'); ?></td>
					<td><?php echo date('d-m-Y', strtotime($gdan['gd_tgl_selesai'])); ?></td>
					<td><a href="assets/home/img/<?php echo $gdan['gd_foto']; ?>" target="_blank"><img src="assets/home/img/<?php echo $gdan['gd_foto']; ?>" alt="<?php echo $gdan['gd_foto']; ?>" width="50"></a></td>
					<td>
						<a href="admin/galang-dana/edit/<?php echo $gdan['gd_id']; ?>" class="btn btn-sm btn-info"><i class="fa fa-edit me-1"></i> Edit</a>
						<a href="admin/galang-dana/hapus/<?php echo $gdan['gd_id']; ?>" onclick="return confirm('Yakin data ini akan dihapus?');" class="btn btn-sm btn-danger"><i class="fa fa-trash me-1"></i> Hapus</a>
					</td>
				</tr>
				<?php $i++; ?>
				<?php endforeach; ?>
	        </tbody>
	      </table>
      </div><!-- content-body -->