ajax()) { return $next($request); } Menu::create('portal-supplier-sidebar', function ($menu) { $menu->url(action([\Modules\Portal\Http\Controllers\Supplier\DashboardController::class, 'index']), __('home.home'), [ 'icon' => 'fa fas fa-tachometer-alt', 'active' => request()->segment(1) == 'supplier' && request()->segment(2) == 'dashboard', ])->order(1); $menu->url(action([\Modules\Portal\Http\Controllers\Supplier\PurchaseOrderController::class, 'index']), __('lang_v1.purchase_order'), [ 'icon' => 'fa fas fa-clipboard-list', 'active' => request()->segment(2) == 'purchase-orders', ])->order(2); $menu->url(action([\Modules\Portal\Http\Controllers\Supplier\PurchaseController::class, 'getPurchaseList']), __('purchase.list_purchase'), [ 'icon' => 'fa fas fa-list', 'active' => request()->segment(2) == 'purchases', ])->order(3); $menu->url(action([\Modules\Portal\Http\Controllers\Supplier\PaymentController::class, 'index']), __('purchase.payments'), [ 'icon' => 'fa fas fa-money-bill-wave', 'active' => request()->segment(2) == 'payments', ])->order(4); $menu->url(action([\Modules\Portal\Http\Controllers\Supplier\PurchaseReturnController::class, 'index']), __('lang_v1.purchase_return'), [ 'icon' => 'fa fas fa-undo', 'active' => request()->segment(2) == 'purchase-returns', ])->order(5); $menu->url(action([\Modules\Portal\Http\Controllers\Supplier\DocumentController::class, 'index']), __('portal::lang.documents'), [ 'icon' => 'fa fas fa-folder-open', 'active' => request()->segment(2) == 'documents', ])->order(6); $menu->url(action([\Modules\Portal\Http\Controllers\Supplier\LedgerController::class, 'index']), __('lang_v1.ledger'), [ 'icon' => 'fas fa-scroll', 'active' => request()->segment(2) == 'ledger', ])->order(7); $business_id = auth()->user()->business_id; $enabled_modules = ! empty(session('business.enabled_modules')) ? session('business.enabled_modules') : []; if ($this->moduleEnabled($enabled_modules, ['supplychain', 'SupplyChain']) && \Module::has('SupplyChain') && \Module::isEnabled('SupplyChain')) { $module_util = new \App\Utils\ModuleUtil(); if ($module_util->isModuleInstalled('SupplyChain') && $module_util->hasThePermissionInSubscription($business_id, 'supplychain_module')) { $menu->url(route('supplier.supplychain.rfq.index'), __('supplychain::lang.portal_rfq'), [ 'icon' => 'fa fas fa-file-signature', 'active' => request()->segment(2) == 'supply-chain', ])->order(7); } } if (in_array('assetexchange', $enabled_modules, true) || in_array('AssetExchange', $enabled_modules, true)) { if (\Module::has('AssetExchange') && \Module::isEnabled('AssetExchange')) { $aex_settings = []; if (\Illuminate\Support\Facades\Schema::hasColumn('business', 'aex_settings')) { $raw = Business::where('id', $business_id)->value('aex_settings'); $aex_settings = ! empty($raw) ? (json_decode($raw, true) ?: []) : []; } if (! empty($aex_settings['portal_listings_enabled'])) { $contact_id = auth()->user()->crm_contact_id; $unreadInquiries = 0; $unreadNotifications = 0; if ($contact_id && \Illuminate\Support\Facades\Schema::hasTable('aex_price_inquiry_recipients')) { $unreadInquiries = PriceInquiryRecipient::where('business_id', $business_id) ->where('recipient_type', 'supplier') ->where('contact_id', $contact_id) ->whereNotNull('sent_at') ->whereNull('viewed_at') ->count(); } if ($contact_id && \Illuminate\Support\Facades\Schema::hasTable('aex_notifications')) { $unreadNotifications = AexNotification::where('business_id', $business_id) ->where('contact_id', $contact_id) ->whereNull('read_at') ->count(); } $menu->url(route('supplier.asset_exchange.listings.index'), __('assetexchange::lang.portal_my_listings'), [ 'icon' => 'fa fas fa-industry', 'active' => request()->segment(2) == 'asset-exchange', ])->order(8); $inqLabel = __('assetexchange::lang.portal_supplier_inquiries'); if ($unreadInquiries > 0) { $inqLabel .= ' ('.$unreadInquiries.')'; } $menu->url(route('supplier.asset_exchange.inquiries.index'), $inqLabel, [ 'icon' => 'fa fas fa-envelope-open-text', 'active' => request()->segment(2) == 'asset-exchange' && request()->segment(3) == 'inquiries', ])->order(9); $notifLabel = __('assetexchange::lang.notifications'); if ($unreadNotifications > 0) { $notifLabel .= ' ('.$unreadNotifications.')'; } $menu->url(route('supplier.asset_exchange.notifications.index'), $notifLabel, [ 'icon' => 'fa fas fa-bell', 'active' => request()->segment(2) == 'asset-exchange' && request()->segment(3) == 'notifications', ])->order(10); } } } }); return $next($request); } private function moduleEnabled(array $enabled_modules, array $names): bool { return (bool) count(array_intersect($enabled_modules, $names)); } }