<table class="table">
<thead>
<tr class="section-heading">
	<th colspan="5">FORMA DE PAGO</th>
</tr>
</thead>
<tbody>
@if ($venta->pie != 0)
<tr>
	<td>Pie <a href="{{url('', ['p' => 'pies', 'a' => 'edit', 'venta' => $venta->id])}}">
		@include('layout.icons.edit', ['small' => true])
	</a></td>
	<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}}
			@if (count($venta->pie()->rebotadas()) > 0)
				[-{{count($venta->pie()->rebotadas())}}]
			@endif
		</a>
		@if (count($venta->pie()->cuotas()) < $venta->pie()->cuotas)
		<a href="{{url('', ['p' => 'cuotas', 'a' => 'add', 'pie' => $venta->pie()->id])}}">
			@include('layout.icons.add', ['small' => true])
		</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->pieReajustado())}} 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 @include('layout.icons.add')
		</a>
	</td>
	<td style="border-top: 1px dashed #ddd;"></td>
		@else
	<td style="border-top: 1px dashed #ddd;" colspan="2"></td>
		@endif
	@else
	<td style="border-top: 1px dashed #ddd;" colspan="2"></td>
</tr>
<tr>
	<td>Reajuste <a href="{{url('', ['p' => 'reajustes', 'a' => 'edit', 'venta' => $venta->id])}}">
		@include('layout.icons.edit', ['small' => true])
	</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 < 1)
		<a href="{{url('', ['p' => 'reajustes', 'a' => 'pagar', 'venta' => $venta->id])}}">
			@include('layout.icons.pagar')
		</a>
		@elseif ($venta->pie()->reajuste()->estado()->estado < 2)
		<a href="{{url('', ['p' => 'reajustes', 'a' => 'abonar', 'venta' => $venta->id])}}">
			@include('layout.icons.abonar')
		</a>
		@else
		<a href="{{url('', ['p' => 'pagos', 'a' => 'edit', 'pago' => $venta->pie()->reajuste()->id, 'asociado' => 'venta', 'venta' => $venta->id])}}">
			@include('layout.icons.edit')
		</a>
		@endif
	</td>
	@endif
</tr>
@endif
@if ($venta->escritura != 0)
<tr>
	<td>Escritura <a href="{{url('', ['p' => 'escrituras', 'a' => 'edit', 'venta' => $venta->id])}}">
		@include('layout.icons.edit', ['small' => true])
	</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])}}">
			@include('layout.icons.abonar')
		</a>
		@elseif ($venta->escritura()->pago()->estado()->estado == 0)
		<a href="{{url('', ['p' => 'escrituras', 'a' => 'pagar', 'venta' => $venta->id])}}">
			@include('layout.icons.pagar')
		</a>
		@endif
	</td>
	<td></td>
</tr>
@endif
<tr>
	<td><b>Anticipo</b></td>
	<td class="text-right"><b>{{format('ufs', $venta->anticipo())}} UF</b></td>
	<td class="text-right"><b>$ {{format('pesos', $venta->anticipo('pesos'))}}</b></td>
	<td colspan="2"></td>
</tr>
@if ($venta->bono_pie != 0)
<tr>
	<td>Bono Pie <a href="{{url('', ['p' => 'bonos', 'a' => 'edit', 'venta' => $venta->id])}}">
		@include('layout.icons.edit', ['small' => true])
	</a></td>
	<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>
@else
<tr>
	<td colspan="5">Bono Pie <a href="{{url('', ['p' => 'bonos', 'a' => 'add', 'venta' => $venta->id])}}">
		@include('layout.icons.add', ['small' => true])
	</a></td>
