Files
mareike/app/Resources/CostUnitResource.php

44 lines
1.3 KiB
PHP

<?php
namespace App\Resources;
use App\Models\CostUnit;
use App\ValueObjects\Amount;
class CostUnitResource {
private CostUnit $costUnit;
public function __construct(CostUnit $costUnit) {
$this->costUnit = $costUnit;
}
public function toArray($request) {
$totalAmount = 0;
$donatedAmount = 0;
$countNewInvoices = 0;
$countApprovedInvoices = 0;
$countDonatedInvoices = 0;
$countDeniedInvoices = 0;
$data = array_merge(
$this->costUnit->toArray(),
[
'distanceAllowanceSmall' => new Amount($this->costUnit->distance_allowance, '')->toString(),
'distanceAllowanceFull' => new Amount($this->costUnit->distance_allowance, ' Euro')->toString(),
'totalAmount' => new Amount($totalAmount, ' Euro')->toString(),
'donatedAmount' => new Amount($donatedAmount, ' Euro')->toString(),
'countNewInvoices' => $countNewInvoices,
'countApprovedInvoices' => $countApprovedInvoices,
'countDonatedInvoices' => $countDonatedInvoices,
'countDeniedInvoices' => $countDeniedInvoices,
'treasurers' => $this->costUnit->tresurers()->get()->map(fn($user) => new UserResource($user))->toArray(),
]);
return $data;
}
}