Cost units can be edited

This commit is contained in:
2026-02-08 20:06:38 +01:00
parent 6fc65e195c
commit bccfc11687
53 changed files with 2021 additions and 29 deletions

View File

@@ -0,0 +1,43 @@
<?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;
}
}