@extends('layout')

@section('content')

<div class="page-header page-header-default">
	<div class="breadcrumb-line">
		<ul class="breadcrumb">
			<li><a href="index.html"><i class="icon-home2 position-left"></i> Master</a></li>
			<li class="active">Manajemen Aset</li>
		</ul>
	</div>
</div>

<div class="content">
	<div class="panel panel-flat">
		<div class="panel-heading">
			<h5 class="panel-title">Manajemen Aset</h5>
			<div class="heading-elements">
				<ul class="icons-list">
		      		<li><a href="{{ url('manajemen-aset') }}" class="text-warning"><i class="icon-circle-left2 warning"></i> Kembali</a></li>
		      		<!-- <li><a data-action="collapse"></a></li> -->
		      	</ul>
	       	</div>
	    </div>
	    <div class="panel-body">

			<form class="form-horizontal" method="POST" action="{{ $url_submit }}" id="form_add_aset_jual">
				{{ csrf_field() }}
				{{ method_field($method) }}

				<div class="row">

						<div class="col-sm-12 col-md-6">

							<fieldset class="content-group">
								<legend class="text-bold">Detail</legend>
								<div class="col-sm-12 col-md-12">
					      			<div class="form-group">
					      				<label class="control-label col-sm-3">Nama Aset</label>
					      				<div class="col-sm-9">
					      					<input type="hidden" name="id_aset" value="{{$aset->id}}">
					      					<input type="text" name="nama_aset" class="form-control" value="{{ $aset->nama_aset }}" readonly="">
					      				</div>
					      			</div>
									<div class="form-group">
					      				<label class="control-label col-sm-3">Akun Aset</label>
					      				<div class="col-sm-9">
					      					<input type="hidden" name="id_akun_aset" value="{{ $aset->id_akun_aset }}" readonly>
					      					<input type="text" name="akun_aset" class="form-control" value="{{ format_akun_perkiraan($aset->akunAset) }}" readonly>
					      				</div>
					      			</div>
					      			<div class="form-group">
					      				<label class="control-label col-sm-3">Biaya Akuisisi</label>
					      				<div class="col-sm-9">
					      					<input type="text" name="biaya_akuisisi" class="form-control text-right" value="{{ $aset->biaya_akuisisi }}" onkeyup="setFormatMoney($(this), 'div')" readonly>
					      					<span class="help-block format-money text-right">Rp0,00</span>
					      				</div>
					      			</div>
					      			<div class="form-group">
					      				<label class="control-label col-sm-3">Akun Akumulasi Penyusutan</label>
					      				<div class="col-sm-9">
					      					<input type="hidden" name="id_akun_akumulasi_penyusutan" value="{{ $aset->id_akun_akumulasi_penyusutan }}">
					      					<input type="text" name="akun_akumulasi_penyusutan" class="form-control" value="{{ format_akun_perkiraan($aset->akunAkumulasiPenyusutan) }}" readonly>
					      				</div>
					      			</div>
					      			<div class="form-group">
					      				<label class="control-label col-sm-3">Akumulasi Penyusutan</label>
					      				<div class="col-sm-9">
					      					<input type="text" name="akumulasi_penyusutan" class="form-control text-right" onkeyup="setFormatMoney($(this), 'div')" value="{{$aset_penyusutan->akumulasi_penyusutan}}" readonly>
					      					<span class="help-block format-money text-right"></span>
					      				</div>
					      			</div>
								</div>
							</fieldset>

						</div>

						<div class="col-sm-12 col-md-6">

							<fieldset class="content-group">
								<legend class="text-bold">Pelepasan Aset</legend>
								<div class="col-sm-12 col-md-12">
					      			<div class="form-group">
					      				<label class="control-label col-sm-4">Tanggal Transaksi</label>
					      				<div class="col-sm-8">
					      					<input type="text" name="tanggal_jual" class="form-control datepicker" value="{{date('d-m-Y')}}">
					      				</div>
					      			</div>
					      			<div class="form-group">
					      				<label class="control-label col-sm-4">Harga Jual</label>
					      				<div class="col-sm-8">
					      					<input type="text" name="harga_jual" class="form-control text-right" onkeyup="isNumberKey(event), setFormatMoney($(this), 'div')" value="0">
					      					<span class="help-block format-money text-right">Rp0,00</span>
					      				</div>
					      			</div>
					      			<div class="form-group">
					      				<label class="control-label col-sm-4">Setor Ke</label>
					      				<div class="col-sm-8">
					      					{{ Form::select("id_akun_terima", $akun, [null], ["class"=>"form-control select-search", "required"=>""])}}
					      				</div>
					      			</div>
					      			<div class="form-group">
					      				<label class="control-label col-sm-4">Selisih</label>
					      				<div class="col-sm-8">
					      					<select name="tipe_id_akun_selisih" class="form-control">
					      						<option value="K">Keuntungan</option>
					      						<option value="D">Kerugian</option>
					      					</select>
					      				</div>
					      			</div>
					      			<div class="form-group">
					      				<label class="control-label col-sm-4">Akun Selisih</label>
					      				<div class="col-sm-8">
					      					{{ Form::select("id_akun_selisih", $akun, [null], ["class"=>"form-control select-search", "required"=>""])}}
					      				</div>
					      			</div>
					      			<div class="form-group">
					      				<label class="control-label col-sm-4">Nilai Selisih</label>
					      				<div class="col-sm-8">
					      					<input type="text" name="nilai_selisih" class="form-control text-right" onkeyup="isNumberKey(event), setFormatMoney($(this), 'div')" value="0">
					      					<span class="help-block format-money text-right">Rp0,00</span>
					      				</div>
					      			</div>
								</div>
							</fieldset>
						</div>
					
				</div>

		</div>

		<div class="panel-footer">
			<div class="col-sm-12 col-md-12 text-right">
				<button class="btn btn-success" type="submit"><i class="fa fa-save"></i> Lepas Aset</button>					
			</div>
		</div>
		
		</form>
	</div>
