Skip to content

Firefly III: a personal finances manager

Clean up piggy alerts.

James Colea70fab1e878e
diff --git a/app/Support/Http/Controllers/PeriodOverview.php b/app/Support/Http/Controllers/PeriodOverview.php
index ddbe866e84..b639eff171 100644
--- a/app/Support/Http/Controllers/PeriodOverview.php
+++ b/app/Support/Http/Controllers/PeriodOverview.php
@@ -331,9 +331,7 @@ trait PeriodOverview
}
return $this->statistics->filter(
- function (PeriodStatistic $statistic) use ($start, $end, $type) {
- return $statistic->start->eq($start) && $statistic->end->eq($end) && $statistic->type === $type;
- }
+ fn(PeriodStatistic $statistic) => $statistic->start->eq($start) && $statistic->end->eq($end) && $statistic->type === $type
);
}
@@ -346,9 +344,7 @@ trait PeriodOverview
}
return $this->statistics->filter(
- function (PeriodStatistic $statistic) use ($start, $end, $prefix) {
- return $statistic->start->eq($start) && $statistic->end->eq($end) && str_starts_with($statistic->type, $prefix);
- }
+ fn(PeriodStatistic $statistic) => $statistic->start->eq($start) && $statistic->end->eq($end) && str_starts_with($statistic->type, $prefix)
);
}
diff --git a/app/TransactionRules/Actions/UpdatePiggyBank.php b/app/TransactionRules/Actions/UpdatePiggyBank.php
index 64fe735e6a..e5bb2a9411 100644
--- a/app/TransactionRules/Actions/UpdatePiggyBank.php
+++ b/app/TransactionRules/Actions/UpdatePiggyBank.php
@@ -31,7 +31,9 @@ use FireflyIII\Models\PiggyBank;
use FireflyIII\Models\RuleAction;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
+use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
+use FireflyIII\Support\Facades\Amount;
use FireflyIII\User;
use Illuminate\Support\Facades\Log;
@@ -176,7 +178,9 @@ class UpdatePiggyBank implements ActionInterface
private function removeAmount(PiggyBank $piggyBank, array $array, TransactionJournal $journal, Account $account, string $amount): void
{
$repository = app(PiggyBankRepositoryInterface::class);
+ $accountRepository = app(AccountRepositoryInterface::class);
$repository->setUser($journal->user);
+ $accountRepository->setUser($account->user);
// how much can we remove from this piggy bank?
$toRemove = $repository->getCurrentAmount($piggyBank, $account);
@@ -196,7 +200,8 @@ class UpdatePiggyBank implements ActionInterface
if (false === $repository->canRemoveAmount($piggyBank, $account, $amount)) {
Log::warning(sprintf('Cannot remove %s from piggy bank.', $amount));
- event(new RuleActionFailedOnArray($this->action, $array, trans('rules.cannot_remove_from_piggy', ['amount' => $amount, 'name' => $piggyBank->name])));
+ $currency = $accountRepository->getAccountCurrency($account) ?? Amount::getPrimaryCurrency();
+ event(new RuleActionFailedOnArray($this->action, $array, trans('rules.cannot_remove_from_piggy', ['amount' => Amount::formatAnything($amount, $currency, false), 'name' => $piggyBank->name])));
return;
}
@@ -208,7 +213,9 @@ class UpdatePiggyBank implements ActionInterface
private function addAmount(PiggyBank $piggyBank, array $array, TransactionJournal $journal, Account $account, string $amount): void
{
$repository = app(PiggyBankRepositoryInterface::class);
+ $accountRepository = app(AccountRepositoryInterface::class);
$repository->setUser($journal->user);
+ $accountRepository->setUser($account->user);
// how much can we add to the piggy bank?
if (0 !== bccomp($piggyBank->target_amount, '0')) {
@@ -233,7 +240,8 @@ class UpdatePiggyBank implements ActionInterface
if (false === $repository->canAddAmount($piggyBank, $account, $amount)) {
Log::warning(sprintf('Cannot add %s to piggy bank.', $amount));
- event(new RuleActionFailedOnArray($this->action, $array, trans('rules.cannot_add_to_piggy', ['amount' => $amount, 'name' => $piggyBank->name])));
+ $currency = $accountRepository->getAccountCurrency($account) ?? Amount::getPrimaryCurrency();
+ event(new RuleActionFailedOnArray($this->action, $array, trans('rules.cannot_add_to_piggy', ['amount' => Amount::formatAnything($amount, $currency, false), 'name' => $piggyBank->name])));
return;
}
diff --git a/resources/lang/en_US/rules.php b/resources/lang/en_US/rules.php
index ce60269015..405b13cb01 100644
--- a/resources/lang/en_US/rules.php
+++ b/resources/lang/en_US/rules.php
@@ -75,7 +75,7 @@ return [
'cannot_set_budget' => 'Firefly III can\'t set budget ":name" to a transaction of type ":type"',
'journal_invalid_amount' => 'Firefly III can\'t set amount ":amount" because it is not a valid number.',
'cannot_remove_zero_piggy' => 'Cannot remove zero amount from piggy bank ":name"',
- 'cannot_remove_from_piggy' => 'Cannot remove ":amount" from piggy bank ":name"',
+ 'cannot_remove_from_piggy' => 'Cannot remove :amount from piggy bank ":name"',
'cannot_add_zero_piggy' => 'Cannot add zero amount to piggy bank ":name"',
- 'cannot_add_to_piggy' => 'Cannot add ":amount" to piggy bank ":name"',
+ 'cannot_add_to_piggy' => 'Cannot add :amount to piggy bank ":name"',
];