commerce = $commerce; } public function mount(): void { $this->workspace = Auth::user()?->defaultHostWorkspace(); if (! $this->workspace) { $this->recentInvoices = collect(); $this->upcomingCharges = collect(); return; } // Load active subscription $this->activeSubscription = $this->workspace->subscriptions() ->active() ->with('workspacePackage.package') ->latest() ->first(); if ($this->activeSubscription) { $this->currentPlan = $this->activeSubscription->workspacePackage?->package?->name ?? 'Subscription'; $this->nextBillingDate = $this->activeSubscription->current_period_end?->format('j M Y'); $this->billingCycle = $this->guessBillingCycle(); // Calculate next billing amount $package = $this->activeSubscription->workspacePackage?->package; if ($package) { $this->nextBillingAmount = $package->getPrice($this->billingCycle); } } // Load recent invoices $this->recentInvoices = $this->workspace->invoices() ->with('items') ->latest() ->limit(5) ->get(); // Calculate upcoming charges (subscriptions renewing soon) $this->upcomingCharges = $this->workspace->subscriptions() ->valid() ->expiringSoon(30) ->with('workspacePackage.package') ->get(); // Load tree planting stats (Trees for Agents programme) $this->treesPlanted = $this->workspace->treesPlanted(); $this->treesThisYear = $this->workspace->treesThisYear(); } public function formatMoney(float $amount): string { return $this->commerce->formatMoney($amount); } protected function guessBillingCycle(): string { if (! $this->activeSubscription) { return 'monthly'; } $periodDays = $this->activeSubscription->current_period_start ?->diffInDays($this->activeSubscription->current_period_end); return ($periodDays ?? 30) > 32 ? 'yearly' : 'monthly'; } public function render() { return view('commerce::web.dashboard') ->layout('hub::admin.layouts.app', ['title' => 'Billing']); } }