@extends('layout.base')

@section('content')
<div class="row page-heading">
	<h3>Editar Forma de Pago - {{$venta->unidad()->descripcion}} - {{$venta->proyecto()->descripcion}}</h3>
</div>
<form method="post" class="form-horizontal" action="{{url('', ['p' => 'forma_pago', 'a' => 'editar', 'venta' => $venta->id])}}">
@if ($venta->pie != 0)
<div class="row section-heading">
	<div class="col-md-12 h2">Pie</div>
</div>
<br />
<div class="form-group">
	<div class="col-md-2">Valor [UF]</div>
	<div class="col-md-3"><input type="text" name="valor_pie" class="form-control" value="{{$venta->pie()->valor}}" /></div>
</div>
<div class="form-group">
	<div class="col-md-2">Cuotas</div>
	<div class="col-md-2"><input type="text" name="cuotas_pie" class="form-control" value="{{$venta->pie()->cuotas}}" /></div>
</div>
@if ($venta->pie()->reajuste != 0)
<div class="row section-heading">
	<div class="col-md-12 h2">Reajuste</div>
</div>
<br />
<div class="form-group">
	<div class="col-md-2">Fecha</div>
	<?php $id = '_reajuste'; $f = \Carbon\Carbon::parse($venta->pie()->reajuste()->fecha, config('app.timezone')) ?>
	@include('form.fecha')
</div>
<div class="form-group">
	<div class="col-md-2">Valor [$]</div>
	<div class="col-md-3"><input type="text" name="valor_reajuste" class="form-control" value="{{$venta->pie()->reajuste()->valor}}" /></div>
</div>
@else
<div class="form-group">
	<div class="col-md-2">Fecha</div>
	<?php $id = '_reajuste' ?>
	@include('form.fecha')
</div>
@endif
@endif
<div class="row section-heading">
	<div class="col-md-12 h2">Escritura</div>
</div>
<br />
@if ($venta->escritura != 0)
<div class="form-group">
	<div class="col-md-2">Fecha</div>
	<?php $id = '_escritura'; $f = \Carbon\Carbon::parse($venta->escritura()->pago()->fecha, config('app.timezone')) ?>
	@include('form.fecha')
</div>
<div class="form-group">
	<div class="col-md-2">Valor [$]</div>
	<div class="col-md-3"><input type="text" name="valor_escritura" class="form-control" value="{{$venta->escritura()->pago()->valor}}" /></div>
</div>
@else
<div class="form-group">
	<div class="col-md-2">Fecha</div>
	<?php $id = '_escritura'; unset($f) ?>
	@include('form.fecha')
</div>
<div class="form-group">
	<div class="col-md-2">Valor [$]</div>
	<div class="col-md-3"><input type="text" name="valor_escritura" class="form-control" /></div>
</div>
@endif
<div class="row section-heading">
	<div class="col-md-12 h2">Cr&eacute;dito</div>
</div>
<br />
@if ($venta->credito != 0)

@endif
<div class="form-group">
	<div class="col-md-offset-2 col-md-2"><input type="submit" value="Editar" class="form-control" /></div>
