
  @if (Auth::user()->role_id >= 5)
    <div class="container-fluid" style="height:100%">
    <div>
  @else
    <div class="container" style="margin:0 1em">
  @endif

    <div class="row">
        <div class="col-sm-7">
          <h3>Contratos Finalizados</h3>
        </div>
        <div class="col-sm-5">
          <a class="btn btn-secondary btn-xs" title="Ver en Mapa"
            href="{{url('finishedcontracts/map')}}">
            <i class="fa fa-map"></i>  Ver en Mapa
          </a>
          <div class="pull-right">
            {!! Form::open(['method'=>'GET','url'=>'finishedcontracts','class'=>'navbar-form navbar-left','role'=>'search'])  !!}
            <div class="input-group">
                <input class="form-control" id="search"
                       value="{{ request()->session()->get('search') }}"
                       placeholder="Buscar" name="search"
                       type="text" id="search"/>
                <div class="input-group-btn">
                    <button type="submit" class="btn btn-primary">
                            <i class="fa fa-search" aria-hidden="true"></i>
                    </button>
                </div>
            </div>
            {!! Form::close() !!}
          </div>
        </div>
    </div>
    <table class="table">
        <thead>
        <tr>

            <th style="vertical-align: middle"><a href="{{url('finishedcontracts?field=id&sort='.(request()->session()->get('sort')=='asc'?'desc':'asc'))}}">ID</a></th>
                {{request()->session()->get('field')=='id'?(request()->session()->get('sort')=='asc'?'':''):''}}

            <th style="vertical-align: middle"><a href="{{url('finishedcontracts?field=user_id&sort='.(request()->session()->get('sort')=='asc'?'desc':'asc'))}}">Usuario</a></th>
                {{request()->session()->get('field')=='user_id'?(request()->session()->get('sort')=='asc'?'':''):''}}

            <th style="vertical-align: middle"><a href="{{url('finishedcontracts?field=supplier_id&sort='.(request()->session()->get('sort')=='asc'?'desc':'asc'))}}">Proveedor</a></th>
                {{request()->session()->get('field')=='supplier_id'?(request()->session()->get('sort')=='asc'?'':''):''}}

            <th style="vertical-align: middle"><a href="{{url('finishedcontracts?field=category_id&sort='.(request()->session()->get('sort')=='asc'?'desc':'asc'))}}">Categoría</a></th>
                {{request()->session()->get('field')=='category_id'?(request()->session()->get('sort')=='asc'?'':''):''}}

            <th style="vertical-align: middle"><a href="{{url('finishedcontracts?field=address&sort='.(request()->session()->get('sort')=='asc'?'desc':'asc'))}}">Dirección</a></th>
                {{request()->session()->get('field')=='address'?(request()->session()->get('sort')=='asc'?'':''):''}}

            <th style="vertical-align: middle"><a href="{{url('finishedcontracts?field=references&sort='.(request()->session()->get('sort')=='asc'?'desc':'asc'))}}">Referencias</a></th>
                {{request()->session()->get('field')=='references'?(request()->session()->get('sort')=='asc'?'':''):''}}

            <th style="vertical-align: middle"><a href="{{url('finishedcontracts?field=appointment&sort='.(request()->session()->get('sort')=='asc'?'desc':'asc'))}}">Cita</a></th>
                {{request()->session()->get('field')=='appointment'?(request()->session()->get('sort')=='asc'?'':''):''}}

            <th style="vertical-align: middle"><a href="{{url('finishedcontracts?field=amount&sort='.(request()->session()->get('sort')=='asc'?'desc':'asc'))}}">Monto</a></th>
                {{request()->session()->get('amount')=='RFC'?(request()->session()->get('sort')=='asc'?'':''):''}}

            <th style="vertical-align: middle"><a href="{{url('finishedcontracts?field=details&sort='.(request()->session()->get('sort')=='asc'?'desc':'asc'))}}">Detalles</a></th>
                {{request()->session()->get('field')=='details'?(request()->session()->get('sort')=='asc'?'':''):''}}

            <th style="vertical-align: middle"><a href="{{url('finishedcontracts?field=transaction_id&sort='.(request()->session()->get('sort')=='asc'?'desc':'asc'))}}">Status</a></th>
                {{request()->session()->get('field')=='status_id'?(request()->session()->get('sort')=='asc'?'':''):''}}

            <th style="vertical-align: middle"><a href="{{url('finishedcontracts?field=score&sort='.(request()->session()->get('sort')=='asc'?'desc':'asc'))}}">Calificación</a></th>
                {{request()->session()->get('field')=='score'?(request()->session()->get('sort')=='asc'?'':''):''}}

            <th style="vertical-align: middle"><a href="{{url('finishedcontracts?field=comments&sort='.(request()->session()->get('sort')=='asc'?'desc':'asc'))}}">Comentarios</a></th>
                {{request()->session()->get('field')=='comments'?(request()->session()->get('sort')=='asc'?'':''):''}}

            <th style="vertical-align: middle"><a href="{{url('finishedcontracts?field=transaction_id&sort='.(request()->session()->get('sort')=='asc'?'desc':'asc'))}}">Cupón</a></th>
                {{request()->session()->get('field')=='coupon_name'?(request()->session()->get('sort')=='asc'?'':''):''}}

            <th style="vertical-align: middle"><a href="{{url('finishedcontracts?field=transaction_id&sort='.(request()->session()->get('sort')=='asc'?'desc':'asc'))}}">Transacción ID</a></th>
                {{request()->session()->get('field')=='transaction_id'?(request()->session()->get('sort')=='asc'?'':''):''}}

            <th style="vertical-align: middle"><a href="{{url('finishedcontracts?field=created_at&sort='.(request()->session()->get('sort')=='asc'?'desc':'asc'))}}">Fecha de creación</a></th>
                {{request()->session()->get('field')=='created_at'?(request()->session()->get('sort')=='asc'?'':''):''}}

            <th style="vertical-align: middle"><a href="{{url('finishedcontracts?field=updated_at&sort='.(request()->session()->get('sort')=='asc'?'desc':'asc'))}}">Ultimo incio de sesión</a></th>
                {{request()->session()->get('field')=='updated_at'?(request()->session()->get('sort')=='asc'?'':''):''}}

        </tr>
        </thead>
        <tbody>
        @php
            $i=1;
        @endphp
        @foreach ($finishedcontracts as $finishedcontract)
          <tr>
            <th>{{ $finishedcontract->id }}</th>
            <td>{{ $finishedcontract->user->name ?? null }}</td>
            <td>{{ $finishedcontract->suppliers->company_name ?? null }}</td>
            <td>{{ $finishedcontract->categories->name ?? null }}</td>
            <td>{{ $finishedcontract->address }}</td>
            <td>{{ $finishedcontract->references }}</td>
            <td>{{ $finishedcontract->appointment }}</td>
            <td>${{ $finishedcontract->amount }}</td>
            <td>{{ $finishedcontract->details }}</td>
            <td>{{ $finishedcontract->status->name }}</td>
            <td>{{ $finishedcontract->score }}</td>
            <td>{{ $finishedcontract->comments }}</td>
            <td>{{ (isset($finishedcontract->coupon->name) ? $finishedcontract->coupon->name : null) }}</td>
            <td>{{ $finishedcontract->transaction_id }}</td>
            <td>{{ $finishedcontract->created_at }}</td>
            <td>{{ $finishedcontract->updated_at }}</td>
            <td>
              <input type="hidden" name="_method" value="delete"/>
                <a class="btn btn-danger btn-xs" title="Delete"
                   href="javascript:if(confirm('¿Estás seguro de que quieres eliminar esta contrato?')) javascript:if(confirm('Usualmente no se deben eliminar contratos, ¿Estás seguro?')) ajaxDelete('{{url('finishedcontracts/delete/'.$finishedcontract->id)}}','{{csrf_token()}}')">
                   <i class="fa fa-trash"></i>
                </a>
            </td>
        </tr>
        @endforeach

        </tbody>
    </table>

        {{ $finishedcontracts->links() }}
</div>