</tr>
@endif
@if ($venta->subsidio != 0)
<tr>
	<td rowspan="2">Subsidio <a href="{{url('', ['p' => 'subsidios', 'a' => 'edit', 'venta' => $venta->id])}}">
		@include('layout.icons.edit', ['small' => true])
	</a></td>
	<td class="text-right">{{format('ufs', $venta->subsidio()->subsidio()->valor('ufs'))}} UF </td>
	<td class="text-right">$ {{format('pesos', $venta->subsidio()->subsidio()->valor())}}</td>
	<td>{{format('shortDate', $venta->subsidio()->subsidio()->estado()->fecha)}}
		@if ($venta->subsidio()->subsidio()->estado()->estado < 1)
			<a href="{{url('', ['p' => 'subsidios', 'a' => 'pagar', 'venta' => $venta->id, 'tipo' => 'subsidio'])}}">
				@include('layout.icons.pagar')
			</a>
		@elseif($venta->subsidio()->subsidio()->estado()->estado < 2)
			<a href="{{url('', ['p' => 'subsidios', 'a' => 'abonar', 'venta' => $venta->id, 'tipo' => 'subsidio'])}}">
				@include('layout.icons.abonar')
			</a>
		@endif
	</td>
	<td>
			Subsidio
			<a href="{{nUrl('pagos', 'show', ['pago' => $venta->subsidio()->subsidio, 'asociado' => 'venta', 'venta' => $venta->id])}}">
				<span class="glyphicon small glyphicon-eye-open"></span>
			</a>
	</td>
</tr>
<tr>
	<td class="text-right">{{format('ufs', $venta->subsidio()->pago()->valor('ufs'))}} UF </td>
	<td class="text-right">$ {{format('pesos', $venta->subsidio()->pago()->valor())}}</td>
	<td>{{format('shortDate', $venta->subsidio()->pago()->estado()->fecha)}}
		@if ($venta->subsidio()->pago()->estado()->estado < 1)
			<a href="{{url('', ['p' => 'subsidios', 'a' => 'pagar', 'venta' => $venta->id, 'tipo' => 'pago'])}}">
				@include('layout.icons.pagar')
			</a>
		@elseif ($venta->subsidio()->pago()->estado()->estado < 2)
			<a href="{{url('', ['p' => 'subsidios', 'a' => 'abonar', 'venta' => $venta->id, 'tipo' => 'pago'])}}">
				@include('layout.icons.abonar')
			</a>
		@endif
	</td>
	<td>
		Libreta de Ahorro
		<a href="{{nUrl('pagos', 'show', ['pago' => $venta->subsidio()->pago, 'asociado' => 'venta', 'venta' => $venta->id])}}">
			<span class="glyphicon small glyphicon-eye-open"></span>
		</a>
	</td>
</tr>
@else
<tr>
	<td colspan="5">Subsidio <a href="{{url('', ['p' => 'subsidios', 'a' => 'add', 'venta' => $venta->id])}}">
		@include('layout.icons.add', ['small' => true])
	</a></td>
</tr>
@endif
@if ($venta->credito != 0)
<tr>
	<td>
		Cr&eacute;dito
		<a href="{{nUrl('creditos', 'show', ['venta' => $venta->id])}}">
			@include('layout.icons.show', ['icon' => 'eye-open', 'small' => true])
		</a>
		<a href="{{url('', ['p' => 'creditos', 'a' => 'remove', 'venta' => $venta->id])}}">
			@include('layout.icons.remove', ['small' => true])
		</a>
	</td>
	<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])}}">
				@include('layout.icons.pagar')
			</a>
		@elseif ($venta->credito()->pago()->estado()->estado < 2)
			<a href="{{url('', ['p' => 'creditos', 'a' => 'abonar', 'venta' => $venta->id])}}">
				@include('layout.icons.abonar')
			</a>
		@endif
	</td>
	<td>Banco: @if ($venta->credito()->pago()->banco != 0) {{$venta->credito()->pago()->banco()->nombre}} @endif</td>
@elseif ($venta->escriturado == null and $venta->estado == 1)
<tr>
	<td>Cr&eacute;dito</td>
	<td class="danger text-right">{{format('ufs', $venta->valor_uf - $venta->pagado())}} UF</td>
	<td><a href="{{url('', ['p' => 'creditos', 'a' => 'agregar', 'venta' => $venta->id])}}">
		@include('layout.icons.add')
	</a></td>
	<td colspan="2"></td>
