Expand API.

This commit is contained in:
James Cole
2020-11-15 14:02:29 +01:00
parent 20e7948d99
commit eb616f36ea
6 changed files with 152 additions and 27 deletions

View File

@@ -29,16 +29,15 @@ use FireflyIII\Models\Budget;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
use Illuminate\Support\Collection;
use Symfony\Component\HttpFoundation\ParameterBag;
/**
* Class BudgetTransformer
*/
class BudgetTransformer extends AbstractTransformer
{
/** @var OperationsRepositoryInterface */
private $opsRepository;
/** @var BudgetRepositoryInterface */
private $repository;
private OperationsRepositoryInterface $opsRepository;
private BudgetRepositoryInterface $repository;
/**
* BudgetTransformer constructor.
@@ -49,6 +48,7 @@ class BudgetTransformer extends AbstractTransformer
{
$this->opsRepository = app(OperationsRepositoryInterface::class);
$this->repository = app(BudgetRepositoryInterface::class);
$this->parameters = new ParameterBag();
}
/**
@@ -66,7 +66,7 @@ class BudgetTransformer extends AbstractTransformer
$autoBudget = $this->repository->getAutoBudget($budget);
$spent = [];
if (null !== $start && null !== $end) {
$spent = $this->beautify($this->opsRepository->sumExpenses($start, $end, null, new Collection([$budget])));
$spent = $this->beautify($this->opsRepository->sumExpenses($start, $end, null, new Collection([$budget])));
}
$abCurrencyId = null;
@@ -81,10 +81,10 @@ class BudgetTransformer extends AbstractTransformer
];
if (null !== $autoBudget) {
$abCurrencyId = (int) $autoBudget->transactionCurrency->id;
$abCurrencyId = (int)$autoBudget->transactionCurrency->id;
$abCurrencyCode = $autoBudget->transactionCurrency->code;
$abType = $types[$autoBudget->auto_budget_type];
$abAmount = number_format((float) $autoBudget->amount, $autoBudget->transactionCurrency->decimal_places, '.', '');
$abAmount = number_format((float)$autoBudget->amount, $autoBudget->transactionCurrency->decimal_places, '.', '');
$abPeriod = $autoBudget->period;
}
@@ -118,7 +118,7 @@ class BudgetTransformer extends AbstractTransformer
{
$return = [];
foreach ($array as $data) {
$data['sum'] = number_format((float) $data['sum'], (int) $data['currency_decimal_places'], '.', '');
$data['sum'] = number_format((float)$data['sum'], (int)$data['currency_decimal_places'], '.', '');
$return[] = $data;
}