46 lines
1.3 KiB
PHP
46 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Resources;
|
|
|
|
use App\Enumerations\EatingHabit;
|
|
use App\Enumerations\EfzStatus;
|
|
use App\Enumerations\ParticipationType;
|
|
use App\Models\CostUnitEstimate;
|
|
use App\Models\EventParticipant;
|
|
use App\ValueObjects\Age;
|
|
use App\ValueObjects\Amount;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class CostUnitEstimateResource extends JsonResource
|
|
{
|
|
function __construct(CostUnitEstimate $estimate)
|
|
{
|
|
parent::__construct($estimate);
|
|
}
|
|
|
|
public function toArray($request) : array
|
|
{
|
|
$amount = $this->resource->calculateAmount();
|
|
$singleAmountString = $this->resource->flat_amount?->toString();
|
|
$amountType = 'flat';
|
|
if ($singleAmountString === null) {
|
|
$amountType = 'per_person';
|
|
$singleAmountString = $this->resource->amount_by_user->toString() . ' / Person (' . $amount->toString() . ' Gesamt)';
|
|
} else {
|
|
$singleAmountString .= ' Gesamt';
|
|
}
|
|
|
|
return [
|
|
'id' => $this->resource->id,
|
|
'title' => $this->resource->description,
|
|
'singleAmountString' => $singleAmountString,
|
|
'calculatedAmount' => $amount,
|
|
'calculatedAmountString' => $amount->toString(),
|
|
'amountValue' => $amount->getAmount(),
|
|
'amountType' => $amountType,
|
|
|
|
|
|
];
|
|
}
|
|
}
|