</div>

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

	$(document).ready(function(){
		validator_form_add_aset_jual = $("#form_add_aset_jual").validate({
	        ignore: 'input[type=hidden], .select2-input, .select2-focusser', // ignore hidden fields
	        errorClass: 'validation-error-label',
	        successClass: 'validation-valid-label',
	        highlight: function(element, errorClass, validClass) {
	            $(element).removeClass(errorClass);
	        },
	        unhighlight: function(element, errorClass, validClass) {
	            $(element).removeClass(errorClass);
	        },// Different components require proper error label placement
	        errorPlacement: function(error, element) {
				if (element.parents('div').hasClass('has-feedback') || element.hasClass('select2-hidden-accessible')) {
	                error.appendTo( element.parent() );
	            } else {
	                error.insertAfter(element);
	            }
	        },
	        rules: {
				id_akun_terima: "required",
				id_akun_selisih: "required",
			},
			messages: {
				id_akun_terima: "Pastikan pilihan akun",
				id_akun_selisih: "Pastikan pilihan akun",
			}
	    });

	    $('select').select2({}).on("change", function (e) {
		  $(this).valid()
		});
		@if($aset->asetJual()->count() > 0)
		edit_aset_jual();
		@endif

		$("input[name=biaya_akuisisi], input[name=akumulasi_penyusutan], input[name=harga_jual], input[name=nilai_selisih]").trigger("keyup");
	})

	@if($aset->asetJual()->count() > 0)
	function edit_aset_jual()
	{
		$("#form_add_aset_jual input[name=tanggal_jual]").val('{{date_db($aset->asetJual->tanggal_jual, true, 2)}}');
		$("#form_add_aset_jual input[name=harga_jual]").val('{{$aset->asetJual->harga_jual}}').trigger("keyup");
		$("#form_add_aset_jual select[name=id_akun_terima]").val('{{$aset->asetJual->id_akun_terima}}').trigger("change");
		$("#form_add_aset_jual select[name=tipe_id_akun_selisih]").val('{{$aset->asetJual->tipe_id_akun_selisih}}').trigger("change");
		$("#form_add_aset_jual select[name=id_akun_selisih]").val('{{$aset->asetJual->id_akun_selisih}}').trigger("change");
		$("#form_add_aset_jual input[name=nilai_selisih]").val('{{$aset->asetJual->nilai_selisih}}').trigger("keyup");
	}
	@endif

	function setFormatMoney(this_, p) {
		var parentz = this_.parent(p);
		var data = this_.val();
		parentz.find(".format-money").text(accounting.formatMoney(data));
	}
</script>

@endsection