70 lines
1.9 KiB
PHP
Raw Normal View History

2017-09-14 22:21:00 +03:00
<?php
namespace App\Http\ViewComposers;
use App\Utilities\Updater;
use Illuminate\View\View;
2018-06-25 17:59:27 +03:00
use App\Traits\Modules as RemoteModules;
2017-09-14 22:21:00 +03:00
class Header
{
2018-06-25 17:59:27 +03:00
use RemoteModules;
2018-05-25 16:57:58 +03:00
2017-09-14 22:21:00 +03:00
/**
* Bind data to the view.
*
* @param View $view
* @return void
*/
public function compose(View $view)
{
2019-11-16 10:21:14 +03:00
$user = user();
2017-09-14 22:21:00 +03:00
2019-12-26 10:53:50 +03:00
$invoices = $bills = [];
$updates = $notifications = 0;
2017-09-14 22:21:00 +03:00
$company = null;
2019-12-26 10:53:50 +03:00
if (!empty($user)) {
// Get customer company
if ($user->can('read-client-portal')) {
$company = (object) [
'company_name' => setting('company.name'),
'company_email' => setting('company.email'),
'company_address' => setting('company.address'),
'company_logo' => setting('company.logo'),
];
}
2017-09-14 22:21:00 +03:00
2019-12-26 10:53:50 +03:00
$undereads = $user->unreadNotifications;
2017-09-14 22:21:00 +03:00
2019-12-26 10:53:50 +03:00
foreach ($undereads as $underead) {
$data = $underead->getAttribute('data');
2017-09-14 22:21:00 +03:00
2019-12-26 10:53:50 +03:00
switch ($underead->getAttribute('type')) {
2019-12-31 15:49:09 +03:00
case 'App\Notifications\Purchase\Bill':
2019-12-26 10:53:50 +03:00
$bills[$data['bill_id']] = $data['amount'];
$notifications++;
break;
2019-12-31 15:49:09 +03:00
case 'App\Notifications\Sale\Invoice':
2019-12-26 10:53:50 +03:00
$invoices[$data['invoice_id']] = $data['amount'];
$notifications++;
break;
}
2017-09-14 22:21:00 +03:00
}
2019-12-26 10:53:50 +03:00
$updates = count(Updater::all());
2017-09-14 22:21:00 +03:00
2019-12-26 10:53:50 +03:00
$this->loadSuggestions();
}
2018-05-25 16:57:58 +03:00
2017-09-14 22:21:00 +03:00
$view->with([
'user' => $user,
'notifications' => $notifications,
'bills' => $bills,
'invoices' => $invoices,
'company' => $company,
'updates' => $updates,
]);
}
}