1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00
invoiceninja/app/Http/ViewComposers/ClientPortalHeaderComposer.php

63 lines
1.9 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;
use App\Models\Contact;
2016-09-22 22:38:07 +02:00
use Illuminate\View\View;
/**
* ClientPortalHeaderComposer.php.
*
* @copyright See LICENSE file that was distributed with this source code.
*/
class ClientPortalHeaderComposer
{
/**
* Bind data to the view.
*
2017-01-30 20:40:43 +01:00
* @param View $view
2016-09-22 22:38:07 +02:00
*
* @return void
*/
public function compose(View $view)
{
2016-09-23 11:02:48 +02:00
$contactKey = session('contact_key');
2017-01-30 17:05:31 +01:00
if (! $contactKey) {
2016-09-23 11:02:48 +02:00
return false;
}
$contact = Contact::where('contact_key', '=', $contactKey)
->with('client')
->first();
2017-01-30 17:05:31 +01:00
if (! $contact || $contact->is_deleted) {
2016-09-23 11:02:48 +02:00
return false;
}
$client = $contact->client;
$account = $contact->account;
2016-09-23 11:02:48 +02:00
$hasDocuments = DB::table('invoices')
->where('invoices.client_id', '=', $client->id)
->whereNull('invoices.deleted_at')
->join('documents', 'documents.invoice_id', '=', 'invoices.id')
->count();
$hasPaymentMethods = false;
if ($account->getTokenGatewayId() && ! $account->enable_client_portal_dashboard) {
$hasPaymentMethods = DB::table('payment_methods')
->where('contacts.client_id', '=', $client->id)
->whereNull('payment_methods.deleted_at')
->join('contacts', 'contacts.id', '=', 'payment_methods.contact_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);
$view->with('hasPaymentMethods', $hasPaymentMethods);
2016-09-22 22:38:07 +02:00
}
}