@extends('layouts.app')

@section('content')
  @if (Auth::user()->role_id >= 5)
    <div class="container-fluid" style="height:100%">
    @include('sidebar')
    <div style="width:90%; float: left; margin:1em 0 0 1em">
  @else
    <div class="container" style="margin:0 1em">
  @endif

    <div class="row">
        <div class="col-sm-7">
          <h3>Pagos</h3>
        </div>
        <div class="col-sm-5">
          <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('payment?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('payment?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('payment?field=membership&sort='.(request()->session()->get('sort')=='asc'?'desc':'asc'))}}">Email</a></th>
                {{request()->session()->get('field')=='membership'?(request()->session()->get('sort')=='asc'?'':''):''}}

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

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

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

            <th style="vertical-align: middle"><a href="{{url('payment?field=bank_id&sort='.(request()->session()->get('sort')=='asc'?'desc':'asc'))}}">Código Banco</a></th>
                {{request()->session()->get('field')=='bank_id'?(request()->session()->get('sort')=='asc'?'':''):''}}

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

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

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

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

            <th style="vertical-align: middle"><a href="{{url('payment?field=ichamba_fee&sort='.(request()->session()->get('sort')=='asc'?'desc':'asc'))}}">Retención iChamba</a></th>
                    {{request()->session()->get('field')=='ichamba_fee'?(request()->session()->get('sort')=='asc'?'':''):''}}
        </tr>
        </thead>
        <tbody>
        @php
            $i=1;
        @endphp
        @foreach ($payments as $payment)
          <tr>
            <th>{{ $payment->id }}</th>
            <td>{{ $payment->suppliers->company_name }}</td>
            <td >{{ $payment->suppliers->user->email }}</td>
            <td >{{ (!$payment->suppliers->RFC) ? $payment->suppliers->CURP : $payment->suppliers->RFC }}</td>
            <td >{{ $payment->suppliers->clabe }}</td>
            <td >{{ (isset($payment->suppliers->banks->name) ? $payment->suppliers->banks->name : null) }}</td>
            <td >{{ (isset($payment->suppliers->banks->code) ? $payment->suppliers->banks->code : null) }}</td>
            <td >{{ $payment->amount }}</td>
            <td >{{ $payment->revenue }}</td>
            <td >{{ $payment->IVA }}</td>
            <td >{{ $payment->ISR }}</td>
            <td >{{ $payment->ichamba_fee }}</td>
        </tr>
        @endforeach

        </tbody>
    </table>

        <ul class="pagination">
            {{ $payments->links() }}
        </ul>
</div>
@endsection
