Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Fix https://github.com/orgs/firefly-iii/discussions/7963
James Cole936c2b8888bd
diff --git a/app/TransactionRules/Actions/SetBudget.php b/app/TransactionRules/Actions/SetBudget.phpindex ed48a2cea5..1dbdc54c18 100644--- a/app/TransactionRules/Actions/SetBudget.php+++ b/app/TransactionRules/Actions/SetBudget.php@@ -83,6 +83,17 @@ class SetBudget implements ActionInterfacereturn false;}+ // find previous budget+ /** @var TransactionJournal $object */+ $object = $user->transactionJournals()->find($journal['transaction_journal_id']);+ $oldBudget = $object->budgets()->first();+ $oldBudgetName = $oldBudget?->name;+ if ((int)$oldBudget?->id === (int)$budget->id) {+ event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.already_linked_to_budget', ['name' => $budget->name])));+ return false;+ }++Log::debug(sprintf('RuleAction SetBudget set the budget of journal #%d to budget #%d ("%s").', $journal['transaction_journal_id'], $budget->id, $budget->name));@@ -92,7 +103,7 @@ class SetBudget implements ActionInterface/** @var TransactionJournal $object */$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);- event(new TriggeredAuditLog($this->action->rule, $object, 'set_budget', null, $budget->name));+ event(new TriggeredAuditLog($this->action->rule, $object, 'set_budget', $oldBudgetName, $budget->name));return true;}diff --git a/app/TransactionRules/Actions/SetCategory.php b/app/TransactionRules/Actions/SetCategory.phpindex 1277d1e2ce..30608a3f11 100644--- a/app/TransactionRules/Actions/SetCategory.php+++ b/app/TransactionRules/Actions/SetCategory.php@@ -87,12 +87,22 @@ class SetCategory implements ActionInterface));+ // find previous category+ /** @var TransactionJournal $object */+ $object = $user->transactionJournals()->find($journal['transaction_journal_id']);+ $oldCategory = $object->categories()->first();+ $oldCategoryName = $oldCategory?->name;+ if ((int)$oldCategory?->id === (int)$category->id) {+ event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.already_linked_to_category', ['name' => $category->name])));+ return false;+ }+DB::table('category_transaction_journal')->where('transaction_journal_id', '=', $journal['transaction_journal_id'])->delete();DB::table('category_transaction_journal')->insert(['transaction_journal_id' => $journal['transaction_journal_id'], 'category_id' => $category->id]);/** @var TransactionJournal $object */$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);- event(new TriggeredAuditLog($this->action->rule, $object, 'set_category', null, $category->name));+ event(new TriggeredAuditLog($this->action->rule, $object, 'set_category', $oldCategoryName, $category->name));return true;}diff --git a/resources/lang/en_US/rules.php b/resources/lang/en_US/rules.phpindex 8d034ab1f3..208a9267aa 100644--- a/resources/lang/en_US/rules.php+++ b/resources/lang/en_US/rules.php@@ -50,6 +50,8 @@ return ['already_has_destination' => 'This transaction already has ":name" as the destination account','already_has_source' => 'This transaction already has ":name" as the source account','already_linked_to_subscription' => 'The transaction is already linked to subscription ":name"',+ 'already_linked_to_category' => 'The transaction is already linked to category ":name"',+ 'already_linked_to_budget' => 'The transaction is already linked to budget ":name"','cannot_find_subscription' => 'Firefly III can\'t find subscription ":name"','no_notes_to_move' => 'The transaction has no notes to move to the description field','no_tags_to_remove' => 'The transaction has no tags to remove',