event = $event; } public function toArray() : array { $duration = $this->event->end_date->diff($this->event->start_date)->d + 1; $returnArray = [ 'id' => $this->event->id, 'name' => $this->event->name, 'location' => $this->event->location, 'postalCode' => $this->event->postal_code, 'email' => $this->event->email, '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')], ]; $returnArray['costUnit'] = new CostUnitResource($this->event->costUnit()->first())->toArray(true); $returnArray['solidarityPayment'] = $this->event->participation_fee_type === ParticipationFeeType::PARTICIPATION_FEE_TYPE_SOLIDARITY; $returnArray['payPerDay'] = $this->event->pay_per_day; $returnArray['maxAmount'] = $this->event->total_max_amount->getFormattedAmount(); $returnArray['eventBegin'] = $this->event->start_date->format('d.m.Y'); $returnArray['eventBeginInternal'] = $this->event->start_date; $returnArray['eventEnd'] = $this->event->end_date->format('d.m.Y'); $returnArray['eventEndInternal'] = $this->event->end_date; $returnArray['duration'] = $duration; # $totalBalance = new Amount(0, 'Euro'); $totalBalance->addAmount($this->calculateIncomes()); $totalBalance->subtractAmount($returnArray['costUnit']['overAllAmount']['value']); $returnArray['totalIncome'] = $this->calculateIncomes()->toString(); $returnArray['totalBalance'] = ['text' => $totalBalance->toString(), 'value' => $totalBalance->getAmount()]; $returnArray['flatSupport'] = $this->event->support_flat->toString(); $returnArray['supportPerson'] = $this->event->support_per_person->toString(); $returnArray['flatSupportEdit'] = $this->event->support_flat->getFormattedAmount(); $returnArray['supportPersonEdit'] = $this->event->support_per_person->getFormattedAmount(); $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['eatingHabits'] = $this->event->eatingHabits()->get()->map( fn($eatingHabit) => new EatingHabitResource($eatingHabit))->toArray(); for ($i = 1; $i <= 4; $i++) { $returnArray['participationFee_' . $i] = [ 'active' => false, 'name' => '', 'description' => '', 'amount' => '0,00', 'type' => null ]; if ($this->event->{'participation_fee_' . $i} === null) { continue; } $returnArray['participationFee_' . $i] = [ '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 ]; 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'; } } return $returnArray; } public function calculateIncomes() : Amount { $amount = new Amount(0, 'Euro'); $amount->addAmount($this->event->support_flat); return $amount; } }