@extends('layout.base')

@section('content')
<div class="panel panel-default">
	<div class="panel-heading">Agregar Crédito - {{$venta->unidad()->descripcion}} - {{$venta->proyecto()->descripcion}}</div>
	<div class="panel-body">
	<form action="{{url('', ['p' => 'creditos', 'a' => 'agregado', 'venta' => $venta->id])}}" method="post" class="form-horizontal">
		<div class="form-group">
			<div class="col-md-2">Banco</div>
			<div class="col-md-5"><input type="text" name="banco" class="form-control" id="banco" autocomplete="off" /></div>
		</div>
		<div class="form-group">
			<div class="col-md-2">Valor [UF]</div>
			<div class="col-md-4"><input type="text" name="valor" class="form-control" /></div>
			<div class="col-md-1">UF</div>
		</div>
		<div class="form-group">
			<div class="col-md-2">Fecha</div>
			<div class="col-md-1">
			<?php $f = \Carbon\Carbon::today(config('app.timezone')) ?>
			<select name="d" class="form-control">
			@for ($i = 0; $i < 31; $i ++)
				<option value="{{$i + 1}}"
				@if ($i + 1 == $f->day)
				selected="selected"
				@endif
				>{{str_pad($i + 1, 2, '0', STR_PAD_LEFT)}}</option>
			@endfor
			</select></div>
			<div class="col-md-1"><select name="m" class="form-control">
			@for ($i = 0; $i < 12; $i ++)
				<option value="{{$i + 1}}"
				@if ($i + 1 == $f->month)
				selected="selected"
				@endif
				>{{str_pad($i + 1, 2, '0', STR_PAD_LEFT)}}</option>
			@endfor
			</select></div>
			<div class="col-md-2"><select name="y" class="form-control">
			@for ($i = $f->year; $i > $f->year - 5; $i --)
				<option value="{{$i}}">{{$i}}</option>
			@endfor
			</select></div>
		</div>
		<div class="form-group">
			<div class="col-md-offset-2 col-md-3"><input type="submit" value="Agregar" class="form-control" /></div>
		</div>
	</form>
	</div>
</div>
@endsection

@push('scripts')
<script type="text/javascript">
$(document).ready(function() {
	$.getJSON('{!!url('', ['p' => 'ajax', 'a' => 'buscar', 't' => 'bancos'])!!}', function(data, status, xhr) {
		$('#banco').typeahead({"source": data});
	});
});
</script>
@endpush