Basic signup for events
This commit is contained in:
@@ -5,17 +5,20 @@ namespace App\Resources;
|
||||
use App\Enumerations\ParticipationFeeType;
|
||||
use App\Models\Event;
|
||||
use App\ValueObjects\Amount;
|
||||
use DateTime;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class EventResource {
|
||||
class EventResource extends JsonResource{
|
||||
private Event $event;
|
||||
|
||||
public function __construct(Event $event) {
|
||||
$this->event = $event;
|
||||
}
|
||||
|
||||
public function toArray() : array {
|
||||
$duration = $this->event->end_date->diff($this->event->start_date)->d + 1;
|
||||
|
||||
public function toArray(Request $request) : array
|
||||
{
|
||||
$duration = $this->event->end_date->diff($this->event->start_date)->days + 1;
|
||||
|
||||
$returnArray = [
|
||||
'id' => $this->event->id,
|
||||
@@ -25,13 +28,31 @@ class EventResource {
|
||||
'email' => $this->event->email,
|
||||
'accountOwner' => $this->event->account_owner,
|
||||
'accountIban' => $this->event->account_iban,
|
||||
'accountOwner' => $this->event->account_owner,
|
||||
'accountIban' => $this->event->account_iban,
|
||||
'alcoholicsAge' => $this->event->alcoholics_age,
|
||||
'sendWeeklyReports' => $this->event->send_weekly_report,
|
||||
'registrationAllowed' => $this->event->registration_allowed,
|
||||
'earlyBirdEnd' => ['internal' => $this->event->early_bird_end->format('Y-m-d'), 'formatted' => $this->event->early_bird_end->format('d.m.Y')],
|
||||
'registrationFinalEnd' => ['internal' => $this->event->registration_final_end->format('Y-m-d'), 'formatted' => $this->event->registration_final_end->format('d.m.Y')],
|
||||
'refundAfterEarlyBirdEnd' => 100 - $this->event->early_bird_end_amount_increase,
|
||||
];
|
||||
|
||||
$returnArray['swimmingPermissions'] = \App\Enumerations\SwimmingPermission::query()
|
||||
->get()
|
||||
->map(fn ($permission) => [
|
||||
'slug' => $permission->slug,
|
||||
'name' => $permission->name,
|
||||
])
|
||||
->toArray();
|
||||
|
||||
$returnArray['firstAidPermissions'] = \App\Enumerations\FirstAidPermission::query()
|
||||
->get()
|
||||
->map(fn ($permission) => [
|
||||
'slug' => $permission->slug,
|
||||
'name' => $permission->name,
|
||||
])
|
||||
->toArray();
|
||||
|
||||
|
||||
$returnArray['costUnit'] = new CostUnitResource($this->event->costUnit()->first())->toArray(true);
|
||||
@@ -58,52 +79,122 @@ class EventResource {
|
||||
$returnArray['managers'] = $this->event->eventManagers()->get()->map(fn($user) => new UserResource($user))->toArray();
|
||||
|
||||
$returnArray['supportPersonCalced'] = $this->event->support_per_person->toString();
|
||||
$returnArray['contributingLocalGroups'] = $this->event->localGroups()->get()->map(fn($localGroup) => new LocalGroupResource($localGroup))->toArray();
|
||||
$returnArray['contributingLocalGroups'] = $this->event->localGroups
|
||||
->map(fn ($localGroup) => new LocalGroupResource($localGroup)->toArray($request))
|
||||
->toArray();
|
||||
|
||||
$returnArray['eatingHabits'] = $this->event->eatingHabits()->get()->map(
|
||||
fn($eatingHabit) => new EatingHabitResource($eatingHabit))->toArray();
|
||||
|
||||
|
||||
$returnArray['participationTypes'] = [];
|
||||
|
||||
$multiplier = $this->getMultiplier();
|
||||
|
||||
for ($i = 1; $i <= 4; $i++) {
|
||||
$returnArray['participationFee_' . $i] = [
|
||||
'active' => false,
|
||||
'name' => '',
|
||||
'description' => '',
|
||||
'amount' => '0,00',
|
||||
'type' => null
|
||||
'amount_standard' => null,
|
||||
'amount_reduced' => null,
|
||||
'amount_solidarity' => null,
|
||||
'type' => null,
|
||||
];
|
||||
|
||||
if ($this->event->{'participation_fee_' . $i} === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$participationFee = $this->event->{'participationFee' . $i}()->first();
|
||||
|
||||
$returnArray['participationFee_' . $i] = [
|
||||
$feeType = [
|
||||
'active' => true,
|
||||
'amount' => $this->event->{'participationFee' . $i}()->first()->amount->getFormattedAmount(),
|
||||
'name' => $this->event->{'participationFee' . $i}->first()->name,
|
||||
'description' => $this->event->{'participationFee' . $i}()->first()->description,
|
||||
'type' => $this->event->{'participationFee' . $i}->first()->type
|
||||
'amount_standard_edit' => $participationFee->amount_standard->getFormattedAmount(),
|
||||
'amount_standard' => [
|
||||
'internal' => [
|
||||
'amount' => $participationFee->amount_standard->getAmount(),
|
||||
'currency' => $participationFee->amount_standard->getCurrency(),
|
||||
],
|
||||
'readable' => $participationFee->amount_standard->multiply($multiplier)->toString(),
|
||||
],
|
||||
'amount_reduced_edit' => $participationFee->amount_reduced === null ? null : $participationFee->amount_reduced->getFormattedAmount(),
|
||||
'amount_reduced' => $participationFee->amount_reduced === null
|
||||
? null
|
||||
: [
|
||||
'internal' => [
|
||||
'amount' => $participationFee->amount_reduced->getAmount(),
|
||||
'currency' => $participationFee->amount_reduced->getCurrency(),
|
||||
],
|
||||
'readable' => $participationFee->amount_reduced->multiply($multiplier)->toString(),
|
||||
],
|
||||
'amount_solidarity_edit' => $participationFee->amount_solidarity === null ? null : $participationFee->amount_solidarity->getFormattedAmount(),
|
||||
'amount_solidarity' => $participationFee->amount_solidarity === null
|
||||
? null
|
||||
: [
|
||||
'internal' => [
|
||||
'amount' => $participationFee->amount_solidarity->getAmount(),
|
||||
'currency' => $participationFee->amount_solidarity->getCurrency(),
|
||||
],
|
||||
'readable' => $participationFee->amount_solidarity->multiply($multiplier)->toString(),
|
||||
],
|
||||
'name' => $participationFee->name,
|
||||
'description' => $participationFee->description,
|
||||
'type' => (new ParticipationTypeResource($participationFee->type()->first()))->toArray($request),
|
||||
];
|
||||
|
||||
|
||||
if ($this->event->participation_fee_type === ParticipationFeeType::PARTICIPATION_FEE_TYPE_SOLIDARITY) {
|
||||
$returnArray['participationFee_1' . $i]['description'] = '';
|
||||
$returnArray['participationFee_2' . $i]['description'] = '';
|
||||
$returnArray['participationFee_3' . $i]['description'] = 'Nach Verfügbarkeit';
|
||||
}
|
||||
|
||||
|
||||
$returnArray['participationFee_' . $i] = $feeType;
|
||||
$returnArray['participationTypes'][] = $feeType;
|
||||
|
||||
}
|
||||
|
||||
return $returnArray;
|
||||
}
|
||||
|
||||
public function getMultiplier() : float {
|
||||
$earlyBirdEnd = $this->event->early_bird_end;
|
||||
if ($earlyBirdEnd > now()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 1 + $this->event->early_bird_end_amount_increase / 100;
|
||||
}
|
||||
|
||||
public function calculateIncomes() : Amount {
|
||||
$amount = new Amount(0, 'Euro');
|
||||
$amount->addAmount($this->event->support_flat);
|
||||
return $amount;
|
||||
}
|
||||
|
||||
public function calculateAmount(
|
||||
string $participationType,
|
||||
string $feeType,
|
||||
DateTime $arrival,
|
||||
DateTime $departure
|
||||
) : Amount {
|
||||
$fee = collect([
|
||||
$this->event->participationFee1,
|
||||
$this->event->participationFee2,
|
||||
$this->event->participationFee3,
|
||||
$this->event->participationFee4,
|
||||
])->filter(fn ($participationFee) => $participationFee !== null)
|
||||
->first(fn ($participationFee) => $participationFee->type === $participationType);
|
||||
|
||||
if ($fee === null) {
|
||||
return new Amount(0, 'Euro');
|
||||
}
|
||||
|
||||
/** @var Amount $basicFee */
|
||||
$basicFee = $fee['amount_' . $feeType];
|
||||
$basicFee = $basicFee->multiply($this->getMultiplier());
|
||||
|
||||
if ($this->event->pay_per_day) {
|
||||
$days = $arrival->diff($departure)->days;
|
||||
$basicFee = $basicFee->multiply($days);
|
||||
}
|
||||
|
||||
return $basicFee;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user