Auto commit for release 'develop' on 2025-01-01

This commit is contained in:
github-actions
2025-01-01 16:47:50 +01:00
parent c11a5384da
commit f727a38b69
3 changed files with 63 additions and 61 deletions

View File

@@ -58,12 +58,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 (null === $piggyBank) {
Log::info(
sprintf('No piggy bank named "%s", cant execute action #%d of rule #%d', $actionValue, $this->action->id, $this->action->rule_id)
@@ -78,7 +78,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));
@@ -130,6 +130,7 @@ class UpdatePiggybank implements ActionInterface
if ($this->isConnected($piggyBank, $accounts['source']) && $this->isConnected($piggyBank, $accounts['destination'])) {
Log::info(sprintf('Piggy bank is linked to BOTH source ("#%d") and destination ("#%d"), so no action will be taken.', $accounts['source']->id, $accounts['destination']->id));
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.no_link_piggy', ['name' => $actionValue])));
return false;
}
Log::info(sprintf('Piggy bank is not linked to source ("#%d") or destination ("#%d"), so no action will be taken.', $accounts['source']->id, $accounts['destination']->id));
@@ -143,6 +144,7 @@ class UpdatePiggybank implements ActionInterface
/** @var PiggyBankRepositoryInterface $repository */
$repository = app(PiggyBankRepositoryInterface::class);
$repository->setUser($user);
return $repository->findByName($name);
}
@@ -152,11 +154,11 @@ class UpdatePiggybank implements ActionInterface
$repository->setUser($journal->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.
@@ -185,7 +187,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:
@@ -234,7 +236,7 @@ class UpdatePiggybank implements ActionInterface
}
}
Log::debug(sprintf('Piggy bank is not connected to account #%d "%s"', $account->id, $account->name));
return false;
}
}