buckets/app/Http/Resources/ProjectionResource.php

24 lines
No EOL
942 B
PHP

<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class ProjectionResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'inflows' => InflowResource::collection($this->resource['inflows']),
'outflows' => OutflowResource::collection($this->resource['outflows']),
'draws' => DrawResource::collection($this->resource['draws']),
'summary' => [
'total_inflow' => $this->resource['inflows']->sum('amount_currency'),
'total_outflow' => $this->resource['outflows']->sum('amount_currency'),
'total_allocated' => $this->resource['draws']->sum('amount_currency'),
'net_cashflow' => $this->resource['inflows']->sum('amount_currency') - $this->resource['outflows']->sum('amount_currency'),
],
];
}
}