196 lines
9.5 KiB
PHP
196 lines
9.5 KiB
PHP
<?php
|
|
|
|
namespace Modules\AssetExchange\Http\Controllers;
|
|
|
|
use App\Http\MenuIcons;
|
|
use App\Utils\ModuleUtil;
|
|
use Illuminate\Routing\Controller;
|
|
use Menu;
|
|
use Modules\AssetExchange\Models\Notification;
|
|
|
|
class DataController extends Controller
|
|
{
|
|
public function superadmin_package()
|
|
{
|
|
return [
|
|
[
|
|
'name' => 'assetexchange_module',
|
|
'label' => __('assetexchange::lang.module_name'),
|
|
'default' => false,
|
|
],
|
|
];
|
|
}
|
|
|
|
public function user_permissions()
|
|
{
|
|
return [
|
|
['value' => 'aex.access', 'label' => __('assetexchange::lang.access'), 'default' => false],
|
|
['value' => 'aex.view', 'label' => __('assetexchange::lang.view_dashboard'), 'default' => false],
|
|
['value' => 'aex.listings.view', 'label' => __('assetexchange::lang.listings_view'), 'default' => false],
|
|
['value' => 'aex.listings.create', 'label' => __('assetexchange::lang.listings_create'), 'default' => false],
|
|
['value' => 'aex.listings.update', 'label' => __('assetexchange::lang.listings_update'), 'default' => false],
|
|
['value' => 'aex.listings.delete', 'label' => __('assetexchange::lang.listings_delete'), 'default' => false],
|
|
['value' => 'aex.appraisals.view', 'label' => __('assetexchange::lang.appraisals_view'), 'default' => false],
|
|
['value' => 'aex.appraisals.create', 'label' => __('assetexchange::lang.appraisals_create'), 'default' => false],
|
|
['value' => 'aex.appraisals.update', 'label' => __('assetexchange::lang.appraisals_update'), 'default' => false],
|
|
['value' => 'aex.appraisals.approve', 'label' => __('assetexchange::lang.appraisals_approve'), 'default' => false],
|
|
['value' => 'aex.deals.view', 'label' => __('assetexchange::lang.deals_view'), 'default' => false],
|
|
['value' => 'aex.deals.create', 'label' => __('assetexchange::lang.deals_create'), 'default' => false],
|
|
['value' => 'aex.deals.update', 'label' => __('assetexchange::lang.deals_update'), 'default' => false],
|
|
['value' => 'aex.deals.complete', 'label' => __('assetexchange::lang.deals_complete'), 'default' => false],
|
|
['value' => 'aex.offers.view', 'label' => __('assetexchange::lang.offers_view'), 'default' => false],
|
|
['value' => 'aex.offers.create', 'label' => __('assetexchange::lang.offers_create'), 'default' => false],
|
|
['value' => 'aex.offers.manage', 'label' => __('assetexchange::lang.offers_manage'), 'default' => false],
|
|
['value' => 'aex.pipeline.view', 'label' => __('assetexchange::lang.pipeline_view'), 'default' => false],
|
|
['value' => 'aex.reports.view', 'label' => __('assetexchange::lang.reports_view'), 'default' => false],
|
|
['value' => 'aex.inquiries.view', 'label' => __('assetexchange::lang.inquiries_view'), 'default' => false],
|
|
['value' => 'aex.inquiries.create', 'label' => __('assetexchange::lang.inquiries_create'), 'default' => false],
|
|
['value' => 'aex.inquiries.manage', 'label' => __('assetexchange::lang.inquiries_manage'), 'default' => false],
|
|
['value' => 'aex.research.view', 'label' => __('assetexchange::lang.research_view'), 'default' => false],
|
|
['value' => 'aex.research.create', 'label' => __('assetexchange::lang.research_create'), 'default' => false],
|
|
['value' => 'aex.research.manage', 'label' => __('assetexchange::lang.research_manage'), 'default' => false],
|
|
];
|
|
}
|
|
|
|
public function modifyAdminMenu()
|
|
{
|
|
if (! \Module::has('AssetExchange') || ! \Module::isEnabled('AssetExchange')) {
|
|
return;
|
|
}
|
|
|
|
$business_id = session()->get('user.business_id');
|
|
$module_util = new ModuleUtil();
|
|
$is_enabled = (bool) $module_util->isModuleInstalled('AssetExchange');
|
|
|
|
if (! $is_enabled) {
|
|
return;
|
|
}
|
|
|
|
$user = auth()->user();
|
|
if (! $user->can('aex.access') && ! $user->can('aex.view')) {
|
|
return;
|
|
}
|
|
|
|
$hasSubscription = true;
|
|
if ($module_util->isSuperadminInstalled()) {
|
|
$hasSubscription = (bool) $module_util->hasThePermissionInSubscription($business_id, 'assetexchange_module');
|
|
}
|
|
|
|
if (! $hasSubscription) {
|
|
return;
|
|
}
|
|
|
|
Menu::modify('admin-sidebar-menu', function ($menu) {
|
|
$menu->dropdown(
|
|
__('assetexchange::lang.module_name'),
|
|
function ($sub) {
|
|
$user = auth()->user();
|
|
|
|
if ($user->can('aex.view') || $user->can('aex.access')) {
|
|
$notifLabel = __('assetexchange::lang.notifications');
|
|
if (\Illuminate\Support\Facades\Schema::hasTable('aex_notifications')) {
|
|
$count = Notification::where('business_id', session()->get('user.business_id'))
|
|
->where(function ($q) use ($user) {
|
|
$q->where('user_id', $user->id);
|
|
if (! empty($user->crm_contact_id)) {
|
|
$q->orWhere('contact_id', $user->crm_contact_id);
|
|
}
|
|
})
|
|
->whereNull('read_at')
|
|
->count();
|
|
if ($count > 0) {
|
|
$notifLabel .= ' ('.$count.')';
|
|
}
|
|
}
|
|
|
|
$sub->url(
|
|
action([DashboardController::class, 'index']),
|
|
__('assetexchange::lang.dashboard'),
|
|
['active' => request()->segment(1) == 'asset-exchange' && request()->segment(2) == 'dashboard']
|
|
);
|
|
|
|
$sub->url(
|
|
action([NotificationController::class, 'index']),
|
|
$notifLabel,
|
|
['active' => request()->segment(1) == 'asset-exchange' && request()->segment(2) == 'notifications']
|
|
);
|
|
}
|
|
|
|
if ($user->can('aex.listings.view')) {
|
|
$sub->url(
|
|
action([ListingController::class, 'index']),
|
|
__('assetexchange::lang.listings'),
|
|
['active' => request()->segment(2) == 'listings']
|
|
);
|
|
}
|
|
|
|
if ($user->can('aex.appraisals.view')) {
|
|
$sub->url(
|
|
action([AppraisalController::class, 'index']),
|
|
__('assetexchange::lang.appraisals'),
|
|
['active' => request()->segment(2) == 'appraisals']
|
|
);
|
|
}
|
|
|
|
if ($user->can('aex.deals.view')) {
|
|
$sub->url(
|
|
action([DealController::class, 'index']),
|
|
__('assetexchange::lang.deals'),
|
|
['active' => request()->segment(2) == 'deals']
|
|
);
|
|
}
|
|
|
|
if ($user->can('aex.offers.view')) {
|
|
$sub->url(
|
|
action([OfferController::class, 'index']),
|
|
__('assetexchange::lang.offers'),
|
|
['active' => request()->segment(2) == 'offers']
|
|
);
|
|
}
|
|
|
|
if ($user->can('aex.pipeline.view')) {
|
|
$sub->url(
|
|
action([PipelineController::class, 'index']),
|
|
__('assetexchange::lang.pipeline'),
|
|
['active' => request()->segment(2) == 'pipeline']
|
|
);
|
|
}
|
|
|
|
if ($user->can('aex.research.view')) {
|
|
$sub->url(
|
|
action([ResearchCaseController::class, 'index']),
|
|
__('assetexchange::lang.research_cases'),
|
|
['active' => request()->segment(2) == 'research']
|
|
);
|
|
}
|
|
|
|
if ($user->can('aex.inquiries.view')) {
|
|
$sub->url(
|
|
action([PriceInquiryController::class, 'index']),
|
|
__('assetexchange::lang.price_inquiries'),
|
|
['active' => request()->segment(2) == 'inquiries']
|
|
);
|
|
}
|
|
|
|
if ($user->can('aex.reports.view')) {
|
|
$sub->url(
|
|
action([ReportController::class, 'index']),
|
|
__('assetexchange::lang.reports'),
|
|
['active' => request()->segment(2) == 'reports']
|
|
);
|
|
}
|
|
|
|
if ($user->can('aex.access')) {
|
|
$sub->url(
|
|
action([SettingsController::class, 'index']),
|
|
__('assetexchange::lang.settings'),
|
|
['active' => request()->segment(2) == 'settings']
|
|
);
|
|
}
|
|
},
|
|
['icon' => MenuIcons::svg('exchange'), 'active' => request()->segment(1) == 'asset-exchange', 'data-module' => 'AssetExchange', 'data-menu-group' => 'management']
|
|
)->order(86);
|
|
});
|
|
}
|
|
}
|