Cost units can be edited
This commit is contained in:
43
app/Resources/CostUnitResource.php
Normal file
43
app/Resources/CostUnitResource.php
Normal 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,16 @@ class UserResource extends JsonResource {
|
||||
unset($data['activation_token_expires_at']);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getReducedData(): array {
|
||||
return [
|
||||
'id' => $this->user->id,
|
||||
'nicename' => $this->user->getNicename(),
|
||||
'fullname' => $this->user->getFullName(),
|
||||
'firstname' => $this->user->firstname,
|
||||
'lastname' => $this->user->lastname,
|
||||
'localGroup' => $this->user->localGroup()->name,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user