2025-11-21 09:18:19 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
|
2025-11-24 08:50:44 +09:00
|
|
|
use App\Models\Tenants\Tenant;
|
2026-01-31 16:40:50 +09:00
|
|
|
use App\Services\Sales\SalesManagerService;
|
2025-11-21 09:18:19 +09:00
|
|
|
use Illuminate\Support\Facades\View;
|
|
|
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
|
|
|
|
|
|
class ViewServiceProvider extends ServiceProvider
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Register services.
|
|
|
|
|
*/
|
|
|
|
|
public function register(): void
|
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Bootstrap services.
|
|
|
|
|
*/
|
|
|
|
|
public function boot(): void
|
|
|
|
|
{
|
2025-11-24 11:17:31 +09:00
|
|
|
// 모든 뷰에 테넌트 목록 공유 (전역용)
|
2025-11-21 09:18:19 +09:00
|
|
|
View::composer('*', function ($view) {
|
|
|
|
|
if (auth()->check()) {
|
2026-02-04 13:13:17 +09:00
|
|
|
// 테넌트가 선택되지 않은 경우 자동으로 HQ 테넌트 설정
|
|
|
|
|
if (!session('selected_tenant_id')) {
|
|
|
|
|
$hqTenant = auth()->user()->getHQTenant();
|
|
|
|
|
if ($hqTenant) {
|
|
|
|
|
session(['selected_tenant_id' => $hqTenant->id]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-24 11:17:31 +09:00
|
|
|
$globalTenants = Tenant::active()
|
2025-11-21 09:18:19 +09:00
|
|
|
->orderBy('company_name')
|
|
|
|
|
->get(['id', 'company_name', 'code']);
|
|
|
|
|
|
2025-11-24 11:17:31 +09:00
|
|
|
$view->with('globalTenants', $globalTenants);
|
2025-11-21 09:18:19 +09:00
|
|
|
}
|
|
|
|
|
});
|
2026-01-31 16:40:50 +09:00
|
|
|
|
2026-01-31 16:50:46 +09:00
|
|
|
// 사이드바 메뉴 뱃지 데이터 (전역 공유 - 컴포넌트에서도 접근 가능)
|
2026-01-31 16:40:50 +09:00
|
|
|
View::composer('partials.sidebar', function ($view) {
|
2026-01-31 16:46:17 +09:00
|
|
|
$menuBadges = [
|
|
|
|
|
'byRoute' => [], // 라우트명 기준
|
|
|
|
|
'byUrl' => [], // URL 기준
|
|
|
|
|
];
|
2026-01-31 16:40:50 +09:00
|
|
|
|
|
|
|
|
if (auth()->check()) {
|
|
|
|
|
try {
|
|
|
|
|
$salesManagerService = app(SalesManagerService::class);
|
|
|
|
|
$approvalStats = $salesManagerService->getApprovalStats();
|
|
|
|
|
|
|
|
|
|
// 영업파트너 승인 대기 건수
|
|
|
|
|
if ($approvalStats['pending'] > 0) {
|
2026-01-31 16:46:17 +09:00
|
|
|
$menuBadges['byRoute']['sales.managers.approvals'] = $approvalStats['pending'];
|
|
|
|
|
$menuBadges['byUrl']['/sales/managers/approvals'] = $approvalStats['pending'];
|
2026-01-31 16:40:50 +09:00
|
|
|
}
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
// 서비스 오류 시 무시
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-31 16:50:46 +09:00
|
|
|
// View::share로 전역 공유 (Blade 컴포넌트에서도 접근 가능)
|
|
|
|
|
View::share('menuBadges', $menuBadges);
|
2026-01-31 16:40:50 +09:00
|
|
|
});
|
2025-11-21 09:18:19 +09:00
|
|
|
}
|
|
|
|
|
}
|