@extends('layout.base')

@section('content')
  <div class="row page-heading">
    <div class="col-md-6 h3">
      Pagar&eacute; {{$pagare->id}}
      <a href="{{nUrl('proyectos', 'construccion', ['proyecto' => $pagare->proyecto()->id])}}">
        <span class="glyphicon small glyphicon-chevron-up"></span>
      </a>
    </div>
    <div class="col-md-6 h3 text-right">
      <a href="{{nUrl('pagares', 'edit', ['pagare' => $pagare->id])}}">
        <span class="glyphicon glyphicon-edit"></span>
      </a>
    </div>
  </div>
  <table class="table table-striped">
    <thead></thead>
    <tbody>
      <tr>
        <td>Estado Pago</td>
        <td>
          {{$pagare->estado_pago}}
        </td>
      </tr>
      <tr>
        <td>Moneda</td>
        <td>{{$pagare->moneda()->descripcion}}</td>
      </tr>
      <tr>
        <td>Capital</td>
        <td>{{format('ufs', $pagare->valor(), null, true)}}</td>
        <td>{{format('pesos', $pagare->valor('pesos'), null, true)}}</td>
        <td>{{format('shortDate', $pagare->fecha_banco)}}</td>
      </tr>
      <tr>
        <td>Abonado</td>
        <td>{{format('ufs', $pagare->abonado(), null, true)}}</td>
        <td>{{format('pesos', $pagare->abonado('pesos'), null, true)}}</td>
        <td>
          @if ($pagare->fecha != '0000-00-00')
            {{format('shortDate', $pagare->fecha)}}
          @endif
        </td>
      </tr>
      <tr>
        <td>Tasa Anualizada</td>
        <td colspan="3">{{format('percent', $pagare->tasa, null, true)}}</td>
      </tr>
      <tr>
        <td>Duraci&oacute;n</td>
        <td>{{$pagare->duracion}}</td>
        <td colspan="2">{{format('shortDate', $pagare->vencimiento()->format('Y-m-d'))}}</td>
      </tr>
    </tbody>
  </table>
  @if ($pagare->renovaciones())
    <table class="table table-striped">
      <thead>
        <tr>
          <th colspan="3">Renovaciones</th>
        </tr>
        <tr>
          <th>Fecha Renovaci&oacute;n</th>
          <th>Intereses Pagados</th>
          <th>
            <a href="{{nUrl('pagares', 'add_renovacion', ['pagare' => $pagare->id])}}">
              <span class="glyphicon glyphicon-plus"></span>
            </a>
          </th>
        </tr>
      </thead>
      <tbody>
        <?php $total = 0 ?>
        @foreach ($pagare->renovaciones() as $renovacion)
          <?php $total += $renovacion->intereses() ?>
          <tr>
            <td>
              {{format('shortDate', $renovacion->fecha)}}
              ({{$renovacion->duracion}})
              {{format('shortDate', $renovacion->vencimiento()->format('Y-m-d'))}}
            </td>
            <td>{{format('ufs', $renovacion->intereses(), null, true)}}</td>
            <td>
              <a href="{{nUrl('pagares', 'edit_renovacion', ['renovacion' => $renovacion->id])}}">
                <span class="glyphicon glyphicon-edit"></span>
              </a>
            </td>
          </tr>
        @endforeach
        <tr>
          <td><b>Total</b></td>
          <td colspan="2"><b>{{format('ufs', $total, null, true)}}</b></td>
        </tr>
      </tbody>
    </table>
  @else
    <a href="{{nUrl('pagares', 'add_renovacion', ['pagare' => $pagare->id])}}">Agregar Renovaci&oacute;n</a>
  @endif
@endsection
