@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 class="active">Jurnal Penyesuaian Sewa</li>
		</ul>
	</div>
</div>

<div class="content">
	<div class="row">
		<div class="col-lg-12">
			@if(Session::has('flash_message_error'))
	    	<div class="alert alert-danger no-border">
				<button type="button" class="close" data-dismiss="alert"><span>×</span><span class="sr-only">Close</span></button>
				{!! session('flash_message_error') !!}
				<!-- <span class="text-semibold">Well done!</span> You successfully read <a href="#" class="alert-link">this important</a> alert message. -->
		    </div>
		    @elseif(Session::has('flash_message_success'))
		    <div class="alert alert-success no-border">
				<button type="button" class="close" data-dismiss="alert"><span>×</span><span class="sr-only">Close</span></button>
				{!! session('flash_message_success') !!}
				<!-- <span class="text-semibold">Well done!</span> You successfully read <a href="#" class="alert-link">this important</a> alert message. -->
		    </div>
		    @endif
		</div>
	</div>
	<div class="panel panel-flat">
		<div class="panel-heading">
			<h5 class="panel-title">Form Jurnal Penyesuaian Sewa</h5>
			<div class="heading-elements">
				<ul class="icons-list">
		      		<li><a href="{{ url('jurnal-penyesuaian-sewa') }}" class="text-warning"><i class="icon-circle-left2 warning"></i> Kembali</a></li>
		      	</ul>
	       	</div>
	    </div>
	    
	    <div class="panel-body">
	    	<form class="form-horizontal" id="form_retur" method="POST" action="{{ route('js.createPenyesuaianSewa') }}" autocomplete="off" >
	    		{{ csrf_field() }}

        	<div class="col-lg-6">
        		<div class="form-group">
	    			{{ Form::label("No. Faktur", "", ['class'=>'control-label col-sm-4']) }}
	    			<div class="col-sm-8">
	    				<select class="form-control select-search" name="id_sewa" id="id_sewa" required>
	    					<option value="">-- Pilih No Faktur --</option>
	    					@foreach($no_faktur as $key => $value)
	    					<option value="{{ $value->id_sewa }}">{{ $value->no_faktur }} ({{ $value->nama_penyedia }})</option>
	    					@endforeach
	    				</select>
	    			</div>
	    		</div>
        		<div class="form-group">
        			<label class="control-label col-sm-4">Tanggal Jurnal</label>
        			<div class="col-sm-8">
        				<input class="form-control set_datepicker" type="text" name="tanggal_jurnal" placeholder="Tanggal Jurnal" data-mask="99/99/9999" value="{{ date('d/m/Y') }}" required/>
        			</div>
        		</div>
        		<div class="form-group">
        			<label class="control-label col-sm-4">Keterangan</label>
        			<div class="col-sm-8">
        				<textarea class="form-control" name="keterangan" rows="2"></textarea>
        			</div>
        		</div>
        	</div>

    		<div class="col-lg-12">
    			<button type="button" class="btn btn-xs btn-primary" id="btn_add"><i class="fa fa-plus"></i> Tambah Data</button>
    			<table class="table table-striped" id="table_jurnal">
        			<thead> 
        				<tr>
        					<td>Akun</td>
        					<td>Tipe Akun</td>
        					<td>Nominal</td>
        					<td></td>
        				</tr>
        			</thead>
        			<tbody>
        				<tr>
        					<td>
        						{{ Form::select("id_akun[]", $akun, [], ['class'=>'form-control select-search']) }}
        					</td>
        					<td>
        						<select class="form-control select-search" name="tipe_akun[]">
        							<option value="D">Debit</option>
        							<option value="K">Kredit</option>
        						</select>
        					</td>
        					<td>
		        				<input type="number" step="0.01" min="0" name="nominal[]" class="form-control text-right" value="0">
        					</td>
        					<td>
        					</td>
        				</tr>
        			</tbody>
        		</table>
    		</div>
	    </div>

	    <div class="panel-footer">
	    	<div class="col-sm-12 col-md-12">
	            <div class="form-group pull-right">
	            	<a href="{{ route('js.indexPenyesuaianSewa') }}" class="btn btn-default">Batal</a>
	             	<button class="hidden" type="submit" id="btn-submit">Simpan</button>
	             	<button class="btn btn-success" type="button" id="btn_simpan">Simpan</button>
	            </div>

	    	</div>

	    </div>

	    </form>
	</div>
</div>


<script type="text/javascript">
var tabel;

$(document).ready(function(){
	// init element
	$(".set_select2").select2();

	$("#btn_simpan").on("click", function(evt){
		if ($("#id_sewa").val() == "") {
			$("#id_sewa").select2('open');
			alert('Pilih nomor faktur!');
		} else {
			$("#btn-submit").trigger("click");
			$("#btn_simpan").attr('disabled', true);
		}
	})

	$("#btn_add").click(function(evt){
		evt.preventDefault();
		var row = '<tr>'+
					'<td>'+
						'{{ Form::select("id_akun[]", $akun, [], ["class"=>"form-control select-search"]) }}'+
					'</td>'+
					'<td>'+
						'<select class="form-control select-search" name="tipe_akun[]">'+
							'<option value="D">Debit</option>'+
							'<option value="K">Kredit</option>'+
						'</select>'+
					'</td>'+
					'<td>'+
        				'<input type="number" step="0.01" min="0" name="nominal[]" class="form-control text-right" value="0">'+
					'</td>'+
					'<td class="text-center">'+
						'<button type="button" class="btn btn-xs btn-danger btn_remove" onclick="removeRow($(this))"><i class="fa fa-times"></i></button>'+
					'</td>'+
				'</tr>';

		$("#table_jurnal tbody").append(row);
		$('.select-search').select2();
	})

});

function removeRow(this_){
	this_.closest('tr').remove();
}

</script>

@endsection