Creation and editing of events

This commit is contained in:
2026-02-16 21:59:21 +01:00
parent 2b458eccd7
commit fcf41c5d13
61 changed files with 3002 additions and 380 deletions

View File

@@ -3,6 +3,7 @@
namespace App\Resources;
use App\Enumerations\InvoiceStatus;
use App\Enumerations\InvoiceType;
use App\Models\CostUnit;
use App\Repositories\CostUnitRepository;
use App\ValueObjects\Amount;
@@ -28,6 +29,14 @@ class CostUnitResource {
$countDonatedInvoices = $countInvoices[InvoiceStatus::INVOICE_META_STATUS_DONATED];
$countDeniedInvoices = $countInvoices[InvoiceStatus::INVOICE_STATUS_DENIED];
$amounts = [];
$overAllAmount = new Amount(0, 'Euro');
foreach (InvoiceType::all() as $invoiceType) {
$overAllAmount->addAmount($costUnitRepository->sumupByInvoiceType($this->costUnit, $invoiceType));
$amounts[$invoiceType->slug]['string'] = $costUnitRepository->sumupByInvoiceType($this->costUnit, $invoiceType)->toString();
$amounts[$invoiceType->slug]['name'] = $invoiceType->name;
}
$data = array_merge(
$this->costUnit->toArray(),
@@ -41,6 +50,8 @@ class CostUnitResource {
'countDonatedInvoices' => $countDonatedInvoices,
'countDeniedInvoices' => $countDeniedInvoices,
'treasurers' => $this->costUnit->treasurers()->get()->map(fn($user) => new UserResource($user))->toArray(),
'amounts' => $amounts,
'overAllAmount' => ['text' => $overAllAmount->toString(), 'value' => $overAllAmount],
]);

View File

@@ -0,0 +1,22 @@
<?php
namespace App\Resources;
use App\Enumerations\EatingHabit;
use Illuminate\Http\Resources\Json\JsonResource;
class EatingHabitResource extends JsonResource {
private EatingHabit $eatingHabit;
public function __construct(EatingHabit $eatingHabit) {
$this->eatingHabit = $eatingHabit;
}
public function toArray($request) : array {
return [
'id' => $this->eatingHabit->id,
'slug' => $this->eatingHabit->slug,
'name' => $this->eatingHabit->name
];
}
}

View File

@@ -0,0 +1,109 @@
<?php
namespace App\Resources;
use App\Enumerations\ParticipationFeeType;
use App\Models\Event;
use App\ValueObjects\Amount;
class EventResource {
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;
$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;
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace App\Resources;
use App\Models\Tenant;
use Illuminate\Http\Resources\Json\JsonResource;
class LocalGroupResource extends JsonResource {
private Tenant $tenant;
public function __construct(Tenant $tenant) {
$this->tenant = $tenant;
}
public function toArray($request) : array {
return [
'id' => $this->tenant->id,
'name' => $this->tenant->name,
'email' => $this->tenant->email,
'city' => $this->tenant->city,
'postalcode'=> $this->tenant->postcode
];
}
}