Event addons bookable

This commit is contained in:
2026-08-12 16:45:02 +02:00
parent e95de52768
commit 0ee952212b
25 changed files with 656 additions and 24 deletions
@@ -0,0 +1,85 @@
<?php
namespace App\Domains\Event\Actions\SetEventAddons;
use App\ValueObjects\Amount;
use Illuminate\Support\Str;
class SetEventAddonsCommand
{
public function __construct(private SetEventAddonsRequest $request)
{
}
public function execute(): SetEventAddonsResponse
{
$response = new SetEventAddonsResponse();
$this->request->event->addons = $this->normalize($this->request->addons);
$this->request->event->save();
$response->success = true;
return $response;
}
/**
* Normalisiert die rohe Addon-Definition: trimmt Titel/Beschreibung, parst den Preis ( 0), erzwingt den
* Titel als Pflichtfeld und generiert stabile Keys (Bestandsschutz für bereits gespeicherte Buchungen).
*
* @param array<int, array<string, mixed>> $addons
* @return array<int, array{key: string, title: string, description: string, price: float, flat: bool}>
*/
private function normalize(array $addons): array
{
$normalized = [];
$usedKeys = [];
foreach ($addons as $addon) {
$title = trim((string)($addon['title'] ?? ''));
if ($title === '') {
continue;
}
$price = Amount::fromString((string)($addon['price'] ?? '0'))->getAmount();
if ($price < 0) {
$price = 0.0;
}
$key = $this->uniqueSlug((string)($addon['key'] ?? ''), $title, $usedKeys);
$usedKeys[] = $key;
$normalized[] = [
'key' => $key,
'title' => $title,
'description' => trim((string)($addon['description'] ?? '')),
'price' => round($price, 2),
'flat' => (bool)($addon['flat'] ?? false),
];
}
return $normalized;
}
/**
* Liefert einen eindeutigen Slug: bevorzugt den bestehenden Wert, sonst aus dem Titel abgeleitet;
* Kollisionen werden durchnummeriert.
*
* @param array<int, string> $used
*/
private function uniqueSlug(string $existing, string $title, array $used): string
{
$base = $existing !== '' ? $existing : Str::slug($title);
if ($base === '') {
$base = 'addon';
}
$candidate = $base;
$suffix = 2;
while (in_array($candidate, $used, true)) {
$candidate = $base . '-' . $suffix;
$suffix++;
}
return $candidate;
}
}
@@ -0,0 +1,19 @@
<?php
namespace App\Domains\Event\Actions\SetEventAddons;
use App\Models\Event;
class SetEventAddonsRequest
{
public Event $event;
/** @var array<int, array<string, mixed>> Rohe Addon-Definition aus dem Admin-Panel. */
public array $addons;
public function __construct(Event $event, array $addons)
{
$this->event = $event;
$this->addons = $addons;
}
}
@@ -0,0 +1,15 @@
<?php
namespace App\Domains\Event\Actions\SetEventAddons;
class SetEventAddonsResponse
{
public bool $success;
public ?string $message;
public function __construct()
{
$this->success = false;
$this->message = null;
}
}
@@ -89,11 +89,32 @@ class SignUpCommand {
); );
$this->persistParticipationOptions($response->participant, $participationOptionRows); $this->persistParticipationOptions($response->participant, $participationOptionRows);
$this->persistAddons($response->participant);
$response->success = true; $response->success = true;
return $response; return $response;
} }
/**
* Speichert die gewählten Zusätze (Event-Addons) als Snapshot-Zeilen (Titel/Preis/Betrag) für die spätere
* Rechnung. Die Beträge sind bereits in der Controller-Auflösung (`resolveAddons`) berechnet, inkl. USt.
*/
private function persistAddons(\App\Models\EventParticipant $participant): void
{
foreach ($this->request->addonItems as $item) {
$participant->selectedAddons()->create([
'tenant' => $this->request->event->tenant,
'event_id' => $this->request->event->id,
'addon_key' => $item['key'],
'title' => $item['title'],
'price' => $item['price'] ?? 0,
'flat' => (bool)($item['flat'] ?? false),
'days' => $item['days'] ?? 0,
'amount' => $item['amount'] ?? 0,
]);
}
}
/** /**
* Validiert die Antworten gegen die am Event definierten Teilnahmeoptionen und erzeugt die zu speichernden * Validiert die Antworten gegen die am Event definierten Teilnahmeoptionen und erzeugt die zu speichernden
* Zeilen mit Label-Snapshots. Gibt null zurück, wenn eine Pflicht-Frage unbeantwortet oder eine Antwort * Zeilen mit Label-Snapshots. Gibt null zurück, wenn eine Pflicht-Frage unbeantwortet oder eine Antwort
@@ -48,6 +48,8 @@ class SignUpRequest {
public array $paymentOptions = [], public array $paymentOptions = [],
/** Antworten auf die Teilnahmeoptionen: [ question_key => value ]. */ /** Antworten auf die Teilnahmeoptionen: [ question_key => value ]. */
public array $participationOptions = [], public array $participationOptions = [],
/** Aufgelöste Zusätze (Event-Addons): je Eintrag [ key, title, price, flat, days, amount ]. */
public array $addonItems = [],
) { ) {
} }
} }
@@ -77,11 +77,45 @@ class UpdateParticipantCommand {
$this->syncParticipationOptions($p); $this->syncParticipationOptions($p);
} }
if ($this->request->selectedAddons !== null) {
$this->syncAddons($p);
}
$this->response->success = true; $this->response->success = true;
$this->response->participant = $p; $this->response->participant = $p;
return $this->response; return $this->response;
} }
/**
* Ersetzt die zugeordneten Zusätze (Event-Addons) anhand der Auswahl. Bewusst **ohne Preis/Betrag**
* (amount 0): der Teilnahmebeitrag wird in den Details ohnehin manuell gesetzt. Es wird nur der Titel als
* Snapshot gespeichert, damit die Zuordnung sichtbar bleibt.
*/
private function syncAddons(EventParticipant $participant): void
{
$participant->selectedAddons()->delete();
$selection = $this->request->selectedAddons ?? [];
foreach ($participant->event?->addons ?? [] as $addon) {
$key = $addon['key'] ?? null;
if ($key === null || empty($selection[$key])) {
continue;
}
$participant->selectedAddons()->create([
'tenant' => $participant->tenant,
'event_id' => $participant->event_id,
'addon_key' => $key,
'title' => $addon['title'] ?? $key,
'price' => 0,
'flat' => (bool)($addon['flat'] ?? false),
'days' => 0,
'amount' => 0,
]);
}
}
/** /**
* Ersetzt die zugeordneten Teilnahmeoptionen anhand der übergebenen Antworten. Nachträgliche Zuordnung im * Ersetzt die zugeordneten Teilnahmeoptionen anhand der übergebenen Antworten. Nachträgliche Zuordnung im
* Back-Office ist lückenlos möglich: nur gegen die Event-Definition gültige Antworten werden gespeichert, * Back-Office ist lückenlos möglich: nur gegen die Event-Definition gültige Antworten werden gespeichert,
@@ -38,5 +38,7 @@ class UpdateParticipantRequest {
public string $cocStatus, public string $cocStatus,
/** Antworten auf die Teilnahmeoptionen: [ question_key => value ]. null = unverändert lassen. */ /** Antworten auf die Teilnahmeoptionen: [ question_key => value ]. null = unverändert lassen. */
public ?array $participationOptions = null, public ?array $participationOptions = null,
/** Gewählte Zusätze: [ addon_key => bool ]. null = unverändert lassen. */
public ?array $selectedAddons = null,
) {} ) {}
} }
@@ -2,6 +2,8 @@
namespace App\Domains\Event\Controllers; 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\SetParticipationFeesCommand;
use App\Domains\Event\Actions\SetParticipationFees\SetParticipationFeesRequest; use App\Domains\Event\Actions\SetParticipationFees\SetParticipationFeesRequest;
use App\Domains\Event\Actions\SetParticipationOptions\SetParticipationOptionsCommand; use App\Domains\Event\Actions\SetParticipationOptions\SetParticipationOptionsCommand;
@@ -155,6 +157,17 @@ class DetailsController extends CommonController {
return response()->json(['status' => $response->success ? 'success' : 'error', 'message' => $response->message]); 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 public function downloadPdfList(string $eventId, string $listType, Request $request): Response
{ {
$event = $this->events->getByIdentifier($eventId); $event = $this->events->getByIdentifier($eventId);
@@ -45,6 +45,7 @@ class ParticipantUpdateController extends CommonController {
amountExpected: $request->input('amountExpected'), amountExpected: $request->input('amountExpected'),
cocStatus: $request->input('cocStatus'), cocStatus: $request->input('cocStatus'),
participationOptions: $request->has('participationOptions') ? (array)$request->input('participationOptions') : null, participationOptions: $request->has('participationOptions') ? (array)$request->input('participationOptions') : null,
selectedAddons: $request->has('selectedAddons') ? (array)$request->input('selectedAddons') : null,
); );
$command = new UpdateParticipantCommand($updateRequest); $command = new UpdateParticipantCommand($updateRequest);
@@ -104,6 +104,11 @@ class SignupController extends CommonController {
$siblingReduction $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( $signupRequest = new SignUpRequest(
$event, $event,
$registrationData['userId'] ?? null, $registrationData['userId'] ?? null,
@@ -143,6 +148,7 @@ class SignupController extends CommonController {
$registrationData['paymentMethod'] ?? null, $registrationData['paymentMethod'] ?? null,
(array)($registrationData['paymentOptions'] ?? []), (array)($registrationData['paymentOptions'] ?? []),
(array)($registrationData['participationOptions'] ?? []), (array)($registrationData['participationOptions'] ?? []),
$addonResolution['items'],
); );
$signupCommand = new SignUpCommand($signupRequest); $signupCommand = new SignUpCommand($signupRequest);
@@ -185,14 +191,22 @@ class SignupController extends CommonController {
$siblingReduction = $request->input('sibling') === 'true'; $siblingReduction = $request->input('sibling') === 'true';
$arrival = \DateTime::createFromFormat('Y-m-d', $request->input('arrival'));
$departure = \DateTime::createFromFormat('Y-m-d', $request->input('departure'));
$amount = $event->calculateAmount( $amount = $event->calculateAmount(
$request->input('participationType'), $request->input('participationType'),
$request->input('beitrag'), $request->input('beitrag'),
\DateTime::createFromFormat('Y-m-d', $request->input('arrival')), $arrival,
\DateTime::createFromFormat('Y-m-d', $request->input('departure')), $departure,
$siblingReduction $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));
$amount->addAmount($event->resolveAddons($selectedAddonKeys, $arrival, $departure)['total']);
// amountValue (numerisch) steuert im Frontend das Überspringen des Zahlungsart-Schritts bei 0 €. // amountValue (numerisch) steuert im Frontend das Überspringen des Zahlungsart-Schritts bei 0 €.
return response()->json([ return response()->json([
'amount' => $amount->toString(), 'amount' => $amount->toString(),
+1
View File
@@ -47,6 +47,7 @@ Route::prefix('api/v1')
Route::post('/common-settings', [DetailsController::class, 'updateCommonSettings']); Route::post('/common-settings', [DetailsController::class, 'updateCommonSettings']);
Route::post('/payment-methods', [DetailsController::class, 'updatePaymentMethods']); Route::post('/payment-methods', [DetailsController::class, 'updatePaymentMethods']);
Route::post('/participation-options', [DetailsController::class, 'updateParticipationOptions']); Route::post('/participation-options', [DetailsController::class, 'updateParticipationOptions']);
Route::post('/event-addons', [DetailsController::class, 'updateEventAddons']);
}); });
@@ -0,0 +1,166 @@
<script setup>
import {ref} from "vue";
import {toast} from "vue3-toastify";
import {request} from "../../../../../resources/js/components/HttpClient.js";
import AmountInput from "../../../../Views/Components/AmountInput.vue";
const emit = defineEmits(['close'])
const props = defineProps({
event: Object,
})
// Addon-Definition dieses Events: [ { key, title, description, price, flat } ].
// key bleibt für bestehende Einträge erhalten (Bestandsschutz für bereits gebuchte Zusätze).
const addons = ref((props.event.addons ?? []).map(a => ({
key: a.key ?? '',
title: a.title ?? '',
description: a.description ?? '',
price: a.price != null ? String(a.price).replace('.', ',') : '0',
flat: a.flat ?? false,
})))
function addAddon() {
addons.value.push({key: '', title: '', description: '', price: '0', flat: true})
}
function removeAddon(index) {
addons.value.splice(index, 1)
}
function validate() {
for (const addon of addons.value) {
if (addon.title.trim() === '') {
toast.error('Bitte für jeden Zusatz einen Titel angeben.')
return false
}
}
return true
}
async function save() {
if (!validate()) {
return
}
const response = await request('/api/v1/event/details/' + props.event.id + '/event-addons', {
method: 'POST',
body: {
addons: addons.value,
}
})
if (response.status !== 'success') {
toast.error(response.message ?? 'Die Zusatzoptionen konnten nicht gespeichert werden.')
return
}
toast.success('Die Zusatzoptionen wurden gespeichert')
emit('close')
}
</script>
<template>
<div class="event-addons">
<h3>Zusatzoptionen</h3>
<p style="color: #6b7280; font-size: 0.9rem;">
Buchbare Zusätze zur Veranstaltung (z. B. Parkticket, Aufnäher). Jede Position ist eine Ja/Nein-Auswahl.
Preis 0 wird dem Teilnehmenden als Kostenfrei" angezeigt. Ist „Pauschale" nicht gesetzt, wird der Preis
mit der Anzahl der Teilnahmetage multipliziert. Ohne Zusätze wird dieser Schritt in der Anmeldung
übersprungen.
</p>
<div v-for="(addon, index) in addons" :key="index" class="addon-card">
<div class="addon-head">
<div class="addon-fields">
<label class="field-label">Titel</label>
<input type="text" v-model="addon.title" class="width-full" placeholder="z. B. „Parkticket“"/>
<label class="field-label">Beschreibung (optional)</label>
<input type="text" v-model="addon.description" class="width-full" placeholder="Kurze Erläuterung"/>
<div class="addon-price-row">
<span>
<label class="field-label">Preis</label>
<AmountInput v-model="addon.price" class="width-small"/> Euro
</span>
<label class="flat-label">
<input type="checkbox" v-model="addon.flat"/>
Pauschale (nicht pro Tag)
</label>
</div>
</div>
<label class="link remove-link" @click="removeAddon(index)">Entfernen</label>
</div>
</div>
<div style="margin-top: 16px;">
<label class="link" @click="addAddon">+ Zusatz hinzufügen</label>
</div>
<div style="margin-top: 24px;">
<input type="button" value="Speichern" @click="save"/>
</div>
</div>
</template>
<style scoped>
.addon-card {
margin-top: 16px;
padding: 14px;
background: #f8fafc;
border: 1px solid #e5e7eb;
border-radius: 10px;
}
.addon-head {
display: flex;
align-items: flex-start;
gap: 12px;
}
.addon-fields {
flex: 1;
}
.field-label {
display: block;
font-size: 0.78rem;
color: #6b7280;
margin: 6px 0 2px;
}
.addon-fields .field-label:first-child {
margin-top: 0;
}
.addon-price-row {
display: flex;
align-items: flex-end;
gap: 24px;
margin-top: 6px;
}
.flat-label {
display: flex;
align-items: center;
gap: 6px;
font-size: 0.9rem;
color: #374151;
}
.width-full {
width: 100%;
}
.width-small {
width: 90px;
}
.remove-link {
white-space: nowrap;
color: #ef4444;
font-size: 0.85rem;
}
</style>
@@ -2,6 +2,7 @@
import {onMounted, reactive, ref} from "vue"; import {onMounted, reactive, ref} from "vue";
import ParticipationFees from "./ParticipationFees.vue"; import ParticipationFees from "./ParticipationFees.vue";
import ParticipationOptions from "./ParticipationOptions.vue"; import ParticipationOptions from "./ParticipationOptions.vue";
import EventAddons from "./EventAddons.vue";
import ParticipationSummary from "./ParticipationSummary.vue"; import ParticipationSummary from "./ParticipationSummary.vue";
import CommonSettings from "./CommonSettings.vue"; import CommonSettings from "./CommonSettings.vue";
import EventManagement from "./EventManagement.vue"; import EventManagement from "./EventManagement.vue";
@@ -41,6 +42,10 @@ const props = defineProps({
displayData.value = 'participationOptions'; displayData.value = 'participationOptions';
} }
async function showEventAddons() {
displayData.value = 'eventAddons';
}
async function showEventManagement() { async function showEventManagement() {
displayData.value = 'eventManagement'; displayData.value = 'eventManagement';
} }
@@ -114,6 +119,7 @@ const props = defineProps({
<ParticipationFees v-if="displayData === 'participationFees'" :event="dynamicProps.event" @close="showMain" /> <ParticipationFees v-if="displayData === 'participationFees'" :event="dynamicProps.event" @close="showMain" />
<ParticipationOptions v-else-if="displayData === 'participationOptions'" :event="dynamicProps.event" <ParticipationOptions v-else-if="displayData === 'participationOptions'" :event="dynamicProps.event"
@close="showMain"/> @close="showMain"/>
<EventAddons v-else-if="displayData === 'eventAddons'" :event="dynamicProps.event" @close="showMain"/>
<CommonSettings v-else-if="displayData === 'commonSettings'" :event="dynamicProps.event" @close="showMain" /> <CommonSettings v-else-if="displayData === 'commonSettings'" :event="dynamicProps.event" @close="showMain" />
<EventManagement v-else-if="displayData === 'eventManagement'" :event="dynamicProps.event" @close="showMain" /> <EventManagement v-else-if="displayData === 'eventManagement'" :event="dynamicProps.event" @close="showMain" />
@@ -194,6 +200,8 @@ const props = defineProps({
<label style="font-size: 9pt;" class="link" @click="showEventManagement">Veranstaltungsleitung</label> &nbsp; <label style="font-size: 9pt;" class="link" @click="showEventManagement">Veranstaltungsleitung</label> &nbsp;
<label style="font-size: 9pt;" class="link" @click="showParticipationFees">Teilnahmegebühren</label> &nbsp; <label style="font-size: 9pt;" class="link" @click="showParticipationFees">Teilnahmegebühren</label> &nbsp;
<label style="font-size: 9pt;" class="link" @click="showParticipationOptions">Teilnahmeoptionen</label> <label style="font-size: 9pt;" class="link" @click="showParticipationOptions">Teilnahmeoptionen</label>
&nbsp;
<label style="font-size: 9pt;" class="link" @click="showEventAddons">Zusatzoptionen</label>
<a style="font-size: 9pt;" class="link" :href="'/budget/' + props.data.event.costUnit.id">Budget bearbeiten</a> <a style="font-size: 9pt;" class="link" :href="'/budget/' + props.data.event.costUnit.id">Budget bearbeiten</a>
<a style="font-size: 9pt;" class="link" :href="'/cost-unit/' + props.data.event.costUnit.id">Ausgabenübersicht</a> <a style="font-size: 9pt;" class="link" :href="'/cost-unit/' + props.data.event.costUnit.id">Ausgabenübersicht</a>
<a v-if="!dynamicProps.event.registrationAllowed && !dynamicProps.event.archived" style="color: #ff0000; font-size: 9pt;" class="link" @click="archiveEvent">Archivieren</a> <a v-if="!dynamicProps.event.registrationAllowed && !dynamicProps.event.archived" style="color: #ff0000; font-size: 9pt;" class="link" @click="archiveEvent">Archivieren</a>
@@ -61,17 +61,26 @@ const form = reactive({
amountExpected: '', amountExpected: '',
cocStatus: '', cocStatus: '',
participationOptions: {}, participationOptions: {},
selectedAddons: {},
}); });
// Teilnahmeoptionen des Events (Definition mit Titel/Frage/Optionen). // Teilnahmeoptionen des Events (Definition mit Titel/Frage/Optionen).
const participationQuestions = computed(() => staticProps.event?.participationOptions ?? []); const participationQuestions = computed(() => staticProps.event?.participationOptions ?? []);
// Zusatzoptionen (Event-Addons) des Events.
const eventAddons = computed(() => staticProps.event?.addons ?? []);
// Gewählte Antwort (Options-Label) eines Teilnehmers zu einer Frage für die Ansicht „Titel: Antwort". // Gewählte Antwort (Options-Label) eines Teilnehmers zu einer Frage für die Ansicht „Titel: Antwort".
function answerLabelFor(questionKey) { function answerLabelFor(questionKey) {
const answer = (props.participant?.participationOptions ?? []).find(o => o.questionKey === questionKey); const answer = (props.participant?.participationOptions ?? []).find(o => o.questionKey === questionKey);
return answer?.valueLabel ?? '—'; return answer?.valueLabel ?? '—';
} }
// Hat der Teilnehmer diesen Zusatz gebucht? für die Ansicht.
function isAddonSelected(addonKey) {
return (props.participant?.selectedAddons ?? []).some(a => a.addonKey === addonKey);
}
watch( watch(
() => props.participant, () => props.participant,
(participant) => { (participant) => {
@@ -107,6 +116,9 @@ watch(
form.participationOptions = Object.fromEntries( form.participationOptions = Object.fromEntries(
(participant?.participationOptions ?? []).map(o => [o.questionKey, o.value]) (participant?.participationOptions ?? []).map(o => [o.questionKey, o.value])
); );
form.selectedAddons = Object.fromEntries(
(participant?.selectedAddons ?? []).map(a => [a.addonKey, true])
);
}, },
{ immediate: true } { immediate: true }
); );
@@ -402,25 +414,41 @@ function saveParticipant() {
</div> </div>
</div> </div>
<div class="participationData" v-if="participationQuestions.length > 0"> <div class="participationData" v-if="participationQuestions.length > 0 || eventAddons.length > 0">
<div> <div>
<h3>Teilnahmeoptionen</h3> <template v-if="participationQuestions.length > 0">
<table> <h3>Teilnahmeoptionen</h3>
<tr v-for="question in participationQuestions" :key="question.key"> <table>
<th>{{ question.title || question.label }}</th> <tr v-for="question in participationQuestions" :key="question.key">
<td> <th>{{ question.title || question.label }}</th>
<span v-if="!staticProps.editMode">{{ answerLabelFor(question.key) }}</span> <td>
<select v-else v-model="form.participationOptions[question.key]"> <span v-if="!staticProps.editMode">{{ answerLabelFor(question.key) }}</span>
<option value=""> keine </option> <select v-else v-model="form.participationOptions[question.key]">
<option v-for="option in question.options" :key="option.value" :value="option.value"> <option value=""> keine </option>
{{ option.label }} <option v-for="option in question.options" :key="option.value"
</option> :value="option.value">
</select> {{ option.label }}
</td> </option>
</tr> </select>
</table> </td>
</tr>
</table>
</template>
</div>
<div>
<template v-if="eventAddons.length > 0">
<h3>Zusatzoptionen</h3>
<table>
<tr v-for="addon in eventAddons" :key="addon.key">
<th>{{ addon.title }}</th>
<td>
<span v-if="!staticProps.editMode">{{ isAddonSelected(addon.key) ? 'Ja' : '' }}</span>
<input v-else type="checkbox" v-model="form.selectedAddons[addon.key]"/>
</td>
</tr>
</table>
</template>
</div> </div>
<div></div>
</div> </div>
</div> </div>
@@ -107,6 +107,7 @@ const steps = [
v-if="currentStep === 11" v-if="currentStep === 11"
:formData="formData" :formData="formData"
:event="event" :event="event"
:selectedAddons="selectedAddons"
:summaryAmount="summaryAmount" :summaryAmount="summaryAmount"
:summaryAmountValue="summaryAmountValue" :summaryAmountValue="summaryAmountValue"
:summaryLoading="summaryLoading" :summaryLoading="summaryLoading"
@@ -29,13 +29,21 @@ const next = () => emit('next', nextVisibleFrom(props.event, STEP_ADDONS))
<!-- Addons --> <!-- Addons -->
<div v-if="event.addons?.length > 0"> <div v-if="event.addons?.length > 0">
<h3>Zusatzoptionen</h3> <h3>Zusatzoptionen</h3>
<div v-for="addon in event.addons" :key="addon.id" style="margin-bottom: 16px; padding: 12px; background: #f8fafc; border-radius: 8px;"> <div v-for="addon in event.addons" :key="addon.key"
style="margin-bottom: 16px; padding: 12px; background: #f8fafc; border-radius: 8px;">
<label style="display: flex; gap: 12px; cursor: pointer;"> <label style="display: flex; gap: 12px; cursor: pointer;">
<input type="checkbox" v-model="selectedAddons[addon.id]" style="margin-top: 4px;" /> <input type="checkbox" v-model="selectedAddons[addon.key]" style="margin-top: 4px;"/>
<span> <span>
<strong>{{ addon.name }}</strong> <strong>{{ addon.title }}</strong>
<span style="display: block; color: #6b7280; font-size: 0.875rem;">Betrag: {{ addon.amount }}</span> <span style="display: block; color: #6b7280; font-size: 0.875rem;">
<span style="display: block; color: #374151; font-size: 0.875rem; margin-top: 4px;">{{ addon.description }}</span> <template v-if="addon.free">Kostenfrei</template>
<template v-else>{{ addon.priceReadable }}<template
v-if="!addon.flat"> / Tag</template></template>
</span>
<span v-if="addon.description"
style="display: block; color: #374151; font-size: 0.875rem; margin-top: 4px;">{{
addon.description
}}</span>
</span> </span>
</label> </label>
</div> </div>
@@ -7,6 +7,7 @@ const PAYMENT_ACCOUNT_TRANSACTION = 'PAYMENT_ACCOUNT_TRANSACTION'
const props = defineProps({ const props = defineProps({
formData: Object, formData: Object,
event: Object, event: Object,
selectedAddons: {type: Object, default: () => ({})},
summaryAmount: String, summaryAmount: String,
summaryAmountValue: {type: Number, default: 0}, summaryAmountValue: {type: Number, default: 0},
summaryLoading: Boolean, summaryLoading: Boolean,
@@ -35,6 +36,16 @@ const paymentConfirmationText = computed(() => {
// Zurück führt zur Zahlungsart (10), sofern dieser Schritt gezeigt wurde; bei 0 € direkt zu Allergien (9). // Zurück führt zur Zahlungsart (10), sofern dieser Schritt gezeigt wurde; bei 0 € direkt zu Allergien (9).
const backTarget = computed(() => props.summaryAmountValue > 0 ? 10 : 9) const backTarget = computed(() => props.summaryAmountValue > 0 ? 10 : 9)
// Gewählte Zusätze (Event-Addons) für die Zusammenfassung mit Preisanzeige.
const selectedAddonList = computed(() =>
(props.event.addons ?? [])
.filter(addon => props.selectedAddons[addon.key])
.map(addon => ({
title: addon.title,
price: addon.free ? 'Kostenfrei' : (addon.priceReadable + (addon.flat ? '' : ' / Tag')),
}))
)
// Gewählte Teilnahmeoptionen für die Zusammenfassung (label statt value anzeigen). // Gewählte Teilnahmeoptionen für die Zusammenfassung (label statt value anzeigen).
const selectedParticipationOptions = computed(() => const selectedParticipationOptions = computed(() =>
(props.event.participationOptions ?? []).map(question => { (props.event.participationOptions ?? []).map(question => {
@@ -129,6 +140,11 @@ function eatingHabit() {
<td>{{ option.value }}</td> <td>{{ option.value }}</td>
</tr> </tr>
<tr v-for="addon in selectedAddonList" :key="addon.title">
<td>{{ addon.title }}:</td>
<td>{{ addon.price }}</td>
</tr>
<tr> <tr>
<td>Foto-Erlaubnis:</td> <td>Foto-Erlaubnis:</td>
<td> <td>
+2
View File
@@ -88,6 +88,7 @@ class Event extends InstancedModel
'tax_exemption_reason', 'tax_exemption_reason',
'tax_exemption_note', 'tax_exemption_note',
'participation_options', 'participation_options',
'addons',
]; ];
@@ -117,6 +118,7 @@ class Event extends InstancedModel
'vat_rate' => 'integer', 'vat_rate' => 'integer',
'participation_options' => 'array', 'participation_options' => 'array',
'addons' => 'array',
]; ];
public function tenant(): BelongsTo public function tenant(): BelongsTo
+6
View File
@@ -110,6 +110,12 @@ class EventParticipant extends InstancedModel
return $this->hasMany(EventParticipantOption::class, 'event_participant_id'); return $this->hasMany(EventParticipantOption::class, 'event_participant_id');
} }
/** Gebuchte Zusätze (Event-Addons) dieser Anmeldung. */
public function selectedAddons(): HasMany
{
return $this->hasMany(EventParticipantAddon::class, 'event_participant_id');
}
public function user() public function user()
{ {
return $this->belongsTo(User::class); return $this->belongsTo(User::class);
+41
View File
@@ -0,0 +1,41 @@
<?php
namespace App\Models;
use App\Casts\AmountCast;
use App\Scopes\InstancedModel;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class EventParticipantAddon extends InstancedModel
{
protected $table = 'event_participant_addons';
protected $fillable = [
'tenant',
'event_id',
'event_participant_id',
'addon_key',
'title',
'price',
'flat',
'days',
'amount',
];
protected $casts = [
'flat' => 'boolean',
'days' => 'integer',
'price' => AmountCast::class,
'amount' => AmountCast::class,
];
public function event(): BelongsTo
{
return $this->belongsTo(Event::class);
}
public function participant(): BelongsTo
{
return $this->belongsTo(EventParticipant::class, 'event_participant_id');
}
}
@@ -0,0 +1,26 @@
<?php
namespace App\Resources;
use App\Models\EventParticipantAddon;
use Illuminate\Http\Resources\Json\JsonResource;
class EventParticipantAddonResource extends JsonResource
{
function __construct(EventParticipantAddon $addon)
{
parent::__construct($addon);
}
public function toArray($request): array
{
return [
'addonKey' => $this->resource->addon_key,
'title' => $this->resource->title,
'flat' => $this->resource->flat,
'amount' => $this->resource->amount?->getAmount() ?? 0,
'amountReadable' => $this->resource->amount?->toString() ?? '0,00 Euro',
'free' => ($this->resource->amount?->getAmount() ?? 0) <= 0,
];
}
}
@@ -98,6 +98,8 @@ class EventParticipantResource extends JsonResource
'departureDateReadable' => $this->resource->departure_date->format('d.m.Y'), 'departureDateReadable' => $this->resource->departure_date->format('d.m.Y'),
'participationOptions' => $this->resource->selectedOptions()->get()->map( 'participationOptions' => $this->resource->selectedOptions()->get()->map(
fn($option) => new EventParticipantOptionResource($option)->toArray($request))->toArray(), fn($option) => new EventParticipantOptionResource($option)->toArray($request))->toArray(),
'selectedAddons' => $this->resource->selectedAddons()->get()->map(
fn($addon) => new EventParticipantAddonResource($addon)->toArray($request))->toArray(),
] ]
); );
} }
+62
View File
@@ -141,6 +141,20 @@ class EventResource extends JsonResource{
// Veranstaltungsspezifische Pflicht-Auswahlfragen (Teilnahmeoptionen); leeres Array => Schritt entfällt. // Veranstaltungsspezifische Pflicht-Auswahlfragen (Teilnahmeoptionen); leeres Array => Schritt entfällt.
$returnArray['participationOptions'] = $this->event->participation_options ?? []; $returnArray['participationOptions'] = $this->event->participation_options ?? [];
// Buchbare Zusätze (Event-Addons); leeres Array => Schritt entfällt. Preis 0 => "Kostenfrei".
$returnArray['addons'] = collect($this->event->addons ?? [])->map(function ($addon) {
$price = (float)($addon['price'] ?? 0);
return [
'key' => $addon['key'] ?? '',
'title' => $addon['title'] ?? '',
'description' => $addon['description'] ?? '',
'price' => $price,
'priceReadable' => new Amount($price, 'Euro')->toString(),
'free' => $price <= 0,
'flat' => (bool)($addon['flat'] ?? false),
];
})->toArray();
$returnArray['participationTypes'] = []; $returnArray['participationTypes'] = [];
@@ -354,6 +368,54 @@ class EventResource extends JsonResource{
return new Amount(round($basicFee->getAmount(), 2), 'Euro'); return new Amount(round($basicFee->getAmount(), 2), 'Euro');
} }
/**
* Löst die gewählten Zusätze (Event-Addons) gegen die Event-Definition auf und berechnet je Position den
* Betrag: Pauschale => Preis, sonst Preis × Teilnahmetage. Bei USt-Pflicht + Netto-Preismodus (`add_on`)
* wird die USt aufgeschlagen (analog Beitrag); bei „inclusive"/keiner Pflicht bleibt der Preis unverändert.
* Kein Early-Bird-Aufschlag.
*
* @param array<int, string> $selectedKeys
* @return array{items: array<int, array{key: string, title: string, price: float, flat: bool, days: int, amount: float}>, total: Amount}
*/
public function resolveAddons(array $selectedKeys, DateTime $arrival, DateTime $departure): array
{
$days = $arrival->diff($departure)->days + 1;
$addsVat = $this->event->tax_liable && $this->event->vat_pricing_mode === VatPricingMode::AddOn->value;
$items = [];
$total = new Amount(0, 'Euro');
foreach ($this->event->addons ?? [] as $addon) {
$key = $addon['key'] ?? null;
if ($key === null || !in_array($key, $selectedKeys, true)) {
continue;
}
$price = (float)($addon['price'] ?? 0);
$flat = (bool)($addon['flat'] ?? false);
$usedDays = $flat ? 1 : $days;
$amount = $flat ? $price : $price * $days;
if ($addsVat) {
$amount *= 1 + $this->event->vat_rate / 100;
}
$amount = round($amount, 2);
$items[] = [
'key' => $key,
'title' => $addon['title'] ?? $key,
'price' => $price,
'flat' => $flat,
'days' => $usedDays,
'amount' => $amount,
];
$total->addAmount(new Amount($amount, 'Euro'));
}
return ['items' => $items, 'total' => $total];
}
} }
@@ -0,0 +1,23 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up(): void
{
Schema::table('events', function (Blueprint $table) {
// Buchbare Zusätze (Event-Addons) als Ja/Nein-Optionen mit Preis.
// Struktur: [ { key, title, description, price, flat } ]
$table->json('addons')->nullable();
});
}
public function down(): void
{
Schema::table('events', function (Blueprint $table) {
$table->dropColumn('addons');
});
}
};
@@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up(): void
{
// Gewählte Zusätze je Anmeldung -- eine Zeile pro gebuchtem Addon.
// Titel/Preis/Betrag werden als Snapshot mitgespeichert (relevant für die spätere Rechnung).
Schema::create('event_participant_addons', function (Blueprint $table) {
$table->id();
$table->string('tenant');
$table->foreignId('event_id')->constrained('events', 'id')->cascadeOnDelete()->cascadeOnUpdate();
$table->foreignId('event_participant_id')->constrained('event_participants', 'id')->cascadeOnDelete()->cascadeOnUpdate();
$table->string('addon_key');
$table->string('title');
$table->float('price')->default(0);
$table->boolean('flat')->default(false);
$table->integer('days')->default(0);
$table->float('amount')->default(0);
$table->timestamps();
$table->foreign('tenant')->references('slug')->on('tenants')->restrictOnDelete()->cascadeOnUpdate();
});
}
public function down(): void
{
Schema::dropIfExists('event_participant_addons');
}
};