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
@@ -2,8 +2,12 @@
namespace App\Domains\Event\Controllers;
use App\Domains\Event\Actions\SetEventAddons\SetEventAddonsCommand;
use App\Domains\Event\Actions\SetEventAddons\SetEventAddonsRequest;
use App\Domains\Event\Actions\SetParticipationFees\SetParticipationFeesCommand;
use App\Domains\Event\Actions\SetParticipationFees\SetParticipationFeesRequest;
use App\Domains\Event\Actions\SetParticipationOptions\SetParticipationOptionsCommand;
use App\Domains\Event\Actions\SetParticipationOptions\SetParticipationOptionsRequest;
use App\Domains\Event\Actions\SetPaymentMethods\SetPaymentMethodsCommand;
use App\Domains\Event\Actions\SetPaymentMethods\SetPaymentMethodsRequest;
use App\Domains\Event\Actions\UpdateEvent\UpdateEventCommand;
@@ -142,6 +146,28 @@ class DetailsController extends CommonController {
return response()->json(['status' => $response->success ? 'success' : 'error']);
}
public function updateParticipationOptions(int $eventId, Request $request): JsonResponse
{
$event = $this->events->getById($eventId);
$setRequest = new SetParticipationOptionsRequest($event, (array)$request->input('questions', []));
$setCommand = new SetParticipationOptionsCommand($setRequest);
$response = $setCommand->execute();
return response()->json(['status' => $response->success ? 'success' : 'error', 'message' => $response->message]);
}
public function updateEventAddons(int $eventId, Request $request): JsonResponse
{
$event = $this->events->getById($eventId);
$setRequest = new SetEventAddonsRequest($event, (array)$request->input('addons', []));
$setCommand = new SetEventAddonsCommand($setRequest);
$response = $setCommand->execute();
return response()->json(['status' => $response->success ? 'success' : 'error', 'message' => $response->message]);
}
public function downloadPdfList(string $eventId, string $listType, Request $request): Response
{
$event = $this->events->getByIdentifier($eventId);
@@ -195,6 +221,12 @@ class DetailsController extends CommonController {
case 'by-participation-group':
$participants = $this->eventParticipants->groupByParticipationType($event, $request);
break;
case 'by-participation-option':
$participants = $this->eventParticipants->groupByParticipationOption($event, $request);
break;
case 'by-addon':
$participants = $this->eventParticipants->groupByAddon($event, $request);
break;
case 'signed-off':
$participants = $this->eventParticipants->getSignedOffParticipants($event, $request);
break;
@@ -19,6 +19,10 @@ class ByGroupController extends CommonController
$participants = $this->eventParticipants->groupByParticipationType($event, $request, $request->input('groupName'));
$recipients = $this->eventParticipants->getMailAddresses($participants[$request->input('groupName')]);
break;
case 'by-participation-option':
$participants = $this->eventParticipants->groupByParticipationOption($event, $request, $request->input('groupName'));
$recipients = $this->eventParticipants->getMailAddresses($participants[$request->input('groupName')] ?? []);
break;
case 'signed-off':
$participants = $this->eventParticipants->getSignedOffParticipants($event, $request, $request->input('groupName'));
$recipients = $this->eventParticipants->getMailAddresses($participants[$request->input('groupName')]);
@@ -44,6 +44,8 @@ class ParticipantUpdateController extends CommonController {
amountPaid: $request->input('amountPaid'),
amountExpected: $request->input('amountExpected'),
cocStatus: $request->input('cocStatus'),
participationOptions: $request->has('participationOptions') ? (array)$request->input('participationOptions') : null,
selectedAddons: $request->has('selectedAddons') ? (array)$request->input('selectedAddons') : null,
);
$command = new UpdateParticipantCommand($updateRequest);
@@ -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,
]);
}
}