qrCodes() ->where('type', QrCode::TYPE_PAYMENT) ->pluck('id'); $todayPayments = MiniPayment::query() ->whereIn('qr_code_id', $qrIds) ->where('status', MiniPayment::STATUS_PAID) ->where('paid_at', '>=', now()->startOfDay()); $recentPayments = MiniPayment::query() ->whereIn('qr_code_id', $qrIds) ->where('status', MiniPayment::STATUS_PAID) ->with('qrCode') ->latest('paid_at') ->limit(8) ->get(); $balanceMinor = 0; try { $balanceMinor = $this->billing->balanceMinor($account->public_id); } catch (Throwable $e) { Log::warning('Mini API overview could not load wallet balance', [ 'user' => $account->public_id, 'error' => $e->getMessage(), ]); } return response()->json([ 'data' => [ 'currency' => 'GHS', 'today_takings_minor' => (int) (clone $todayPayments)->sum('merchant_amount_minor'), 'today_count' => (clone $todayPayments)->count(), 'payment_qr_count' => $qrIds->count(), 'wallet_balance_minor' => $balanceMinor, 'recent_payments' => $recentPayments->map(fn (MiniPayment $p) => PaymentPresenter::present($p))->values(), ], ]); } }