Files
ladill-give/app/Http/Controllers/Give/OverviewController.php
T
isaaccladandCursor 0860b08af7 Initial Ladill Give extraction — online giving pages at give.ladill.com.
Donation checkout via Ladill Pay (9% fee), church/giving QR pages, SSO, and platform scan forwarding.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-09 07:25:49 +00:00

71 lines
2.1 KiB
PHP

<?php
namespace App\Http\Controllers\Give;
use App\Http\Controllers\Controller;
use App\Models\GiveDonation;
use App\Models\QrCode;
use App\Services\Billing\BillingClient;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Illuminate\View\View;
use Throwable;
class OverviewController extends Controller
{
public function __construct(private BillingClient $billing) {}
public function index(Request $request): View
{
$account = ladill_account();
$qrIds = $account->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,
]);
}
}