{% extends '../template.html' %}
{% block style %}
<link href="{% nav public %}css/infomodal.css" rel="stylesheet">
{% endblock %}
{% block subcontent %}
<!-- iModal -->
<div id="infoModal" class="imodal">
  <!-- iModal content -->
	<div class="imodal-content">
		<span class="close">&times;</span>
		<h2 id="modal-title">Akun Baru</h2>
		<br/>
		<form method="post">
			<input type="hidden" id="id_akun" name="id_akun" value=""/>
			<input type="hidden" id="id_jenis" name="id_jenis" value="{{jenis.id}}"/>
			<input type="hidden" id="posisi" name="posisi" value="{{jenis.posisi}}"/>
			<table cellpadding="5" cellspacing="0" border="0">
				<tr>
					<td style="width:80px">Jenis</td>
					<td><b>{{jenis.nama}}</b></td>
				</tr>
				<tr>
					<td style="width:80px">Kode</td>
					<td><input type="text" name="kode" id="kode" value="" style="width:40px"></td>
				</tr>
				<tr>
					<td style="width:80px">Subkode</td>
					<td><input type="text" name="subkode" id="subkode" value="" style="width:40px"></td>
				</tr>
				<tr>
					<td style="width:80px">Nama</td>
					<td><input type="text" name="nama" id="nama" value="" style="width:400px"></td>
				</tr>
				<tr>
					<td style="width:80px">Normal</td>
					<td>
						<select id="normal" name="normal">
							<option value="debit" {%if jenis.normal == 'debit'%}selected{%endif%}>debit</option>
							<option value="kredit" {%if jenis.normal == 'kredit'%}selected{%endif%}>kredit</option>
						</select>
					</td>
				</tr>
				<tr>
					<td style="width:80px">Posisi</td>
					<td><input type="text" value="{{jenis.posisi}}" disabled></td>
				</tr>
			</table>
			<table cellpadding="5" cellspacing="0" border="0">
				<tr>
					<td><span class="txtError" style="color:red"></span></td>
				</tr>
			</table>
			<br/><input type="submit" class="btn btn-success btnSimpan" value="Simpan"/> <span class="btn btn-danger btnBatal">Batal</span>
		</form>
		<br/>
	</div>
</div>

<h2>Keuangan - Akun</h2>
<h3>
	<select id="jenisAkun">
		{% for a in listJenis %}
		<option value="{{a.id}}" {%if a.id == jenis.id%}selected{%endif%}>{{a.kode}} - {{a.nama}}</option>
		{% endfor %}
	</select>
</h3>
<br/><br/>
<button type="button" class="btn btn-primary btnTambah" style="width:80px">Tambah</button>
<br/><br/>
{% if data.length > 0 %}
<table class="data">
	<tr>
		<th>Kode</th>
		<th>Nama Akun</th>
		<th>Normal</th>
		<th>Posisi</th>
		<th></th>
	</tr>
	{% for row in data %}
		<tr class="order_histori_{{row.id}} orders" valign="top">
			<td>{{row.kode}}-{{row.subkode}}</td>
			<td>{{row.nama}}</td>
			<td>{{row.normal}}</td>
			<td>{{row.posisi}}</td>
			<td style="width:100px">
				<button style='width:40px;' type="button" id_akun="{{row.id}}" class="btn btn-default btnUbah"><i class="far fa-edit"></i></button>
				<a onclick="return confirm('Apakah Anda Yakin Ingin Menghapus Data Ini ?');" class="btn btn-default" href="{% nav bendahara_keuangan_delakun %}/{{ row.id }}"><i class="far fa-trash-alt"></i></a>
			</td>
		</tr>
	{% endfor %}
</table>
{% else %}
	- Data Masih Kosong -<br/><br/>
{% endif %}
<br/><br/><br/>
{% endblock %}
{% block script %}
<script type="text/javascript" src="{% nav public %}js/infomodal.js"></script>
<script type="text/javascript">
	var modal = document.getElementById('infoModal');
	$(document).ready(function() {
		menuSelected("mSetting","smAkun");
		$('.btnTambah').on("click", function(){
			$("#id_akun").val("");
			$('#infoModal').show();
			$('#modal-title').html('Akun Baru');
			$('#kode').val('');
			$('#subkode').val('');
			$('#nama').val('');
		});
		$('.btnUbah').on("click", function(){
			$('.imodal-content').hide();
			$('#infoModal').show();
			$('#modal-title').html('Sedang memproses...');
			
			var id_akun = $(this).attr('id_akun');
			$("#id_akun").val(id_akun);
			$.ajax({
				type: "GET",
				url: "{% nav bendahara_keuangan_getakun %}?id="+id_akun,
				dataType: "json",
				async: true,
				cache: false,
				timeout:50000,
				success: function(data){
					$('#kode').val(data.kode);
					$('#subkode').val(data.kode);
					$('#nama').val(data.nama);
					$('#normal').val(data.normal);
					$('#modal-title').html('Edit Akun');
					$('.imodal-content').show();
				}
			});
		});
		$("#jenisAkun").on('change',function() {
			window.location='{% nav bendahara_keuangan_akun %}?idj='+$("#jenisAkun").val();
		});
		$(".btnBatal").on("click",function() {
			$("#infoModal").hide();
		});
	});
</script>
{% endblock %}