Handling of event addons

This commit is contained in:
2026-08-12 17:18:45 +02:00
parent 085299336e
commit 6e4e6b645c
74 changed files with 3072 additions and 95 deletions
@@ -12,6 +12,7 @@ use App\Providers\DoubleCheckEventRegistrationProvider;
use App\Providers\InertiaProvider;
use App\Resources\UserResource;
use App\Scopes\CommonController;
use App\ValueObjects\Amount;
use DateTime;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
@@ -104,6 +105,11 @@ class SignupController extends CommonController {
$siblingReduction
);
// Gewählte Zusätze (Event-Addons) auflösen und auf den Gesamtbetrag aufaddieren.
$selectedAddonKeys = array_keys(array_filter((array)$request->input('addons', []), fn($v) => (bool)$v));
$addonResolution = $eventResource->resolveAddons($selectedAddonKeys, $arrival, $departure);
$amount->addAmount($addonResolution['total']);
$signupRequest = new SignUpRequest(
$event,
$registrationData['userId'] ?? null,
@@ -142,6 +148,8 @@ class SignupController extends CommonController {
$amount,
$registrationData['paymentMethod'] ?? null,
(array)($registrationData['paymentOptions'] ?? []),
(array)($registrationData['participationOptions'] ?? []),
$addonResolution['items'],
);
$signupCommand = new SignUpCommand($signupRequest);
@@ -184,18 +192,41 @@ class SignupController extends CommonController {
$siblingReduction = $request->input('sibling') === 'true';
$amount = $event->calculateAmount(
$arrival = \DateTime::createFromFormat('Y-m-d', $request->input('arrival'));
$departure = \DateTime::createFromFormat('Y-m-d', $request->input('departure'));
$baseFee = $event->calculateAmount(
$request->input('participationType'),
$request->input('beitrag'),
\DateTime::createFromFormat('Y-m-d', $request->input('arrival')),
\DateTime::createFromFormat('Y-m-d', $request->input('departure')),
$arrival,
$departure,
$siblingReduction
);
// Gewählte Zusätze immer einrechnen -- so enthält der finale Anzeigebetrag (und der Bestätigungstext)
// stets die Addons und der Zahlungsschritt wird nur bei Gesamt 0 € übersprungen.
$selectedAddonKeys = array_keys(array_filter((array)$request->input('addons', []), fn($v) => (bool)$v));
$resolution = $event->resolveAddons($selectedAddonKeys, $arrival, $departure);
// Gesamt = Teilnahmebeitrag + Zusätze; Basisbetrag separat für die Kostenübersicht in der Zusammenfassung.
$total = new Amount($baseFee->getAmount(), 'Euro');
$total->addAmount($resolution['total']);
$addonLines = array_map(fn($item) => [
'key' => $item['key'],
'title' => $item['title'],
'amountValue' => $item['amount'],
'amount' => new Amount($item['amount'], 'Euro')->toString(),
'free' => $item['amount'] <= 0,
], $resolution['items']);
// amountValue (numerisch) steuert im Frontend das Überspringen des Zahlungsart-Schritts bei 0 €.
return response()->json([
'amount' => $amount->toString(),
'amountValue' => $amount->getAmount(),
'amount' => $total->toString(),
'amountValue' => $total->getAmount(),
'baseAmount' => $baseFee->toString(),
'baseAmountValue' => $baseFee->getAmount(),
'addons' => $addonLines,
]);
}
}