2016-09-22 22:38:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\ViewComposers;
|
|
|
|
|
2016-09-23 11:02:48 +02:00
|
|
|
use DB;
|
2017-04-16 15:47:20 +02:00
|
|
|
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;
|
2017-04-16 15:47:20 +02:00
|
|
|
$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();
|
|
|
|
|
2017-04-16 15:47:20 +02:00
|
|
|
$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();
|
|
|
|
}
|
|
|
|
|
2016-12-05 09:11:33 +01:00
|
|
|
$view->with('hasQuotes', $client->publicQuotes->count());
|
2016-09-23 11:02:48 +02:00
|
|
|
$view->with('hasCredits', $client->creditsWithBalance->count());
|
|
|
|
$view->with('hasDocuments', $hasDocuments);
|
2017-04-16 15:47:20 +02:00
|
|
|
$view->with('hasPaymentMethods', $hasPaymentMethods);
|
2016-09-22 22:38:07 +02:00
|
|
|
}
|
|
|
|
}
|