qrCodes() ->where('type', QrCode::TYPE_CHURCH) ->pluck('id'); $todayStart = now()->startOfDay(); $todayDonations = GiveDonation::query() ->whereIn('qr_code_id', $qrIds) ->where('status', GiveDonation::STATUS_PAID) ->where('paid_at', '>=', $todayStart); $todayCount = (clone $todayDonations)->count(); $todayMinor = (int) (clone $todayDonations)->sum('merchant_amount_minor'); $recentDonations = GiveDonation::query() ->whereIn('qr_code_id', $qrIds) ->where('status', GiveDonation::STATUS_PAID) ->with('qrCode') ->latest('paid_at') ->limit(8) ->get(); $givingPageCount = $qrIds->count(); $donorCount = GiveDonation::query() ->whereIn('qr_code_id', $qrIds) ->where('status', GiveDonation::STATUS_PAID) ->distinct('payer_email') ->count('payer_email'); $balanceMinor = 0; try { $balanceMinor = $this->billing->balanceMinor($account->public_id); } catch (Throwable $e) { Log::warning('Give dashboard could not load wallet balance', [ 'user' => $account->public_id, 'error' => $e->getMessage(), ]); } return view('give.dashboard', [ 'todayCount' => $todayCount, 'todayMinor' => $todayMinor, 'givingPageCount' => $givingPageCount, 'donorCount' => $donorCount, 'recentDonations' => $recentDonations, 'balanceMinor' => $balanceMinor, ]); } }