</div>
</form>
@endsection
<?php
/*
$total = 0; $total_uf = 0; $anticipo = 0; $anticipo_uf = 0 ?>
<tbody>
@if ($venta->pie != 0)
<tr>
	<td>Pie <a href="{{url('', ['p' => 'pies', 'a' => 'edit', 'venta' => $venta->id])}}"><span class="glyphicon glyphicon-edit small"></span></a></td>
	<?php
	$total += $venta->pie()->valorPagado('pesos');
	$total_uf = $venta->pie()->valorPagado();
	$anticipo += $venta->pie()->valorPagado('pesos');
	$anticipo_uf += $venta->pie()->valorPagado()
	?>
	<td class="text-right">{{format('ufs', $venta->pie()->valor)}} UF</td>
	<td class="text-right">$ {{format('pesos', $venta->pie()->valorPesos())}}</td>
	<td>Cuotas</td>
	<td>
		<a href="{{url('', ['p' => 'pies', 'action' => 'resumen', 'pie' => $venta->pie()->id])}}">{{count($venta->pie()->pagadas())}} / {{$venta->pie()->cuotas}}</a>
		@if (count($venta->pie()->cuotas()) < $venta->pie()->cuotas)
		<a href="{{url('', ['p' => 'cuotas', 'a' => 'add', 'pie' => $venta->pie()->id])}}"><span class="small glyphicon glyphicon-plus"></span></a>
		@endif
	</td>
</tr>
<tr>
	<td style="border-top: 1px dashed #ddd;">Pagado</td>
	<td style="border-top: 1px dashed #ddd;" class="text-right">{{format('ufs', $venta->pie()->valorPagado())}} UF</td>
	<td style="border-top: 1px dashed #ddd;" class="text-right">$ {{format('pesos', $venta->pie()->valorPagado('pesos'))}}</td>
	@if ($venta->pie()->reajuste == 0)
		@if ($venta->escriturado == 0)
	<td style="border-top: 1px dashed #ddd;"><a class="small" href="{{url('', ['p' => 'pies', 'a' => 'reajustar', 'venta' => $venta->id])}}">Reajustar <span class="glyphicon glyphicon-plus"></span></a></td>
	<td style="border-top: 1px dashed #ddd;"></td>
		@else
	<td style="border-top: 1px dashed #ddd;" colspan="2"></td>
		@endif
	@else
	<?php
	$total += $venta->pie()->reajuste()->valor;
	$total_uf += $venta->pie()->reajuste()->valor('ufs');
	$anticipo += $venta->pie()->reajuste()->valor;
	$anticipo_uf += $venta->pie()->reajuste()->valor('ufs');
	?>
	<td style="border-top: 1px dashed #ddd;" colspan="2"></td>
</tr>
<tr>
	<td>Reajuste <a href="{{url('', ['p' => 'reajustes', 'a' => 'edit', 'venta' => $venta->id])}}"><span class="small glyphicon glyphicon-edit"></span></a></td>
	<td class="text-right">{{format('ufs', $venta->pie()->reajuste()->valor('ufs'))}} UF</td>
	<td class="text-right">$ {{format('pesos', $venta->pie()->reajuste()->valor)}}</td>
	<td>{{format('shortDate', $venta->pie()->reajuste()->estado()->fecha)}}
		@if ($venta->pie()->reajuste()->estado()->estado < 2)
		<a href="{{url('', ['p' => 'reajustes', 'a' => 'abonar', 'venta' => $venta->id])}}">&check;</a>
		@endif
	</td>
	@endif
</tr>
@endif
@if ($venta->bono_pie != 0)
<tr>
	<td>Bono Pie <a href="{{url('', ['p' => 'bonos', 'a' => 'edit', 'venta' => $venta->id])}}"><span class="small glyphicon glyphicon-edit"></span></a></td>
	<?php
	$total += $venta->bonoPie()->pago()->valor;
	$total_uf += $venta->bonoPie()->pago()->valor('ufs');
	$anticipo += $venta->bonoPie()->pago()->valor;
	$anticipo_uf += $venta->bonoPie()->pago()->valor('ufs');
	?>
	<td class="text-right">{{format('ufs', $venta->bonoPie()->pago()->valor('ufs'))}} UF</td>
	<td class="text-right">$ {{format('pesos', $venta->bonoPie()->pago()->valor)}}</td>
	<td colspan="2"></td>
</tr>
@endif
@if ($venta->escritura != 0)
<?php
$total += $venta->escritura()->pago()->valor;
$total_uf += $venta->escritura()->pago()->valor('ufs');
$anticipo += $venta->escritura()->pago()->valor;
$anticipo_uf += $venta->escritura()->pago()->valor('ufs');
?>
<tr>
	<td>Escritura <a href="{{url('', ['p' => 'escrituras', 'a' => 'edit', 'venta' => $venta->id])}}"><span class="small glyphicon glyphicon-edit"></span></a></td>
	<td class="text-right">{{format('ufs', $venta->escritura()->pago()->valor('ufs'))}} UF</td>
	<td class="text-right">$ {{format('pesos', $venta->escritura()->pago()->valor)}}</td>
	<td>{{format('shortDate', $venta->escritura()->pago()->estado()->fecha)}}
		@if ($venta->escritura()->pago()->estado()->estado == 1)
		<a href="{{url('', ['p' => 'escrituras', 'a' => 'abonar', 'venta' => $venta->id])}}">&check;</a>
		@elseif ($venta->escritura()->pago()->estado()->estado == 0)
		<a href="{{url('', ['p' => 'escrituras', 'a' => 'depositar', 'venta' => $venta->id])}}">&check;</a>
		@endif
	</td>
	<td></td>
</tr>
@endif
<tr>
	<td><b>Anticipo</b></td>
	<td class="text-right"><b>{{format('ufs', $anticipo_uf)}} UF</b></td>
	<td class="text-right"><b>$ {{format('pesos', $anticipo)}}</b></td>
	<td colspan="2"></td>
</tr>
@if ($venta->subsidio != 0)
<?php $total+= $venta->subsidio()->total(); $total_uf += $venta->subsidio()->total('ufs') ?>
<tr>
	<td>Subsidio <a href="{{url('', ['p' => 'subsidios', 'a' => 'edit', 'venta' => $venta->id])}}"><span class="small glyphicon glyphicon-edit"></span></a></td>
	<td class="text-right">{{format('ufs', $venta->subsidio()->total('ufs'))}} UF </td>
	<td class="text-right">$ {{format('pesos', $venta->subsidio()->total())}}</td>
	<td>{{format('shortDate', $venta->subsidio()->pago()->fecha)}}
		@if ($venta->subsidio()->pago()->estado()->estado < 2)
		<a href="{{url('', ['p' => 'subsidios', 'a' => 'abonar', 'venta' => $venta->id])}}">&check;</a>
		@endif
	</td>
</tr>
@endif
@if ($venta->credito != 0)
<tr>
	<td>Cr&eacute;dito @if ($venta->credito != 0)  <a href="{{url('', ['p' => 'creditos', 'a' => 'edit', 'venta' => $venta->id])}}"><span class="small glyphicon glyphicon-edit"></span></a>@endif </td>
<?php $total += $venta->credito()->pago()->valor; $total_uf += $venta->credito()->pago()->valor('ufs') ?>
	<td class="text-right">{{format('ufs', $venta->credito()->pago()->valor('ufs'))}} UF</td>
	<td class="text-right">$ {{format('pesos', $venta->credito()->pago()->valor)}}</td>
	<td>{{format('shortDate', $venta->credito()->pago()->estado()->fecha)}}
		@if ($venta->credito()->pago()->estado()->estado < 1)
			<a href="{{url('', ['p' => 'creditos', 'a' => 'pagar', 'venta' => $venta->id])}}">&check;</a>
		@elseif ($venta->credito()->pago()->estado()->estado < 2)
			<a href="{{url('', ['p' => 'creditos', 'a' => 'abonar', 'venta' => $venta->id])}}">&check;</a>
		@endif
	</td>
	<td>Banco: @if ($venta->credito()->pago()->banco != 0) {{$venta->credito()->pago()->banco()->nombre}} @endif</td>
@elseif ($venta->escriturado == null)
<tr>
	<td>Cr&eacute;dito @if ($venta->credito != 0)  <a href="{{url('', ['p' => 'creditos', 'a' => 'edit', 'venta' => $venta->id])}}"><span class="small glyphicon glyphicon-edit"></span></a>@endif </td>
	<td class="danger text-right">{{format('ufs', $venta->valor_uf - $total_uf)}} UF</td>
	<td><a href="{{url('', ['p' => 'creditos', 'a' => 'agregar', 'venta' => $venta->id])}}"><span class="glyphicon glyphicon-plus"></span></a></td>
	<td colspan="2"></td>
</tr>
@endif
<tr class="
@if (abs($total_uf - $venta->valor_uf) / $venta->valor_uf < 0.01)
	success
@elseif (abs($total_uf - $venta->valor_uf) / $venta->valor_uf < 0.02)
	warning
@else
	danger
@endif">
	<td>Total</td>
	<td class="text-right">{{format('ufs', $total_uf)}} UF</td>
	<td class="text-right">$ {{format('pesos', $total)}}</td>
	<td class="text-right">{{format('ufs', $total_uf - $venta->valor_uf)}} UF</td>
	<td></td>
</tr>
</tbody>
</table>
<?php */ ?>