mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-09 22:26:04 +00:00
Clean up piggy alerts.
This commit is contained in:
@@ -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)
|
||||
);
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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"',
|
||||
];
|
||||
|
Reference in New Issue
Block a user