Teilnahmerechnungen erstellen
This commit is contained in:
@@ -6,6 +6,7 @@ use App\Enumerations\EatingHabit;
|
||||
use App\Enumerations\EfzStatus;
|
||||
use App\EventPaymentModules\EventPaymentModuleRegistry;
|
||||
use App\ValueObjects\Age;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class SignUpCommand {
|
||||
@@ -43,15 +44,21 @@ class SignUpCommand {
|
||||
|
||||
$participantAge = new Age($this->request->birthday);
|
||||
|
||||
$response->participant = $this->request->event->participants()->create(
|
||||
// Anmeldung als Ganzes: die laufende Nummer (invoice_sequence) muss unter der Sperre vergeben und
|
||||
// im selben Zug geschrieben werden, sonst könnten zwei gleichzeitige Anmeldungen dieselbe erhalten.
|
||||
$response->participant = DB::transaction(function () use ($participantAge, $eatingHabit, $paymentOptions, $participationOptionRows) {
|
||||
$participant = $this->request->event->participants()->create(
|
||||
[
|
||||
'tenant' => $this->request->event->tenant,
|
||||
'user_id' => $this->request->user_id,
|
||||
'identifier' => Str::random(10),
|
||||
'invoice_sequence' => $this->nextInvoiceSequence(),
|
||||
'firstname' => $this->request->firstname,
|
||||
'lastname' => $this->request->lastname,
|
||||
'nickname' => $this->request->nickname,
|
||||
'participation_type' => $this->request->participationType,
|
||||
'fee_type' => $this->request->feeType,
|
||||
'sibling_reduction' => $this->request->siblingReduction,
|
||||
'local_group' => $this->request->localGroup->slug,
|
||||
'birthday' => $this->request->birthday,
|
||||
'address_1' => $this->request->address_1,
|
||||
@@ -90,15 +97,40 @@ class SignUpCommand {
|
||||
'payment_options' => $paymentOptions,
|
||||
'efz_status' => $participantAge->isfullAged() ? EfzStatus::EFZ_STATUS_NOT_CHECKED : EfzStatus::EFZ_STATUS_NOT_REQUIRED,
|
||||
]
|
||||
);
|
||||
);
|
||||
|
||||
$this->persistParticipationOptions($response->participant, $participationOptionRows);
|
||||
$this->persistAddons($response->participant);
|
||||
$this->persistParticipationOptions($participant, $participationOptionRows);
|
||||
$this->persistAddons($participant);
|
||||
|
||||
return $participant;
|
||||
});
|
||||
|
||||
$response->success = true;
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Nächste laufende Nummer des Teilis innerhalb der Veranstaltung -- der letzte Block der
|
||||
* Rechnungsnummer. Die Event-Zeile wird gesperrt, damit gleichzeitige Anmeldungen derselben
|
||||
* Veranstaltung serialisiert werden; der Aufruf erfolgt innerhalb der Anmelde-Transaktion, sodass die
|
||||
* Sperre bis zum Schreiben des Teilis steht.
|
||||
*
|
||||
* Abgemeldete Teilis behalten ihre Nummer, gezählt wird deshalb über MAX und nicht über COUNT.
|
||||
*/
|
||||
private function nextInvoiceSequence(): int
|
||||
{
|
||||
DB::table('events')
|
||||
->where('id', $this->request->event->id)
|
||||
->lockForUpdate()
|
||||
->first();
|
||||
|
||||
$highest = DB::table('event_participants')
|
||||
->where('event_id', $this->request->event->id)
|
||||
->max('invoice_sequence');
|
||||
|
||||
return (int) $highest + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
|
||||
@@ -50,6 +50,10 @@ class SignUpRequest {
|
||||
public array $participationOptions = [],
|
||||
/** Aufgelöste Zusätze (Event-Addons): je Eintrag [ key, title, price, flat, days, amount ]. */
|
||||
public array $addonItems = [],
|
||||
/** Gewählte Preisspalte: standard | reduced | solidarity. Wird für die Rechnung mitgeschrieben. */
|
||||
public ?string $feeType = null,
|
||||
/** Ob die 50-%-Geschwisterermäßigung in `amount` eingerechnet ist. */
|
||||
public bool $siblingReduction = false,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user