where('user_id', $account->id) ->where('status', Transfer::STATUS_ACTIVE); $activeCount = (clone $transfers)->count(); $storageBytes = (int) (clone $transfers)->sum('storage_bytes'); $transferIds = Transfer::query() ->where('user_id', $account->id) ->pluck('id'); $downloads30d = TransferDownloadEvent::query() ->whereIn('transfer_id', $transferIds) ->where('downloaded_at', '>=', now()->subDays(30)) ->count(); $expiringSoon = Transfer::query() ->where('user_id', $account->id) ->where('status', Transfer::STATUS_ACTIVE) ->whereNotNull('expires_at') ->whereBetween('expires_at', [now(), now()->addDays(7)]) ->count(); $recentTransfers = Transfer::query() ->where('user_id', $account->id) ->where('status', Transfer::STATUS_ACTIVE) ->with('qrCode') ->latest() ->limit(6) ->get(); $balanceMinor = 0; try { $balanceMinor = $this->billing->balanceMinor($account->public_id); } catch (Throwable $e) { Log::warning('Transfer dashboard could not load wallet balance', [ 'user' => $account->public_id, 'error' => $e->getMessage(), ]); } $storageGb = round($storageBytes / (1024 * 1024 * 1024), 2); $monthlyEstimateGhs = round($storageGb * (float) config('transfer.price_per_gb_month', 0.30), 2); return view('transfer.dashboard', [ 'activeCount' => $activeCount, 'storageBytes' => $storageBytes, 'storageGb' => $storageGb, 'downloads30d' => $downloads30d, 'expiringSoon' => $expiringSoon, 'recentTransfers' => $recentTransfers, 'balanceMinor' => $balanceMinor, 'monthlyEstimateGhs' => $monthlyEstimateGhs, ]); } }