Deploy Ladill Events / deploy (push) Successful in 57s
The balance is still on Payments & payouts, which is where someone goes when they actually care about it — the overview is for events, not billing. Removes the BillingClient call behind it as well. Leaving that in place would have kept an external billing API request on every overview load to render nothing, and it was the controller's only use of the client, so the dependency goes too.
77 lines
2.4 KiB
PHP
77 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Events;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\QrCode;
|
|
use App\Models\QrEventRegistration;
|
|
use App\Services\Events\SubscriptionService;
|
|
use App\Support\Qr\QrTypeCatalog;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\View\View;
|
|
|
|
class OverviewController extends Controller
|
|
{
|
|
public function __construct(private SubscriptionService $subscriptions) {}
|
|
|
|
public function index(Request $request): View
|
|
{
|
|
$account = ladill_account();
|
|
|
|
$events = $account->qrCodes()
|
|
->where('type', QrCode::TYPE_EVENT)
|
|
->get();
|
|
|
|
$eventIds = $events->pluck('id');
|
|
|
|
$upcomingCount = $events->filter(function (QrCode $event) {
|
|
$startsAt = $event->content()['starts_at'] ?? null;
|
|
if (! $startsAt) {
|
|
return true;
|
|
}
|
|
|
|
return strtotime((string) $startsAt) >= now()->startOfDay()->timestamp;
|
|
})->count();
|
|
|
|
$registrationsQuery = QrEventRegistration::query()
|
|
->whereIn('qr_code_id', $eventIds)
|
|
->where('status', QrEventRegistration::STATUS_CONFIRMED);
|
|
|
|
$ticketsSold = (clone $registrationsQuery)->count();
|
|
$revenueMinor = (int) (clone $registrationsQuery)->sum('amount_minor');
|
|
$checkedIn = QrEventRegistration::query()
|
|
->whereIn('qr_code_id', $eventIds)
|
|
->whereNotNull('checked_in_at')
|
|
->count();
|
|
|
|
$checkInRate = $ticketsSold > 0 ? round(($checkedIn / $ticketsSold) * 100) : 0;
|
|
|
|
$recentEvents = $account->qrCodes()
|
|
->where('type', QrCode::TYPE_EVENT)
|
|
->latest()
|
|
->limit(5)
|
|
->get()
|
|
->map(function (QrCode $event) {
|
|
$event->confirmed_count = $event->eventRegistrations()
|
|
->where('status', QrEventRegistration::STATUS_CONFIRMED)
|
|
->count();
|
|
|
|
return $event;
|
|
});
|
|
|
|
$programmeCount = $account->qrCodes()
|
|
->whereIn('type', QrTypeCatalog::programmeTypes())
|
|
->count();
|
|
|
|
return view('events.dashboard', [
|
|
'upcomingCount' => $upcomingCount,
|
|
'ticketsSold' => $ticketsSold,
|
|
'revenueMinor' => $revenueMinor,
|
|
'checkInRate' => $checkInRate,
|
|
'recentEvents' => $recentEvents,
|
|
'programmeCount' => $programmeCount,
|
|
'hasPaidPlan' => $this->subscriptions->hasPaidPlan($account),
|
|
]);
|
|
}
|
|
}
|