2019-07-19 06:32:51 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2019-07-19 06:32:51 +02:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2024-04-12 06:15:41 +02:00
|
|
|
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-07-19 06:32:51 +02:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2019-07-19 06:32:51 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Http\ViewComposers;
|
|
|
|
|
2020-11-10 04:36:16 +01:00
|
|
|
use App\Utils\Ninja;
|
2019-08-12 00:33:17 +02:00
|
|
|
use App\Utils\TranslationHelper;
|
2021-06-01 00:09:38 +02:00
|
|
|
use Illuminate\Support\Facades\App;
|
2019-07-19 06:32:51 +02:00
|
|
|
use Illuminate\View\View;
|
|
|
|
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Class PortalComposer.
|
2019-07-19 06:32:51 +02:00
|
|
|
*/
|
|
|
|
class PortalComposer
|
|
|
|
{
|
2021-06-17 14:06:44 +02:00
|
|
|
public const MODULE_RECURRING_INVOICES = 1;
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2021-06-17 14:06:44 +02:00
|
|
|
public const MODULE_CREDITS = 2;
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2021-06-17 14:06:44 +02:00
|
|
|
public const MODULE_QUOTES = 4;
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2021-06-17 14:06:44 +02:00
|
|
|
public const MODULE_TASKS = 8;
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2021-06-17 14:06:44 +02:00
|
|
|
public const MODULE_EXPENSES = 16;
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2021-06-17 14:06:44 +02:00
|
|
|
public const MODULE_PROJECTS = 32;
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2021-06-17 14:06:44 +02:00
|
|
|
public const MODULE_VENDORS = 64;
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2021-06-17 14:06:44 +02:00
|
|
|
public const MODULE_TICKETS = 128;
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2021-06-17 14:06:44 +02:00
|
|
|
public const MODULE_PROPOSALS = 256;
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2021-06-17 14:06:44 +02:00
|
|
|
public const MODULE_RECURRING_EXPENSES = 512;
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2021-06-17 14:06:44 +02:00
|
|
|
public const MODULE_RECURRING_TASKS = 1024;
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2021-06-17 14:06:44 +02:00
|
|
|
public const MODULE_RECURRING_QUOTES = 2048;
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2021-06-17 14:06:44 +02:00
|
|
|
public const MODULE_INVOICES = 4096;
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2021-06-17 14:06:44 +02:00
|
|
|
public const MODULE_PROFORMAL_INVOICES = 8192;
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2021-06-17 14:06:44 +02:00
|
|
|
public const MODULE_PURCHASE_ORDERS = 16384;
|
|
|
|
|
2021-01-13 08:43:26 +01:00
|
|
|
public $settings;
|
|
|
|
|
2019-07-19 06:32:51 +02:00
|
|
|
/**
|
|
|
|
* Bind data to the view.
|
|
|
|
*
|
|
|
|
* @param View $view
|
|
|
|
* @return void
|
|
|
|
*/
|
2024-01-14 05:05:00 +01:00
|
|
|
public function compose(View $view): void
|
2019-07-19 06:32:51 +02:00
|
|
|
{
|
2019-12-30 22:59:12 +01:00
|
|
|
$view->with($this->portalData());
|
2020-11-10 04:36:16 +01:00
|
|
|
|
2022-02-16 03:24:10 +01:00
|
|
|
if (auth()->guard('contact')->user()) {
|
2021-05-31 12:40:34 +02:00
|
|
|
App::forgetInstance('translator');
|
|
|
|
$t = app('translator');
|
2022-02-16 03:24:10 +01:00
|
|
|
$t->replace(Ninja::transformTranslations(auth()->guard('contact')->user()->client->getMergedSettings()));
|
2020-11-25 15:19:52 +01:00
|
|
|
}
|
2019-07-19 06:32:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
2024-01-14 05:05:00 +01:00
|
|
|
private function portalData(): array
|
2019-07-19 06:32:51 +02:00
|
|
|
{
|
2022-02-16 03:24:10 +01:00
|
|
|
if (! auth()->guard('contact')->user()) {
|
2019-07-19 06:32:51 +02:00
|
|
|
return [];
|
2019-12-30 22:59:12 +01:00
|
|
|
}
|
2019-07-19 06:32:51 +02:00
|
|
|
|
2024-06-15 08:18:33 +02:00
|
|
|
auth()->guard('contact')->user()->loadMissing(['client' => function ($query) {
|
|
|
|
$query->without('gateway_tokens', 'documents'); // Exclude 'grandchildren' relation of 'client'
|
|
|
|
}]);
|
|
|
|
|
2022-02-16 03:24:10 +01:00
|
|
|
$this->settings = auth()->guard('contact')->user()->client->getMergedSettings();
|
2021-01-13 08:43:26 +01:00
|
|
|
|
2019-07-22 05:54:34 +02:00
|
|
|
$data['sidebar'] = $this->sidebarMenu();
|
|
|
|
$data['header'] = [];
|
|
|
|
$data['footer'] = [];
|
2024-08-05 03:57:42 +02:00
|
|
|
$data['countries'] = app('countries');
|
2022-02-16 03:24:10 +01:00
|
|
|
$data['company'] = auth()->guard('contact')->user()->company;
|
|
|
|
$data['client'] = auth()->guard('contact')->user()->client;
|
2021-01-13 08:43:26 +01:00
|
|
|
$data['settings'] = $this->settings;
|
2024-08-05 03:57:42 +02:00
|
|
|
$data['currencies'] = app('currencies');
|
2022-02-16 03:24:10 +01:00
|
|
|
$data['contact'] = auth()->guard('contact')->user();
|
2020-05-27 06:46:19 +02:00
|
|
|
|
2021-09-01 09:01:39 +02:00
|
|
|
$data['multiple_contacts'] = session()->get('multiple_contacts') ?: collect();
|
2019-11-04 01:22:59 +01:00
|
|
|
|
2019-07-19 06:32:51 +02:00
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2024-01-14 05:05:00 +01:00
|
|
|
private function sidebarMenu(): array
|
2019-07-22 05:54:34 +02:00
|
|
|
{
|
2022-02-16 03:24:10 +01:00
|
|
|
$enabled_modules = auth()->guard('contact')->user()->company->enabled_modules;
|
2019-07-22 05:54:34 +02:00
|
|
|
$data = [];
|
|
|
|
|
2024-03-26 17:11:29 +01:00
|
|
|
if ($this->settings->enable_client_portal_dashboard) {
|
|
|
|
$data[] = [ 'title' => ctrans('texts.dashboard'), 'url' => 'client.dashboard', 'icon' => 'activity'];
|
|
|
|
}
|
2021-06-17 14:06:44 +02:00
|
|
|
|
|
|
|
if (self::MODULE_INVOICES & $enabled_modules) {
|
|
|
|
$data[] = ['title' => ctrans('texts.invoices'), 'url' => 'client.invoices.index', 'icon' => 'file-text'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (self::MODULE_RECURRING_INVOICES & $enabled_modules) {
|
|
|
|
$data[] = ['title' => ctrans('texts.recurring_invoices'), 'url' => 'client.recurring_invoices.index', 'icon' => 'file'];
|
|
|
|
}
|
2021-02-16 13:16:22 +01:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$data[] = ['title' => ctrans('texts.payments'), 'url' => 'client.payments.index', 'icon' => 'credit-card'];
|
2021-06-17 14:06:44 +02:00
|
|
|
|
|
|
|
if (self::MODULE_QUOTES & $enabled_modules) {
|
|
|
|
$data[] = ['title' => ctrans('texts.quotes'), 'url' => 'client.quotes.index', 'icon' => 'align-left'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (self::MODULE_CREDITS & $enabled_modules) {
|
|
|
|
$data[] = ['title' => ctrans('texts.credits'), 'url' => 'client.credits.index', 'icon' => 'credit-card'];
|
|
|
|
}
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$data[] = ['title' => ctrans('texts.payment_methods'), 'url' => 'client.payment_methods.index', 'icon' => 'shield'];
|
2020-09-28 12:04:34 +02:00
|
|
|
$data[] = ['title' => ctrans('texts.documents'), 'url' => 'client.documents.index', 'icon' => 'download'];
|
2019-07-22 05:54:34 +02:00
|
|
|
|
2022-02-16 03:24:10 +01:00
|
|
|
if (auth()->guard('contact')->user()->client->getSetting('enable_client_portal_tasks')) {
|
2021-05-12 16:39:29 +02:00
|
|
|
$data[] = ['title' => ctrans('texts.tasks'), 'url' => 'client.tasks.index', 'icon' => 'clock'];
|
2020-11-17 15:01:28 +01:00
|
|
|
}
|
|
|
|
|
2021-09-07 18:00:22 +02:00
|
|
|
$data[] = ['title' => ctrans('texts.statement'), 'url' => 'client.statement', 'icon' => 'activity'];
|
|
|
|
|
2024-08-05 10:52:34 +02:00
|
|
|
// if (Ninja::isHosted() && auth()->guard('contact')->user()->company->id == config('ninja.ninja_default_company_id')) {
|
2024-08-22 08:45:06 +02:00
|
|
|
$data[] = ['title' => ctrans('texts.plan'), 'url' => 'client.plan', 'icon' => 'credit-card'];
|
2024-08-05 10:52:34 +02:00
|
|
|
// } else {
|
2024-08-22 08:45:06 +02:00
|
|
|
$data[] = ['title' => ctrans('texts.subscriptions'), 'url' => 'client.subscriptions.index', 'icon' => 'calendar'];
|
2024-08-05 10:52:34 +02:00
|
|
|
// }
|
2021-11-23 22:57:24 +01:00
|
|
|
|
2023-03-21 23:20:54 +01:00
|
|
|
if (auth()->guard('contact')->user()->client->getSetting('client_initiated_payments')) {
|
2023-03-15 12:59:40 +01:00
|
|
|
$data[] = ['title' => ctrans('texts.pre_payment'), 'url' => 'client.pre_payments.index', 'icon' => 'dollar-sign'];
|
2023-03-21 23:20:54 +01:00
|
|
|
}
|
2024-01-14 05:05:00 +01:00
|
|
|
|
2019-07-22 05:54:34 +02:00
|
|
|
return $data;
|
|
|
|
}
|
2019-12-30 22:59:12 +01:00
|
|
|
}
|