@extends('layouts.app', ['page' => 'Reference', 'pageSlug' => 'reference', 'section' => 'reference'])
@section('content')
{{-- <p>{{dd($ref->client)}}</p> --}}
<div class="row">
<div class="col-md-12">
<div class="card ">
<div class="card-header">
<div class="row">
<div class="col-7">
<h4 class="card-title">{{$ref->name}}</h4>
<p>{{$ref->phone}}</p>
<p>{{$ref->area}}</p>
<h2>All Clients of {{$ref->name}}</h2>
</div>
<div class="col-2">
<a class="btn btn-primary text-white" target="_blank" href="{{ route('reference.print.ledger',$ref->id) }}">Print Ledger</a>
</div>
<div class="col-2">
<a class="btn btn-primary text-white" target="_blank" href="{{ route('reference.print.report',$ref->id) }}">Print Outstanding Report</a>
</div>
</div>
</div>
<div class="card-body">
@include('alerts.success')
<div class="">
<table class="table tablesorter " id="">
<thead class=" text-primary">
<th>Name</th>
<th>Telephone</th>
<th>Balance</th>
<th>Purchases</th>
<th>Total Payment</th>
<th>Last purchase</th>
<th>Action</th>
</thead>
<tbody>
@foreach ($ref->client as $refs)
<tr>
<td>{{ $refs->name }}</td>
<td>
{{ $refs->phone }}
</td>
<td>
@if (round($refs->balance) > 0)
<span class="text-success">{{ $refs->balance }}</span>
@elseif (round($refs->balance) < 0.00)
<span class="text-danger">{{ $refs->balance }}</span>
@else
{{ $refs->balance }}
@endif
</td>
<td>{{ $refs->sales->count() }}</td>
<td>{{ $refs->transactions->sum('amount') }}</td>
<td>{{ (empty($refs->sales)) ? date('d-m-y', strtotime($refs->sales->reverse()->first()->created_at)) : 'N/A' }}</td>
<td class="td-actions text-right">
<a href="{{ route('clients.show', $refs) }}" class="btn btn-link" data-toggle="tooltip" data-placement="bottom" title="More Details">
<i class="tim-icons icon-zoom-split"></i>
</a>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
<div class="card-footer py-4">
<nav class="d-flex justify-content-end" aria-label="...">
{{-- {{ $ref->links() }} --}}
</nav>
</div>
</div>
</div>
</div>
@endsection