mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Catch already linked transactions.
This commit is contained in:
@@ -40,7 +40,9 @@ class UpdatePiggyBank implements ActionInterface
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*/
|
||||
public function __construct(private readonly RuleAction $action) {}
|
||||
public function __construct(private readonly RuleAction $action)
|
||||
{
|
||||
}
|
||||
|
||||
public function actOnArray(array $journal): bool
|
||||
{
|
||||
@@ -67,6 +69,15 @@ class UpdatePiggyBank implements ActionInterface
|
||||
|
||||
Log::debug(sprintf('Found piggy bank #%d ("%s")', $piggyBank->id, $piggyBank->name));
|
||||
|
||||
// piggy bank already has an event for this transaction journal?
|
||||
if ($this->alreadyEventPresent($piggyBank, $journal)) {
|
||||
Log::info(sprintf('Piggy bank #%d ("%s") already has an event for transaction journal #%d, so no action will be taken.', $piggyBank->id, $piggyBank->name, $journalObj->id));
|
||||
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.cannot_find_piggy', ['name' => $actionValue])));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/** @var Transaction $destination */
|
||||
$destination = $journalObj->transactions()->where('amount', '>', 0)->first();
|
||||
|
||||
@@ -231,4 +242,9 @@ class UpdatePiggyBank implements ActionInterface
|
||||
|
||||
$repository->addAmount($piggyBank, $account, $amount, $journal);
|
||||
}
|
||||
|
||||
private function alreadyEventPresent(PiggyBank $piggyBank, array $journal): bool
|
||||
{
|
||||
return $piggyBank->piggyBankEvents()->where('transaction_journal_id', $journal['transaction_journal_id'])->exists();
|
||||
}
|
||||
}
|
||||
|
@@ -68,6 +68,7 @@ return [
|
||||
'cannot_find_piggy' => 'Firefly III can\'t find a piggy bank named ":name"',
|
||||
'no_link_piggy' => 'This transaction\'s accounts are not linked to the piggy bank, so no action will be taken',
|
||||
'both_link_piggy' => 'This transaction\'s accounts are both linked to the piggy bank, so no action will be taken',
|
||||
'already_linked' => 'This transaction is already linked to piggy bank ":name"',
|
||||
'cannot_unlink_tag' => 'Tag ":tag" isn\'t linked to this transaction',
|
||||
'cannot_find_budget' => 'Firefly III can\'t find budget ":name"',
|
||||
'cannot_find_category' => 'Firefly III can\'t find category ":name"',
|
||||
|
Reference in New Issue
Block a user