Skip to content

Firefly III: a personal finances manager

Fix processing new transactions.

James Cole035d59991000
diff --git a/app/Listeners/Model/TransactionGroup/ProcessesNewTransactionGroup.php b/app/Listeners/Model/TransactionGroup/ProcessesNewTransactionGroup.php
index eaef9fc3de..37c1139d5f 100644
--- a/app/Listeners/Model/TransactionGroup/ProcessesNewTransactionGroup.php
+++ b/app/Listeners/Model/TransactionGroup/ProcessesNewTransactionGroup.php
@@ -64,14 +64,15 @@ class ProcessesNewTransactionGroup implements ShouldQueue
if ($event->flags->applyRules) {
$this->processRules($set);
}
- if($event->flags->recalculateCredit) {
+ if ($event->flags->recalculateCredit) {
$this->recalculateCredit($set);
}
- if($event->flags->fireWebhooks) {
+ if ($event->flags->fireWebhooks) {
$this->fireWebhooks($set);
}
// always remove old statistics.
$this->removePeriodStatistics($set);
+ $repository->markAsCompleted($set);
}
@@ -86,10 +87,10 @@ class ProcessesNewTransactionGroup implements ShouldQueue
private function fireWebhooks(Collection $set): void
{
// collect transaction groups by set ids.
- $groups = TransactionGroup::whereIn('id',array_unique($set->pluck('transaction_group_id')->toArray()))->get();
+ $groups = TransactionGroup::whereIn('id', array_unique($set->pluck('transaction_group_id')->toArray()))->get();
Log::debug(__METHOD__);
- $user = $set->first()->user;
+ $user = $set->first()->user;
/** @var MessageGeneratorInterface $engine */
$engine = app(MessageGeneratorInterface::class);
diff --git a/app/Repositories/Journal/JournalRepository.php b/app/Repositories/Journal/JournalRepository.php
index 025ded15ce..e9e4a8b889 100644
--- a/app/Repositories/Journal/JournalRepository.php
+++ b/app/Repositories/Journal/JournalRepository.php
@@ -256,4 +256,10 @@ class JournalRepository implements JournalRepositoryInterface, UserGroupInterfac
{
return $this->userGroup->transactionJournals()->where('completed', false)->get(['transaction_journals.*']);
}
+
+ #[\Override]
+ public function markAsCompleted(Collection $set): void
+ {
+ TransactionJournal::whereIn('id', $set->pluck('id')->toArray())->update(['completed' => true]);
+ }
}
diff --git a/app/Repositories/Journal/JournalRepositoryInterface.php b/app/Repositories/Journal/JournalRepositoryInterface.php
index 9df1fe9a1e..67533f609c 100644
--- a/app/Repositories/Journal/JournalRepositoryInterface.php
+++ b/app/Repositories/Journal/JournalRepositoryInterface.php
@@ -54,6 +54,8 @@ interface JournalRepositoryInterface
public function getUncompletedJournals(): Collection;
+ public function markAsCompleted(Collection $set): void;
+
/**
* Deletes a journal.
*/
diff --git a/app/Services/Internal/Support/CreditRecalculateService.php b/app/Services/Internal/Support/CreditRecalculateService.php
index f21d3df510..86f461b9ee 100644
--- a/app/Services/Internal/Support/CreditRecalculateService.php
+++ b/app/Services/Internal/Support/CreditRecalculateService.php
@@ -75,29 +75,33 @@ class CreditRecalculateService
$this->processWork();
}
- private function processGroup(): void
+ private function collectFromJournals(Collection $transactionJournals): void
{
- /** @var TransactionJournal $journal */
- foreach ($this->group->transactionJournals as $journal) {
- try {
- $this->findByJournal($journal);
- } catch (FireflyException $e) {
- Log::error($e->getTraceAsString());
- Log::error(sprintf('Could not find work account for transaction group #%d.', $this->group->id));
+ Log::debug('Now in collectFromJournals()');
+ $valid = config('firefly.valid_liabilities');
+ $accounts = Account
+ ::leftJoin('transactions', 'transactions.account_id', 'accounts.id')
+ ->leftJoin('transaction_journals', 'transaction_journals.id', 'transactions.transaction_journal_id')
+ ->leftJoin('account_types', 'account_types.id', 'accounts.account_type_id')
+ ->whereIn('transaction_journals.id', $transactionJournals->pluck('id')->toArray())
+ ->whereIn('account_types.type', $valid)
+ ->get(['accounts.*']);
+ if ($accounts->count() > 0) {
+ Log::debug(sprintf('Found %d account(s) to process.', $accounts->count()));
+ foreach ($accounts as $account) {
+ $this->work[] = $account;
}
}
}
+ private function processGroup(): void
+ {
+ $this->collectFromJournals($this->group->transactionJournals);
+ }
+
private function processJournals(): void
{
- foreach ($this->journals as $journal) {
- try {
- $this->findByJournal($journal);
- } catch (FireflyException $e) {
- Log::error($e->getTraceAsString());
- Log::error(sprintf('Could not find work account for transaction journal #%d.', $journal->id));
- }
- }
+ $this->collectFromJournals($this->journals);
}