mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-05-04 13:16:31 +00:00
🤖 Auto commit for release 'develop' on 2026-01-23
This commit is contained in:
@@ -54,12 +54,12 @@ class UpdatePiggyBank implements ActionInterface
|
||||
|
||||
// refresh the transaction type.
|
||||
/** @var User $user */
|
||||
$user = User::find($journal['user_id']);
|
||||
$user = User::find($journal['user_id']);
|
||||
|
||||
/** @var TransactionJournal $journalObj */
|
||||
$journalObj = $user->transactionJournals()->find($journal['transaction_journal_id']);
|
||||
$journalObj = $user->transactionJournals()->find($journal['transaction_journal_id']);
|
||||
|
||||
$piggyBank = $this->findPiggyBank($user, $actionValue);
|
||||
$piggyBank = $this->findPiggyBank($user, $actionValue);
|
||||
if (!$piggyBank instanceof PiggyBank) {
|
||||
Log::info(sprintf('No piggy bank named "%s", cant execute action #%d of rule #%d', $actionValue, $this->action->id, $this->action->rule_id));
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.cannot_find_piggy', ['name' => $actionValue])));
|
||||
@@ -86,7 +86,7 @@ class UpdatePiggyBank implements ActionInterface
|
||||
/** @var Transaction $destination */
|
||||
$destination = $journalObj->transactions()->where('amount', '>', 0)->first();
|
||||
|
||||
$accounts = $this->getAccounts($journalObj);
|
||||
$accounts = $this->getAccounts($journalObj);
|
||||
Log::debug(sprintf('Source account is #%d: "%s"', $accounts['source']->id, $accounts['source']->name));
|
||||
Log::debug(sprintf('Destination account is #%d: "%s"', $accounts['destination']->id, $accounts['source']->name));
|
||||
|
||||
@@ -98,7 +98,7 @@ class UpdatePiggyBank implements ActionInterface
|
||||
'currency_symbol' => $journalObj->transactionCurrency->symbol,
|
||||
'decimal_places' => $journalObj->transactionCurrency->decimal_places,
|
||||
'amount' => $destination->amount,
|
||||
'piggy' => $piggyBank->name
|
||||
'piggy' => $piggyBank->name,
|
||||
]));
|
||||
|
||||
return true;
|
||||
@@ -114,7 +114,7 @@ class UpdatePiggyBank implements ActionInterface
|
||||
'decimal_places' => $journalObj->transactionCurrency->decimal_places,
|
||||
'amount' => $destination->amount,
|
||||
'piggy' => $piggyBank->name,
|
||||
'piggy_id' => $piggyBank->id
|
||||
'piggy_id' => $piggyBank->id,
|
||||
]));
|
||||
|
||||
return true;
|
||||
@@ -139,7 +139,7 @@ class UpdatePiggyBank implements ActionInterface
|
||||
return false;
|
||||
}
|
||||
|
||||
private function findPiggyBank(User $user, string $name): null|PiggyBank
|
||||
private function findPiggyBank(User $user, string $name): ?PiggyBank
|
||||
{
|
||||
/** @var PiggyBankRepositoryInterface $repository */
|
||||
$repository = app(PiggyBankRepositoryInterface::class);
|
||||
@@ -152,11 +152,11 @@ class UpdatePiggyBank implements ActionInterface
|
||||
{
|
||||
return [
|
||||
'source' => $journal->transactions()->where('amount', '<', '0')->first()?->account,
|
||||
'destination' => $journal->transactions()->where('amount', '>', '0')->first()?->account
|
||||
'destination' => $journal->transactions()->where('amount', '>', '0')->first()?->account,
|
||||
];
|
||||
}
|
||||
|
||||
private function isConnected(PiggyBank $piggyBank, null|Account $link): bool
|
||||
private function isConnected(PiggyBank $piggyBank, ?Account $link): bool
|
||||
{
|
||||
if (!$link instanceof Account) {
|
||||
return false;
|
||||
@@ -179,11 +179,11 @@ class UpdatePiggyBank implements ActionInterface
|
||||
$accountRepository->setUser($account->user);
|
||||
|
||||
// how much can we remove from this piggy bank?
|
||||
$toRemove = $repository->getCurrentAmount($piggyBank, $account);
|
||||
$toRemove = $repository->getCurrentAmount($piggyBank, $account);
|
||||
Log::debug(sprintf('Amount is %s, max to remove is %s', $amount, $toRemove));
|
||||
|
||||
// if $amount is bigger than $toRemove, shrink it.
|
||||
$amount = -1 === bccomp($amount, $toRemove) ? $amount : $toRemove;
|
||||
$amount = -1 === bccomp($amount, $toRemove) ? $amount : $toRemove;
|
||||
Log::debug(sprintf('Amount is now %s', $amount));
|
||||
|
||||
// if amount is zero, stop.
|
||||
@@ -199,7 +199,7 @@ class UpdatePiggyBank implements ActionInterface
|
||||
$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
|
||||
'name' => $piggyBank->name,
|
||||
])));
|
||||
|
||||
return;
|
||||
@@ -218,7 +218,7 @@ class UpdatePiggyBank implements ActionInterface
|
||||
|
||||
// how much can we add to the piggy bank?
|
||||
if (0 !== bccomp($piggyBank->target_amount, '0')) {
|
||||
$toAdd = bcsub($piggyBank->target_amount, $repository->getCurrentAmount($piggyBank, $account));
|
||||
$toAdd = bcsub($piggyBank->target_amount, $repository->getCurrentAmount($piggyBank, $account));
|
||||
Log::debug(sprintf('Max amount to add to piggy bank is %s, amount is %s', $toAdd, $amount));
|
||||
|
||||
// update amount to fit:
|
||||
@@ -242,7 +242,7 @@ class UpdatePiggyBank implements ActionInterface
|
||||
$currency = $accountRepository->getAccountCurrency($account) ?? Amount::getPrimaryCurrency();
|
||||
event(new RuleActionFailedOnArray($this->action, $array, trans('rules.cannot_add_to_piggy', [
|
||||
'amount' => Amount::formatAnything($currency, $amount, false),
|
||||
'name' => $piggyBank->name
|
||||
'name' => $piggyBank->name,
|
||||
])));
|
||||
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user