WiP
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user