This commit is contained in:
2026-03-25 20:28:04 +01:00
parent 37039f082c
commit 33b4a249cc
9 changed files with 303 additions and 42 deletions

View File

@@ -22,9 +22,19 @@ class EventParticipantResource extends JsonResource
$amountLeft->subtractAmount($this->resource->amount_paid);
}
$presenceDays = $this->resource->arrival_date->diff($this->resource->departure_date)->days;
$presenceDaysSupport = $presenceDays;
if ($presenceDaysSupport === 0) {
$presenceDaysSupport = 1;
} else {
$presenceDaysSupport = $presenceDaysSupport - 1;
}
return array_merge(
$this->resource->toArray(),
[
'presenceDays' => ['real' => $presenceDays, 'support' => $presenceDaysSupport],
'participationType' => ParticipationType::where(['slug' => $this->resource->participation_type])->first()->name,
'needs_payment' => $this->resource->amount->getAmount() > 0 && $event->pay_direct,
'nicename' => $this->resource->getNicename(),

View File

@@ -3,6 +3,7 @@
namespace App\Resources;
use App\Enumerations\ParticipationFeeType;
use App\Enumerations\ParticipationType;
use App\Models\Event;
use App\ValueObjects\Amount;
use DateTime;
@@ -24,6 +25,7 @@ class EventResource extends JsonResource{
'id' => $this->event->id,
'name' => $this->event->name,
'identifier' => $this->event->identifier,
'url' => 'https://' . app('tenant')->url . '/event/' . $this->event->identifier . '/signup',
'location' => $this->event->location,
'postalCode' => $this->event->postal_code,
'email' => $this->event->email,
@@ -56,6 +58,18 @@ class EventResource extends JsonResource{
->toArray();
foreach ([
ParticipationType::PARTICIPATION_TYPE_PARTICIPANT,
ParticipationType::PARTICIPATION_TYPE_TEAM,
ParticipationType::PARTICIPATION_TYPE_VOLUNTEER,
ParticipationType::PARTICIPATION_TYPE_OTHER,
] as $participationType) {
$returnArray['participants'][$participationType] = $this->getParticipants($participationType);
}
$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;
@@ -65,15 +79,33 @@ class EventResource extends JsonResource{
$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['supportPersonIndex'] = $this->event->support_per_person->toString();
$returnArray['supportPerson'] = $this->calculateSupportPerPerson($returnArray['participants']);
$returnArray['income'] = $this->calculateIncomes($returnArray['participants'], $returnArray['supportPerson']['amount']);
$totalBalanceReal = new Amount(0, 'Euro');
$totalBalanceExpected = new Amount(0, 'Euro');
$totalBalanceReal->addAmount($returnArray['income']['real']['amount']);
$totalBalanceExpected->addAmount($returnArray['income']['expected']['amount']);
$totalBalanceReal->subtractAmount($returnArray['costUnit']['overAllAmount']['value']);
$totalBalanceExpected->subtractAmount($returnArray['costUnit']['overAllAmount']['value']);
$returnArray['totalBalance'] = [
'real' => [
'value' => $totalBalanceReal->getAmount(),
'readable' => $totalBalanceReal->toString(),
], 'expected' => [
'value' => $totalBalanceExpected->getAmount(),
'readable' => $totalBalanceExpected->toString(),
]
];
$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();
@@ -161,12 +193,106 @@ class EventResource extends JsonResource{
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 calculateSupportPerPerson(array $participants) : array {
if ($this->event->support_per_person === null) {
return [
'amount' => new Amount(0, 'Euro'),
'readable' => '0,00'
];
}
$amount = $this->event->support_per_person;
$multiplier = 0;
foreach ($participants as $participationType => $participantData) {
if (isset($participantData['participants']) && count($participantData['participants']) > 0) {
foreach ($participantData['participants'] as $participant) {
$multiplier += $participant->toResource()->toArray(new Request())['presenceDays']['support'];
}
}
}
$amount->multiply($multiplier);
return [
'amount' => $amount,
'readable' => $amount->toString()
];
}
public function calculateIncomes(array $participants, Amount $supportPerPerson) : array {
$expectedAmount = $supportPerPerson;
$expectedAmount->addAmount($this->event->support_flat);
$realAmount = $supportPerPerson;
$realAmount->addAmount($this->event->support_flat);
foreach ($participants as $participationType => $participantData) {
$expectedAmount->addAmount(new Amount($participantData['amount']['expected']['value'], 'Euro'));
$realAmount->addAmount(new Amount($participantData['amount']['paid']['value'], 'Euro'));
}
return ['real' => [
'amount' => $realAmount,
'readable' => $realAmount->toString()
],
'expected' => [
'amount' => $expectedAmount,
'readable' => $expectedAmount->toString(),
]
];
}
public function getParticipants(string $participationType) : array {
$returnData = [];
$returnData['amount'] = ['expected' => new Amount(0, 'Euro'), 'paid' => new Amount(0, 'Euro')];
$returnData['count'] = 0;
foreach ($this->event->participants()->where(
[
'participation_type' => $participationType,
'unregistered_at' => null
]
)->get() as $participant)
{
$returnData['count']++;
$returnData['participants'][] = $participant;
if ($participant->amount !== null) {
$returnData['amount']['expected'] = $returnData['amount']['expected']->addAmount($participant->amount);
}
if ($participant->amount_paid !== null) {
$returnData['amount']['paid'] = $returnData['amount']['paid']->addAmount($participant->amount_paid);
}
};
$returnData['amount']['expected'] =
[
'value' => $returnData['amount']['expected']->getAmount(),
'readable' => $returnData['amount']['expected']->toString()
];
$returnData['amount']['paid'] =
[
'value' => $returnData['amount']['paid']->getAmount(),
'readable' => $returnData['amount']['paid']->toString()
];
return $returnData;
}
public function calculateAmount(
string $participationType,
string $feeType,