</tr>
@endif
@if ($venta->saldo() / $venta->valor_uf > 0.01 or $venta->devolucion)
<tr
@if (!$venta->devolucion)
class="warning"
@endif
>
	<td>Devoluci&oacute;n
		@if (!$venta->devolucion)
			<a href="{{url('', ['p' => 'devoluciones', 'a' => 'liquidacion', 'venta' => $venta->id])}}"><span class="glyphicon glyphicon-print" title="Imprimir"></span></a>
		@else
			<a href="{{nUrl('pagos', 'edit', ['pago' => $venta->devolucion, 'asociado' => 'venta', 'venta' => $venta->id])}}">
				@include('layout.icons.edit')
			</a>
		@endif
	</td>
	@if (!$venta->devolucion)
	<td class="text-right">-{{format('ufs', $venta->saldo('ufs'))}} UF</td>
	<td class="text-right">-$ {{format('pesos', $venta->saldo('pesos'))}}</td>
	<td><a href="{{url('', ['p' => 'ventas', 'a' => 'devolucion', 'venta' => $venta->id])}}">
		@include('layout.icons.add')
	</a></td>
	<td></td>
	@else
	<td class="text-right">-{{format('ufs', $venta->devolucion()->valor('ufs'))}} UF</td>
	<td class="text-right">-$ {{format('pesos', $venta->devolucion()->valor('pesos'))}}</td>
	<td>{{format('shortDate', $venta->devolucion()->estado()->fecha)}}
	@if ($venta->devolucion()->estado()->estado < 1)
		<a href="{{url('', ['p' => 'pagos', 'a' => 'pagar', 'pago' => $venta->devolucion, 'asociado' => 'venta', 'venta' => $venta->id])}}">
			@include('layout.icons.pagar')
		</a>
	@elseif ($venta->devolucion()->estado()->estado < 2)
		<a href="{{url('', ['p' => 'pagos', 'a' => 'abonar', 'pago' => $venta->devolucion, 'asociado' => 'venta', 'venta' => $venta->id])}}">
			@include('layout.icons.abonar')
		</a>
	@endif
	</td>
	@endif
</tr>
@endif
@if ($venta->estado == 0)
<tr>
	<td>Resciliaci&oacute;n</td>
	<td class="text-right">-{{format('ufs', (($venta->resciliacion) ? $venta->resciliacion()->valor('ufs') : $venta->anticipo('ufs')), null, true)}}</td>
	<td class="text-right">-{{format('pesos', (($venta->resciliacion) ? $venta->resciliacion()->valor('pesos') : $venta->anticipo('pesos')), null, true)}}</td>
	@if ($venta->resciliacion)
	<td>
	@if ($venta->resciliacion()->estado()->estado < 1)
		<a href="{{url('', ['p' => 'pagos', 'a' => 'pagar', 'pago' => $venta->resciliacion, 'asociado' => 'venta', 'venta' => $venta->id])}}">
			@include('layout.icons.pagar')
		</a>
	@elseif ($venta->resciliacion()->estado()->estado < 2)
		<a href="{{url('', ['p' => 'pagos', 'a' => 'abonar', 'pago' => $venta->resciliacion, 'asociado' => 'venta', 'venta' => $venta->id])}}">
			@include('layout.icons.abonar')
		</a>
	@endif
	</td>
	@else
	<td colspan="2"></td>
	@endif
</tr>
@endif
<tr class="
@if (abs($venta->saldo()) / $venta->valor_uf < 0.01)
	success
@elseif (abs($venta->saldo()) / $venta->valor_uf < 0.02)
	warning
@else
	danger
@endif">
	<td>Total</td>
	<td class="text-right">{{format('ufs', $venta->pagado())}} UF</td>
	<td class="text-right">$ {{format('pesos', $venta->pagado('pesos'))}}</td>
	<td class="text-right">{{format('ufs', $venta->saldo())}} UF</td>
	<td></td>
</tr>
</tbody>
</table>
