mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
API allows update/set of budget limit notes. https://github.com/firefly-iii/firefly-iii/issues/5523
This commit is contained in:
@@ -25,6 +25,7 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Transformers;
|
||||
|
||||
use FireflyIII\Models\BudgetLimit;
|
||||
use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\OperationsRepository;
|
||||
use Illuminate\Support\Collection;
|
||||
use League\Fractal\Resource\Item;
|
||||
@@ -54,8 +55,10 @@ class BudgetLimitTransformer extends AbstractTransformer
|
||||
*/
|
||||
public function transform(BudgetLimit $budgetLimit): array
|
||||
{
|
||||
$repository = app(OperationsRepository::class);
|
||||
$repository = app(OperationsRepository::class);
|
||||
$limitRepos = app(BudgetLimitRepositoryInterface::class);
|
||||
$repository->setUser($budgetLimit->budget->user);
|
||||
$limitRepos->setUser($budgetLimit->budget->user);
|
||||
$expenses = $repository->sumExpenses(
|
||||
$budgetLimit->start_date,
|
||||
$budgetLimit->end_date,
|
||||
@@ -65,6 +68,7 @@ class BudgetLimitTransformer extends AbstractTransformer
|
||||
);
|
||||
$currency = $budgetLimit->transactionCurrency;
|
||||
$amount = $budgetLimit->amount;
|
||||
$notes = $limitRepos->getNoteText($budgetLimit);
|
||||
$currencyDecimalPlaces = 2;
|
||||
$currencyId = null;
|
||||
$currencyName = null;
|
||||
@@ -78,16 +82,16 @@ class BudgetLimitTransformer extends AbstractTransformer
|
||||
$currencySymbol = $currency->symbol;
|
||||
$currencyDecimalPlaces = $currency->decimal_places;
|
||||
}
|
||||
$amount = app('steam')->bcround($amount, $currencyDecimalPlaces);
|
||||
$amount = app('steam')->bcround($amount, $currencyDecimalPlaces);
|
||||
|
||||
return [
|
||||
'id' => (string)$budgetLimit->id,
|
||||
'id' => (string) $budgetLimit->id,
|
||||
'created_at' => $budgetLimit->created_at->toAtomString(),
|
||||
'updated_at' => $budgetLimit->updated_at->toAtomString(),
|
||||
'start' => $budgetLimit->start_date->toAtomString(),
|
||||
'end' => $budgetLimit->end_date->endOfDay()->toAtomString(),
|
||||
'budget_id' => (string)$budgetLimit->budget_id,
|
||||
'currency_id' => (string)$currencyId,
|
||||
'budget_id' => (string) $budgetLimit->budget_id,
|
||||
'currency_id' => (string) $currencyId,
|
||||
'currency_code' => $currencyCode,
|
||||
'currency_name' => $currencyName,
|
||||
'currency_decimal_places' => $currencyDecimalPlaces,
|
||||
@@ -95,10 +99,11 @@ class BudgetLimitTransformer extends AbstractTransformer
|
||||
'amount' => $amount,
|
||||
'period' => $budgetLimit->period,
|
||||
'spent' => $expenses[$currencyId]['sum'] ?? '0',
|
||||
'notes' => '' === $notes ? null : $notes,
|
||||
'links' => [
|
||||
[
|
||||
'rel' => 'self',
|
||||
'uri' => '/budgets/limits/'.$budgetLimit->id,
|
||||
'uri' => '/budgets/limits/' . $budgetLimit->id,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
Reference in New Issue
Block a user