@extends('layout')


@section('content')

<div class="page-header page-header-default">
	<div class="breadcrumb-line">
		<ul class="breadcrumb">
			<li><a href="#"><i class="icon-home2 position-left"></i> Keuangan</a></li>
			<li><a href="#">Jurnal Lain</a></li>
			<li class="active">Tambah Jurnal Lain</li>
		</ul>
	</div>
</div>

<div class="content">
	<div class="panel panel-flat">
		<div class="panel-heading">
			<h5 class="panel-title">Tambah Jurnal Lain</h5>

			<div class="heading-elements">
				<ul class="icons-list">
		      		<li><a href="{{ url('jurnal_lain') }}" class="text-warning"><i class="icon-circle-left2 warning"></i> Kembali</a></li>
		      	</ul>
	       	</div>

	    </div>

	    <form class="" role="form" id="form-jurnal-lain" method="post" action="{{ url('jurnal_lain/simpan_jurnal_lain') }}">
	    	{{ Form::hidden("id")}}
	    	{{ Form::token()}}
	    <div class="panel-body">
	    	<div class="row">
	    		<div class="col-sm-12 col-md-12">
	    			<div class="col-sm-3 col-md-3">
	    				<div class="form-group">
		    				{{ Form::label("No. Jurnal", "", ['class'=>'control-label']) }}
		    				{{ Form::text("nomor_jurnal", "", ['class'=>'form-control']) }}
		    			</div>
	    			</div>
	    			<div class="col-sm-3 col-md-3">
	    				<div class="form-group">
		    				{{ Form::label("Tanggal", "", ['class'=>'control-label']) }}
		    				{{ Form::text("tanggal_jurnal", "", ['class'=>'form-control set_datepicker']) }}
		    			</div>
	    			</div>
	    		</div>
	    		<div class="col-sm-12 col-md-12">
	    			<table class="table table-striped" id="tabel-akun-jurnal-lain">
	    				<thead>
	    					<tr>
	    						<th>Akun Perkiraan</th>
	    						<th>Keterangan</th>
	    						<th>Debet</th>
	    						<th>Kredit</th>
	    						<th></th>
	    					</tr>
	    				</thead>
	    				<tbody>

	    				</tbody>
	    				<tfoot>
	    					<tr>
	    						<td colspan="2">
	    							<button type="button" class="btn btn-xs btn-primary" onclick="tambah_row_akun()"><i class="icon-plus2"></i> Tambah</button>
	    						</td>
	    						<td>&nbsp;</td>
	    						<td>&nbsp;</td>
	    					</tr>
	    				</tfoot>
	    			</table>
	    		</div>

	    		<div class="col-sm-12 col-md-12">
	    			<div class="col-sm-12 col-md-12 text-right">
	    				<div class="form-group">
					    	<button type="button" class="btn btn-md btn-default" onclick="resetFormJurnalLain()">Batal</button>
					    	<button type="submit" class="btn btn-md btn-success"><i class="icon-floppy-disk"></i> Simpan</button>
		    			</div>
	    			</div>
	    		</div>
	    	</div>
	    </div>
		</form>
	    
	</div>
</div>

<script type="text/javascript">
var formJurnalLain = $("#form-jurnal-lain");
var idJurnalLain = formJurnalLain.find("input[name=id]");

$(document).ready(function () {
	$(".set_select2").select2();
	$(".set_datepicker").datepicker({
		format : 'dd/mm/yyyy',
		autoclose : true,
      	zIndexOffset : 9999,
	});
});

function tambah_row_akun() {
	var rows = "<tr>"+
          "<td class='hide'><input type='text' name='id_jurnal_lain_detail[]' value=''  class='form-control' /></td>"+
          "<td style='vertical-align:top;' width='35%'><select name='id_akun[]' class='form-control set_select2'><?php foreach ($id_akun as $key => $value){ echo "<option value='$key'>$value</option>"; } ?></select></td>"+
          "<td style='vertical-align:top;'><input type='text' name='keterangan[]' value='-'  class='form-control' /></td>"+
          "<td style='vertical-align:top;'><input type='text' name='debet[]' value='0'  class='form-control text-right' onkeyup='setFormatMoney($(this), \"td\")' /><strong><span class='help-block text-right'>0,00</span></strong></td>"+
          "<td style='vertical-align:top;'><input type='text' name='kredit[]' value='0'  class='form-control text-right' onkeyup='setFormatMoney($(this), \"td\")' /><strong><span class='help-block text-right'>0,00</span></strong></td>"+
          "<td style='vertical-align:top;'><button type='button' class='btn btn-xs btn-link text-danger' onclick='hapusRowAkun($(this))'><i class='icon-trash'></i></button></td>"+
        "</tr>";
  	$("table#tabel-akun-jurnal-lain > tbody").append(rows);
  	$(".set_select2").select2();
}

function hapusRowAkun(this_) {
	var row = this_.parents("tr");
	row.remove();
}

function resetFormJurnalLain() {
	$('body').loading({
        start : true,
        message : 'Memuat ...'
    });
    setTimeout(function(){
		formJurnalLain[0].reset();
		idJurnalLain.val("");
  		$("table#tabel-akun-jurnal-lain > tbody").html("");
    	$('body').loading({
	        start : false,
	        message : 'Memuat ...'
	    });
    }, 1000);

}

function setFormatMoney(this_, p) {
	var div = this_.parents(p);
	var data = this_.val();
	if(data==""){
		data = 0;
	}
	div.find(".help-block").html(curr(data));
}
</script>

@endsection