<div class="container-fluid" id="container-wrapper">
	<div class="d-sm-flex align-items-center justify-content-between mb-4">
		<h1 class="h3 mb-0 text-gray-800"><?= $title;  ?></h1>
		<ol class="breadcrumb">
			<li class="breadcrumb-item"><a href="./">Home</a></li>
			<li class="breadcrumb-item active" aria-current="page"><?= $title;  ?></li>
		</ol>
	</div>
	<?php
        echo $this->session->flashdata('message');
	?>
	<div class="card">
		
		<div class="row">
			<div class="col-sm-12">
				<div class="card">
					<div class="card-header py-0">
						
						<div class="row">
							<div class="col my-3">
								Tabel Data Akun
							</div>
							<div class="col my-3">
								<div class="form-group">
									<div class="pull-right">
										<a href="<?= base_url(); ?>masterdata/add" class="btn btn-sm btn-primary shadow-sm">
											<i class="fa fa-plus fa-sm text-white-50"></i>
											<span class="text">Tambah Data Akun</span>
										</a>
									</div>
								</div>
							</div>
						</div>
					</div>
					<div class="card-body pt-0">
						<div class="table-responsive">
							<table class="table table-dataAkun table-striped table-bordered table-sm" id="tabel-data">
								<thead class="text-center">
									<tr>
										<th scope="col" rowspan="2">#</th>
										<th scope="col" rowspan="2">Kelompok Akun</th>
										<th scope="col" rowspan="2" width="20%">No Akun</th>
										<th scope="col" rowspan="2">Nama Akun</th>
										<th scope="col" colspan="2">Saldo Awal</th>
										
										<th scope="col" rowspan="2">Action</th>
										
									</tr>
									<tr>
										<th scope="col">Debit</th>
										<th scope="col">Kredit</th>
									</tr>
								</thead>
								<tbody>
									<?php $i = 1; ?>
									<?php $total_debit = 0; ?>
									<?php $total_kredit = 0; ?>
									<?php foreach ($masterdata as $md) : ?>
									<tr>
										<th width="10px" scope="row"><?= $i++; ?></th>
										<td width="20%"><?= $md['nama_kel_akun']; ?></td>
										<td width="10%" class="text-center"><?= $md['noakun']; ?></td>
										<td ><?= $md['nama']; ?></td>
										<?php 
											if ($md['id_perkiraan'] == 1) {
											?>
											<td width="15%" align="right"><?= 'Rp. '.number_format($md['saldo_awal'],0,',','.') ?></td>
											<td></td>
											<?php $total_debit += $md['saldo_awal']; ?>
											<?php  
												} else {
											?>
											<td></td>
											<td width="15%" align="right"><?= 'Rp. '.number_format($md['saldo_awal'],0,',','.') ?></td>
											<?php $total_kredit += $md['saldo_awal']; ?>
											<?php  
											}
										?>
										
										<td class="text-center" width="15%">
											<a href="<?= base_url(); ?>masterdata/edit/<?= $md['id_akun']; ?>" class="badge badge-primary">
												<span class="icon text-white-50">
													<i class="fa fa-fw fa-edit"></i>
												</span>
												<span class="text">Edit</span>
											</a>
											<a href="<?= base_url(); ?>masterdata/delete/<?= $md['id_akun']; ?>" class="badge badge-danger" onclick="return confirm('yakin?');">
												<span class="icon text-white-50">
													<i class="fa fa-fw fa-trash"></i>
												</span>
												<span class="text">Delete</span>
											</a>
										</td>
										
									</tr>
									<?php endforeach; ?>
								</tbody>
								<tfoot>
									<tr>
										<th colspan="4" class="text-right">Total</th>
										<th><?= 'Rp. '.number_format($total_debit,0,',','.') ?></th>
										<th><?= 'Rp. '.number_format($total_kredit,0,',','.') ?></th>
										
										<th></th>
										
									</tr>
								</tfoot>
							</table>
						</div>
					</div>
				</div>
			</div>
		</div>
		
	</div>
</div>
<!-- /.container-fluid -->
<script>
	$(document).ready(function() {
		$('#tabel-data').DataTable();
		
		$(".bootstrap-select").selectpicker();
	});
</script>