1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 23:22:52 +01:00
invoiceninja/app/Http/ViewComposers/ClientPortalHeaderComposer.php

53 lines
1.3 KiB
PHP
Raw Normal View History

2016-09-22 22:38:07 +02:00
<?php
namespace App\Http\ViewComposers;
2016-09-23 11:02:48 +02:00
use DB;
2016-09-22 22:38:07 +02:00
use Cache;
use Illuminate\View\View;
2016-09-23 11:02:48 +02:00
use App\Models\Contact;
2016-09-22 22:38:07 +02:00
/**
* ClientPortalHeaderComposer.php.
*
* @copyright See LICENSE file that was distributed with this source code.
*/
class ClientPortalHeaderComposer
{
/**
* Bind data to the view.
*
* @param View $view
*
* @return void
*/
public function compose(View $view)
{
2016-09-23 11:02:48 +02:00
$contactKey = session('contact_key');
if ( ! $contactKey) {
return false;
}
$contact = Contact::where('contact_key', '=', $contactKey)
->with('client')
->first();
if ( ! $contact || $contact->is_deleted) {
return false;
}
$client = $contact->client;
$hasDocuments = DB::table('invoices')
->where('invoices.client_id', '=', $client->id)
->whereNull('invoices.deleted_at')
->join('documents', 'documents.invoice_id', '=', 'invoices.id')
->count();
$view->with('hasQuotes', $client->publicQuotes->count());
2016-09-23 11:02:48 +02:00
$view->with('hasCredits', $client->creditsWithBalance->count());
$view->with('hasDocuments', $hasDocuments);
2016-09-22 22:38:07 +02:00
}
}