@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="#">Sumber Dana</a></li>
			<li class="active">Transaksi : {{ $transaksi }}</li>
		</ul>
	</div>
</div>

<div class="content">
	<div class="panel panel-flat">
		<div class="panel-heading">
			<h5 class="panel-title">Transaksi : {{ $transaksi }}</h5>

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

	    </div>

	    <form class="" role="form" id="form-transaksi-pemasukkan" method="post" action="{{ url('sumberdana/transaksi/simpan_transaksi') }}">
	    	{{ Form::hidden("id") }}
	    	{{ Form::token() }}
	    	{{ Form::hidden("jenis_transaksi", 2) }}
	    <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">
			    			<label class="control-label">Lokasi</label>
			    			<select name="lokasi" class="form-control set_select2" required="">
			    				@foreach($lokasi_produksi AS $key => $value)
			    				<option value="{{ $value->id_lokasi }}">{{ $value->nama_lokasi }}</option>
			    				@endforeach
			    			</select>
			    		</div>
	    			</div>
	    		</div>
	    		<div class="col-sm-12 col-md-12">
	    			<div class="col-sm-6 col-md-6">
	    				<div class="form-group">
		    				{{ Form::label("Setor ke", "", ['class'=>'control-label']) }}
		    				{{ Form::select("dari_akun", $akun, [], ['class'=>'form-control set_select2']) }}
		    				{{ Form::hidden("tipe_dari_akun", "D") }}
		    			</div>
	    			</div>
	    		</div>
	    		<div class="col-sm-12 col-md-12">
	    			<div class="col-sm-6 col-md-6">
	    				<div class="form-group">
	    					{{ Form::label("Diterima dari", "", ['class'=>'control-label']) }}
		    				{{ Form::text("penerima_transaksi", "", ['class'=>'form-control']) }}
	    				</div>
	    			</div>
	    		</div>
	    		<div class="col-sm-12 col-md-12">
	    			<div class="col-sm-3 col-md-3">
	    				<div class="form-group">
		    				{{ Form::label("No. Transaksi", "", ['class'=>'control-label']) }}
		    				{{ Form::text("nomor_transaksi", $no_urut, ['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_transaksi", "", ['class'=>'form-control set_datepicker']) }}
		    			</div>
	    			</div>
	    		</div>
	    		<div class="col-sm-12 col-md-12">
	    			<table class="table table-striped" id="tabel-transaksi-pemasukkan">
	    				<thead>
	    					<tr>
	    						<th>Terima dari</th>
	    						<th>Keterangan</th>
	    						<th>Nominal</th>
	    						<th>Tipe</th>
	    						<th></th>
	    					</tr>
	    				</thead>
	    				<tbody>

	    				</tbody>
	    				<tfoot>
	    					<tr>
	    						<td colspan="5">
	    							<button type="button" class="btn btn-xs btn-primary" onclick="tambah_row_akun()"><i class="icon-plus2"></i> Tambah</button>
	    						</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="resetFormPemasukkan()">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 formPemasukkan = $("#form-transaksi-pemasukkan");
var idTransfer = formPemasukkan.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_transaksi_sumberdana[]' value=''  class='form-control' />"+
          	// "<input type='text' name='tipe_ke_akun[]' value='K'  class='form-control' />"+
          	""+
          "<td style='vertical-align:top;' width='35%'><select name='ke_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='nominal_transaksi[]' 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;' width='8%'><select name='tipe_ke_akun[]' class='form-control set_select2'><?php $arr_tipe = ['K'=>'Kredit', 'D'=>'Debet']; foreach ($arr_tipe as $key => $value){ echo "<option value='$key'>$value</option>"; } ?></select></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-transaksi-pemasukkan > tbody").append(rows);
	$(".set_select2").select2();

}

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

function resetFormPemasukkan() {
	$('body').loading({
        start : true,
        message : 'Memuat ...'
    });
    setTimeout(function(){
		formPemasukkan[0].reset();
		idTransfer.val("");
		$("table#tabel-transaksi-pemasukkan > 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