Skip to content

Commit

Permalink
Display estimates on client.show
Browse files Browse the repository at this point in the history
  • Loading branch information
lovett committed Dec 4, 2018
1 parent 3c8af0d commit f2e00e0
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
10 changes: 10 additions & 0 deletions app/Client.php
Expand Up @@ -174,4 +174,14 @@ public function time()
return $this->hasManyThrough('App\Time', 'App\Project');
}

/**
* Estimates associated with the client.
*
* @return HasMany
*/
public function estimates()
{
return $this->hasMany('App\Estimate');
}

}
1 change: 1 addition & 0 deletions app/Estimate.php
Expand Up @@ -134,6 +134,7 @@ public function client()
*/
public function scopeForList($query)
{
$query->select('estimates.*');
$query->leftJoin('clients', 'estimates.client_id', '=', 'clients.id');
$query->selectRaw('clients.name as clientName');
$query->selectRaw('clients.id as clientId');
Expand Down
3 changes: 3 additions & 0 deletions app/Http/Controllers/ClientController.php
Expand Up @@ -131,6 +131,8 @@ public function show(Request $request, $id)
{
$client = $request->user()->clients()->with('projects')->findOrFail($id);

$estimates = $client->estimates()->forList()->get();

$invoices = $client->invoices()->forList()->newest(5)->get();

$time = $client->time()->newest(10)->get();
Expand All @@ -139,6 +141,7 @@ public function show(Request $request, $id)
'model' => $client,
'pageTitle' => $client->name,
'invoices' => $invoices,
'estimates' => $estimates,
'time' => $time,
'stats' => $client->stats(),
];
Expand Down
10 changes: 10 additions & 0 deletions resources/views/client/show.blade.php
Expand Up @@ -69,6 +69,16 @@
</div>
@endif

<h2>Estimates</h2>

@include('partials.empty-message', ['collection' => $estimates])

@if ($estimates->isNotEmpty())
<div class="panel panel-default">
@include('estimate.table', ['collection' => $estimates])
</div>
@endif

</div>

@include('partials.timestamps-footer', ['record' => $model])
Expand Down
7 changes: 6 additions & 1 deletion resources/views/estimate/table.blade.php
Expand Up @@ -3,7 +3,10 @@
<tr>
<th>Name</th>
<th>Recipient</th>
<th>Client</th>

@unless(Route::is('client.show'))
<th>Client</th>
@endunless
<th>Fee</th>
<th>Hours</th>
<th>Status</th>
Expand All @@ -21,6 +24,7 @@
<td>
{{ $estimate->recipient }}
</td>
@unless(Route::is('client.show'))
<td>
@if ($estimate->clientId)
<a href="{{ route('client.show', ['record' => $estimate->clientId]) }}">
Expand All @@ -30,6 +34,7 @@
none
@endif
</td>
@endunless
<td>
{{ CurrencyHelper::money($estimate->fee) }}
</td>
Expand Down

0 comments on commit f2e00e0

Please sign in to comment.