@extends('layout.base') @section('content')
<div class="panel panel-default">
	<div class="panel-heading">Agregar Cuotas - <a href="{{url('', ['p' => 'pies', 'a' => 'resumen', 'pie' => $pie->id])}}">Departamento {{$pie->venta()->unidad()->descripcion}}</a> - {{$pie->venta()->proyecto()->descripcion}}</div>
	<div class="panel-body">
		@if (count($pie->venta()->propietario()->ventas()) > 1)
		<form class="form-horizontal" method="post" action="{{url('', ['p' => 'pies', 'a' => 'asociar', 'pie' => $pie->id])}}">
			<div class="form-group">
				<div class="col-md-3">
					<select name="asociado" class="form-control">
						@foreach ($pie->venta()->propietario()->ventas() as $v)
							@if ($v->unidad()->id == $pie->venta()->unidad()->id)
								@continue
							@endif
						<option value="{{$v->pie()->id}}">
							{{$v->unidad()->descripcion}} - {{$v->proyecto()->descripcion}}
							@if ($v->pie()->asociado == 0)
								({{count($v->pie()->cuotas())}})
							@endif
						</option>
						@endforeach
					</select>
				</div>
				<div class="col-md-2"><input type="submit" class="form-control" value="Asociar" /></div>
			</div>
		</form>
		@endif
		<form class="form-horizontal" method="post" action="{{url('', ['p' => 'cuotas', 'a' => 'agregar', 'pie' => $pie->id])}}">
			<?php $t = \Carbon\Carbon::today(config('app.timezone')) ?>
			<table class="table">
			<thead>
			<tr>
				<th>#</th>
				<th colspan="3">Fecha</th>
				<th>Banco</th>
				<th>Identificador</th>
				<th>Valor [$]</th>
			</tr>
			</thead>
			<tbody>
			<?php $cant = $pie->cuotas - count($pie->cuotas()); $ini = count($pie->cuotas()) + 1 ?>
			@for ($n = 0; $n < $cant; $n ++)
			<tr>
				<td>
					<div class="input-group">
						<input type="text" size="2" maxlength="2" name="numero{{$n}}" class="form-control" value="{{$ini + $n}}" />
						<span class="input-group-addon glyphicon glyphicon-copy" data-name="numero" data-n="{{$n}}"></span>
					</div>
				</td>
				<td><select name="day{{$n}}" class="form-control">
				@for ($i = 0; $i < 31; $i ++)
					<option value="{{$i + 1}}"
					@if ($i + 1 == $t->day)
					selected="selected"
					@endif
					>{{str_pad($i + 1, 2, '0', STR_PAD_LEFT)}}</option>
				@endfor
				</select></td>
				<td><select name="month{{$n}}" class="form-control">
				@for ($i = 0; $i < 12; $i ++)
					<option value="{{$i + 1}}"
					@if ($i + 1 == $t->month)
						selected="selected"
					@endif
					>{{str_pad($i + 1, 2, '0', STR_PAD_LEFT)}}</option>
				@endfor
				</select></td>
				<td>
					<div class="input-group">
						<select name="year{{$n}}" class="form-control">
				@for ($i = $t->year + 4; $i > $t->year - 5; $i --)
							<option value="{{$i}}"
					@if ($i == $t->year)
						selected="selected"
					@endif
					>{{$i}}</option>
				@endfor
						</select>
						<span class="input-group-addon glyphicon glyphicon-copy" data-n="{{$n}}" data-name="fecha"></span>
					</div>
				</td>
				<td>
					<div class="input-group">
						<input type="text" name="banco{{$n}}" class="banco form-control" autocomplete="off" />
						<span class="input-group-addon glyphicon glyphicon-copy" data-n="{{$n}}" data-name="banco"></span>
					</div>
				</td>
				<td>
					<div class="input-group">
						<input type="text" name="identificador{{$n}}" class="form-control" />
						<span class="input-group-addon glyphicon glyphicon-copy" data-n="{{$n}}" data-name="identificador"></span>
					</div>
				</td>
				<td>
					<div class="input-group">
						<input type="text" name="valor{{$n}}" class="form-control" />
						<span class="input-group-addon glyphicon glyphicon-copy" data-n="{{$n}}" data-name="valor"></span>
					</div>
				</td>
			</tr>
			@endfor
			</tbody>
			</table>
			<input type="hidden" name="cuotas" value="{{$cant}}" />
			<div class="form-group">
				<div class="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').each(function(i, e) {
			$(this).typeahead({"source": data});
		});
	});
});
</script>
<script type="text/javascript" src="{!!url('js/ventas/pies/cuotas/add.js')!!}"></script>
@endpush
